1 # Copyright (C) 2014-2019 Free Software Foundation, Inc.
3 # Copying and distribution of this file, with or without modification,
4 # are permitted in any medium without royalty provided the copyright
5 # notice and this notice are preserved.
7 # Unusual variables checked by this code:
8 # NOP - four byte opcode for no-op (defaults to 0)
9 # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
10 # INITIAL_READONLY_SECTIONS - at start of data segment
11 # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
12 # (e.g., .PARISC.milli)
13 # OTHER_TEXT_SECTIONS - these get put in .text when relocating
14 # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
15 # (e.g., .PARISC.global)
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 # DATA_PLT - .plt should be in data segment, not text segment.
29 # BSS_PLT - .plt should be in bss segment
30 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
31 # EMBEDDED - whether this is for an embedded system.
32 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
33 # start address of shared library.
34 # INPUT_FILES - INPUT command of files to always include
35 # WRITABLE_RODATA - if set, the .rodata section should be writable
36 # INIT_START, INIT_END - statements just before and just after
37 # combination of .init sections.
38 # FINI_START, FINI_END - statements just before and just after
39 # combination of .fini sections.
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
63 # Each of these can also have corresponding .rel.* and .rela.* sections.
65 test -z "$ENTRY" && ENTRY=_start
66 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
67 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
68 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
69 test -z "${ELFSIZE}" && ELFSIZE=32
70 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
71 test "$LD_FLAG" = "N" && DATA_ADDR=.
72 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
73 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
74 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
75 RODATA=".rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)} }"
76 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2) ${RELOCATING+*(.sbss2.*)} ${RELOCATING+*(.gnu.linkonce.sb2.*)} }"
77 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2) ${RELOCATING+*(.sdata2.*)} ${RELOCATING+*(.gnu.linkonce.s2.*)} }"
78 CTOR=".ctors ${CONSTRUCTING-0} :
80 ${CONSTRUCTING+${CTOR_START}}
81 /* gcc uses crtbegin.o to find the start of
82 the constructors, so we make sure it is
83 first. Because this is a wildcard, it
84 doesn't matter if the user does not
85 actually link against crtbegin.o; the
86 linker won't look for a file to match a
87 wildcard. The wildcard also means that it
88 doesn't matter which directory crtbegin.o
91 KEEP (*crtbegin.o(.ctors))
92 KEEP (*crtbegin?.o(.ctors))
94 /* We don't want to include the .ctor section from
95 the crtend.o file until after the sorted ctors.
96 The .ctor section from the crtend file contains the
97 end of ctors marker and it must be last */
99 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
100 KEEP (*(SORT(.ctors.*)))
102 ${CONSTRUCTING+${CTOR_END}}
105 DTOR=" .dtors ${CONSTRUCTING-0} :
107 ${CONSTRUCTING+${DTOR_START}}
108 KEEP (*crtbegin.o(.dtors))
109 KEEP (*crtbegin?.o(.dtors))
110 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
111 KEEP (*(SORT(.dtors.*)))
113 ${CONSTRUCTING+${DTOR_END}}
116 # If this is for an embedded system, don't add SIZEOF_HEADERS.
117 if [ -z "$EMBEDDED" ]; then
118 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
120 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
124 /* Copyright (C) 2014-2019 Free Software Foundation, Inc.
126 Copying and distribution of this script, with or without modification,
127 are permitted in any medium without royalty provided the copyright
128 notice and this notice are preserved. */
130 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
131 "${LITTLE_OUTPUT_FORMAT}")
132 OUTPUT_ARCH(${OUTPUT_ARCH})
133 ${RELOCATING+ENTRY(${ENTRY})}
135 ${RELOCATING+${LIB_SEARCH_DIRS}}
136 ${RELOCATING+/* Do we need any of these for elf?
137 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
138 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
139 ${RELOCATING+${INPUT_FILES}}
140 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
141 if gld -r is used and the intermediate file has sections starting
142 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
143 bug. But for now assigning the zero vmas works. */}
147 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
148 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
149 ${CREATE_SHLIB-${INTERP}}
150 ${TEXT_DYNAMIC+${DYNAMIC}}
153 if [ "x$COMBRELOC" = x ]; then
156 COMBRELOCCAT="cat > $COMBRELOC"
158 eval $COMBRELOCCAT <<EOF
159 .rel.init ${RELOCATING-0} : { *(.rel.init) }
160 .rela.init ${RELOCATING-0} : { *(.rela.init) }
161 .rel.text ${RELOCATING-0} :
164 ${RELOCATING+*(.rel.text.*)}
165 ${RELOCATING+*(.rel.gnu.linkonce.t.*)}
167 .rela.text ${RELOCATING-0} :
170 ${RELOCATING+*(.rela.text.*)}
171 ${RELOCATING+*(.rela.gnu.linkonce.t.*)}
173 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
174 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
175 .rel.rodata ${RELOCATING-0} :
178 ${RELOCATING+*(.rel.rodata.*)}
179 ${RELOCATING+*(.rel.gnu.linkonce.r.*)}
181 .rela.rodata ${RELOCATING-0} :
184 ${RELOCATING+*(.rela.rodata.*)}
185 ${RELOCATING+*(.rela.gnu.linkonce.r.*)}
187 ${OTHER_READONLY_RELOC_SECTIONS}
188 .rel.data ${RELOCATING-0} :
191 ${RELOCATING+*(.rel.data.*)}
192 ${RELOCATING+*(.rel.gnu.linkonce.d.*)}
194 .rela.data ${RELOCATING-0} :
197 ${RELOCATING+*(.rela.data.*)}
198 ${RELOCATING+*(.rela.gnu.linkonce.d.*)}
200 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
201 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
202 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
203 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
204 .rel.got ${RELOCATING-0} : { *(.rel.got) }
205 .rela.got ${RELOCATING-0} : { *(.rela.got) }
206 ${OTHER_GOT_RELOC_SECTIONS}
207 .rel.sdata ${RELOCATING-0} :
210 ${RELOCATING+*(.rel.sdata.*)}
211 ${RELOCATING+*(.rel.gnu.linkonce.s.*)}
213 .rela.sdata ${RELOCATING-0} :
216 ${RELOCATING+*(.rela.sdata.*)}
217 ${RELOCATING+*(.rela.gnu.linkonce.s.*)}
219 .rel.sbss ${RELOCATING-0} :
222 ${RELOCATING+*(.rel.sbss.*)}
223 ${RELOCATING+*(.rel.gnu.linkonce.sb.*)}
225 .rela.sbss ${RELOCATING-0} :
228 ${RELOCATING+*(.rela.sbss.*)}
229 ${RELOCATING+*(.rela.gnu.linkonce.sb.*)}
231 .rel.sdata2 ${RELOCATING-0} :
234 ${RELOCATING+*(.rel.sdata2.*)}
235 ${RELOCATING+*(.rel.gnu.linkonce.s2.*)}
237 .rela.sdata2 ${RELOCATING-0} :
240 ${RELOCATING+*(.rela.sdata2.*)}
241 ${RELOCATING+*(.rela.gnu.linkonce.s2.*)}
243 .rel.sbss2 ${RELOCATING-0} :
246 ${RELOCATING+*(.rel.sbss2.*)}
247 ${RELOCATING+*(.rel.gnu.linkonce.sb2.*)}
249 .rela.sbss2 ${RELOCATING-0} :
252 ${RELOCATING+*(.rela.sbss2.*)}
253 ${RELOCATING+*(.rela.gnu.linkonce.sb2.*)}
255 .rel.bss ${RELOCATING-0} :
258 ${RELOCATING+*(.rel.bss.*)}
259 ${RELOCATING+*(.rel.gnu.linkonce.b.*)}
261 .rela.bss ${RELOCATING-0} :
264 ${RELOCATING+*(.rela.bss.*)}
265 ${RELOCATING+*(.rela.gnu.linkonce.b.*)}
268 if [ -n "$COMBRELOC" ]; then
273 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
279 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
285 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
286 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
287 ${OTHER_PLT_RELOC_SECTIONS}
289 .init ${RELOCATING-0} :
291 ${RELOCATING+${INIT_START}}
292 KEEP (*(SORT_NONE(.init)))
293 ${RELOCATING+${INIT_END}}
296 ${DATA_PLT-${BSS_PLT-${PLT}}}
297 .text ${RELOCATING-0} :
299 ${RELOCATING+${TEXT_START_SYMBOLS}}
301 ${RELOCATING+*(.text.*)}
303 /* .gnu.warning sections are handled specially by elf32.em. */
305 ${RELOCATING+*(.gnu.linkonce.t.*)}
306 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
308 .fini ${RELOCATING-0} :
310 ${RELOCATING+${FINI_START}}
311 KEEP (*(SORT_NONE(.fini)))
312 ${RELOCATING+${FINI_END}}
314 ${RELOCATING+PROVIDE (__etext = .);}
315 ${RELOCATING+PROVIDE (_etext = .);}
316 ${RELOCATING+PROVIDE (etext = .);}
318 /* Adjust the address for the data segment. We want to adjust up to
319 the same address within the page on the next page up. */
320 ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
321 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
323 .data ${RELOCATING-0} :
325 ${RELOCATING+${DATA_START_SYMBOLS}}
327 ${RELOCATING+*(.data.*)}
328 ${RELOCATING+*(.gnu.linkonce.d.*)}
329 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
331 .data1 ${RELOCATING-0} : { *(.data1) }
332 .eh_frame ${RELOCATING-0} :
334 ${RELOCATING+PROVIDE (__eh_frame_begin = .);}
336 ${RELOCATING+LONG (0);}
337 ${RELOCATING+PROVIDE (__eh_frame_end = .);}
339 .gcc_except_table : { *(.gcc_except_table) }
340 ${INITIAL_READONLY_SECTIONS}
341 .hash ${RELOCATING-0} : { *(.hash) }
342 .dynsym ${RELOCATING-0} : { *(.dynsym) }
343 .dynstr ${RELOCATING-0} : { *(.dynstr) }
344 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
345 .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
346 .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
348 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
349 ${CREATE_SHLIB-${SDATA2}}
350 ${CREATE_SHLIB-${SBSS2}}
351 ${RELOCATING+${OTHER_READONLY_SECTIONS}}
352 ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
353 ${TEXT_DYNAMIC-${DYNAMIC}}
354 ${RELOCATING+${CTOR}}
355 ${RELOCATING+${DTOR}}
356 .jcr : { KEEP (*(.jcr)) }
358 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
359 .got ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) }
360 ${RELOCATING+${OTHER_GOT_SECTIONS}}
361 ${CREATE_SHLIB+${SDATA2}}
362 ${CREATE_SHLIB+${SBSS2}}
363 /* We want the small data sections together, so single-instruction offsets
364 can access them all, and initialized data all before uninitialized, so
365 we can shorten the on-disk segment size. */
366 .sdata ${RELOCATING-0} :
368 ${RELOCATING+${SDATA_START_SYMBOLS}}
370 ${RELOCATING+*(.sdata.*)}
371 ${RELOCATING+*(.gnu.linkonce.s.*)}
373 ${RELOCATING+${OTHER_SDATA_SECTIONS}}
374 ${RELOCATING+_edata = .;}
375 ${RELOCATING+PROVIDE (edata = .);}
376 ${RELOCATING+__bss_start = .;}
377 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
378 .sbss ${RELOCATING-0} :
380 ${RELOCATING+PROVIDE (__sbss_start = .);}
381 ${RELOCATING+PROVIDE (___sbss_start = .);}
382 ${RELOCATING+*(.dynsbss)}
384 ${RELOCATING+*(.sbss.*)}
385 ${RELOCATING+*(.gnu.linkonce.sb.*)}
386 ${RELOCATING+*(.scommon)}
387 ${RELOCATING+PROVIDE (__sbss_end = .);}
388 ${RELOCATING+PROVIDE (___sbss_end = .);}
391 .bss ${RELOCATING-0} :
393 ${RELOCATING+*(.dynbss)}
395 ${RELOCATING+*(.bss.*)}
396 ${RELOCATING+*(.gnu.linkonce.b.*)}
397 ${RELOCATING+*(COMMON)
398 /* Align here to ensure that the .bss section occupies space up to
399 _end. Align after .bss to ensure correct alignment even if the
400 .bss section disappears because there are no input sections. */
401 . = ALIGN(${ALIGNMENT});}
403 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
404 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
405 ${RELOCATING+${OTHER_END_SYMBOLS}}
406 ${RELOCATING+_end = .;}
407 ${RELOCATING+PROVIDE (end = .);}
409 /* Stabs debugging sections. */
410 .stab 0 : { *(.stab) }
411 .stabstr 0 : { *(.stabstr) }
412 .stab.excl 0 : { *(.stab.excl) }
413 .stab.exclstr 0 : { *(.stab.exclstr) }
414 .stab.index 0 : { *(.stab.index) }
415 .stab.indexstr 0 : { *(.stab.indexstr) }
417 .comment 0 : { *(.comment) }
421 . $srcdir/scripttempl/DWARF.sc
424 ${RELOCATING+${OTHER_RELOCATING_SECTIONS}}
426 /* These must appear regardless of ${RELOCATING}. */