Skip to content

Commit 27be420

Browse files
bors[bot]japaric
andcommitted
Merge #144
144: [RFC] rename UserHardFault to HardFault r=adamgreig a=japaric so it matches the exception name (`#[exception] fn HardFault(..`) Right now the symbol name of all exception handlers match the name of the function used with the `#[exception]` attribute *except* for `HardFault`, whose symbol name actually is `UserHardFault`. This PR corrects that inconsistency by renaming the `UserHardFault` symbol to `HardFault`, and the `HardFault` symbol to `HardFaultTrampoline`. This change doesn't break compilation or changes functionality but it does soft break GDB scripts that include the command `break UserHardFault` (e.g. the GDB script in cortex-m-quickstart) in the sense that the breakpoint will no longer work. However the rest of the GDB script will continue to work. RFC questions: (a) do we want to do this rename? (b) if the answer is yes, do we want to include this rename in the v0.5.x release, or should we consider it a breaking change and postpone it until v0.6.0? Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 3f2031c + b46b29f commit 27be420

File tree

10 files changed

+21
-21
lines changed

10 files changed

+21
-21
lines changed

cortex-m-rt/asm.s

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# LLD requires that the section flags are explicitly set here
2-
.section .HardFault, "ax"
3-
.global HardFault
2+
.section .HardFaultTrampoline, "ax"
3+
.global HardFaultTrampoline
44
# .type and .thumb_func are both required; otherwise its Thumb bit does not
55
# get set and an invalid vector table is generated
6-
.type HardFault,%function
6+
.type HardFaultTrampoline,%function
77
.thumb_func
8-
HardFault:
8+
HardFaultTrampoline:
99
mrs r0, MSP
10-
b UserHardFault
10+
b HardFault

cortex-m-rt/bin/thumbv6m-none-eabi.a

38 Bytes
Binary file not shown.

cortex-m-rt/bin/thumbv7em-none-eabi.a

38 Bytes
Binary file not shown.
38 Bytes
Binary file not shown.

cortex-m-rt/bin/thumbv7m-none-eabi.a

38 Bytes
Binary file not shown.
38 Bytes
Binary file not shown.

cortex-m-rt/link.x.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ EXTERN(__EXCEPTIONS); /* depends on all the these PROVIDED symbols */
3535
EXTERN(DefaultHandler);
3636

3737
PROVIDE(NonMaskableInt = DefaultHandler);
38-
EXTERN(HardFault);
38+
EXTERN(HardFaultTrampoline);
3939
PROVIDE(MemoryManagement = DefaultHandler);
4040
PROVIDE(BusFault = DefaultHandler);
4141
PROVIDE(UsageFault = DefaultHandler);
@@ -46,7 +46,7 @@ PROVIDE(PendSV = DefaultHandler);
4646
PROVIDE(SysTick = DefaultHandler);
4747

4848
PROVIDE(DefaultHandler = DefaultHandler_);
49-
PROVIDE(UserHardFault = UserHardFault_);
49+
PROVIDE(HardFault = HardFault_);
5050

5151
/* # Interrupt vectors */
5252
EXTERN(__INTERRUPTS); /* `static` variable similar to `__EXCEPTIONS` */
@@ -86,8 +86,8 @@ SECTIONS
8686
.text _stext :
8787
{
8888
*(.text .text.*);
89-
*(.HardFault);
90-
*(.UserHardFault);
89+
*(.HardFaultTrampoline);
90+
*(.HardFault.*);
9191
} > FLASH
9292

9393
/* ### .rodata */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
397397
let pat = &arg.pat;
398398

399399
quote!(
400-
#[export_name = "UserHardFault"]
401-
#[link_section = ".UserHardFault"]
400+
#[export_name = "HardFault"]
401+
#[link_section = ".HardFault.user"]
402402
#(#attrs)*
403403
pub #unsafety extern "C" fn #hash(#arg) -> ! {
404404
extern crate cortex_m_rt;

cortex-m-rt/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@
203203
//! - `DefaultHandler`. This is the default handler. If not overridden using `#[exception] fn
204204
//! DefaultHandler(..` this will be an infinite loop.
205205
//!
206-
//! - `HardFault`. This is the hard fault handler. This function is simply a trampoline that jumps
207-
//! into the user defined hard fault handler named `UserHardFault`. The trampoline is required to
208-
//! set up the pointer to the stacked exception frame.
206+
//! - `HardFaultTrampoline`. This is the real hard fault handler. This function is simply a
207+
//! trampoline that jumps into the user defined hard fault handler named `HardFault`. The
208+
//! trampoline is required to set up the pointer to the stacked exception frame.
209209
//!
210-
//! - `UserHardFault`. This is the user defined hard fault handler. If not overridden using
211-
//! `#[exception] fn HardFault(..` this will be an infinite loop.
210+
//! - `HardFault`. This is the user defined hard fault handler. If not overridden using
211+
//! `#[exception] fn HardFault(..` it will default to an infinite loop.
212212
//!
213213
//! - `__STACK_START`. This is the first entry in the `.vector_table` section. This symbol contains
214214
//! the initial value of the stack pointer; this is where the stack will be located -- the stack
@@ -534,9 +534,9 @@ pub unsafe extern "C" fn Reset() -> ! {
534534

535535
#[allow(unused_variables)]
536536
#[doc(hidden)]
537-
#[link_section = ".UserHardFault"]
537+
#[link_section = ".HardFault.default"]
538538
#[no_mangle]
539-
pub unsafe extern "C" fn UserHardFault_(ef: &ExceptionFrame) -> ! {
539+
pub unsafe extern "C" fn HardFault_(ef: &ExceptionFrame) -> ! {
540540
loop {
541541
// add some side effect to prevent this from turning into a UDF instruction
542542
// see rust-lang/rust#28728 for details
@@ -590,7 +590,7 @@ pub enum Exception {
590590
extern "C" {
591591
fn NonMaskableInt();
592592

593-
fn HardFault();
593+
fn HardFaultTrampoline();
594594

595595
#[cfg(not(armv6m))]
596596
fn MemoryManagement();
@@ -629,7 +629,7 @@ pub static __EXCEPTIONS: [Vector; 14] = [
629629
handler: NonMaskableInt,
630630
},
631631
// Exception 3: Hard Fault Interrupt.
632-
Vector { handler: HardFault },
632+
Vector { handler: HardFaultTrampoline },
633633
// Exception 4: Memory Management Interrupt [not on Cortex-M0 variants].
634634
#[cfg(not(armv6m))]
635635
Vector {

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 @@ fn HardFault(_ef: &ExceptionFrame) -> ! {
1919
pub mod reachable {
2020
use cortex_m_rt::{exception, ExceptionFrame};
2121

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

0 commit comments

Comments
 (0)