From 98eb7ea7816e17b38f03c39173804358adb15a7c Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 26 Oct 2018 23:04:03 +0200 Subject: `b UserHardFault` this commit replaces the `bl UserHardFault` instruction in HardFault with `b UserHardFault`. This lets us drop the prologue (`push {r0,lr}`) while preserving the ability to unwind the stack using GDB. To prevent linker errors about relocations when UserHardFault and HardFault end up far away from each other and the target is ARMv6-M (where the `b` instruction only supports offsets of +/- 2KB) we use two *input* sections: .HardFault and .UserHardFault. HardFault is placed in the .HardFault section and UserHardFault is placed in the .UserHardFault section. The .HardFault input section is placed in the output .text section after all the input .text sections, and the .UserHardFault input section is placed after the .HardFault section. This causes the two symbols to always appear next to each other in the output binary, furthermore UserHardFault *always* appears after HardFault so the branch offset of `b UserHardFault` is always a few bytes. It should be noted that neither .HardFault or .UserHardFault will appear in the output of the `size -A` command as they are input sections that get merged into the output .text section. IOW, the sizes of HardFault and UserHardFault will continue to be reported under the .text section. --- cortex-m-rt/src/lib.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'cortex-m-rt/src') diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs index 7488cc9..5fb5057 100644 --- a/cortex-m-rt/src/lib.rs +++ b/cortex-m-rt/src/lib.rs @@ -532,6 +532,7 @@ pub unsafe extern "C" fn Reset() -> ! { #[allow(unused_variables)] #[doc(hidden)] +#[link_section = ".UserHardFault"] #[no_mangle] pub unsafe extern "C" fn UserHardFault_(ef: &ExceptionFrame) -> ! { loop { -- cgit v1.2.3