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