Skip to content

Commit 97ad368

Browse files
bors[bot]mattico
andauthoredAug 29, 2020
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 rust-embedded/cortex-m-rt#287 (comment) Co-authored-by: Matt Ickstadt <[email protected]>
2 parents 8a165d9 + 49a68f1 commit 97ad368

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed
 

‎cortex-m-rt/link.x.in

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ SECTIONS
8888
*(.text .text.*);
8989
*(.HardFaultTrampoline);
9090
*(.HardFault.*);
91-
. = ALIGN(4);
92-
__etext = .;
91+
. = ALIGN(4); /* Pad .text to the alignment to workaround overlapping load section bug in old lld */
9392
} > FLASH
93+
. = ALIGN(4); /* Ensure __etext is aligned if something unaligned is inserted after .text */
94+
__etext = .; /* Define outside of .text to allow using INSERT AFTER .text */
9495

9596
/* ### .rodata */
9697
.rodata __etext : ALIGN(4)
@@ -101,8 +102,9 @@ SECTIONS
101102
This is required by LLD to ensure the LMA of the following .data
102103
section will have the correct alignment. */
103104
. = ALIGN(4);
104-
__erodata = .;
105105
} > FLASH
106+
. = ALIGN(4); /* Ensure __erodata is aligned if something unaligned is inserted after .rodata */
107+
__erodata = .;
106108

107109
/* ## Sections in RAM */
108110
/* ### .data */
@@ -112,21 +114,24 @@ SECTIONS
112114
__sdata = .;
113115
*(.data .data.*);
114116
. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
115-
__edata = .;
116117
} > RAM AT>FLASH
118+
. = ALIGN(4); /* Ensure __edata is aligned if something unaligned is inserted after .data */
119+
__edata = .;
117120

118121
/* LMA of .data */
119122
__sidata = LOADADDR(.data);
120123

121124
/* ### .bss */
125+
. = ALIGN(4);
126+
__sbss = .; /* Define outside of section to include INSERT BEFORE/AFTER symbols */
122127
.bss (NOLOAD) : ALIGN(4)
123128
{
124-
. = ALIGN(4);
125-
__sbss = .;
126129
*(.bss .bss.*);
130+
*(COMMON); /* Uninitialized C statics */
127131
. = ALIGN(4); /* 4-byte align the end (VMA) of this section */
128-
__ebss = .;
129132
} > RAM
133+
. = ALIGN(4); /* Ensure __ebss is aligned if something unaligned is inserted after .bss */
134+
__ebss = .;
130135

131136
/* ### .uninit */
132137
.uninit (NOLOAD) : ALIGN(4)

0 commit comments

Comments
 (0)
Please sign in to comment.