diff options
author | 2023-07-21 14:16:46 +0200 | |
---|---|---|
committer | 2023-07-21 14:16:46 +0200 | |
commit | f07d5b3241cb2e70c37d049caab64d75ef32860b (patch) | |
tree | 68fe2b1d247f6adfcb29391f7cf4c083c4f19101 /cortex-m-rt | |
parent | 3bd46e56e4e4c138cb51900f47280cc991f51702 (diff) | |
download | cortex-m-f07d5b3241cb2e70c37d049caab64d75ef32860b.tar.gz cortex-m-f07d5b3241cb2e70c37d049caab64d75ef32860b.tar.zst cortex-m-f07d5b3241cb2e70c37d049caab64d75ef32860b.zip |
Changed setup for better compiler diagnostics. We won't get a nasty assembly error anymore
Diffstat (limited to 'cortex-m-rt')
-rw-r--r-- | cortex-m-rt/macros/src/lib.rs | 18 | ||||
-rw-r--r-- | cortex-m-rt/tests/compile-fail/hard-fault-twice-mixed-trampoline.rs | 26 | ||||
-rw-r--r-- | cortex-m-rt/tests/compile-fail/hard-fault-twice.rs | 2 |
3 files changed, 39 insertions, 7 deletions
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs index 80ac665..d89bdea 100644 --- a/cortex-m-rt/macros/src/lib.rs +++ b/cortex-m-rt/macros/src/lib.rs @@ -356,10 +356,10 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { } f.sig.ident = Ident::new(&format!("__cortex_m_rt_{}", f.sig.ident), Span::call_site()); + let tramp_ident = + Ident::new(&format!("{}_trampoline", f.sig.ident), Span::call_site()); if args.trampoline { - let tramp_ident = - Ident::new(&format!("{}_trampoline", f.sig.ident), Span::call_site()); let ident = &f.sig.ident; let (ref cfgs, ref attrs) = extract_cfgs(f.attrs.clone()); @@ -368,8 +368,8 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { #(#cfgs)* #(#attrs)* #[doc(hidden)] - #[export_name = "HardFaultUser"] - pub unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) { + #[export_name = "_HardFault"] + unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) { #ident(frame) } @@ -391,16 +391,22 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { tst r0, r1 bne 0f mrs r0, MSP - b HardFaultUser + b _HardFault 0: mrs r0, PSP - b HardFaultUser", + b _HardFault", ".cfi_endproc .size HardFault, . - HardFault", ); ) } else { quote!( + #[doc(hidden)] + #[export_name = "_HardFault"] + unsafe extern "C" fn #tramp_ident() { + // This trampoline has no function except making the compiler diagnostics better. + } + #[export_name = "HardFault"] // Only emit link_section when building for embedded targets, // because some hosted platforms (used to check the build) diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-twice-mixed-trampoline.rs b/cortex-m-rt/tests/compile-fail/hard-fault-twice-mixed-trampoline.rs new file mode 100644 index 0000000..3610170 --- /dev/null +++ b/cortex-m-rt/tests/compile-fail/hard-fault-twice-mixed-trampoline.rs @@ -0,0 +1,26 @@ +#![no_main] +#![no_std] + +extern crate cortex_m_rt; +extern crate panic_halt; + +use cortex_m_rt::{entry, exception, ExceptionFrame}; + +#[entry] +fn foo() -> ! { + loop {} +} + +#[exception(trampoline = false)] +unsafe fn HardFault() -> ! { + loop {} +} + +pub mod reachable { + use cortex_m_rt::{exception, ExceptionFrame}; + + #[exception] //~ ERROR symbol `_HardFault` is already defined + unsafe fn HardFault(_ef: &ExceptionFrame) -> ! { + loop {} + } +} diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs b/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs index 03b79a5..af80127 100644 --- a/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs +++ b/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs @@ -19,7 +19,7 @@ unsafe fn HardFault(_ef: &ExceptionFrame) -> ! { pub mod reachable { use cortex_m_rt::{exception, ExceptionFrame}; - #[exception] //~ ERROR symbol `HardFault` is already defined + #[exception] //~ ERROR symbol `_HardFault` is already defined unsafe fn HardFault(_ef: &ExceptionFrame) -> ! { loop {} } |