[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <73d55231-d1e5-400d-9446-1914a78c0db8@iscas.ac.cn>
Date: Fri, 19 Sep 2025 13:20:25 +0800
From: Vivian Wang <wangruikang@...as.ac.cn>
To: Asuna Yang <spriteovo@...il.com>, Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>,
Jonathan Corbet <corbet@....net>, Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>,
Alexandre Ghiti <alex@...ti.fr>, Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
Bill Wendling <morbo@...gle.com>, Justin Stitt <justinstitt@...gle.com>,
Han Gao <rabenda.cn@...il.com>, Jason Montleon <jmontleo@...hat.com>,
Conor Dooley <conor@...nel.org>
Cc: rust-for-linux@...r.kernel.org, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-riscv@...ts.infradead.org,
linux-kbuild@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH v3] RISC-V: re-enable gcc + rust builds
On 9/14/25 15:16, Asuna Yang wrote:
> [...]
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 51dcd8eaa24356d947ebe0f1c4a701a3cfc6b757..3e892864f930778218073e8ee5980eb8f4e1594a 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -191,7 +191,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
> @@ -629,6 +629,8 @@ config TOOLCHAIN_HAS_V
> depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32imv)
> depends on LLD_VERSION >= 140000 || LD_VERSION >= 23800
> depends on AS_HAS_OPTION_ARCH
> + # https://github.com/llvm/llvm-project/commit/e6de53b4de4aecca4ac892500a0907805896ed27
> + depends on !RUST || RUST_BINDGEN_LIBCLANG_VERSION >= 140000
>
I think instead of testing libclang version, it would make more sense to
feature test if bindgen the binary supports these flags, like what we
already do with $(cc-option,...).
Same for all the other version tests.
> [...]
>
> +config TOOLCHAIN_MATCHES_ZICSR_ZIFENCEI
TOOLCHAIN_ACCEPTS_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_LIBCLANG_VERSION >= 170000
> + 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/init/Kconfig b/init/Kconfig
> index e3eb63eadc8757a10b091c74bbee8008278c0521..0859d308a48591df769c7dbaef6f035324892bd3 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -82,6 +82,12 @@ config RUSTC_LLVM_VERSION
> int
> default $(rustc-llvm-version)
>
> +config RUST_BINDGEN_LIBCLANG_VERSION
> + int
> + default $(rustc-bindgen-libclang-version)
> + help
> + This is the version of `libclang` used by the Rust bindings generator.
> +
This can go away if we don't test the version anymore.
> config CC_CAN_LINK
> bool
> default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT
> diff --git a/rust/Makefile b/rust/Makefile
> index bfa915b0e58854045b367557342727fee4fe2808..8c6f84487c41880816d1e55ba4c0df0e5af4e8fd 100644
> --- a/rust/Makefile
> +++ b/rust/Makefile
> @@ -290,20 +290,25 @@ 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-%
> + --param=% --param asan-% -mno-riscv-attribute
>
> # 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_riscv := riscv64-linux-gnu
Do you know if this works for riscv32? Makefile.clang uses "-m32" for
32BIT, AFAICT, but i don't know if this is a good idea.
Maybe riscv32 Rust for Linux is broken anyway...
> BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
> BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
>
> +ifeq ($(BINDGEN_TARGET),)
> +$(error add '--target=' option to rust/Makefile)
> +else
Is this necessary? Maybe this can go in a separate patch, or even
submitted separately entirely - it's unrelated to "RISC-V: re-enable gcc
+ rust builds" and would be weird to see in git blame.
Vivian "dramforever" Wang
Powered by blists - more mailing lists