Skip to content

Commit 9488c5f

Browse files
committed
cortex-m-rt: Remove LR push, to ensure the stack is 8-byte aligned.
This was causing incorrect execution of code optimized with the assumption the stack is 8-byte aligned.
1 parent 9d63aa9 commit 9488c5f

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

cortex-m-rt/src/lib.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,10 @@ macro_rules! cfg_global_asm {
499499
// Finally jumps to the user main function.
500500
#[cfg(cortex_m)]
501501
cfg_global_asm! {
502-
".cfi_sections .debug_frame
503-
.section .Reset, \"ax\"
502+
".section .Reset, \"ax\"
504503
.global Reset
505504
.type Reset,%function
506-
.thumb_func",
507-
".cfi_startproc
505+
.thumb_func
508506
Reset:",
509507

510508
// Ensure LR is loaded with 0xFFFF_FFFF at startup to help debuggers find the first call frame.
@@ -572,20 +570,16 @@ cfg_global_asm! {
572570
dsb
573571
isb",
574572

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",
573+
// Put the stack pointer in r7 so the next callee-saved frame pointer (i.e. main's) is correct
574+
"mov r7, sp",
580575

581576
// Jump to user main function.
582577
// `bl` is used for the extended range, but the user main function should not return,
583578
// so trap on any unexpected return.
584579
"bl main
585580
udf #0",
586581

587-
".cfi_endproc
588-
.size Reset, . - Reset",
582+
".size Reset, . - Reset",
589583
}
590584

591585
/// Attribute to declare an interrupt (AKA device-specific exception) handler

0 commit comments

Comments
 (0)