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