Fix memory corruption when assembling an i386 darwin source file.
[deliverable/binutils-gdb.git] / ld / scripttempl / pep.sc
CommitLineData
99ad8390 1# Linker script for PE.
985743c7 2#
2571583a 3# Copyright (C) 2014-2017 Free Software Foundation, Inc.
985743c7
NC
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.
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$*))
24 *(.rdata)
25 *(SORT(.rdata$*))'
26 R_RDATA=''
27 else
28 R_DATA='*(SORT(.data$*))'
29 R_RDATA='*(.rdata)
30 *(SORT(.rdata$*))'
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
2571583a 73/* Copyright (C) 2014-2017 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);}
5063daf7 101 ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
0f088b2a
KT
102 LONG (-1); LONG (-1);
103 KEEP (*(.ctors));
104 KEEP (*(.ctor));
105 KEEP (*(SORT(.ctors.*)));
106 LONG (0); LONG (0); }
5063daf7 107 ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
0f088b2a
KT
108 LONG (-1); LONG (-1);
109 KEEP (*(.dtors));
110 KEEP (*(.dtor));
111 KEEP (*(SORT(.dtors.*)));
112 LONG (0); LONG (0); }
113 ${RELOCATING+ KEEP (*(.fini))}
99ad8390
NC
114 /* ??? Why is .gcc_exc here? */
115 ${RELOCATING+ *(.gcc_exc)}
116 ${RELOCATING+PROVIDE (etext = .);}
0f088b2a 117 ${RELOCATING+ KEEP (*(.gcc_except_table))}
99ad8390
NC
118 }
119
120 /* The Cygwin32 library uses a section to avoid copying certain data
121 on fork. This used to be named ".data$nocopy". The linker used
122 to include this between __data_start__ and __data_end__, but that
123 breaks building the cygwin32 dll. Instead, we name the section
cc643b88 124 ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
99ad8390 125
5063daf7 126 .data ${RELOCATING+BLOCK(__section_alignment__)} :
99ad8390
NC
127 {
128 ${RELOCATING+__data_start__ = . ;}
129 *(.data)
c48cfedd 130 ${RELOCATING+*(.data2)}
99ad8390 131 ${R_DATA}
0f088b2a 132 KEEP(*(.jcr))
99ad8390
NC
133 ${RELOCATING+__data_end__ = . ;}
134 ${RELOCATING+*(.data_cygwin_nocopy)}
135 }
136
137 .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
138 {
99ad8390 139 ${R_RDATA}
730035f7 140 ${RELOCATING+__rt_psrelocs_start = .;}
c48cfedd 141 ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
730035f7 142 ${RELOCATING+__rt_psrelocs_end = .;}
99ad8390 143 }
730035f7
DK
144 ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
145 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
146 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
147 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
148 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
99ad8390 149
27505b5d
TG
150 .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
151 {
c48cfedd 152 KEEP (*(.eh_frame${RELOCATING+*}))
27505b5d
TG
153 }
154
99ad8390
NC
155 .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
156 {
c48cfedd 157 KEEP(*(.pdata${RELOCATING+*}))
2d7f4929
KT
158 }
159
160 .xdata ${RELOCATING+BLOCK(__section_alignment__)} :
161 {
c48cfedd 162 KEEP(*(.xdata${RELOCATING+*}))
99ad8390
NC
163 }
164
165 .bss ${RELOCATING+BLOCK(__section_alignment__)} :
166 {
167 ${RELOCATING+__bss_start__ = . ;}
168 *(.bss)
169 *(COMMON)
170 ${RELOCATING+__bss_end__ = . ;}
171 }
172
173 .edata ${RELOCATING+BLOCK(__section_alignment__)} :
174 {
175 *(.edata)
176 }
177
178 /DISCARD/ :
179 {
180 *(.debug\$S)
181 *(.debug\$T)
182 *(.debug\$F)
183 *(.drectve)
fecc36fd
KT
184 ${RELOCATING+ *(.note.GNU-stack)}
185 ${RELOCATING+ *(.gnu.lto_*)}
99ad8390
NC
186 }
187
188 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
189 {
190 /* This cannot currently be handled with grouped sections.
191 See pep.em:sort_sections. */
d4874973
KT
192 ${R_IDATA234}
193 ${RELOCATING+__IAT_start__ = .;}
194 ${R_IDATA5}
195 ${RELOCATING+__IAT_end__ = .;}
196 ${R_IDATA67}
99ad8390
NC
197 }
198 .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
199 {
200 ${RELOCATING+___crt_xc_start__ = . ;}
201 ${R_CRT_XC}
202 ${RELOCATING+___crt_xc_end__ = . ;}
203 ${RELOCATING+___crt_xi_start__ = . ;}
204 ${R_CRT_XI}
205 ${RELOCATING+___crt_xi_end__ = . ;}
206 ${RELOCATING+___crt_xl_start__ = . ;}
207 ${R_CRT_XL}
208 /* ___crt_xl_end__ is defined in the TLS Directory support code */
209 ${RELOCATING+___crt_xp_start__ = . ;}
210 ${R_CRT_XP}
211 ${RELOCATING+___crt_xp_end__ = . ;}
212 ${RELOCATING+___crt_xt_start__ = . ;}
213 ${R_CRT_XT}
214 ${RELOCATING+___crt_xt_end__ = . ;}
215 }
216
a988325c
NC
217 /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
218 at the end of the .tls section. This is important because _tls_start MUST
219 be at the beginning of the section to enable SECREL32 relocations with TLS
220 data. */
99ad8390
NC
221 .tls ${RELOCATING+BLOCK(__section_alignment__)} :
222 {
223 ${RELOCATING+___tls_start__ = . ;}
224 ${R_TLS}
225 ${RELOCATING+___tls_end__ = . ;}
226 }
227
228 .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
229 {
230 /* end is deprecated, don't use it */
231 ${RELOCATING+PROVIDE (end = .);}
232 ${RELOCATING+PROVIDE ( _end = .);}
233 ${RELOCATING+ __end__ = .;}
234 }
235
1d63324c 236 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
5063daf7 237 {
99ad8390
NC
238 ${R_RSRC}
239 }
240
241 .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
5063daf7 242 {
99ad8390
NC
243 *(.reloc)
244 }
245
246 .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
247 {
248 *(.stab)
249 }
250
251 .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
252 {
253 *(.stabstr)
254 }
255
256 /* DWARF debug sections.
257 Symbols in the DWARF debugging sections are relative to the beginning
258 of the section. Unlike other targets that fake this by putting the
259 section VMA at 0, the PE format will not allow it. */
5063daf7 260
99ad8390
NC
261 /* DWARF 1.1 and DWARF 2. */
262 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
263 {
264 *(.debug_aranges)
265 }
a29a8af8
KT
266 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
267 {
268 *(.zdebug_aranges)
269 }
99ad8390
NC
270
271 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
272 {
273 *(.debug_pubnames)
274 }
a29a8af8
KT
275 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
276 {
277 *(.zdebug_pubnames)
278 }
99ad8390 279
22418005 280 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
a626fe20
KT
281 {
282 *(.debug_pubtypes)
283 }
a29a8af8
KT
284 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
285 {
286 *(.zdebug_pubtypes)
287 }
a626fe20 288
99ad8390
NC
289 /* DWARF 2. */
290 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
291 {
ebe9c501 292 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
99ad8390 293 }
a29a8af8
KT
294 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
295 {
296 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
297 }
99ad8390
NC
298
299 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
300 {
301 *(.debug_abbrev)
302 }
a29a8af8
KT
303 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
304 {
305 *(.zdebug_abbrev)
306 }
99ad8390
NC
307
308 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
309 {
310 *(.debug_line)
311 }
a29a8af8
KT
312 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
313 {
314 *(.zdebug_line)
315 }
99ad8390
NC
316
317 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
318 {
f5c66ab0 319 *(.debug_frame)
99ad8390 320 }
a29a8af8
KT
321 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
322 {
f5c66ab0 323 *(.zdebug_frame)
a29a8af8 324 }
99ad8390
NC
325
326 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
327 {
328 *(.debug_str)
329 }
a29a8af8
KT
330 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
331 {
332 *(.zdebug_str)
333 }
99ad8390
NC
334
335 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
336 {
337 *(.debug_loc)
338 }
a29a8af8
KT
339 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
340 {
341 *(.zdebug_loc)
342 }
99ad8390
NC
343
344 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
345 {
346 *(.debug_macinfo)
347 }
a29a8af8
KT
348 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
349 {
350 *(.zdebug_macinfo)
351 }
99ad8390
NC
352
353 /* SGI/MIPS DWARF 2 extensions. */
354 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
355 {
356 *(.debug_weaknames)
357 }
a29a8af8
KT
358 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
359 {
360 *(.zdebug_weaknames)
361 }
99ad8390
NC
362
363 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
364 {
365 *(.debug_funcnames)
366 }
a29a8af8
KT
367 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
368 {
369 *(.zdebug_funcnames)
370 }
99ad8390
NC
371
372 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
373 {
374 *(.debug_typenames)
375 }
a29a8af8
KT
376 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
377 {
378 *(.zdebug_typenames)
379 }
99ad8390
NC
380
381 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
382 {
383 *(.debug_varnames)
384 }
a29a8af8
KT
385 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
386 {
387 *(.zdebug_varnames)
388 }
99ad8390 389
b990ad61
KT
390 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
391 {
392 *(.debug_macro)
393 }
a29a8af8
KT
394 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
395 {
396 *(.zdebug_macro)
397 }
b990ad61 398
99ad8390
NC
399 /* DWARF 3. */
400 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
401 {
402 *(.debug_ranges)
403 }
a29a8af8
KT
404 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
405 {
406 *(.zdebug_ranges)
407 }
802d4822
KT
408
409 /* DWARF 4. */
410 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
411 {
ebe9c501 412 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
802d4822 413 }
a29a8af8
KT
414 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
415 {
416 *(.zdebug_types${RELOCATING+ .zdebug.gnu.linkonce.wt.*})
417 }
786e3eba
NC
418
419 /* For Go and Rust. */
420 .debug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
421 {
422 *(.debug_gdb_scripts)
423 }
424 .zdebug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
425 {
426 *(.zdebug_gdb_scripts)
427 }
99ad8390
NC
428}
429EOF
This page took 0.850219 seconds and 4 git commands to generate.