Skip to content

Commit 8f57be8

Browse files
committed
align symbols to cortex-m-rt convention
1 parent 2ce267a commit 8f57be8

File tree

5 files changed

+310
-164
lines changed

5 files changed

+310
-164
lines changed

riscv-rt/CHANGELOG.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,29 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Changed
1111

12-
- `link.x.in`: remove references to `eh_frame`
12+
- `link.x.in`: remove references to `eh_frame`.
13+
- Rename start/end section symbols to align with `cortex-m-rt`:
14+
- `_stext`: it remains, as linker files can modify it.
15+
- `__stext`: it coincides with `_stext`.
16+
- `__etext`: new symbol. It points to the end of the text section.
17+
- `__srodata`: new symbol. It points to the start of the read-only data section.
18+
- `__erodata`: new symbol. It points to the end of the read-only data section.
19+
- `__sdata`: substitutes `_sdata`. It points to the start of the on-flash data section.
20+
- `__edata`: substitutes `_edata`. It points to the end of the on-flash data section.
21+
- `__idata`: substitutes `_idata`. It points to the start of the on-RAM data section.
22+
- `__sbss`: substitutes `_sbss`. It points to the start of the BSS section.
23+
- `__ebss`: substitutes `_ebss`. It points to the end of the BSS section.
24+
- `__sheap`: substitutes `_sheap`. It points to the start of the heap section.
25+
- `__eheap`: substitutes `_eheap`. It points to the end of the heap section.
26+
- `__estack`: substitutes `_estack`. It points to the end of the stack section.
27+
- `__sstack`: substitutes `_sstack`. It points to the start of the stack section.
28+
- `__edata` and `__ebss` are now defined outside of their respective sections.
29+
In this way, users can inject custom sections and benefit from the copying and
30+
zeroing routines, respectively.
31+
- As `__sheap` is now private, `riscv-rt` now provides a `heap_start` function to
32+
allow users get the initial address of the heap when initializing an allocator.
33+
- Update documentation.
34+
- Removed `.init.rust` section, as it is no longer required.
1335

1436
## [v0.13.0] - 2024-10-19
1537

riscv-rt/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ riscv-pac = { path = "../riscv-pac", version = "0.2.0" }
2525
riscv-rt-macros = { path = "macros", version = "0.2.2" }
2626

2727
[dev-dependencies]
28-
panic-halt = "0.2.0"
28+
panic-halt = "1.0.0"
2929

3030
[features]
3131
s-mode = ["riscv-rt-macros/s-mode"]

riscv-rt/link.x.in

+41-18
Original file line numberDiff line numberDiff line change
@@ -100,65 +100,88 @@ SECTIONS
100100

101101
.text _stext :
102102
{
103+
__stext = .;
104+
103105
/* Put reset handler first in .text section so it ends up as the entry */
104106
/* point of the program. */
105107
KEEP(*(.init));
106-
KEEP(*(.init.rust));
107108
. = ALIGN(4);
108109
KEEP(*(.init.trap));
109110
. = ALIGN(4);
110111
*(.trap);
111112
*(.trap.rust);
112113
*(.text.abort);
113114
*(.text .text.*);
115+
116+
. = ALIGN(4);
117+
__etext = .;
114118
} > REGION_TEXT
115119

116120
.rodata : ALIGN(4)
117121
{
122+
. = ALIGN(4);
123+
__srodata = .;
124+
118125
*(.srodata .srodata.*);
119126
*(.rodata .rodata.*);
120127

121-
/* 4-byte align the end (VMA) of this section.
128+
/* ${ARCH_WIDTH}-byte align the end (VMA) of this section.
122129
This is required by LLD to ensure the LMA of the following .data
123130
section will have the correct alignment. */
124-
. = ALIGN(4);
131+
. = ALIGN(${ARCH_WIDTH});
132+
__erodata = .;
125133
} > REGION_RODATA
126134

127135
.data : ALIGN(${ARCH_WIDTH})
128136
{
129-
_sidata = LOADADDR(.data);
130-
_sdata = .;
137+
. = ALIGN(${ARCH_WIDTH});
138+
__sdata = .;
139+
131140
/* Must be called __global_pointer$ for linker relaxations to work. */
132141
PROVIDE(__global_pointer$ = . + 0x800);
133142
*(.sdata .sdata.* .sdata2 .sdata2.*);
134143
*(.data .data.*);
135-
. = ALIGN(${ARCH_WIDTH});
136-
_edata = .;
144+
137145
} > REGION_DATA AT > REGION_RODATA
146+
147+
/* Allow sections from user `memory.x` injected using `INSERT AFTER .data` to
148+
* use the .data loading mechanism by pushing __edata. Note: do not change
149+
* output region or load region in those user sections! */
150+
. = ALIGN(${ARCH_WIDTH});
151+
__edata = .;
152+
153+
/* LMA of .data */
154+
__sidata = LOADADDR(.data);
138155

139156
.bss (NOLOAD) : ALIGN(${ARCH_WIDTH})
140157
{
141-
_sbss = .;
142-
*(.sbss .sbss.* .bss .bss.*);
143158
. = ALIGN(${ARCH_WIDTH});
144-
_ebss = .;
159+
__sbss = .;
160+
161+
*(.sbss .sbss.* .bss .bss.*);
145162
} > REGION_BSS
146163

164+
/* Allow sections from user `memory.x` injected using `INSERT AFTER .bss` to
165+
* use the .bss zeroing mechanism by pushing __ebss. Note: do not change
166+
* output region or load region in those user sections! */
167+
. = ALIGN(${ARCH_WIDTH});
168+
__ebss = .;
169+
147170
/* fictitious region that represents the memory available for the heap */
148171
.heap (NOLOAD) :
149172
{
150-
_sheap = .;
173+
__sheap = .;
151174
. += _heap_size;
152175
. = ALIGN(4);
153-
_eheap = .;
176+
__eheap = .;
154177
} > REGION_HEAP
155178

156179
/* fictitious region that represents the memory available for the stack */
157180
.stack (NOLOAD) :
158181
{
159-
_estack = .;
182+
__estack = .;
160183
. = ABSOLUTE(_stack_start);
161-
_sstack = .;
184+
__sstack = .;
162185
} > REGION_STACK
163186

164187
/* fake output .got section */
@@ -190,16 +213,16 @@ ERROR(riscv-rt): the start of the REGION_STACK must be 4-byte aligned");
190213
ASSERT(_stext % 4 == 0, "
191214
ERROR(riscv-rt): `_stext` must be 4-byte aligned");
192215

193-
ASSERT(_sdata % ${ARCH_WIDTH} == 0 && _edata % ${ARCH_WIDTH} == 0, "
216+
ASSERT(__sdata % ${ARCH_WIDTH} == 0 && __edata % ${ARCH_WIDTH} == 0, "
194217
BUG(riscv-rt): .data is not ${ARCH_WIDTH}-byte aligned");
195218

196-
ASSERT(_sidata % ${ARCH_WIDTH} == 0, "
219+
ASSERT(__sidata % ${ARCH_WIDTH} == 0, "
197220
BUG(riscv-rt): the LMA of .data is not ${ARCH_WIDTH}-byte aligned");
198221

199-
ASSERT(_sbss % ${ARCH_WIDTH} == 0 && _ebss % ${ARCH_WIDTH} == 0, "
222+
ASSERT(__sbss % ${ARCH_WIDTH} == 0 && __ebss % ${ARCH_WIDTH} == 0, "
200223
BUG(riscv-rt): .bss is not ${ARCH_WIDTH}-byte aligned");
201224

202-
ASSERT(_sheap % 4 == 0, "
225+
ASSERT(__sheap % 4 == 0, "
203226
BUG(riscv-rt): start of .heap is not 4-byte aligned");
204227

205228
ASSERT(_stext + SIZEOF(.text) < ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT), "

riscv-rt/src/asm.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ cfg_global_asm!(
152152
cfg_global_asm!(
153153
"call __pre_init
154154
// Copy .data from flash to RAM
155-
la t0, _sdata
156-
la t2, _edata
157-
la t1, _sidata
155+
la t0, __sdata
156+
la t2, __edata
157+
la t1, __sidata
158158
bgeu t0, t2, 2f
159159
1: ",
160160
#[cfg(target_arch = "riscv32")]
@@ -171,8 +171,8 @@ cfg_global_asm!(
171171
bltu t0, t2, 1b",
172172
"
173173
2: // Zero out .bss
174-
la t0, _sbss
175-
la t2, _ebss
174+
la t0, __sbss
175+
la t2, __ebss
176176
bgeu t0, t2, 4f
177177
3: ",
178178
#[cfg(target_arch = "riscv32")]

0 commit comments

Comments
 (0)