* Makefile.am (CONFIG_STATUS_DEPENDENCIES): Define.
[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 # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
5 # INITIAL_READONLY_SECTIONS - at start of text segment
6 # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
7 # (e.g., .PARISC.milli)
8 # OTHER_TEXT_SECTIONS - these get put in .text when relocating
9 # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
10 # (e.g., .PARISC.global)
11 # OTHER_BSS_SECTIONS - other than .bss .sbss ...
12 # OTHER_SECTIONS - at the end
13 # EXECUTABLE_SYMBOLS - symbols that must be defined for an
14 # executable (e.g., _DYNAMIC_LINK)
15 # TEXT_START_SYMBOLS - symbols that appear at the start of the
16 # .text section.
17 # DATA_START_SYMBOLS - symbols that appear at the start of the
18 # .data section.
19 # OTHER_GOT_SYMBOLS - symbols defined just before .got.
20 # OTHER_GOT_SECTIONS - sections just after .got.
21 # OTHER_SDATA_SECTIONS - sections just after .sdata.
22 # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
23 # .bss section besides __bss_start.
24 # DATA_PLT - .plt should be in data segment, not text segment.
25 # BSS_PLT - .plt should be in bss segment
26 # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
27 # EMBEDDED - whether this is for an embedded system.
28 # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
29 # start address of shared library.
30 # INPUT_FILES - INPUT command of files to always include
31 # WRITABLE_RODATA - if set, the .rodata section should be writable
32 # INIT_START, INIT_END - statements just before and just after
33 # combination of .init sections.
34 # FINI_START, FINI_END - statements just before and just after
35 # combination of .fini sections.
36 # STACK_ADDR - start of a .stack section.
37 # OTHER_END_SYMBOLS - symbols to place right at the end of the script.
38 #
39 # When adding sections, do note that the names of some sections are used
40 # when specifying the start address of the next.
41 #
42
43 # Many sections come in three flavours. There is the 'real' section,
44 # like ".data". Then there are the per-procedure or per-variable
45 # sections, generated by -ffunction-sections and -fdata-sections in GCC,
46 # and useful for --gc-sections, which for a variable "foo" might be
47 # ".data.foo". Then there are the linkonce sections, for which the linker
48 # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
49 # The exact correspondences are:
50 #
51 # Section Linkonce section
52 # .text .gnu.linkonce.t.foo
53 # .rodata .gnu.linkonce.r.foo
54 # .data .gnu.linkonce.d.foo
55 # .bss .gnu.linkonce.b.foo
56 # .sdata .gnu.linkonce.s.foo
57 # .sbss .gnu.linkonce.sb.foo
58 # .sdata2 .gnu.linkonce.s2.foo
59 # .sbss2 .gnu.linkonce.sb2.foo
60 # .debug_info .gnu.linkonce.wi.foo
61 #
62 # Each of these can also have corresponding .rel.* and .rela.* sections.
63
64 test -z "$ENTRY" && ENTRY=_start
65 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
66 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
67 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
68 test -z "${ELFSIZE}" && ELFSIZE=32
69 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
70 test "$LD_FLAG" = "N" && DATA_ADDR=.
71 INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
72 PLT=".plt ${RELOCATING-0} : { *(.plt) }"
73 DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
74 RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
75 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
76 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }"
77 CTOR=".ctors ${CONSTRUCTING-0} :
78 {
79 ${CONSTRUCTING+${CTOR_START}}
80 /* gcc uses crtbegin.o to find the start of
81 the constructors, so we make sure it is
82 first. Because this is a wildcard, it
83 doesn't matter if the user does not
84 actually link against crtbegin.o; the
85 linker won't look for a file to match a
86 wildcard. The wildcard also means that it
87 doesn't matter which directory crtbegin.o
88 is in. */
89
90 KEEP (*crtbegin.o(.ctors))
91
92 /* We don't want to include the .ctor section from
93 from the crtend.o file until after the sorted ctors.
94 The .ctor section from the crtend file contains the
95 end of ctors marker and it must be last */
96
97 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .ctors))
98 KEEP (*(SORT(.ctors.*)))
99 KEEP (*(.ctors))
100 ${CONSTRUCTING+${CTOR_END}}
101 }"
102 DTOR=".dtors ${CONSTRUCTING-0} :
103 {
104 ${CONSTRUCTING+${DTOR_START}}
105 KEEP (*crtbegin.o(.dtors))
106 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .dtors))
107 KEEP (*(SORT(.dtors.*)))
108 KEEP (*(.dtors))
109 ${CONSTRUCTING+${DTOR_END}}
110 }"
111 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
112 {
113 ${RELOCATING+_stack = .;}
114 *(.stack)
115 }"
116
117 # if this is for an embedded system, don't add SIZEOF_HEADERS.
118 if [ -z "$EMBEDDED" ]; then
119 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
120 else
121 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
122 fi
123
124 cat <<EOF
125 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
126 "${LITTLE_OUTPUT_FORMAT}")
127 OUTPUT_ARCH(${OUTPUT_ARCH})
128 ENTRY(${ENTRY})
129
130 ${RELOCATING+${LIB_SEARCH_DIRS}}
131 ${RELOCATING+/* Do we need any of these for elf?
132 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
133 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
134 ${RELOCATING+${INPUT_FILES}}
135 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
136 if gld -r is used and the intermediate file has sections starting
137 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
138 bug. But for now assigning the zero vmas works. */}
139
140 SECTIONS
141 {
142 /* Read-only sections, merged into text segment: */
143 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
144 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
145 ${CREATE_SHLIB-${INTERP}}
146 ${INITIAL_READONLY_SECTIONS}
147 ${TEXT_DYNAMIC+${DYNAMIC}}
148 .hash ${RELOCATING-0} : { *(.hash) }
149 .dynsym ${RELOCATING-0} : { *(.dynsym) }
150 .dynstr ${RELOCATING-0} : { *(.dynstr) }
151 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
152 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
153 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
154
155 EOF
156 if [ "x$COMBRELOC" = x ]; then
157 COMBRELOCCAT=cat
158 else
159 COMBRELOCCAT="cat > $COMBRELOC"
160 fi
161 eval $COMBRELOCCAT <<EOF
162 .rel.init ${RELOCATING-0} : { *(.rel.init) }
163 .rela.init ${RELOCATING-0} : { *(.rela.init) }
164 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
165 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
166 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
167 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
168 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
169 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
170 ${OTHER_READONLY_RELOC_SECTIONS}
171 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
172 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
173 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
174 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
175 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
176 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
177 .rel.got ${RELOCATING-0} : { *(.rel.got) }
178 .rela.got ${RELOCATING-0} : { *(.rela.got) }
179 ${OTHER_GOT_RELOC_SECTIONS}
180 .rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
181 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }
182 .rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
183 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }
184 .rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
185 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }
186 .rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
187 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }
188 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
189 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
190 EOF
191 if [ -n "$COMBRELOC" ]; then
192 cat <<EOF
193 .rel.dyn ${RELOCATING-0} :
194 {
195 EOF
196 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
197 cat <<EOF
198 }
199 .rela.dyn ${RELOCATING-0} :
200 {
201 EOF
202 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
203 cat <<EOF
204 }
205 EOF
206 fi
207 cat <<EOF
208 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
209 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
210 ${OTHER_PLT_RELOC_SECTIONS}
211
212 .init ${RELOCATING-0} :
213 {
214 ${RELOCATING+${INIT_START}}
215 KEEP (*(.init))
216 ${RELOCATING+${INIT_END}}
217 } =${NOP-0}
218
219 ${DATA_PLT-${BSS_PLT-${PLT}}}
220 .text ${RELOCATING-0} :
221 {
222 ${RELOCATING+${TEXT_START_SYMBOLS}}
223 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
224 /* .gnu.warning sections are handled specially by elf32.em. */
225 *(.gnu.warning)
226 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
227 } =${NOP-0}
228 .fini ${RELOCATING-0} :
229 {
230 ${RELOCATING+${FINI_START}}
231 KEEP (*(.fini))
232 ${RELOCATING+${FINI_END}}
233 } =${NOP-0}
234 ${RELOCATING+PROVIDE (__etext = .);}
235 ${RELOCATING+PROVIDE (_etext = .);}
236 ${RELOCATING+PROVIDE (etext = .);}
237 ${WRITABLE_RODATA-${RODATA}}
238 .rodata1 ${RELOCATING-0} : { *(.rodata1) }
239 ${CREATE_SHLIB-${SDATA2}}
240 ${CREATE_SHLIB-${SBSS2}}
241 ${OTHER_READONLY_SECTIONS}
242
243 /* Adjust the address for the data segment. We want to adjust up to
244 the same address within the page on the next page up. */
245 ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
246 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
247
248 .data ${RELOCATING-0} :
249 {
250 ${RELOCATING+${DATA_START_SYMBOLS}}
251 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
252 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
253 }
254 .data1 ${RELOCATING-0} : { *(.data1) }
255 .eh_frame ${RELOCATING-0} : { KEEP (*(.eh_frame)) }
256 .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }
257 ${WRITABLE_RODATA+${RODATA}}
258 ${OTHER_READWRITE_SECTIONS}
259 ${TEXT_DYNAMIC-${DYNAMIC}}
260 ${RELOCATING+${CTOR}}
261 ${RELOCATING+${DTOR}}
262 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) }
263 ${DATA_PLT+${PLT}}
264 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
265 .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
266 ${OTHER_GOT_SECTIONS}
267 ${CREATE_SHLIB+${SDATA2}}
268 ${CREATE_SHLIB+${SBSS2}}
269 /* We want the small data sections together, so single-instruction offsets
270 can access them all, and initialized data all before uninitialized, so
271 we can shorten the on-disk segment size. */
272 .sdata ${RELOCATING-0} :
273 {
274 ${RELOCATING+${SDATA_START_SYMBOLS}}
275 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
276 }
277 ${OTHER_SDATA_SECTIONS}
278 ${RELOCATING+_edata = .;}
279 ${RELOCATING+PROVIDE (edata = .);}
280 ${RELOCATING+__bss_start = .;}
281 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
282 .sbss ${RELOCATING-0} :
283 {
284 ${RELOCATING+PROVIDE (__sbss_start = .);}
285 ${RELOCATING+PROVIDE (___sbss_start = .);}
286 *(.dynsbss)
287 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
288 *(.scommon)
289 ${RELOCATING+PROVIDE (__sbss_end = .);}
290 ${RELOCATING+PROVIDE (___sbss_end = .);}
291 }
292 ${BSS_PLT+${PLT}}
293 .bss ${RELOCATING-0} :
294 {
295 *(.dynbss)
296 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
297 *(COMMON)
298 /* Align here to ensure that the .bss section occupies space up to
299 _end. Align after .bss to ensure correct alignment even if the
300 .bss section disappears because there are no input sections. */
301 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
302 }
303 ${OTHER_BSS_SECTIONS}
304 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
305 ${RELOCATING+_end = .;}
306 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
307 ${RELOCATING+PROVIDE (end = .);}
308
309 /* Stabs debugging sections. */
310 .stab 0 : { *(.stab) }
311 .stabstr 0 : { *(.stabstr) }
312 .stab.excl 0 : { *(.stab.excl) }
313 .stab.exclstr 0 : { *(.stab.exclstr) }
314 .stab.index 0 : { *(.stab.index) }
315 .stab.indexstr 0 : { *(.stab.indexstr) }
316
317 .comment 0 : { *(.comment) }
318
319 /* DWARF debug sections.
320 Symbols in the DWARF debugging sections are relative to the beginning
321 of the section so we begin them at 0. */
322
323 /* DWARF 1 */
324 .debug 0 : { *(.debug) }
325 .line 0 : { *(.line) }
326
327 /* GNU DWARF 1 extensions */
328 .debug_srcinfo 0 : { *(.debug_srcinfo) }
329 .debug_sfnames 0 : { *(.debug_sfnames) }
330
331 /* DWARF 1.1 and DWARF 2 */
332 .debug_aranges 0 : { *(.debug_aranges) }
333 .debug_pubnames 0 : { *(.debug_pubnames) }
334
335 /* DWARF 2 */
336 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
337 .debug_abbrev 0 : { *(.debug_abbrev) }
338 .debug_line 0 : { *(.debug_line) }
339 .debug_frame 0 : { *(.debug_frame) }
340 .debug_str 0 : { *(.debug_str) }
341 .debug_loc 0 : { *(.debug_loc) }
342 .debug_macinfo 0 : { *(.debug_macinfo) }
343
344 /* SGI/MIPS DWARF 2 extensions */
345 .debug_weaknames 0 : { *(.debug_weaknames) }
346 .debug_funcnames 0 : { *(.debug_funcnames) }
347 .debug_typenames 0 : { *(.debug_typenames) }
348 .debug_varnames 0 : { *(.debug_varnames) }
349
350 ${STACK_ADDR+${STACK}}
351 ${OTHER_SECTIONS}
352 ${RELOCATING+${OTHER_END_SYMBOLS}}
353 }
354 EOF
This page took 0.036785 seconds and 5 git commands to generate.