]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/scripttempl/pep.sc
Add support for generating and inserting build IDs into COFF binaries.
[thirdparty/binutils-gdb.git] / ld / scripttempl / pep.sc
CommitLineData
99ad8390
NC
1# Linker script for PE.
2
3if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
4 RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
5fi
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).
14if test "${RELOCATING}"; then
15 R_TEXT='*(SORT(.text$*))'
e2a83dd0
NC
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
d4874973 26 R_IDATA234='
99ad8390
NC
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);
d4874973
KT
31 SORT(*)(.idata$4)'
32 R_IDATA5='SORT(*)(.idata$5)'
33 R_IDATA67='
99ad8390
NC
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='
5063daf7 42 *(.tls$AAA)
99ad8390
NC
43 *(.tls)
44 *(.tls$)
a988325c
NC
45 *(SORT(.tls$*))
46 *(.tls$ZZZ)'
5063daf7
NC
47 if test -z "$DEFAULT_MANIFEST"; then
48 R_RSRC='
49 *(.rsrc)
6caf7111 50 *(.rsrc$*)'
5063daf7
NC
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
6caf7111
NC
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. */
1d63324c 60 *(EXCLUDE_FILE (*$DEFAULT_MANIFEST) .rsrc)
6caf7111 61 *(.rsrc*)
5063daf7
NC
62 KEEP ($DEFAULT_MANIFEST(.rsrc))"
63 fi
99ad8390
NC
64else
65 R_TEXT=
66 R_DATA=
e2a83dd0 67 R_RDATA='*(.rdata)'
d4874973
KT
68 R_IDATA234=
69 R_IDATA5=
70 R_IDATA67=
99ad8390 71 R_CRT=
5063daf7 72 R_RSRC='*(.rsrc)'
99ad8390
NC
73fi
74
75cat <<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
82SECTIONS
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__);}
5063daf7 88 .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
99ad8390
NC
89 {
90 ${RELOCATING+ *(.init)}
91 *(.text)
92 ${R_TEXT}
032f3e01 93 ${RELOCATING+ *(.text.*)}
ebe9c501 94 ${RELOCATING+ *(.gnu.linkonce.t.*)}
99ad8390
NC
95 *(.glue_7t)
96 *(.glue_7)
da6fa31a 97 ${CONSTRUCTING+. = ALIGN(8);}
5063daf7 98 ${CONSTRUCTING+ ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
9b996610 99 LONG (-1); LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0); LONG (0); }
5063daf7 100 ${CONSTRUCTING+ ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
9b996610 101 LONG (-1); LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0); LONG (0); }
99ad8390
NC
102 ${RELOCATING+ *(.fini)}
103 /* ??? Why is .gcc_exc here? */
104 ${RELOCATING+ *(.gcc_exc)}
105 ${RELOCATING+PROVIDE (etext = .);}
5f294ed6 106 ${RELOCATING+ *(.gcc_except_table)}
99ad8390
NC
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
cc643b88 113 ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
99ad8390 114
5063daf7 115 .data ${RELOCATING+BLOCK(__section_alignment__)} :
99ad8390
NC
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 {
99ad8390 128 ${R_RDATA}
730035f7 129 ${RELOCATING+__rt_psrelocs_start = .;}
99ad8390 130 *(.rdata_runtime_pseudo_reloc)
730035f7 131 ${RELOCATING+__rt_psrelocs_end = .;}
99ad8390 132 }
730035f7
DK
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;}
99ad8390 138
27505b5d
TG
139 .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
140 {
72b016b4 141 *(.eh_frame*)
27505b5d
TG
142 }
143
99ad8390
NC
144 .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
145 {
b138e9bf 146 *(.pdata*)
2d7f4929
KT
147 }
148
149 .xdata ${RELOCATING+BLOCK(__section_alignment__)} :
150 {
b138e9bf 151 *(.xdata*)
99ad8390
NC
152 }
153
154 .bss ${RELOCATING+BLOCK(__section_alignment__)} :
155 {
156 ${RELOCATING+__bss_start__ = . ;}
157 *(.bss)
158 *(COMMON)
159 ${RELOCATING+__bss_end__ = . ;}
160 }
161
162 .edata ${RELOCATING+BLOCK(__section_alignment__)} :
163 {
164 *(.edata)
165 }
166
167 /DISCARD/ :
168 {
169 *(.debug\$S)
170 *(.debug\$T)
171 *(.debug\$F)
172 *(.drectve)
fecc36fd
KT
173 ${RELOCATING+ *(.note.GNU-stack)}
174 ${RELOCATING+ *(.gnu.lto_*)}
99ad8390
NC
175 }
176
177 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
178 {
179 /* This cannot currently be handled with grouped sections.
180 See pep.em:sort_sections. */
d4874973
KT
181 ${R_IDATA234}
182 ${RELOCATING+__IAT_start__ = .;}
183 ${R_IDATA5}
184 ${RELOCATING+__IAT_end__ = .;}
185 ${R_IDATA67}
99ad8390
NC
186 }
187 .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
188 {
189 ${RELOCATING+___crt_xc_start__ = . ;}
190 ${R_CRT_XC}
191 ${RELOCATING+___crt_xc_end__ = . ;}
192 ${RELOCATING+___crt_xi_start__ = . ;}
193 ${R_CRT_XI}
194 ${RELOCATING+___crt_xi_end__ = . ;}
195 ${RELOCATING+___crt_xl_start__ = . ;}
196 ${R_CRT_XL}
197 /* ___crt_xl_end__ is defined in the TLS Directory support code */
198 ${RELOCATING+___crt_xp_start__ = . ;}
199 ${R_CRT_XP}
200 ${RELOCATING+___crt_xp_end__ = . ;}
201 ${RELOCATING+___crt_xt_start__ = . ;}
202 ${R_CRT_XT}
203 ${RELOCATING+___crt_xt_end__ = . ;}
204 }
205
a988325c
NC
206 /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
207 at the end of the .tls section. This is important because _tls_start MUST
208 be at the beginning of the section to enable SECREL32 relocations with TLS
209 data. */
99ad8390
NC
210 .tls ${RELOCATING+BLOCK(__section_alignment__)} :
211 {
212 ${RELOCATING+___tls_start__ = . ;}
213 ${R_TLS}
214 ${RELOCATING+___tls_end__ = . ;}
215 }
216
217 .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
218 {
219 /* end is deprecated, don't use it */
220 ${RELOCATING+PROVIDE (end = .);}
221 ${RELOCATING+PROVIDE ( _end = .);}
222 ${RELOCATING+ __end__ = .;}
223 }
224
1d63324c 225 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
5063daf7 226 {
99ad8390
NC
227 ${R_RSRC}
228 }
229
230 .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
5063daf7 231 {
99ad8390
NC
232 *(.reloc)
233 }
234
235 .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
236 {
237 *(.stab)
238 }
239
240 .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
241 {
242 *(.stabstr)
243 }
244
245 /* DWARF debug sections.
246 Symbols in the DWARF debugging sections are relative to the beginning
247 of the section. Unlike other targets that fake this by putting the
248 section VMA at 0, the PE format will not allow it. */
5063daf7 249
99ad8390
NC
250 /* DWARF 1.1 and DWARF 2. */
251 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
252 {
253 *(.debug_aranges)
254 }
a29a8af8
KT
255 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
256 {
257 *(.zdebug_aranges)
258 }
99ad8390
NC
259
260 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
261 {
262 *(.debug_pubnames)
263 }
a29a8af8
KT
264 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
265 {
266 *(.zdebug_pubnames)
267 }
99ad8390 268
22418005 269 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
a626fe20
KT
270 {
271 *(.debug_pubtypes)
272 }
a29a8af8
KT
273 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
274 {
275 *(.zdebug_pubtypes)
276 }
a626fe20 277
99ad8390
NC
278 /* DWARF 2. */
279 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
280 {
ebe9c501 281 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
99ad8390 282 }
a29a8af8
KT
283 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
284 {
285 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
286 }
99ad8390
NC
287
288 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
289 {
290 *(.debug_abbrev)
291 }
a29a8af8
KT
292 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
293 {
294 *(.zdebug_abbrev)
295 }
99ad8390
NC
296
297 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
298 {
299 *(.debug_line)
300 }
a29a8af8
KT
301 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
302 {
303 *(.zdebug_line)
304 }
99ad8390
NC
305
306 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
307 {
f5c66ab0 308 *(.debug_frame)
99ad8390 309 }
a29a8af8
KT
310 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
311 {
f5c66ab0 312 *(.zdebug_frame)
a29a8af8 313 }
99ad8390
NC
314
315 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
316 {
317 *(.debug_str)
318 }
a29a8af8
KT
319 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
320 {
321 *(.zdebug_str)
322 }
99ad8390
NC
323
324 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
325 {
326 *(.debug_loc)
327 }
a29a8af8
KT
328 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
329 {
330 *(.zdebug_loc)
331 }
99ad8390
NC
332
333 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
334 {
335 *(.debug_macinfo)
336 }
a29a8af8
KT
337 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
338 {
339 *(.zdebug_macinfo)
340 }
99ad8390
NC
341
342 /* SGI/MIPS DWARF 2 extensions. */
343 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
344 {
345 *(.debug_weaknames)
346 }
a29a8af8
KT
347 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
348 {
349 *(.zdebug_weaknames)
350 }
99ad8390
NC
351
352 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
353 {
354 *(.debug_funcnames)
355 }
a29a8af8
KT
356 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
357 {
358 *(.zdebug_funcnames)
359 }
99ad8390
NC
360
361 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
362 {
363 *(.debug_typenames)
364 }
a29a8af8
KT
365 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
366 {
367 *(.zdebug_typenames)
368 }
99ad8390
NC
369
370 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
371 {
372 *(.debug_varnames)
373 }
a29a8af8
KT
374 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
375 {
376 *(.zdebug_varnames)
377 }
99ad8390 378
b990ad61
KT
379 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
380 {
381 *(.debug_macro)
382 }
a29a8af8
KT
383 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
384 {
385 *(.zdebug_macro)
386 }
b990ad61 387
99ad8390
NC
388 /* DWARF 3. */
389 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
390 {
391 *(.debug_ranges)
392 }
a29a8af8
KT
393 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
394 {
395 *(.zdebug_ranges)
396 }
802d4822
KT
397
398 /* DWARF 4. */
399 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
400 {
ebe9c501 401 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
802d4822 402 }
a29a8af8
KT
403 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
404 {
405 *(.zdebug_types${RELOCATING+ .zdebug.gnu.linkonce.wt.*})
406 }
99ad8390
NC
407}
408EOF