Closed japaric closed 3 years ago
#[naked]
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub unsafe extern "C" fn __aeabi_uldivmod() {
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}}",
options(noreturn)
);
}
LLVM-IR:
; Function Attrs: naked noinline nounwind
define hidden void @__aeabi_uidivmod() unnamed_addr #1 {
start:
tail call void asm sideeffect alignstack "push {lr}\0Asub sp, sp, #4\0Amov r2, sp\0Abl __udivmodsi4\0Aldr r1, [sp]\0Aadd sp, sp, #4\0Apop {pc}", "~{cc},~{memory}"() #16, !srcloc !0
unreachable
}
I know -Zemit-stack-sizes (LLVM's stack-sizes feature) ignores all inline assembly when computing the stack usage of a function -- we already warn about this other places like cortex_m::asm
where we assume the inline assembly uses 0 bytes of stack, which is usually the case.
So I guess the issue here is that stack-sizes also ignores the naked attribute so it considers this function to be a normal, empty function that uses a few bytes of stack -- even though no extra machine code is generated around the inline asm!
call.
I think in general we should identify the #[naked]
+ inline asm!
pattern in LLVM-IR and assume that LLVM is wrong on those and solely rely on cargo-call-stack's disassembler.
To get the LLVM-IR for compiler-builtins we would need to do #46
(It would have been nice if they had written these subroutines with global_asm!
instead of #[naked]
then we wouldn't be seeing this issue)
I know -Zemit-stack-sizes (LLVM's stack-sizes feature) ignores all inline assembly when computing the stack usage of a function
Ah, I wouldn't have expected that. I would've thought that the stack size analysis runs on MIR.
The proposed solution sounds good though!
Source code
Error message
Machine code