]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/scripttempl/elf.sc
Fix formatting
[thirdparty/binutils-gdb.git] / ld / scripttempl / elf.sc
CommitLineData
252b5132
RH
1#
2# Unusual variables checked by this code:
3# NOP - two byte opcode for no-op (defaults to 0)
4# DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
5# INITIAL_READONLY_SECTIONS - at start of text segment
6# OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
7# (e.g., .PARISC.milli)
8# OTHER_TEXT_SECTIONS - these get put in .text when relocating
9# OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
10# (e.g., .PARISC.global)
904ecb2d 11# OTHER_BSS_SECTIONS - other than .bss .sbss ...
252b5132
RH
12# OTHER_SECTIONS - at the end
13# EXECUTABLE_SYMBOLS - symbols that must be defined for an
14# executable (e.g., _DYNAMIC_LINK)
15# TEXT_START_SYMBOLS - symbols that appear at the start of the
16# .text section.
17# DATA_START_SYMBOLS - symbols that appear at the start of the
18# .data section.
19# OTHER_GOT_SYMBOLS - symbols defined just before .got.
20# OTHER_GOT_SECTIONS - sections just after .got and .sdata.
21# OTHER_BSS_SYMBOLS - symbols that appear at the start of the
22# .bss section besides __bss_start.
23# DATA_PLT - .plt should be in data segment, not text segment.
6c86c541 24# BSS_PLT - .plt should be in bss segment
252b5132
RH
25# TEXT_DYNAMIC - .dynamic in text segment, not data segment.
26# EMBEDDED - whether this is for an embedded system.
27# SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
28# start address of shared library.
29# INPUT_FILES - INPUT command of files to always include
a8e53fb0 30# WRITABLE_RODATA - if set, the .rodata section should be writable
904ecb2d
JL
31# INIT_START, INIT_END - statements just before and just after
32# combination of .init sections.
33# FINI_START, FINI_END - statements just before and just after
34# combination of .fini sections.
252b5132
RH
35#
36# When adding sections, do note that the names of some sections are used
37# when specifying the start address of the next.
38#
39
d73e9da0
AS
40# Many sections come in three flavours. There is the 'real' section,
41# like ".data". Then there are the per-procedure or per-variable
42# sections, generated by -ffunction-sections and -fdata-sections in GCC,
43# and useful for --gc-sections, which for a variable "foo" might be
44# ".data.foo". Then there are the linkonce sections, for which the linker
45# eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
46# The exact correspondences are:
47#
48# Section Linkonce section
49# .text .gnu.linkonce.t.foo
50# .rodata .gnu.linkonce.r.foo
51# .data .gnu.linkonce.d.foo
52# .bss .gnu.linkonce.b.foo
53# .sdata .gnu.linkonce.s.foo
54# .sbss .gnu.linkonce.sb.foo
55# .sdata2 .gnu.linkonce.s2.foo
56# .sbss2 .gnu.linkonce.sb2.foo
57#
58# Each of these can also have corresponding .rel.* and .rela.* sections.
9ac4db9c 59
252b5132
RH
60test -z "$ENTRY" && ENTRY=_start
61test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
62test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
63if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
64test -z "${ELFSIZE}" && ELFSIZE=32
65test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
66test "$LD_FLAG" = "N" && DATA_ADDR=.
67INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
68PLT=".plt ${RELOCATING-0} : { *(.plt) }"
63653551 69DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
9ac4db9c
GK
70RODATA=".rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)} }"
71SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2) ${RELOCATING+*(.sbss2.*)} ${RELOCATING+*(.gnu.linkonce.sb2.*)} }"
72SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2) ${RELOCATING+*(.sdata2.*)} ${RELOCATING+*(.gnu.linkonce.s2.*)} }"
252b5132
RH
73CTOR=".ctors ${CONSTRUCTING-0} :
74 {
75 ${CONSTRUCTING+${CTOR_START}}
76 /* gcc uses crtbegin.o to find the start of
77 the constructors, so we make sure it is
78 first. Because this is a wildcard, it
79 doesn't matter if the user does not
80 actually link against crtbegin.o; the
81 linker won't look for a file to match a
82 wildcard. The wildcard also means that it
83 doesn't matter which directory crtbegin.o
84 is in. */
85
86 KEEP (*crtbegin.o(.ctors))
87
88 /* We don't want to include the .ctor section from
89 from the crtend.o file until after the sorted ctors.
90 The .ctor section from the crtend file contains the
91 end of ctors marker and it must be last */
92
18625d54 93 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .ctors))
252b5132
RH
94 KEEP (*(SORT(.ctors.*)))
95 KEEP (*(.ctors))
96 ${CONSTRUCTING+${CTOR_END}}
97 }"
98
99DTOR=" .dtors ${CONSTRUCTING-0} :
100 {
101 ${CONSTRUCTING+${DTOR_START}}
102 KEEP (*crtbegin.o(.dtors))
18625d54 103 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .dtors))
252b5132
RH
104 KEEP (*(SORT(.dtors.*)))
105 KEEP (*(.dtors))
106 ${CONSTRUCTING+${DTOR_END}}
107 }"
108
109# if this is for an embedded system, don't add SIZEOF_HEADERS.
110if [ -z "$EMBEDDED" ]; then
111 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
112else
113 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
114fi
115
116cat <<EOF
117OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
118 "${LITTLE_OUTPUT_FORMAT}")
119OUTPUT_ARCH(${OUTPUT_ARCH})
120ENTRY(${ENTRY})
121
122${RELOCATING+${LIB_SEARCH_DIRS}}
123${RELOCATING+/* Do we need any of these for elf?
124 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
125${RELOCATING+${EXECUTABLE_SYMBOLS}}
126${RELOCATING+${INPUT_FILES}}
127${RELOCATING- /* For some reason, the Solaris linker makes bad executables
128 if gld -r is used and the intermediate file has sections starting
129 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
130 bug. But for now assigning the zero vmas works. */}
131
132SECTIONS
133{
134 /* Read-only sections, merged into text segment: */
135 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
136 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
137 ${CREATE_SHLIB-${INTERP}}
138 ${INITIAL_READONLY_SECTIONS}
139 ${TEXT_DYNAMIC+${DYNAMIC}}
140 .hash ${RELOCATING-0} : { *(.hash) }
141 .dynsym ${RELOCATING-0} : { *(.dynsym) }
142 .dynstr ${RELOCATING-0} : { *(.dynstr) }
143 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
144 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
145 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
9e4141bc 146
4ab10e93
GK
147 .rel.init ${RELOCATING-0} : { *(.rel.init) }
148 .rela.init ${RELOCATING-0} : { *(.rela.init) }
252b5132
RH
149 .rel.text ${RELOCATING-0} :
150 {
151 *(.rel.text)
152 ${RELOCATING+*(.rel.text.*)}
9ac4db9c 153 ${RELOCATING+*(.rel.gnu.linkonce.t.*)}
252b5132
RH
154 }
155 .rela.text ${RELOCATING-0} :
156 {
157 *(.rela.text)
158 ${RELOCATING+*(.rela.text.*)}
9ac4db9c 159 ${RELOCATING+*(.rela.gnu.linkonce.t.*)}
252b5132 160 }
9e4141bc
RH
161 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
162 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
252b5132
RH
163 .rel.rodata ${RELOCATING-0} :
164 {
165 *(.rel.rodata)
166 ${RELOCATING+*(.rel.rodata.*)}
9ac4db9c 167 ${RELOCATING+*(.rel.gnu.linkonce.r.*)}
252b5132
RH
168 }
169 .rela.rodata ${RELOCATING-0} :
170 {
171 *(.rela.rodata)
172 ${RELOCATING+*(.rela.rodata.*)}
9ac4db9c 173 ${RELOCATING+*(.rela.gnu.linkonce.r.*)}
252b5132 174 }
9e4141bc
RH
175 ${OTHER_READONLY_RELOC_SECTIONS}
176 .rel.data ${RELOCATING-0} :
177 {
178 *(.rel.data)
179 ${RELOCATING+*(.rel.data.*)}
9ac4db9c 180 ${RELOCATING+*(.rel.gnu.linkonce.d.*)}
9e4141bc
RH
181 }
182 .rela.data ${RELOCATING-0} :
183 {
184 *(.rela.data)
185 ${RELOCATING+*(.rela.data.*)}
9ac4db9c 186 ${RELOCATING+*(.rela.gnu.linkonce.d.*)}
9e4141bc 187 }
252b5132
RH
188 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
189 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
190 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
191 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
9e4141bc
RH
192 .rel.got ${RELOCATING-0} : { *(.rel.got) }
193 .rela.got ${RELOCATING-0} : { *(.rela.got) }
194 ${OTHER_GOT_RELOC_SECTIONS}
cfd0966c
GK
195 .rel.sdata ${RELOCATING-0} :
196 {
197 *(.rel.sdata)
198 ${RELOCATING+*(.rel.sdata.*)}
9ac4db9c 199 ${RELOCATING+*(.rel.gnu.linkonce.s.*)}
cfd0966c
GK
200 }
201 .rela.sdata ${RELOCATING-0} :
202 {
203 *(.rela.sdata)
204 ${RELOCATING+*(.rela.sdata.*)}
9ac4db9c
GK
205 ${RELOCATING+*(.rela.gnu.linkonce.s.*)}
206 }
207 .rel.sbss ${RELOCATING-0} :
208 {
209 *(.rel.sbss)
210 ${RELOCATING+*(.rel.sbss.*)}
211 ${RELOCATING+*(.rel.gnu.linkonce.sb.*)}
212 }
213 .rela.sbss ${RELOCATING-0} :
214 {
215 *(.rela.sbss)
216 ${RELOCATING+*(.rela.sbss.*)}
217 ${RELOCATING+*(.rel.gnu.linkonce.sb.*)}
218 }
219 .rel.sdata2 ${RELOCATING-0} :
220 {
221 *(.rel.sdata2)
222 ${RELOCATING+*(.rel.sdata2.*)}
223 ${RELOCATING+*(.rel.gnu.linkonce.s2.*)}
224 }
225 .rela.sdata2 ${RELOCATING-0} :
226 {
227 *(.rela.sdata2)
228 ${RELOCATING+*(.rela.sdata2.*)}
229 ${RELOCATING+*(.rela.gnu.linkonce.s2.*)}
230 }
231 .rel.sbss2 ${RELOCATING-0} :
232 {
233 *(.rel.sbss2)
234 ${RELOCATING+*(.rel.sbss2.*)}
235 ${RELOCATING+*(.rel.gnu.linkonce.sb2.*)}
236 }
237 .rela.sbss2 ${RELOCATING-0} :
238 {
239 *(.rela.sbss2)
240 ${RELOCATING+*(.rela.sbss2.*)}
241 ${RELOCATING+*(.rela.gnu.linkonce.sb2.*)}
242 }
243 .rel.bss ${RELOCATING-0} :
244 {
245 *(.rel.bss)
246 ${RELOCATING+*(.rel.bss.*)}
247 ${RELOCATING+*(.rel.gnu.linkonce.b.*)}
248 }
249 .rela.bss ${RELOCATING-0} :
250 {
251 *(.rela.bss)
252 ${RELOCATING+*(.rela.bss.*)}
253 ${RELOCATING+*(.rela.gnu.linkonce.b.*)}
cfd0966c 254 }
252b5132
RH
255 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
256 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
9e673ad1 257 ${OTHER_PLT_RELOC_SECTIONS}
9e4141bc 258
4ab10e93
GK
259 .init ${RELOCATING-0} :
260 {
53db15ed 261 ${RELOCATING+${INIT_START}}
4ab10e93 262 KEEP (*(.init))
53db15ed 263 ${RELOCATING+${INIT_END}}
4ab10e93
GK
264 } =${NOP-0}
265
6c86c541 266 ${DATA_PLT-${BSS_PLT-${PLT}}}
252b5132
RH
267 .text ${RELOCATING-0} :
268 {
269 ${RELOCATING+${TEXT_START_SYMBOLS}}
270 *(.text)
271 ${RELOCATING+*(.text.*)}
272 *(.stub)
273 /* .gnu.warning sections are handled specially by elf32.em. */
274 *(.gnu.warning)
9ac4db9c 275 ${RELOCATING+*(.gnu.linkonce.t.*)}
252b5132
RH
276 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
277 } =${NOP-0}
904ecb2d
JL
278 .fini ${RELOCATING-0} :
279 {
53db15ed 280 ${RELOCATING+${FINI_START}}
904ecb2d 281 KEEP (*(.fini))
53db15ed 282 ${RELOCATING+${FINI_END}}
904ecb2d 283 } =${NOP-0}
6c86c541
GK
284 ${RELOCATING+PROVIDE (__etext = .);}
285 ${RELOCATING+PROVIDE (_etext = .);}
286 ${RELOCATING+PROVIDE (etext = .);}
a8e53fb0 287 ${WRITABLE_RODATA-${RODATA}}
252b5132 288 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
6c86c541
GK
289 ${CREATE_SHLIB-${SDATA2}}
290 ${CREATE_SHLIB-${SBSS2}}
252b5132
RH
291 ${RELOCATING+${OTHER_READONLY_SECTIONS}}
292
293 /* Adjust the address for the data segment. We want to adjust up to
294 the same address within the page on the next page up. */
295 ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
296 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
297
298 .data ${RELOCATING-0} :
299 {
300 ${RELOCATING+${DATA_START_SYMBOLS}}
301 *(.data)
302 ${RELOCATING+*(.data.*)}
9ac4db9c 303 ${RELOCATING+*(.gnu.linkonce.d.*)}
252b5132
RH
304 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
305 }
306 .data1 ${RELOCATING-0} : { *(.data1) }
987fd5b4 307 .eh_frame : { KEEP (*(.eh_frame)) }
252b5132 308 .gcc_except_table : { *(.gcc_except_table) }
a8e53fb0 309 ${WRITABLE_RODATA+${RODATA}}
252b5132
RH
310 ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
311 ${RELOCATING+${CTOR}}
312 ${RELOCATING+${DTOR}}
313 ${DATA_PLT+${PLT}}
314 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
6c86c541
GK
315 .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
316 ${CREATE_SHLIB+${SDATA2}}
317 ${CREATE_SHLIB+${SBSS2}}
252b5132
RH
318 ${TEXT_DYNAMIC-${DYNAMIC}}
319 /* We want the small data sections together, so single-instruction offsets
320 can access them all, and initialized data all before uninitialized, so
321 we can shorten the on-disk segment size. */
cfd0966c
GK
322 .sdata ${RELOCATING-0} :
323 {
324 ${RELOCATING+${SDATA_START_SYMBOLS}}
325 *(.sdata)
326 ${RELOCATING+*(.sdata.*)}
327 ${RELOCATING+*(.gnu.linkonce.s.*)}
328 }
252b5132 329 ${RELOCATING+${OTHER_GOT_SECTIONS}}
9e4141bc 330 ${RELOCATING+_edata = .;}
252b5132
RH
331 ${RELOCATING+PROVIDE (edata = .);}
332 ${RELOCATING+__bss_start = .;}
333 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
3c9cf3a3
NC
334 .sbss ${RELOCATING-0} :
335 {
6c86c541
GK
336 ${RELOCATING+PROVIDE (__sbss_start = .);}
337 ${RELOCATING+PROVIDE (___sbss_start = .);}
cfd0966c
GK
338 *(.dynsbss)
339 *(.sbss)
340 ${RELOCATING+*(.sbss.*)}
9ac4db9c 341 ${RELOCATING+*(.gnu.linkonce.sb.*)}
cfd0966c 342 *(.scommon)
6c86c541
GK
343 ${RELOCATING+PROVIDE (__sbss_end = .);}
344 ${RELOCATING+PROVIDE (___sbss_end = .);}
3c9cf3a3 345 }
6c86c541 346 ${BSS_PLT+${PLT}}
252b5132
RH
347 .bss ${RELOCATING-0} :
348 {
349 *(.dynbss)
350 *(.bss)
3c9cf3a3 351 ${RELOCATING+*(.bss.*)}
9ac4db9c 352 ${RELOCATING+*(.gnu.linkonce.b.*)}
252b5132
RH
353 *(COMMON)
354 /* Align here to ensure that the .bss section occupies space up to
355 _end. Align after .bss to ensure correct alignment even if the
356 .bss section disappears because there are no input sections. */
357 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
358 }
904ecb2d 359 ${RELOCATING+${OTHER_BSS_SECTIONS}}
252b5132 360 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
9e4141bc 361 ${RELOCATING+_end = .;}
252b5132
RH
362 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
363 ${RELOCATING+PROVIDE (end = .);}
364
365 /* Stabs debugging sections. */
366 .stab 0 : { *(.stab) }
367 .stabstr 0 : { *(.stabstr) }
368 .stab.excl 0 : { *(.stab.excl) }
369 .stab.exclstr 0 : { *(.stab.exclstr) }
370 .stab.index 0 : { *(.stab.index) }
371 .stab.indexstr 0 : { *(.stab.indexstr) }
372
373 .comment 0 : { *(.comment) }
374
375 /* DWARF debug sections.
376 Symbols in the DWARF debugging sections are relative to the beginning
377 of the section so we begin them at 0. */
378
379 /* DWARF 1 */
380 .debug 0 : { *(.debug) }
381 .line 0 : { *(.line) }
382
383 /* GNU DWARF 1 extensions */
384 .debug_srcinfo 0 : { *(.debug_srcinfo) }
385 .debug_sfnames 0 : { *(.debug_sfnames) }
386
387 /* DWARF 1.1 and DWARF 2 */
388 .debug_aranges 0 : { *(.debug_aranges) }
389 .debug_pubnames 0 : { *(.debug_pubnames) }
390
391 /* DWARF 2 */
3a9d486c 392 .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
252b5132
RH
393 .debug_abbrev 0 : { *(.debug_abbrev) }
394 .debug_line 0 : { *(.debug_line) }
395 .debug_frame 0 : { *(.debug_frame) }
396 .debug_str 0 : { *(.debug_str) }
397 .debug_loc 0 : { *(.debug_loc) }
398 .debug_macinfo 0 : { *(.debug_macinfo) }
399
400 /* SGI/MIPS DWARF 2 extensions */
401 .debug_weaknames 0 : { *(.debug_weaknames) }
402 .debug_funcnames 0 : { *(.debug_funcnames) }
403 .debug_typenames 0 : { *(.debug_typenames) }
404 .debug_varnames 0 : { *(.debug_varnames) }
405
406 ${RELOCATING+${OTHER_RELOCATING_SECTIONS}}
407
408 /* These must appear regardless of ${RELOCATING}. */
409 ${OTHER_SECTIONS}
410}
411EOF