Skip to content

Commit 988562e

Browse files
committed
riscv: Fix initialized data
Startup script has only one loop that copies initialized data and code that should execute from RAM. It implies that variables in .data .ram_text .srodata .sdata and such has same layout in flash and in RAM. Those data are packed by default in flash so output sections (.data .srodata .sdata) if they start with something that requires alignment change may end up with wrong data being copied to statically initialized data. One way to prevent such case is to copy each output section in separate loop. But it is also possibly to add output section attribute ALIGN_WITH_INPUT and then linker will fill necessary space in flash image.
1 parent 532a643 commit 988562e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

hw/bsp/hifive1/hifive1.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ SECTIONS
128128
PROVIDE( _data = . );
129129
} >ram AT>flash
130130

131-
.data :
131+
.data : ALIGN_WITH_INPUT
132132
{
133133
*(.ram_text, .ram_text.*)
134134
*(.data .data.*)
135135
*(.gnu.linkonce.d.*)
136136
} >ram AT>flash
137137

138-
.srodata :
138+
.srodata : ALIGN_WITH_INPUT
139139
{
140140
PROVIDE( _gp = . + 0x800 );
141141
PROVIDE( __global_pointer$ = _gp);
@@ -146,7 +146,7 @@ SECTIONS
146146
*(.srodata .srodata.*)
147147
} >ram AT>flash
148148

149-
.sdata :
149+
.sdata : ALIGN_WITH_INPUT
150150
{
151151
*(.sdata .sdata.*)
152152
*(.gnu.linkonce.s.*)

0 commit comments

Comments
 (0)