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
+
1
25
PROVIDE(_stext = ORIGIN(REGION_TEXT));
2
26
PROVIDE(_stack_start = ORIGIN(REGION_STACK) + LENGTH(REGION_STACK));
3
27
PROVIDE(_max_hart_id = 0);
@@ -72,23 +96,23 @@ SECTIONS
72
96
. = ALIGN(4);
73
97
} > REGION_RODATA
74
98
75
- .data : ALIGN (4 )
99
+ .data : ALIGN(${ARCH_WIDTH} )
76
100
{
77
101
_sidata = LOADADDR(.data);
78
102
_sdata = .;
79
103
/* Must be called __global_pointer$ for linker relaxations to work. */
80
104
PROVIDE(__global_pointer$ = . + 0x800);
81
105
*(.sdata .sdata.* .sdata2 .sdata2.*);
82
106
*(.data .data.*);
83
- . = ALIGN (4 );
107
+ . = ALIGN(${ARCH_WIDTH} );
84
108
_edata = .;
85
109
} > REGION_DATA AT > REGION_RODATA
86
110
87
- .bss (NOLOAD) : ALIGN (4 )
111
+ .bss (NOLOAD) : ALIGN(${ARCH_WIDTH} )
88
112
{
89
113
_sbss = .;
90
114
*(.sbss .sbss.* .bss .bss.*);
91
- . = ALIGN (4 );
115
+ . = ALIGN(${ARCH_WIDTH} );
92
116
_ebss = .;
93
117
} > REGION_BSS
94
118
@@ -129,8 +153,8 @@ ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned");
129
153
ASSERT(ORIGIN(REGION_RODATA) % 4 == 0, "
130
154
ERROR(riscv-rt): the start of the REGION_RODATA must be 4-byte aligned");
131
155
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");
134
158
135
159
ASSERT(ORIGIN(REGION_HEAP) % 4 == 0, "
136
160
ERROR(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");
144
168
ASSERT(_stext % 4 == 0, "
145
169
ERROR(riscv-rt): `_stext` must be 4-byte aligned");
146
170
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");
149
173
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");
152
176
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");
155
179
156
180
ASSERT(_sheap % 4 == 0, "
157
181
BUG(riscv-rt): start of .heap is not 4-byte aligned");
0 commit comments