aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bors[bot] <bors[bot]@users.noreply.github.com> 2018-10-26 22:06:24 +0000
committerGravatar bors[bot] <bors[bot]@users.noreply.github.com> 2018-10-26 22:06:24 +0000
commit68c56ab139e03e33d9b8c1d2ecfd67d5e9f0eb69 (patch)
tree8bdf4a7eebb9a43370441008102a4e3de9357e11
parentf7ab39c983d729d56f5a0d4101e111d5d9fe004f (diff)
parent98eb7ea7816e17b38f03c39173804358adb15a7c (diff)
downloadcortex-m-68c56ab139e03e33d9b8c1d2ecfd67d5e9f0eb69.tar.gz
cortex-m-68c56ab139e03e33d9b8c1d2ecfd67d5e9f0eb69.tar.zst
cortex-m-68c56ab139e03e33d9b8c1d2ecfd67d5e9f0eb69.zip
Merge #143
143: `b UserHardFault` r=adamgreig a=japaric 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. cc @adamgreen Co-authored-by: Jorge Aparicio <jorge@japaric.io>
-rw-r--r--cortex-m-rt/asm.s9
-rw-r--r--cortex-m-rt/bin/thumbv6m-none-eabi.abin920 -> 882 bytes
-rw-r--r--cortex-m-rt/bin/thumbv7em-none-eabi.abin920 -> 882 bytes
-rw-r--r--cortex-m-rt/bin/thumbv7em-none-eabihf.abin920 -> 882 bytes
-rw-r--r--cortex-m-rt/bin/thumbv7m-none-eabi.abin920 -> 882 bytes
-rw-r--r--cortex-m-rt/link.x.in2
-rw-r--r--cortex-m-rt/macros/src/lib.rs1
-rw-r--r--cortex-m-rt/src/lib.rs1
8 files changed, 10 insertions, 3 deletions
diff --git a/cortex-m-rt/asm.s b/cortex-m-rt/asm.s
index a5748a5..4636bc3 100644
--- a/cortex-m-rt/asm.s
+++ b/cortex-m-rt/asm.s
@@ -1,7 +1,10 @@
- .section .text.HardFault
+ # LLD requires that the section flags are explicitly set here
+ .section .HardFault, "ax"
.global HardFault
+ # .type and .thumb_func are both required; otherwise its Thumb bit does not
+ # get set and an invalid vector table is generated
+ .type HardFault,%function
.thumb_func
HardFault:
- push {r0, lr}
mrs r0, MSP
- bl UserHardFault
+ b UserHardFault
diff --git a/cortex-m-rt/bin/thumbv6m-none-eabi.a b/cortex-m-rt/bin/thumbv6m-none-eabi.a
index 4a2f178..9857abc 100644
--- a/cortex-m-rt/bin/thumbv6m-none-eabi.a
+++ b/cortex-m-rt/bin/thumbv6m-none-eabi.a
Binary files differ
diff --git a/cortex-m-rt/bin/thumbv7em-none-eabi.a b/cortex-m-rt/bin/thumbv7em-none-eabi.a
index e5ffd6f..3f8b8fe 100644
--- a/cortex-m-rt/bin/thumbv7em-none-eabi.a
+++ b/cortex-m-rt/bin/thumbv7em-none-eabi.a
Binary files differ
diff --git a/cortex-m-rt/bin/thumbv7em-none-eabihf.a b/cortex-m-rt/bin/thumbv7em-none-eabihf.a
index e5ffd6f..3f8b8fe 100644
--- a/cortex-m-rt/bin/thumbv7em-none-eabihf.a
+++ b/cortex-m-rt/bin/thumbv7em-none-eabihf.a
Binary files differ
diff --git a/cortex-m-rt/bin/thumbv7m-none-eabi.a b/cortex-m-rt/bin/thumbv7m-none-eabi.a
index d3cc07e..43c843e 100644
--- a/cortex-m-rt/bin/thumbv7m-none-eabi.a
+++ b/cortex-m-rt/bin/thumbv7m-none-eabi.a
Binary files differ
diff --git a/cortex-m-rt/link.x.in b/cortex-m-rt/link.x.in
index fde4e70..e6e0d3b 100644
--- a/cortex-m-rt/link.x.in
+++ b/cortex-m-rt/link.x.in
@@ -86,6 +86,8 @@ SECTIONS
.text _stext :
{
*(.text .text.*);
+ *(.HardFault);
+ *(.UserHardFault);
} > FLASH
/* ### .rodata */
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs
index 50cea38..0032837 100644
--- a/cortex-m-rt/macros/src/lib.rs
+++ b/cortex-m-rt/macros/src/lib.rs
@@ -394,6 +394,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
quote!(
#[export_name = "UserHardFault"]
+ #[link_section = ".UserHardFault"]
#(#attrs)*
pub #unsafety extern "C" fn #hash(#arg) -> ! {
extern crate cortex_m_rt;
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 {