Skip to content

Commit 2bb8bc3

Browse files
committed
cortex-m-rt: ensure the stack is 8-byte aligned.
Stack must be 8-byte aligned on ARM. Pushing 1 word makes it not aligned, so we push 2 words. This was breaking code that used LDRD/STRD on stack, since that needs 8-byte alignment.
1 parent 9d63aa9 commit 2bb8bc3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cortex-m-rt/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,11 @@ cfg_global_asm! {
573573
isb",
574574

575575
// Push `lr` to the stack for debuggers, to prevent them unwinding past Reset.
576+
// Push a dummy `r4` (which is always 0xFFFF_FFFF) to ensure the stack stays 8-byte aligned.
576577
// See https://sourceware.org/binutils/docs/as/CFI-directives.html.
577578
".cfi_def_cfa sp, 0
578-
push {{lr}}
579-
.cfi_offset lr, 0",
579+
push {{r4, lr}}
580+
.cfi_offset lr, 4",
580581

581582
// Jump to user main function.
582583
// `bl` is used for the extended range, but the user main function should not return,

0 commit comments

Comments
 (0)