1# $MirOS: src/gnu/usr.bin/binutils/ld/scripttempl/pe.sc,v 1.3 2009/10/04 03:03:05 tg Exp $
2#
3# Linker script for PE.
4
5if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
6  RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
7fi
8
9# We can't easily and portably get an unquoted $ in a shell
10# substitution, so we do this instead.
11# Sorting of the .foo$* sections is required by the definition of
12# grouped sections in PE.
13# Sorting of the file names in R_IDATA is required by the
14# current implementation of dlltool (this could probably be changed to
15# use grouped sections instead).
16if test "${RELOCATING}"; then
17  R_TEXT='*(SORT(.text$*))'
18  R_DATA='*(SORT(.data$*))'
19  R_RDATA='*(SORT(.rdata$*))'
20  R_IDATA='
21    SORT(*)(.idata$2)
22    SORT(*)(.idata$3)
23    /* These zeroes mark the end of the import list.  */
24    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
25    SORT(*)(.idata$4)
26    SORT(*)(.idata$5)
27    SORT(*)(.idata$6)
28    SORT(*)(.idata$7)'
29  R_CRT_XC='*(SORT(.CRT$XC*))  /* C initialization */'
30  R_CRT_XI='*(SORT(.CRT$XI*))  /* C++ initialization */'
31  R_CRT_XL='*(SORT(.CRT$XL*))  /* TLS callbacks */'
32  R_CRT_XP='*(SORT(.CRT$XP*))  /* Pre-termination */'
33  R_CRT_XT='*(SORT(.CRT$XT*))  /* Termination */'
34  R_TLS='
35    *(.tls)
36    *(.tls$)
37    *(SORT(.tls$*))'
38  R_RSRC='*(SORT(.rsrc$*))'
39else
40  R_TEXT=
41  R_DATA=
42  R_RDATA=
43  R_IDATA=
44  R_CRT=
45  R_RSRC=
46fi
47
48cat <<EOF
49${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
50${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
51${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
52
53${LIB_SEARCH_DIRS}
54
55ENTRY(${ENTRY})
56
57SECTIONS
58{
59  ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
60  ${RELOCATING+   lower than the target page size. */}
61  ${RELOCATING+. = SIZEOF_HEADERS;}
62  ${RELOCATING+. = ALIGN(__section_alignment__);}
63  .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
64  {
65    ${RELOCATING+ *(.init)}
66    *(.text)
67    ${R_TEXT}
68    *(.glue_7t)
69    *(.glue_7)
70    ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
71			LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0); }
72    ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
73			LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0); }
74    ${RELOCATING+ *(.fini)}
75    /* ??? Why is .gcc_exc here?  */
76    ${RELOCATING+ *(.gcc_exc)}
77    ${RELOCATING+PROVIDE (etext = .);}
78    *(.gcc_except_table)
79  }
80
81  /* The Cygwin32 library uses a section to avoid copying certain data
82     on fork.  This used to be named ".data\$nocopy".  The linker used
83     to include this between __data_start__ and __data_end__, but that
84     breaks building the cygwin32 dll.  Instead, we name the section
85     ".data_cygwin_nocopy" and explictly include it after __data_end__. */
86
87  .data ${RELOCATING+BLOCK(__section_alignment__)} :
88  {
89    ${RELOCATING+__data_start__ = . ;}
90    *(.data)
91    *(.data2)
92    ${R_DATA}
93    *(.jcr)
94    ${RELOCATING+__data_end__ = . ;}
95    ${RELOCATING+*(.data_cygwin_nocopy)}
96  }
97
98  .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
99  {
100    *(.rdata)
101    ${R_RDATA}
102    *(.eh_frame)
103    ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = .;}
104    ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = .;}
105    *(.rdata_runtime_pseudo_reloc)
106    ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
107    ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
108  }
109
110  .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
111  {
112    *(.pdata)
113  }
114
115  .bss ${RELOCATING+BLOCK(__section_alignment__)} :
116  {
117    ${RELOCATING+__bss_start__ = . ;}
118    *(.bss)
119    *(COMMON)
120    ${RELOCATING+__bss_end__ = . ;}
121  }
122
123  .edata ${RELOCATING+BLOCK(__section_alignment__)} :
124  {
125    *(.edata)
126  }
127
128  /DISCARD/ :
129  {
130    *(.debug\$S)
131    *(.debug\$T)
132    *(.debug\$F)
133    *(.drectve)
134  }
135
136  .idata ${RELOCATING+BLOCK(__section_alignment__)} :
137  {
138    /* This cannot currently be handled with grouped sections.
139	See pe.em:sort_sections.  */
140    ${R_IDATA}
141  }
142  .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
143  {
144    ${RELOCATING+___crt_xc_start__ = . ;}
145    ${R_CRT_XC}
146    ${RELOCATING+___crt_xc_end__ = . ;}
147    ${RELOCATING+___crt_xi_start__ = . ;}
148    ${R_CRT_XI}
149    ${RELOCATING+___crt_xi_end__ = . ;}
150    ${RELOCATING+___crt_xl_start__ = . ;}
151    ${R_CRT_XL}
152    /* ___crt_xl_end__ is defined in the TLS Directory support code */
153    ${RELOCATING+___crt_xp_start__ = . ;}
154    ${R_CRT_XP}
155    ${RELOCATING+___crt_xp_end__ = . ;}
156    ${RELOCATING+___crt_xt_start__ = . ;}
157    ${R_CRT_XT}
158    ${RELOCATING+___crt_xt_end__ = . ;}
159  }
160
161  .tls ${RELOCATING+BLOCK(__section_alignment__)} :
162  {
163    ${RELOCATING+___tls_start__ = . ;}
164    ${R_TLS}
165    ${RELOCATING+___tls_end__ = . ;}
166  }
167
168  .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
169  {
170    /* end is deprecated, don't use it */
171    ${RELOCATING+PROVIDE (end = .);}
172    ${RELOCATING+PROVIDE ( _end = .);}
173    ${RELOCATING+ __end__ = .;}
174  }
175
176  .rsrc ${RELOCATING+BLOCK(__section_alignment__)} :
177  {
178    *(.rsrc)
179    ${R_RSRC}
180  }
181
182  .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
183  {
184    *(.reloc)
185  }
186
187  .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
188  {
189    *(.stab)
190  }
191
192  .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
193  {
194    *(.stabstr)
195  }
196
197  /* DWARF debug sections.
198     Symbols in the DWARF debugging sections are relative to the beginning
199     of the section.  Unlike other targets that fake this by putting the
200     section VMA at 0, the PE format will not allow it.  */
201
202  /* DWARF 1.1 and DWARF 2.  */
203  .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
204  {
205    *(.debug_aranges)
206  }
207
208  .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
209  {
210    *(.debug_pubnames)
211  }
212
213  /* DWARF 2.  */
214  .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
215  {
216    *(.debug_info) *(.gnu.linkonce.wi.*)
217  }
218
219  .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
220  {
221    *(.debug_abbrev)
222  }
223
224  .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
225  {
226    *(.debug_line)
227  }
228
229  .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
230  {
231    *(.debug_frame)
232  }
233
234  .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
235  {
236    *(.debug_str)
237  }
238
239  .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
240  {
241    *(.debug_loc)
242  }
243
244  .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
245  {
246    *(.debug_macinfo)
247  }
248
249  /* SGI/MIPS DWARF 2 extensions.  */
250  .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
251  {
252    *(.debug_weaknames)
253  }
254
255  .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
256  {
257    *(.debug_funcnames)
258  }
259
260  .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
261  {
262    *(.debug_typenames)
263  }
264
265  .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
266  {
267    *(.debug_varnames)
268  }
269
270  /* DWARF 3.  */
271  .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+\(NOLOAD\)} :
272  {
273    *(.debug_ranges)
274  }
275}
276EOF
277