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 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)
11 # ATTRS_SECTIONS - at the end
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
17 # DATA_START_SYMBOLS - symbols that appear at the start of the
19 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
20 # OTHER_GOT_SECTIONS - sections just after .got.
21 # OTHER_SDATA_SECTIONS - sections just after .sdata.
22 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
23 # .bss section besides __bss_start.
24 # DATA_PLT - .plt should be in data segment, not text segment.
25 # BSS_PLT - .plt should be in bss segment
26 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
27 # EMBEDDED - whether this is for an embedded system.
28 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
29 # start address of shared library.
30 # INPUT_FILES - INPUT command of files to always include
31 # WRITABLE_RODATA - if set, the .rodata section should be writable
32 # INIT_START, INIT_END - statements just before and just after
33 # combination of .init sections.
34 # FINI_START, FINI_END - statements just before and just after
35 # combination of .fini sections.
36 # STACK_ADDR - start of a .stack section.
37 # OTHER_SYMBOLS - symbols to place right at the end of the script.
39 # When adding sections, do note that the names of some sections are used
40 # when specifying the start address of the next.
43 # Many sections come in three flavours. There is the 'real' section,
44 # like ".data". Then there are the per-procedure or per-variable
45 # sections, generated by -ffunction-sections and -fdata-sections in GCC,
46 # and useful for --gc-sections, which for a variable "foo" might be
47 # ".data.foo". Then there are the linkonce sections, for which the linker
48 # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
49 # The exact correspondences are:
51 # Section Linkonce section
52 # .text .gnu.linkonce.t.foo
53 # .rodata .gnu.linkonce.r.foo
54 # .data .gnu.linkonce.d.foo
55 # .bss .gnu.linkonce.b.foo
56 # .sdata .gnu.linkonce.s.foo
57 # .sbss .gnu.linkonce.sb.foo
58 # .sdata2 .gnu.linkonce.s2.foo
59 # .sbss2 .gnu.linkonce.sb2.foo
60 # .debug_info .gnu.linkonce.wi.foo
61 # .tdata .gnu.linkonce.td.foo
62 # .tbss .gnu.linkonce.tb.foo
64 # Each of these can also have corresponding .rel.* and .rela.* sections.
66 test -z "$ENTRY" && ENTRY=_start
67 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
68 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
69 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
70 test -z "${ELFSIZE}" && ELFSIZE=32
71 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
72 test "$LD_FLAG" = "N" && DATA_ADDR=.
73 test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
74 test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
75 test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }"
76 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
78 if test -n "${COMMONPAGESIZE}"; then
79 DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
80 DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
82 INTERP=".interp ALIGN(4) : { *(.interp) }"
83 PLT=".plt : { *(.plt) } :dynamic :dyn"
84 DYNAMIC=".dynamic : { *(.dynamic) } :dynamic :dyn"
85 RODATA=".rodata ALIGN(4) : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
86 DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.directive) }"
87 test -z "$GOT" && GOT=".got ${RELOCATING-0} : { *(.got.plt) *(.got) } :dynamic :dyn"
88 CTOR=".ctors ALIGN(4) :
90 ${CONSTRUCTING+${CTOR_START}}
91 /* gcc uses crtbegin.o to find the start of
92 the constructors, so we make sure it is
93 first. Because this is a wildcard, it
94 doesn't matter if the user does not
95 actually link against crtbegin.o; the
96 linker won't look for a file to match a
97 wildcard. The wildcard also means that it
98 doesn't matter which directory crtbegin.o
101 KEEP (*crtbegin.o(.ctors))
102 KEEP (*crtbegin?.o(.ctors))
104 /* We don't want to include the .ctor section from
105 the crtend.o file until after the sorted ctors.
106 The .ctor section from the crtend file contains the
107 end of ctors marker and it must be last */
109 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
110 KEEP (*(SORT(.ctors.*)))
112 ${CONSTRUCTING+${CTOR_END}}
114 DTOR=".dtors ALIGN(4) :
116 ${CONSTRUCTING+${DTOR_START}}
117 KEEP (*crtbegin.o(.dtors))
118 KEEP (*crtbegin?.o(.dtors))
119 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
120 KEEP (*(SORT(.dtors.*)))
122 ${CONSTRUCTING+${DTOR_END}}
124 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
126 ${RELOCATING+_stack = .;}
130 # if this is for an embedded system, don't add SIZEOF_HEADERS.
131 if [ -z "$EMBEDDED" ]; then
132 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
134 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
138 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
139 "${LITTLE_OUTPUT_FORMAT}")
140 OUTPUT_ARCH(${OUTPUT_ARCH})
143 ${RELOCATING+${LIB_SEARCH_DIRS}}
144 ${RELOCATING+/* Do we need any of these for elf?
145 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
146 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
147 ${RELOCATING+${INPUT_FILES}}
148 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
149 if gld -r is used and the intermediate file has sections starting
150 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
151 bug. But for now assigning the zero vmas works. */}
155 headers PT_PHDR PHDRS ;
158 dyn PT_LOAD FLAGS (0) ;
164 /* Read-only sections, merged into text segment: */
165 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}}
166 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
167 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
168 ${CREATE_SHLIB-${INTERP}}
170 ${INITIAL_READONLY_SECTIONS}
174 ${RELOCATING+${INIT_START}}
176 ${RELOCATING+${INIT_END}}
181 ${RELOCATING+${TEXT_START_SYMBOLS}}
182 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
183 /* .gnu.warning sections are handled specially by elf32.em. */
185 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
188 ${RELOCATING+${CTOR}}
189 ${RELOCATING+${DTOR}}
193 ${RELOCATING+${FINI_START}}
195 ${RELOCATING+${FINI_END}}
198 ${RELOCATING+PROVIDE (__etext = .);}
199 ${RELOCATING+PROVIDE (_etext = .);}
200 ${RELOCATING+PROVIDE (etext = .);}
202 ${WRITABLE_RODATA-${RODATA}}
203 .rodata1 ALIGN(4) : { *(.rodata1) }
205 ExportTable ALIGN(4) : { KEEP (*(ExportTable)) }
206 .eh_frame_hdr ALIGN(4) : { *(.eh_frame_hdr) } :text
208 /* Adjust the address for the data segment. We want to adjust up to
209 the same address within the page on the next page up. */
210 . = ALIGN(128) + (. & (128 - 1));
211 .preinit_array ${RELOCATING-0} :
213 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__preinit_array_start = .);}}
214 KEEP (*(.preinit_array))
215 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__preinit_array_end = .);}}
217 .init_array ${RELOCATING-0} :
219 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__init_array_start = .);}}
220 KEEP (*(SORT(.init_array.*)))
221 KEEP (*(.init_array))
222 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__init_array_end = .);}}
224 .fini_array ${RELOCATING-0} :
226 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__fini_array_start = .);}}
227 KEEP (*(.fini_array))
228 KEEP (*(SORT(.fini_array.*)))
229 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__fini_array_end = .);}}
232 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
233 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
234 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
238 ${RELOCATING+${DATA_START_SYMBOLS}}
239 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
240 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
243 .data1 ALIGN(4) : { *(.data1) } :data
244 .tdata ALIGN(4) : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) } :data
245 .tbss ALIGN(4) : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} } :data
246 .eh_frame ALIGN(4) : { KEEP (*(.eh_frame)) } :data
247 .gcc_except_table ALIGN(4) : { *(.gcc_except_table) } :data
248 ${WRITABLE_RODATA+${RODATA}}
249 ${OTHER_READWRITE_SECTIONS}
251 ${OTHER_SDATA_SECTIONS}
252 ${RELOCATING+_edata = .;}
253 ${RELOCATING+PROVIDE (edata = .);}
254 ${RELOCATING+__bss_start = .;}
255 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
260 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
262 /* Align here to ensure that the .bss section occupies space up to
263 _end. Align after .bss to ensure correct alignment even if the
264 .bss section disappears because there are no input sections. */
265 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
267 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
268 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
269 ${RELOCATING+${OTHER_END_SYMBOLS}}
270 ${RELOCATING+_end = .;}
271 ${RELOCATING+PROVIDE (end = .);}
272 ${RELOCATING+${DATA_SEGMENT_END}}
274 ${TEXT_DYNAMIC-${DYNAMIC}}
275 ${TEXT_DYNAMIC+${DYNAMIC}}
276 .hash ${RELOCATING-0} : { *(.hash) } :dynamic :dyn
277 .dynsym ${RELOCATING-0} : { *(.dynsym) } :dynamic :dyn
278 .dynstr ${RELOCATING-0} : { *(.dynstr) } :dynamic :dyn
279 ${DATA_PLT-${BSS_PLT-${PLT}}}
280 .got.plt : { *(.got.plt) } :dynamic :dyn
281 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
282 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
283 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
285 if [ "x$COMBRELOC" = x ]; then
288 COMBRELOCCAT="cat > $COMBRELOC"
290 eval $COMBRELOCCAT <<EOF
291 .rel.init ${RELOCATING-0} : { *(.rel.init) }
292 .rela.init ${RELOCATING-0} : { *(.rela.init) }
293 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
294 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
295 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
296 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
297 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
298 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
299 ${OTHER_READONLY_RELOC_SECTIONS}
300 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
301 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
302 .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
303 .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
304 .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
305 .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
306 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
307 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
308 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
309 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
310 .rel.got ${RELOCATING-0} : { *(.rel.got) }
311 .rela.got ${RELOCATING-0} : { *(.rela.got) }
312 ${OTHER_GOT_RELOC_SECTIONS}
313 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
314 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
316 if [ -n "$COMBRELOC" ]; then
318 .rel.dyn ${RELOCATING-0} :
321 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
324 .rela.dyn ${RELOCATING-0} :
327 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
333 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
334 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
335 ${OTHER_PLT_RELOC_SECTIONS}
338 /* Stabs debugging sections. */
339 .stab 0 : { *(.stab) }
340 .stabstr 0 : { *(.stabstr) }
341 .stab.excl 0 : { *(.stab.excl) }
342 .stab.exclstr 0 : { *(.stab.exclstr) }
343 .stab.index 0 : { *(.stab.index) }
344 .stab.indexstr 0 : { *(.stab.indexstr) }
346 .comment 0 : { *(.comment) }
348 /* DWARF debug sections.
349 Symbols in the DWARF debugging sections are relative to the beginning
350 of the section so we begin them at 0. */
353 .debug 0 : { *(.debug) }
354 .line 0 : { *(.line) }
356 /* GNU DWARF 1 extensions */
357 .debug_srcinfo 0 : { *(.debug_srcinfo) }
358 .debug_sfnames 0 : { *(.debug_sfnames) }
360 /* DWARF 1.1 and DWARF 2 */
361 .debug_aranges 0 : { *(.debug_aranges) }
362 .debug_pubnames 0 : { *(.debug_pubnames) }
365 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
366 .debug_abbrev 0 : { *(.debug_abbrev) }
367 .debug_line 0 : { *(.debug_line) }
368 .debug_frame 0 : { *(.debug_frame) }
369 .debug_str 0 : { *(.debug_str) }
370 .debug_loc 0 : { *(.debug_loc) }
371 .debug_macinfo 0 : { *(.debug_macinfo) }
373 /* SGI/MIPS DWARF 2 extensions */
374 .debug_weaknames 0 : { *(.debug_weaknames) }
375 .debug_funcnames 0 : { *(.debug_funcnames) }
376 .debug_typenames 0 : { *(.debug_typenames) }
377 .debug_varnames 0 : { *(.debug_varnames) }
379 ${STACK_ADDR+${STACK}}
382 ${RELOCATING+${OTHER_SYMBOLS}}
383 ${RELOCATING+${DISCARDED}}