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