]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/scripttempl/elf.sc
ld: optionally emit _etext last, before .data
[thirdparty/binutils-gdb.git] / ld / scripttempl / elf.sc
1 # Copyright (C) 2014-2020 Free Software Foundation, Inc.
2 #
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.
6 #
7 # Unusual variables checked by this code:
8 # NOP - four byte opcode for no-op (defaults to none)
9 # NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
10 # empty.
11 # SMALL_DATA_CTOR - .ctors contains small data.
12 # SMALL_DATA_DTOR - .dtors contains small data.
13 # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
14 # INITIAL_READONLY_SECTIONS - at start of text segment
15 # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
16 # (e.g., .PARISC.milli)
17 # OTHER_TEXT_SECTIONS - these get put in .text when relocating
18 # INITIAL_READWRITE_SECTIONS - at start of data segment (after relro)
19 # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
20 # (e.g., .PARISC.global)
21 # OTHER_RELRO_SECTIONS - other than .data.rel.ro ...
22 # (e.g. PPC32 .fixup, .got[12])
23 # OTHER_RELRO_SECTIONS_2 - as above, but after .dynamic in text segment
24 # OTHER_BSS_SECTIONS - other than .bss .sbss ...
25 # ATTRS_SECTIONS - at the end
26 # OTHER_SECTIONS - at the end
27 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
28 # executable (e.g., _DYNAMIC_LINK)
29 # TEXT_START_ADDR - the first byte of the text segment, after any
30 # headers.
31 # TEXT_BASE_ADDRESS - the first byte of the text segment.
32 # TEXT_START_SYMBOLS - symbols that appear at the start of the
33 # .text section.
34 # DATA_START_SYMBOLS - symbols that appear at the start of the
35 # .data section.
36 # DATA_END_SYMBOLS - symbols that appear at the end of the
37 # writeable data sections.
38 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
39 # OTHER_GOT_SECTIONS - sections just after .got.
40 # OTHER_PLT_SECTIONS - sections just after .plt.
41 # OTHER_SDATA_SECTIONS - sections just after .sdata.
42 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
43 # .bss section besides __bss_start.
44 # PLT_NEXT_DATA - .plt next to data segment when .plt is in text segment.
45 # DATA_PLT - .plt should be in data segment, not text segment.
46 # PLT_BEFORE_GOT - .plt just before .got when .plt is in data segement.
47 # BSS_PLT - .plt should be in bss segment
48 # NO_REL_RELOCS - Don't include .rel.* sections in script
49 # NO_RELA_RELOCS - Don't include .rela.* sections in script
50 # NON_ALLOC_DYN - Place dynamic sections after data segment.
51 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
52 # EMBEDDED - whether this is for an embedded system.
53 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
54 # start address of shared library.
55 # INPUT_FILES - INPUT command of files to always include
56 # WRITABLE_RODATA - if set, the .rodata section should be writable
57 # INIT_START, INIT_END - statements just before and just after
58 # combination of .init sections.
59 # FINI_START, FINI_END - statements just before and just after
60 # combination of .fini sections.
61 # STACK_ADDR - start of a .stack section.
62 # OTHER_SYMBOLS - symbols to place right at the end of the script.
63 # ETEXT_NAME - name of a symbol for the end of the text section,
64 # normally etext.
65 # ETEXT_LAST_IN_RODATA_SEGMENT - emit ETEXT_NAME after all sections in
66 # the read-only data segment (which may or may not be equal to
67 # the code segment), instead of after just the code parts.
68 # SEPARATE_CODE - if set, .text and similar sections containing
69 # actual machine instructions must be in wholly disjoint
70 # pages from any other data, including headers
71 # SEPARATE_GOTPLT - if set, .got.plt should be separate output section,
72 # so that .got can be in the RELRO area. It should be set to
73 # the number of bytes in the beginning of .got.plt which can be
74 # in the RELRO area as well.
75 # USER_LABEL_PREFIX - prefix to add to user-visible symbols.
76 # RODATA_NAME, SDATA_NAME, SBSS_NAME, BSS_NAME - base parts of names
77 # for standard sections, without initial "." or suffixes.
78 #
79 # When adding sections, do note that the names of some sections are used
80 # when specifying the start address of the next.
81 #
82
83 # Many sections come in three flavours. There is the 'real' section,
84 # like ".data". Then there are the per-procedure or per-variable
85 # sections, generated by -ffunction-sections and -fdata-sections in GCC,
86 # and useful for --gc-sections, which for a variable "foo" might be
87 # ".data.foo". Then there are the linkonce sections, for which the linker
88 # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
89 # The exact correspondences are:
90 #
91 # Section Linkonce section
92 # .text .gnu.linkonce.t.foo
93 # .rodata .gnu.linkonce.r.foo
94 # .data .gnu.linkonce.d.foo
95 # .bss .gnu.linkonce.b.foo
96 # .sdata .gnu.linkonce.s.foo
97 # .sbss .gnu.linkonce.sb.foo
98 # .sdata2 .gnu.linkonce.s2.foo
99 # .sbss2 .gnu.linkonce.sb2.foo
100 # .debug_info .gnu.linkonce.wi.foo
101 # .tdata .gnu.linkonce.td.foo
102 # .tbss .gnu.linkonce.tb.foo
103 # .lrodata .gnu.linkonce.lr.foo
104 # .ldata .gnu.linkonce.l.foo
105 # .lbss .gnu.linkonce.lb.foo
106 #
107 # Each of these can also have corresponding .rel.* and .rela.* sections.
108
109 if test -n "$NOP"; then
110 FILL="=$NOP"
111 else
112 FILL=
113 fi
114
115 test -n "$CREATE_SHLIB$CREATE_PIE" && CREATE_PIC=" "
116 test -z "$RODATA_NAME" && RODATA_NAME=rodata
117 test -z "$SDATA_NAME" && SDATA_NAME=sdata
118 test -z "$SBSS_NAME" && SBSS_NAME=sbss
119 test -z "$BSS_NAME" && BSS_NAME=bss
120 test -z "$ENTRY" && ENTRY=${USER_LABEL_PREFIX}_start
121 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
122 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
123 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
124 test -z "${ELFSIZE}" && ELFSIZE=32
125 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
126 test "$LD_FLAG" = "N" && DATA_ADDR=.
127 test -z "${ETEXT_NAME}" && ETEXT_NAME=${USER_LABEL_PREFIX}etext
128 test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT
129 test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }"
130 if test -z "$DATA_SEGMENT_ALIGN"; then
131 test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
132 test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
133 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
134 DATA_SEGMENT_RELRO_END=""
135 DATA_SEGMENT_END=""
136 if test -n "${COMMONPAGESIZE}"; then
137 if test "${SEGMENT_SIZE}" != "${MAXPAGESIZE}"; then
138 DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
139 else
140 DATA_SEGMENT_ALIGN="DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
141 fi
142 DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
143 DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
144 fi
145 fi
146 if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
147 INITIAL_READONLY_SECTIONS=".interp ${RELOCATING-0} : { *(.interp) }"
148 fi
149 if test -z "$PLT"; then
150 IPLT=".iplt ${RELOCATING-0} : { *(.iplt) }"
151 PLT=".plt ${RELOCATING-0} : { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }
152 ${IREL_IN_PLT-$IPLT}"
153 fi
154 test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=
155 if test -z "$GOT"; then
156 if test -z "$SEPARATE_GOTPLT"; then
157 GOT=".got ${RELOCATING-0} : {${RELOCATING+ *(.got.plt) *(.igot.plt)} *(.got)${RELOCATING+ *(.igot)} }"
158 else
159 GOT=".got ${RELOCATING-0} : { *(.got)${RELOCATING+ *(.igot)} }"
160 GOTPLT=".got.plt ${RELOCATING-0} : { *(.got.plt)${RELOCATING+ *(.igot.plt)} }"
161 fi
162 fi
163 REL_IFUNC=".rel.ifunc ${RELOCATING-0} : { *(.rel.ifunc) }"
164 RELA_IFUNC=".rela.ifunc ${RELOCATING-0} : { *(.rela.ifunc) }"
165 REL_IPLT=".rel.iplt ${RELOCATING-0} :
166 {
167 ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_start = .);}}
168 *(.rel.iplt)
169 ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_end = .);}}
170 }"
171 RELA_IPLT=".rela.iplt ${RELOCATING-0} :
172 {
173 ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_start = .);}}
174 *(.rela.iplt)
175 ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_end = .);}}
176 }"
177 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
178 RODATA=".${RODATA_NAME} ${RELOCATING-0} : { *(.${RODATA_NAME}${RELOCATING+ .${RODATA_NAME}.* .gnu.linkonce.r.*}) }"
179 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
180 DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
181 if test -z "${NO_SMALL_DATA}"; then
182 SBSS=".${SBSS_NAME} ${RELOCATING-0} :
183 {
184 ${RELOCATING+${SBSS_START_SYMBOLS}}
185 ${CREATE_SHLIB+*(.${SBSS_NAME}2 .${SBSS_NAME}2.* .gnu.linkonce.sb2.*)}
186 ${RELOCATING+*(.dyn${SBSS_NAME})}
187 *(.${SBSS_NAME}${RELOCATING+ .${SBSS_NAME}.* .gnu.linkonce.sb.*})
188 ${RELOCATING+*(.scommon)}
189 ${RELOCATING+${SBSS_END_SYMBOLS}}
190 }"
191 SBSS2=".${SBSS_NAME}2 ${RELOCATING-0} : { *(.${SBSS_NAME}2${RELOCATING+ .${SBSS_NAME}2.* .gnu.linkonce.sb2.*}) }"
192 SDATA="/* We want the small data sections together, so single-instruction offsets
193 can access them all, and initialized data all before uninitialized, so
194 we can shorten the on-disk segment size. */
195 .${SDATA_NAME} ${RELOCATING-0} :
196 {
197 ${RELOCATING+${SDATA_START_SYMBOLS}}
198 ${CREATE_SHLIB+*(.${SDATA_NAME}2 .${SDATA_NAME}2.* .gnu.linkonce.s2.*)}
199 *(.${SDATA_NAME}${RELOCATING+ .${SDATA_NAME}.* .gnu.linkonce.s.*})
200 }"
201 SDATA2=".${SDATA_NAME}2 ${RELOCATING-0} :
202 {
203 ${RELOCATING+${SDATA2_START_SYMBOLS}}
204 *(.${SDATA_NAME}2${RELOCATING+ .${SDATA_NAME}2.* .gnu.linkonce.s2.*})
205 }"
206 REL_SDATA=".rel.${SDATA_NAME} ${RELOCATING-0} : { *(.rel.${SDATA_NAME}${RELOCATING+ .rel.${SDATA_NAME}.* .rel.gnu.linkonce.s.*}) }
207 .rela.${SDATA_NAME} ${RELOCATING-0} : { *(.rela.${SDATA_NAME}${RELOCATING+ .rela.${SDATA_NAME}.* .rela.gnu.linkonce.s.*}) }"
208 REL_SBSS=".rel.${SBSS_NAME} ${RELOCATING-0} : { *(.rel.${SBSS_NAME}${RELOCATING+ .rel.${SBSS_NAME}.* .rel.gnu.linkonce.sb.*}) }
209 .rela.${SBSS_NAME} ${RELOCATING-0} : { *(.rela.${SBSS_NAME}${RELOCATING+ .rela.${SBSS_NAME}.* .rela.gnu.linkonce.sb.*}) }"
210 REL_SDATA2=".rel.${SDATA_NAME}2 ${RELOCATING-0} : { *(.rel.${SDATA_NAME}2${RELOCATING+ .rel.${SDATA_NAME}2.* .rel.gnu.linkonce.s2.*}) }
211 .rela.${SDATA_NAME}2 ${RELOCATING-0} : { *(.rela.${SDATA_NAME}2${RELOCATING+ .rela.${SDATA_NAME}2.* .rela.gnu.linkonce.s2.*}) }"
212 REL_SBSS2=".rel.${SBSS_NAME}2 ${RELOCATING-0} : { *(.rel.${SBSS_NAME}2${RELOCATING+ .rel.${SBSS_NAME}2.* .rel.gnu.linkonce.sb2.*}) }
213 .rela.${SBSS_NAME}2 ${RELOCATING-0} : { *(.rela.${SBSS_NAME}2${RELOCATING+ .rela.${SBSS_NAME}2.* .rela.gnu.linkonce.sb2.*}) }"
214 else
215 NO_SMALL_DATA=" "
216 fi
217 if test -z "${SDATA_GOT}${DATA_GOT}"; then
218 if test -n "${NO_SMALL_DATA}"; then
219 DATA_GOT=" "
220 fi
221 fi
222 if test -z "${SDATA_GOT}${DATA_GOT}"; then
223 if test -z "${NO_SMALL_DATA}"; then
224 SDATA_GOT=" "
225 fi
226 fi
227 test -n "$SEPARATE_GOTPLT" && SEPARATE_GOTPLT=" "
228 test "${LARGE_SECTIONS}" = "yes" && REL_LARGE="
229 .rel.ldata ${RELOCATING-0} : { *(.rel.ldata${RELOCATING+ .rel.ldata.* .rel.gnu.linkonce.l.*}) }
230 .rela.ldata ${RELOCATING-0} : { *(.rela.ldata${RELOCATING+ .rela.ldata.* .rela.gnu.linkonce.l.*}) }
231 .rel.lbss ${RELOCATING-0} : { *(.rel.lbss${RELOCATING+ .rel.lbss.* .rel.gnu.linkonce.lb.*}) }
232 .rela.lbss ${RELOCATING-0} : { *(.rela.lbss${RELOCATING+ .rela.lbss.* .rela.gnu.linkonce.lb.*}) }
233 .rel.lrodata ${RELOCATING-0} : { *(.rel.lrodata${RELOCATING+ .rel.lrodata.* .rel.gnu.linkonce.lr.*}) }
234 .rela.lrodata ${RELOCATING-0} : { *(.rela.lrodata${RELOCATING+ .rela.lrodata.* .rela.gnu.linkonce.lr.*}) }"
235 test "${LARGE_SECTIONS}" = "yes" && LARGE_BSS="
236 .lbss ${RELOCATING-0} :
237 {
238 ${RELOCATING+*(.dynlbss)}
239 *(.lbss${RELOCATING+ .lbss.* .gnu.linkonce.lb.*})
240 ${RELOCATING+*(LARGE_COMMON)}
241 }"
242 test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS="
243 .lrodata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
244 {
245 *(.lrodata${RELOCATING+ .lrodata.* .gnu.linkonce.lr.*})
246 }
247 .ldata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
248 {
249 *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*})
250 ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
251 }"
252 if test "${ENABLE_INITFINI_ARRAY}" = "yes"; then
253 SORT_INIT_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))"
254 SORT_FINI_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))"
255 CTORS_IN_INIT_ARRAY="EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors"
256 DTORS_IN_FINI_ARRAY="EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors"
257 else
258 SORT_INIT_ARRAY="KEEP (*(SORT(.init_array.*)))"
259 SORT_FINI_ARRAY="KEEP (*(SORT(.fini_array.*)))"
260 CTORS_IN_INIT_ARRAY=
261 DTORS_IN_FINI_ARRAY=
262 fi
263 PREINIT_ARRAY=".preinit_array :
264 {
265 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);}
266 KEEP (*(.preinit_array))
267 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}
268 }"
269 INIT_ARRAY=".init_array :
270 {
271 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}
272 ${SORT_INIT_ARRAY}
273 KEEP (*(.init_array ${CTORS_IN_INIT_ARRAY}))
274 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}
275 }"
276 FINI_ARRAY=".fini_array :
277 {
278 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}
279 ${SORT_FINI_ARRAY}
280 KEEP (*(.fini_array ${DTORS_IN_FINI_ARRAY}))
281 ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}
282 }"
283 CTOR=".ctors ${CONSTRUCTING-0} :
284 {
285 ${CONSTRUCTING+${CTOR_START}}
286 /* gcc uses crtbegin.o to find the start of
287 the constructors, so we make sure it is
288 first. Because this is a wildcard, it
289 doesn't matter if the user does not
290 actually link against crtbegin.o; the
291 linker won't look for a file to match a
292 wildcard. The wildcard also means that it
293 doesn't matter which directory crtbegin.o
294 is in. */
295
296 KEEP (*crtbegin.o(.ctors))
297 KEEP (*crtbegin?.o(.ctors))
298
299 /* We don't want to include the .ctor section from
300 the crtend.o file until after the sorted ctors.
301 The .ctor section from the crtend file contains the
302 end of ctors marker and it must be last */
303
304 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
305 KEEP (*(SORT(.ctors.*)))
306 KEEP (*(.ctors))
307 ${CONSTRUCTING+${CTOR_END}}
308 }"
309 DTOR=".dtors ${CONSTRUCTING-0} :
310 {
311 ${CONSTRUCTING+${DTOR_START}}
312 KEEP (*crtbegin.o(.dtors))
313 KEEP (*crtbegin?.o(.dtors))
314 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
315 KEEP (*(SORT(.dtors.*)))
316 KEEP (*(.dtors))
317 ${CONSTRUCTING+${DTOR_END}}
318 }"
319 STACK=".stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
320 {
321 ${RELOCATING+${USER_LABEL_PREFIX}_stack = .;}
322 *(.stack)
323 ${RELOCATING+${STACK_SENTINEL}}
324 }"
325
326 TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})"
327 SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${SHLIB_TEXT_START_ADDR:-0})"
328
329 # Don't bother with separate code segment when there are data sections
330 # between .plt and .text.
331 if test -z "$TINY_READONLY_SECTION"; then
332 case "$LD_FLAG" in
333 *textonly*)
334 SEPARATE_TEXT=" "
335 TEXT_SEGMENT_ALIGN=". = ALIGN(${MAXPAGESIZE});"
336 ;;
337 esac
338 fi
339
340 if [ -z "$SEPARATE_CODE" ]; then
341 SIZEOF_HEADERS_CODE=" + SIZEOF_HEADERS"
342 else
343 SIZEOF_HEADERS_CODE=
344 fi
345
346 # If this is for an embedded system, don't add SIZEOF_HEADERS.
347 if [ -z "$EMBEDDED" ]; then
348 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}${SIZEOF_HEADERS_CODE}"
349 else
350 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
351 fi
352
353 cat <<EOF
354 /* Copyright (C) 2014-2020 Free Software Foundation, Inc.
355
356 Copying and distribution of this script, with or without modification,
357 are permitted in any medium without royalty provided the copyright
358 notice and this notice are preserved. */
359
360 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
361 "${LITTLE_OUTPUT_FORMAT}")
362 OUTPUT_ARCH(${OUTPUT_ARCH})
363 ${RELOCATING+ENTRY(${ENTRY})}
364
365 ${RELOCATING+${LIB_SEARCH_DIRS}}
366 ${RELOCATING+${CREATE_SHLIB-${EXECUTABLE_SYMBOLS}}}
367 ${RELOCATING+${INPUT_FILES}}
368 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
369 if gld -r is used and the intermediate file has sections starting
370 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
371 bug. But for now assigning the zero vmas works. */}
372
373 SECTIONS
374 {
375 ${RELOCATING+${SEPARATE_TEXT-/* Read-only sections, merged into text segment: */}}
376 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
377 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR}${SIZEOF_HEADERS_CODE};}}
378 ${CREATE_PIE+${RELOCATING+PROVIDE (__executable_start = ${SHLIB_TEXT_START_ADDR}); . = ${SHLIB_TEXT_START_ADDR}${SIZEOF_HEADERS_CODE};}}
379 EOF
380
381 emit_early_ro()
382 {
383 cat <<EOF
384 ${INITIAL_READONLY_SECTIONS}
385 .note.gnu.build-id ${RELOCATING-0}: { *(.note.gnu.build-id) }
386 EOF
387 }
388
389 test -n "${SEPARATE_CODE}" || emit_early_ro
390
391 test -n "${RELOCATING+0}" || unset NON_ALLOC_DYN
392 test -z "${NON_ALLOC_DYN}" || TEXT_DYNAMIC=
393 cat > ldscripts/dyntmp.$$ <<EOF
394 ${TEXT_DYNAMIC+${DYNAMIC}}
395 .hash ${RELOCATING-0} : { *(.hash) }
396 .gnu.hash ${RELOCATING-0} : { *(.gnu.hash) }
397 .dynsym ${RELOCATING-0} : { *(.dynsym) }
398 .dynstr ${RELOCATING-0} : { *(.dynstr) }
399 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
400 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
401 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
402 EOF
403
404 if [ "x$COMBRELOC" = x ]; then
405 COMBRELOCCAT="cat >> ldscripts/dyntmp.$$"
406 else
407 COMBRELOCCAT="cat > $COMBRELOC"
408 fi
409 eval $COMBRELOCCAT <<EOF
410 ${INITIAL_RELOC_SECTIONS}
411 .rel.init ${RELOCATING-0} : { *(.rel.init) }
412 .rela.init ${RELOCATING-0} : { *(.rela.init) }
413 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
414 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
415 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
416 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
417 .rel.${RODATA_NAME} ${RELOCATING-0} : { *(.rel.${RODATA_NAME}${RELOCATING+ .rel.${RODATA_NAME}.* .rel.gnu.linkonce.r.*}) }
418 .rela.${RODATA_NAME} ${RELOCATING-0} : { *(.rela.${RODATA_NAME}${RELOCATING+ .rela.${RODATA_NAME}.* .rela.gnu.linkonce.r.*}) }
419 ${OTHER_READONLY_RELOC_SECTIONS}
420 .rel.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+ .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*}) }
421 .rela.data.rel.ro ${RELOCATING-0} : { *(.rela.data.rel.ro${RELOCATING+ .rela.data.rel.ro.* .rela.gnu.linkonce.d.rel.ro.*}) }
422 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
423 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
424 ${OTHER_READWRITE_RELOC_SECTIONS}
425 .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
426 .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
427 .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
428 .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
429 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
430 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
431 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
432 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
433 .rel.got ${RELOCATING-0} : { *(.rel.got) }
434 .rela.got ${RELOCATING-0} : { *(.rela.got) }
435 ${OTHER_GOT_RELOC_SECTIONS}
436 ${REL_SDATA}
437 ${REL_SBSS}
438 ${REL_SDATA2}
439 ${REL_SBSS2}
440 .rel.${BSS_NAME} ${RELOCATING-0} : { *(.rel.${BSS_NAME}${RELOCATING+ .rel.${BSS_NAME}.* .rel.gnu.linkonce.b.*}) }
441 .rela.${BSS_NAME} ${RELOCATING-0} : { *(.rela.${BSS_NAME}${RELOCATING+ .rela.${BSS_NAME}.* .rela.gnu.linkonce.b.*}) }
442 ${REL_LARGE}
443 ${IREL_IN_PLT+$REL_IFUNC}
444 ${IREL_IN_PLT+$RELA_IFUNC}
445 ${IREL_IN_PLT-$REL_IPLT}
446 ${IREL_IN_PLT-$RELA_IPLT}
447 EOF
448
449 if [ -n "$COMBRELOC" ]; then
450 cat >> ldscripts/dyntmp.$$ <<EOF
451 .rel.dyn ${RELOCATING-0} :
452 {
453 EOF
454 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;/__rela_iplt_/d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC >> ldscripts/dyntmp.$$
455 cat >> ldscripts/dyntmp.$$ <<EOF
456 }
457 .rela.dyn ${RELOCATING-0} :
458 {
459 EOF
460 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;/__rel_iplt_/d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC >> ldscripts/dyntmp.$$
461 cat >> ldscripts/dyntmp.$$ <<EOF
462 }
463 EOF
464 fi
465
466 cat >> ldscripts/dyntmp.$$ <<EOF
467 .rel.plt ${RELOCATING-0} :
468 {
469 *(.rel.plt)
470 ${IREL_IN_PLT+${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_start = .);}}}
471 ${IREL_IN_PLT+${RELOCATING+*(.rel.iplt)}}
472 ${IREL_IN_PLT+${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_end = .);}}}
473 }
474 .rela.plt ${RELOCATING-0} :
475 {
476 *(.rela.plt)
477 ${IREL_IN_PLT+${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_start = .);}}}
478 ${IREL_IN_PLT+${RELOCATING+*(.rela.iplt)}}
479 ${IREL_IN_PLT+${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_end = .);}}}
480 }
481 ${OTHER_PLT_RELOC_SECTIONS}
482 EOF
483
484 emit_dyn()
485 {
486 if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
487 cat ldscripts/dyntmp.$$
488 else
489 if test -z "${NO_REL_RELOCS}"; then
490 sed -e '/^[ ]*\.rela\.[^}]*$/,/}/d;/^[ ]*\.rela\./d;/__rela_iplt_/d' ldscripts/dyntmp.$$
491 fi
492 if test -z "${NO_RELA_RELOCS}"; then
493 sed -e '/^[ ]*\.rel\.[^}]*$/,/}/d;/^[ ]*\.rel\./d;/__rel_iplt_/d' ldscripts/dyntmp.$$
494 fi
495 fi
496 rm -f ldscripts/dyntmp.$$
497 }
498
499 test -n "${NON_ALLOC_DYN}${SEPARATE_CODE}" || emit_dyn
500
501 cat <<EOF
502 ${RELOCATING+${TEXT_SEGMENT_ALIGN}}
503
504 .init ${RELOCATING-0}${RELOCATING+${INIT_ADDR}} :
505 {
506 ${RELOCATING+${INIT_START}}
507 KEEP (*(SORT_NONE(.init)))
508 ${RELOCATING+${INIT_END}}
509 } ${FILL}
510
511 ${TEXT_PLT+${PLT_NEXT_DATA-${PLT} ${OTHER_PLT_SECTIONS}}}
512 ${TINY_READONLY_SECTION}
513 .text ${RELOCATING-0} :
514 {
515 ${RELOCATING+${TEXT_START_SYMBOLS}}
516 ${RELOCATING+*(.text.unlikely .text.*_unlikely .text.unlikely.*)}
517 ${RELOCATING+*(.text.exit .text.exit.*)}
518 ${RELOCATING+*(.text.startup .text.startup.*)}
519 ${RELOCATING+*(.text.hot .text.hot.*)}
520 ${RELOCATING+*(SORT(.text.sorted.*))}
521 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
522 /* .gnu.warning sections are handled specially by elf.em. */
523 *(.gnu.warning)
524 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
525 } ${FILL}
526 .fini ${RELOCATING-0}${RELOCATING+${FINI_ADDR}} :
527 {
528 ${RELOCATING+${FINI_START}}
529 KEEP (*(SORT_NONE(.fini)))
530 ${RELOCATING+${FINI_END}}
531 } ${FILL}
532 ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT-PROVIDE (__${ETEXT_NAME} = .);}}
533 ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT-PROVIDE (_${ETEXT_NAME} = .);}}
534 ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT-PROVIDE (${ETEXT_NAME} = .);}}
535 ${RELOCATING+${TEXT_SEGMENT_ALIGN}}
536 EOF
537
538 if test -n "${SEPARATE_CODE}${SEPARATE_TEXT}"; then
539 if test -n "${RODATA_ADDR}"; then
540 RODATA_ADDR="\
541 SEGMENT_START(\"rodata-segment\", ${RODATA_ADDR}) + SIZEOF_HEADERS"
542 else
543 RODATA_ADDR="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
544 RODATA_ADDR="SEGMENT_START(\"rodata-segment\", ${RODATA_ADDR})"
545 fi
546 if test -n "${SHLIB_RODATA_ADDR}"; then
547 SHLIB_RODATA_ADDR="\
548 SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR}) + SIZEOF_HEADERS"
549 else
550 SHLIB_RODATA_ADDR="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
551 SHLIB_RODATA_ADDR="SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR})"
552 fi
553 cat <<EOF
554 ${RELOCATING+/* Adjust the address for the rodata segment. We want to adjust up to
555 the same address within the page on the next page up. */
556 ${CREATE_SHLIB-${CREATE_PIE-. = ${RODATA_ADDR};}}
557 ${CREATE_SHLIB+. = ${SHLIB_RODATA_ADDR};}
558 ${CREATE_PIE+. = ${SHLIB_RODATA_ADDR};}}
559 EOF
560 if test -n "${SEPARATE_CODE}"; then
561 emit_early_ro
562 emit_dyn
563 fi
564 fi
565
566 cat <<EOF
567 ${WRITABLE_RODATA-${RODATA}}
568 .${RODATA_NAME}1 ${RELOCATING-0} : { *(.${RODATA_NAME}1) }
569 ${CREATE_SHLIB-${SDATA2}}
570 ${CREATE_SHLIB-${SBSS2}}
571 ${OTHER_READONLY_SECTIONS}
572 .eh_frame_hdr ${RELOCATING-0} : { *(.eh_frame_hdr)${RELOCATING+ *(.eh_frame_entry .eh_frame_entry.*)} }
573 .eh_frame ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} }
574 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
575 .gnu_extab ${RELOCATING-0} : ONLY_IF_RO { *(.gnu_extab*) }
576 /* These sections are generated by the Sun/Oracle C++ compiler. */
577 .exception_ranges ${RELOCATING-0} : ONLY_IF_RO { *(.exception_ranges${RELOCATING+*}) }
578 ${TEXT_PLT+${PLT_NEXT_DATA+${PLT} ${OTHER_PLT_SECTIONS}}}
579
580 ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT+PROVIDE (__${ETEXT_NAME} = .);}}
581 ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT+PROVIDE (_${ETEXT_NAME} = .);}}
582 ${RELOCATING+${ETEXT_LAST_IN_RODATA_SEGMENT+PROVIDE (${ETEXT_NAME} = .);}}
583
584 ${RELOCATING+/* Adjust the address for the data segment. We want to adjust up to
585 the same address within the page on the next page up. */}
586 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
587 ${CREATE_SHLIB+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}
588 ${CREATE_PIE+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}
589
590 /* Exception handling */
591 .eh_frame ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} }
592 .gnu_extab ${RELOCATING-0} : ONLY_IF_RW { *(.gnu_extab) }
593 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
594 .exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges${RELOCATING+*}) }
595
596 /* Thread Local Storage sections */
597 .tdata ${RELOCATING-0} :
598 {
599 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__tdata_start = .);}}
600 *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*})
601 }
602 .tbss ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
603
604 ${RELOCATING+${PREINIT_ARRAY}}
605 ${RELOCATING+${INIT_ARRAY}}
606 ${RELOCATING+${FINI_ARRAY}}
607 ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
608 ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}
609 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
610
611 ${RELOCATING+${DATARELRO}}
612 ${OTHER_RELRO_SECTIONS}
613 ${TEXT_DYNAMIC-${DYNAMIC}}
614 ${OTHER_RELRO_SECTIONS_2}
615 ${DATA_GOT+${RELRO_NOW+${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}}}
616 ${DATA_GOT+${RELRO_NOW+${GOT}}}
617 ${DATA_GOT+${RELRO_NOW+${GOTPLT}}}
618 ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT+${GOT}}}}
619 ${RELOCATING+${DATA_SEGMENT_RELRO_END}}
620 ${INITIAL_READWRITE_SECTIONS}
621 ${DATA_SDATA+${SDATA}}
622 ${DATA_SDATA+${OTHER_SDATA_SECTIONS}}
623 ${DATA_SDATA+${SBSS}}
624 ${DATA_GOT+${RELRO_NOW-${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}}}
625 ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT-${GOT}}}}
626 ${DATA_GOT+${RELRO_NOW-${GOTPLT}}}
627
628 ${DATA_PLT+${PLT_BEFORE_GOT-${PLT}}}
629
630 .data ${RELOCATING-0} :
631 {
632 ${RELOCATING+${DATA_START_SYMBOLS}}
633 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
634 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
635 }
636 .data1 ${RELOCATING-0} : { *(.data1) }
637 ${WRITABLE_RODATA+${RODATA}}
638 ${OTHER_READWRITE_SECTIONS}
639 ${SMALL_DATA_CTOR+${RELOCATING+${CTOR}}}
640 ${SMALL_DATA_DTOR+${RELOCATING+${DTOR}}}
641 ${SDATA_GOT+${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}}
642 ${SDATA_GOT+${RELOCATING+${OTHER_GOT_SYMBOLS+. = .; ${OTHER_GOT_SYMBOLS}}}}
643 ${SDATA_GOT+${GOT}}
644 ${SDATA_GOT+${OTHER_GOT_SECTIONS}}
645 ${DATA_SDATA-${SDATA}}
646 ${DATA_SDATA-${OTHER_SDATA_SECTIONS}}
647 ${RELOCATING+${DATA_END_SYMBOLS-${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}_edata = .${CREATE_SHLIB+)}; PROVIDE (${USER_LABEL_PREFIX}edata = .);}}
648 ${RELOCATING+. = .;}
649 ${RELOCATING+${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}__bss_start = .${CREATE_SHLIB+)};}
650 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
651 ${DATA_SDATA-${SBSS}}
652 ${BSS_PLT+${PLT}}
653 .${BSS_NAME} ${RELOCATING-0} :
654 {
655 ${RELOCATING+*(.dynbss)}
656 *(.${BSS_NAME}${RELOCATING+ .${BSS_NAME}.* .gnu.linkonce.b.*})
657 ${RELOCATING+*(COMMON)
658 /* Align here to ensure that the .bss section occupies space up to
659 _end. Align after .bss to ensure correct alignment even if the
660 .bss section disappears because there are no input sections.
661 FIXME: Why do we need it? When there is no .bss section, we do not
662 pad the .data section. */
663 . = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
664 }
665 ${OTHER_BSS_SECTIONS}
666 ${LARGE_BSS_AFTER_BSS+${LARGE_BSS}}
667 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
668 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
669 EOF
670
671 LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${LARGE_DATA_ADDR-.});"
672 SHLIB_LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${SHLIB_LARGE_DATA_ADDR-.});"
673
674 cat <<EOF
675 ${RELOCATING+${CREATE_SHLIB-${CREATE_PIE-${LARGE_DATA_ADDR}}}}
676 ${CREATE_SHLIB+${SHLIB_LARGE_DATA_ADDR}}
677 ${CREATE_PIE+${SHLIB_LARGE_DATA_ADDR}}
678 ${LARGE_SECTIONS}
679 ${LARGE_BSS_AFTER_BSS-${LARGE_BSS}}
680 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
681 ${RELOCATING+${OTHER_END_SYMBOLS}}
682 ${RELOCATING+${END_SYMBOLS-${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}_end = .${CREATE_SHLIB+)}; PROVIDE (${USER_LABEL_PREFIX}end = .);}}
683 ${RELOCATING+${DATA_SEGMENT_END}}
684 ${TINY_DATA_SECTION}
685 ${TINY_BSS_SECTION}
686 ${STACK_ADDR+${STACK}}
687 EOF
688
689 test -z "${NON_ALLOC_DYN}" || emit_dyn
690
691 cat <<EOF
692 /* Stabs debugging sections. */
693 .stab 0 : { *(.stab) }
694 .stabstr 0 : { *(.stabstr) }
695 .stab.excl 0 : { *(.stab.excl) }
696 .stab.exclstr 0 : { *(.stab.exclstr) }
697 .stab.index 0 : { *(.stab.index) }
698 .stab.indexstr 0 : { *(.stab.indexstr) }
699
700 .comment 0 : { *(.comment) }
701
702 .gnu.build.attributes : { *(.gnu.build.attributes${RELOCATING+ .gnu.build.attributes.*}) }
703
704 EOF
705
706 . $srcdir/scripttempl/DWARF.sc
707
708 cat <<EOF
709 ${ATTRS_SECTIONS}
710 ${OTHER_SECTIONS}
711 ${RELOCATING+${OTHER_SYMBOLS}}
712 ${RELOCATING+${DISCARDED}}
713 }
714 EOF