2 # Unusual variables checked by this code:
3 # NOP - four 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 data 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)
11 # OTHER_SECTIONS - at the end
12 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
13 # executable (e.g., _DYNAMIC_LINK)
14 # TEXT_START_SYMBOLS - symbols that appear at the start of the
16 # DATA_START_SYMBOLS - symbols that appear at the start of the
18 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
19 # OTHER_GOT_SECTIONS - sections just after .got.
20 # OTHER_SDATA_SECTIONS - sections just after .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.
24 # BSS_PLT - .plt should be in bss segment
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
30 # WRITABLE_RODATA - if set, the .rodata section should be writable
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.
36 # When adding sections, do note that the names of some sections are used
37 # when specifying the start address of the next.
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:
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
58 # Each of these can also have corresponding .rel.* and .rela.* sections.
60 test -z "$ENTRY" && ENTRY=_start
61 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
62 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
63 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
64 test -z "${ELFSIZE}" && ELFSIZE=32
65 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
66 test "$LD_FLAG" = "N" && DATA_ADDR=.
67 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
68 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
69 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
70 RODATA=".rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)} }"
71 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2) ${RELOCATING+*(.sbss2.*)} ${RELOCATING+*(.gnu.linkonce.sb2.*)} }"
72 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2) ${RELOCATING+*(.sdata2.*)} ${RELOCATING+*(.gnu.linkonce.s2.*)} }"
73 CTOR=".ctors ${CONSTRUCTING-0} :
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
86 KEEP (*crtbegin*.o(.ctors))
88 /* We don't want to include the .ctor section from
89 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 */
93 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
94 KEEP (*(SORT(.ctors.*)))
96 ${CONSTRUCTING+${CTOR_END}}
99 DTOR=" .dtors ${CONSTRUCTING-0} :
101 ${CONSTRUCTING+${DTOR_START}}
102 KEEP (*crtbegin*.o(.dtors))
103 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
104 KEEP (*(SORT(.dtors.*)))
106 ${CONSTRUCTING+${DTOR_END}}
109 # if this is for an embedded system, don't add SIZEOF_HEADERS.
110 if [ -z "$EMBEDDED" ]; then
111 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
113 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
117 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
118 "${LITTLE_OUTPUT_FORMAT}")
119 OUTPUT_ARCH(${OUTPUT_ARCH})
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. */}
134 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
135 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
136 ${CREATE_SHLIB-${INTERP}}
137 ${TEXT_DYNAMIC+${DYNAMIC}}
140 if [ "x$COMBRELOC" = x ]; then
143 COMBRELOCCAT="cat > $COMBRELOC"
145 eval $COMBRELOCCAT <<EOF
146 .rel.init ${RELOCATING-0} : { *(.rel.init) }
147 .rela.init ${RELOCATING-0} : { *(.rela.init) }
148 .rel.text ${RELOCATING-0} :
151 ${RELOCATING+*(.rel.text.*)}
152 ${RELOCATING+*(.rel.gnu.linkonce.t.*)}
154 .rela.text ${RELOCATING-0} :
157 ${RELOCATING+*(.rela.text.*)}
158 ${RELOCATING+*(.rela.gnu.linkonce.t.*)}
160 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
161 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
162 .rel.rodata ${RELOCATING-0} :
165 ${RELOCATING+*(.rel.rodata.*)}
166 ${RELOCATING+*(.rel.gnu.linkonce.r.*)}
168 .rela.rodata ${RELOCATING-0} :
171 ${RELOCATING+*(.rela.rodata.*)}
172 ${RELOCATING+*(.rela.gnu.linkonce.r.*)}
174 ${OTHER_READONLY_RELOC_SECTIONS}
175 .rel.data ${RELOCATING-0} :
178 ${RELOCATING+*(.rel.data.*)}
179 ${RELOCATING+*(.rel.gnu.linkonce.d.*)}
181 .rela.data ${RELOCATING-0} :
184 ${RELOCATING+*(.rela.data.*)}
185 ${RELOCATING+*(.rela.gnu.linkonce.d.*)}
187 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
188 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
189 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
190 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
191 .rel.got ${RELOCATING-0} : { *(.rel.got) }
192 .rela.got ${RELOCATING-0} : { *(.rela.got) }
193 ${OTHER_GOT_RELOC_SECTIONS}
194 .rel.sdata ${RELOCATING-0} :
197 ${RELOCATING+*(.rel.sdata.*)}
198 ${RELOCATING+*(.rel.gnu.linkonce.s.*)}
200 .rela.sdata ${RELOCATING-0} :
203 ${RELOCATING+*(.rela.sdata.*)}
204 ${RELOCATING+*(.rela.gnu.linkonce.s.*)}
206 .rel.sbss ${RELOCATING-0} :
209 ${RELOCATING+*(.rel.sbss.*)}
210 ${RELOCATING+*(.rel.gnu.linkonce.sb.*)}
212 .rela.sbss ${RELOCATING-0} :
215 ${RELOCATING+*(.rela.sbss.*)}
216 ${RELOCATING+*(.rela.gnu.linkonce.sb.*)}
218 .rel.sdata2 ${RELOCATING-0} :
221 ${RELOCATING+*(.rel.sdata2.*)}
222 ${RELOCATING+*(.rel.gnu.linkonce.s2.*)}
224 .rela.sdata2 ${RELOCATING-0} :
227 ${RELOCATING+*(.rela.sdata2.*)}
228 ${RELOCATING+*(.rela.gnu.linkonce.s2.*)}
230 .rel.sbss2 ${RELOCATING-0} :
233 ${RELOCATING+*(.rel.sbss2.*)}
234 ${RELOCATING+*(.rel.gnu.linkonce.sb2.*)}
236 .rela.sbss2 ${RELOCATING-0} :
239 ${RELOCATING+*(.rela.sbss2.*)}
240 ${RELOCATING+*(.rela.gnu.linkonce.sb2.*)}
242 .rel.bss ${RELOCATING-0} :
245 ${RELOCATING+*(.rel.bss.*)}
246 ${RELOCATING+*(.rel.gnu.linkonce.b.*)}
248 .rela.bss ${RELOCATING-0} :
251 ${RELOCATING+*(.rela.bss.*)}
252 ${RELOCATING+*(.rela.gnu.linkonce.b.*)}
255 if [ -n "$COMBRELOC" ]; then
260 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
266 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
272 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
273 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
274 ${OTHER_PLT_RELOC_SECTIONS}
276 .init ${RELOCATING-0} :
278 ${RELOCATING+${INIT_START}}
280 ${RELOCATING+${INIT_END}}
283 ${DATA_PLT-${BSS_PLT-${PLT}}}
284 .text ${RELOCATING-0} :
286 ${RELOCATING+${TEXT_START_SYMBOLS}}
288 ${RELOCATING+*(.text.*)}
290 /* .gnu.warning sections are handled specially by elf32.em. */
292 ${RELOCATING+*(.gnu.linkonce.t.*)}
293 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
295 .fini ${RELOCATING-0} :
297 ${RELOCATING+${FINI_START}}
299 ${RELOCATING+${FINI_END}}
301 ${RELOCATING+PROVIDE (__etext = .);}
302 ${RELOCATING+PROVIDE (_etext = .);}
303 ${RELOCATING+PROVIDE (etext = .);}
305 /* Adjust the address for the data segment. We want to adjust up to
306 the same address within the page on the next page up. */
307 ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
308 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
310 .data ${RELOCATING-0} :
312 ${RELOCATING+${DATA_START_SYMBOLS}}
314 ${RELOCATING+*(.data.*)}
315 ${RELOCATING+*(.gnu.linkonce.d.*)}
316 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
318 .data1 ${RELOCATING-0} : { *(.data1) }
319 .eh_frame ${RELOCATING-0} :
321 ${RELOCATING+PROVIDE (__eh_frame_begin = .);}
324 ${RELOCATING+PROVIDE (__eh_frame_end = .);}
326 .gcc_except_table : { *(.gcc_except_table) }
327 ${INITIAL_READONLY_SECTIONS}
328 .hash ${RELOCATING-0} : { *(.hash) }
329 .dynsym ${RELOCATING-0} : { *(.dynsym) }
330 .dynstr ${RELOCATING-0} : { *(.dynstr) }
331 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
332 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
333 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
335 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
336 ${CREATE_SHLIB-${SDATA2}}
337 ${CREATE_SHLIB-${SBSS2}}
338 ${RELOCATING+${OTHER_READONLY_SECTIONS}}
339 ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
340 ${TEXT_DYNAMIC-${DYNAMIC}}
341 ${RELOCATING+${CTOR}}
342 ${RELOCATING+${DTOR}}
343 .jcr : { KEEP (*(.jcr)) }
345 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
346 .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
347 ${RELOCATING+${OTHER_GOT_SECTIONS}}
348 ${CREATE_SHLIB+${SDATA2}}
349 ${CREATE_SHLIB+${SBSS2}}
350 /* We want the small data sections together, so single-instruction offsets
351 can access them all, and initialized data all before uninitialized, so
352 we can shorten the on-disk segment size. */
353 .sdata ${RELOCATING-0} :
355 ${RELOCATING+${SDATA_START_SYMBOLS}}
357 ${RELOCATING+*(.sdata.*)}
358 ${RELOCATING+*(.gnu.linkonce.s.*)}
360 ${RELOCATING+${OTHER_SDATA_SECTIONS}}
361 ${RELOCATING+_edata = .;}
362 ${RELOCATING+PROVIDE (edata = .);}
363 ${RELOCATING+__bss_start = .;}
364 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
365 .sbss ${RELOCATING-0} :
367 ${RELOCATING+PROVIDE (__sbss_start = .);}
368 ${RELOCATING+PROVIDE (___sbss_start = .);}
371 ${RELOCATING+*(.sbss.*)}
372 ${RELOCATING+*(.gnu.linkonce.sb.*)}
374 ${RELOCATING+PROVIDE (__sbss_end = .);}
375 ${RELOCATING+PROVIDE (___sbss_end = .);}
378 .bss ${RELOCATING-0} :
382 ${RELOCATING+*(.bss.*)}
383 ${RELOCATING+*(.gnu.linkonce.b.*)}
385 /* Align here to ensure that the .bss section occupies space up to
386 _end. Align after .bss to ensure correct alignment even if the
387 .bss section disappears because there are no input sections. */
388 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
390 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
391 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
392 ${RELOCATING+${OTHER_END_SYMBOLS}}
393 ${RELOCATING+_end = .;}
394 ${RELOCATING+PROVIDE (end = .);}
396 /* Stabs debugging sections. */
397 .stab 0 : { *(.stab) }
398 .stabstr 0 : { *(.stabstr) }
399 .stab.excl 0 : { *(.stab.excl) }
400 .stab.exclstr 0 : { *(.stab.exclstr) }
401 .stab.index 0 : { *(.stab.index) }
402 .stab.indexstr 0 : { *(.stab.indexstr) }
404 .comment 0 : { *(.comment) }
406 /* DWARF debug sections.
407 Symbols in the DWARF debugging sections are relative to the beginning
408 of the section so we begin them at 0. */
411 .debug 0 : { *(.debug) }
412 .line 0 : { *(.line) }
414 /* GNU DWARF 1 extensions */
415 .debug_srcinfo 0 : { *(.debug_srcinfo) }
416 .debug_sfnames 0 : { *(.debug_sfnames) }
418 /* DWARF 1.1 and DWARF 2 */
419 .debug_aranges 0 : { *(.debug_aranges) }
420 .debug_pubnames 0 : { *(.debug_pubnames) }
423 .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
424 .debug_abbrev 0 : { *(.debug_abbrev) }
425 .debug_line 0 : { *(.debug_line) }
426 .debug_frame 0 : { *(.debug_frame) }
427 .debug_str 0 : { *(.debug_str) }
428 .debug_loc 0 : { *(.debug_loc) }
429 .debug_macinfo 0 : { *(.debug_macinfo) }
431 /* SGI/MIPS DWARF 2 extensions */
432 .debug_weaknames 0 : { *(.debug_weaknames) }
433 .debug_funcnames 0 : { *(.debug_funcnames) }
434 .debug_typenames 0 : { *(.debug_typenames) }
435 .debug_varnames 0 : { *(.debug_varnames) }
437 ${RELOCATING+${OTHER_RELOCATING_SECTIONS}}
439 /* These must appear regardless of ${RELOCATING}. */