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