arm: rust: Enable Rust support for ARMv7
Subsystems (3)
PATCH 1/1 arm: rust: Enable Rust support for ARMv7
This commit allows building ARMv7 kernels with Rust support.
The rust core library expects some __eabi_... functions that are not implemented in the kernel.
Those functions are some float operations and __aeabi_uldivmod.
This is based on the code by Sven Van Asbroeck from the original rust branch and inspired by the AArch version by Jamie Cunliffe.
I have tested the rust samples and a custom simple MMIO module on on hardware (De1SoC FPGA + Arm A9 CPU).
--- Documentation/rust/arch-support.rst | 1 + arch/arm/Kconfig | 1 + arch/arm/Makefile | 1 + rust/Makefile | 10 +++++++++- rust/bindgen_parameters | 4 ++++ rust/compiler_builtins.rs | 24 ++++++++++++++++++++++++ scripts/generate_rust_target.rs | 4 +++- 7 files changed, 43 insertions(+), 2 deletions(-)
Documentation/rust/arch-support.rst +1 -0
@@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. ============= ================ ============================================== Architecture Level of support Constraints ============= ================ ============================================== +``arm`` Maintained ARMv7 Little Endian only. ``arm64`` Maintained Little Endian only. ``loongarch`` Maintained \- ``riscv`` Maintained ``riscv64`` only.
arch/arm/Kconfig +1 -0
@@ -126,6 +126,7 @@ config ARM select MMU_GATHER_RCU_TABLE_FREE if SMP && ARM_LPAE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RSEQ + select HAVE_RUST if CPU_LITTLE_ENDIAN && CPU_32v7 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_UID16
arch/arm/Makefile +1 -0
@@ -150,6 +150,7 @@ endif KBUILD_CPPFLAGS +=$(cpp-y) KBUILD_CFLAGS +=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) -Wa,$(arch-y) $(tune-y) -include asm/unified.h -msoft-float +KBUILD_RUSTFLAGS += --target=arm-unknown-linux-gnueabi CHECKFLAGS += -D__arm__
rust/Makefile +9 -1
@@ -286,7 +286,8 @@ 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_arm64:= aarch64-linux-gnu +BINDGEN_TARGET_arm := arm-linux-gnueabi BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) # All warnings are inhibited since GCC builds are very experimental,
@@ -413,6 +414,13 @@ redirect-intrinsics = \ __muloti4 __multi3 \ __udivmodti4 __udivti3 __umodti3 +ifdef CONFIG_ARM + # Add eabi initrinsics for ARM 32-bit + redirect-intrinsics += \ + __aeabi_fadd __aeabi_fmul __aeabi_fcmpeq __aeabi_fcmple __aeabi_fcmplt __aeabi_fcmpun \ + __aeabi_dadd __aeabi_dmul __aeabi_dcmple __aeabi_dcmplt __aeabi_dcmpun \ + __aeabi_uldivmod +endif ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) # These intrinsics are defined for ARM64 and RISCV64 redirect-intrinsics += \
rust/bindgen_parameters +4 -0
@@ -24,3 +24,7 @@ # These functions use the `__preserve_most` calling convention, which neither bindgen # nor Rust currently understand, and which Clang currently declares to be unstable. --blocklist-function __list_.*_report + +# Depending on how the architecute defines ARCH_SLAB_MINALIGN, bindgen might generate a binding. +# Disable this here as there is a const that will always be generated in bindings_helper.c +--blocklist-item ARCH_SLAB_MINALIGN
rust/compiler_builtins.rs +24 -0
@@ -70,5 +70,29 @@ pub extern "C" fn $ident() { __umodti3, }); +#[cfg(target_arch = "arm" )] +define_panicking_intrinsics! ("`f32` should not be used" , { + __aeabi_fadd, + __aeabi_fmul, + __aeabi_fcmpeq, + __aeabi_fcmple, + __aeabi_fcmplt, + __aeabi_fcmpun, +}); + +#[cfg(target_arch = "arm" )] +define_panicking_intrinsics! ("`f64` should not be used" , { + __aeabi_dadd, + __aeabi_dmul, + __aeabi_dcmple, + __aeabi_dcmplt, + __aeabi_dcmpun, +}); + +#[cfg(target_arch = "arm" )] +define_panicking_intrinsics! ("`u64` division/modulo should not be used" , { + __aeabi_uldivmod, +}); +// NOTE: if you are adding a new intrinsic here, you should also add it to // `redirect-intrinsics` in `rust/Makefile`.
scripts/generate_rust_target.rs +3 -1
@@ -148,7 +148,9 @@ fn main() {let mut ts =TargetSpec ::new ();// `llvm-target`s are taken from `scripts/Makefile.clang`. -if cfg.has ("ARM64" ) { +if cfg.has ("ARM" ) { +panic! ("arm uses the builtin rustc target" ); + }else if cfg.has ("ARM64" ) {panic! ("arm64 uses the builtin rustc aarch64-unknown-none target" ); }else if cfg.has ("RISCV" ) {if cfg.has ("64BIT" ) {
Signature · 1 line
2.45.2
Quoted 3 lines · Christian Schrefl
This is based on the code by Sven Van Asbroeck from the original rust branch and inspired by the AArch version by Jamie Cunliffe.
Thanks for mentioning that!
(AArch64 perhaps?)
Quoted 2 lines
I have tested the rust samples and a custom simple MMIO module on on hardware (De1SoC FPGA + Arm A9 CPU).
Very nice to have tested it in real hardware, thanks!
(Duplicate "on on").
Quoted 1 line
+``arm`` Maintained ARMv7 Little Endian only.
How hard would it be to test and maintain other versions, eventually? I met Jamie recently, he may have some ideas here.
rust/Makefile bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \ · line 289
Quoted 2 lines
rust/Makefile +1
-1-BINDGEN_TARGET_arm64 := aarch64-linux-gnu +BINDGEN_TARGET_arm64:= aarch64-linux-gnu
Spurious change?
rust/bindgen_parameters line 29
Quoted 2 lines
rust/bindgen_parameters +2
-0+# Depending on how the architecute defines ARCH_SLAB_MINALIGN, bindgen might generate a binding. +# Disable this here as there is a const that will always be generated in bindings_helper.c
Typo in "architecute". Also, I guess you mean .h instead. Please use Markdown formatting for consistency with the rest of the file.
Quoted 1 line
+ panic!("arm uses the builtin rustc target");
Since ARM64 puts the name of the target in the message, it would be nice to do the same (or perhaps it can be removed from the ARM64 one otherwise).
Cheers,
Miguel
rust/Makefile bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \ · line 289
Quoted 8 lines · Christian Schrefl
rust/Makefile +1
-1@@ -286,7 +286,8 @@ 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_arm64:= aarch64-linux-gnu
That white space change is probably accidently.
rust/Makefile bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \ · line 293
Quoted 4 lines
rust/Makefile +1
-0+BINDGEN_TARGET_arm := arm-linux-gnueabi BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) # All warnings are inhibited since GCC builds are very experimental,
Groeten
Geert Stappers
Signature · 6 lines
Silence is hard to parse _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 9 lines · Miguel Ojeda
Quoted 3 lines · Christian Schrefl
This is based on the code by Sven Van Asbroeck from the original rust branch and inspired by the AArch version by Jamie Cunliffe.
Thanks for mentioning that!
(AArch64 perhaps?)
Ah yes I meant AArch64. Fixed it locally.
Quoted 6 lines
Quoted 2 lines
I have tested the rust samples and a custom simple MMIO module on on hardware (De1SoC FPGA + Arm A9 CPU).
Very nice to have tested it in real hardware, thanks!
(Duplicate "on on").
I fixed that locally, but forgot to run format-patch again, sorry!
Quoted 4 lines
Quoted 1 line
+``arm`` Maintained ARMv7 Little Endian only.
How hard would it be to test and maintain other versions, eventually? I met Jamie recently, he may have some ideas here.
I think it would just be setting the correct rust target, but I have no hardware to test it and I think its best to only do v7 for the initial support.
Quoted 4 lines
rust/Makefile bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \ · line 289
Quoted 2 lines
rust/Makefile +1
-1-BINDGEN_TARGET_arm64 := aarch64-linux-gnu +BINDGEN_TARGET_arm64:= aarch64-linux-gnuSpurious change?
I've changed that so the := aligns with the others, but I can remove that for v2 if you want
Quoted 5 lines
rust/bindgen_parameters line 29
Quoted 2 lines
rust/bindgen_parameters +2
-0+# Depending on how the architecute defines ARCH_SLAB_MINALIGN, bindgen might generate a binding. +# Disable this here as there is a const that will always be generated in bindings_helper.cTypo in "architecute". Also, I guess you mean
.hinstead. Please use Markdown formatting for consistency with the rest of the file.
Fixed.
Quoted 5 lines
Quoted 1 line
+ panic!("arm uses the builtin rustc target");
Since ARM64 puts the name of the target in the message, it would be nice to do the same (or perhaps it can be removed from the ARM64 one otherwise).
I can add the target here but then the message would have to depend on the sub architecture if we support v6 in the future.
Quoted 2 lines
Cheers,
Miguel
Documentation/rust/arch-support.rst support corresponds to ``S`` values in the ``MAINTAINERS`` file. · line 18
Quoted 7 lines
Documentation/rust/arch-support.rst +1
-0@@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. ============= ================ ============================================== Architecture Level of support Constraints ============= ================ ============================================== +``arm`` Maintained ARMv7 Little Endian only.
Might be a FAQ, but what does Maintained mean here? Should you be adding yourself to the RUST entry in MAINTAINERS? You are Maintaining Rust on ARMv7 and so should be given credit/responsibility for that in MAINTAINERS?
Andrew
Quoted 4 lines · Andrew Lunn
Quoted 4 lines
Documentation/rust/arch-support.rst +0
-0@@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. ============= ================ ==============================================
Quoted 8 lines
Documentation/rust/arch-support.rst support corresponds to ``S`` values in the ``MAINTAINERS`` file. · line 18
Quoted 3 lines
Documentation/rust/arch-support.rst +1
-0Architecture Level of support Constraints ============= ================ ============================================== +``arm`` Maintained ARMv7 Little Endian only.Might be a FAQ, but what does Maintained mean here? Should you be adding yourself to the RUST entry in
MAINTAINERS? You are Maintaining Rust on ARMv7 and so should be given credit/responsibility for that inMAINTAINERS?
From my side I can/will take a look if there are issues/patches related to this, but I can't be sure how fast I'll be able to respond and I don't feel qualified to handle larger or more complicated issues myself.
But there isn't a MAINTAINERS entry depending on the architecture, so I'm not sure who will be responsible for this.
Miguel how is the support handled for the other architectures?
Quoted 2 lines · Christian Schrefl
Miguel how is the support handled for the other architectures?
The arch maintainers are the ones taking the patches through their trees and so on (with the initial exception of x86).
Of course, if you want to contribute to that, that is great. If an entry is wanted/needed, then a possibility is a sub-entry to the architecture.
Cheers,
Miguel