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