Skip to content

Commit

Permalink
Mark EXCEPTIONS and INTERRUPTS as EXTERN in the linker script
Browse files Browse the repository at this point in the history
This is required because otherwise the linker finishes as soon as all unresolved symbols are found. If it stumbles upon one of them by accident (because it looked at the file to find other symbols), the symbol is kept. If not, it is discarded. The `EXTERN` declaration tells the linker that it should look for the passed symbol.

This also explains why our workaround worked: If the EXCEPTIONS static is alone in a separate module, it wasn't found because the linker didn't look at the module file to find other symbols.

For more details, see rust-lang/rust#40289 (comment)
  • Loading branch information
phil-opp committed May 4, 2018
1 parent 5d2fd00 commit e117bd3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,3 @@ type Handler = extern "C" fn();
extern "C" fn fault() {
panic!("EXCEPTION: hard fault");
}

// workaround for https://github.com/rust-lang/rust/issues/47384
#[inline(never)]
pub fn hello() {}
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ pub extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line:
use core::fmt::Write;
use interrupts::primask_mutex::PrimaskMutex;

// workaround for https://github.com/rust-lang/rust/issues/47384
exceptions::hello();

// Disable all interrupts after panic
let mutex: PrimaskMutex<()> = PrimaskMutex::new(());
mutex.lock(|_| {
Expand Down
2 changes: 2 additions & 0 deletions stm32f7.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ MEMORY
}

ENTRY(reset)
EXTERN(EXCEPTIONS);
EXTERN(INTERRUPTS);

__DATA_LOAD = LOADADDR(.data);

Expand Down

0 comments on commit e117bd3

Please sign in to comment.