* [PATCH v4 1/4] rust: export BINDGEN_TARGET from a separate Makefile
2025-11-24 0:23 [PATCH v4 0/4] RISC-V: re-enable gcc + rust builds Asuna Yang
@ 2025-11-24 0:23 ` Asuna Yang
2025-11-24 1:40 ` Miguel Ojeda
2025-11-24 0:23 ` [PATCH v4 2/4] rust: generate a fatal error if BINDGEN_TARGET is undefined Asuna Yang
` (2 subsequent siblings)
3 siblings, 1 reply; 14+ messages in thread
From: Asuna Yang @ 2025-11-24 0:23 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley
Cc: linux-kbuild, linux-kernel, rust-for-linux, llvm, linux-doc,
linux-riscv, Asuna Yang
A subsequent commit will add a new function `rust-bindgen-option` to
`scripts/Kconfig.include`. The bindgen backend requires the `--target`
option for cross compiling, but variable `BINDGEN_TARGET` in
`rust/Makefile` cannot be exported to `scripts/Kconfig.include`.
Signed-off-by: Asuna Yang <SpriteOvO@gmail.com>
---
Makefile | 2 ++
rust/Makefile | 8 --------
scripts/Makefile.rust | 9 +++++++++
3 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
index fb4389aa5d5f..e4fcae38cc13 100644
--- a/Makefile
+++ b/Makefile
@@ -718,6 +718,8 @@ ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
include $(srctree)/scripts/Makefile.clang
endif
+include $(srctree)/scripts/Makefile.rust
+
# Include this also for config targets because some architectures need
# cc-cross-prefix to determine CROSS_COMPILE.
ifdef need-compiler
diff --git a/rust/Makefile b/rust/Makefile
index 7842ad0a4ea7..ae7cbbd89da3 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -300,14 +300,6 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
-fzero-init-padding-bits=% -mno-fdpic \
--param=% --param asan-% -fno-isolate-erroneous-paths-dereference
-# Derived from `scripts/Makefile.clang`.
-BINDGEN_TARGET_x86 := x86_64-linux-gnu
-BINDGEN_TARGET_arm64 := aarch64-linux-gnu
-BINDGEN_TARGET_arm := arm-linux-gnueabi
-BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
-BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
-BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
-
# All warnings are inhibited since GCC builds are very experimental,
# many GCC warnings are not supported by Clang, they may only appear in
# some configurations, with new GCC versions, etc.
diff --git a/scripts/Makefile.rust b/scripts/Makefile.rust
new file mode 100644
index 000000000000..5c12b4b8c8b6
--- /dev/null
+++ b/scripts/Makefile.rust
@@ -0,0 +1,9 @@
+# Derived from `scripts/Makefile.clang`.
+BINDGEN_TARGET_x86 := x86_64-linux-gnu
+BINDGEN_TARGET_arm64 := aarch64-linux-gnu
+BINDGEN_TARGET_arm := arm-linux-gnueabi
+BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
+BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
+BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
+
+export BINDGEN_TARGET
--
2.51.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v4 1/4] rust: export BINDGEN_TARGET from a separate Makefile
2025-11-24 0:23 ` [PATCH v4 1/4] rust: export BINDGEN_TARGET from a separate Makefile Asuna Yang
@ 2025-11-24 1:40 ` Miguel Ojeda
0 siblings, 0 replies; 14+ messages in thread
From: Miguel Ojeda @ 2025-11-24 1:40 UTC (permalink / raw)
To: Asuna Yang
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley, linux-kbuild, linux-kernel, rust-for-linux, llvm,
linux-doc, linux-riscv
On Mon, Nov 24, 2025 at 1:23 AM Asuna Yang <spriteovo@gmail.com> wrote:
>
> A subsequent commit will add a new function `rust-bindgen-option` to
> `scripts/Kconfig.include`. The bindgen backend requires the `--target`
> option for cross compiling, but variable `BINDGEN_TARGET` in
> `rust/Makefile` cannot be exported to `scripts/Kconfig.include`.
Please end with another paragraph saying what the commit does, e.g.
"Thus move the variable to a new `Makefile` that can then be imported
from the main `Makefile`" or similar.
Also, I am not sure if this should be called `Makefile.bindgen`, but I
guess it is fine as it is -- with the current name, the new file
should be covered by the `F: scripts/*rust*` rule in `MAINTAINERS`
already, so this looks OK, but please double-check it is the case.
Finally, is it possible to put this under `need-compiler` like
`Makefile.compiler`? I don't think we need to evaluate those options
for things like `make help`, but perhaps I am missing something.
Please see commit 805b2e1d427a ("kbuild: include Makefile.compiler
only when compiler is needed").
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 2/4] rust: generate a fatal error if BINDGEN_TARGET is undefined
2025-11-24 0:23 [PATCH v4 0/4] RISC-V: re-enable gcc + rust builds Asuna Yang
2025-11-24 0:23 ` [PATCH v4 1/4] rust: export BINDGEN_TARGET from a separate Makefile Asuna Yang
@ 2025-11-24 0:23 ` Asuna Yang
2025-11-24 1:24 ` Miguel Ojeda
2025-11-24 0:23 ` [PATCH v4 3/4] rust: add a Kconfig function to test for support of bindgen options Asuna Yang
2025-11-24 0:23 ` [PATCH v4 4/4] RISC-V: fix gcc + rust builds Asuna Yang
3 siblings, 1 reply; 14+ messages in thread
From: Asuna Yang @ 2025-11-24 0:23 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley
Cc: linux-kbuild, linux-kernel, rust-for-linux, llvm, linux-doc,
linux-riscv, Asuna Yang
Generate a friendly fatal error if the target triplet is undefined for
bindgen, rather than having the compiler generate obscure error messages
during the build stage.
This piece of code is copied from `scripts/Makefile.clang`.
Signed-off-by: Asuna Yang <SpriteOvO@gmail.com>
---
scripts/Makefile.rust | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/scripts/Makefile.rust b/scripts/Makefile.rust
index 5c12b4b8c8b6..b219244cd051 100644
--- a/scripts/Makefile.rust
+++ b/scripts/Makefile.rust
@@ -6,4 +6,8 @@ BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
+ifeq ($(BINDGEN_TARGET),)
+$(error add '--target=' option to scripts/Makefile.rust)
+else
export BINDGEN_TARGET
+endif
--
2.51.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v4 2/4] rust: generate a fatal error if BINDGEN_TARGET is undefined
2025-11-24 0:23 ` [PATCH v4 2/4] rust: generate a fatal error if BINDGEN_TARGET is undefined Asuna Yang
@ 2025-11-24 1:24 ` Miguel Ojeda
0 siblings, 0 replies; 14+ messages in thread
From: Miguel Ojeda @ 2025-11-24 1:24 UTC (permalink / raw)
To: Asuna Yang
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley, linux-kbuild, linux-kernel, rust-for-linux, llvm,
linux-doc, linux-riscv
On Mon, Nov 24, 2025 at 1:23 AM Asuna Yang <spriteovo@gmail.com> wrote:
>
> Generate a friendly fatal error if the target triplet is undefined for
> bindgen, rather than having the compiler generate obscure error messages
> during the build stage.
I normally suggest putting in the log the errors in case someone
searches for them and for future reference etc.
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Cheers,
Miguel
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 3/4] rust: add a Kconfig function to test for support of bindgen options
2025-11-24 0:23 [PATCH v4 0/4] RISC-V: re-enable gcc + rust builds Asuna Yang
2025-11-24 0:23 ` [PATCH v4 1/4] rust: export BINDGEN_TARGET from a separate Makefile Asuna Yang
2025-11-24 0:23 ` [PATCH v4 2/4] rust: generate a fatal error if BINDGEN_TARGET is undefined Asuna Yang
@ 2025-11-24 0:23 ` Asuna Yang
2025-11-24 1:48 ` Miguel Ojeda
2025-11-24 0:23 ` [PATCH v4 4/4] RISC-V: fix gcc + rust builds Asuna Yang
3 siblings, 1 reply; 14+ messages in thread
From: Asuna Yang @ 2025-11-24 0:23 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley
Cc: linux-kbuild, linux-kernel, rust-for-linux, llvm, linux-doc,
linux-riscv, Asuna Yang
Use the `BINDGEN_EXTRA_CLANG_ARGS` environment variable to pass the
`--target` option for cross compiling, so that the function can be used
to test both bindgen options and bindgen backend options.
Signed-off-by: Asuna Yang <SpriteOvO@gmail.com>
---
scripts/Kconfig.include | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index 33193ca6e803..a8cfe9f408a5 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -75,3 +75,8 @@ rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC))
# If you are testing for unstable features, consider testing RUSTC_VERSION
# instead, as features may have different completeness while available.
rustc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(RUSTC) $(1) --crate-type=rlib /dev/null --out-dir=.tmp_$$ -o .tmp_$$/tmp.rlib)
+
+# $(rust-bindgen-option,<flag>)
+# Return y if the Rust bindgen supports <flag>, n otherwise
+# To test options for the bindgen backend, add -- at the beginning, for example: $(rust-bindgen-option,-- <backend-flag>)
+rust-bindgen-option = $(success,trap "rm -f .tmp_$$.h" EXIT; touch .tmp_$$.h; BINDGEN_EXTRA_CLANG_ARGS+=" --target=$(BINDGEN_TARGET)" $(BINDGEN) .tmp_$$.h $(1))
--
2.51.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/4] rust: add a Kconfig function to test for support of bindgen options
2025-11-24 0:23 ` [PATCH v4 3/4] rust: add a Kconfig function to test for support of bindgen options Asuna Yang
@ 2025-11-24 1:48 ` Miguel Ojeda
2025-11-24 2:42 ` Asuna Yang
0 siblings, 1 reply; 14+ messages in thread
From: Miguel Ojeda @ 2025-11-24 1:48 UTC (permalink / raw)
To: Asuna Yang
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley, linux-kbuild, linux-kernel, rust-for-linux, llvm,
linux-doc, linux-riscv
On Mon, Nov 24, 2025 at 1:23 AM Asuna Yang <spriteovo@gmail.com> wrote:
>
> Use the `BINDGEN_EXTRA_CLANG_ARGS` environment variable to pass the
> `--target` option for cross compiling, so that the function can be used
> to test both bindgen options and bindgen backend options.
It seems this explains part of how it works, but not what the commit
adds and why, i.e. could we start with "Add `rustc-bindgen-option`..."
etc.?
By the way, shouldn't this just be called `bindgen-option`? Up to the
Kbuild team.
More importantly, should we just have a separate function for backend
flags? That would be easier and would avoid having to use the
environment variable, if I understand the commit message here
correctly. And, anyway, it is actually the only function we need so
far.
> +# Return y if the Rust bindgen supports <flag>, n otherwise
Maybe just "y if bindgen supports"?
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/4] rust: add a Kconfig function to test for support of bindgen options
2025-11-24 1:48 ` Miguel Ojeda
@ 2025-11-24 2:42 ` Asuna Yang
2025-11-24 3:08 ` Miguel Ojeda
0 siblings, 1 reply; 14+ messages in thread
From: Asuna Yang @ 2025-11-24 2:42 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley, linux-kbuild, linux-kernel, rust-for-linux, llvm,
linux-doc, linux-riscv
On 11/24/25 9:48 AM, Miguel Ojeda wrote:
> More importantly, should we just have a separate function for backend
> flags? That would be easier and would avoid having to use the
> environment variable, if I understand the commit message here
> correctly. And, anyway, it is actually the only function we need so
> far.
You are right, separated might be better.
Another reason is, in `scripts/Makefile.compiler`, there is a set of
functions with the same name provided for use by Makefile. Since we
currently do not need to check for bindgen options in Makefile, I didn't
add function for bindgen there. If we add it in the future, the
`bindgen-option` function in `Kconfig.include` will correspond to the
`bindgen-option-yn` function in `Makefile.compiler`, and
`bindgen-option` function in `Makefile.compiler` will return the
selected option instead of yn.
If we don't separate them now, for consistency, in `Makefile.compiler`,
`$(call bindgen-option,-- --some-flag-a,-- --some-flag-b)` will return
an option prefixed with --, which makes it difficult to use.
I will separate them into two functions in the next revision,
`bindgen-option` and `bindgen-backend-option` (or `bindgen-cc-option`?
Which one do you prefer?).
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/4] rust: add a Kconfig function to test for support of bindgen options
2025-11-24 2:42 ` Asuna Yang
@ 2025-11-24 3:08 ` Miguel Ojeda
2025-11-24 18:36 ` Nathan Chancellor
0 siblings, 1 reply; 14+ messages in thread
From: Miguel Ojeda @ 2025-11-24 3:08 UTC (permalink / raw)
To: Asuna Yang
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley, linux-kbuild, linux-kernel, rust-for-linux, llvm,
linux-doc, linux-riscv
On Mon, Nov 24, 2025 at 3:42 AM Asuna Yang <spriteovo@gmail.com> wrote:
>
> I will separate them into two functions in the next revision,
> `bindgen-option` and `bindgen-backend-option` (or `bindgen-cc-option`?
> Which one do you prefer?).
If we don't need `bindgen-option` (the normal one I mean) so far,
perhaps we should skip it. On the other hand, `rustc-option-yn` is
there and is not used either (it was added for consistency). Up to the
Kbuild team, I guess.
As for the name, no strong preference. `bindgen-backend-option` sounds
good, but `bindgen-cc-option` is more consistent with `cc-option` and
probably easier to understand for people new to `bindgen`, and anyway
the flags we pass there wouldn't make sense if the backend is not a C
compiler.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 3/4] rust: add a Kconfig function to test for support of bindgen options
2025-11-24 3:08 ` Miguel Ojeda
@ 2025-11-24 18:36 ` Nathan Chancellor
0 siblings, 0 replies; 14+ messages in thread
From: Nathan Chancellor @ 2025-11-24 18:36 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Asuna Yang, Nicolas Schier, Miguel Ojeda, Alex Gaynor, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Nick Desaulniers,
Bill Wendling, Justin Stitt, Nicolas Schier, Jonathan Corbet,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Vivian Wang, Han Gao, Jason Montleon, Conor Dooley, linux-kbuild,
linux-kernel, rust-for-linux, llvm, linux-doc, linux-riscv
On Mon, Nov 24, 2025 at 04:08:36AM +0100, Miguel Ojeda wrote:
> On Mon, Nov 24, 2025 at 3:42 AM Asuna Yang <spriteovo@gmail.com> wrote:
> >
> > I will separate them into two functions in the next revision,
> > `bindgen-option` and `bindgen-backend-option` (or `bindgen-cc-option`?
> > Which one do you prefer?).
>
> If we don't need `bindgen-option` (the normal one I mean) so far,
> perhaps we should skip it. On the other hand, `rustc-option-yn` is
> there and is not used either (it was added for consistency). Up to the
> Kbuild team, I guess.
I do not have a strong preference one way or the other. These macros
tend to be low maintenance and do not take up much space regardless so
preemptively adding it so that it is ready for use in the future is no
big deal in my opinion.
> As for the name, no strong preference. `bindgen-backend-option` sounds
> good, but `bindgen-cc-option` is more consistent with `cc-option` and
> probably easier to understand for people new to `bindgen`, and anyway
> the flags we pass there wouldn't make sense if the backend is not a C
> compiler.
Yeah, I think either one sort of requires knowledge of bindgen to know
the difference between a flag to bindgen and a flag to the C compiler
behind bindgen so no strong preference from my side (Nicolas may feel
differently).
Cheers,
Nathan
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 4/4] RISC-V: fix gcc + rust builds
2025-11-24 0:23 [PATCH v4 0/4] RISC-V: re-enable gcc + rust builds Asuna Yang
` (2 preceding siblings ...)
2025-11-24 0:23 ` [PATCH v4 3/4] rust: add a Kconfig function to test for support of bindgen options Asuna Yang
@ 2025-11-24 0:23 ` Asuna Yang
2025-11-24 1:21 ` Miguel Ojeda
3 siblings, 1 reply; 14+ messages in thread
From: Asuna Yang @ 2025-11-24 0:23 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley
Cc: linux-kbuild, linux-kernel, rust-for-linux, llvm, linux-doc,
linux-riscv, Asuna Yang
Commit 33549fcf37ec ("RISC-V: disallow gcc + rust builds") disabled GCC
+ Rust builds for RISC-V due to differences in extension handling
compared to LLVM.
Add `rust-bindgen-option` conditions for the availability of libclang to
the RISC-V extension Kconfig symbols that depend on the `cc-option`
function.
For Zicsr/Zifencei special handling, since LLVM/Clang always enables
these two extensions, either don't pass them to `-march`, or pass them
explicitly and Rust bindgen libclang must recognize them.
Clang does not support `-mno-riscv-attribute` flag, filter it out to
resolve error: unknown argument: '-mno-riscv-attribute'.
Define `BINDGEN_TARGET_riscv` to pass the target triplet to Rust bindgen
libclang for RISC-V to resolve error: unsupported argument 'medany' to
option '-mcmodel=' for target 'unknown'.
Update the documentation, GCC + Rust builds for RISC-V are now
supported.
Signed-off-by: Asuna Yang <SpriteOvO@gmail.com>
---
Documentation/rust/arch-support.rst | 2 +-
arch/riscv/Kconfig | 35 ++++++++++++++++++++++++++++++++++-
rust/Makefile | 3 ++-
scripts/Makefile.rust | 1 +
4 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst
index 6e6a515d0899..5282e0e174e8 100644
--- a/Documentation/rust/arch-support.rst
+++ b/Documentation/rust/arch-support.rst
@@ -18,7 +18,7 @@ Architecture Level of support Constraints
``arm`` Maintained ARMv7 Little Endian only.
``arm64`` Maintained Little Endian only.
``loongarch`` Maintained \-
-``riscv`` Maintained ``riscv64`` and LLVM/Clang only.
+``riscv`` Maintained ``riscv64`` only.
``um`` Maintained \-
``x86`` Maintained ``x86_64`` only.
============= ================ ==============================================
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index fadec20b87a8..e3ea132191d1 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -193,7 +193,7 @@ config RISCV
select HAVE_REGS_AND_STACK_ACCESS_API
select HAVE_RETHOOK if !XIP_KERNEL
select HAVE_RSEQ
- select HAVE_RUST if RUSTC_SUPPORTS_RISCV && CC_IS_CLANG
+ select HAVE_RUST if RUSTC_SUPPORTS_RISCV && TOOLCHAIN_MATCHES_ZICSR_ZIFENCEI
select HAVE_SAMPLE_FTRACE_DIRECT
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
select HAVE_STACKPROTECTOR
@@ -617,6 +617,8 @@ config TOOLCHAIN_HAS_V
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32imv)
depends on LD_IS_LLD || LD_VERSION >= 23800
depends on AS_HAS_OPTION_ARCH
+ depends on !RUST || !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=rv64imv)
+ depends on !RUST || !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=rv32imv)
config RISCV_ISA_V
bool "Vector extension support"
@@ -681,6 +683,8 @@ config TOOLCHAIN_HAS_ZABHA
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zabha)
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zabha)
depends on AS_HAS_OPTION_ARCH
+ depends on !RUST || !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=rv64ima_zabha)
+ depends on !RUST || !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=rv32ima_zabha)
config RISCV_ISA_ZABHA
bool "Zabha extension support for atomic byte/halfword operations"
@@ -699,6 +703,8 @@ config TOOLCHAIN_HAS_ZACAS
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zacas)
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zacas)
depends on AS_HAS_OPTION_ARCH
+ depends on !RUST || !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=rv64ima_zacas)
+ depends on !RUST || !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=rv32ima_zacas)
config RISCV_ISA_ZACAS
bool "Zacas extension support for atomic CAS"
@@ -717,6 +723,8 @@ config TOOLCHAIN_HAS_ZBB
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb)
depends on LD_IS_LLD || LD_VERSION >= 23900
depends on AS_HAS_OPTION_ARCH
+ depends on !RUST || !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=rv64ima_zbb)
+ depends on !RUST || !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=rv32ima_zbb)
# This symbol indicates that the toolchain supports all v1.0 vector crypto
# extensions, including Zvk*, Zvbb, and Zvbc. LLVM added all of these at once.
@@ -732,6 +740,8 @@ config TOOLCHAIN_HAS_ZBA
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zba)
depends on LD_IS_LLD || LD_VERSION >= 23900
depends on AS_HAS_OPTION_ARCH
+ depends on !RUST || !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=rv64ima_zba)
+ depends on !RUST || !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=rv32ima_zba)
config RISCV_ISA_ZBA
bool "Zba extension support for bit manipulation instructions"
@@ -767,6 +777,8 @@ config TOOLCHAIN_HAS_ZBC
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbc)
depends on LD_IS_LLD || LD_VERSION >= 23900
depends on AS_HAS_OPTION_ARCH
+ depends on !RUST || !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=rv64ima_zbc)
+ depends on !RUST || !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=rv32ima_zbc)
config RISCV_ISA_ZBC
bool "Zbc extension support for carry-less multiplication instructions"
@@ -790,6 +802,8 @@ config TOOLCHAIN_HAS_ZBKB
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbkb)
depends on LD_IS_LLD || LD_VERSION >= 23900
depends on AS_HAS_OPTION_ARCH
+ depends on !RUST || !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=rv64ima_zbkb)
+ depends on !RUST || !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=rv32ima_zbkb)
config RISCV_ISA_ZBKB
bool "Zbkb extension support for bit manipulation instructions"
@@ -877,6 +891,25 @@ config TOOLCHAIN_NEEDS_OLD_ISA_SPEC
versions of clang and GCC to be passed to GAS, which has the same result
as passing zicsr and zifencei to -march.
+config RUST_BINDGEN_HAS_ZICSR_ZIFENCEI
+ def_bool y
+ depends on !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=rv64ima_zicsr_zifencei)
+ depends on !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=rv32ima_zicsr_zifencei)
+
+config TOOLCHAIN_MATCHES_ZICSR_ZIFENCEI
+ def_bool y
+ # https://github.com/llvm/llvm-project/commit/22e199e6afb1263c943c0c0d4498694e15bf8a16
+ depends on TOOLCHAIN_NEEDS_OLD_ISA_SPEC || !TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI || RUST_BINDGEN_HAS_ZICSR_ZIFENCEI
+ help
+ LLVM/Clang >= 17.0.0 starts recognizing Zicsr/Zifencei in -march, passing
+ them to -march doesn't generate an error anymore, and passing them or not
+ doesn't have any real difference, it still follows ISA before version
+ 20190608 - Zicsr/Zifencei are included in base ISA.
+
+ The current latest version of LLVM/Clang still does not require explicit
+ Zicsr/Zifencei to enable these two extensions, Clang just accepts them in
+ -march and then silently ignores them.
+
config FPU
bool "FPU support"
default y
diff --git a/rust/Makefile b/rust/Makefile
index ae7cbbd89da3..1f209e6025e4 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -298,7 +298,8 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
-fno-inline-functions-called-once -fsanitize=bounds-strict \
-fstrict-flex-arrays=% -fmin-function-alignment=% \
-fzero-init-padding-bits=% -mno-fdpic \
- --param=% --param asan-% -fno-isolate-erroneous-paths-dereference
+ --param=% --param asan-% -fno-isolate-erroneous-paths-dereference \
+ -mno-riscv-attribute
# All warnings are inhibited since GCC builds are very experimental,
# many GCC warnings are not supported by Clang, they may only appear in
diff --git a/scripts/Makefile.rust b/scripts/Makefile.rust
index b219244cd051..cee28a604830 100644
--- a/scripts/Makefile.rust
+++ b/scripts/Makefile.rust
@@ -3,6 +3,7 @@ BINDGEN_TARGET_x86 := x86_64-linux-gnu
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
BINDGEN_TARGET_arm := arm-linux-gnueabi
BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
+BINDGEN_TARGET_riscv := riscv64-linux-gnu
BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
--
2.51.1
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v4 4/4] RISC-V: fix gcc + rust builds
2025-11-24 0:23 ` [PATCH v4 4/4] RISC-V: fix gcc + rust builds Asuna Yang
@ 2025-11-24 1:21 ` Miguel Ojeda
2025-11-24 2:05 ` Asuna Yang
0 siblings, 1 reply; 14+ messages in thread
From: Miguel Ojeda @ 2025-11-24 1:21 UTC (permalink / raw)
To: Asuna Yang
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley, linux-kbuild, linux-kernel, rust-for-linux, llvm,
linux-doc, linux-riscv
On Mon, Nov 24, 2025 at 1:23 AM Asuna Yang <spriteovo@gmail.com> wrote:
>
> Commit 33549fcf37ec ("RISC-V: disallow gcc + rust builds") disabled GCC
> + Rust builds for RISC-V due to differences in extension handling
> compared to LLVM.
This should mention what we are doing, i.e. re-enabling the GCC + Rust
support again.
Also, I would recommend avoiding to say "fix" in the title, unless it
is actually a fix, but perhaps the RISC-V maintainers consider it a
fix.
> Add `rust-bindgen-option` conditions for the availability of libclang to
> the RISC-V extension Kconfig symbols that depend on the `cc-option`
> function.
This is now in a different commit, right?
> Update the documentation, GCC + Rust builds for RISC-V are now
> supported.
"are now maintained" may be better to avoid confusing it with the
"Level of Support" in the table.
> Documentation/rust/arch-support.rst | 2 +-
> rust/Makefile | 3 ++-
> scripts/Makefile.rust | 1 +
In any case, for the Rust bits, this seems OK (I didn't test it, though), so:
Acked-by: Miguel Ojeda <ojeda@kernel.org>
(By the way, I wouldn't mind if we started adding `MAINTAINERS`
entries on who is maintaining particular architectures for Rust,
especially if there is someone in particular involved with it etc.).
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v4 4/4] RISC-V: fix gcc + rust builds
2025-11-24 1:21 ` Miguel Ojeda
@ 2025-11-24 2:05 ` Asuna Yang
2025-11-24 2:12 ` Miguel Ojeda
0 siblings, 1 reply; 14+ messages in thread
From: Asuna Yang @ 2025-11-24 2:05 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley, linux-kbuild, linux-kernel, rust-for-linux, llvm,
linux-doc, linux-riscv
On 11/24/25 9:21 AM, Miguel Ojeda wrote:
>> Add `rust-bindgen-option` conditions for the availability of libclang to
>> the RISC-V extension Kconfig symbols that depend on the `cc-option`
>> function.
> This is now in a different commit, right?
Sorry, I may not have made it clear. I mean all these changes.
+ depends on !RUST || !64BIT || $(rust-bindgen-option,-- -mabi=lp64 -march=...)
+ depends on !RUST || !32BIT || $(rust-bindgen-option,-- -mabi=ilp32 -march=...)
> (By the way, I wouldn't mind if we started adding `MAINTAINERS`
> entries on who is maintaining particular architectures for Rust,
> especially if there is someone in particular involved with it etc.).
I had some contributions in rust-lang/rust repo for riscv64 (PR #131955,
FWIW), and I'd like to be added as a Rust + RISC-V Linux maintainer if
that's okay for you guys.
For the suggestions about commit messages, I will improve them in the
next revision.
Thanks for your reviews!
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v4 4/4] RISC-V: fix gcc + rust builds
2025-11-24 2:05 ` Asuna Yang
@ 2025-11-24 2:12 ` Miguel Ojeda
0 siblings, 0 replies; 14+ messages in thread
From: Miguel Ojeda @ 2025-11-24 2:12 UTC (permalink / raw)
To: Asuna Yang
Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Nick Desaulniers, Bill Wendling, Justin Stitt, Nicolas Schier,
Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, Vivian Wang, Han Gao, Jason Montleon,
Conor Dooley, linux-kbuild, linux-kernel, rust-for-linux, llvm,
linux-doc, linux-riscv
On Mon, Nov 24, 2025 at 3:05 AM Asuna Yang <spriteovo@gmail.com> wrote:
>
> Sorry, I may not have made it clear. I mean all these changes.
Ah, sorry, I missed the "conditions" word by reading too quickly and
misinterpreted it, my bad.
> I had some contributions in rust-lang/rust repo for riscv64 (PR #131955,
> FWIW), and I'd like to be added as a Rust + RISC-V Linux maintainer if
> that's okay for you guys.
I think having people explicitly listed like that would be great (e.g.
in an `... [RUST]` sub-entry to the ARCH one or similar, like we do in
other places), and it is a good way to contribute to Linux. I was
thinking about it for other architectures too. But let's see what
RISC-V maintainers think about it.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 14+ messages in thread