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