arm: rust: Enable Rust support for ARMv7
Subsystems (3)
PATCH v3 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. For now those are implemented with define_panicking_intrinsics!.
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 hardware (De1SoC FPGA + Arm A9 CPU).
---
I've updated my Rust ARMv7 patches.
Not much has changed since v2 but I want to send it out again before sending it to Russell's ARM patch tracker, since I should hopefully have more time to work on this again.
I'm not sure how exactly the patch tracker works, I assume I should just sent it to the tracker once all review comments are addressed and it has sat in the mailing list for some time?
I've kept the Tags from v2 since nothing signifficant has changed,
I hope thats fine with everyone.
---
Changes in v3:
- Rebased ontop of v6.13
Removing the rust/bindgen_parameters changes which are
already in 732cd686cdd6 (rust: fix ARCH_SLAB_MINALIGN multiple definition error)
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Removed unrelated whitespace change.
- Added target name to panic message in scripts/generate_rust_target.rs.
- Fixed the comment in rust/bindgen_parameters.
- Link to v1: https://lore.kernel.org/r/[email protected]
--- Documentation/rust/arch-support.rst | 1 + arch/arm/Kconfig | 1 + arch/arm/Makefile | 1 + rust/Makefile | 8 ++++++++ rust/compiler_builtins.rs | 24 ++++++++++++++++++++++++ scripts/generate_rust_target.rs | 4 +++- 6 files changed, 38 insertions(+), 1 deletion(-)
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`` and LLVM/Clang only.
arch/arm/Kconfig +1 -0
@@ -130,6 +130,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 +8 -0
@@ -243,6 +243,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_arm := arm-linux-gnueabi BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH)) # All warnings are inhibited since GCC builds are very experimental,
@@ -394,6 +395,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/compiler_builtins.rs +24 -0
@@ -73,5 +73,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
@@ -172,7 +172,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" ) {
---
base-commit: ffd294d346d185b70e28b1a28abe367bbfe53c04
change-id: 20250123-rfl-arm32-f93334146367
Best regards,
Signature · 1 line
Christian Schrefl <[email protected]>
Quoted 25 lines · Christian Schrefl
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. For now those are implemented withdefine_panicking_intrinsics!.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 hardware (De1SoC FPGA + Arm A9 CPU).
Tested-by Rudraksha Gupta <[email protected]>Reviewed-by Alice Ryhl <[email protected]>Acked-by Miguel Ojeda <[email protected]>Tested-by Miguel Ojeda <[email protected]>Acked-by Ard Biesheuvel <[email protected]>Signed-off-by Christian Schrefl <[email protected]>---
I've updated my Rust ARMv7 patches.
Not much has changed since v2 but I want to send it out again before sending it to Russell's ARM patch tracker, since I should hopefully have more time to work on this again.
Quoted 7 lines
I'm not sure how exactly the patch tracker works, I assume I should just sent it to the tracker once all review comments are addressed and it has sat in the mailing list for some time?
I've kept the Tags from v2 since nothing signifficant has changed, I hope thats fine with everyone.
---
I have now submitted this as:
https://www.armlinux.org.uk/developer/patches/viewpatch.php?id=9441/1
I hope I've done that correctly.
Cheers
Christian
Quoted 6 lines · Christian Schrefl
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. For now those are implemented withdefine_panicking_intrinsics!.
I see you are doing this part the same as the other architectures, but I don't see why it's done like this in the first place:
In C code, we really want to get a link failure rather than a runtime error in order to catch those bugs as early as possible and fix them before even trying to run the kernel. Is there a reason this doesn't work in rust, or is there a plan to change this later when the existing callers of those functions have been fixed?
202397be76d8037b531b34dee16c7dfcfd0124ef..3375c91e698c024f95a85682f5a91d9815c355e5
arch/arm/Kconfig config ARM · line 133
Quoted 8 lines
100644
arch/arm/Kconfig +1
-0@@ -130,6 +130,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
The ARMv7 dependency makes sense, but I think it needs
be disabled on combined v6/v7 kernels, like (CPU_V7 && !CPU_V6 && !CPU_V6K).
ARnd
Quoted 11 lines · Arnd Bergmann
Quoted 6 lines · Christian Schrefl
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. For now those are implemented withdefine_panicking_intrinsics!.I see you are doing this part the same as the other architectures, but I don't see why it's done like this in the first place:
Quoted 6 lines
In C code, we really want to get a link failure rather than a runtime error in order to catch those bugs as early as possible and fix them before even trying to run the kernel. Is there a reason this doesn't work in rust, or is there a plan to change this later when the existing callers of those functions have been fixed?
I agree having a linker error instead of a runtime panic would be ideal, but it is currently impossible to build without these intrinsics.
To fix this Rust would have to provide a way to build the core library without float support. I don't know if there is a plan already to allow this.
Quoted 13 lines
202397be76d8037b531b34dee16c7dfcfd0124ef..3375c91e698c024f95a85682f5a91d9815c355e5arch/arm/Kconfig config ARM · line 133
Quoted 8 lines
100644
arch/arm/Kconfig +1
-0@@ -130,6 +130,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_32v7The ARMv7 dependency makes sense, but I think it needs
be disabled on combined v6/v7 kernels, like (CPU_V7&& !CPU_V6 && !CPU_V6K).
That might be correct, I don't know much about the build system for the kernel. I've tried it and it still builds with this change.
Also it should probably be relatively easy to support armv6 as well.
Cheers
Christian
Quoted 3 lines
To fix this Rust would have to provide a way to build the core library without float support. I don't know if there is a plan already to allow this.
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
Andrew
Quoted 11 lines · Andrew Lunn
Quoted 3 lines
To fix this Rust would have to provide a way to build the core library without float support. I don't know if there is a plan already to allow this.
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
After checking again, it seems the float intrinsics are actually not needed anymore at least for my config. Only __aeabi_uldivmod is still required for parse_u64_into since [0] allows disabling float formatting.
Link error without the __aeabi_uldivmod symbol defined:
ld.lld: error: undefined symbol: __aeabi_uldivmod
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
referenced by num.rs:580 (
/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:580)rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.areferenced 34 more times
did you mean:__aeabi_uidivmod
defined in:vmlinux.a(arch/arm/lib/lib1funcs.o)
Not sure if we should just implement __aeabi_uldivmod, keep the panicking intrinsic for it or somehow fix it in upstream Rust?
Miguel do you know how this is best handled?
Cheers
Christian
Quoted 10 lines · Christian Schrefl
Quoted 9 lines · Andrew Lunn
Quoted 3 lines
To fix this Rust would have to provide a way to build the core library without float support. I don't know if there is a plan already to allow this.
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
Quoted 5 lines
Quoted 2 lines
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
After checking again, it seems the float intrinsics are actually not needed anymore at least for my config.
Ah, nice! If this is true for all architectures using the current rust compiler, it would be great to remove the FP stubs entirely and have link errors instead of panicking, to make it consistent with C.
Quoted 16 lines
Only
__aeabi_uldivmodis still
required forparse_u64_intosince [0] allows disabling float formatting.Link error without the
__aeabi_uldivmodsymbol defined:ld.lld: error: undefined symbol:
__aeabi_uldivmodQuoted 9 lines
Quoted 9 lines
Quoted 9 lines
referenced by num.rs:580 (
/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:580)rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.areferenced 34 more times
did you mean:__aeabi_uidivmod
defined in:vmlinux.a(arch/arm/lib/lib1funcs.o)
Quoted 2 lines
Not sure if we should just implement
__aeabi_uldivmod, keep the panicking intrinsic for it or somehow fix it in upstream Rust?
The 64-bit division is particularly easy to introduce by accident on 32-bit architectures, so ending up in a panic here is clearly a problem. From the message above it appears that there is only a single calling function (parse_u64_into()) in the rust library, so I wonder if it might be sufficient to split that out into another object file that then doesn't need to get linked into the kernel, or for the kernel to override it with an implementation that does not rely on __aeabi_uldivmod() but calls __do_div64() instead.
Since parse_u64_into seems to be a parsing function that is expected to be slow, it should be acceptable to call __do_div64() here, while we still prevent calling __aeabi_uldivmod() from kernel source code.
Note that on earlier ARMv7 (Cortex-A8, A9), even a 32-bit division is implemented through an expensive software loop. Later cores (Cortex-A7, A15, A17) have native 32-bit division instructions but still no 64-bit ones.
Arnd
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · Christian Schrefl
Quoted 11 lines · Andrew Lunn
Quoted 3 lines
To fix this Rust would have to provide a way to build the core library without float support. I don't know if there is a plan already to allow this.
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
Quoted 7 lines
Quoted 2 lines
After checking again, it seems the float intrinsics are actually not needed anymore at least for my config.
Ah, nice! If this is true for all architectures using the current rust compiler, it would be great to remove the FP stubs entirely and have link errors instead of panicking, to make it consistent with C.
After a quick test it seems that (most?) intrinsics are not needed anymore on x86, but not sure if that's valid for all supported rust versions and config options.
Quoted 20 lines
Quoted 17 lines
Only
__aeabi_uldivmodis still
required forparse_u64_intosince [0] allows disabling float formatting.Link error without the
__aeabi_uldivmodsymbol defined:ld.lld: error: undefined symbol:
__aeabi_uldivmodQuoted 9 lines
Quoted 9 lines
Quoted 9 lines
referenced by num.rs:580 (
/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:580)rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.areferenced 34 more times
did you mean:__aeabi_uidivmod
defined in:vmlinux.a(arch/arm/lib/lib1funcs.o)Quoted 2 lines
Not sure if we should just implement
__aeabi_uldivmod, keep the panicking intrinsic for it or somehow fix it in upstream Rust?
Quoted 9 lines
The 64-bit division is particularly easy to introduce by accident on 32-bit architectures, so ending up in a panic here is clearly a problem. From the message above it appears that there is only a single calling function (
parse_u64_into()) in the rust library, so I wonder if it might be sufficient to split that out into another object file that then doesn't need to get linked into the kernel, or for the kernel to override it with an implementation that does not rely on__aeabi_uldivmod()but calls__do_div64()instead.
I don't think that we can split it into a different object file or do some weird redirect in Rust itself.
Quoted 4 lines
Since
parse_u64_intoseems to be a parsing function that is expected to be slow, it should be acceptable to call__do_div64()here, while we still prevent calling__aeabi_uldivmod()from kernel source code.
parse_u64_into seems to be used by Formatting for u128 and i128 so it would be fine to disable these with a flag. However __aeabi_uldivmod is used by some other parts of core as well, like logarithm calculation for 64 and 128 bit integers, not sure what else uses is. I would guess its fine for these to be slow.
Can someone help me figure out how to get ld.lld to print every usage instead of just the first three?
Not sure how easy it would be to disable these but it would probably require some effort and would probably be pretty hacky, so not sure if Rust would accept these.
Quoted 5 lines
Note that on earlier ARMv7 (Cortex-A8, A9), even a 32-bit division is implemented through an expensive software loop. Later cores (Cortex-A7, A15, A17) have native 32-bit division instructions but still no 64-bit ones.
I would assume that a software implementation is fine.
Cheers
Christian
Quoted 18 lines · Christian Schrefl
Quoted 17 lines · Arnd Bergmann
Quoted 15 lines · Christian Schrefl
Quoted 11 lines · Andrew Lunn
Quoted 3 lines
To fix this Rust would have to provide a way to build the core library without float support. I don't know if there is a plan already to allow this.
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
After checking again, it seems the float intrinsics are actually not needed anymore at least for my config.
Quoted 8 lines
Quoted 4 lines
Ah, nice! If this is true for all architectures using the current rust compiler, it would be great to remove the FP stubs entirely and have link errors instead of panicking, to make it consistent with C.
After a quick test it seems that (most?) intrinsics are not needed anymore on x86, but not sure if that's valid for all supported rust versions and config options.
On Rust 1.84.1 only __udivti3 is requied, with 1.78 most of the intrinsics seem to still be required.
Cheers
Christian
Quoted 56 lines · Arnd Bergmann
Quoted 10 lines · Christian Schrefl
Quoted 9 lines · Andrew Lunn
Quoted 3 lines
To fix this Rust would have to provide a way to build the core library without float support. I don't know if there is a plan already to allow this.
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
Quoted 5 lines
Quoted 2 lines
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
After checking again, it seems the float intrinsics are actually not needed anymore at least for my config.
Ah, nice! If this is true for all architectures using the current rust compiler, it would be great to remove the FP stubs entirely and have link errors instead of panicking, to make it consistent with C.
Quoted 16 lines
Only
__aeabi_uldivmodis still
required forparse_u64_intosince [0] allows disabling float formatting.Link error without the
__aeabi_uldivmodsymbol defined:ld.lld: error: undefined symbol:
__aeabi_uldivmodQuoted 9 lines
Quoted 9 lines
Quoted 9 lines
referenced by num.rs:580 (
/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:580)rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.areferenced 34 more times
did you mean:__aeabi_uidivmod
defined in:vmlinux.a(arch/arm/lib/lib1funcs.o)Quoted 2 lines
Not sure if we should just implement
__aeabi_uldivmod, keep the panicking intrinsic for it or somehow fix it in upstream Rust?The 64-bit division is particularly easy to introduce by accident on 32-bit architectures, so ending up in a panic here is clearly a problem. From the message above it appears that there is only a single calling function (
parse_u64_into()) in the rust library, so I wonder if it might be sufficient to split that out into another object file that then doesn't need to get linked into the kernel, or for the kernel to override it with an implementation that does not rely on__aeabi_uldivmod()but calls__do_div64()instead.Since
parse_u64_intoseems to be a parsing function that is expected to be slow, it should be acceptable to call__do_div64()here, while we still prevent calling__aeabi_uldivmod()from kernel source code.
Quoted 4 lines
Note that on earlier ARMv7 (Cortex-A8, A9), even a 32-bit division is implemented through an expensive software loop. Later cores (Cortex-A7, A15, A17) have native 32-bit division instructions but still no 64-bit ones.
It seems be possible to implement __aeabi_uldivmod like this [0]:
#[naked]
#[cfg(target_arch = "arm")]
#[export_name = "__rust__aeabi_uldivmod"]
pub unsafe extern "C" fn __aeabi_uldivmod() {
unsafe {
core::arch::naked_asm!(
"push {{r4, lr}}",
"sub sp, sp, #16",
"add r4, sp, #8",
"str r4, [sp]",
"bl __udivmoddi4",
"ldr r2, [sp, #8]",
"ldr r3, [sp, #12]",
"add sp, sp, #16",
"pop {{r4, pc}}",
);
}
}However that requires the naked_functions unstable feature. Or it should be possible to just implement in a asm file.
I think it would be very difficult to entirely build core without needing __aeabi_uldivmod.
Christian
Quoted 10 lines · Christian Schrefl
Quoted 9 lines · Andrew Lunn
Quoted 3 lines
To fix this Rust would have to provide a way to build the core library without float support. I don't know if there is a plan already to allow this.
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
Quoted 6 lines
Quoted 2 lines
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
After checking again, it seems the float intrinsics are actually not needed anymore at least for my config. Only
__aeabi_uldivmodis still required forparse_u64_intosince [0] allows disabling float formatting.
Seems like Rust 1.78 still needs at least __aeabi_fcmpeq __aeabi_fcmpun __aeabi_dcmpun and __aeabi_uldivmod.
Quoted 23 lines
Link error without the
__aeabi_uldivmodsymbol defined:ld.lld: error: undefined symbol:
__aeabi_uldivmodQuoted 9 lines
Quoted 9 lines
Quoted 9 lines
referenced by num.rs:580 (
/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:580)rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.a referenced by num.rs:589 (/home/chrisi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:589) rust/core.o:(core::fmt::num::parse_u64_into::<39>) in archive vmlinux.areferenced 34 more times
did you mean:__aeabi_uidivmod
defined in:vmlinux.a(arch/arm/lib/lib1funcs.o)Not sure if we should just implement
__aeabi_uldivmod, keep the panicking intrinsic for it or somehow fix it in upstream Rust?Miguel do you know how this is best handled?
Cheers
Christian
Quoted 8 lines · Andrew Lunn
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
Yeah, it has been discussed, including in the last couple weeks in the Rust Zulip due to the upcoming move to the aarch64 softfloat target (the disallowing of disabling neon in the hardfloat one).
Ideally, I think upstream Rust could perhaps give us a way to do something like -mgeneral-regs-only or -march=...+nofp (in the form GCC does it, i.e. a hard error if one even tries to use the floating point types even within a function implementation, not just in interfaces like in Clang), i.e. a way to avoid unintended use of floating point facilities:
https://godbolt.org/z/o1E5nrrzc
Currently it is unclear what form that could take (e.g. whether a -nofloat target could be possible, "disabling" the f* types, just Clippy...).
Cc'ing Catalin in case he wants to be in the loop, since I discussed it with him recently.
Cheers,
Miguel
Alice Ryhl
reviewerQuoted 22 lines · Miguel Ojeda
Quoted 8 lines · Andrew Lunn
Floating point is banned within the kernel, except for in very narrow conditions, because the floating point registers are lazy saved on context switch. If the kernel uses the floating point registers, you can break user space in bad ways.
I expect this has been discussed, since it is well known kernel restriction. Maybe go see what happened to that discussion within RfL?
Yeah, it has been discussed, including in the last couple weeks in the Rust Zulip due to the upcoming move to the aarch64
softfloattarget (the disallowing of disablingneonin the hardfloat one).Ideally, I think upstream Rust could perhaps give us a way to do something like
-mgeneral-regs-onlyor-march=...+nofp(in the form GCC does it, i.e. a hard error if one even tries to use the floating point types even within a function implementation, not just in interfaces like in Clang), i.e. a way to avoid unintended use of floating point facilities:
Quoted 5 lines
https://godbolt.org/z/o1E5nrrzcCurrently it is unclear what form that could take (e.g. whether a
-nofloattarget could be possible, "disabling" thef*types, just Clippy...).
Seems like we already have a warning for it:
warning: floating-point arithmetic detected
--> /home/aliceryhl/rust-for-linux/rust/kernel/lib.rs:89:5
| 89 | a + b | ^^^^^ |
= help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
= note: requested on the command line with -W clippy::float-arithmetic
Quoted 5 lines
Cc'ing Catalin in case he wants to be in the loop, since I discussed it with him recently.
Cheers,
Miguel
Quoted 2 lines · Alice Ryhl
Seems like we already have a warning for it:
Yeah, that is the "just Clippy" part, but other forms could perhaps do more, e.g. imply no_fp_fmt_parse (in a stable way) and remove other bits that may not be needed.
Cheers,
Miguel
On Fri, Jan 31, 2025, at 16:34, Christian Schrefl wrote:202397be76d8037b531b34dee16c7dfcfd0124ef..3375c91e698c024f95a85682f5a91d9815c355e5
Quoted 12 lines
Quoted 11 lines
arch/arm/Kconfig config ARM · line 133
Quoted 8 lines
100644
arch/arm/Kconfig +1
-0@@ -130,6 +130,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_32v7The ARMv7 dependency makes sense, but I think it needs
be disabled on combined v6/v7 kernels, like (CPU_V7&& !CPU_V6 && !CPU_V6K).
Quoted 6 lines
That might be correct, I don't know much about the build system for the kernel. I've tried it and it still builds with this change.
Also it should probably be relatively easy to support armv6 as well.
ARMv6K should be trivial to support, as it contains the same set of barriers and atomics as ARMv7, the main difference being the lack of Thumb2 mode. The plain ARMv6 may be a little harder to get right since that needs special barriers and can only do 32-bit atomics but not 8/16/64.
As there is only really one relevant machine left with the original ARMv6 (Nokia N8x0), we already plan to drop that in a year, and I wouldn't put too much work into supporting it. ARMv5 and earlier will stay around for a while longer, but are getting rare enough that you probably don't need to worry about those either.
Arnd
Hi Christian,
thanks for your patch!
Sorry for being late to the show. I missed this very nice patch that was actually on my personal TODO but I have to much to do and also I'm not smart with Rust, but I'm a big supporter.
Quoted 1 line · Christian Schrefl
+ select
HAVE_RUSTifCPU_LITTLE_ENDIAN&&CPU_32v7
Nothing in the patch series really explains this restriction, so it should be in the commit message. Arnd mentions some atomics etc, but we really need to know exactly why this is in the patch.
I'm a bit surprised by this since the rustc LLVM backend nowadays support all old ARM ISAs. I would have expected:
select HAVE_RUST if AEABI
Ideally this should work on any ARM core, but it's fair to require EABI.
The big reason: I think we want to be able to use Rust in kernel core components sooner than ARMv5 goes away from the kernel.
If testing is the only issue, I can provide testing on ARMv4, v5, ARMv5 BE etc, just tell me how to test. (But I guess it's more than that...)
Yours,
Linus Walleij
Hi Linus,
Quoted 8 lines · Linus Walleij
Hi Christian,
thanks for your patch!
Sorry for being late to the show. I missed this very nice patch that was actually on my personal TODO but I have to much to do and also I'm not smart with Rust, but I'm a big supporter.
Quoted 8 lines
Quoted 1 line · Christian Schrefl
+ select
HAVE_RUSTifCPU_LITTLE_ENDIAN&&CPU_32v7Nothing in the patch series really explains this restriction, so it should be in the commit message. Arnd mentions some atomics etc, but we really need to know exactly why this is in the patch.
This should probably work with armv6 targets, for v5 or v4 Targets a different target would have to be specified in the KBUILD_RUSTFLAGS.
Rust also has some big endian arm targets.
Quoted 9 lines
I'm a bit surprised by this since the rustc LLVM backend nowadays support all old ARM ISAs. I would have expected:
select
HAVE_RUSTif AEABIIdeally this should work on any ARM core, but it's fair to require EABI.
Quoted 6 lines
The big reason: I think we want to be able to use Rust in kernel core components sooner than ARMv5 goes away from the kernel.
If testing is the only issue, I can provide testing on ARMv4, v5, ARMv5 BE etc, just tell me how to test. (But I guess it's more than that...)
The main reason that I only did this for ARMv7 was that I'm not very familiar with older arm versions and that I only have v7 hardware for testing.
I currently don't have much time to work on this, but when/if it works in qemu I'll send you a message to test it on HW.
Cheers
Christian
Tested with Beaglebone back with following configs:
# zcat /proc/config.gz | grep RUST CONFIG_RUSTC_VERSION=108600 CONFIG_RUST_IS_AVAILABLE=y CONFIG_RUSTC_LLVM_VERSION=190107 CONFIG_RUST=y CONFIG_RUSTC_VERSION_TEXT="rustc 1.86.0 (05f9846f8 2025-03-31)" CONFIG_HAVE_RUST=y # CONFIG_RUST_FW_LOADER_ABSTRACTIONS is not set CONFIG_TRUSTED_FOUNDATIONS=y # CONFIG_BLK_DEV_RUST_NULL is not set # CONFIG_RUST_PHYLIB_ABSTRACTIONS is not set # CONFIG_HID_THRUSTMASTER is not set # CONFIG_TRUSTED_KEYS is not set CONFIG_SYSTEM_TRUSTED_KEYRING=y CONFIG_SYSTEM_TRUSTED_KEYS="" # CONFIG_SECONDARY_TRUSTED_KEYRING is not set CONFIG_RUST_DEBUG_ASSERTIONS=y CONFIG_RUST_OVERFLOW_CHECKS=y CONFIG_RUST_BUILD_ASSERT_ALLOW=y
Quoted 2 lines · Manish Shakya
CONFIG_RUST_DEBUG_ASSERTIONS=y
This is great for testing...
Quoted 1 line
CONFIG_RUST_BUILD_ASSERT_ALLOW=y
...but this one should really be disabled (both for testing and for production use).
RUST_BUILD_ASSERT_ALLOW is really only there as a worst case workaround (escape hatch) that nobody should ever hit, hopefully.
If you ever find you need to set it, then please report it -- thanks!
Cheers,
Miguel
Quoted 6 lines · Miguel Ojeda
Quoted 2 lines · Manish Shakya
CONFIG_RUST_DEBUG_ASSERTIONS=yThis is great for testing...
Quoted 7 lines
Quoted 1 line
CONFIG_RUST_BUILD_ASSERT_ALLOW=y...but this one should really be disabled (both for testing and for production use).
RUST_BUILD_ASSERT_ALLOWis really only there as a worst case workaround (escape hatch) that nobody should ever hit, hopefully.
Maybe we should rename it to something more discouraging then. Eg CONFIG_RUST_BUILD_ASSERT_DISABLE.
---
Cheers,
Benno
Quoted 3 lines · Benno Lossin
Maybe we should rename it to something more discouraging then. Eg
CONFIG_RUST_BUILD_ASSERT_DISABLE.
To clarify: it doesn't disable them, but rather converts them to runtime checks.
Perhaps it should be _ESCAPE_HATCH or _KEEP_DISABLED or _AT_RUNTIME or similar -- though changing it now may be even more confusing.
The description already mentions it should not happen, and that is an escape hatch, and the recommendation and the default is N. So if someone enables it in production, they really went out of their way to do so, and even then they are protected by the panics (that they shouldn't hit at all).
Eventually, we may just want to remove it entirely if we never see a case failing and/or if we get proper support for those from upstream Rust for this.
Cheers,
Miguel
Quoted 25 lines · Linus Walleij
Hi Christian,
thanks for your patch!
Sorry for being late to the show. I missed this very nice patch that was actually on my personal TODO but I have to much to do and also I'm not smart with Rust, but I'm a big supporter.
Quoted 1 line · Christian Schrefl
+ select
HAVE_RUSTifCPU_LITTLE_ENDIAN&&CPU_32v7Nothing in the patch series really explains this restriction, so it should be in the commit message. Arnd mentions some atomics etc, but we really need to know exactly why this is in the patch.
I'm a bit surprised by this since the rustc LLVM backend nowadays support all old ARM ISAs. I would have expected:
select
HAVE_RUSTif AEABIIdeally this should work on any ARM core, but it's fair to require EABI.
Quoted 6 lines
The big reason: I think we want to be able to use Rust in kernel core components sooner than ARMv5 goes away from the kernel.
If testing is the only issue, I can provide testing on ARMv4, v5, ARMv5 BE etc, just tell me how to test. (But I guess it's more than that...)
I've done a quick test on armv5 with the armv5te-none-eabi rust target and it needs some atomics (AtomicU64 type and for AtomicBool the compare_exchange and compare_exchange functions) to build:
```
RUSTC L rust/kernel.o
error[E0432]: unresolved import `core::sync::atomic::AtomicU64`
--> rust/kernel/block/mq/operations.rs:15:33
|
15 | use core::{marker::PhantomData, sync::atomic::AtomicU64, sync::atomic::Ordering};
| ^^^^^^^^^^^^^^---------
| | |
| | help: a similar name exists in the module: `AtomicU8`
| no `AtomicU64` in `sync::atomic`
error[E0432]: unresolved import `core::sync::atomic::AtomicU64`
--> rust/kernel/block/mq/request.rs:16:20
|
16 | sync::atomic::{AtomicU64, Ordering},
| ^^^^^^^^^
| |
| no `AtomicU64` in `sync::atomic`
| help: a similar name exists in the module: `AtomicU8`
error[E0599]: no method named `compare_exchange` found for struct `AtomicBool` in the current scope
--> rust/kernel/list/arc.rs:518:14
|
517 | / self.inner
518 | | .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
| | -^^^^^^^^^^^^^^^^ method not found in `AtomicBool`
| |_____________|
|
error[E0599]: no method named `swap` found for struct `AtomicBool` in the current scope
--> rust/kernel/revocable.rs:130:30
|
130 | if self.is_available.swap(false, Ordering::Relaxed) {
| ^^^^ method not found in `AtomicBool`
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
```When gating all the modules that need these linking fails because of missing __eabi__* intrinsics:
``` ld.lld: error: undefined symbol: __aeabi_memcpy >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::str::RawFormatter as core::fmt::Write>::write_char) in archive vmlinux.a >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::str::Formatter as core::fmt::Write>::write_char) in archive vmlinux.a >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::page::Page>::read_raw) in archive vmlinux.a >>> referenced 29 more times ld.lld: error: undefined symbol: __aeabi_memclr8 >>> referenced by bindings.4cab29b7397d35cb-cgu.0 >>> rust/bindings.o:(<bindings::bindings_raw::module as core::default::Default>::default) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::module as core::default::Default>::default) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::thread_info as core::default::Default>::default) in archive vmlinux.a >>> referenced 86 more times ld.lld: error: undefined symbol: __aeabi_memclr4 >>> referenced by bindings.4cab29b7397d35cb-cgu.0 >>> rust/bindings.o:(<bindings::bindings_raw::fp_hard_struct as core::default::Default>::default) in archive vmlinux.a >>> referenced by bindings.4cab29b7397d35cb-cgu.0 >>> rust/bindings.o:(<bindings::bindings_raw::iwmmxt_struct as core::default::Default>::default) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::fp_soft_struct as core::default::Default>::default) in archive vmlinux.a >>> referenced 95 more times ld.lld: error: undefined symbol: __aeabi_memset >>> referenced by core.64aa0a46a0f8f964-cgu.0 >>> rust/core.o:(<core::num::fmt::Part>::write) in archive vmlinux.a >>> referenced by core.64aa0a46a0f8f964-cgu.0 >>> rust/core.o:(core::fmt::num::fmt_u128) in archive vmlinux.a ld.lld: error: undefined symbol: __aeabi_memcpy4 >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::of::DeviceId>::new) in archive vmlinux.a >>> referenced by core.64aa0a46a0f8f964-cgu.0 >>> rust/core.o:(<core::char::ToLowercase as core::fmt::Display>::fmt) in archive vmlinux.a ld.lld: error: undefined symbol: __aeabi_memclr >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::page::Page>::fill_zero_raw) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::__kernel_sockaddr_storage__bindgen_ty_1__bindgen_ty_1 as core::default::Default>::default) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::sockaddr__bindgen_ty_1 as core::default::Default>::default) in archive vmlinux.a >>> referenced 16 more times ld.lld: error: undefined symbol: __aeabi_memset4 >>> referenced by core.64aa0a46a0f8f964-cgu.0 >>> rust/core.o:(core::fmt::num::fmt_u128) in archive vmlinux.a make[2]: *** [scripts/Makefile.vmlinux:91: vmlinux] Error 1 make[1]: *** [/home/chrisi/Documents/code/rust-arm32/Makefile:1242: vmlinux] Error 2 make: *** [Makefile:248: __sub-make] Error 2 ```
With define_panicking_intrinsics! for these an empty sample works (not yet tested as module), but even printing a non formatted string (with pr_info!("Hi rust\n");) fails because rust tries to use __adddf3:
``
Hardware name: ARM-Versatile (Device Tree Support) PC is at __rust__adddf3+0x0/0x4 LR is at _RNvXsg_NtCs3KHxpmQFgFb_6kernel3strNtB5_12RawFormatterNtNtCs8DPF7ip8WBQ_4core3fmt5Write9write_str+0x34/0x40 pc : [<c028950c>] lr : [<c028b5ec>] psr: 20000193
sp : c8811a78 ip : c8811ae8 fp : c058e44e
r10: 00000000 r9 : c058e450 r8 : c07ac118
r7 : 00000000 r6 : 00000000 r5 : c07ac120 r4 : c8811adc r3 : c07ac120 r2 : 00000008 r1 : c0667f60 r0 : c07ac118
Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment none ```
I'm not sure how to proceed from here and I most likely won't find time to continue working on this anytime soon.
My very hacky changes are available on Github at:
https://github.com/onestacked/linux/commit/edddb388267ab1afe5255bea4d84f96cbdb37978
Cheers,
Christian
Quoted 25 lines · Linus Walleij
Hi Christian,
thanks for your patch!
Sorry for being late to the show. I missed this very nice patch that was actually on my personal TODO but I have to much to do and also I'm not smart with Rust, but I'm a big supporter.
Quoted 1 line · Christian Schrefl
+ select
HAVE_RUSTifCPU_LITTLE_ENDIAN&&CPU_32v7Nothing in the patch series really explains this restriction, so it should be in the commit message. Arnd mentions some atomics etc, but we really need to know exactly why this is in the patch.
I'm a bit surprised by this since the rustc LLVM backend nowadays support all old ARM ISAs. I would have expected:
select
HAVE_RUSTif AEABIIdeally this should work on any ARM core, but it's fair to require EABI.
Quoted 6 lines
The big reason: I think we want to be able to use Rust in kernel core components sooner than ARMv5 goes away from the kernel.
If testing is the only issue, I can provide testing on ARMv4, v5, ARMv5 BE etc, just tell me how to test. (But I guess it's more than that...)
I've done a quick test on armv5 with the armv5te-none-eabi rust target and it needs some atomics (AtomicU64 type and for AtomicBool the compare_exchange and compare_exchange functions) to build:
```
RUSTC L rust/kernel.o
error[E0432]: unresolved import `core::sync::atomic::AtomicU64`
--> rust/kernel/block/mq/operations.rs:15:33
|
15 | use core::{marker::PhantomData, sync::atomic::AtomicU64, sync::atomic::Ordering};
| ^^^^^^^^^^^^^^---------
| | |
| | help: a similar name exists in the module: `AtomicU8`
| no `AtomicU64` in `sync::atomic`
error[E0432]: unresolved import `core::sync::atomic::AtomicU64`
--> rust/kernel/block/mq/request.rs:16:20
|
16 | sync::atomic::{AtomicU64, Ordering},
| ^^^^^^^^^
| |
| no `AtomicU64` in `sync::atomic`
| help: a similar name exists in the module: `AtomicU8`
error[E0599]: no method named `compare_exchange` found for struct `AtomicBool` in the current scope
--> rust/kernel/list/arc.rs:518:14
|
517 | / self.inner
518 | | .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
| | -^^^^^^^^^^^^^^^^ method not found in `AtomicBool`
| |_____________|
|
error[E0599]: no method named `swap` found for struct `AtomicBool` in the current scope
--> rust/kernel/revocable.rs:130:30
|
130 | if self.is_available.swap(false, Ordering::Relaxed) {
| ^^^^ method not found in `AtomicBool`
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
```When gating all the modules that need these linking fails because of missing __eabi__* intrinsics:
``` ld.lld: error: undefined symbol: __aeabi_memcpy >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::str::RawFormatter as core::fmt::Write>::write_char) in archive vmlinux.a >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::str::Formatter as core::fmt::Write>::write_char) in archive vmlinux.a >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::page::Page>::read_raw) in archive vmlinux.a >>> referenced 29 more times ld.lld: error: undefined symbol: __aeabi_memclr8 >>> referenced by bindings.4cab29b7397d35cb-cgu.0 >>> rust/bindings.o:(<bindings::bindings_raw::module as core::default::Default>::default) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::module as core::default::Default>::default) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::thread_info as core::default::Default>::default) in archive vmlinux.a >>> referenced 86 more times ld.lld: error: undefined symbol: __aeabi_memclr4 >>> referenced by bindings.4cab29b7397d35cb-cgu.0 >>> rust/bindings.o:(<bindings::bindings_raw::fp_hard_struct as core::default::Default>::default) in archive vmlinux.a >>> referenced by bindings.4cab29b7397d35cb-cgu.0 >>> rust/bindings.o:(<bindings::bindings_raw::iwmmxt_struct as core::default::Default>::default) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::fp_soft_struct as core::default::Default>::default) in archive vmlinux.a >>> referenced 95 more times ld.lld: error: undefined symbol: __aeabi_memset >>> referenced by core.64aa0a46a0f8f964-cgu.0 >>> rust/core.o:(<core::num::fmt::Part>::write) in archive vmlinux.a >>> referenced by core.64aa0a46a0f8f964-cgu.0 >>> rust/core.o:(core::fmt::num::fmt_u128) in archive vmlinux.a ld.lld: error: undefined symbol: __aeabi_memcpy4 >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::of::DeviceId>::new) in archive vmlinux.a >>> referenced by core.64aa0a46a0f8f964-cgu.0 >>> rust/core.o:(<core::char::ToLowercase as core::fmt::Display>::fmt) in archive vmlinux.a ld.lld: error: undefined symbol: __aeabi_memclr >>> referenced by kernel.2bb770ae1dba3d33-cgu.0 >>> rust/kernel.o:(<kernel::page::Page>::fill_zero_raw) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::__kernel_sockaddr_storage__bindgen_ty_1__bindgen_ty_1 as core::default::Default>::default) in archive vmlinux.a >>> referenced by uapi.fe46408b8870a0f6-cgu.0 >>> rust/uapi.o:(<uapi::sockaddr__bindgen_ty_1 as core::default::Default>::default) in archive vmlinux.a >>> referenced 16 more times ld.lld: error: undefined symbol: __aeabi_memset4 >>> referenced by core.64aa0a46a0f8f964-cgu.0 >>> rust/core.o:(core::fmt::num::fmt_u128) in archive vmlinux.a make[2]: *** [scripts/Makefile.vmlinux:91: vmlinux] Error 1 make[1]: *** [/home/chrisi/Documents/code/rust-arm32/Makefile:1242: vmlinux] Error 2 make: *** [Makefile:248: __sub-make] Error 2 ```
With define_panicking_intrinsics! for these an empty sample works (not yet tested as module), but even printing a non formatted string (with pr_info!("Hi rust\n");) fails because rust tries to use __adddf3:
``
Hardware name: ARM-Versatile (Device Tree Support) PC is at __rust__adddf3+0x0/0x4 LR is at _RNvXsg_NtCs3KHxpmQFgFb_6kernel3strNtB5_12RawFormatterNtNtCs8DPF7ip8WBQ_4core3fmt5Write9write_str+0x34/0x40 pc : [<c028950c>] lr : [<c028b5ec>] psr: 20000193
sp : c8811a78 ip : c8811ae8 fp : c058e44e
r10: 00000000 r9 : c058e450 r8 : c07ac118
r7 : 00000000 r6 : 00000000 r5 : c07ac120 r4 : c8811adc r3 : c07ac120 r2 : 00000008 r1 : c0667f60 r0 : c07ac118
Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment none ```
I'm not sure how to proceed from here and I most likely won't find time to continue working on this anytime soon.
My very hacky changes are available on Github at:
https://github.com/onestacked/linux/commit/edddb388267ab1afe5255bea4d84f96cbdb37978
Cheers,
Christian
I followed the Documentation/rust/testing.rs document to test more. It seems that only the KUnit test is possible, while the other two tests are not feasible in a cross-compilation setup. What other tests need to be performed?
The KUnit test passed.
[ 1.162374] # rust_doctests_kernel: pass:128 fail:0 skip:0 total:128 [ 1.162388] # Totals: pass:128 fail:0 skip:0 total:128
[ 1.162401] ok 1 rust_doctests_kernel
Here is my current setup:
# zcat /proc/config.gz | grep RUST CONFIG_RUSTC_VERSION=108600 CONFIG_RUST_IS_AVAILABLE=y CONFIG_RUSTC_LLVM_VERSION=190107 CONFIG_RUST=y CONFIG_RUSTC_VERSION_TEXT="rustc 1.86.0 (05f9846f8 2025-03-31)" CONFIG_HAVE_RUST=y # CONFIG_RUST_FW_LOADER_ABSTRACTIONS is not set CONFIG_TRUSTED_FOUNDATIONS=y # CONFIG_BLK_DEV_RUST_NULL is not set # CONFIG_TRUSTED_KEYS is not set CONFIG_SYSTEM_TRUSTED_KEYRING=y CONFIG_SYSTEM_TRUSTED_KEYS="" # CONFIG_SECONDARY_TRUSTED_KEYRING is not set CONFIG_SAMPLES_RUST=y CONFIG_SAMPLE_RUST_MINIMAL=y CONFIG_SAMPLE_RUST_PRINT=y CONFIG_SAMPLE_RUST_HOSTPROGS=y CONFIG_RUST_DEBUG_ASSERTIONS=y CONFIG_RUST_OVERFLOW_CHECKS=y # CONFIG_RUST_BUILD_ASSERT_ALLOW is not set CONFIG_RUST_KERNEL_DOCTESTS=y
# cat /proc/cpuinfo processor : 0 model name : ARMv7 Processor rev 2 (v7l) BogoMIPS : 298.84 Features : half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpd32 CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x3 CPU part : 0xc08 CPU revision : 2
Hardware : Generic AM33XX (Flattened Device Tree) Revision : 0000
Serial : 4014BBBK0948