Skip to content

Commit 13174b0

Browse files
committed
Add link_section = ".HardFault.user" to _HardFault
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.
1 parent 5473462 commit 13174b0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cortex-m-rt/macros/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
368368
#(#attrs)*
369369
#[doc(hidden)]
370370
#[export_name = "_HardFault"]
371+
// Only emit link_section when building for embedded targets,
372+
// because some hosted platforms (used to check the build)
373+
// cannot handle the long link section names.
374+
#[cfg_attr(target_os = "none", link_section = ".HardFault.user")]
371375
unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) {
372376
#ident(frame)
373377
}
@@ -379,7 +383,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
379383
// Depending on the stack mode in EXC_RETURN, fetches stack from either MSP or PSP.
380384
core::arch::global_asm!(
381385
".cfi_sections .debug_frame
382-
.section .HardFault.user, \"ax\"
386+
.section .HardFaultTrampoline, \"ax\"
383387
.global HardFault
384388
.type HardFault,%function
385389
.thumb_func

0 commit comments

Comments
 (0)