* scripttempl/elf.sc: Handle function names and other
[external/binutils.git] / ld / scripttempl / pe.sc
1 # Linker script for PE.
2
3 if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
4   RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
5 fi
6
7 # We can't easily and portably get an unquoted $ in a shell
8 # substitution, so we do this instead.
9 # Sorting of the .foo$* sections is required by the definition of
10 # grouped sections in PE.
11 # Sorting of the file names in R_IDATA is required by the
12 # current implementation of dlltool (this could probably be changed to
13 # use grouped sections instead).
14 if test "${RELOCATING}"; then
15   R_TEXT='*(SORT(.text$*))'
16   if test "x$LD_FLAG" = "xauto_import" ; then
17     R_DATA='*(SORT(.data$*))
18             *(.rdata)
19             *(SORT(.rdata$*))'
20     R_RDATA=''
21   else
22     R_DATA='*(SORT(.data$*))'
23     R_RDATA='*(.rdata)
24              *(SORT(.rdata$*))'
25   fi
26   R_IDATA234='
27     SORT(*)(.idata$2)
28     SORT(*)(.idata$3)
29     /* These zeroes mark the end of the import list.  */
30     LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
31     SORT(*)(.idata$4)'
32   R_IDATA5='SORT(*)(.idata$5)'
33   R_IDATA67='
34     SORT(*)(.idata$6)
35     SORT(*)(.idata$7)'
36   R_CRT_XC='*(SORT(.CRT$XC*))  /* C initialization */'
37   R_CRT_XI='*(SORT(.CRT$XI*))  /* C++ initialization */'
38   R_CRT_XL='*(SORT(.CRT$XL*))  /* TLS callbacks */'
39   R_CRT_XP='*(SORT(.CRT$XP*))  /* Pre-termination */'
40   R_CRT_XT='*(SORT(.CRT$XT*))  /* Termination */'
41   R_TLS='
42     *(.tls$AAA)    
43     *(.tls)
44     *(.tls$)
45     *(SORT(.tls$*))
46     *(.tls$ZZZ)'
47   R_RSRC='*(SORT(.rsrc$*))'
48 else
49   R_TEXT=
50   R_DATA=
51   R_RDATA='*(.rdata)'
52   R_IDATA234=
53   R_IDATA5=
54   R_IDATA67=
55   R_CRT=
56   R_RSRC=
57 fi
58
59 cat <<EOF
60 ${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
61 ${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
62 ${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
63
64 ${LIB_SEARCH_DIRS}
65
66 SECTIONS
67 {
68   ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
69   ${RELOCATING+   lower than the target page size. */}
70   ${RELOCATING+. = SIZEOF_HEADERS;}
71   ${RELOCATING+. = ALIGN(__section_alignment__);}
72   .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} : 
73   {
74     ${RELOCATING+ *(.init)}
75     *(.text)
76     ${R_TEXT}
77     ${RELOCATING+ *(.text.*)}
78     ${RELOCATING+ *(.gnu.linkonce.t.*)}
79     *(.glue_7t)
80     *(.glue_7)
81     ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ; 
82                         LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0); }
83     ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; 
84                         LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0); }
85     ${RELOCATING+ *(.fini)}
86     /* ??? Why is .gcc_exc here?  */
87     ${RELOCATING+ *(.gcc_exc)}
88     ${RELOCATING+PROVIDE (etext = .);}
89     ${RELOCATING+PROVIDE (_etext = .);}
90     ${RELOCATING+ *(.gcc_except_table)}
91   }
92
93   /* The Cygwin32 library uses a section to avoid copying certain data
94      on fork.  This used to be named ".data$nocopy".  The linker used
95      to include this between __data_start__ and __data_end__, but that
96      breaks building the cygwin32 dll.  Instead, we name the section
97      ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
98
99   .data ${RELOCATING+BLOCK(__section_alignment__)} : 
100   {
101     ${RELOCATING+__data_start__ = . ;}
102     *(.data)
103     *(.data2)
104     ${R_DATA}
105     *(.jcr)
106     ${RELOCATING+__data_end__ = . ;}
107     ${RELOCATING+*(.data_cygwin_nocopy)}
108   }
109
110   .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
111   {
112     ${R_RDATA}
113     ${RELOCATING+__rt_psrelocs_start = .;}
114     *(.rdata_runtime_pseudo_reloc)
115     ${RELOCATING+__rt_psrelocs_end = .;}
116   }
117   ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
118   ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
119   ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
120   ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
121   ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
122
123   .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
124   {
125     *(.eh_frame*)
126   }
127
128   .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
129   {
130     *(.pdata)
131   }
132
133   .bss ${RELOCATING+BLOCK(__section_alignment__)} :
134   {
135     ${RELOCATING+__bss_start__ = . ;}
136     *(.bss)
137     *(COMMON)
138     ${RELOCATING+__bss_end__ = . ;}
139   }
140
141   .edata ${RELOCATING+BLOCK(__section_alignment__)} :
142   {
143     *(.edata)
144   }
145
146   /DISCARD/ :
147   {
148     *(.debug\$S)
149     *(.debug\$T)
150     *(.debug\$F)
151     *(.drectve)
152     ${RELOCATING+ *(.note.GNU-stack)}
153     ${RELOCATING+ *(.gnu.lto_*)}
154   }
155
156   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
157   {
158     /* This cannot currently be handled with grouped sections.
159         See pe.em:sort_sections.  */
160     ${R_IDATA234}
161     ${RELOCATING+__IAT_start__ = .;}
162     ${R_IDATA5}
163     ${RELOCATING+__IAT_end__ = .;}
164     ${R_IDATA67}
165   }
166   .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
167   {                                     
168     ${RELOCATING+___crt_xc_start__ = . ;}
169     ${R_CRT_XC}
170     ${RELOCATING+___crt_xc_end__ = . ;}
171     ${RELOCATING+___crt_xi_start__ = . ;}
172     ${R_CRT_XI}
173     ${RELOCATING+___crt_xi_end__ = . ;}
174     ${RELOCATING+___crt_xl_start__ = . ;}
175     ${R_CRT_XL}
176     /* ___crt_xl_end__ is defined in the TLS Directory support code */
177     ${RELOCATING+___crt_xp_start__ = . ;}
178     ${R_CRT_XP}
179     ${RELOCATING+___crt_xp_end__ = . ;}
180     ${RELOCATING+___crt_xt_start__ = . ;}
181     ${R_CRT_XT}
182     ${RELOCATING+___crt_xt_end__ = . ;}
183   }
184
185   /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
186      at the end of section.  This is important because _tls_start MUST
187      be at the beginning of the section to enable SECREL32 relocations with TLS
188      data.  */
189   .tls ${RELOCATING+BLOCK(__section_alignment__)} :
190   {                                     
191     ${RELOCATING+___tls_start__ = . ;}
192     ${R_TLS}
193     ${RELOCATING+___tls_end__ = . ;}
194   }
195
196   .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
197   {
198     /* end is deprecated, don't use it */
199     ${RELOCATING+PROVIDE (end = .);}
200     ${RELOCATING+PROVIDE ( _end = .);}
201     ${RELOCATING+ __end__ = .;}
202   }
203
204   .rsrc ${RELOCATING+BLOCK(__section_alignment__)} :
205   {                                     
206     *(.rsrc)
207     ${R_RSRC}
208   }
209
210   .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
211   {                                     
212     *(.reloc)
213   }
214
215   .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
216   {
217     *(.stab)
218   }
219
220   .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
221   {
222     *(.stabstr)
223   }
224
225   /* DWARF debug sections.
226      Symbols in the DWARF debugging sections are relative to the beginning
227      of the section.  Unlike other targets that fake this by putting the
228      section VMA at 0, the PE format will not allow it.  */
229      
230   /* DWARF 1.1 and DWARF 2.  */
231   .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
232   {
233     *(.debug_aranges)
234   }
235   .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
236   {
237     *(.zdebug_aranges)
238   }
239
240   .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
241   {
242     *(.debug_pubnames)
243   }
244   .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
245   {
246     *(.zdebug_pubnames)
247   }
248
249   .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
250   {
251     *(.debug_pubtypes)
252   }
253   .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
254   {
255     *(.zdebug_pubtypes)
256   }
257
258   /* DWARF 2.  */
259   .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
260   {
261     *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
262   }
263   .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
264   {
265     *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
266   }
267
268   .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
269   {
270     *(.debug_abbrev)
271   }
272   .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
273   {
274     *(.zdebug_abbrev)
275   }
276
277   .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
278   {
279     *(.debug_line)
280   }
281   .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
282   {
283     *(.zdebug_line)
284   }
285
286   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
287   {
288     *(.debug_frame*)
289   }
290   .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
291   {
292     *(.zdebug_frame*)
293   }
294
295   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
296   {
297     *(.debug_str)
298   }
299   .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
300   {
301     *(.zdebug_str)
302   }
303
304   .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
305   {
306     *(.debug_loc)
307   }
308   .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
309   {
310     *(.zdebug_loc)
311   }
312
313   .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
314   {
315     *(.debug_macinfo)
316   }
317   .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
318   {
319     *(.zdebug_macinfo)
320   }
321
322   /* SGI/MIPS DWARF 2 extensions.  */
323   .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
324   {
325     *(.debug_weaknames)
326   }
327   .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
328   {
329     *(.zdebug_weaknames)
330   }
331
332   .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
333   {
334     *(.debug_funcnames)
335   }
336   .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
337   {
338     *(.zdebug_funcnames)
339   }
340
341   .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
342   {
343     *(.debug_typenames)
344   }
345   .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
346   {
347     *(.zdebug_typenames)
348   }
349
350   .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
351   {
352     *(.debug_varnames)
353   }
354   .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
355   {
356     *(.zdebug_varnames)
357   }
358
359   .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
360   {
361     *(.debug_macro)
362   }
363   .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
364   {
365     *(.zdebug_macro)
366   }
367
368   /* DWARF 3.  */
369   .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
370   {
371     *(.debug_ranges)
372   }
373   .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
374   {
375     *(.zdebug_ranges)
376   }
377
378   /* DWARF 4.  */
379   .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
380   {
381     *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
382   }
383   .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
384   {
385     *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*})
386   }
387 }
388 EOF