bf678117772e2d625583626a3c5a240cebcbce8b
[deliverable/binutils-gdb.git] / ld / scripttempl / elf.sc
1 #
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
5 # empty.
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
18 # .text section.
19 # DATA_START_SYMBOLS - symbols that appear at the start of the
20 # .data section.
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.
40 #
41 # When adding sections, do note that the names of some sections are used
42 # when specifying the start address of the next.
43 #
44
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:
52 #
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 #
64 # Each of these can also have corresponding .rel.* and .rela.* sections.
65
66 test -z "$ENTRY" && ENTRY=_start
67 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
68 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
69 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
70 test -z "${ELFSIZE}" && ELFSIZE=32
71 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
72 test "$LD_FLAG" = "N" && DATA_ADDR=.
73 DATA_SEGMENT_ALIGN="ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))"
74 if [ -n "${COMMONPAGESIZE}" ]; then
75 DATA_SEGMENT_ALIGN="DATA_SEGMENT_ALIGN(${MAXPAGESIZE}, ${COMMONPAGESIZE})"
76 fi
77 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
78 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
79 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
80 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
81 if test -z "${NO_SMALL_DATA}"; then
82 SBSS=".sbss ${RELOCATING-0} :
83 {
84 ${RELOCATING+PROVIDE (__sbss_start = .);}
85 ${RELOCATING+PROVIDE (___sbss_start = .);}
86 *(.dynsbss)
87 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
88 *(.scommon)
89 ${RELOCATING+PROVIDE (__sbss_end = .);}
90 ${RELOCATING+PROVIDE (___sbss_end = .);}
91 }"
92 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
93 SDATA="/* We want the small data sections together, so single-instruction offsets
94 can access them all, and initialized data all before uninitialized, so
95 we can shorten the on-disk segment size. */
96 .sdata ${RELOCATING-0} :
97 {
98 ${RELOCATING+${SDATA_START_SYMBOLS}}
99 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
100 }"
101 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }"
102 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
103 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
104 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
105 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
106 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
107 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
108 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
109 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
110 fi
111 CTOR=".ctors ${CONSTRUCTING-0} :
112 {
113 ${CONSTRUCTING+${CTOR_START}}
114 /* gcc uses crtbegin.o to find the start of
115 the constructors, so we make sure it is
116 first. Because this is a wildcard, it
117 doesn't matter if the user does not
118 actually link against crtbegin.o; the
119 linker won't look for a file to match a
120 wildcard. The wildcard also means that it
121 doesn't matter which directory crtbegin.o
122 is in. */
123
124 KEEP (*crtbegin.o(.ctors))
125
126 /* We don't want to include the .ctor section from
127 from the crtend.o file until after the sorted ctors.
128 The .ctor section from the crtend file contains the
129 end of ctors marker and it must be last */
130
131 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .ctors))
132 KEEP (*(SORT(.ctors.*)))
133 KEEP (*(.ctors))
134 ${CONSTRUCTING+${CTOR_END}}
135 }"
136 DTOR=".dtors ${CONSTRUCTING-0} :
137 {
138 ${CONSTRUCTING+${DTOR_START}}
139 KEEP (*crtbegin.o(.dtors))
140 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .dtors))
141 KEEP (*(SORT(.dtors.*)))
142 KEEP (*(.dtors))
143 ${CONSTRUCTING+${DTOR_END}}
144 }"
145 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
146 {
147 ${RELOCATING+_stack = .;}
148 *(.stack)
149 }"
150
151 # if this is for an embedded system, don't add SIZEOF_HEADERS.
152 if [ -z "$EMBEDDED" ]; then
153 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
154 else
155 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
156 fi
157
158 cat <<EOF
159 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
160 "${LITTLE_OUTPUT_FORMAT}")
161 OUTPUT_ARCH(${OUTPUT_ARCH})
162 ENTRY(${ENTRY})
163
164 ${RELOCATING+${LIB_SEARCH_DIRS}}
165 ${RELOCATING+/* Do we need any of these for elf?
166 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
167 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
168 ${RELOCATING+${INPUT_FILES}}
169 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
170 if gld -r is used and the intermediate file has sections starting
171 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
172 bug. But for now assigning the zero vmas works. */}
173
174 SECTIONS
175 {
176 /* Read-only sections, merged into text segment: */
177 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
178 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
179 ${CREATE_SHLIB-${INTERP}}
180 ${INITIAL_READONLY_SECTIONS}
181 ${TEXT_DYNAMIC+${DYNAMIC}}
182 .hash ${RELOCATING-0} : { *(.hash) }
183 .dynsym ${RELOCATING-0} : { *(.dynsym) }
184 .dynstr ${RELOCATING-0} : { *(.dynstr) }
185 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
186 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
187 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
188
189 EOF
190 if [ "x$COMBRELOC" = x ]; then
191 COMBRELOCCAT=cat
192 else
193 COMBRELOCCAT="cat > $COMBRELOC"
194 fi
195 eval $COMBRELOCCAT <<EOF
196 .rel.init ${RELOCATING-0} : { *(.rel.init) }
197 .rela.init ${RELOCATING-0} : { *(.rela.init) }
198 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
199 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
200 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
201 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
202 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
203 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
204 ${OTHER_READONLY_RELOC_SECTIONS}
205 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
206 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
207 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
208 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
209 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
210 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
211 .rel.got ${RELOCATING-0} : { *(.rel.got) }
212 .rela.got ${RELOCATING-0} : { *(.rela.got) }
213 ${OTHER_GOT_RELOC_SECTIONS}
214 ${REL_SDATA}
215 ${REL_SBSS}
216 ${REL_SDATA2}
217 ${REL_SBSS2}
218 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
219 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
220 EOF
221 if [ -n "$COMBRELOC" ]; then
222 cat <<EOF
223 .rel.dyn ${RELOCATING-0} :
224 {
225 EOF
226 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
227 cat <<EOF
228 }
229 .rela.dyn ${RELOCATING-0} :
230 {
231 EOF
232 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
233 cat <<EOF
234 }
235 EOF
236 fi
237 cat <<EOF
238 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
239 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
240 ${OTHER_PLT_RELOC_SECTIONS}
241
242 .init ${RELOCATING-0} :
243 {
244 ${RELOCATING+${INIT_START}}
245 KEEP (*(.init))
246 ${RELOCATING+${INIT_END}}
247 } =${NOP-0}
248
249 /* Ensure the __preinit_array_start label is properly aligned. We
250 could instead move the label definition inside the section, but
251 the linker would then create the section even if it turns out to
252 be empty, which isn't pretty. */
253 ${RELOCATING+. = ALIGN(${ALIGNMENT})}
254 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
255 .preinit_array ${RELOCATING-0} : { *(.preinit_array) }
256 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
257
258 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .)}};
259 .init_array ${RELOCATING-0} : { *(.init_array) }
260 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
261
262 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
263 .fini_array ${RELOCATING-0} : { *(.fini_array) }
264 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
265
266 ${DATA_PLT-${BSS_PLT-${PLT}}}
267 .text ${RELOCATING-0} :
268 {
269 ${RELOCATING+${TEXT_START_SYMBOLS}}
270 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
271 /* .gnu.warning sections are handled specially by elf32.em. */
272 *(.gnu.warning)
273 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
274 } =${NOP-0}
275 .fini ${RELOCATING-0} :
276 {
277 ${RELOCATING+${FINI_START}}
278 KEEP (*(.fini))
279 ${RELOCATING+${FINI_END}}
280 } =${NOP-0}
281 ${RELOCATING+PROVIDE (__etext = .);}
282 ${RELOCATING+PROVIDE (_etext = .);}
283 ${RELOCATING+PROVIDE (etext = .);}
284 ${WRITABLE_RODATA-${RODATA}}
285 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
286 ${CREATE_SHLIB-${SDATA2}}
287 ${CREATE_SHLIB-${SBSS2}}
288 ${OTHER_READONLY_SECTIONS}
289 .eh_frame_hdr : { *(.eh_frame_hdr) }
290
291 /* Adjust the address for the data segment. We want to adjust up to
292 the same address within the page on the next page up. */
293 ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
294 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
295
296 .data ${RELOCATING-0} :
297 {
298 ${RELOCATING+${DATA_START_SYMBOLS}}
299 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
300 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
301 }
302 .data1 ${RELOCATING-0} : { *(.data1) }
303 .eh_frame ${RELOCATING-0} : { KEEP (*(.eh_frame)) }
304 .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }
305 ${WRITABLE_RODATA+${RODATA}}
306 ${OTHER_READWRITE_SECTIONS}
307 ${TEXT_DYNAMIC-${DYNAMIC}}
308 ${RELOCATING+${CTOR}}
309 ${RELOCATING+${DTOR}}
310 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
311 ${DATA_PLT+${PLT}}
312 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
313 .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
314 ${OTHER_GOT_SECTIONS}
315 ${CREATE_SHLIB+${SDATA2}}
316 ${CREATE_SHLIB+${SBSS2}}
317 ${SDATA}
318 ${OTHER_SDATA_SECTIONS}
319 ${RELOCATING+_edata = .;}
320 ${RELOCATING+PROVIDE (edata = .);}
321 ${RELOCATING+__bss_start = .;}
322 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
323 ${SBSS}
324 ${BSS_PLT+${PLT}}
325 .bss ${RELOCATING-0} :
326 {
327 *(.dynbss)
328 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
329 *(COMMON)
330 /* Align here to ensure that the .bss section occupies space up to
331 _end. Align after .bss to ensure correct alignment even if the
332 .bss section disappears because there are no input sections. */
333 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
334 }
335 ${OTHER_BSS_SECTIONS}
336 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
337 ${RELOCATING+_end = .;}
338 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
339 ${RELOCATING+PROVIDE (end = .);}
340 ${COMMONPAGESIZE+${RELOCATING+. = DATA_SEGMENT_END (.);}}
341
342 /* Stabs debugging sections. */
343 .stab 0 : { *(.stab) }
344 .stabstr 0 : { *(.stabstr) }
345 .stab.excl 0 : { *(.stab.excl) }
346 .stab.exclstr 0 : { *(.stab.exclstr) }
347 .stab.index 0 : { *(.stab.index) }
348 .stab.indexstr 0 : { *(.stab.indexstr) }
349
350 .comment 0 : { *(.comment) }
351
352 /* DWARF debug sections.
353 Symbols in the DWARF debugging sections are relative to the beginning
354 of the section so we begin them at 0. */
355
356 /* DWARF 1 */
357 .debug 0 : { *(.debug) }
358 .line 0 : { *(.line) }
359
360 /* GNU DWARF 1 extensions */
361 .debug_srcinfo 0 : { *(.debug_srcinfo) }
362 .debug_sfnames 0 : { *(.debug_sfnames) }
363
364 /* DWARF 1.1 and DWARF 2 */
365 .debug_aranges 0 : { *(.debug_aranges) }
366 .debug_pubnames 0 : { *(.debug_pubnames) }
367
368 /* DWARF 2 */
369 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
370 .debug_abbrev 0 : { *(.debug_abbrev) }
371 .debug_line 0 : { *(.debug_line) }
372 .debug_frame 0 : { *(.debug_frame) }
373 .debug_str 0 : { *(.debug_str) }
374 .debug_loc 0 : { *(.debug_loc) }
375 .debug_macinfo 0 : { *(.debug_macinfo) }
376
377 /* SGI/MIPS DWARF 2 extensions */
378 .debug_weaknames 0 : { *(.debug_weaknames) }
379 .debug_funcnames 0 : { *(.debug_funcnames) }
380 .debug_typenames 0 : { *(.debug_typenames) }
381 .debug_varnames 0 : { *(.debug_varnames) }
382
383 ${STACK_ADDR+${STACK}}
384 ${OTHER_SECTIONS}
385 ${RELOCATING+${OTHER_END_SYMBOLS}}
386 }
387 EOF
This page took 0.039978 seconds and 4 git commands to generate.