1+ /* # Developer notes
2+
3+ - Symbols that start with a double underscore (__) are considered "private"
4+
5+ - Symbols that start with a single underscore (_) are considered "semi-public"; they can be
6+ overridden in a user linker script, but should not be referred from user code (e.g. `extern "C" {
7+ static mut _heap_size }`).
8+
9+ - `EXTERN` forces the linker to keep a symbol in the final binary. We use this to make sure a
10+ symbol if not dropped if it appears in or near the front of the linker arguments and "it's not
11+ needed" by any of the preceding objects (linker arguments)
12+
13+ - `PROVIDE` is used to provide default values that can be overridden by a user linker script
14+
15+ - In this linker script, you may find symbols that look like `${...}` (e.g., `${ARCH_WIDTH}`).
16+ These are wildcards used by the `build.rs` script to adapt to different target particularities.
17+ Check `build.rs` for more details about these symbols.
18+
19+ - On alignment: it's important for correctness that the VMA boundaries of both .bss and .data *and*
20+ the LMA of .data are all `${ARCH_WIDTH}`-byte aligned. These alignments are assumed by the RAM
21+ initialization routine. There's also a second benefit: `${ARCH_WIDTH}`-byte aligned boundaries
22+ means that you won't see "Address (..) is out of bounds" in the disassembly produced by `objdump`.
23+ */
24+
125PROVIDE(_stext = ORIGIN(REGION_TEXT));
226PROVIDE(_stack_start = ORIGIN(REGION_STACK) + LENGTH(REGION_STACK));
327PROVIDE(_max_hart_id = 0);
@@ -72,23 +96,23 @@ SECTIONS
7296 . = ALIGN(4);
7397 } > REGION_RODATA
7498
75- .data : ALIGN (4 )
99+ .data : ALIGN(${ARCH_WIDTH} )
76100 {
77101 _sidata = LOADADDR(.data);
78102 _sdata = .;
79103 /* Must be called __global_pointer$ for linker relaxations to work. */
80104 PROVIDE(__global_pointer$ = . + 0x800);
81105 *(.sdata .sdata.* .sdata2 .sdata2.*);
82106 *(.data .data.*);
83- . = ALIGN (4 );
107+ . = ALIGN(${ARCH_WIDTH} );
84108 _edata = .;
85109 } > REGION_DATA AT > REGION_RODATA
86110
87- .bss (NOLOAD) : ALIGN (4 )
111+ .bss (NOLOAD) : ALIGN(${ARCH_WIDTH} )
88112 {
89113 _sbss = .;
90114 *(.sbss .sbss.* .bss .bss.*);
91- . = ALIGN (4 );
115+ . = ALIGN(${ARCH_WIDTH} );
92116 _ebss = .;
93117 } > REGION_BSS
94118
@@ -129,8 +153,8 @@ ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned");
129153ASSERT(ORIGIN(REGION_RODATA) % 4 == 0, "
130154ERROR(riscv-rt): the start of the REGION_RODATA must be 4-byte aligned");
131155
132- ASSERT (ORIGIN (REGION_DATA ) % 4 == 0 , "
133- ERROR(riscv-rt): the start of the REGION_DATA must be 4 -byte aligned" );
156+ ASSERT(ORIGIN(REGION_DATA) % ${ARCH_WIDTH} == 0, "
157+ ERROR(riscv-rt): the start of the REGION_DATA must be ${ARCH_WIDTH} -byte aligned");
134158
135159ASSERT(ORIGIN(REGION_HEAP) % 4 == 0, "
136160ERROR(riscv-rt): the start of the REGION_HEAP must be 4-byte aligned");
@@ -144,14 +168,14 @@ ERROR(riscv-rt): the start of the REGION_STACK must be 4-byte aligned");
144168ASSERT(_stext % 4 == 0, "
145169ERROR(riscv-rt): `_stext` must be 4-byte aligned");
146170
147- ASSERT (_sdata % 4 == 0 && _edata % 4 == 0 , "
148- BUG(riscv-rt): .data is not 4 -byte aligned" );
171+ ASSERT(_sdata % ${ARCH_WIDTH} == 0 && _edata % ${ARCH_WIDTH} == 0, "
172+ BUG(riscv-rt): .data is not ${ARCH_WIDTH} -byte aligned");
149173
150- ASSERT (_sidata % 4 == 0 , "
151- BUG(riscv-rt): the LMA of .data is not 4 -byte aligned" );
174+ ASSERT(_sidata % ${ARCH_WIDTH} == 0, "
175+ BUG(riscv-rt): the LMA of .data is not ${ARCH_WIDTH} -byte aligned");
152176
153- ASSERT (_sbss % 4 == 0 && _ebss % 4 == 0 , "
154- BUG(riscv-rt): .bss is not 4 -byte aligned" );
177+ ASSERT(_sbss % ${ARCH_WIDTH} == 0 && _ebss % ${ARCH_WIDTH} == 0, "
178+ BUG(riscv-rt): .bss is not ${ARCH_WIDTH} -byte aligned");
155179
156180ASSERT(_sheap % 4 == 0, "
157181BUG(riscv-rt): start of .heap is not 4-byte aligned");
0 commit comments