1# Linker script for PE. 2# 3# Copyright (C) 2014-2022 Free Software Foundation, Inc. 4# 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. 8 9if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then 10 RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT} 11fi 12 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). 20if test "${RELOCATING}"; then 21 R_TEXT='*(SORT(.text$*))' 22 if test "x$LD_FLAG" = "xauto_import" ; then 23 R_DATA='*(SORT(.data$*)) 24 *(.rdata) 25 *(SORT(.rdata$*))' 26 R_RDATA='' 27 else 28 R_DATA='*(SORT(.data$*))' 29 R_RDATA='*(.rdata) 30 *(SORT(.rdata$*))' 31 fi 32 R_IDATA234=' 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))' 39 R_IDATA67=' 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 */' 47 R_TLS=' 48 KEEP (*(.tls$AAA)) 49 KEEP (*(.tls)) 50 KEEP (*(.tls$)) 51 KEEP (*(SORT(.tls$*))) 52 KEEP (*(.tls$ZZZ))' 53 R_RSRC=' 54 KEEP (*(.rsrc)) 55 KEEP (*(.rsrc$*))' 56else 57 R_TEXT= 58 R_DATA= 59 R_RDATA='*(.rdata)' 60 R_IDATA234= 61 R_IDATA5= 62 R_IDATA67= 63 R_CRT_XC= 64 R_CRT_XI= 65 R_CRT_XL= 66 R_CRT_XP= 67 R_CRT_XT= 68 R_TLS='*(.tls)' 69 R_RSRC='*(.rsrc)' 70fi 71 72cat <<EOF 73/* Copyright (C) 2014-2022 Free Software Foundation, Inc. 74 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. */ 78 79${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})} 80${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})} 81${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})} 82 83${LIB_SEARCH_DIRS} 84 85SECTIONS 86{ 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__ )} : 92 { 93 ${RELOCATING+KEEP (*(SORT_NONE(.init)))} 94 *(.text) 95 ${R_TEXT} 96 ${RELOCATING+ *(.text.*)} 97 ${RELOCATING+ *(.gnu.linkonce.t.*)} 98 ${RELOCATING+*(.glue_7t)} 99 ${RELOCATING+*(.glue_7)} 100 ${CONSTRUCTING+ 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. 108 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). 116 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. */ 120 ___CTOR_LIST__ = .; 121 __CTOR_LIST__ = .; 122 LONG (-1); 123 KEEP(*(.ctors)); 124 KEEP(*(.ctor)); 125 KEEP(*(SORT_BY_NAME(.ctors.*))); 126 LONG (0); 127 } 128 ${CONSTRUCTING+ 129 /* See comment about __CTOR_LIST__ above. The same reasoning 130 applies here too. */ 131 ___DTOR_LIST__ = .; 132 __DTOR_LIST__ = .; 133 LONG (-1); 134 KEEP(*(.dtors)); 135 KEEP(*(.dtor)); 136 KEEP(*(SORT_BY_NAME(.dtors.*))); 137 LONG (0); 138 } 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))} 145 } 146 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__. */ 152 153 .data ${RELOCATING+BLOCK(__section_alignment__)} : 154 { 155 ${RELOCATING+__data_start__ = . ;} 156 *(.data) 157 ${RELOCATING+*(.data2)} 158 ${R_DATA} 159 KEEP(*(.jcr)) 160 ${RELOCATING+__data_end__ = . ;} 161 ${RELOCATING+*(.data_cygwin_nocopy)} 162 } 163 164 .rdata ${RELOCATING+BLOCK(__section_alignment__)} : 165 { 166 ${R_RDATA} 167 . = ALIGN(4); 168 ${RELOCATING+__rt_psrelocs_start = .;} 169 ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))} 170 ${RELOCATING+__rt_psrelocs_end = .;} 171 } 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;} 177 178 .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} : 179 { 180 KEEP(*(.eh_frame${RELOCATING+*})) 181 } 182 183 .pdata ${RELOCATING+BLOCK(__section_alignment__)} : 184 { 185 KEEP(*(.pdata${RELOCATING+*})) 186 } 187 188 .bss ${RELOCATING+BLOCK(__section_alignment__)} : 189 { 190 ${RELOCATING+__bss_start__ = . ;} 191 *(.bss) 192 *(COMMON) 193 ${RELOCATING+__bss_end__ = . ;} 194 } 195 196 .edata ${RELOCATING+BLOCK(__section_alignment__)} : 197 { 198 *(.edata) 199 } 200 201 /DISCARD/ : 202 { 203 *(.debug\$S) 204 *(.debug\$T) 205 *(.debug\$F) 206 *(.drectve) 207 ${RELOCATING+ *(.note.GNU-stack)} 208 ${RELOCATING+ *(.gnu.lto_*)} 209 } 210 211 .idata ${RELOCATING+BLOCK(__section_alignment__)} : 212 { 213 /* This cannot currently be handled with grouped sections. 214 See pe.em:sort_sections. */ 215 ${R_IDATA234} 216 ${RELOCATING+__IAT_start__ = .;} 217 ${R_IDATA5} 218 ${RELOCATING+__IAT_end__ = .;} 219 ${R_IDATA67} 220 } 221 .CRT ${RELOCATING+BLOCK(__section_alignment__)} : 222 { 223 ${RELOCATING+___crt_xc_start__ = . ;} 224 ${R_CRT_XC} 225 ${RELOCATING+___crt_xc_end__ = . ;} 226 ${RELOCATING+___crt_xi_start__ = . ;} 227 ${R_CRT_XI} 228 ${RELOCATING+___crt_xi_end__ = . ;} 229 ${RELOCATING+___crt_xl_start__ = . ;} 230 ${R_CRT_XL} 231 /* ___crt_xl_end__ is defined in the TLS Directory support code */ 232 ${RELOCATING+___crt_xp_start__ = . ;} 233 ${R_CRT_XP} 234 ${RELOCATING+___crt_xp_end__ = . ;} 235 ${RELOCATING+___crt_xt_start__ = . ;} 236 ${R_CRT_XT} 237 ${RELOCATING+___crt_xt_end__ = . ;} 238 } 239 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 243 data. */ 244 .tls ${RELOCATING+BLOCK(__section_alignment__)} : 245 { 246 ${RELOCATING+___tls_start__ = . ;} 247 ${R_TLS} 248 ${RELOCATING+___tls_end__ = . ;} 249 } 250 251 .endjunk ${RELOCATING+BLOCK(__section_alignment__)} : 252 { 253 /* end is deprecated, don't use it */ 254 ${RELOCATING+PROVIDE (end = .);} 255 ${RELOCATING+PROVIDE ( _end = .);} 256 ${RELOCATING+ __end__ = .;} 257 } 258 259 .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4) 260 { 261 ${R_RSRC} 262 } 263 264 .reloc ${RELOCATING+BLOCK(__section_alignment__)} : 265 { 266 *(.reloc) 267 } 268 269 .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 270 { 271 *(.stab) 272 } 273 274 .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 275 { 276 *(.stabstr) 277 } 278 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. */ 283 284 /* DWARF 1.1 and DWARF 2. */ 285 .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 286 { 287 *(.debug_aranges) 288 } 289 .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 290 { 291 *(.zdebug_aranges) 292 } 293 294 .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 295 { 296 *(.debug_pubnames) 297 } 298 .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 299 { 300 *(.zdebug_pubnames) 301 } 302 303 /* DWARF 2. */ 304 .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 305 { 306 *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) 307 } 308 .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 309 { 310 *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*}) 311 } 312 313 .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 314 { 315 *(.debug_abbrev) 316 } 317 .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 318 { 319 *(.zdebug_abbrev) 320 } 321 322 .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 323 { 324 *(.debug_line) 325 } 326 .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 327 { 328 *(.zdebug_line) 329 } 330 331 .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 332 { 333 *(.debug_frame*) 334 } 335 .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 336 { 337 *(.zdebug_frame*) 338 } 339 340 .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 341 { 342 *(.debug_str) 343 } 344 .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 345 { 346 *(.zdebug_str) 347 } 348 349 .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 350 { 351 *(.debug_loc) 352 } 353 .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 354 { 355 *(.zdebug_loc) 356 } 357 358 .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 359 { 360 *(.debug_macinfo) 361 } 362 .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 363 { 364 *(.zdebug_macinfo) 365 } 366 367 /* SGI/MIPS DWARF 2 extensions. */ 368 .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 369 { 370 *(.debug_weaknames) 371 } 372 .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 373 { 374 *(.zdebug_weaknames) 375 } 376 377 .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 378 { 379 *(.debug_funcnames) 380 } 381 .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 382 { 383 *(.zdebug_funcnames) 384 } 385 386 .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 387 { 388 *(.debug_typenames) 389 } 390 .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 391 { 392 *(.zdebug_typenames) 393 } 394 395 .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 396 { 397 *(.debug_varnames) 398 } 399 .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 400 { 401 *(.zdebug_varnames) 402 } 403 404 /* DWARF 3. */ 405 .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 406 { 407 *(.debug_pubtypes) 408 } 409 .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 410 { 411 *(.zdebug_pubtypes) 412 } 413 414 .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 415 { 416 *(.debug_ranges) 417 } 418 .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 419 { 420 *(.zdebug_ranges) 421 } 422 423 /* DWARF 4. */ 424 .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 425 { 426 *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*}) 427 } 428 .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 429 { 430 *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*}) 431 } 432 433 /* DWARF 5. */ 434 .debug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 435 { 436 *(.debug_addr) 437 } 438 .zdebug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 439 { 440 *(.zdebug_addr) 441 } 442 .debug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 443 { 444 *(.debug_line_str) 445 } 446 .zdebug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 447 { 448 *(.zdebug_line_str) 449 } 450 .debug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 451 { 452 *(.debug_loclists) 453 } 454 .zdebug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 455 { 456 *(.zdebug_loclists) 457 } 458 .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 459 { 460 *(.debug_macro) 461 } 462 .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 463 { 464 *(.zdebug_macro) 465 } 466 .debug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 467 { 468 *(.debug_names) 469 } 470 .zdebug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 471 { 472 *(.zdebug_names) 473 } 474 .debug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 475 { 476 *(.debug_rnglists) 477 } 478 .zdebug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 479 { 480 *(.zdebug_rnglists) 481 } 482 .debug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 483 { 484 *(.debug_str_offsets) 485 } 486 .zdebug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 487 { 488 *(.zdebug_str_offsets) 489 } 490 .debug_sup ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 491 { 492 *(.debug_sup) 493 } 494 495 /* For Go and Rust. */ 496 .debug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 497 { 498 *(.debug_gdb_scripts) 499 } 500 .zdebug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} : 501 { 502 *(.zdebug_gdb_scripts) 503 } 504} 505EOF 506