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