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