Skip to content

Commit

Permalink
rust: replace __aeabi_uldivmod stub with actual implementation
Browse files Browse the repository at this point in the history
Rust's libcore genuinely needs 64-bit division for formatting, but we
can't change these to use kernel's division routine; so `__aeabi_uldivmod`
calls will be generated.

Instead of redirecting these calls to a panicking stub, forward them to
`div64_u64_rem`.

Signed-off-by: Gary Guo <gary@garyguo.net>
  • Loading branch information
nbdd0121 committed Nov 1, 2022
1 parent 2d98d37 commit 17ea967
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions rust/compiler_builtins.rs
Expand Up @@ -20,6 +20,7 @@
//! [`compiler-rt`]: https://compiler-rt.llvm.org/

#![feature(compiler_builtins)]
#![feature(naked_functions)]
#![compiler_builtins]
#![no_builtins]
#![no_std]
Expand Down Expand Up @@ -74,6 +75,24 @@ define_panicking_intrinsics!("`f64` should not be used", {
});

#[cfg(target_arch = "arm")]
define_panicking_intrinsics!("`u64` division/modulo should not be used", {
__aeabi_uldivmod,
});
#[doc(hidden)]
#[naked]
#[no_mangle]
pub unsafe extern "C" fn __rust__aeabi_uldivmod() {
// Adapted from compiler-rt:
// https://github.com/llvm/llvm-project/blob/a80e65e00ada7a9c16acf17a5fd40b4f12ced3a8/compiler-rt/lib/builtins/arm/aeabi_uldivmod.S
unsafe {
core::arch::asm!(
"push {{r6, lr}}",
"sub sp, sp, #16",
"add r6, sp, #8",
"str r6, [sp]",
"bl div64_u64_rem",
"ldr r2, [sp, #8]",
"ldr r3, [sp, #12]",
"add sp, sp, #16",
"pop {{r6, pc}}",
options(noreturn)
);
}
}

0 comments on commit 17ea967

Please sign in to comment.