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 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 = .);}
46 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
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 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})
157 ${RELOCATING+ENTRY(${ENTRY})}
159 ${RELOCATING+${LIB_SEARCH_DIRS}}
160 ${RELOCATING+/* Do we need any of these for elf?
161 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
162 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
163 ${RELOCATING+${INPUT_FILES}}
164 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
165 if gld -r is used and the intermediate file has sections starting
166 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
167 bug. But for now assigning the zero vmas works. */}
169 /* ARM's proprietary toolchain generate these symbols to match the start
170 and end of particular sections of the image. SymbianOS uses these
171 symbols. We provide them for compatibility with ARM's toolchains.
172 These symbols should be bound locally; each shared object may define
173 its own version of these symbols. */
177 /* Give these a dummy version to work around linker lameness.
178 The name used shouldn't matter as these are all local symbols. */
181 Image\$\$ER_RO\$\$Base;
182 Image\$\$ER_RO\$\$Limit;
183 SHT\$\$INIT_ARRAY\$\$Base;
184 SHT\$\$INIT_ARRAY\$\$Limit;
192 /* Read-only sections, merged into text segment: */
193 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR});}}}
195 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+ . = ${TEXT_BASE_ADDRESS};}}}
196 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_BASE_ADDRESS};}}
197 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_BASE_ADDRESS};}}
199 /* Define Image\$\$ER_RO\$\$Base. */
200 ${RELOCATING+PROVIDE (Image\$\$ER_RO\$\$Base = .);}
202 ${INITIAL_READONLY_SECTIONS}
206 .init ${RELOCATING-0} :
208 ${RELOCATING+${INIT_START}}
210 ${RELOCATING+${INIT_END}}
212 .text ${RELOCATING-0} :
214 ${RELOCATING+${TEXT_START_SYMBOLS}}
215 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
216 /* .gnu.warning sections are handled specially by elf32.em. */
218 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
220 .fini ${RELOCATING-0} :
222 ${RELOCATING+${FINI_START}}
224 ${RELOCATING+${FINI_END}}
226 /* The SymbianOS kernel requires that the PLT go at the end of the
228 ${DATA_PLT-${BSS_PLT-${PLT}}}
229 ${RELOCATING+PROVIDE (__etext = .);}
230 ${RELOCATING+PROVIDE (_etext = .);}
231 ${RELOCATING+PROVIDE (etext = .);}
233 /* Define Image\$\$ER_RO\$\$Limit. */
234 ${RELOCATING+PROVIDE (Image\$\$ER_RO\$\$Limit = .);}
236 ${WRITABLE_RODATA-${RODATA}}
237 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
238 ${CREATE_SHLIB-${SDATA2}}
239 ${CREATE_SHLIB-${SBSS2}}
241 /* On SymbianOS, put .init_array and friends in the read-only
242 segment; there is no runtime relocation applied to these
245 .preinit_array ${RELOCATING-0} :
247 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__preinit_array_start = .);}}
248 KEEP (*(.preinit_array))
249 ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__preinit_array_end = .);}}
251 ${RELOCATING+${INIT_ARRAY}}
252 ${RELOCATING+${FINI_ARRAY}}
254 ${OTHER_READONLY_SECTIONS}
255 .eh_frame_hdr : { *(.eh_frame_hdr) }
256 .eh_frame ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
257 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
259 /* Adjust the address for the data segment. We want to adjust up to
260 the same address within the page on the next page up. */
261 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR};}}}
262 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR};}}
263 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR};}}
265 /* Exception handling */
266 .eh_frame ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
267 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
269 /* Thread Local Storage sections */
270 .tdata ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
271 .tbss ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
273 ${RELOCATING+${CTOR}}
274 ${RELOCATING+${DTOR}}
275 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
277 ${RELOCATING+${DATARELRO}}
278 ${OTHER_RELRO_SECTIONS}
279 ${RELOCATING+${DATA_SEGMENT_RELRO_END}}
281 ${DATA_PLT+${PLT_BEFORE_GOT-${PLT}}}
283 .data ${RELOCATING-0} :
285 ${RELOCATING+${DATA_START_SYMBOLS}}
286 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
287 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
289 .data1 ${RELOCATING-0} : { *(.data1) }
290 ${WRITABLE_RODATA+${RODATA}}
291 ${OTHER_READWRITE_SECTIONS}
292 ${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}
293 ${CREATE_SHLIB+${SDATA2}}
294 ${CREATE_SHLIB+${SBSS2}}
296 ${OTHER_SDATA_SECTIONS}
297 ${RELOCATING+_edata = .;}
298 ${RELOCATING+PROVIDE (edata = .);}
299 ${RELOCATING+. = DEFINED(__bss_segment_start) ? __bss_segment_start : .;}
300 ${RELOCATING+__bss_start = .;}
301 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
304 .bss ${RELOCATING-0} :
307 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
309 /* Align here to ensure that the .bss section occupies space up to
310 _end. Align after .bss to ensure correct alignment even if the
311 .bss section disappears because there are no input sections. */
312 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
314 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
315 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
316 ${RELOCATING+${OTHER_END_SYMBOLS}}
317 ${RELOCATING+_end = .;}
318 ${RELOCATING+PROVIDE (end = .);}
319 ${RELOCATING+${DATA_SEGMENT_END}}
321 /* These sections are not mapped under the BPABI. */
322 .dynamic 0 : { *(.dynamic) }
323 .hash 0 : { *(.hash) }
324 .dynsym 0 : { *(.dynsym) }
325 .dynstr 0 : { *(.dynstr) }
326 .gnu.version 0 : { *(.gnu.version) }
327 .gnu.version_d 0: { *(.gnu.version_d) }
328 .gnu.version_r 0: { *(.gnu.version_r) }
329 ${CREATE_SHLIB-${INTERP}}
331 /* Stabs debugging sections. */
332 .stab 0 : { *(.stab) }
333 .stabstr 0 : { *(.stabstr) }
334 .stab.excl 0 : { *(.stab.excl) }
335 .stab.exclstr 0 : { *(.stab.exclstr) }
336 .stab.index 0 : { *(.stab.index) }
337 .stab.indexstr 0 : { *(.stab.indexstr) }
339 .comment 0 : { *(.comment) }
342 . $srcdir/scripttempl/DWARF.sc
345 ${STACK_ADDR+${STACK}}
347 ${RELOCATING+${OTHER_SYMBOLS}}
348 ${RELOCATING+${DISCARDED}}
351 # These relocations sections are part of the read-only segment in SVR4
352 # executables, but are not mapped in BPABI executables.
353 if [ "x$COMBRELOC" = x ]; then
356 COMBRELOCCAT="cat > $COMBRELOC"
358 eval $COMBRELOCCAT <<EOF
359 .rel.init 0 : { *(.rel.init) }
360 .rela.init 0 : { *(.rela.init) }
361 .rel.text 0 : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
362 .rela.text 0 : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
363 .rel.fini 0 : { *(.rel.fini) }
364 .rela.fini 0 : { *(.rela.fini) }
365 .rel.rodata 0 : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
366 .rela.rodata 0 : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
367 ${OTHER_READONLY_RELOC_SECTIONS}
368 .rel.data.rel.ro 0 : { *(.rel.data.rel.ro${RELOCATING+ .rel.data.rel.ro.*}) }
369 .rela.data.rel.ro 0 : { *(.rela.data.rel.ro${RELOCATING+ .rela.data.rel.ro.*}) }
370 .rel.data 0 : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
371 .rela.data 0 : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
372 .rel.tdata 0 : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
373 .rela.tdata 0 : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
374 .rel.tbss 0 : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
375 .rela.tbss 0 : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
376 .rel.ctors 0 : { *(.rel.ctors) }
377 .rela.ctors 0 : { *(.rela.ctors) }
378 .rel.dtors 0 : { *(.rel.dtors) }
379 .rela.dtors 0 : { *(.rela.dtors) }
384 .rel.bss 0 : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
385 .rela.bss 0 : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
386 .rel.init_array 0 : { *(.rel.init_array) }
387 .rela.init_array 0 : { *(.rela.init_array) }
388 .rel.fini_array 0 : { *(.rel.fini_array) }
389 .rela.fini_array 0 : { *(.rela.fini_array) }
391 if [ -n "$COMBRELOC" ]; then
396 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
402 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
408 .rel.plt 0 : { *(.rel.plt) }
409 .rela.plt 0 : { *(.rela.plt) }
410 ${OTHER_PLT_RELOC_SECTIONS}
411 .rel.other 0 : { *(.rel.*) }
412 .rela.other 0 : { *(.rela.*) }
413 .reli.other 0 : { *(.reli.*) }