1# Linker script for PE.
2#
3# Copyright (C) 2014-2016 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
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$*))'
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$*))'
56else
57  R_TEXT=
58  R_DATA=
59  R_RDATA='*(.rdata)'
60  R_IDATA234=
61  R_IDATA5=
62  R_IDATA67=
63  R_CRT=
64  R_RSRC='*(.rsrc)'
65fi
66
67cat <<EOF
68/* Copyright (C) 2014-2016 Free Software Foundation, Inc.
69
70   Copying and distribution of this script, with or without modification,
71   are permitted in any medium without royalty provided the copyright
72   notice and this notice are preserved.  */
73
74${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
75${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
76${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
77
78${LIB_SEARCH_DIRS}
79
80SECTIONS
81{
82  ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
83  ${RELOCATING+   lower than the target page size. */}
84  ${RELOCATING+. = SIZEOF_HEADERS;}
85  ${RELOCATING+. = ALIGN(__section_alignment__);}
86  .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
87  {
88    ${RELOCATING+ KEEP(*(.init))}
89    *(.text)
90    ${R_TEXT}
91    ${RELOCATING+ *(.text.*)}
92    ${RELOCATING+ *(.gnu.linkonce.t.*)}
93    *(.glue_7t)
94    *(.glue_7)
95    ${CONSTRUCTING+. = ALIGN(8);}
96    ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
97			LONG (-1); LONG (-1);
98			KEEP (*(.ctors));
99			KEEP (*(.ctor));
100			KEEP (*(SORT(.ctors.*)));
101			LONG (0); LONG (0); }
102    ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
103			LONG (-1); LONG (-1);
104			KEEP (*(.dtors));
105			KEEP (*(.dtor));
106			KEEP (*(SORT(.dtors.*)));
107			LONG (0); LONG (0); }
108    ${RELOCATING+ KEEP (*(.fini))}
109    /* ??? Why is .gcc_exc here?  */
110    ${RELOCATING+ *(.gcc_exc)}
111    ${RELOCATING+PROVIDE (etext = .);}
112    ${RELOCATING+ KEEP (*(.gcc_except_table))}
113  }
114
115  /* The Cygwin32 library uses a section to avoid copying certain data
116     on fork.  This used to be named ".data$nocopy".  The linker used
117     to include this between __data_start__ and __data_end__, but that
118     breaks building the cygwin32 dll.  Instead, we name the section
119     ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
120
121  .data ${RELOCATING+BLOCK(__section_alignment__)} :
122  {
123    ${RELOCATING+__data_start__ = . ;}
124    *(.data)
125    *(.data2)
126    ${R_DATA}
127    KEEP(*(.jcr))
128    ${RELOCATING+__data_end__ = . ;}
129    ${RELOCATING+*(.data_cygwin_nocopy)}
130  }
131
132  .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
133  {
134    ${R_RDATA}
135    ${RELOCATING+__rt_psrelocs_start = .;}
136    KEEP(*(.rdata_runtime_pseudo_reloc))
137    ${RELOCATING+__rt_psrelocs_end = .;}
138  }
139  ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
140  ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
141  ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
142  ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
143  ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
144
145  .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
146  {
147    KEEP (*(.eh_frame*))
148  }
149
150  .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
151  {
152    KEEP(*(.pdata*))
153  }
154
155  .xdata ${RELOCATING+BLOCK(__section_alignment__)} :
156  {
157    KEEP(*(.xdata*))
158  }
159
160  .bss ${RELOCATING+BLOCK(__section_alignment__)} :
161  {
162    ${RELOCATING+__bss_start__ = . ;}
163    *(.bss)
164    *(COMMON)
165    ${RELOCATING+__bss_end__ = . ;}
166  }
167
168  .edata ${RELOCATING+BLOCK(__section_alignment__)} :
169  {
170    *(.edata)
171  }
172
173  /DISCARD/ :
174  {
175    *(.debug\$S)
176    *(.debug\$T)
177    *(.debug\$F)
178    *(.drectve)
179    ${RELOCATING+ *(.note.GNU-stack)}
180    ${RELOCATING+ *(.gnu.lto_*)}
181  }
182
183  .idata ${RELOCATING+BLOCK(__section_alignment__)} :
184  {
185    /* This cannot currently be handled with grouped sections.
186	See pep.em:sort_sections.  */
187    ${R_IDATA234}
188    ${RELOCATING+__IAT_start__ = .;}
189    ${R_IDATA5}
190    ${RELOCATING+__IAT_end__ = .;}
191    ${R_IDATA67}
192  }
193  .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
194  {
195    ${RELOCATING+___crt_xc_start__ = . ;}
196    ${R_CRT_XC}
197    ${RELOCATING+___crt_xc_end__ = . ;}
198    ${RELOCATING+___crt_xi_start__ = . ;}
199    ${R_CRT_XI}
200    ${RELOCATING+___crt_xi_end__ = . ;}
201    ${RELOCATING+___crt_xl_start__ = . ;}
202    ${R_CRT_XL}
203    /* ___crt_xl_end__ is defined in the TLS Directory support code */
204    ${RELOCATING+___crt_xp_start__ = . ;}
205    ${R_CRT_XP}
206    ${RELOCATING+___crt_xp_end__ = . ;}
207    ${RELOCATING+___crt_xt_start__ = . ;}
208    ${R_CRT_XT}
209    ${RELOCATING+___crt_xt_end__ = . ;}
210  }
211
212  /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
213     at the end of the .tls section.  This is important because _tls_start MUST
214     be at the beginning of the section to enable SECREL32 relocations with TLS
215     data.  */
216  .tls ${RELOCATING+BLOCK(__section_alignment__)} :
217  {
218    ${RELOCATING+___tls_start__ = . ;}
219    ${R_TLS}
220    ${RELOCATING+___tls_end__ = . ;}
221  }
222
223  .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
224  {
225    /* end is deprecated, don't use it */
226    ${RELOCATING+PROVIDE (end = .);}
227    ${RELOCATING+PROVIDE ( _end = .);}
228    ${RELOCATING+ __end__ = .;}
229  }
230
231  .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
232  {
233    ${R_RSRC}
234  }
235
236  .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
237  {
238    *(.reloc)
239  }
240
241  .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
242  {
243    *(.stab)
244  }
245
246  .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
247  {
248    *(.stabstr)
249  }
250
251  /* DWARF debug sections.
252     Symbols in the DWARF debugging sections are relative to the beginning
253     of the section.  Unlike other targets that fake this by putting the
254     section VMA at 0, the PE format will not allow it.  */
255
256  /* DWARF 1.1 and DWARF 2.  */
257  .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
258  {
259    *(.debug_aranges)
260  }
261  .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
262  {
263    *(.zdebug_aranges)
264  }
265
266  .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
267  {
268    *(.debug_pubnames)
269  }
270  .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
271  {
272    *(.zdebug_pubnames)
273  }
274
275  .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
276  {
277    *(.debug_pubtypes)
278  }
279  .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
280  {
281    *(.zdebug_pubtypes)
282  }
283
284  /* DWARF 2.  */
285  .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
286  {
287    *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
288  }
289  .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
290  {
291    *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
292  }
293
294  .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
295  {
296    *(.debug_abbrev)
297  }
298  .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
299  {
300    *(.zdebug_abbrev)
301  }
302
303  .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
304  {
305    *(.debug_line)
306  }
307  .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
308  {
309    *(.zdebug_line)
310  }
311
312  .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
313  {
314    *(.debug_frame)
315  }
316  .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
317  {
318    *(.zdebug_frame)
319  }
320
321  .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
322  {
323    *(.debug_str)
324  }
325  .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
326  {
327    *(.zdebug_str)
328  }
329
330  .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
331  {
332    *(.debug_loc)
333  }
334  .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
335  {
336    *(.zdebug_loc)
337  }
338
339  .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
340  {
341    *(.debug_macinfo)
342  }
343  .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
344  {
345    *(.zdebug_macinfo)
346  }
347
348  /* SGI/MIPS DWARF 2 extensions.  */
349  .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
350  {
351    *(.debug_weaknames)
352  }
353  .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
354  {
355    *(.zdebug_weaknames)
356  }
357
358  .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
359  {
360    *(.debug_funcnames)
361  }
362  .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
363  {
364    *(.zdebug_funcnames)
365  }
366
367  .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
368  {
369    *(.debug_typenames)
370  }
371  .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
372  {
373    *(.zdebug_typenames)
374  }
375
376  .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
377  {
378    *(.debug_varnames)
379  }
380  .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
381  {
382    *(.zdebug_varnames)
383  }
384
385  .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
386  {
387    *(.debug_macro)
388  }
389  .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
390  {
391    *(.zdebug_macro)
392  }
393
394  /* DWARF 3.  */
395  .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
396  {
397    *(.debug_ranges)
398  }
399  .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
400  {
401    *(.zdebug_ranges)
402  }
403
404  /* DWARF 4.  */
405  .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
406  {
407    *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
408  }
409  .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
410  {
411    *(.zdebug_types${RELOCATING+ .zdebug.gnu.linkonce.wt.*})
412  }
413}
414EOF
415