Skip to content

Commit 1134e59

Browse files
dcpleungnashif
authored andcommitted
linker: allow SoC to insert linker script fragments
This allows the SoC to specify some additional linker script fragments into the bss, data and read-only data sections. For example, the Cypress PSOC6 has a few input sections that must be put into bss and data sections. Without specifying these in the linker script, they are consider orphan sections and the placement is based on linker heuristic which is arbitrary. POSIX is not supported as the main linker script is provided by the host system's binutils and we have no control over it. Also, currently Xtensa SoCs have their own linker scripts so there is no need to this feature. Signed-off-by: Daniel Leung <[email protected]>
1 parent 005f6c7 commit 1134e59

File tree

7 files changed

+113
-0
lines changed

7 files changed

+113
-0
lines changed

include/arch/arc/v2/linker.ld

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ SECTIONS {
107107
*(".rodata.*")
108108
*(.gnu.linkonce.r.*)
109109

110+
#ifdef CONFIG_SOC_RODATA_LD
111+
#include <soc-rodata.ld>
112+
#endif
113+
110114
#ifdef CONFIG_CUSTOM_RODATA_LD
111115
/* Located in project source directory */
112116
#include <custom-rodata.ld>
@@ -228,6 +232,10 @@ SECTIONS {
228232
KERNEL_INPUT_SECTION(".noinit.*")
229233
*(".kernel_noinit.*")
230234

235+
#ifdef CONFIG_SOC_NOINIT_LD
236+
#include <soc-noinit.ld>
237+
#endif
238+
231239
} GROUP_LINK_IN(RAMABLE_REGION)
232240

233241
SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,) {
@@ -238,6 +246,10 @@ SECTIONS {
238246
KERNEL_INPUT_SECTION(".data.*")
239247
*(".kernel.*")
240248

249+
#ifdef CONFIG_SOC_RWDATA_LD
250+
#include <soc-rwdata.ld>
251+
#endif
252+
241253
#ifdef CONFIG_CUSTOM_RWDATA_LD
242254
/* Located in project source directory */
243255
#include <custom-rwdata.ld>

include/arch/arm/cortex_m/scripts/linker.ld

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ SECTIONS
163163
*(".rodata.*")
164164
*(.gnu.linkonce.r.*)
165165

166+
#ifdef CONFIG_SOC_RODATA_LD
167+
#include <soc-rodata.ld>
168+
#endif
169+
166170
#ifdef CONFIG_CUSTOM_RODATA_LD
167171
/* Located in project source directory */
168172
#include <custom-rodata.ld>
@@ -330,6 +334,10 @@ SECTIONS
330334
KERNEL_INPUT_SECTION(".noinit.*")
331335
*(".kernel_noinit.*")
332336

337+
#ifdef CONFIG_SOC_NOINIT_LD
338+
#include <soc-noinit.ld>
339+
#endif
340+
333341
} GROUP_LINK_IN(RAMABLE_REGION)
334342

335343
SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,)
@@ -339,6 +347,10 @@ SECTIONS
339347
KERNEL_INPUT_SECTION(".data.*")
340348
*(".kernel.*")
341349

350+
#ifdef CONFIG_SOC_RWDATA_LD
351+
#include <soc-rwdata.ld>
352+
#endif
353+
342354
#ifdef CONFIG_CUSTOM_RWDATA_LD
343355
/* Located in project source directory */
344356
#include <custom-rwdata.ld>

include/arch/nios2/linker.ld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ SECTIONS
128128
*(".rodata.*")
129129
*(.gnu.linkonce.r.*)
130130

131+
#ifdef CONFIG_SOC_RODATA_LD
132+
#include <soc-rodata.ld>
133+
#endif
134+
131135
#ifdef CONFIG_CUSTOM_RODATA_LD
132136
/* Located in project source directory */
133137
#include <custom-rodata.ld>
@@ -174,6 +178,10 @@ SECTIONS
174178
*(.data)
175179
*(".data.*")
176180

181+
#ifdef CONFIG_SOC_RWDATA_LD
182+
#include <soc-rwdata.ld>
183+
#endif
184+
177185
#ifdef CONFIG_CUSTOM_RWDATA_LD
178186
/* Located in project source directory */
179187
#include <custom-rwdata.ld>
@@ -231,6 +239,11 @@ SECTIONS
231239
*/
232240
*(.noinit)
233241
*(".noinit.*")
242+
243+
#ifdef CONFIG_SOC_NOINIT_LD
244+
#include <soc-noinit.ld>
245+
#endif
246+
234247
} GROUP_LINK_IN(RAMABLE_REGION)
235248

236249
/* Define linker symbols */

include/arch/riscv32/common/linker.ld

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ SECTIONS
9696
*(.rodata)
9797
*(".rodata.*")
9898
*(.gnu.linkonce.r.*)
99+
100+
#ifdef CONFIG_SOC_RODATA_LD
101+
#include <soc-rodata.ld>
102+
#endif
103+
99104
} GROUP_LINK_IN(ROMABLE_REGION)
100105

101106
_image_rom_end = .;
@@ -117,6 +122,10 @@ SECTIONS
117122
*(.sdata .sdata.* .gnu.linkonce.s.*)
118123
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
119124

125+
#ifdef CONFIG_SOC_RWDATA_LD
126+
#include <soc-rwdata.ld>
127+
#endif
128+
120129
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
121130

122131
#include <linker/common-ram.ld>
@@ -151,6 +160,11 @@ SECTIONS
151160
*/
152161
*(.noinit)
153162
*(".noinit.*")
163+
164+
#ifdef CONFIG_SOC_NOINIT_LD
165+
#include <soc-noinit.ld>
166+
#endif
167+
154168
} GROUP_LINK_IN(RAMABLE_REGION)
155169

156170
_image_ram_end = .;

include/arch/riscv32/pulpino/linker.ld

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ SECTIONS
9090
*(.rodata)
9191
*(".rodata.*")
9292
*(.gnu.linkonce.r.*)
93+
94+
#ifdef CONFIG_SOC_RODATA_LD
95+
#include <soc-rodata.ld>
96+
#endif
97+
9398
} GROUP_LINK_IN(RAMABLE_REGION)
9499

95100
_image_ram_start = .;
@@ -106,6 +111,10 @@ SECTIONS
106111
*(.sdata .sdata.* .gnu.linkonce.s.*)
107112
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
108113

114+
#ifdef CONFIG_SOC_RWDATA_LD
115+
#include <soc-rwdata.ld>
116+
#endif
117+
109118
} GROUP_LINK_IN(RAMABLE_REGION)
110119

111120
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
@@ -136,6 +145,11 @@ SECTIONS
136145
*/
137146
*(.noinit)
138147
*(".noinit.*")
148+
149+
#ifdef CONFIG_SOC_NOINIT_LD
150+
#include <soc-noinit.ld>
151+
#endif
152+
139153
} GROUP_LINK_IN(RAMABLE_REGION)
140154

141155
_image_ram_end = .;

include/arch/x86/linker.ld

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ SECTIONS
132132
#endif
133133
#endif
134134

135+
#ifdef CONFIG_SOC_RODATA_LD
136+
#include <soc-rodata.ld>
137+
#endif
138+
135139
#ifdef CONFIG_CUSTOM_RODATA_LD
136140
/* Located in project source directory */
137141
#include <custom-rodata.ld>
@@ -244,6 +248,10 @@ SECTIONS
244248
KERNEL_INPUT_SECTION(".noinit.*")
245249
*(".kernel_noinit.*")
246250

251+
#ifdef CONFIG_SOC_NOINIT_LD
252+
#include <soc-noinit.ld>
253+
#endif
254+
247255
MMU_PAGE_ALIGN
248256

249257
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
@@ -257,6 +265,10 @@ SECTIONS
257265
KERNEL_INPUT_SECTION(".data.*")
258266
*(".kernel.*")
259267

268+
#ifdef CONFIG_SOC_RWDATA_LD
269+
#include <soc-rwdata.ld>
270+
#endif
271+
260272
#ifdef CONFIG_CUSTOM_RWDATA_LD
261273
/* Located in project source directory */
262274
#include <custom-rwdata.ld>

soc/Kconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,39 @@ config SOC_COMPATIBLE_NRF52X
2929

3030
config SOC_COMPATIBLE_NRF52832
3131
bool
32+
33+
#
34+
# SOC_*_LD: SoC specific Linker script additions
35+
#
36+
config SOC_NOINIT_LD
37+
bool
38+
depends on (ARC || ARM || X86 || NIOS2 || RISCV32)
39+
help
40+
Include an SoC specific linker script fragment named soc-noinit.ld
41+
for inserting additional data and linker directives into
42+
the noinit section.
43+
44+
This only has effect if the SoC uses the common linker script
45+
under include/arch/.
46+
47+
config SOC_RODATA_LD
48+
bool
49+
depends on (ARC || ARM || X86 || NIOS2 || RISCV32)
50+
help
51+
Include an SoC specific linker script fragment named soc-rodata.ld
52+
for inserting additional data and linker directives into
53+
the rodata section.
54+
55+
This only has effect if the SoC uses the common linker script
56+
under include/arch/.
57+
58+
config SOC_RWDATA_LD
59+
bool
60+
depends on (ARC || ARM || X86 || NIOS2 || RISCV32)
61+
help
62+
Include an SoC specific linker script fragment named soc-rwdata.ld
63+
for inserting additional data and linker directives into
64+
the data section.
65+
66+
This only has effect if the SoC uses the common linker script
67+
under include/arch/.

0 commit comments

Comments
 (0)