]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/scripttempl/pe.sc
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / scripttempl / pe.sc
CommitLineData
252b5132 1# Linker script for PE.
985743c7 2#
250d07de 3# Copyright (C) 2014-2021 Free Software Foundation, Inc.
6c19b93b 4#
985743c7
NC
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.
252b5132
RH
8
9if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
10 RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
11fi
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).
20if test "${RELOCATING}"; then
21 R_TEXT='*(SORT(.text$*))'
e2a83dd0
NC
22 if test "x$LD_FLAG" = "xauto_import" ; then
23 R_DATA='*(SORT(.data$*))
6c19b93b 24 *(.rdata)
e2a83dd0
NC
25 *(SORT(.rdata$*))'
26 R_RDATA=''
27 else
28 R_DATA='*(SORT(.data$*))'
29 R_RDATA='*(.rdata)
6c19b93b 30 *(SORT(.rdata$*))'
e2a83dd0 31 fi
d4874973 32 R_IDATA234='
0f088b2a
KT
33 KEEP (SORT(*)(.idata$2))
34 KEEP (SORT(*)(.idata$3))
252b5132
RH
35 /* These zeroes mark the end of the import list. */
36 LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
0f088b2a
KT
37 KEEP (SORT(*)(.idata$4))'
38 R_IDATA5='KEEP (SORT(*)(.idata$5))'
d4874973 39 R_IDATA67='
0f088b2a
KT
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 */'
ca6dee30 47 R_TLS='
0f088b2a
KT
48 KEEP (*(.tls$AAA))
49 KEEP (*(.tls))
50 KEEP (*(.tls$))
51 KEEP (*(SORT(.tls$*)))
52 KEEP (*(.tls$ZZZ))'
6c1799ad 53 R_RSRC='
0f088b2a
KT
54 KEEP (*(.rsrc))
55 KEEP (*(.rsrc$*))'
252b5132
RH
56else
57 R_TEXT=
58 R_DATA=
e2a83dd0 59 R_RDATA='*(.rdata)'
d4874973
KT
60 R_IDATA234=
61 R_IDATA5=
62 R_IDATA67=
c48cfedd
AM
63 R_CRT_XC=
64 R_CRT_XI=
65 R_CRT_XL=
66 R_CRT_XP=
67 R_CRT_XT=
68 R_TLS='*(.tls)'
5063daf7 69 R_RSRC='*(.rsrc)'
252b5132
RH
70fi
71
72cat <<EOF
250d07de 73/* Copyright (C) 2014-2021 Free Software Foundation, Inc.
985743c7
NC
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
252b5132
RH
79${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
80${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
c6c37250 81${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
252b5132
RH
82
83${LIB_SEARCH_DIRS}
84
252b5132
RH
85SECTIONS
86{
03098a9a
CF
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__);}
5063daf7 91 .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
252b5132 92 {
2d3181c7 93 ${RELOCATING+KEEP (*(SORT_NONE(.init)))}
252b5132
RH
94 *(.text)
95 ${R_TEXT}
032f3e01 96 ${RELOCATING+ *(.text.*)}
ebe9c501 97 ${RELOCATING+ *(.gnu.linkonce.t.*)}
c48cfedd
AM
98 ${RELOCATING+*(.glue_7t)}
99 ${RELOCATING+*(.glue_7)}
ca6f2be7 100 ${CONSTRUCTING+
b0daac83
NC
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.
5b537ffc 107 See PR 22762 for more details.
b0daac83
NC
108
109 This does mean that it is not possible for a user to define
99f8774c
MS
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).
b0daac83 116
5b537ffc
AM
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. */
b0daac83
NC
120 ___CTOR_LIST__ = .;
121 __CTOR_LIST__ = .;
ca6f2be7
NC
122 LONG (-1);
123 KEEP(*(.ctors));
124 KEEP(*(.ctor));
125 KEEP(*(SORT_BY_NAME(.ctors.*)));
126 LONG (0);
127 }
128 ${CONSTRUCTING+
b0daac83
NC
129 /* See comment about __CTOR_LIST__ above. The same reasoning
130 applies here too. */
131 ___DTOR_LIST__ = .;
132 __DTOR_LIST__ = .;
ca6f2be7
NC
133 LONG (-1);
134 KEEP(*(.dtors));
135 KEEP(*(.dtor));
136 KEEP(*(SORT_BY_NAME(.dtors.*)));
137 LONG (0);
138 }
2d3181c7 139 ${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
5b537ffc 140 ${RELOCATING+/* ??? Why is .gcc_exc here? */}
252b5132 141 ${RELOCATING+ *(.gcc_exc)}
15c9f673 142 ${RELOCATING+PROVIDE (etext = .);}
ee8206a9 143 ${RELOCATING+PROVIDE (_etext = .);}
aa785360 144 ${RELOCATING+ KEEP (*(.gcc_except_table))}
252b5132
RH
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
cc643b88 151 ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
252b5132 152
5063daf7 153 .data ${RELOCATING+BLOCK(__section_alignment__)} :
252b5132
RH
154 {
155 ${RELOCATING+__data_start__ = . ;}
156 *(.data)
c48cfedd 157 ${RELOCATING+*(.data2)}
252b5132 158 ${R_DATA}
0f088b2a 159 KEEP(*(.jcr))
252b5132
RH
160 ${RELOCATING+__data_end__ = . ;}
161 ${RELOCATING+*(.data_cygwin_nocopy)}
162 }
163
be4514d3
ILT
164 .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
165 {
be4514d3 166 ${R_RDATA}
73af69e7 167 . = ALIGN(4);
730035f7 168 ${RELOCATING+__rt_psrelocs_start = .;}
c48cfedd 169 ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
730035f7 170 ${RELOCATING+__rt_psrelocs_end = .;}
be4514d3 171 }
730035f7
DK
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;}
be4514d3 177
27505b5d
TG
178 .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
179 {
c48cfedd 180 KEEP(*(.eh_frame${RELOCATING+*}))
27505b5d
TG
181 }
182
344a211f
NC
183 .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
184 {
c48cfedd 185 KEEP(*(.pdata${RELOCATING+*}))
344a211f
NC
186 }
187
252b5132
RH
188 .bss ${RELOCATING+BLOCK(__section_alignment__)} :
189 {
190 ${RELOCATING+__bss_start__ = . ;}
191 *(.bss)
192 *(COMMON)
193 ${RELOCATING+__bss_end__ = . ;}
194 }
195
252b5132
RH
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)
fecc36fd
KT
207 ${RELOCATING+ *(.note.GNU-stack)}
208 ${RELOCATING+ *(.gnu.lto_*)}
252b5132
RH
209 }
210
211 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
212 {
213 /* This cannot currently be handled with grouped sections.
214 See pe.em:sort_sections. */
d4874973
KT
215 ${R_IDATA234}
216 ${RELOCATING+__IAT_start__ = .;}
217 ${R_IDATA5}
218 ${RELOCATING+__IAT_end__ = .;}
219 ${R_IDATA67}
252b5132
RH
220 }
221 .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
6c19b93b 222 {
552f8272
CF
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__ = . ;}
252b5132
RH
238 }
239
a988325c
NC
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. */
ca6dee30 244 .tls ${RELOCATING+BLOCK(__section_alignment__)} :
6c19b93b 245 {
552f8272 246 ${RELOCATING+___tls_start__ = . ;}
ca6dee30 247 ${R_TLS}
552f8272 248 ${RELOCATING+___tls_end__ = . ;}
ca6dee30
NC
249 }
250
252b5132
RH
251 .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
252 {
253 /* end is deprecated, don't use it */
15c9f673
CF
254 ${RELOCATING+PROVIDE (end = .);}
255 ${RELOCATING+PROVIDE ( _end = .);}
252b5132
RH
256 ${RELOCATING+ __end__ = .;}
257 }
258
1d63324c 259 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
5063daf7 260 {
252b5132
RH
261 ${R_RSRC}
262 }
263
be4514d3 264 .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
5063daf7 265 {
be4514d3
ILT
266 *(.reloc)
267 }
268
252b5132
RH
269 .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
270 {
8a7140c3 271 *(.stab)
252b5132
RH
272 }
273
274 .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
275 {
8a7140c3 276 *(.stabstr)
252b5132
RH
277 }
278
8a7140c3
NC
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. */
5063daf7 283
8a7140c3
NC
284 /* DWARF 1.1 and DWARF 2. */
285 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
286 {
287 *(.debug_aranges)
288 }
a29a8af8
KT
289 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
290 {
291 *(.zdebug_aranges)
292 }
8a7140c3
NC
293
294 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
295 {
296 *(.debug_pubnames)
297 }
a29a8af8
KT
298 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
299 {
300 *(.zdebug_pubnames)
301 }
8a7140c3 302
22418005 303 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
a626fe20
KT
304 {
305 *(.debug_pubtypes)
306 }
a29a8af8
KT
307 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
308 {
309 *(.zdebug_pubtypes)
310 }
a626fe20 311
8a7140c3
NC
312 /* DWARF 2. */
313 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
314 {
ebe9c501 315 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
8a7140c3 316 }
a29a8af8
KT
317 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
318 {
319 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
320 }
8a7140c3
NC
321
322 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
323 {
324 *(.debug_abbrev)
325 }
a29a8af8
KT
326 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
327 {
328 *(.zdebug_abbrev)
329 }
8a7140c3
NC
330
331 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
332 {
333 *(.debug_line)
334 }
a29a8af8
KT
335 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
336 {
337 *(.zdebug_line)
338 }
8a7140c3
NC
339
340 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
341 {
72b016b4 342 *(.debug_frame*)
8a7140c3 343 }
a29a8af8
KT
344 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
345 {
346 *(.zdebug_frame*)
347 }
8a7140c3
NC
348
349 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
350 {
351 *(.debug_str)
352 }
a29a8af8
KT
353 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
354 {
355 *(.zdebug_str)
356 }
8a7140c3
NC
357
358 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
359 {
360 *(.debug_loc)
361 }
a29a8af8
KT
362 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
363 {
364 *(.zdebug_loc)
365 }
8a7140c3
NC
366
367 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
368 {
369 *(.debug_macinfo)
370 }
a29a8af8
KT
371 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
372 {
373 *(.zdebug_macinfo)
374 }
8a7140c3
NC
375
376 /* SGI/MIPS DWARF 2 extensions. */
377 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
378 {
379 *(.debug_weaknames)
380 }
a29a8af8
KT
381 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
382 {
383 *(.zdebug_weaknames)
384 }
8a7140c3
NC
385
386 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
387 {
388 *(.debug_funcnames)
389 }
a29a8af8
KT
390 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
391 {
392 *(.zdebug_funcnames)
393 }
8a7140c3
NC
394
395 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
396 {
397 *(.debug_typenames)
398 }
a29a8af8
KT
399 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
400 {
401 *(.zdebug_typenames)
402 }
8a7140c3
NC
403
404 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
405 {
406 *(.debug_varnames)
407 }
a29a8af8
KT
408 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
409 {
410 *(.zdebug_varnames)
411 }
8a7140c3 412
b990ad61
KT
413 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
414 {
415 *(.debug_macro)
416 }
a29a8af8
KT
417 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
418 {
419 *(.zdebug_macro)
420 }
b990ad61 421
8a7140c3
NC
422 /* DWARF 3. */
423 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
424 {
425 *(.debug_ranges)
426 }
a29a8af8
KT
427 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
428 {
429 *(.zdebug_ranges)
430 }
802d4822
KT
431
432 /* DWARF 4. */
433 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
434 {
ebe9c501 435 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
802d4822 436 }
a29a8af8
KT
437 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
438 {
439 *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*})
440 }
786e3eba
NC
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 }
252b5132
RH
451}
452EOF