* scripttempl/elf.sc: Ensure that crtbegin and crtend entries will
[deliverable/binutils-gdb.git] / ld / scripttempl / elf_chaos.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_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
17 # .text section.
18 # DATA_START_SYMBOLS - symbols that appear at the start of the
19 # .data section.
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.
39 #
40 # When adding sections, do note that the names of some sections are used
41 # when specifying the start address of the next.
42 #
43
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:
51 #
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
62 #
63 # Each of these can also have corresponding .rel.* and .rela.* sections.
64
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} :
78 {
79 ${RELOCATING+PROVIDE (__sbss_start = .);}
80 ${RELOCATING+PROVIDE (___sbss_start = .);}
81 *(.dynsbss)
82 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
83 *(.scommon)
84 ${RELOCATING+PROVIDE (__sbss_end = .);}
85 ${RELOCATING+PROVIDE (___sbss_end = .);}
86 }"
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} :
92 {
93 ${RELOCATING+${SDATA_START_SYMBOLS}}
94 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
95 }"
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.*}) }"
105 fi
106 CTOR="
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
116 is in. */
117
118 KEEP (*crtbegin.o(.ctors))
119 KEEP (*crtbegin?.o(.ctors))
120
121 /* We don't want to include the .ctor section from
122 the crtend.o file until after the sorted ctors.
123 The .ctor section from the crtend file contains the
124 end of ctors marker and it must be last */
125
126 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
127 KEEP (*(SORT(.ctors.*)))
128 KEEP (*(.ctors))
129 ${CONSTRUCTING+${CTOR_END}}
130 "
131 DTOR="
132 ${CONSTRUCTING+${DTOR_START}}
133 KEEP (*crtbegin.o(.dtors))
134 KEEP (*crtbegin?.o(.dtors))
135 KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
136 KEEP (*(SORT(.dtors.*)))
137 KEEP (*(.dtors))
138 ${CONSTRUCTING+${DTOR_END}}
139 "
140 STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
141 {
142 ${RELOCATING+_stack = .;}
143 *(.stack)
144 }"
145
146 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
147
148 cat <<EOF
149 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
150 "${LITTLE_OUTPUT_FORMAT}")
151 OUTPUT_ARCH(${OUTPUT_ARCH})
152 ENTRY(${ENTRY})
153
154 ${RELOCATING+${LIB_SEARCH_DIRS}}
155 ${RELOCATING+/* Do we need any of these for elf?
156 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
157 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
158 ${RELOCATING+${INPUT_FILES}}
159 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
160 if gld -r is used and the intermediate file has sections starting
161 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
162 bug. But for now assigning the zero vmas works. */}
163
164 SECTIONS
165 {
166 /* Read-only sections, merged into text segment: */
167 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
168 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
169 ${CREATE_SHLIB-${INTERP}}
170 ${INITIAL_READONLY_SECTIONS}
171 ${TEXT_DYNAMIC+${DYNAMIC}}
172 .hash ${RELOCATING-0} : { *(.hash) }
173 .dynsym ${RELOCATING-0} : { *(.dynsym) }
174 .dynstr ${RELOCATING-0} : { *(.dynstr) }
175 .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
176 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
177 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
178
179 EOF
180 if [ "x$COMBRELOC" = x ]; then
181 COMBRELOCCAT=cat
182 else
183 COMBRELOCCAT="cat > $COMBRELOC"
184 fi
185 eval $COMBRELOCCAT <<EOF
186 .rel.init ${RELOCATING-0} : { *(.rel.init) }
187 .rela.init ${RELOCATING-0} : { *(.rela.init) }
188 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
189 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
190 .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
191 .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
192 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
193 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
194 ${OTHER_READONLY_RELOC_SECTIONS}
195 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
196 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
197 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
198 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
199 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
200 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
201 .rel.got ${RELOCATING-0} : { *(.rel.got) }
202 .rela.got ${RELOCATING-0} : { *(.rela.got) }
203 ${OTHER_GOT_RELOC_SECTIONS}
204 ${REL_SDATA}
205 ${REL_SBSS}
206 ${REL_SDATA2}
207 ${REL_SBSS2}
208 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
209 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
210 EOF
211 if [ -n "$COMBRELOC" ]; then
212 cat <<EOF
213 .rel.dyn ${RELOCATING-0} :
214 {
215 EOF
216 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
217 cat <<EOF
218 }
219 .rela.dyn ${RELOCATING-0} :
220 {
221 EOF
222 sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
223 cat <<EOF
224 }
225 EOF
226 fi
227 cat <<EOF
228 . = ALIGN(0x1000);
229 .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
230 .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
231 ${OTHER_PLT_RELOC_SECTIONS}
232 ${DATA_PLT-${BSS_PLT-${PLT}}}
233 .text ${RELOCATING-0} :
234 {
235 ${RELOCATING+${TEXT_START_SYMBOLS}}
236 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
237 /* .gnu.warning sections are handled specially by elf32.em. */
238 *(.gnu.warning)
239 ${RELOCATING+${OTHER_TEXT_SECTIONS}}
240 } =${NOP-0}
241 .fini ${RELOCATING-0} :
242 {
243 ${RELOCATING+${FINI_START}}
244 KEEP (*(.fini))
245 ${RELOCATING+${FINI_END}}
246 } =${NOP-0}
247 ${RELOCATING+PROVIDE (__etext = .);}
248 ${RELOCATING+PROVIDE (_etext = .);}
249 ${RELOCATING+PROVIDE (etext = .);}
250 . = ALIGN(0x1000);
251 ${CREATE_SHLIB-${SDATA2}}
252 ${CREATE_SHLIB-${SBSS2}}
253 ${OTHER_READONLY_SECTIONS}
254 .eh_frame_hdr : { *(.eh_frame_hdr) }
255
256 . = ALIGN(0x1000);
257 .data ${RELOCATING-0} :
258 {
259 *(.rodata .rodata.*)
260 *(.rodata1)
261 *(.gnu.linkonce.r.*)
262 ${RELOCATING+${DATA_START_SYMBOLS}}
263 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
264 ${CONSTRUCTING+SORT(CONSTRUCTORS)}
265 KEEP (*(.eh_frame))
266 *(.gcc_except_table)
267 ${CTOR}
268 ${DTOR}
269 KEEP (*(.jcr))
270 }
271 .data1 ${RELOCATING-0} : { *(.data1) }
272 . = ALIGN(0x1000);
273 .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }
274 ${WRITABLE_RODATA+${RODATA}}
275 ${OTHER_READWRITE_SECTIONS}
276 ${TEXT_DYNAMIC-${DYNAMIC}}
277 ${DATA_PLT+${PLT}}
278 ${RELOCATING+${OTHER_GOT_SYMBOLS}}
279 .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
280 ${OTHER_GOT_SECTIONS}
281 ${CREATE_SHLIB+${SDATA2}}
282 ${CREATE_SHLIB+${SBSS2}}
283 ${SDATA}
284 ${OTHER_SDATA_SECTIONS}
285 ${RELOCATING+_edata = .;}
286 ${RELOCATING+PROVIDE (edata = .);}
287 ${RELOCATING+__bss_start = .;}
288 ${RELOCATING+${OTHER_BSS_SYMBOLS}}
289 ${SBSS}
290 ${BSS_PLT+${PLT}}
291 . = ALIGN(0x1000);
292 .bss ${RELOCATING-0} :
293 {
294 *(.dynbss)
295 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
296 *(COMMON)
297 /* Align here to ensure that the .bss section occupies space up to
298 _end. Align after .bss to ensure correct alignment even if the
299 .bss section disappears because there are no input sections. */
300 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
301 }
302 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
303 ${RELOCATING+. = ALIGN(${ALIGNMENT});}
304 ${RELOCATING+${OTHER_END_SYMBOLS}}
305 ${RELOCATING+_end = .;}
306 ${RELOCATING+PROVIDE (end = .);}
307
308 /* Stabs debugging sections. */
309 . = ALIGN(0x1000);
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 . = ALIGN(0x1000);
318 .comment 0 : { *(.comment) }
319
320 /* DWARF debug sections.
321 Symbols in the DWARF debugging sections are relative to the beginning
322 of the section so we begin them at 0. */
323
324 /* DWARF 1 */
325 .debug 0 : { *(.debug) }
326 .line 0 : { *(.line) }
327
328 /* GNU DWARF 1 extensions */
329 .debug_srcinfo 0 : { *(.debug_srcinfo) }
330 .debug_sfnames 0 : { *(.debug_sfnames) }
331
332 /* DWARF 1.1 and DWARF 2 */
333 .debug_aranges 0 : { *(.debug_aranges) }
334 .debug_pubnames 0 : { *(.debug_pubnames) }
335
336 /* DWARF 2 */
337 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
338 .debug_abbrev 0 : { *(.debug_abbrev) }
339 .debug_line 0 : { *(.debug_line) }
340 .debug_frame 0 : { *(.debug_frame) }
341 .debug_str 0 : { *(.debug_str) }
342 .debug_loc 0 : { *(.debug_loc) }
343 .debug_macinfo 0 : { *(.debug_macinfo) }
344
345 /* SGI/MIPS DWARF 2 extensions */
346 .debug_weaknames 0 : { *(.debug_weaknames) }
347 .debug_funcnames 0 : { *(.debug_funcnames) }
348 .debug_typenames 0 : { *(.debug_typenames) }
349 .debug_varnames 0 : { *(.debug_varnames) }
350
351 ${STACK_ADDR+${STACK}}
352 ${OTHER_SECTIONS}
353 ${RELOCATING+${OTHER_SYMBOLS}}
354 }
355 EOF
This page took 0.040481 seconds and 5 git commands to generate.