mirror-llvm-project/libc/startup
Simon Tatham 73e1c53474
[libc][ARM] Defend banked SP setup against register allocator (#206757)
The startup code for bare-metal AArch32 A/R shifts the CPU through all
the different modes which have their own copies of SP, updating all the
stack pointers to the same value. But it does it using C intrinsics,
leaving the register allocation to the compiler – so it's possible that
the register allocator happens to use one of the _other_ banked
registers, such as LR.

For example, when I built this code today, it happened that LR was used
to hold one of the constants written into CPSR_c to change mode. That
constant was written into the SVC mode LR before any mode changes, but
the MSR instruction that tried to use it was run in a different mode, so
it copied from _that_ mode's LR, which contained uninitialised nonsense
in place of the desired constant, triggering a boot-time crash.

I think it's safer to use a single asm statement for the whole job,
guaranteeing which registers it uses.
2026-07-03 09:16:27 +01:00
..
baremetal [libc][ARM] Defend banked SP setup against register allocator (#206757) 2026-07-03 09:16:27 +01:00
gpu [LLVM] Port 'llvm-gpu-loader' to use LLVMOffload (#162739) 2026-02-24 08:44:29 -06:00
linux [libc] Port munmap and mprotect to the new syscall interface (#199199) 2026-05-25 13:07:05 +02:00
uefi [libc][uefi] add crt1 (#132150) 2025-05-09 09:02:33 -07:00
CMakeLists.txt