Skip to content

Commit f07d5b3

Browse files
committed
Changed setup for better compiler diagnostics. We won't get a nasty assembly error anymore
1 parent 3bd46e5 commit f07d5b3

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
356356
}
357357

358358
f.sig.ident = Ident::new(&format!("__cortex_m_rt_{}", f.sig.ident), Span::call_site());
359+
let tramp_ident =
360+
Ident::new(&format!("{}_trampoline", f.sig.ident), Span::call_site());
359361

360362
if args.trampoline {
361-
let tramp_ident =
362-
Ident::new(&format!("{}_trampoline", f.sig.ident), Span::call_site());
363363
let ident = &f.sig.ident;
364364

365365
let (ref cfgs, ref attrs) = extract_cfgs(f.attrs.clone());
@@ -368,8 +368,8 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
368368
#(#cfgs)*
369369
#(#attrs)*
370370
#[doc(hidden)]
371-
#[export_name = "HardFaultUser"]
372-
pub unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) {
371+
#[export_name = "_HardFault"]
372+
unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) {
373373
#ident(frame)
374374
}
375375

@@ -391,16 +391,22 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
391391
tst r0, r1
392392
bne 0f
393393
mrs r0, MSP
394-
b HardFaultUser
394+
b _HardFault
395395
0:
396396
mrs r0, PSP
397-
b HardFaultUser",
397+
b _HardFault",
398398
".cfi_endproc
399399
.size HardFault, . - HardFault",
400400
);
401401
)
402402
} else {
403403
quote!(
404+
#[doc(hidden)]
405+
#[export_name = "_HardFault"]
406+
unsafe extern "C" fn #tramp_ident() {
407+
// This trampoline has no function except making the compiler diagnostics better.
408+
}
409+
404410
#[export_name = "HardFault"]
405411
// Only emit link_section when building for embedded targets,
406412
// because some hosted platforms (used to check the build)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m_rt;
5+
extern crate panic_halt;
6+
7+
use cortex_m_rt::{entry, exception, ExceptionFrame};
8+
9+
#[entry]
10+
fn foo() -> ! {
11+
loop {}
12+
}
13+
14+
#[exception(trampoline = false)]
15+
unsafe fn HardFault() -> ! {
16+
loop {}
17+
}
18+
19+
pub mod reachable {
20+
use cortex_m_rt::{exception, ExceptionFrame};
21+
22+
#[exception] //~ ERROR symbol `_HardFault` is already defined
23+
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
24+
loop {}
25+
}
26+
}

cortex-m-rt/tests/compile-fail/hard-fault-twice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
1919
pub mod reachable {
2020
use cortex_m_rt::{exception, ExceptionFrame};
2121

22-
#[exception] //~ ERROR symbol `HardFault` is already defined
22+
#[exception] //~ ERROR symbol `_HardFault` is already defined
2323
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
2424
loop {}
2525
}

0 commit comments

Comments
 (0)