2 # Unusual variables checked by this code:
3 # NOP - four byte opcode for no-op (defaults to 0)
4 # NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
6 # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
7 # INITIAL_READONLY_SECTIONS - at start of text segment
8 # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
9 # (e.g., .PARISC.milli)
10 # OTHER_TEXT_SECTIONS - these get put in .text when relocating
11 # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
12 # (e.g., .PARISC.global)
13 # OTHER_RELRO_SECTIONS - other than .data.rel.ro ...
14 # (e.g. PPC32 .fixup, .got[12])
15 # OTHER_BSS_SECTIONS - other than .bss .sbss ...
16 # OTHER_SECTIONS - at the end
17 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
18 # executable (e.g., _DYNAMIC_LINK)
19 # TEXT_START_SYMBOLS - symbols that appear at the start of the
21 # DATA_START_SYMBOLS - symbols that appear at the start of the
23 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
24 # OTHER_GOT_SECTIONS - sections just after .got.
25 # OTHER_SDATA_SECTIONS - sections just after .sdata.
26 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
27 # .bss section besides __bss_start.
28 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
29 # EMBEDDED - whether this is for an embedded system.
30 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
31 # start address of shared library.
32 # INPUT_FILES - INPUT command of files to always include
33 # WRITABLE_RODATA - if set, the .rodata section should be writable
34 # INIT_START, INIT_END - statements just before and just after
35 # combination of .init sections.
36 # FINI_START, FINI_END - statements just before and just after
37 # combination of .fini sections.
38 # STACK_ADDR - start of a .stack section.
39 # OTHER_END_SYMBOLS - symbols to place right at the end of the script.
41 # When adding sections, do note that the names of some sections are used
42 # when specifying the start address of the next.
45 # Many sections come in three flavours. There is the 'real' section,
46 # like ".data". Then there are the per-procedure or per-variable
47 # sections, generated by -ffunction-sections and -fdata-sections in GCC,
48 # and useful for --gc-sections, which for a variable "foo" might be
49 # ".data.foo". Then there are the linkonce sections, for which the linker
50 # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
51 # The exact correspondences are:
53 # Section Linkonce section
54 # .text .gnu.linkonce.t.foo
55 # .rodata .gnu.linkonce.r.foo
56 # .data .gnu.linkonce.d.foo
57 # .bss .gnu.linkonce.b.foo
58 # .sdata .gnu.linkonce.s.foo
59 # .sbss .gnu.linkonce.sb.foo
60 # .sdata2 .gnu.linkonce.s2.foo
61 # .sbss2 .gnu.linkonce.sb2.foo
62 # .debug_info .gnu.linkonce.wi.foo
63 # .tdata .gnu.linkonce.td.foo
64 # .tbss .gnu.linkonce.tb.foo
66 # Each of these can also have corresponding .rel.* and .rela.* sections.
68 test -z "$ENTRY" && ENTRY=_start
69 test -z "${ELFSIZE}" && ELFSIZE=32
70 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
71 test "$LD_FLAG" = "N" && DATA_ADDR=.
72 test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
73 test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
74 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
75 DATA_SEGMENT_RELRO_END=""
77 if test -n "${COMMONPAGESIZE}"; then
78 DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
79 DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
80 DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (.);"
82 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
83 if test -z "$GOT"; then
84 GOT=".got ${RELOCATING-0} : { *(.got) }"
86 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
87 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
88 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro*) }"
89 STACKNOTE="/DISCARD/ : { *(.note.GNU-stack) }"
90 INIT_LIT=".init.literal 0 : { *(.init.literal) }"
91 INIT=".init 0 : { *(.init) }"
92 FINI_LIT=".fini.literal 0 : { *(.fini.literal) }"
93 FINI=".fini 0 : { *(.fini) }"
94 if test -z "${NO_SMALL_DATA}"; then
95 SBSS=".sbss ${RELOCATING-0} :
97 ${RELOCATING+PROVIDE (__sbss_start = .);}
98 ${RELOCATING+PROVIDE (___sbss_start = .);}
100 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
102 ${RELOCATING+PROVIDE (__sbss_end = .);}
103 ${RELOCATING+PROVIDE (___sbss_end = .);}
105 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
106 SDATA="/* We want the small data sections together, so single-instruction offsets
107 can access them all, and initialized data all before uninitialized, so
108 we can shorten the on-disk segment size. */
109 .sdata ${RELOCATING-0} :
111 ${RELOCATING+${SDATA_START_SYMBOLS}}
112 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
114 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }"
115 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
116 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
117 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
118 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
119 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
120 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
121 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
122 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
126 CTOR=".ctors ${CONSTRUCTING-0} :
128 ${CONSTRUCTING+${CTOR_START}}
129 /* gcc uses crtbegin.o to find the start of
130 the constructors, so we make sure it is
131 first. Because this is a wildcard, it
132 doesn't matter if the user does not
133 actually link against crtbegin.o; the
134 linker won't look for a file to match a
135 wildcard. The wildcard also means that it
136 doesn't matter which directory crtbegin.o
139 KEEP (*crtbegin*.o(.ctors))
141 /* We don't want to include the .ctor section from
142 from the crtend.o file until after the sorted ctors.
143 The .ctor section from the crtend file contains the
144 end of ctors marker and it must be last */
146 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
147 KEEP (*(SORT(.ctors.*)))
149 ${CONSTRUCTING+${CTOR_END}}
151 DTOR=".dtors ${CONSTRUCTING-0} :
153 ${CONSTRUCTING+${DTOR_START}}
154 KEEP (*crtbegin*.o(.dtors))
155 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
156 KEEP (*(SORT(.dtors.*)))
158 ${CONSTRUCTING+${DTOR_END}}
160 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
162 ${RELOCATING+_stack = .;}
166 # if this is for an embedded system, don't add SIZEOF_HEADERS.
167 if [ -z "$EMBEDDED" ]; then
168 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
170 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
176 ${RELOCATING+${LIB_SEARCH_DIRS}}
177 ${RELOCATING+/* Do we need any of these for elf?
178 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
179 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
180 ${RELOCATING+${INPUT_FILES}}
181 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
182 if gld -r is used and the intermediate file has sections starting
183 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
184 bug. But for now assigning the zero vmas works. */}
188 /* Read-only sections, merged into text segment: */
189 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
190 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
191 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
192 ${CREATE_SHLIB-${INTERP}}
193 ${INITIAL_READONLY_SECTIONS}
194 ${TEXT_DYNAMIC+${DYNAMIC}}
195 .hash ${RELOCATING-0} : { *(.hash) }
196 .dynsym ${RELOCATING-0} : { *(.dynsym) }
197 .dynstr ${RELOCATING-0} : { *(.dynstr) }
198 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
199 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
200 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
203 if [ "x$COMBRELOC" = x ]; then
206 COMBRELOCCAT="cat > $COMBRELOC"
208 eval $COMBRELOCCAT <<EOF
209 .rel.init ${RELOCATING-0} : { *(.rel.init) }
210 .rela.init ${RELOCATING-0} : { *(.rela.init) }
211 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
212 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
213 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
214 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
215 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
216 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
217 ${OTHER_READONLY_RELOC_SECTIONS}
218 .rel.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+*}) }
219 .rela.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+*}) }
220 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
221 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
222 .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
223 .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
224 .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
225 .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
226 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
227 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
228 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
229 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
230 .rel.got ${RELOCATING-0} : { *(.rel.got) }
231 .rela.got ${RELOCATING-0} : { *(.rela.got) }
232 ${OTHER_GOT_RELOC_SECTIONS}
237 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
238 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
240 if [ -n "$COMBRELOC" ]; then
242 .rel.dyn ${RELOCATING-0} :
245 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
248 .rela.dyn ${RELOCATING-0} :
251 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
257 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
258 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
259 ${OTHER_PLT_RELOC_SECTIONS}
261 ${RELOCATING-$INIT_LIT}
264 .text ${RELOCATING-0} :
268 ${RELOCATING+${INIT_START}}
269 ${RELOCATING+KEEP (*(.init.literal))}
270 ${RELOCATING+KEEP (*(.init))}
271 ${RELOCATING+${INIT_END}}
273 ${RELOCATING+${TEXT_START_SYMBOLS}}
274 *(.literal .text .stub${RELOCATING+ .text.* .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*})
275 KEEP (*(.text.*personality*))
276 /* .gnu.warning sections are handled specially by elf32.em. */
278 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
280 ${RELOCATING+${FINI_START}}
281 ${RELOCATING+KEEP (*(.fini.literal))}
282 ${RELOCATING+KEEP (*(.fini))}
283 ${RELOCATING+${FINI_END}}
286 ${RELOCATING-$FINI_LIT}
289 ${RELOCATING+PROVIDE (__etext = .);}
290 ${RELOCATING+PROVIDE (_etext = .);}
291 ${RELOCATING+PROVIDE (etext = .);}
292 ${WRITABLE_RODATA-${RODATA}}
293 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
294 ${CREATE_SHLIB-${SDATA2}}
295 ${CREATE_SHLIB-${SBSS2}}
296 ${OTHER_READONLY_SECTIONS}
297 .eh_frame_hdr : { *(.eh_frame_hdr) }
298 .eh_frame ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
299 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
301 /* Adjust the address for the data segment. We want to adjust up to
302 the same address within the page on the next page up. */
303 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
304 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
305 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
307 /* Exception handling */
308 .eh_frame ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
309 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
311 /* Thread Local Storage sections */
312 .tdata ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
313 .tbss ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
315 /* Ensure the __preinit_array_start label is properly aligned. We
316 could instead move the label definition inside the section, but
317 the linker would then create the section even if it turns out to
318 be empty, which isn't pretty. */
319 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
320 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
321 .preinit_array ${RELOCATING-0} : { KEEP (*(.preinit_array)) }
322 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
324 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
325 .init_array ${RELOCATING-0} : { KEEP (*(.init_array)) }
326 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
328 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
329 .fini_array ${RELOCATING-0} : { KEEP (*(.fini_array)) }
330 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
332 ${RELOCATING+${CTOR}}
333 ${RELOCATING+${DTOR}}
334 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
336 ${RELOCATING+${DATARELRO}}
337 ${OTHER_RELRO_SECTIONS}
338 ${TEXT_DYNAMIC-${DYNAMIC}}
339 ${NO_SMALL_DATA+${GOT}}
340 ${RELOCATING+${DATA_SEGMENT_RELRO_END}}
342 .data ${RELOCATING-0} :
344 ${RELOCATING+${DATA_START_SYMBOLS}}
345 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
346 KEEP (*(.gnu.linkonce.d.*personality*))
347 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
349 .data1 ${RELOCATING-0} : { *(.data1) }
350 ${WRITABLE_RODATA+${RODATA}}
351 ${OTHER_READWRITE_SECTIONS}
352 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
353 ${NO_SMALL_DATA-${GOT}}
354 ${OTHER_GOT_SECTIONS}
355 ${CREATE_SHLIB+${SDATA2}}
356 ${CREATE_SHLIB+${SBSS2}}
358 ${OTHER_SDATA_SECTIONS}
359 ${RELOCATING+_edata = .;}
360 ${RELOCATING+PROVIDE (edata = .);}
361 ${RELOCATING+__bss_start = .;}
362 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
364 .bss ${RELOCATING-0} :
367 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
369 /* Align here to ensure that the .bss section occupies space up to
370 _end. Align after .bss to ensure correct alignment even if the
371 .bss section disappears because there are no input sections. */
372 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
374 ${OTHER_BSS_SECTIONS}
375 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
376 ${RELOCATING+_end = .;}
377 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
378 ${RELOCATING+PROVIDE (end = .);}
379 ${RELOCATING+${DATA_SEGMENT_END}}
381 /* Stabs debugging sections. */
382 .stab 0 : { *(.stab) }
383 .stabstr 0 : { *(.stabstr) }
384 .stab.excl 0 : { *(.stab.excl) }
385 .stab.exclstr 0 : { *(.stab.exclstr) }
386 .stab.index 0 : { *(.stab.index) }
387 .stab.indexstr 0 : { *(.stab.indexstr) }
389 .comment 0 : { *(.comment) }
391 /* DWARF debug sections.
392 Symbols in the DWARF debugging sections are relative to the beginning
393 of the section so we begin them at 0. */
396 .debug 0 : { *(.debug) }
397 .line 0 : { *(.line) }
399 /* GNU DWARF 1 extensions */
400 .debug_srcinfo 0 : { *(.debug_srcinfo) }
401 .debug_sfnames 0 : { *(.debug_sfnames) }
403 /* DWARF 1.1 and DWARF 2 */
404 .debug_aranges 0 : { *(.debug_aranges) }
405 .debug_pubnames 0 : { *(.debug_pubnames) }
408 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
409 .debug_abbrev 0 : { *(.debug_abbrev) }
410 .debug_line 0 : { *(.debug_line) }
411 .debug_frame 0 : { *(.debug_frame) }
412 .debug_str 0 : { *(.debug_str) }
413 .debug_loc 0 : { *(.debug_loc) }
414 .debug_macinfo 0 : { *(.debug_macinfo) }
416 /* SGI/MIPS DWARF 2 extensions */
417 .debug_weaknames 0 : { *(.debug_weaknames) }
418 .debug_funcnames 0 : { *(.debug_funcnames) }
419 .debug_typenames 0 : { *(.debug_typenames) }
420 .debug_varnames 0 : { *(.debug_varnames) }
422 ${STACK_ADDR+${STACK}}
424 ${RELOCATING+${OTHER_END_SYMBOLS}}
425 ${RELOCATING+${STACKNOTE}}