* scripttempl/elf.sc: Handle function names and other
[external/binutils.git] / ld / scripttempl / pep.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+. = ALIGN(8);}
82     ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ; 
83                         LONG (-1); LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0); LONG (0); }
84     ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ; 
85                         LONG (-1); LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0); LONG (0); }
86     ${RELOCATING+ *(.fini)}
87     /* ??? Why is .gcc_exc here?  */
88     ${RELOCATING+ *(.gcc_exc)}
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   .xdata ${RELOCATING+BLOCK(__section_alignment__)} :
134   {
135     *(.xdata*)
136   }
137
138   .bss ${RELOCATING+BLOCK(__section_alignment__)} :
139   {
140     ${RELOCATING+__bss_start__ = . ;}
141     *(.bss)
142     *(COMMON)
143     ${RELOCATING+__bss_end__ = . ;}
144   }
145
146   .edata ${RELOCATING+BLOCK(__section_alignment__)} :
147   {
148     *(.edata)
149   }
150
151   /DISCARD/ :
152   {
153     *(.debug\$S)
154     *(.debug\$T)
155     *(.debug\$F)
156     *(.drectve)
157     ${RELOCATING+ *(.note.GNU-stack)}
158     ${RELOCATING+ *(.gnu.lto_*)}
159   }
160
161   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
162   {
163     /* This cannot currently be handled with grouped sections.
164         See pep.em:sort_sections.  */
165     ${R_IDATA234}
166     ${RELOCATING+__IAT_start__ = .;}
167     ${R_IDATA5}
168     ${RELOCATING+__IAT_end__ = .;}
169     ${R_IDATA67}
170   }
171   .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
172   {                                     
173     ${RELOCATING+___crt_xc_start__ = . ;}
174     ${R_CRT_XC}
175     ${RELOCATING+___crt_xc_end__ = . ;}
176     ${RELOCATING+___crt_xi_start__ = . ;}
177     ${R_CRT_XI}
178     ${RELOCATING+___crt_xi_end__ = . ;}
179     ${RELOCATING+___crt_xl_start__ = . ;}
180     ${R_CRT_XL}
181     /* ___crt_xl_end__ is defined in the TLS Directory support code */
182     ${RELOCATING+___crt_xp_start__ = . ;}
183     ${R_CRT_XP}
184     ${RELOCATING+___crt_xp_end__ = . ;}
185     ${RELOCATING+___crt_xt_start__ = . ;}
186     ${R_CRT_XT}
187     ${RELOCATING+___crt_xt_end__ = . ;}
188   }
189
190   /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
191      at the end of the .tls section.  This is important because _tls_start MUST
192      be at the beginning of the section to enable SECREL32 relocations with TLS
193      data.  */
194   .tls ${RELOCATING+BLOCK(__section_alignment__)} :
195   {                                     
196     ${RELOCATING+___tls_start__ = . ;}
197     ${R_TLS}
198     ${RELOCATING+___tls_end__ = . ;}
199   }
200
201   .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
202   {
203     /* end is deprecated, don't use it */
204     ${RELOCATING+PROVIDE (end = .);}
205     ${RELOCATING+PROVIDE ( _end = .);}
206     ${RELOCATING+ __end__ = .;}
207   }
208
209   .rsrc ${RELOCATING+BLOCK(__section_alignment__)} :
210   {                                     
211     *(.rsrc)
212     ${R_RSRC}
213   }
214
215   .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
216   {                                     
217     *(.reloc)
218   }
219
220   .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
221   {
222     *(.stab)
223   }
224
225   .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
226   {
227     *(.stabstr)
228   }
229
230   /* DWARF debug sections.
231      Symbols in the DWARF debugging sections are relative to the beginning
232      of the section.  Unlike other targets that fake this by putting the
233      section VMA at 0, the PE format will not allow it.  */
234      
235   /* DWARF 1.1 and DWARF 2.  */
236   .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
237   {
238     *(.debug_aranges)
239   }
240   .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
241   {
242     *(.zdebug_aranges)
243   }
244
245   .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
246   {
247     *(.debug_pubnames)
248   }
249   .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
250   {
251     *(.zdebug_pubnames)
252   }
253
254   .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
255   {
256     *(.debug_pubtypes)
257   }
258   .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
259   {
260     *(.zdebug_pubtypes)
261   }
262
263   /* DWARF 2.  */
264   .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
265   {
266     *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
267   }
268   .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
269   {
270     *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
271   }
272
273   .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
274   {
275     *(.debug_abbrev)
276   }
277   .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
278   {
279     *(.zdebug_abbrev)
280   }
281
282   .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
283   {
284     *(.debug_line)
285   }
286   .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
287   {
288     *(.zdebug_line)
289   }
290
291   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
292   {
293     *(.debug_frame)
294   }
295   .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
296   {
297     *(.zdebug_frame)
298   }
299
300   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
301   {
302     *(.debug_str)
303   }
304   .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
305   {
306     *(.zdebug_str)
307   }
308
309   .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
310   {
311     *(.debug_loc)
312   }
313   .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
314   {
315     *(.zdebug_loc)
316   }
317
318   .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
319   {
320     *(.debug_macinfo)
321   }
322   .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
323   {
324     *(.zdebug_macinfo)
325   }
326
327   /* SGI/MIPS DWARF 2 extensions.  */
328   .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
329   {
330     *(.debug_weaknames)
331   }
332   .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
333   {
334     *(.zdebug_weaknames)
335   }
336
337   .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
338   {
339     *(.debug_funcnames)
340   }
341   .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
342   {
343     *(.zdebug_funcnames)
344   }
345
346   .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
347   {
348     *(.debug_typenames)
349   }
350   .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
351   {
352     *(.zdebug_typenames)
353   }
354
355   .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
356   {
357     *(.debug_varnames)
358   }
359   .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
360   {
361     *(.zdebug_varnames)
362   }
363
364   .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
365   {
366     *(.debug_macro)
367   }
368   .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
369   {
370     *(.zdebug_macro)
371   }
372
373   /* DWARF 3.  */
374   .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
375   {
376     *(.debug_ranges)
377   }
378   .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
379   {
380     *(.zdebug_ranges)
381   }
382
383   /* DWARF 4.  */
384   .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
385   {
386     *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
387   }
388   .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
389   {
390     *(.zdebug_types${RELOCATING+ .zdebug.gnu.linkonce.wt.*})
391   }
392 }
393 EOF