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