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_BSS_SECTIONS - other than .bss .sbss ...
14 # OTHER_SECTIONS - at the end
15 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
16 # executable (e.g., _DYNAMIC_LINK)
17 # TEXT_START_SYMBOLS - symbols that appear at the start of the
19 # DATA_START_SYMBOLS - symbols that appear at the start of the
21 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
22 # OTHER_GOT_SECTIONS - sections just after .got.
23 # OTHER_SDATA_SECTIONS - sections just after .sdata.
24 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
25 # .bss section besides __bss_start.
26 # DATA_PLT - .plt should be in data segment, not text segment.
27 # BSS_PLT - .plt should be in bss segment
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 "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
70 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
71 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
72 test -z "${ELFSIZE}" && ELFSIZE=32
73 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
74 test "$LD_FLAG" = "N" && DATA_ADDR=.
75 test -n "$CREATE_SHLIB" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
76 test -z "$CREATE_SHLIB" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
77 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
79 if test -n "${COMMONPAGESIZE}"; then
80 DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
81 DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
83 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
84 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
85 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
86 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
87 STACKNOTE="/DISCARD/ : { *(.note.GNU-stack) }"
88 if test -z "${NO_SMALL_DATA}"; then
89 SBSS=".sbss ${RELOCATING-0} :
91 ${RELOCATING+PROVIDE (__sbss_start = .);}
92 ${RELOCATING+PROVIDE (___sbss_start = .);}
94 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
96 ${RELOCATING+PROVIDE (__sbss_end = .);}
97 ${RELOCATING+PROVIDE (___sbss_end = .);}
99 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
100 SDATA="/* We want the small data sections together, so single-instruction offsets
101 can access them all, and initialized data all before uninitialized, so
102 we can shorten the on-disk segment size. */
103 .sdata ${RELOCATING-0} :
105 ${RELOCATING+${SDATA_START_SYMBOLS}}
106 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
108 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }"
109 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
110 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
111 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
112 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
113 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
114 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
115 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
116 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
118 CTOR=".ctors ${CONSTRUCTING-0} :
120 ${CONSTRUCTING+${CTOR_START}}
121 /* gcc uses crtbegin.o to find the start of
122 the constructors, so we make sure it is
123 first. Because this is a wildcard, it
124 doesn't matter if the user does not
125 actually link against crtbegin.o; the
126 linker won't look for a file to match a
127 wildcard. The wildcard also means that it
128 doesn't matter which directory crtbegin.o
131 KEEP (*crtbegin*.o(.ctors))
133 /* We don't want to include the .ctor section from
134 from the crtend.o file until after the sorted ctors.
135 The .ctor section from the crtend file contains the
136 end of ctors marker and it must be last */
138 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
139 KEEP (*(SORT(.ctors.*)))
141 ${CONSTRUCTING+${CTOR_END}}
143 DTOR=".dtors ${CONSTRUCTING-0} :
145 ${CONSTRUCTING+${DTOR_START}}
146 KEEP (*crtbegin*.o(.dtors))
147 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
148 KEEP (*(SORT(.dtors.*)))
150 ${CONSTRUCTING+${DTOR_END}}
152 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
154 ${RELOCATING+_stack = .;}
158 # if this is for an embedded system, don't add SIZEOF_HEADERS.
159 if [ -z "$EMBEDDED" ]; then
160 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
162 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
166 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
167 "${LITTLE_OUTPUT_FORMAT}")
168 OUTPUT_ARCH(${OUTPUT_ARCH})
171 ${RELOCATING+${LIB_SEARCH_DIRS}}
172 ${RELOCATING+/* Do we need any of these for elf?
173 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
174 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
175 ${RELOCATING+${INPUT_FILES}}
176 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
177 if gld -r is used and the intermediate file has sections starting
178 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
179 bug. But for now assigning the zero vmas works. */}
183 /* Read-only sections, merged into text segment: */
184 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}}
185 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
186 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
187 ${CREATE_SHLIB-${INTERP}}
188 ${INITIAL_READONLY_SECTIONS}
189 ${TEXT_DYNAMIC+${DYNAMIC}}
190 .hash ${RELOCATING-0} : { *(.hash) }
191 .dynsym ${RELOCATING-0} : { *(.dynsym) }
192 .dynstr ${RELOCATING-0} : { *(.dynstr) }
193 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
194 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
195 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
198 if [ "x$COMBRELOC" = x ]; then
201 COMBRELOCCAT="cat > $COMBRELOC"
203 eval $COMBRELOCCAT <<EOF
204 .rel.init ${RELOCATING-0} : { *(.rel.init) }
205 .rela.init ${RELOCATING-0} : { *(.rela.init) }
206 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
207 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
208 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
209 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
210 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
211 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
212 ${OTHER_READONLY_RELOC_SECTIONS}
213 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
214 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
215 .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
216 .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
217 .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
218 .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
219 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
220 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
221 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
222 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
223 .rel.got ${RELOCATING-0} : { *(.rel.got) }
224 .rela.got ${RELOCATING-0} : { *(.rela.got) }
225 ${OTHER_GOT_RELOC_SECTIONS}
230 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
231 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
233 if [ -n "$COMBRELOC" ]; then
235 .rel.dyn ${RELOCATING-0} :
238 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
241 .rela.dyn ${RELOCATING-0} :
244 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
250 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
251 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
252 ${OTHER_PLT_RELOC_SECTIONS}
254 .init ${RELOCATING-0} :
256 ${RELOCATING+${INIT_START}}
258 ${RELOCATING+${INIT_END}}
261 ${DATA_PLT-${BSS_PLT-${PLT}}}
262 .text ${RELOCATING-0} :
264 ${RELOCATING+${TEXT_START_SYMBOLS}}
265 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
266 /* .gnu.warning sections are handled specially by elf32.em. */
268 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
270 .fini ${RELOCATING-0} :
272 ${RELOCATING+${FINI_START}}
274 ${RELOCATING+${FINI_END}}
276 ${RELOCATING+PROVIDE (__etext = .);}
277 ${RELOCATING+PROVIDE (_etext = .);}
278 ${RELOCATING+PROVIDE (etext = .);}
279 ${WRITABLE_RODATA-${RODATA}}
280 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
281 ${CREATE_SHLIB-${SDATA2}}
282 ${CREATE_SHLIB-${SBSS2}}
283 ${OTHER_READONLY_SECTIONS}
284 .eh_frame_hdr : { *(.eh_frame_hdr) }
286 /* Adjust the address for the data segment. We want to adjust up to
287 the same address within the page on the next page up. */
288 ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
289 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
291 /* Ensure the __preinit_array_start label is properly aligned. We
292 could instead move the label definition inside the section, but
293 the linker would then create the section even if it turns out to
294 be empty, which isn't pretty. */
295 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
296 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
297 .preinit_array ${RELOCATING-0} : { *(.preinit_array) }
298 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
300 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
301 .init_array ${RELOCATING-0} : { *(.init_array) }
302 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
304 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
305 .fini_array ${RELOCATING-0} : { *(.fini_array) }
306 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
308 .data ${RELOCATING-0} :
310 ${RELOCATING+${DATA_START_SYMBOLS}}
311 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
312 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
314 .data1 ${RELOCATING-0} : { *(.data1) }
315 .tdata ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
316 .tbss ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
317 .eh_frame ${RELOCATING-0} : { KEEP (*(.eh_frame)) }
318 .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }
319 ${WRITABLE_RODATA+${RODATA}}
320 ${OTHER_READWRITE_SECTIONS}
321 ${TEXT_DYNAMIC-${DYNAMIC}}
322 ${RELOCATING+${CTOR}}
323 ${RELOCATING+${DTOR}}
324 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
326 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
327 .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
328 ${OTHER_GOT_SECTIONS}
329 ${CREATE_SHLIB+${SDATA2}}
330 ${CREATE_SHLIB+${SBSS2}}
332 ${OTHER_SDATA_SECTIONS}
333 ${RELOCATING+_edata = .;}
334 ${RELOCATING+PROVIDE (edata = .);}
335 ${RELOCATING+__bss_start = .;}
336 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
339 .bss ${RELOCATING-0} :
342 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
344 /* Align here to ensure that the .bss section occupies space up to
345 _end. Align after .bss to ensure correct alignment even if the
346 .bss section disappears because there are no input sections. */
347 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
349 ${OTHER_BSS_SECTIONS}
350 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
351 ${RELOCATING+_end = .;}
352 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
353 ${RELOCATING+PROVIDE (end = .);}
354 ${RELOCATING+${DATA_SEGMENT_END}}
356 /* Stabs debugging sections. */
357 .stab 0 : { *(.stab) }
358 .stabstr 0 : { *(.stabstr) }
359 .stab.excl 0 : { *(.stab.excl) }
360 .stab.exclstr 0 : { *(.stab.exclstr) }
361 .stab.index 0 : { *(.stab.index) }
362 .stab.indexstr 0 : { *(.stab.indexstr) }
364 .comment 0 : { *(.comment) }
366 /* DWARF debug sections.
367 Symbols in the DWARF debugging sections are relative to the beginning
368 of the section so we begin them at 0. */
371 .debug 0 : { *(.debug) }
372 .line 0 : { *(.line) }
374 /* GNU DWARF 1 extensions */
375 .debug_srcinfo 0 : { *(.debug_srcinfo) }
376 .debug_sfnames 0 : { *(.debug_sfnames) }
378 /* DWARF 1.1 and DWARF 2 */
379 .debug_aranges 0 : { *(.debug_aranges) }
380 .debug_pubnames 0 : { *(.debug_pubnames) }
383 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
384 .debug_abbrev 0 : { *(.debug_abbrev) }
385 .debug_line 0 : { *(.debug_line) }
386 .debug_frame 0 : { *(.debug_frame) }
387 .debug_str 0 : { *(.debug_str) }
388 .debug_loc 0 : { *(.debug_loc) }
389 .debug_macinfo 0 : { *(.debug_macinfo) }
391 /* SGI/MIPS DWARF 2 extensions */
392 .debug_weaknames 0 : { *(.debug_weaknames) }
393 .debug_funcnames 0 : { *(.debug_funcnames) }
394 .debug_typenames 0 : { *(.debug_typenames) }
395 .debug_varnames 0 : { *(.debug_varnames) }
397 ${STACK_ADDR+${STACK}}
399 ${RELOCATING+${OTHER_END_SYMBOLS}}
400 ${RELOCATING+${STACKNOTE}}