]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/scripttempl/pe.sc
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / scripttempl / pe.sc
1 # Linker script for PE.
2 #
3 # Copyright (C) 2014-2021 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-2021 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 (*(SORT_NONE(.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 See PR 22762 for more details.
108
109 This does mean that it is not possible for a user to define
110 their own __CTOR_LIST__ and __DTOR_LIST__ symbols; if they do,
111 the content from those variables are included but the symbols
112 defined here silently take precedence. If they truly need to
113 be redefined, a custom linker script will have to be used.
114 (The custom script can just be a copy of this script with the
115 PROVIDE() qualifiers added).
116
117 In particular this means that ld -Ur does not work, because
118 the proper __CTOR_LIST__ set by ld -Ur is overridden by a
119 bogus __CTOR_LIST__ set by the final link. See PR 46. */
120 ___CTOR_LIST__ = .;
121 __CTOR_LIST__ = .;
122 LONG (-1);
123 KEEP(*(.ctors));
124 KEEP(*(.ctor));
125 KEEP(*(SORT_BY_NAME(.ctors.*)));
126 LONG (0);
127 }
128 ${CONSTRUCTING+
129 /* See comment about __CTOR_LIST__ above. The same reasoning
130 applies here too. */
131 ___DTOR_LIST__ = .;
132 __DTOR_LIST__ = .;
133 LONG (-1);
134 KEEP(*(.dtors));
135 KEEP(*(.dtor));
136 KEEP(*(SORT_BY_NAME(.dtors.*)));
137 LONG (0);
138 }
139 ${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
140 ${RELOCATING+/* ??? Why is .gcc_exc here? */}
141 ${RELOCATING+ *(.gcc_exc)}
142 ${RELOCATING+PROVIDE (etext = .);}
143 ${RELOCATING+PROVIDE (_etext = .);}
144 ${RELOCATING+ KEEP (*(.gcc_except_table))}
145 }
146
147 /* The Cygwin32 library uses a section to avoid copying certain data
148 on fork. This used to be named ".data$nocopy". The linker used
149 to include this between __data_start__ and __data_end__, but that
150 breaks building the cygwin32 dll. Instead, we name the section
151 ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
152
153 .data ${RELOCATING+BLOCK(__section_alignment__)} :
154 {
155 ${RELOCATING+__data_start__ = . ;}
156 *(.data)
157 ${RELOCATING+*(.data2)}
158 ${R_DATA}
159 KEEP(*(.jcr))
160 ${RELOCATING+__data_end__ = . ;}
161 ${RELOCATING+*(.data_cygwin_nocopy)}
162 }
163
164 .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
165 {
166 ${R_RDATA}
167 . = ALIGN(4);
168 ${RELOCATING+__rt_psrelocs_start = .;}
169 ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
170 ${RELOCATING+__rt_psrelocs_end = .;}
171 }
172 ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
173 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
174 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
175 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
176 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
177
178 .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
179 {
180 KEEP(*(.eh_frame${RELOCATING+*}))
181 }
182
183 .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
184 {
185 KEEP(*(.pdata${RELOCATING+*}))
186 }
187
188 .bss ${RELOCATING+BLOCK(__section_alignment__)} :
189 {
190 ${RELOCATING+__bss_start__ = . ;}
191 *(.bss)
192 *(COMMON)
193 ${RELOCATING+__bss_end__ = . ;}
194 }
195
196 .edata ${RELOCATING+BLOCK(__section_alignment__)} :
197 {
198 *(.edata)
199 }
200
201 /DISCARD/ :
202 {
203 *(.debug\$S)
204 *(.debug\$T)
205 *(.debug\$F)
206 *(.drectve)
207 ${RELOCATING+ *(.note.GNU-stack)}
208 ${RELOCATING+ *(.gnu.lto_*)}
209 }
210
211 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
212 {
213 /* This cannot currently be handled with grouped sections.
214 See pe.em:sort_sections. */
215 ${R_IDATA234}
216 ${RELOCATING+__IAT_start__ = .;}
217 ${R_IDATA5}
218 ${RELOCATING+__IAT_end__ = .;}
219 ${R_IDATA67}
220 }
221 .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
222 {
223 ${RELOCATING+___crt_xc_start__ = . ;}
224 ${R_CRT_XC}
225 ${RELOCATING+___crt_xc_end__ = . ;}
226 ${RELOCATING+___crt_xi_start__ = . ;}
227 ${R_CRT_XI}
228 ${RELOCATING+___crt_xi_end__ = . ;}
229 ${RELOCATING+___crt_xl_start__ = . ;}
230 ${R_CRT_XL}
231 /* ___crt_xl_end__ is defined in the TLS Directory support code */
232 ${RELOCATING+___crt_xp_start__ = . ;}
233 ${R_CRT_XP}
234 ${RELOCATING+___crt_xp_end__ = . ;}
235 ${RELOCATING+___crt_xt_start__ = . ;}
236 ${R_CRT_XT}
237 ${RELOCATING+___crt_xt_end__ = . ;}
238 }
239
240 /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
241 at the end of section. This is important because _tls_start MUST
242 be at the beginning of the section to enable SECREL32 relocations with TLS
243 data. */
244 .tls ${RELOCATING+BLOCK(__section_alignment__)} :
245 {
246 ${RELOCATING+___tls_start__ = . ;}
247 ${R_TLS}
248 ${RELOCATING+___tls_end__ = . ;}
249 }
250
251 .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
252 {
253 /* end is deprecated, don't use it */
254 ${RELOCATING+PROVIDE (end = .);}
255 ${RELOCATING+PROVIDE ( _end = .);}
256 ${RELOCATING+ __end__ = .;}
257 }
258
259 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
260 {
261 ${R_RSRC}
262 }
263
264 .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
265 {
266 *(.reloc)
267 }
268
269 .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
270 {
271 *(.stab)
272 }
273
274 .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
275 {
276 *(.stabstr)
277 }
278
279 /* DWARF debug sections.
280 Symbols in the DWARF debugging sections are relative to the beginning
281 of the section. Unlike other targets that fake this by putting the
282 section VMA at 0, the PE format will not allow it. */
283
284 /* DWARF 1.1 and DWARF 2. */
285 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
286 {
287 *(.debug_aranges)
288 }
289 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
290 {
291 *(.zdebug_aranges)
292 }
293
294 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
295 {
296 *(.debug_pubnames)
297 }
298 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
299 {
300 *(.zdebug_pubnames)
301 }
302
303 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
304 {
305 *(.debug_pubtypes)
306 }
307 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
308 {
309 *(.zdebug_pubtypes)
310 }
311
312 /* DWARF 2. */
313 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
314 {
315 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
316 }
317 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
318 {
319 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
320 }
321
322 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
323 {
324 *(.debug_abbrev)
325 }
326 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
327 {
328 *(.zdebug_abbrev)
329 }
330
331 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
332 {
333 *(.debug_line)
334 }
335 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
336 {
337 *(.zdebug_line)
338 }
339
340 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
341 {
342 *(.debug_frame*)
343 }
344 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
345 {
346 *(.zdebug_frame*)
347 }
348
349 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
350 {
351 *(.debug_str)
352 }
353 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
354 {
355 *(.zdebug_str)
356 }
357
358 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
359 {
360 *(.debug_loc)
361 }
362 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
363 {
364 *(.zdebug_loc)
365 }
366
367 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
368 {
369 *(.debug_macinfo)
370 }
371 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
372 {
373 *(.zdebug_macinfo)
374 }
375
376 /* SGI/MIPS DWARF 2 extensions. */
377 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
378 {
379 *(.debug_weaknames)
380 }
381 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
382 {
383 *(.zdebug_weaknames)
384 }
385
386 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
387 {
388 *(.debug_funcnames)
389 }
390 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
391 {
392 *(.zdebug_funcnames)
393 }
394
395 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
396 {
397 *(.debug_typenames)
398 }
399 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
400 {
401 *(.zdebug_typenames)
402 }
403
404 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
405 {
406 *(.debug_varnames)
407 }
408 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
409 {
410 *(.zdebug_varnames)
411 }
412
413 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
414 {
415 *(.debug_macro)
416 }
417 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
418 {
419 *(.zdebug_macro)
420 }
421
422 /* DWARF 3. */
423 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
424 {
425 *(.debug_ranges)
426 }
427 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
428 {
429 *(.zdebug_ranges)
430 }
431
432 /* DWARF 4. */
433 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
434 {
435 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
436 }
437 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
438 {
439 *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*})
440 }
441
442 /* For Go and Rust. */
443 .debug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
444 {
445 *(.debug_gdb_scripts)
446 }
447 .zdebug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
448 {
449 *(.zdebug_gdb_scripts)
450 }
451 }
452 EOF