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_SECTIONS - at the end
14 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
15 # executable (e.g., _DYNAMIC_LINK)
16 # TEXT_START_SYMBOLS - symbols that appear at the start of the
18 # DATA_START_SYMBOLS - symbols that appear at the start of the
20 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
21 # OTHER_GOT_SECTIONS - sections just after .got.
22 # OTHER_SDATA_SECTIONS - sections just after .sdata.
23 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
24 # .bss section besides __bss_start.
25 # DATA_PLT - .plt should be in data segment, not text segment.
26 # BSS_PLT - .plt should be in bss segment
27 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
28 # EMBEDDED - whether this is for an embedded system.
29 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
30 # start address of shared library.
31 # INPUT_FILES - INPUT command of files to always include
32 # WRITABLE_RODATA - if set, the .rodata section should be writable
33 # INIT_START, INIT_END - statements just before and just after
34 # combination of .init sections.
35 # FINI_START, FINI_END - statements just before and just after
36 # combination of .fini sections.
37 # STACK_ADDR - start of a .stack section.
38 # OTHER_SYMBOLS - symbols to place right at the end of the script.
40 # When adding sections, do note that the names of some sections are used
41 # when specifying the start address of the next.
44 # Many sections come in three flavours. There is the 'real' section,
45 # like ".data". Then there are the per-procedure or per-variable
46 # sections, generated by -ffunction-sections and -fdata-sections in GCC,
47 # and useful for --gc-sections, which for a variable "foo" might be
48 # ".data.foo". Then there are the linkonce sections, for which the linker
49 # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
50 # The exact correspondences are:
52 # Section Linkonce section
53 # .text .gnu.linkonce.t.foo
54 # .rodata .gnu.linkonce.r.foo
55 # .data .gnu.linkonce.d.foo
56 # .bss .gnu.linkonce.b.foo
57 # .sdata .gnu.linkonce.s.foo
58 # .sbss .gnu.linkonce.sb.foo
59 # .sdata2 .gnu.linkonce.s2.foo
60 # .sbss2 .gnu.linkonce.sb2.foo
61 # .debug_info .gnu.linkonce.wi.foo
63 # Each of these can also have corresponding .rel.* and .rela.* sections.
65 test -z "$ENTRY" && ENTRY=_start
66 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
67 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
68 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
69 test -z "${ELFSIZE}" && ELFSIZE=32
70 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
71 test "$LD_FLAG" = "N" && DATA_ADDR=.
72 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
73 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
74 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
75 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
76 if test -z "${NO_SMALL_DATA}"; then
77 SBSS=".sbss ${RELOCATING-0} :
79 ${RELOCATING+PROVIDE (__sbss_start = .);}
80 ${RELOCATING+PROVIDE (___sbss_start = .);}
82 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
84 ${RELOCATING+PROVIDE (__sbss_end = .);}
85 ${RELOCATING+PROVIDE (___sbss_end = .);}
87 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
88 SDATA="/* We want the small data sections together, so single-instruction offsets
89 can access them all, and initialized data all before uninitialized, so
90 we can shorten the on-disk segment size. */
91 .sdata ${RELOCATING-0} :
93 ${RELOCATING+${SDATA_START_SYMBOLS}}
94 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
96 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }"
97 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
98 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
99 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
100 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
101 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
102 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
103 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
104 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
107 ${CONSTRUCTING+${CTOR_START}}
108 /* gcc uses crtbegin.o to find the start of
109 the constructors, so we make sure it is
110 first. Because this is a wildcard, it
111 doesn't matter if the user does not
112 actually link against crtbegin.o; the
113 linker won't look for a file to match a
114 wildcard. The wildcard also means that it
115 doesn't matter which directory crtbegin.o
118 KEEP (*crtbegin*.o(.ctors))
120 /* We don't want to include the .ctor section from
121 from the crtend.o file until after the sorted ctors.
122 The .ctor section from the crtend file contains the
123 end of ctors marker and it must be last */
125 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
126 KEEP (*(SORT(.ctors.*)))
128 ${CONSTRUCTING+${CTOR_END}}
131 ${CONSTRUCTING+${DTOR_START}}
132 KEEP (*crtbegin*.o(.dtors))
133 KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
134 KEEP (*(SORT(.dtors.*)))
136 ${CONSTRUCTING+${DTOR_END}}
138 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
140 ${RELOCATING+_stack = .;}
144 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
147 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
148 "${LITTLE_OUTPUT_FORMAT}")
149 OUTPUT_ARCH(${OUTPUT_ARCH})
152 ${RELOCATING+${LIB_SEARCH_DIRS}}
153 ${RELOCATING+/* Do we need any of these for elf?
154 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
155 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
156 ${RELOCATING+${INPUT_FILES}}
157 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
158 if gld -r is used and the intermediate file has sections starting
159 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
160 bug. But for now assigning the zero vmas works. */}
164 /* Read-only sections, merged into text segment: */
165 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
166 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
167 ${CREATE_SHLIB-${INTERP}}
168 ${INITIAL_READONLY_SECTIONS}
169 ${TEXT_DYNAMIC+${DYNAMIC}}
170 .hash ${RELOCATING-0} : { *(.hash) }
171 .dynsym ${RELOCATING-0} : { *(.dynsym) }
172 .dynstr ${RELOCATING-0} : { *(.dynstr) }
173 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
174 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
175 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
178 if [ "x$COMBRELOC" = x ]; then
181 COMBRELOCCAT="cat > $COMBRELOC"
183 eval $COMBRELOCCAT <<EOF
184 .rel.init ${RELOCATING-0} : { *(.rel.init) }
185 .rela.init ${RELOCATING-0} : { *(.rela.init) }
186 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
187 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
188 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
189 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
190 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
191 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
192 ${OTHER_READONLY_RELOC_SECTIONS}
193 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
194 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
195 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
196 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
197 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
198 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
199 .rel.got ${RELOCATING-0} : { *(.rel.got) }
200 .rela.got ${RELOCATING-0} : { *(.rela.got) }
201 ${OTHER_GOT_RELOC_SECTIONS}
206 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
207 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
209 if [ -n "$COMBRELOC" ]; then
211 .rel.dyn ${RELOCATING-0} :
214 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
217 .rela.dyn ${RELOCATING-0} :
220 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
227 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
228 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
229 ${OTHER_PLT_RELOC_SECTIONS}
230 ${DATA_PLT-${BSS_PLT-${PLT}}}
231 .text ${RELOCATING-0} :
233 ${RELOCATING+${TEXT_START_SYMBOLS}}
234 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
235 /* .gnu.warning sections are handled specially by elf32.em. */
237 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
239 .fini ${RELOCATING-0} :
241 ${RELOCATING+${FINI_START}}
243 ${RELOCATING+${FINI_END}}
245 ${RELOCATING+PROVIDE (__etext = .);}
246 ${RELOCATING+PROVIDE (_etext = .);}
247 ${RELOCATING+PROVIDE (etext = .);}
249 ${CREATE_SHLIB-${SDATA2}}
250 ${CREATE_SHLIB-${SBSS2}}
251 ${OTHER_READONLY_SECTIONS}
252 .eh_frame_hdr : { *(.eh_frame_hdr) }
255 .data ${RELOCATING-0} :
260 ${RELOCATING+${DATA_START_SYMBOLS}}
261 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
262 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
269 .data1 ${RELOCATING-0} : { *(.data1) }
271 .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }
272 ${WRITABLE_RODATA+${RODATA}}
273 ${OTHER_READWRITE_SECTIONS}
274 ${TEXT_DYNAMIC-${DYNAMIC}}
276 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
277 .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
278 ${OTHER_GOT_SECTIONS}
279 ${CREATE_SHLIB+${SDATA2}}
280 ${CREATE_SHLIB+${SBSS2}}
282 ${OTHER_SDATA_SECTIONS}
283 ${RELOCATING+_edata = .;}
284 ${RELOCATING+PROVIDE (edata = .);}
285 ${RELOCATING+__bss_start = .;}
286 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
290 .bss ${RELOCATING-0} :
293 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
295 /* Align here to ensure that the .bss section occupies space up to
296 _end. Align after .bss to ensure correct alignment even if the
297 .bss section disappears because there are no input sections. */
298 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
300 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
301 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
302 ${RELOCATING+${OTHER_END_SYMBOLS}}
303 ${RELOCATING+_end = .;}
304 ${RELOCATING+PROVIDE (end = .);}
306 /* Stabs debugging sections. */
308 .stab 0 : { *(.stab) }
309 .stabstr 0 : { *(.stabstr) }
310 .stab.excl 0 : { *(.stab.excl) }
311 .stab.exclstr 0 : { *(.stab.exclstr) }
312 .stab.index 0 : { *(.stab.index) }
313 .stab.indexstr 0 : { *(.stab.indexstr) }
316 .comment 0 : { *(.comment) }
318 /* DWARF debug sections.
319 Symbols in the DWARF debugging sections are relative to the beginning
320 of the section so we begin them at 0. */
323 .debug 0 : { *(.debug) }
324 .line 0 : { *(.line) }
326 /* GNU DWARF 1 extensions */
327 .debug_srcinfo 0 : { *(.debug_srcinfo) }
328 .debug_sfnames 0 : { *(.debug_sfnames) }
330 /* DWARF 1.1 and DWARF 2 */
331 .debug_aranges 0 : { *(.debug_aranges) }
332 .debug_pubnames 0 : { *(.debug_pubnames) }
335 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
336 .debug_abbrev 0 : { *(.debug_abbrev) }
337 .debug_line 0 : { *(.debug_line) }
338 .debug_frame 0 : { *(.debug_frame) }
339 .debug_str 0 : { *(.debug_str) }
340 .debug_loc 0 : { *(.debug_loc) }
341 .debug_macinfo 0 : { *(.debug_macinfo) }
343 /* SGI/MIPS DWARF 2 extensions */
344 .debug_weaknames 0 : { *(.debug_weaknames) }
345 .debug_funcnames 0 : { *(.debug_funcnames) }
346 .debug_typenames 0 : { *(.debug_typenames) }
347 .debug_varnames 0 : { *(.debug_varnames) }
349 ${STACK_ADDR+${STACK}}
351 ${RELOCATING+${OTHER_SYMBOLS}}