Skip to content

Commit 7b27817

Browse files
bors[bot]adamgreig
andauthored
Merge #310
310: Only emit link_section for cortex-m r=jonas-schievink a=adamgreig Previously we always emitted `link_section`, even though it only had an effect when our linker script was being used (and only made sense on cortex-m targets). This breaks building the code for a MacOS target, which is occasionally useful for running `cargo check` etc. In the macros crate we don't have the target information available, so instead we continue to emit `link_section` except specifically on MacOS. This keeps the fix from #306 but hopefully resolves the confusion in rust-embedded/cortex-m-rt#74 (comment). Co-authored-by: Adam Greig <[email protected]>
2 parents 8a64815 + f0e2218 commit 7b27817

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
278278
#(#attrs)*
279279
#[doc(hidden)]
280280
#[export_name = "HardFault"]
281-
#[cfg_attr(target_os = "macos", link_section = ".HardFault,user")]
282-
#[cfg_attr(not(target_os = "macos"), link_section = ".HardFault.user")]
281+
// Only emit link_section when building for embedded targets,
282+
// because some hosted platforms (used to check the build)
283+
// cannot handle the long link section names.
284+
#[cfg_attr(target_os = "none", link_section = ".HardFault.user")]
283285
pub unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) {
284286
#ident(frame)
285287
}

cortex-m-rt/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -910,15 +910,13 @@ pub fn heap_start() -> *mut u32 {
910910

911911
// Entry point is Reset.
912912
#[doc(hidden)]
913-
#[cfg_attr(target_os = "macos", link_section = ".vector_table,reset_vector")]
914-
#[cfg_attr(not(target_os = "macos"), link_section = ".vector_table.reset_vector")]
913+
#[cfg_attr(cortex_m, link_section = ".vector_table.reset_vector")]
915914
#[no_mangle]
916915
pub static __RESET_VECTOR: unsafe extern "C" fn() -> ! = Reset;
917916

918917
#[allow(unused_variables)]
919918
#[doc(hidden)]
920-
#[cfg_attr(target_os = "macos", link_section = ".HardFault,default")]
921-
#[cfg_attr(not(target_os = "macos"), link_section = ".HardFault.default")]
919+
#[cfg_attr(cortex_m, link_section = ".HardFault.default")]
922920
#[no_mangle]
923921
pub unsafe extern "C" fn HardFault_(ef: &ExceptionFrame) -> ! {
924922
loop {
@@ -1010,8 +1008,7 @@ pub union Vector {
10101008
}
10111009

10121010
#[doc(hidden)]
1013-
#[cfg_attr(target_os = "macos", link_section = ".vector_table,exceptions")]
1014-
#[cfg_attr(not(target_os = "macos"), link_section = ".vector_table.exceptions")]
1011+
#[cfg_attr(cortex_m, link_section = ".vector_table.exceptions")]
10151012
#[no_mangle]
10161013
pub static __EXCEPTIONS: [Vector; 14] = [
10171014
// Exception 2: Non Maskable Interrupt.
@@ -1073,8 +1070,7 @@ pub static __EXCEPTIONS: [Vector; 14] = [
10731070
// to the default handler
10741071
#[cfg(all(any(not(feature = "device"), test), not(armv6m)))]
10751072
#[doc(hidden)]
1076-
#[cfg_attr(target_os = "macos", link_section = ".vector_table,interrupts")]
1077-
#[cfg_attr(not(target_os = "macos"), link_section = ".vector_table.interrupts")]
1073+
#[cfg_attr(cortex_m, link_section = ".vector_table.interrupts")]
10781074
#[no_mangle]
10791075
pub static __INTERRUPTS: [unsafe extern "C" fn(); 240] = [{
10801076
extern "C" {

0 commit comments

Comments
 (0)