Re: ld: Lookup section in output with the same name
[deliverable/binutils-gdb.git] / ld / scripttempl / pe.sc
1 # Linker script for PE.
2 #
3 # Copyright (C) 2014-2018 Free Software Foundation, Inc.
4 #
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved.
8
9 if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
10 RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
11 fi
12
13 # We can't easily and portably get an unquoted $ in a shell
14 # substitution, so we do this instead.
15 # Sorting of the .foo$* sections is required by the definition of
16 # grouped sections in PE.
17 # Sorting of the file names in R_IDATA is required by the
18 # current implementation of dlltool (this could probably be changed to
19 # use grouped sections instead).
20 if test "${RELOCATING}"; then
21 R_TEXT='*(SORT(.text$*))'
22 if test "x$LD_FLAG" = "xauto_import" ; then
23 R_DATA='*(SORT(.data$*))
24 *(.rdata)
25 *(SORT(.rdata$*))'
26 R_RDATA=''
27 else
28 R_DATA='*(SORT(.data$*))'
29 R_RDATA='*(.rdata)
30 *(SORT(.rdata$*))'
31 fi
32 R_IDATA234='
33 KEEP (SORT(*)(.idata$2))
34 KEEP (SORT(*)(.idata$3))
35 /* These zeroes mark the end of the import list. */
36 LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
37 KEEP (SORT(*)(.idata$4))'
38 R_IDATA5='KEEP (SORT(*)(.idata$5))'
39 R_IDATA67='
40 KEEP (SORT(*)(.idata$6))
41 KEEP (SORT(*)(.idata$7))'
42 R_CRT_XC='KEEP (*(SORT(.CRT$XC*))) /* C initialization */'
43 R_CRT_XI='KEEP (*(SORT(.CRT$XI*))) /* C++ initialization */'
44 R_CRT_XL='KEEP (*(SORT(.CRT$XL*))) /* TLS callbacks */'
45 R_CRT_XP='KEEP (*(SORT(.CRT$XP*))) /* Pre-termination */'
46 R_CRT_XT='KEEP (*(SORT(.CRT$XT*))) /* Termination */'
47 R_TLS='
48 KEEP (*(.tls$AAA))
49 KEEP (*(.tls))
50 KEEP (*(.tls$))
51 KEEP (*(SORT(.tls$*)))
52 KEEP (*(.tls$ZZZ))'
53 R_RSRC='
54 KEEP (*(.rsrc))
55 KEEP (*(.rsrc$*))'
56 else
57 R_TEXT=
58 R_DATA=
59 R_RDATA='*(.rdata)'
60 R_IDATA234=
61 R_IDATA5=
62 R_IDATA67=
63 R_CRT_XC=
64 R_CRT_XI=
65 R_CRT_XL=
66 R_CRT_XP=
67 R_CRT_XT=
68 R_TLS='*(.tls)'
69 R_RSRC='*(.rsrc)'
70 fi
71
72 cat <<EOF
73 /* Copyright (C) 2014-2018 Free Software Foundation, Inc.
74
75 Copying and distribution of this script, with or without modification,
76 are permitted in any medium without royalty provided the copyright
77 notice and this notice are preserved. */
78
79 ${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
80 ${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
81 ${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
82
83 ${LIB_SEARCH_DIRS}
84
85 SECTIONS
86 {
87 ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
88 ${RELOCATING+ lower than the target page size. */}
89 ${RELOCATING+. = SIZEOF_HEADERS;}
90 ${RELOCATING+. = ALIGN(__section_alignment__);}
91 .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
92 {
93 ${RELOCATING+ KEEP(*(.init))}
94 *(.text)
95 ${R_TEXT}
96 ${RELOCATING+ *(.text.*)}
97 ${RELOCATING+ *(.gnu.linkonce.t.*)}
98 ${RELOCATING+*(.glue_7t)}
99 ${RELOCATING+*(.glue_7)}
100 ${CONSTRUCTING+
101 /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
102 we do not PROVIDE them. This is because the ctors.o startup
103 code in libgcc defines them as common symbols, with the
104 expectation that they will be overridden by the definitions
105 here. If we PROVIDE the symbols then they will not be
106 overridden and global constructors will not be run.
107
108 This does mean that it is not possible for a user to define
109 their own __CTOR_LIST__ and __DTOR_LIST__ symbols; if they do,
110 the content from those variables are included but the symbols
111 defined here silently take precedence. If they truly need to
112 be redefined, a custom linker script will have to be used.
113 (The custom script can just be a copy of this script with the
114 PROVIDE() qualifiers added).
115
116 See PR 22762 for more details. */
117 ___CTOR_LIST__ = .;
118 __CTOR_LIST__ = .;
119 LONG (-1);
120 KEEP(*(.ctors));
121 KEEP(*(.ctor));
122 KEEP(*(SORT_BY_NAME(.ctors.*)));
123 LONG (0);
124 }
125 ${CONSTRUCTING+
126 /* See comment about __CTOR_LIST__ above. The same reasoning
127 applies here too. */
128 ___DTOR_LIST__ = .;
129 __DTOR_LIST__ = .;
130 LONG (-1);
131 KEEP(*(.dtors));
132 KEEP(*(.dtor));
133 KEEP(*(SORT_BY_NAME(.dtors.*)));
134 LONG (0);
135 }
136 ${RELOCATING+ KEEP (*(.fini))}
137 /* ??? Why is .gcc_exc here? */
138 ${RELOCATING+ *(.gcc_exc)}
139 ${RELOCATING+PROVIDE (etext = .);}
140 ${RELOCATING+PROVIDE (_etext = .);}
141 ${RELOCATING+ KEEP (*(.gcc_except_table))}
142 }
143
144 /* The Cygwin32 library uses a section to avoid copying certain data
145 on fork. This used to be named ".data$nocopy". The linker used
146 to include this between __data_start__ and __data_end__, but that
147 breaks building the cygwin32 dll. Instead, we name the section
148 ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
149
150 .data ${RELOCATING+BLOCK(__section_alignment__)} :
151 {
152 ${RELOCATING+__data_start__ = . ;}
153 *(.data)
154 ${RELOCATING+*(.data2)}
155 ${R_DATA}
156 KEEP(*(.jcr))
157 ${RELOCATING+__data_end__ = . ;}
158 ${RELOCATING+*(.data_cygwin_nocopy)}
159 }
160
161 .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
162 {
163 ${R_RDATA}
164 ${RELOCATING+__rt_psrelocs_start = .;}
165 ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
166 ${RELOCATING+__rt_psrelocs_end = .;}
167 }
168 ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
169 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
170 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
171 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
172 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
173
174 .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
175 {
176 KEEP(*(.eh_frame${RELOCATING+*}))
177 }
178
179 .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
180 {
181 KEEP(*(.pdata${RELOCATING+*}))
182 }
183
184 .bss ${RELOCATING+BLOCK(__section_alignment__)} :
185 {
186 ${RELOCATING+__bss_start__ = . ;}
187 *(.bss)
188 *(COMMON)
189 ${RELOCATING+__bss_end__ = . ;}
190 }
191
192 .edata ${RELOCATING+BLOCK(__section_alignment__)} :
193 {
194 *(.edata)
195 }
196
197 /DISCARD/ :
198 {
199 *(.debug\$S)
200 *(.debug\$T)
201 *(.debug\$F)
202 *(.drectve)
203 ${RELOCATING+ *(.note.GNU-stack)}
204 ${RELOCATING+ *(.gnu.lto_*)}
205 }
206
207 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
208 {
209 /* This cannot currently be handled with grouped sections.
210 See pe.em:sort_sections. */
211 ${R_IDATA234}
212 ${RELOCATING+__IAT_start__ = .;}
213 ${R_IDATA5}
214 ${RELOCATING+__IAT_end__ = .;}
215 ${R_IDATA67}
216 }
217 .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
218 {
219 ${RELOCATING+___crt_xc_start__ = . ;}
220 ${R_CRT_XC}
221 ${RELOCATING+___crt_xc_end__ = . ;}
222 ${RELOCATING+___crt_xi_start__ = . ;}
223 ${R_CRT_XI}
224 ${RELOCATING+___crt_xi_end__ = . ;}
225 ${RELOCATING+___crt_xl_start__ = . ;}
226 ${R_CRT_XL}
227 /* ___crt_xl_end__ is defined in the TLS Directory support code */
228 ${RELOCATING+___crt_xp_start__ = . ;}
229 ${R_CRT_XP}
230 ${RELOCATING+___crt_xp_end__ = . ;}
231 ${RELOCATING+___crt_xt_start__ = . ;}
232 ${R_CRT_XT}
233 ${RELOCATING+___crt_xt_end__ = . ;}
234 }
235
236 /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
237 at the end of section. This is important because _tls_start MUST
238 be at the beginning of the section to enable SECREL32 relocations with TLS
239 data. */
240 .tls ${RELOCATING+BLOCK(__section_alignment__)} :
241 {
242 ${RELOCATING+___tls_start__ = . ;}
243 ${R_TLS}
244 ${RELOCATING+___tls_end__ = . ;}
245 }
246
247 .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
248 {
249 /* end is deprecated, don't use it */
250 ${RELOCATING+PROVIDE (end = .);}
251 ${RELOCATING+PROVIDE ( _end = .);}
252 ${RELOCATING+ __end__ = .;}
253 }
254
255 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
256 {
257 ${R_RSRC}
258 }
259
260 .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
261 {
262 *(.reloc)
263 }
264
265 .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
266 {
267 *(.stab)
268 }
269
270 .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
271 {
272 *(.stabstr)
273 }
274
275 /* DWARF debug sections.
276 Symbols in the DWARF debugging sections are relative to the beginning
277 of the section. Unlike other targets that fake this by putting the
278 section VMA at 0, the PE format will not allow it. */
279
280 /* DWARF 1.1 and DWARF 2. */
281 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
282 {
283 *(.debug_aranges)
284 }
285 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
286 {
287 *(.zdebug_aranges)
288 }
289
290 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
291 {
292 *(.debug_pubnames)
293 }
294 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
295 {
296 *(.zdebug_pubnames)
297 }
298
299 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
300 {
301 *(.debug_pubtypes)
302 }
303 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
304 {
305 *(.zdebug_pubtypes)
306 }
307
308 /* DWARF 2. */
309 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
310 {
311 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
312 }
313 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
314 {
315 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
316 }
317
318 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
319 {
320 *(.debug_abbrev)
321 }
322 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
323 {
324 *(.zdebug_abbrev)
325 }
326
327 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
328 {
329 *(.debug_line)
330 }
331 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
332 {
333 *(.zdebug_line)
334 }
335
336 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
337 {
338 *(.debug_frame*)
339 }
340 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
341 {
342 *(.zdebug_frame*)
343 }
344
345 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
346 {
347 *(.debug_str)
348 }
349 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
350 {
351 *(.zdebug_str)
352 }
353
354 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
355 {
356 *(.debug_loc)
357 }
358 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
359 {
360 *(.zdebug_loc)
361 }
362
363 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
364 {
365 *(.debug_macinfo)
366 }
367 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
368 {
369 *(.zdebug_macinfo)
370 }
371
372 /* SGI/MIPS DWARF 2 extensions. */
373 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
374 {
375 *(.debug_weaknames)
376 }
377 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
378 {
379 *(.zdebug_weaknames)
380 }
381
382 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
383 {
384 *(.debug_funcnames)
385 }
386 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
387 {
388 *(.zdebug_funcnames)
389 }
390
391 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
392 {
393 *(.debug_typenames)
394 }
395 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
396 {
397 *(.zdebug_typenames)
398 }
399
400 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
401 {
402 *(.debug_varnames)
403 }
404 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
405 {
406 *(.zdebug_varnames)
407 }
408
409 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
410 {
411 *(.debug_macro)
412 }
413 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
414 {
415 *(.zdebug_macro)
416 }
417
418 /* DWARF 3. */
419 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
420 {
421 *(.debug_ranges)
422 }
423 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
424 {
425 *(.zdebug_ranges)
426 }
427
428 /* DWARF 4. */
429 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
430 {
431 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
432 }
433 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
434 {
435 *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*})
436 }
437
438 /* For Go and Rust. */
439 .debug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
440 {
441 *(.debug_gdb_scripts)
442 }
443 .zdebug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
444 {
445 *(.zdebug_gdb_scripts)
446 }
447 }
448 EOF
This page took 0.03988 seconds and 4 git commands to generate.