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