diff options
author | 2020-08-29 11:31:50 +0000 | |
---|---|---|
committer | 2020-08-29 11:31:50 +0000 | |
commit | 97ad3685d82cab3582602a1d044e80bc3edaaab6 (patch) | |
tree | c26c4a4b099123d4142a9c88479fd9d5fa7b3d54 | |
parent | 8a165d9a45cecd551b115dc52ed5b1bdc77f4af1 (diff) | |
parent | 49a68f13d8d22cad02004e4c90559345b225ce26 (diff) | |
download | cortex-m-97ad3685d82cab3582602a1d044e80bc3edaaab6.tar.gz cortex-m-97ad3685d82cab3582602a1d044e80bc3edaaab6.tar.zst cortex-m-97ad3685d82cab3582602a1d044e80bc3edaaab6.zip |
Merge #287
287: Fix common uses of INSERT AFTER with .bss and .text r=adamgreig a=mattico
Fixes #267
Fixes #266
This fixes two related issues.
1. Named sections are often inserted after `.bss` or `.text` in order to have them handled as if they were part of that section. Defining the start/end symbols outside of the section allows this to work.
2. Uninitialized C statics will end up as common symbols which end up in the COMMON input section. If this section is orphaned, it will likely end up placed after `.bss`. C code often expects these statics to be zero initialized. The first change would cause these symbols to be placed before `__ebss` so they will get zeroed by the reset handler. Explicitly placing the common symbols into `.bss` ensures this happens. Users who want uninitialized symbols should use the `.uninit` section.
See https://github.com/rust-embedded/cortex-m-rt/pull/287#issuecomment-677743856
Co-authored-by: Matt Ickstadt <mattico8@gmail.com>
-rw-r--r-- | cortex-m-rt/link.x.in | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/cortex-m-rt/link.x.in b/cortex-m-rt/link.x.in index 01eb521..f5e582e 100644 --- a/cortex-m-rt/link.x.in +++ b/cortex-m-rt/link.x.in @@ -88,9 +88,10 @@ SECTIONS *(.text .text.*); *(.HardFaultTrampoline); *(.HardFault.*); - . = ALIGN(4); - __etext = .; + . = ALIGN(4); /* Pad .text to the alignment to workaround overlapping load section bug in old lld */ } > FLASH + . = ALIGN(4); /* Ensure __etext is aligned if something unaligned is inserted after .text */ + __etext = .; /* Define outside of .text to allow using INSERT AFTER .text */ /* ### .rodata */ .rodata __etext : ALIGN(4) @@ -101,8 +102,9 @@ SECTIONS This is required by LLD to ensure the LMA of the following .data section will have the correct alignment. */ . = ALIGN(4); - __erodata = .; } > FLASH + . = ALIGN(4); /* Ensure __erodata is aligned if something unaligned is inserted after .rodata */ + __erodata = .; /* ## Sections in RAM */ /* ### .data */ @@ -112,21 +114,24 @@ SECTIONS __sdata = .; *(.data .data.*); . = ALIGN(4); /* 4-byte align the end (VMA) of this section */ - __edata = .; } > RAM AT>FLASH + . = ALIGN(4); /* Ensure __edata is aligned if something unaligned is inserted after .data */ + __edata = .; /* LMA of .data */ __sidata = LOADADDR(.data); /* ### .bss */ + . = ALIGN(4); + __sbss = .; /* Define outside of section to include INSERT BEFORE/AFTER symbols */ .bss (NOLOAD) : ALIGN(4) { - . = ALIGN(4); - __sbss = .; *(.bss .bss.*); + *(COMMON); /* Uninitialized C statics */ . = ALIGN(4); /* 4-byte align the end (VMA) of this section */ - __ebss = .; } > RAM + . = ALIGN(4); /* Ensure __ebss is aligned if something unaligned is inserted after .bss */ + __ebss = .; /* ### .uninit */ .uninit (NOLOAD) : ALIGN(4) |