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