rust/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
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
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
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
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
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
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
© 2016 - 2026 Red Hat, Inc.