Skip to content

Commit 2029d3f

Browse files
SpriteOvOMingcongBai
authored andcommitted
BACKPORT: FROMLIST: RISC-V: handle extension configs for bindgen, re-enable gcc + rust builds
Commit 33549fc ("RISC-V: disallow gcc + rust builds") disabled GCC + Rust builds for RISC-V due to differences in extension handling compared to LLVM. This commit enables GCC + Rust builds again. Add `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 maintained. Acked-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Asuna Yang <SpriteOvO@gmail.com> Link: https://lore.kernel.org/r/20251204-gcc-rust-v5-v5-4-2d4f20d86c24@gmail.com Signed-off-by: Han Gao <gaohan@iscas.ac.cn> [Mingcong Bai: (6.19-rc8) Resolved a minor merge conflict in rust/Makefile] Signed-off-by: Mingcong Bai <jeffbai@aosc.io>
1 parent d735a27 commit 2029d3f

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

Documentation/rust/arch-support.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Architecture Level of support Constraints
1818
``arm`` Maintained ARMv7 Little Endian only.
1919
``arm64`` Maintained Little Endian only.
2020
``loongarch`` Maintained \-
21-
``riscv`` Maintained ``riscv64`` and LLVM/Clang only.
21+
``riscv`` Maintained ``riscv64`` only.
2222
``um`` Maintained \-
2323
``x86`` Maintained ``x86_64`` only.
2424
============= ================ ==============================================

arch/riscv/Kconfig

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ config RISCV
196196
select HAVE_REGS_AND_STACK_ACCESS_API
197197
select HAVE_RETHOOK if !XIP_KERNEL
198198
select HAVE_RSEQ
199-
select HAVE_RUST if RUSTC_SUPPORTS_RISCV && CC_IS_CLANG
199+
select HAVE_RUST if RUSTC_SUPPORTS_RISCV && TOOLCHAIN_MATCHES_ZICSR_ZIFENCEI
200200
select HAVE_SAMPLE_FTRACE_DIRECT
201201
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
202202
select HAVE_STACKPROTECTOR
@@ -620,6 +620,8 @@ config TOOLCHAIN_HAS_V
620620
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32imv)
621621
depends on LD_IS_LLD || LD_VERSION >= 23800
622622
depends on AS_HAS_OPTION_ARCH
623+
depends on !RUST || !64BIT || $(bindgen-backend-option,-mabi=lp64 -march=rv64imv)
624+
depends on !RUST || !32BIT || $(bindgen-backend-option,-mabi=ilp32 -march=rv32imv)
623625

624626
config RISCV_ISA_V
625627
bool "Vector extension support"
@@ -684,6 +686,8 @@ config TOOLCHAIN_HAS_ZABHA
684686
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zabha)
685687
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zabha)
686688
depends on AS_HAS_OPTION_ARCH
689+
depends on !RUST || !64BIT || $(bindgen-backend-option,-mabi=lp64 -march=rv64ima_zabha)
690+
depends on !RUST || !32BIT || $(bindgen-backend-option,-mabi=ilp32 -march=rv32ima_zabha)
687691

688692
config RISCV_ISA_ZABHA
689693
bool "Zabha extension support for atomic byte/halfword operations"
@@ -702,6 +706,8 @@ config TOOLCHAIN_HAS_ZACAS
702706
depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zacas)
703707
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zacas)
704708
depends on AS_HAS_OPTION_ARCH
709+
depends on !RUST || !64BIT || $(bindgen-backend-option,-mabi=lp64 -march=rv64ima_zacas)
710+
depends on !RUST || !32BIT || $(bindgen-backend-option,-mabi=ilp32 -march=rv32ima_zacas)
705711

706712
config RISCV_ISA_ZACAS
707713
bool "Zacas extension support for atomic CAS"
@@ -720,6 +726,8 @@ config TOOLCHAIN_HAS_ZBB
720726
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb)
721727
depends on LD_IS_LLD || LD_VERSION >= 23900
722728
depends on AS_HAS_OPTION_ARCH
729+
depends on !RUST || !64BIT || $(bindgen-backend-option,-mabi=lp64 -march=rv64ima_zbb)
730+
depends on !RUST || !32BIT || $(bindgen-backend-option,-mabi=ilp32 -march=rv32ima_zbb)
723731

724732
# This symbol indicates that the toolchain supports all v1.0 vector crypto
725733
# extensions, including Zvk*, Zvbb, and Zvbc. LLVM added all of these at once.
@@ -735,6 +743,8 @@ config TOOLCHAIN_HAS_ZBA
735743
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zba)
736744
depends on LD_IS_LLD || LD_VERSION >= 23900
737745
depends on AS_HAS_OPTION_ARCH
746+
depends on !RUST || !64BIT || $(bindgen-backend-option,-mabi=lp64 -march=rv64ima_zba)
747+
depends on !RUST || !32BIT || $(bindgen-backend-option,-mabi=ilp32 -march=rv32ima_zba)
738748

739749
config RISCV_ISA_ZBA
740750
bool "Zba extension support for bit manipulation instructions"
@@ -770,6 +780,8 @@ config TOOLCHAIN_HAS_ZBC
770780
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbc)
771781
depends on LD_IS_LLD || LD_VERSION >= 23900
772782
depends on AS_HAS_OPTION_ARCH
783+
depends on !RUST || !64BIT || $(bindgen-backend-option,-mabi=lp64 -march=rv64ima_zbc)
784+
depends on !RUST || !32BIT || $(bindgen-backend-option,-mabi=ilp32 -march=rv32ima_zbc)
773785

774786
config RISCV_ISA_ZBC
775787
bool "Zbc extension support for carry-less multiplication instructions"
@@ -793,6 +805,8 @@ config TOOLCHAIN_HAS_ZBKB
793805
depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbkb)
794806
depends on LD_IS_LLD || LD_VERSION >= 23900
795807
depends on AS_HAS_OPTION_ARCH
808+
depends on !RUST || !64BIT || $(bindgen-backend-option,-mabi=lp64 -march=rv64ima_zbkb)
809+
depends on !RUST || !32BIT || $(bindgen-backend-option,-mabi=ilp32 -march=rv32ima_zbkb)
796810

797811
config RISCV_ISA_ZBKB
798812
bool "Zbkb extension support for bit manipulation instructions"
@@ -894,6 +908,25 @@ config TOOLCHAIN_NEEDS_OLD_ISA_SPEC
894908
versions of clang and GCC to be passed to GAS, which has the same result
895909
as passing zicsr and zifencei to -march.
896910

911+
config RUST_BINDGEN_HAS_ZICSR_ZIFENCEI
912+
def_bool y
913+
depends on !64BIT || $(bindgen-backend-option,-mabi=lp64 -march=rv64ima_zicsr_zifencei)
914+
depends on !32BIT || $(bindgen-backend-option,-mabi=ilp32 -march=rv32ima_zicsr_zifencei)
915+
916+
config TOOLCHAIN_MATCHES_ZICSR_ZIFENCEI
917+
def_bool y
918+
# https://github.com/llvm/llvm-project/commit/22e199e6afb1263c943c0c0d4498694e15bf8a16
919+
depends on TOOLCHAIN_NEEDS_OLD_ISA_SPEC || !TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI || RUST_BINDGEN_HAS_ZICSR_ZIFENCEI
920+
help
921+
LLVM/Clang >= 17.0.0 starts recognizing Zicsr/Zifencei in -march, passing
922+
them to -march doesn't generate an error anymore, and passing them or not
923+
doesn't have any real difference, it still follows ISA before version
924+
20190608 - Zicsr/Zifencei are included in base ISA.
925+
926+
The current latest version of LLVM/Clang still does not require explicit
927+
Zicsr/Zifencei to enable these two extensions, Clang just accepts them in
928+
-march and then silently ignores them.
929+
897930
config FPU
898931
bool "FPU support"
899932
default y

rust/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
402402
-fstrict-flex-arrays=% -fmin-function-alignment=% \
403403
-fzero-init-padding-bits=% -mno-fdpic \
404404
-fdiagnostics-show-context -fdiagnostics-show-context=% \
405-
--param=% --param asan-% -fno-isolate-erroneous-paths-dereference
405+
--param=% --param asan-% -fno-isolate-erroneous-paths-dereference \
406+
-mno-riscv-attribute
406407

407408
# All warnings are inhibited since GCC builds are very experimental,
408409
# many GCC warnings are not supported by Clang, they may only appear in

scripts/Makefile.rust

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ BINDGEN_TARGET_x86 := x86_64-linux-gnu
33
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
44
BINDGEN_TARGET_arm := arm-linux-gnueabi
55
BINDGEN_TARGET_loongarch := loongarch64-linux-gnusf
6+
BINDGEN_TARGET_riscv := riscv64-linux-gnu
67
BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
78
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
89

0 commit comments

Comments
 (0)