rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: Fix enabling Rust and building with GCC for LoongArch
@ 2025-03-04  7:35 WANG Rui
  2025-03-04  7:49 ` Xi Ruoyao
  0 siblings, 1 reply; 6+ messages in thread
From: WANG Rui @ 2025-03-04  7:35 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Huacai Chen
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	rust-for-linux, linux-kernel, loongarch, loongson-kernel,
	WANG Rui, stable

This patch fixes a build issue on LoongArch when Rust is enabled and
compiled with GCC by explicitly setting the bindgen target and skipping
C flags that Clang doesn't support.

Cc: stable@vger.kernel.org
Signed-off-by: WANG Rui <wangrui@loongson.cn>
---
 rust/Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/rust/Makefile b/rust/Makefile
index ea3849eb78f6..2c57c624fe7d 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -232,7 +232,8 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
 	-mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
 	-mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
 	-mno-pointers-to-nested-functions -mno-string \
-	-mno-strict-align -mstrict-align \
+	-mno-strict-align -mstrict-align -mdirect-extern-access \
+	-mexplicit-relocs -mno-check-zero-division \
 	-fconserve-stack -falign-jumps=% -falign-loops=% \
 	-femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \
 	-fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \
@@ -246,6 +247,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
 # Derived from `scripts/Makefile.clang`.
 BINDGEN_TARGET_x86	:= x86_64-linux-gnu
 BINDGEN_TARGET_arm64	:= aarch64-linux-gnu
+BINDGEN_TARGET_loongarch	:= loongarch64-linux-gnusf
 BINDGEN_TARGET		:= $(BINDGEN_TARGET_$(SRCARCH))
 
 # All warnings are inhibited since GCC builds are very experimental,
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: Fix enabling Rust and building with GCC for LoongArch
  2025-03-04  7:35 [PATCH] rust: Fix enabling Rust and building with GCC for LoongArch WANG Rui
@ 2025-03-04  7:49 ` Xi Ruoyao
  2025-03-04  9:12   ` Huacai Chen
  0 siblings, 1 reply; 6+ messages in thread
From: Xi Ruoyao @ 2025-03-04  7:49 UTC (permalink / raw)
  To: WANG Rui, Miguel Ojeda, Alex Gaynor, Huacai Chen
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	rust-for-linux, linux-kernel, loongarch, loongson-kernel, stable

On Tue, 2025-03-04 at 15:35 +0800, WANG Rui wrote:
> This patch fixes a build issue on LoongArch when Rust is enabled and
> compiled with GCC by explicitly setting the bindgen target and skipping
> C flags that Clang doesn't support.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: WANG Rui <wangrui@loongson.cn>
> ---
>  rust/Makefile | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/rust/Makefile b/rust/Makefile
> index ea3849eb78f6..2c57c624fe7d 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -232,7 +232,8 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
>  	-mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
>  	-mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
>  	-mno-pointers-to-nested-functions -mno-string \
> -	-mno-strict-align -mstrict-align \
> +	-mno-strict-align -mstrict-align -mdirect-extern-access \
> +	-mexplicit-relocs -mno-check-zero-division \

Hmm I'm wondering if we can just drop -mno-check-zero-division from
cflags-y: for all GCC releases it's the default at either -O2 or -Os,
and AFAIK we don't support other optimization levels.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: Fix enabling Rust and building with GCC for LoongArch
  2025-03-04  7:49 ` Xi Ruoyao
@ 2025-03-04  9:12   ` Huacai Chen
  2025-03-28 16:15     ` Miguel Ojeda
  0 siblings, 1 reply; 6+ messages in thread
From: Huacai Chen @ 2025-03-04  9:12 UTC (permalink / raw)
  To: Xi Ruoyao
  Cc: WANG Rui, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel,
	loongarch, loongson-kernel, stable

On Tue, Mar 4, 2025 at 3:49 PM Xi Ruoyao <xry111@xry111.site> wrote:
>
> On Tue, 2025-03-04 at 15:35 +0800, WANG Rui wrote:
> > This patch fixes a build issue on LoongArch when Rust is enabled and
> > compiled with GCC by explicitly setting the bindgen target and skipping
> > C flags that Clang doesn't support.
> >
> > Cc: stable@vger.kernel.org
> > Signed-off-by: WANG Rui <wangrui@loongson.cn>
> > ---
> >  rust/Makefile | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/rust/Makefile b/rust/Makefile
> > index ea3849eb78f6..2c57c624fe7d 100644
> > --- a/rust/Makefile
> > +++ b/rust/Makefile
> > @@ -232,7 +232,8 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
> >       -mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
> >       -mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
> >       -mno-pointers-to-nested-functions -mno-string \
> > -     -mno-strict-align -mstrict-align \
> > +     -mno-strict-align -mstrict-align -mdirect-extern-access \
> > +     -mexplicit-relocs -mno-check-zero-division \
>
> Hmm I'm wondering if we can just drop -mno-check-zero-division from
> cflags-y: for all GCC releases it's the default at either -O2 or -Os,
> and AFAIK we don't support other optimization levels.
Don't rely on  default behavior, things may change in future.
Acked-by: Huacai Chen <chenhuacai@loongson.cn>

>
> --
> Xi Ruoyao <xry111@xry111.site>
> School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: Fix enabling Rust and building with GCC for LoongArch
  2025-03-04  9:12   ` Huacai Chen
@ 2025-03-28 16:15     ` Miguel Ojeda
  2025-03-29  2:42       ` WANG Rui
  2025-03-29  8:45       ` Huacai Chen
  0 siblings, 2 replies; 6+ messages in thread
From: Miguel Ojeda @ 2025-03-28 16:15 UTC (permalink / raw)
  To: Huacai Chen
  Cc: Xi Ruoyao, WANG Rui, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, rust-for-linux,
	linux-kernel, loongarch, loongson-kernel, stable

On Tue, Mar 4, 2025 at 10:12 AM Huacai Chen <chenhuacai@kernel.org> wrote:
>
> Don't rely on  default behavior, things may change in future.
> Acked-by: Huacai Chen <chenhuacai@loongson.cn>

I was pinged about this one -- are you picking this one through your tree?

I didn't test it, but the change seems safe to me for other
architectures that we have at the moment, since they don't seem to set
any of those three from a quick look, so:

Acked-by: Miguel Ojeda <ojeda@kernel.org>

In any case, the usual question for these "skipped flags" is whether
they could affect the output of `bindgen`, i.e. could they modify
layouts somehow?

Also, it would be nice to mention a bit more what was the build error
and the GCC version in the commit message.

Finally, regarding the Cc: stable, I guess that means 6.12+ since it
is the first LTS with loongarch64, right?

Thanks!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: Fix enabling Rust and building with GCC for LoongArch
  2025-03-28 16:15     ` Miguel Ojeda
@ 2025-03-29  2:42       ` WANG Rui
  2025-03-29  8:45       ` Huacai Chen
  1 sibling, 0 replies; 6+ messages in thread
From: WANG Rui @ 2025-03-29  2:42 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Huacai Chen, Xi Ruoyao, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, rust-for-linux,
	linux-kernel, loongarch, loongson-kernel, stable

On Sat, Mar 29, 2025 at 12:15 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>

Thanks for the review and feedback!

> In any case, the usual question for these "skipped flags" is whether
> they could affect the output of `bindgen`, i.e. could they modify
> layouts somehow?

These "skipped flags" won't affect the output of `bindgen`.

>
> Also, it would be nice to mention a bit more what was the build error
> and the GCC version in the commit message.

To make it easier for the maintainer to include more details in the
commit message, I've attached the original build error message below.

  BINDGEN rust/bindings/bindings_generated.rs
error: unknown argument: '-mexplicit-relocs'
error: unknown argument: '-mdirect-extern-access'
error: unsupported argument 'normal' to option '-mcmodel=' for target 'unknown'
error: unknown target triple 'unknown'
panicked at /home/hev/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bindgen-0.71.1/ir/context.rs:564:15:
libclang error; possible causes include:
- Invalid flag syntax
- Unrecognized flags
- Invalid flag arguments
- File I/O errors
- Host vs. target architecture mismatch
If you encounter an error missing from this list, please file an issue or a PR!

gcc version 14.2.0 (crosstool-NG 1.27.0)

>
> Finally, regarding the Cc: stable, I guess that means 6.12+ since it
> is the first LTS with loongarch64, right?

Also, the `Cc: stable` is indeed targeting 6.12+, as it's the first
LTS with LoongArch64.

Thanks again!

Cheers,
-Rui


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: Fix enabling Rust and building with GCC for LoongArch
  2025-03-28 16:15     ` Miguel Ojeda
  2025-03-29  2:42       ` WANG Rui
@ 2025-03-29  8:45       ` Huacai Chen
  1 sibling, 0 replies; 6+ messages in thread
From: Huacai Chen @ 2025-03-29  8:45 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Xi Ruoyao, WANG Rui, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, rust-for-linux,
	linux-kernel, loongarch, loongson-kernel, stable

Hi, Miguel,

On Sat, Mar 29, 2025 at 12:15 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Tue, Mar 4, 2025 at 10:12 AM Huacai Chen <chenhuacai@kernel.org> wrote:
> >
> > Don't rely on  default behavior, things may change in future.
> > Acked-by: Huacai Chen <chenhuacai@loongson.cn>
>
> I was pinged about this one -- are you picking this one through your tree?
OK, I wll pick it to the loongarch tree, thanks.

Huacai

>
> I didn't test it, but the change seems safe to me for other
> architectures that we have at the moment, since they don't seem to set
> any of those three from a quick look, so:
>
> Acked-by: Miguel Ojeda <ojeda@kernel.org>
>
> In any case, the usual question for these "skipped flags" is whether
> they could affect the output of `bindgen`, i.e. could they modify
> layouts somehow?
>
> Also, it would be nice to mention a bit more what was the build error
> and the GCC version in the commit message.
>
> Finally, regarding the Cc: stable, I guess that means 6.12+ since it
> is the first LTS with loongarch64, right?
>
> Thanks!
>
> Cheers,
> Miguel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-03-29  8:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-04  7:35 [PATCH] rust: Fix enabling Rust and building with GCC for LoongArch WANG Rui
2025-03-04  7:49 ` Xi Ruoyao
2025-03-04  9:12   ` Huacai Chen
2025-03-28 16:15     ` Miguel Ojeda
2025-03-29  2:42       ` WANG Rui
2025-03-29  8:45       ` Huacai Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).