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