Skip to content

Commit

Permalink
Add link_section = ".HardFault.user" to _HardFault
Browse files Browse the repository at this point in the history
Without that link_section, I get the following error when using a
HardFault handler with trampoline enabled:

```
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/jan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/jan/bin:/home/jan/.local/bin:/home/jan/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" VSLANG="1033" "rust-lld" "-flavor" "gnu" "/tmp/rustco5o3sY/symbols.o" "/tmp/hf/target/thumbv6m-none-eabi/release/deps/hf-60e327b1df262da6.hf.b796e35f6a1db46-cgu.0.rcgu.o" "--as-needed" "-L" "/tmp/hf/target/thumbv6m-none-eabi/release/deps" "-L" "/tmp/hf/target/release/deps" "-L" "/tmp/hf/target/thumbv6m-none-eabi/release/build/hf-ff0c4c84ae595cf3/out" "-L" "/tmp/hf/target/thumbv6m-none-eabi/release/build/cortex-m-a49cc6d3fe1b56bb/out" "-L" "/tmp/hf/target/thumbv6m-none-eabi/release/build/cortex-m-rt-92c9f0977947feec/out" "-L" "/tmp/hf/target/thumbv6m-none-eabi/release/build/defmt-f49fb1c33a63ef3f/out" "-L" "/tmp/hf/target/thumbv6m-none-eabi/release/build/rp2040-pac-b75ed87cecd188ac/out" "-L" "/home/jan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/thumbv6m-none-eabi/lib" "-Bstatic" "/tmp/rustco5o3sY/libcortex_m-e77ad2852f31030c.rlib" "/home/jan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/thumbv6m-none-eabi/lib/libcompiler_builtins-94a92625991d7a16.rlib" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-L" "/home/jan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/thumbv6m-none-eabi/lib" "-o" "/tmp/hf/target/thumbv6m-none-eabi/release/deps/hf-60e327b1df262da6" "--gc-sections" "-O1" "--nmagic" "-Tlink.x" "-Tdefmt.x"
  = note: rust-lld: error: /tmp/hf/target/thumbv6m-none-eabi/release/deps/hf-60e327b1df262da6.hf.b796e35f6a1db46-cgu.0.rcgu.o:(function HardFault: .HardFault.user+0xc): relocation R_ARM_THM_JUMP11 out of range: -7055 is not in [-2048, 2047]; references '_HardFault'
          >>> referenced by hf.b796e35f6a1db46-cgu.0
          >>> defined in /tmp/hf/target/thumbv6m-none-eabi/release/deps/hf-60e327b1df262da6.hf.b796e35f6a1db46-cgu.0.rcgu.o
```

This commit also moves the trampoline from .HardFault.user to
.HardFaultTrampoline. This is not strictly necessary, but is consistent
with previous (cortex-m-rt <= 0.7.3) usage. Alternatively,
`*(.HardFaultTrampoline)` could be removed from link.x.
  • Loading branch information
jannic committed May 21, 2024
1 parent 4395bae commit 99b5e89
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cortex-m-rt/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
#(#attrs)*
#[doc(hidden)]
#[export_name = "_HardFault"]
// Only emit link_section when building for embedded targets,
// because some hosted platforms (used to check the build)
// cannot handle the long link section names.
#[cfg_attr(target_os = "none", link_section = ".HardFault.user")]
unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) {
#ident(frame)
}
Expand All @@ -379,7 +383,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
// Depending on the stack mode in EXC_RETURN, fetches stack from either MSP or PSP.
core::arch::global_asm!(
".cfi_sections .debug_frame
.section .HardFault.user, \"ax\"
.section .HardFaultTrampoline, \"ax\"
.global HardFault
.type HardFault,%function
.thumb_func
Expand Down

0 comments on commit 99b5e89

Please sign in to comment.