Skip to content

Commit bba5c33

Browse files
bors[bot]Dirbaio
andauthored
Merge #467
467: cortex-m-rt: Remove LR push, to ensure the stack is 8-byte aligned. r=adamgreig a=Dirbaio This was causing incorrect execution of code optimized with the assumption the stack is 8-byte aligned. Alternate version of #463 - Remove instead of fix the sentinel/fake frame. - Remove code initializing LR, since it's now clobbered by the `bl main` anyway. - ~~Remove the .cfi directives, since Reset now has no correct CFI info. I think this is the "correct" thing to do here.~~ - ~~Initialize the frame pointer in R7 (suggestion from `@jamesmunns)~~` Co-authored-by: Dario Nieuwenhuis <[email protected]>
2 parents 9d63aa9 + ebf2dd6 commit bba5c33

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

cortex-m-rt/src/lib.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,6 @@ cfg_global_asm! {
507507
".cfi_startproc
508508
Reset:",
509509

510-
// Ensure LR is loaded with 0xFFFF_FFFF at startup to help debuggers find the first call frame.
511-
// On ARMv6-M LR is not initialised at all, while other platforms should initialise it.
512-
"movs r4, #0
513-
mvns r4, r4
514-
mov lr, r4",
515-
516510
// If enabled, initialise the SP. This is normally initialised by the CPU itself or by a
517511
// bootloader, but some debuggers fail to set it when resetting the target, leading to
518512
// stack corruptions.
@@ -533,9 +527,7 @@ cfg_global_asm! {
533527
// Run user pre-init code which must be executed immediately after startup, before the
534528
// potentially time-consuming memory initialisation takes place.
535529
// Example use cases include disabling default watchdogs or enabling RAM.
536-
// Reload LR after returning from pre-init (r4 is preserved by subroutines).
537-
"bl __pre_init
538-
mov lr, r4",
530+
"bl __pre_init",
539531

540532
// Initialise .bss memory. `__sbss` and `__ebss` come from the linker script.
541533
"ldr r0, =__sbss
@@ -572,12 +564,6 @@ cfg_global_asm! {
572564
dsb
573565
isb",
574566

575-
// Push `lr` to the stack for debuggers, to prevent them unwinding past Reset.
576-
// See https://sourceware.org/binutils/docs/as/CFI-directives.html.
577-
".cfi_def_cfa sp, 0
578-
push {{lr}}
579-
.cfi_offset lr, 0",
580-
581567
// Jump to user main function.
582568
// `bl` is used for the extended range, but the user main function should not return,
583569
// so trap on any unexpected return.

0 commit comments

Comments
 (0)