2 # Unusual variables checked by this code:
3 # NOP - four byte opcode for no-op (defaults to 0)
4 # NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
6 # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
7 # INITIAL_READONLY_SECTIONS - at start of text segment
8 # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
9 # (e.g., .PARISC.milli)
10 # OTHER_TEXT_SECTIONS - these get put in .text when relocating
11 # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
12 # (e.g., .PARISC.global)
13 # OTHER_BSS_SECTIONS - other than .bss .sbss ...
14 # OTHER_SECTIONS - at the end
15 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
16 # executable (e.g., _DYNAMIC_LINK)
17 # TEXT_START_SYMBOLS - symbols that appear at the start of the
19 # DATA_START_SYMBOLS - symbols that appear at the start of the
21 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
22 # OTHER_GOT_SECTIONS - sections just after .got.
23 # OTHER_SDATA_SECTIONS - sections just after .sdata.
24 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
25 # .bss section besides __bss_start.
26 # DATA_PLT - .plt should be in data segment, not text segment.
27 # BSS_PLT - .plt should be in bss segment
28 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
29 # EMBEDDED - whether this is for an embedded system.
30 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
31 # start address of shared library.
32 # INPUT_FILES - INPUT command of files to always include
33 # WRITABLE_RODATA - if set, the .rodata section should be writable
34 # INIT_START, INIT_END - statements just before and just after
35 # combination of .init sections.
36 # FINI_START, FINI_END - statements just before and just after
37 # combination of .fini sections.
38 # STACK_ADDR - start of a .stack section.
39 # OTHER_END_SYMBOLS - symbols to place right at the end of the script.
41 # When adding sections, do note that the names of some sections are used
42 # when specifying the start address of the next.
45 # Many sections come in three flavours. There is the 'real' section,
46 # like ".data". Then there are the per-procedure or per-variable
47 # sections, generated by -ffunction-sections and -fdata-sections in GCC,
48 # and useful for --gc-sections, which for a variable "foo" might be
49 # ".data.foo". Then there are the linkonce sections, for which the linker
50 # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
51 # The exact correspondences are:
53 # Section Linkonce section
54 # .text .gnu.linkonce.t.foo
55 # .rodata .gnu.linkonce.r.foo
56 # .data .gnu.linkonce.d.foo
57 # .bss .gnu.linkonce.b.foo
58 # .sdata .gnu.linkonce.s.foo
59 # .sbss .gnu.linkonce.sb.foo
60 # .sdata2 .gnu.linkonce.s2.foo
61 # .sbss2 .gnu.linkonce.sb2.foo
62 # .debug_info .gnu.linkonce.wi.foo
63 # .tdata .gnu.linkonce.td.foo
64 # .tbss .gnu.linkonce.tb.foo
66 # Each of these can also have corresponding .rel.* and .rela.* sections.
68 test -z "$ENTRY" && ENTRY=start
69 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
70 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
71 # If we request a big endian toolchain, give a big endian linker
72 test "${ARC_ENDIAN}" = "big" && OUTPUT_FORMAT=${BIG_OUTPUT_FORMAT}
73 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
74 test -z "${ELFSIZE}" && ELFSIZE=32
75 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
76 test "$LD_FLAG" = "N" && DATA_ADDR=.
77 test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
78 test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
79 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
81 if test -n "${COMMONPAGESIZE}"; then
82 DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
83 DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
85 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
86 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
87 test -z "$GOT" && GOT=".got ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) }"
88 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
89 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
90 STACKNOTE="/DISCARD/ : { *(.note.GNU-stack) }"
91 if test -z "${NO_SMALL_DATA}"; then
92 SBSS=".sbss ${RELOCATING-0} :
94 ${RELOCATING+PROVIDE (__sbss_start = .);}
95 ${RELOCATING+PROVIDE (___sbss_start = .);}
96 ${RELOCATING+*(.dynsbss)}
97 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
98 ${RELOCATING+*(.scommon)}
99 ${RELOCATING+PROVIDE (__sbss_end = .);}
100 ${RELOCATING+PROVIDE (___sbss_end = .);}
102 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
103 SDATA="/* We want the small data sections together, so single-instruction offsets
104 can access them all, and initialized data all before uninitialized, so
105 we can shorten the on-disk segment size. */
106 .sdata ${RELOCATING-0} :
108 ${RELOCATING+${SDATA_START_SYMBOLS}}
109 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
111 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }"
112 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
113 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
114 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
115 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
116 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
117 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
118 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
119 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
121 INIT_ARRAY=".init_array ${RELOCATING-0} :
123 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
124 KEEP (*(SORT(.init_array.*)))
125 KEEP (*(.init_array))
126 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
128 FINI_ARRAY=".fini_array ${RELOCATING-0} :
130 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
131 KEEP (*(SORT(.fini_array.*)))
132 KEEP (*(.fini_array))
133 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
135 CTOR=".ctors ${CONSTRUCTING-0} :
137 ${CONSTRUCTING+${CTOR_START}}
138 /* gcc uses crtbegin.o to find the start of
139 the constructors, so we make sure it is
140 first. Because this is a wildcard, it
141 doesn't matter if the user does not
142 actually link against crtbegin.o; the
143 linker won't look for a file to match a
144 wildcard. The wildcard also means that it
145 doesn't matter which directory crtbegin.o
148 KEEP (*crtbegin*.o(.ctors))
150 /* We don't want to include the .ctor section from
151 from the crtend.o file until after the sorted ctors.
152 The .ctor section from the crtend file contains the
153 end of ctors marker and it must be last */
155 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
156 KEEP (*(SORT(.ctors.*)))
158 ${CONSTRUCTING+${CTOR_END}}
160 DTOR=".dtors ${CONSTRUCTING-0} :
162 ${CONSTRUCTING+${DTOR_START}}
163 KEEP (*crtbegin*.o(.dtors))
164 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
165 KEEP (*(SORT(.dtors.*)))
167 ${CONSTRUCTING+${DTOR_END}}
169 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
171 ${RELOCATING+_stack = .;}
175 TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})"
176 SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${SHLIB_TEXT_START_ADDR:-0})"
178 # if this is for an embedded system, don't add SIZEOF_HEADERS.
179 if [ -z "$EMBEDDED" ]; then
180 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
182 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
186 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
187 "${LITTLE_OUTPUT_FORMAT}")
188 OUTPUT_ARCH(${OUTPUT_ARCH})
189 ${RELOCATING+ENTRY(${ENTRY})}
191 ${RELOCATING+${LIB_SEARCH_DIRS}}
192 ${RELOCATING+/* Do we need any of these for elf?
193 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
194 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
195 ${RELOCATING+${INPUT_FILES}}
196 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
197 if gld -r is used and the intermediate file has sections starting
198 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
199 bug. But for now assigning the zero vmas works. */}
203 /* Read-only sections, merged into text segment: */
204 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
205 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
206 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
207 ${CREATE_SHLIB-${INTERP}}
208 ${INITIAL_READONLY_SECTIONS}
209 ${TEXT_DYNAMIC+${DYNAMIC}}
210 .hash ${RELOCATING-0} : { *(.hash) }
211 .dynsym ${RELOCATING-0} : { *(.dynsym) }
212 .dynstr ${RELOCATING-0} : { *(.dynstr) }
213 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
214 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
215 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
218 if [ "x$COMBRELOC" = x ]; then
221 COMBRELOCCAT="cat > $COMBRELOC"
223 eval $COMBRELOCCAT <<EOF
224 .rel.init ${RELOCATING-0} : { *(.rel.init) }
225 .rela.init ${RELOCATING-0} : { *(.rela.init) }
226 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
227 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
228 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
229 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
230 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
231 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
232 ${OTHER_READONLY_RELOC_SECTIONS}
233 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
234 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
235 .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
236 .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
237 .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
238 .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
239 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
240 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
241 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
242 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
243 .rel.got ${RELOCATING-0} : { *(.rel.got) }
244 .rela.got ${RELOCATING-0} : { *(.rela.got) }
245 ${OTHER_GOT_RELOC_SECTIONS}
250 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
251 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
253 if [ -n "$COMBRELOC" ]; then
255 .rel.dyn ${RELOCATING-0} :
258 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
261 .rela.dyn ${RELOCATING-0} :
264 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
270 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
271 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
272 ${OTHER_PLT_RELOC_SECTIONS}
274 .init ${RELOCATING-0} :
276 ${RELOCATING+${INIT_START}}
277 KEEP (*(SORT_NONE(.init)))
278 ${RELOCATING+${INIT_END}}
281 ${DATA_PLT-${BSS_PLT-${PLT}}}
282 .jlitab ${RELOCATING-0} :
284 ${RELOCATING+${JLI_START_TABLE}}
285 ${RELOCATING+jlitab*.o(.jlitab*)}
286 *(.jlitab${RELOCATING+*})
288 .text ${RELOCATING-0} :
290 ${RELOCATING+${TEXT_START_SYMBOLS}}
291 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
292 /* .gnu.warning sections are handled specially by elf.em. */
294 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
296 .text.init ${RELOCATING-0} :
300 .fini ${RELOCATING-0} :
302 ${RELOCATING+${FINI_START}}
303 KEEP (*(SORT_NONE(.fini)))
304 ${RELOCATING+${FINI_END}}
306 ${RELOCATING+PROVIDE (__etext = .);}
307 ${RELOCATING+PROVIDE (_etext = .);}
308 ${RELOCATING+PROVIDE (etext = .);}
309 ${WRITABLE_RODATA-${RODATA}}
310 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
311 ${CREATE_SHLIB-${SDATA2}}
312 ${CREATE_SHLIB-${SBSS2}}
313 ${OTHER_READONLY_SECTIONS}
314 .eh_frame_hdr ${RELOCATING-0} : { *(.eh_frame_hdr) }
315 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
317 /* Adjust the address for the data segment. We want to adjust up to
318 the same address within the page on the next page up. */
319 ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
320 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
321 ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
323 /* Exception handling */
324 .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
326 /* Ensure the __preinit_array_start label is properly aligned. We
327 could instead move the label definition inside the section, but
328 the linker would then create the section even if it turns out to
329 be empty, which isn't pretty. */
330 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
331 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
332 .preinit_array ${RELOCATING-0} : { *(.preinit_array) }
333 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
334 ${RELOCATING+${INIT_ARRAY}}
335 ${RELOCATING+${FINI_ARRAY}}
337 .data ${RELOCATING-0} :
339 ${RELOCATING+${DATA_START_SYMBOLS}}
340 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
341 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
343 .data.init ${RELOCATING-0} :
347 .data1 ${RELOCATING-0} : { *(.data1) }
348 .tdata ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
349 .tbss ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
350 .eh_frame ${RELOCATING-0} : { KEEP (*(.eh_frame)) }
351 .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }
352 ${WRITABLE_RODATA+${RODATA}}
353 ${OTHER_READWRITE_SECTIONS}
354 ${TEXT_DYNAMIC-${DYNAMIC}}
355 ${RELOCATING+${CTOR}}
356 ${RELOCATING+${DTOR}}
357 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
359 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
361 ${OTHER_GOT_SECTIONS}
362 ${CREATE_SHLIB+${SDATA2}}
363 ${CREATE_SHLIB+${SBSS2}}
365 ${OTHER_SDATA_SECTIONS}
366 ${RELOCATING+_edata = .;}
367 ${RELOCATING+PROVIDE (edata = .);}
368 ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));}
369 ${RELOCATING+__bss_start = .;}
370 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
373 .bss ${RELOCATING-0} :
375 ${RELOCATING+*(.dynbss)}
376 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
377 ${RELOCATING+*(COMMON)
378 /* Align here to ensure that the .bss section occupies space up to
379 _end. Align after .bss to ensure correct alignment even if the
380 .bss section disappears because there are no input sections. */
381 . = ALIGN(${ALIGNMENT});}
383 ${OTHER_BSS_SECTIONS}
384 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
385 ${RELOCATING+_end = .;}
386 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
387 ${RELOCATING+PROVIDE (end = .);}
388 ${RELOCATING+${DATA_SEGMENT_END}}
391 test -n "${RELOCATING}" && cat <<EOF
392 /* We want to be able to set a default stack / heap size in a dejagnu
393 board description file, but override it for selected test cases.
394 The options appear in the wrong order to do this with a single symbol -
395 ldflags comes after flags injected with per-file stanzas, and thus
396 the setting from ldflags prevails. */
400 . = . + (DEFINED(__HEAP_SIZE) ? __HEAP_SIZE : (DEFINED(__DEFAULT_HEAP_SIZE) ? __DEFAULT_HEAP_SIZE : 20k)) ;
408 . = . + (DEFINED(__STACK_SIZE) ? __STACK_SIZE : (DEFINED(__DEFAULT_STACK_SIZE) ? __DEFAULT_STACK_SIZE : 64k)) ;
413 source_sh $srcdir/scripttempl/misc-sections.sc
414 source_sh $srcdir/scripttempl/DWARF.sc
417 /* ARC Extension Sections */
418 .arcextmap 0 : { *(.arcextmap.*) }
421 ${RELOCATING+${OTHER_END_SYMBOLS}}
422 ${RELOCATING+${STACKNOTE}}