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