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);
37 KEEP (SORT(*)(.idata$4))'
38 R_IDATA5='KEEP (SORT(*)(.idata$5))'
40 KEEP (SORT(*)(.idata$6))
41 KEEP (SORT(*)(.idata$7))'
42 R_CRT_XC='KEEP (*(SORT(.CRT$XC*))) /* C initialization */'
43 R_CRT_XI='KEEP (*(SORT(.CRT$XI*))) /* C++ initialization */'
44 R_CRT_XL='KEEP (*(SORT(.CRT$XL*))) /* TLS callbacks */'
45 R_CRT_XP='KEEP (*(SORT(.CRT$XP*))) /* Pre-termination */'
46 R_CRT_XT='KEEP (*(SORT(.CRT$XT*))) /* Termination */'
51 KEEP (*(SORT(.tls$*)))
73 /* Copyright (C) 2014-2024 Free Software Foundation, Inc.
75 Copying and distribution of this script, with or without modification,
76 are permitted in any medium without royalty provided the copyright
77 notice and this notice are preserved. */
79 ${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
80 ${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
81 ${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
87 ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
88 ${RELOCATING+ lower than the target page size. */}
89 ${RELOCATING+. = SIZEOF_HEADERS;}
90 ${RELOCATING+. = ALIGN(__section_alignment__);}
91 .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
93 ${RELOCATING+KEEP (*(SORT_NONE(.init)))}
96 ${RELOCATING+ *(.text.*)}
97 ${RELOCATING+ *(.gnu.linkonce.t.*)}
98 ${RELOCATING+*(.glue_7t)}
99 ${RELOCATING+*(.glue_7)}
101 /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
102 we do not PROVIDE them. This is because the ctors.o startup
103 code in libgcc defines them as common symbols, with the
104 expectation that they will be overridden by the definitions
105 here. If we PROVIDE the symbols then they will not be
106 overridden and global constructors will not be run.
107 See PR 22762 for more details.
109 This does mean that it is not possible for a user to define
110 their own __CTOR_LIST__ and __DTOR_LIST__ symbols; if they do,
111 the content from those variables are included but the symbols
112 defined here silently take precedence. If they truly need to
113 be redefined, a custom linker script will have to be used.
114 (The custom script can just be a copy of this script with the
115 PROVIDE() qualifiers added).
117 In particular this means that ld -Ur does not work, because
118 the proper __CTOR_LIST__ set by ld -Ur is overridden by a
119 bogus __CTOR_LIST__ set by the final link. See PR 46. */
125 KEEP(*(SORT_BY_NAME(.ctors.*)));
129 /* See comment about __CTOR_LIST__ above. The same reasoning
136 KEEP(*(SORT_BY_NAME(.dtors.*)));
139 ${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
140 ${RELOCATING+/* ??? Why is .gcc_exc here? */}
141 ${RELOCATING+ *(.gcc_exc)}
142 ${RELOCATING+PROVIDE (etext = .);}
143 ${RELOCATING+PROVIDE (_etext = .);}
144 ${RELOCATING+ KEEP (*(.gcc_except_table))}
147 /* The Cygwin32 library uses a section to avoid copying certain data
148 on fork. This used to be named ".data$nocopy". The linker used
149 to include this between __data_start__ and __data_end__, but that
150 breaks building the cygwin32 dll. Instead, we name the section
151 ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
153 .data ${RELOCATING+BLOCK(__section_alignment__)} :
155 ${RELOCATING+__data_start__ = . ;}
157 ${RELOCATING+*(.data2)}
160 ${RELOCATING+__data_end__ = . ;}
161 ${RELOCATING+*(.data_cygwin_nocopy)}
164 .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
168 ${RELOCATING+__rt_psrelocs_start = .;}
169 ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
170 ${RELOCATING+__rt_psrelocs_end = .;}
172 ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
173 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
174 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
175 ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
176 ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
178 .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
180 KEEP(*(.eh_frame${RELOCATING+*}))
183 .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
185 KEEP(*(.pdata${RELOCATING+*}))
188 .bss ${RELOCATING+BLOCK(__section_alignment__)} :
190 ${RELOCATING+__bss_start__ = . ;}
193 ${RELOCATING+__bss_end__ = . ;}
196 .edata ${RELOCATING+BLOCK(__section_alignment__)} :
206 ${RELOCATING+ *(.drectve)}
207 ${RELOCATING+ *(.note.GNU-stack)}
208 ${RELOCATING+ *(.gnu.lto_*)}
211 .idata ${RELOCATING+BLOCK(__section_alignment__)} :
213 /* This cannot currently be handled with grouped sections.
214 See pe.em:sort_sections. */
216 ${RELOCATING+__IAT_start__ = .;}
218 ${RELOCATING+__IAT_end__ = .;}
221 .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
223 ${RELOCATING+___crt_xc_start__ = . ;}
225 ${RELOCATING+___crt_xc_end__ = . ;}
226 ${RELOCATING+___crt_xi_start__ = . ;}
228 ${RELOCATING+___crt_xi_end__ = . ;}
229 ${RELOCATING+___crt_xl_start__ = . ;}
231 /* ___crt_xl_end__ is defined in the TLS Directory support code */
232 ${RELOCATING+___crt_xp_start__ = . ;}
234 ${RELOCATING+___crt_xp_end__ = . ;}
235 ${RELOCATING+___crt_xt_start__ = . ;}
237 ${RELOCATING+___crt_xt_end__ = . ;}
240 /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
241 at the end of section. This is important because _tls_start MUST
242 be at the beginning of the section to enable SECREL32 relocations with TLS
244 .tls ${RELOCATING+BLOCK(__section_alignment__)} :
246 ${RELOCATING+___tls_start__ = . ;}
248 ${RELOCATING+___tls_end__ = . ;}
251 .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
253 /* end is deprecated, don't use it */
254 ${RELOCATING+PROVIDE (end = .);}
255 ${RELOCATING+PROVIDE ( _end = .);}
256 ${RELOCATING+ __end__ = .;}
259 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
264 .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
269 .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
274 .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
279 /* DWARF debug sections.
280 Symbols in the DWARF debugging sections are relative to the beginning
281 of the section. Unlike other targets that fake this by putting the
282 section VMA at 0, the PE format will not allow it. */
284 /* DWARF 1.1 and DWARF 2. */
285 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
289 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
294 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
298 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
304 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
306 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
308 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
310 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
313 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
317 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
322 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
326 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
331 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
335 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
340 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
344 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
349 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
353 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
358 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
362 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
367 /* SGI/MIPS DWARF 2 extensions. */
368 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
372 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
377 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
381 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
386 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
390 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
395 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
399 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
405 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
409 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
414 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
418 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
424 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
426 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
428 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
430 *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*})
434 .debug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
438 .zdebug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
442 .debug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
446 .zdebug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
450 .debug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
454 .zdebug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
458 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
462 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
466 .debug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
470 .zdebug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
474 .debug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
478 .zdebug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
482 .debug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
484 *(.debug_str_offsets)
486 .zdebug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
488 *(.zdebug_str_offsets)
490 .debug_sup ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
495 /* For Go and Rust. */
496 .debug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
498 *(.debug_gdb_scripts)
500 .zdebug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
502 *(.zdebug_gdb_scripts)