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 # NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
11 # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
12 # INITIAL_READONLY_SECTIONS - at start of text segment
13 # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
14 # (e.g., .PARISC.milli)
15 # OTHER_TEXT_SECTIONS - these get put in .text when relocating
16 # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
17 # (e.g., .PARISC.global)
18 # ATTRS_SECTIONS - at the end
19 # OTHER_SECTIONS - at the end
20 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
21 # executable (e.g., _DYNAMIC_LINK)
22 # TEXT_START_SYMBOLS - symbols that appear at the start of the
24 # DATA_START_SYMBOLS - symbols that appear at the start of the
26 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
27 # OTHER_GOT_SECTIONS - sections just after .got.
28 # OTHER_SDATA_SECTIONS - sections just after .sdata.
29 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
30 # .bss section besides __bss_start.
31 # DATA_PLT - .plt should be in data segment, not text segment.
32 # BSS_PLT - .plt should be in bss segment
33 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
34 # EMBEDDED - whether this is for an embedded system.
35 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
36 # start address of shared library.
37 # INPUT_FILES - INPUT command of files to always include
38 # WRITABLE_RODATA - if set, the .rodata section should be writable
39 # INIT_START, INIT_END - statements just before and just after
40 # combination of .init sections.
41 # FINI_START, FINI_END - statements just before and just after
42 # combination of .fini sections.
43 # STACK_ADDR - start of a .stack section.
44 # OTHER_SYMBOLS - symbols to place right at the end of the script.
46 # When adding sections, do note that the names of some sections are used
47 # when specifying the start address of the next.
50 # Many sections come in three flavours. There is the 'real' section,
51 # like ".data". Then there are the per-procedure or per-variable
52 # sections, generated by -ffunction-sections and -fdata-sections in GCC,
53 # and useful for --gc-sections, which for a variable "foo" might be
54 # ".data.foo". Then there are the linkonce sections, for which the linker
55 # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
56 # The exact correspondences are:
58 # Section Linkonce section
59 # .text .gnu.linkonce.t.foo
60 # .rodata .gnu.linkonce.r.foo
61 # .data .gnu.linkonce.d.foo
62 # .bss .gnu.linkonce.b.foo
63 # .sdata .gnu.linkonce.s.foo
64 # .sbss .gnu.linkonce.sb.foo
65 # .sdata2 .gnu.linkonce.s2.foo
66 # .sbss2 .gnu.linkonce.sb2.foo
67 # .debug_info .gnu.linkonce.wi.foo
69 # Each of these can also have corresponding .rel.* and .rela.* sections.
71 test -z "$ENTRY" && ENTRY=_start
72 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
73 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
74 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
75 test -z "${ELFSIZE}" && ELFSIZE=32
76 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
77 test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }"
78 test "$LD_FLAG" = "N" && DATA_ADDR=.
79 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
80 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
81 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
82 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
83 if test -z "${NO_SMALL_DATA}"; then
84 SBSS=".sbss ${RELOCATING-0} :
86 ${RELOCATING+PROVIDE (__sbss_start = .);}
87 ${RELOCATING+PROVIDE (___sbss_start = .);}
89 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
91 ${RELOCATING+PROVIDE (__sbss_end = .);}
92 ${RELOCATING+PROVIDE (___sbss_end = .);}
94 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
95 SDATA="/* We want the small data sections together, so single-instruction offsets
96 can access them all, and initialized data all before uninitialized, so
97 we can shorten the on-disk segment size. */
98 .sdata ${RELOCATING-0} :
100 ${RELOCATING+${SDATA_START_SYMBOLS}}
101 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
103 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }"
104 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
105 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
106 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
107 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
108 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
109 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
110 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
111 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
114 ${CONSTRUCTING+${CTOR_START}}
115 /* gcc uses crtbegin.o to find the start of
116 the constructors, so we make sure it is
117 first. Because this is a wildcard, it
118 doesn't matter if the user does not
119 actually link against crtbegin.o; the
120 linker won't look for a file to match a
121 wildcard. The wildcard also means that it
122 doesn't matter which directory crtbegin.o
125 KEEP (*crtbegin.o(.ctors))
126 KEEP (*crtbegin?.o(.ctors))
128 /* We don't want to include the .ctor section from
129 the crtend.o file until after the sorted ctors.
130 The .ctor section from the crtend file contains the
131 end of ctors marker and it must be last */
133 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
134 KEEP (*(SORT(.ctors.*)))
136 ${CONSTRUCTING+${CTOR_END}}
139 ${CONSTRUCTING+${DTOR_START}}
140 KEEP (*crtbegin.o(.dtors))
141 KEEP (*crtbegin?.o(.dtors))
142 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
143 KEEP (*(SORT(.dtors.*)))
145 ${CONSTRUCTING+${DTOR_END}}
147 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
149 ${RELOCATING+_stack = .;}
153 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
156 /* Copyright (C) 2014-2019 Free Software Foundation, Inc.
158 Copying and distribution of this script, with or without modification,
159 are permitted in any medium without royalty provided the copyright
160 notice and this notice are preserved. */
162 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
163 "${LITTLE_OUTPUT_FORMAT}")
164 OUTPUT_ARCH(${OUTPUT_ARCH})
165 ${RELOCATING+ENTRY(${ENTRY})}
167 ${RELOCATING+${LIB_SEARCH_DIRS}}
168 ${RELOCATING+/* Do we need any of these for elf?
169 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
170 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
171 ${RELOCATING+${INPUT_FILES}}
172 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
173 if gld -r is used and the intermediate file has sections starting
174 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
175 bug. But for now assigning the zero vmas works. */}
179 /* Read-only sections, merged into text segment: */
180 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
181 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
182 ${CREATE_SHLIB-${INTERP}}
183 ${INITIAL_READONLY_SECTIONS}
184 ${TEXT_DYNAMIC+${DYNAMIC}}
185 .hash ${RELOCATING-0} : { *(.hash) }
186 .dynsym ${RELOCATING-0} : { *(.dynsym) }
187 .dynstr ${RELOCATING-0} : { *(.dynstr) }
188 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
189 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
190 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
193 if [ "x$COMBRELOC" = x ]; then
196 COMBRELOCCAT="cat > $COMBRELOC"
198 eval $COMBRELOCCAT <<EOF
199 .rel.init ${RELOCATING-0} : { *(.rel.init) }
200 .rela.init ${RELOCATING-0} : { *(.rela.init) }
201 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
202 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
203 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
204 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
205 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
206 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
207 ${OTHER_READONLY_RELOC_SECTIONS}
208 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
209 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
210 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
211 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
212 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
213 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
214 .rel.got ${RELOCATING-0} : { *(.rel.got) }
215 .rela.got ${RELOCATING-0} : { *(.rela.got) }
216 ${OTHER_GOT_RELOC_SECTIONS}
221 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
222 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
224 if [ -n "$COMBRELOC" ]; then
226 .rel.dyn ${RELOCATING-0} :
229 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
232 .rela.dyn ${RELOCATING-0} :
235 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
241 ${RELOCATING+. = ALIGN(0x1000);}
242 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
243 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
244 ${OTHER_PLT_RELOC_SECTIONS}
245 ${DATA_PLT-${BSS_PLT-${PLT}}}
246 .text ${RELOCATING-0} :
248 ${RELOCATING+${TEXT_START_SYMBOLS}}
249 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
250 /* .gnu.warning sections are handled specially by elf32.em. */
252 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
254 .init ${RELOCATING-0} :
256 ${RELOCATING+${INIT_START}}
257 KEEP (*(SORT_NONE(.init)))
258 ${RELOCATING+${INIT_END}}
260 .fini ${RELOCATING-0} :
262 ${RELOCATING+${FINI_START}}
263 KEEP (*(SORT_NONE(.fini)))
264 ${RELOCATING+${FINI_END}}
266 ${RELOCATING+PROVIDE (__etext = .);}
267 ${RELOCATING+PROVIDE (_etext = .);}
268 ${RELOCATING+PROVIDE (etext = .);}
269 ${RELOCATING+. = ALIGN(0x1000);}
270 ${CREATE_SHLIB-${SDATA2}}
271 ${CREATE_SHLIB-${SBSS2}}
272 ${OTHER_READONLY_SECTIONS}
273 .eh_frame_hdr ${RELOCATING-0} : { *(.eh_frame_hdr) }
275 ${RELOCATING+. = ALIGN(0x1000);}
276 .data ${RELOCATING-0} :
278 ${RELOCATING+*(.rodata .rodata.*)
281 ${DATA_START_SYMBOLS}}
282 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
283 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
284 ${RELOCATING+KEEP (*(.eh_frame))
290 .data1 ${RELOCATING-0} : { *(.data1) }
291 ${RELOCATING+. = ALIGN(0x1000);}
292 .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }
293 ${WRITABLE_RODATA+${RODATA}}
294 ${OTHER_READWRITE_SECTIONS}
295 ${TEXT_DYNAMIC-${DYNAMIC}}
297 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
298 .got ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) }
299 ${OTHER_GOT_SECTIONS}
300 ${CREATE_SHLIB+${SDATA2}}
301 ${CREATE_SHLIB+${SBSS2}}
303 ${OTHER_SDATA_SECTIONS}
304 ${RELOCATING+_edata = .;}
305 ${RELOCATING+PROVIDE (edata = .);}
306 ${RELOCATING+__bss_start = .;}
307 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
310 ${RELOCATING+. = ALIGN(0x1000);}
311 .bss ${RELOCATING-0} :
313 ${RELOCATING+*(.dynbss)}
314 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
315 ${RELOCATING+*(COMMON)
316 /* Align here to ensure that the .bss section occupies space up to
317 _end. Align after .bss to ensure correct alignment even if the
318 .bss section disappears because there are no input sections. */
319 . = ALIGN(${ALIGNMENT});}
321 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
322 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
323 ${RELOCATING+${OTHER_END_SYMBOLS}}
324 ${RELOCATING+_end = .;}
325 ${RELOCATING+PROVIDE (end = .);}
326 ${STACK_ADDR+${STACK}}
328 /* Stabs debugging sections. */
329 .stab 0 : { *(.stab) }
330 .stabstr 0 : { *(.stabstr) }
331 .stab.excl 0 : { *(.stab.excl) }
332 .stab.exclstr 0 : { *(.stab.exclstr) }
333 .stab.index 0 : { *(.stab.index) }
334 .stab.indexstr 0 : { *(.stab.indexstr) }
336 .comment 0 : { *(.comment) }
340 . $srcdir/scripttempl/DWARF.sc
345 ${RELOCATING+${OTHER_SYMBOLS}}