1 # Linker script for PE.
3 # Copyright (C) 2014-2024 Free Software Foundation, Inc.
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved.
9 if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
10 RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
13 # We can't easily and portably get an unquoted $ in a shell
14 # substitution, so we do this instead.
15 # Sorting of the .foo$* sections is required by the definition of
16 # grouped sections in PE.
17 # Sorting of the file names in R_IDATA is required by the
18 # current implementation of dlltool (this could probably be changed to
19 # use grouped sections instead).
20 if test "${RELOCATING}"; then
21 R_TEXT='*(SORT(.text$*))'
22 if test "x$LD_FLAG" = "xauto_import" ; then
23 R_DATA='*(SORT(.data$*))
28 R_DATA='*(SORT(.data$*))'
33 KEEP (SORT(*)(.idata$2))
34 KEEP (SORT(*)(.idata$3))
35 /* These zeroes mark the end of the import list. */
36 LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
38 KEEP (SORT(*)(.idata$4))'
39 R_IDATA5='SORT(*)(.idata$5)'
41 KEEP (SORT(*)(.idata$6))
42 KEEP (SORT(*)(.idata$7))'
43 R_CRT_XC='KEEP (*(SORT(.CRT$XC*))) /* C initialization */'
44 R_CRT_XI='KEEP (*(SORT(.CRT$XI*))) /* C++ initialization */'
45 R_CRT_XL='KEEP (*(SORT(.CRT$XL*))) /* TLS callbacks */'
46 R_CRT_XP='KEEP (*(SORT(.CRT$XP*))) /* Pre-termination */'
47 R_CRT_XT='KEEP (*(SORT(.CRT$XT*))) /* Termination */'
52 KEEP (*(SORT(.tls$*)))
74 /* Copyright (C) 2014-2024 Free Software Foundation, Inc.
76 Copying and distribution of this script, with or without modification,
77 are permitted in any medium without royalty provided the copyright
78 notice and this notice are preserved. */
80 ${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
81 ${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
82 ${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
88 ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
89 ${RELOCATING+ lower than the target page size. */}
90 ${RELOCATING+. = SIZEOF_HEADERS;}
91 ${RELOCATING+. = ALIGN(__section_alignment__);}
92 .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
94 ${RELOCATING+KEEP (*(SORT_NONE(.init)))}
97 ${RELOCATING+ *(.text.*)}
98 ${RELOCATING+ *(.gnu.linkonce.t.*)}
99 ${RELOCATING+*(.glue_7t)}
100 ${RELOCATING+*(.glue_7)}
101 ${CONSTRUCTING+. = ALIGN(8);}
103 /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
104 we do not PROVIDE them. This is because the ctors.o startup
105 code in libgcc defines them as common symbols, with the
106 expectation that they will be overridden by the definitions
107 here. If we PROVIDE the symbols then they will not be
108 overridden and global constructors will not be run.
109 See PR 22762 for more details.
111 This does mean that it is not possible for a user to define
112 their own __CTOR_LIST__ and __DTOR_LIST__ symbols; if they do,
113 the content from those variables are included but the symbols
114 defined here silently take precedence. If they truly need to
115 be redefined, a custom linker script will have to be used.
116 (The custom script can just be a copy of this script with the
117 PROVIDE() qualifiers added).
119 In particular this means that ld -Ur does not work, because
120 the proper __CTOR_LIST__ set by ld -Ur is overridden by a
121 bogus __CTOR_LIST__ set by the final link. See PR 46. */
124 LONG (-1); LONG (-1);
127 KEEP (*(SORT_BY_NAME(.ctors.*)));
131 /* See comment about __CTOR_LIST__ above. The same reasoning
135 LONG (-1); LONG (-1);
138 KEEP (*(SORT_BY_NAME(.dtors.*)));
141 ${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
142 ${RELOCATING+/* ??? Why is .gcc_exc here? */}
143 ${RELOCATING+ *(.gcc_exc)}
144 ${RELOCATING+PROVIDE (etext = .);}
145 ${RELOCATING+ KEEP (*(.gcc_except_table))}
148 /* The Cygwin32 library uses a section to avoid copying certain data
149 on fork. This used to be named ".data$nocopy". The linker used
150 to include this between __data_start__ and __data_end__, but that
151 breaks building the cygwin32 dll. Instead, we name the section
152 ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
154 .data ${RELOCATING+BLOCK(__section_alignment__)} :
156 ${RELOCATING+__data_start__ = . ;}
158 ${RELOCATING+*(.data2)}
161 ${RELOCATING+__data_end__ = . ;}
162 ${RELOCATING+*(.data_cygwin_nocopy)}
165 .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
169 ${RELOCATING+__rt_psrelocs_start = .;}
170 ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
171 ${RELOCATING+__rt_psrelocs_end = .;}
173 ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
174 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
175 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
176 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
177 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
179 .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
181 KEEP (*(.eh_frame${RELOCATING+*}))
184 .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
186 KEEP(*(.pdata${RELOCATING+*}))
189 .xdata ${RELOCATING+BLOCK(__section_alignment__)} :
191 KEEP(*(.xdata${RELOCATING+*}))
194 .bss ${RELOCATING+BLOCK(__section_alignment__)} :
196 ${RELOCATING+__bss_start__ = . ;}
199 ${RELOCATING+__bss_end__ = . ;}
202 .edata ${RELOCATING+BLOCK(__section_alignment__)} :
212 ${RELOCATING+ *(.drectve)}
213 ${RELOCATING+ *(.note.GNU-stack)}
214 ${RELOCATING+ *(.gnu.lto_*)}
217 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
219 /* This cannot currently be handled with grouped sections.
220 See pep.em:sort_sections. */
222 ${RELOCATING+__IAT_start__ = .;}
224 ${RELOCATING+__IAT_end__ = .;}
227 .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
229 ${RELOCATING+___crt_xc_start__ = . ;}
231 ${RELOCATING+___crt_xc_end__ = . ;}
232 ${RELOCATING+___crt_xi_start__ = . ;}
234 ${RELOCATING+___crt_xi_end__ = . ;}
235 ${RELOCATING+___crt_xl_start__ = . ;}
237 /* ___crt_xl_end__ is defined in the TLS Directory support code */
238 ${RELOCATING+___crt_xp_start__ = . ;}
240 ${RELOCATING+___crt_xp_end__ = . ;}
241 ${RELOCATING+___crt_xt_start__ = . ;}
243 ${RELOCATING+___crt_xt_end__ = . ;}
246 /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
247 at the end of the .tls section. This is important because _tls_start MUST
248 be at the beginning of the section to enable SECREL32 relocations with TLS
250 .tls ${RELOCATING+BLOCK(__section_alignment__)} :
252 ${RELOCATING+___tls_start__ = . ;}
254 ${RELOCATING+___tls_end__ = . ;}
257 .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
259 /* end is deprecated, don't use it */
260 ${RELOCATING+PROVIDE (end = .);}
261 ${RELOCATING+PROVIDE ( _end = .);}
262 ${RELOCATING+ __end__ = .;}
265 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
270 .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
275 .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
280 .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
285 /* DWARF debug sections.
286 Symbols in the DWARF debugging sections are relative to the beginning
287 of the section. Unlike other targets that fake this by putting the
288 section VMA at 0, the PE format will not allow it. */
290 /* DWARF 1.1 and DWARF 2. */
291 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
295 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
300 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
304 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
310 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
312 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
314 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
316 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
319 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
323 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
328 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
332 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
337 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
341 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
346 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
350 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
355 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
359 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
364 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
368 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
373 /* SGI/MIPS DWARF 2 extensions. */
374 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
378 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
383 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
387 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
392 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
396 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
401 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
405 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
411 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
415 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
420 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
424 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
430 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
432 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
434 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
436 *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*})
440 .debug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
444 .zdebug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
448 .debug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
452 .zdebug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
456 .debug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
460 .zdebug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
464 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
468 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
472 .debug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
476 .zdebug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
480 .debug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
484 .zdebug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
488 .debug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
490 *(.debug_str_offsets)
492 .zdebug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
494 *(.zdebug_str_offsets)
496 .debug_sup ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
501 /* For Go and Rust. */
502 .debug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
504 *(.debug_gdb_scripts)
506 .zdebug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
508 *(.zdebug_gdb_scripts)