]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/scripttempl/pep.sc
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / scripttempl / pep.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='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+. = ALIGN(8);}
101 ${CONSTRUCTING+
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.
108 See PR 22762 for more details.
109
110 This does mean that it is not possible for a user to define
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).
117
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. */
121 ___CTOR_LIST__ = .;
122 __CTOR_LIST__ = .;
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+
130 /* See comment about __CTOR_LIST__ above. The same reasoning
131 applies here too. */
132 ___DTOR_LIST__ = .;
133 __DTOR_LIST__ = .;
134 LONG (-1); LONG (-1);
135 KEEP (*(.dtors));
136 KEEP (*(.dtor));
137 KEEP (*(SORT_BY_NAME(.dtors.*)));
138 LONG (0); LONG (0);
139 }
140 ${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
141 ${RELOCATING+/* ??? Why is .gcc_exc here? */}
142 ${RELOCATING+ *(.gcc_exc)}
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 .xdata ${RELOCATING+BLOCK(__section_alignment__)} :
189 {
190 KEEP(*(.xdata${RELOCATING+*}))
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)
212 ${RELOCATING+ *(.note.GNU-stack)}
213 ${RELOCATING+ *(.gnu.lto_*)}
214 }
215
216 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
217 {
218 /* This cannot currently be handled with grouped sections.
219 See pep.em:sort_sections. */
220 ${R_IDATA234}
221 ${RELOCATING+__IAT_start__ = .;}
222 ${R_IDATA5}
223 ${RELOCATING+__IAT_end__ = .;}
224 ${R_IDATA67}
225 }
226 .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
227 {
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
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. */
249 .tls ${RELOCATING+BLOCK(__section_alignment__)} :
250 {
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
264 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
265 {
266 ${R_RSRC}
267 }
268
269 .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
270 {
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. */
288
289 /* DWARF 1.1 and DWARF 2. */
290 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
291 {
292 *(.debug_aranges)
293 }
294 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
295 {
296 *(.zdebug_aranges)
297 }
298
299 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
300 {
301 *(.debug_pubnames)
302 }
303 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
304 {
305 *(.zdebug_pubnames)
306 }
307
308 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
309 {
310 *(.debug_pubtypes)
311 }
312 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
313 {
314 *(.zdebug_pubtypes)
315 }
316
317 /* DWARF 2. */
318 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
319 {
320 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
321 }
322 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
323 {
324 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
325 }
326
327 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
328 {
329 *(.debug_abbrev)
330 }
331 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
332 {
333 *(.zdebug_abbrev)
334 }
335
336 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
337 {
338 *(.debug_line)
339 }
340 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
341 {
342 *(.zdebug_line)
343 }
344
345 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
346 {
347 *(.debug_frame)
348 }
349 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
350 {
351 *(.zdebug_frame)
352 }
353
354 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
355 {
356 *(.debug_str)
357 }
358 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
359 {
360 *(.zdebug_str)
361 }
362
363 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
364 {
365 *(.debug_loc)
366 }
367 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
368 {
369 *(.zdebug_loc)
370 }
371
372 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
373 {
374 *(.debug_macinfo)
375 }
376 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
377 {
378 *(.zdebug_macinfo)
379 }
380
381 /* SGI/MIPS DWARF 2 extensions. */
382 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
383 {
384 *(.debug_weaknames)
385 }
386 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
387 {
388 *(.zdebug_weaknames)
389 }
390
391 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
392 {
393 *(.debug_funcnames)
394 }
395 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
396 {
397 *(.zdebug_funcnames)
398 }
399
400 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
401 {
402 *(.debug_typenames)
403 }
404 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
405 {
406 *(.zdebug_typenames)
407 }
408
409 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
410 {
411 *(.debug_varnames)
412 }
413 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
414 {
415 *(.zdebug_varnames)
416 }
417
418 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
419 {
420 *(.debug_macro)
421 }
422 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
423 {
424 *(.zdebug_macro)
425 }
426
427 /* DWARF 3. */
428 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
429 {
430 *(.debug_ranges)
431 }
432 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
433 {
434 *(.zdebug_ranges)
435 }
436
437 /* DWARF 4. */
438 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
439 {
440 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
441 }
442 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
443 {
444 *(.zdebug_types${RELOCATING+ .zdebug.gnu.linkonce.wt.*})
445 }
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 }
456 }
457 EOF