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