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