1 # This variant of elf.sc is used for ARM BPABI platforms, like Symbian
2 # OS, where a separate postlinker will operated on the generated
3 # executable or shared object. See elf.sc for configuration variables
4 # that apply; only BPABI-specific variables will be noted here.
6 # Copyright (C) 2014-2020 Free Software Foundation, Inc.
8 # Copying and distribution of this file, with or without modification,
9 # are permitted in any medium without royalty provided the copyright
10 # notice and this notice are preserved.
12 test -z "$ENTRY" && ENTRY=_start
13 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
14 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
15 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
16 test -z "${ELFSIZE}" && ELFSIZE=32
17 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
18 test "$LD_FLAG" = "N" && DATA_ADDR=.
19 test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
20 test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
21 test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT
22 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
23 DATA_SEGMENT_RELRO_END=""
24 DATA_SEGMENT_RELRO_GOTPLT_END=""
26 if test -n "${COMMONPAGESIZE}"; then
27 DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
28 DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
29 if test -n "${SEPARATE_GOTPLT}"; then
30 DATA_SEGMENT_RELRO_GOTPLT_END=". = DATA_SEGMENT_RELRO_END (. + ${SEPARATE_GOTPLT});"
32 DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (.);"
35 INTERP=".interp 0 : { *(.interp) }"
36 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
37 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
38 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro .data.rel.ro.*) }"
39 DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
40 if test -z "${NO_SMALL_DATA}"; then
41 SBSS=".sbss ${RELOCATING-0} :
43 ${RELOCATING+PROVIDE (__sbss_start = .);}
44 ${RELOCATING+PROVIDE (___sbss_start = .);}
45 ${RELOCATING+*(.dynsbss)}
46 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
47 ${RELOCATING+*(.scommon)}
48 ${RELOCATING+PROVIDE (__sbss_end = .);}
49 ${RELOCATING+PROVIDE (___sbss_end = .);}
51 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
52 SDATA="/* We want the small data sections together, so single-instruction offsets
53 can access them all, and initialized data all before uninitialized, so
54 we can shorten the on-disk segment size. */
55 .sdata ${RELOCATING-0} :
57 ${RELOCATING+${SDATA_START_SYMBOLS}}
58 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
60 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }"
61 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
62 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
63 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
64 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
65 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
66 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
67 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
68 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
72 test -n "$SEPARATE_GOTPLT" && SEPARATE_GOTPLT=" "
73 INIT_ARRAY=".init_array ${RELOCATING-0} :
75 /* SymbianOS uses this symbol. */
76 ${RELOCATING+PROVIDE (SHT\$\$INIT_ARRAY\$\$Base = .);}
77 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__init_array_start = .);}}
78 KEEP (*(SORT(.init_array.*)))
80 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__init_array_end = .);}}
81 /* SymbianOS uses this symbol. */
82 ${RELOCATING+PROVIDE (SHT\$\$INIT_ARRAY\$\$Limit = .);}
84 FINI_ARRAY=".fini_array ${RELOCATING-0} :
86 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__fini_array_start = .);}}
87 KEEP (*(SORT(.fini_array.*)))
89 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__fini_array_end = .);}}
91 CTOR=".ctors ${CONSTRUCTING-0} :
93 ${CONSTRUCTING+${CTOR_START}}
94 /* gcc uses crtbegin.o to find the start of
95 the constructors, so we make sure it is
96 first. Because this is a wildcard, it
97 doesn't matter if the user does not
98 actually link against crtbegin.o; the
99 linker won't look for a file to match a
100 wildcard. The wildcard also means that it
101 doesn't matter which directory crtbegin.o
104 KEEP (*crtbegin.o(.ctors))
105 KEEP (*crtbegin?.o(.ctors))
107 /* We don't want to include the .ctor section from
108 the crtend.o file until after the sorted ctors.
109 The .ctor section from the crtend file contains the
110 end of ctors marker and it must be last */
112 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
113 KEEP (*(SORT(.ctors.*)))
115 ${CONSTRUCTING+${CTOR_END}}
117 DTOR=".dtors ${CONSTRUCTING-0} :
119 ${CONSTRUCTING+${DTOR_START}}
120 KEEP (*crtbegin.o(.dtors))
121 KEEP (*crtbegin?.o(.dtors))
122 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
123 KEEP (*(SORT(.dtors.*)))
125 ${CONSTRUCTING+${DTOR_END}}
127 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
129 ${RELOCATING+_stack = .;}
133 TEXT_START_ADDR="SEGMENT_START(\"text\", ${TEXT_START_ADDR})"
134 SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text\", ${SHLIB_TEXT_START_ADDR:-0})"
135 DATA_ADDR="SEGMENT_START(\"data\", ${DATA_ADDR-${DATA_SEGMENT_ALIGN}})"
136 SHLIB_DATA_ADDR="SEGMENT_START(\"data\", ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}})"
138 # If this is for an embedded system, don't add SIZEOF_HEADERS.
139 if [ -z "$EMBEDDED" ]; then
140 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
141 SHLIB_BASE_ADDRESS="${SHLIB_TEXT_START_ADDR} + SIZEOF_HEADERS"
143 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
144 SHLIB_BASE_ADDRESS="${SHLIB_TEXT_START_ADDR}"
148 /* Copyright (C) 2014-2020 Free Software Foundation, Inc.
150 Copying and distribution of this script, with or without modification,
151 are permitted in any medium without royalty provided the copyright
152 notice and this notice are preserved. */
154 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
155 "${LITTLE_OUTPUT_FORMAT}")
156 OUTPUT_ARCH(${OUTPUT_ARCH})
159 test -n "${RELOCATING}" && cat <<EOF
163 /* Do we need any of these for elf?
164 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */
165 ${EXECUTABLE_SYMBOLS}
168 /* ARM's proprietary toolchain generate these symbols to match the start
169 and end of particular sections of the image. SymbianOS uses these
170 symbols. We provide them for compatibility with ARM's toolchains.
171 These symbols should be bound locally; each shared object may define
172 its own version of these symbols. */
176 /* Give these a dummy version to work around linker lameness.
177 The name used shouldn't matter as these are all local symbols. */
180 Image\$\$ER_RO\$\$Base;
181 Image\$\$ER_RO\$\$Limit;
182 SHT\$\$INIT_ARRAY\$\$Base;
183 SHT\$\$INIT_ARRAY\$\$Limit;
194 /* Read-only sections, merged into text segment: */
195 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR});}}}
197 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+ . = ${TEXT_BASE_ADDRESS};}}}
198 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_BASE_ADDRESS};}}
199 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_BASE_ADDRESS};}}
201 /* Define Image\$\$ER_RO\$\$Base. */
202 ${RELOCATING+PROVIDE (Image\$\$ER_RO\$\$Base = .);}
204 ${INITIAL_READONLY_SECTIONS}
208 .init ${RELOCATING-0} :
210 ${RELOCATING+${INIT_START}}
211 KEEP (*(SORT_NONE(.init)))
212 ${RELOCATING+${INIT_END}}
214 .text ${RELOCATING-0} :
216 ${RELOCATING+${TEXT_START_SYMBOLS}}
217 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
218 /* .gnu.warning sections are handled specially by elf.em. */
220 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
222 .fini ${RELOCATING-0} :
224 ${RELOCATING+${FINI_START}}
225 KEEP (*(SORT_NONE(.fini)))
226 ${RELOCATING+${FINI_END}}
228 /* The SymbianOS kernel requires that the PLT go at the end of the
230 ${DATA_PLT-${BSS_PLT-${PLT}}}
231 ${RELOCATING+PROVIDE (__etext = .);}
232 ${RELOCATING+PROVIDE (_etext = .);}
233 ${RELOCATING+PROVIDE (etext = .);}
235 /* Define Image\$\$ER_RO\$\$Limit. */
236 ${RELOCATING+PROVIDE (Image\$\$ER_RO\$\$Limit = .);}
238 ${WRITABLE_RODATA-${RODATA}}
239 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
240 ${CREATE_SHLIB-${SDATA2}}
241 ${CREATE_SHLIB-${SBSS2}}
243 /* On SymbianOS, put .init_array and friends in the read-only
244 segment; there is no runtime relocation applied to these
247 .preinit_array ${RELOCATING-0} :
249 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__preinit_array_start = .);}}
250 KEEP (*(.preinit_array))
251 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__preinit_array_end = .);}}
253 ${RELOCATING+${INIT_ARRAY}}
254 ${RELOCATING+${FINI_ARRAY}}
256 ${OTHER_READONLY_SECTIONS}
257 .eh_frame_hdr ${RELOCATING-0} : { *(.eh_frame_hdr) }
258 .eh_frame ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
259 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.gcc_except_table${RELOCATING+ .gcc_except_table.*})) }
261 /* Adjust the address for the data segment. We want to adjust up to
262 the same address within the page on the next page up. */
263 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR};}}}
264 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR};}}
265 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR};}}
267 /* Exception handling */
268 .eh_frame ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
269 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.gcc_except_table${RELOCATING+ .gcc_except_table.*})) }
271 /* Thread Local Storage sections */
272 .tdata ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
273 .tbss ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
275 ${RELOCATING+${CTOR}}
276 ${RELOCATING+${DTOR}}
277 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
279 ${RELOCATING+${DATARELRO}}
280 ${OTHER_RELRO_SECTIONS}
281 ${RELOCATING+${DATA_SEGMENT_RELRO_END}}
283 ${DATA_PLT+${PLT_BEFORE_GOT-${PLT}}}
285 .data ${RELOCATING-0} :
287 ${RELOCATING+${DATA_START_SYMBOLS}}
288 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
289 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
291 .data1 ${RELOCATING-0} : { *(.data1) }
292 ${WRITABLE_RODATA+${RODATA}}
293 ${OTHER_READWRITE_SECTIONS}
294 ${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}
295 ${CREATE_SHLIB+${SDATA2}}
296 ${CREATE_SHLIB+${SBSS2}}
298 ${OTHER_SDATA_SECTIONS}
299 ${RELOCATING+_edata = .;}
300 ${RELOCATING+PROVIDE (edata = .);}
301 ${RELOCATING+. = DEFINED(__bss_segment_start) ? __bss_segment_start : .;}
302 ${RELOCATING+__bss_start = .;}
303 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
306 .bss ${RELOCATING-0} :
308 ${RELOCATING+*(.dynbss)}
309 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
310 ${RELOCATING+*(COMMON)
311 /* Align here to ensure that the .bss section occupies space up to
312 _end. Align after .bss to ensure correct alignment even if the
313 .bss section disappears because there are no input sections. */
314 . = ALIGN(${ALIGNMENT});}
316 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
317 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
318 ${RELOCATING+${OTHER_END_SYMBOLS}}
319 ${RELOCATING+_end = .;}
320 ${RELOCATING+PROVIDE (end = .);}
321 ${RELOCATING+${DATA_SEGMENT_END}}
322 ${STACK_ADDR+${STACK}}
324 /* These sections are not mapped under the BPABI. */
325 .dynamic 0 : { *(.dynamic) }
326 .hash 0 : { *(.hash) }
327 .dynsym 0 : { *(.dynsym) }
328 .dynstr 0 : { *(.dynstr) }
329 .gnu.version 0 : { *(.gnu.version) }
330 .gnu.version_d 0: { *(.gnu.version_d) }
331 .gnu.version_r 0: { *(.gnu.version_r) }
332 ${CREATE_SHLIB-${INTERP}}
334 /* Stabs debugging sections. */
335 .stab 0 : { *(.stab) }
336 .stabstr 0 : { *(.stabstr) }
337 .stab.excl 0 : { *(.stab.excl) }
338 .stab.exclstr 0 : { *(.stab.exclstr) }
339 .stab.index 0 : { *(.stab.index) }
340 .stab.indexstr 0 : { *(.stab.indexstr) }
342 .comment 0 : { *(.comment) }
345 . $srcdir/scripttempl/DWARF.sc
349 ${RELOCATING+${OTHER_SYMBOLS}}
350 ${RELOCATING+${DISCARDED}}
353 # These relocations sections are part of the read-only segment in SVR4
354 # executables, but are not mapped in BPABI executables.
355 if [ "x$COMBRELOC" = x ]; then
358 COMBRELOCCAT="cat > $COMBRELOC"
360 eval $COMBRELOCCAT <<EOF
361 .rel.init 0 : { *(.rel.init) }
362 .rela.init 0 : { *(.rela.init) }
363 .rel.text 0 : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
364 .rela.text 0 : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
365 .rel.fini 0 : { *(.rel.fini) }
366 .rela.fini 0 : { *(.rela.fini) }
367 .rel.rodata 0 : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
368 .rela.rodata 0 : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
369 ${OTHER_READONLY_RELOC_SECTIONS}
370 .rel.data.rel.ro 0 : { *(.rel.data.rel.ro${RELOCATING+ .rel.data.rel.ro.*}) }
371 .rela.data.rel.ro 0 : { *(.rela.data.rel.ro${RELOCATING+ .rela.data.rel.ro.*}) }
372 .rel.data 0 : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
373 .rela.data 0 : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
374 .rel.tdata 0 : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
375 .rela.tdata 0 : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
376 .rel.tbss 0 : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
377 .rela.tbss 0 : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
378 .rel.ctors 0 : { *(.rel.ctors) }
379 .rela.ctors 0 : { *(.rela.ctors) }
380 .rel.dtors 0 : { *(.rel.dtors) }
381 .rela.dtors 0 : { *(.rela.dtors) }
386 .rel.bss 0 : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
387 .rela.bss 0 : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
388 .rel.init_array 0 : { *(.rel.init_array) }
389 .rela.init_array 0 : { *(.rela.init_array) }
390 .rel.fini_array 0 : { *(.rel.fini_array) }
391 .rela.fini_array 0 : { *(.rela.fini_array) }
393 if [ -n "$COMBRELOC" ]; then
398 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
404 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
410 .rel.plt 0 : { *(.rel.plt) }
411 .rela.plt 0 : { *(.rela.plt) }
412 ${OTHER_PLT_RELOC_SECTIONS}
413 .rel.other 0 : { *(.rel.*) }
414 .rela.other 0 : { *(.rela.*) }
415 .reli.other 0 : { *(.reli.*) }