pep.sc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
  9. RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  10. fi
  11. # We can't easily and portably get an unquoted $ in a shell
  12. # substitution, so we do this instead.
  13. # Sorting of the .foo$* sections is required by the definition of
  14. # grouped sections in PE.
  15. # Sorting of the file names in R_IDATA is required by the
  16. # current implementation of dlltool (this could probably be changed to
  17. # use grouped sections instead).
  18. if test "${RELOCATING}"; then
  19. R_TEXT='*(SORT(.text$*))'
  20. if test "x$LD_FLAG" = "xauto_import" ; then
  21. R_DATA='*(SORT(.data$*))
  22. *(.rdata)
  23. *(SORT(.rdata$*))'
  24. R_RDATA=''
  25. else
  26. R_DATA='*(SORT(.data$*))'
  27. R_RDATA='*(.rdata)
  28. *(SORT(.rdata$*))'
  29. fi
  30. R_IDATA234='
  31. KEEP (SORT(*)(.idata$2))
  32. KEEP (SORT(*)(.idata$3))
  33. /* These zeroes mark the end of the import list. */
  34. LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
  35. KEEP (SORT(*)(.idata$4))'
  36. R_IDATA5='SORT(*)(.idata$5)'
  37. R_IDATA67='
  38. KEEP (SORT(*)(.idata$6))
  39. KEEP (SORT(*)(.idata$7))'
  40. R_CRT_XC='KEEP (*(SORT(.CRT$XC*))) /* C initialization */'
  41. R_CRT_XI='KEEP (*(SORT(.CRT$XI*))) /* C++ initialization */'
  42. R_CRT_XL='KEEP (*(SORT(.CRT$XL*))) /* TLS callbacks */'
  43. R_CRT_XP='KEEP (*(SORT(.CRT$XP*))) /* Pre-termination */'
  44. R_CRT_XT='KEEP (*(SORT(.CRT$XT*))) /* Termination */'
  45. R_TLS='
  46. KEEP (*(.tls$AAA))
  47. KEEP (*(.tls))
  48. KEEP (*(.tls$))
  49. KEEP (*(SORT(.tls$*)))
  50. KEEP (*(.tls$ZZZ))'
  51. R_RSRC='
  52. KEEP (*(.rsrc))
  53. KEEP (*(.rsrc$*))'
  54. else
  55. R_TEXT=
  56. R_DATA=
  57. R_RDATA='*(.rdata)'
  58. R_IDATA234=
  59. R_IDATA5=
  60. R_IDATA67=
  61. R_CRT_XC=
  62. R_CRT_XI=
  63. R_CRT_XL=
  64. R_CRT_XP=
  65. R_CRT_XT=
  66. R_TLS='*(.tls)'
  67. R_RSRC='*(.rsrc)'
  68. fi
  69. cat <<EOF
  70. /* Copyright (C) 2014-2022 Free Software Foundation, Inc.
  71. Copying and distribution of this script, with or without modification,
  72. are permitted in any medium without royalty provided the copyright
  73. notice and this notice are preserved. */
  74. ${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
  75. ${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
  76. ${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
  77. ${LIB_SEARCH_DIRS}
  78. SECTIONS
  79. {
  80. ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
  81. ${RELOCATING+ lower than the target page size. */}
  82. ${RELOCATING+. = SIZEOF_HEADERS;}
  83. ${RELOCATING+. = ALIGN(__section_alignment__);}
  84. .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
  85. {
  86. ${RELOCATING+KEEP (*(SORT_NONE(.init)))}
  87. *(.text)
  88. ${R_TEXT}
  89. ${RELOCATING+ *(.text.*)}
  90. ${RELOCATING+ *(.gnu.linkonce.t.*)}
  91. ${RELOCATING+*(.glue_7t)}
  92. ${RELOCATING+*(.glue_7)}
  93. ${CONSTRUCTING+. = ALIGN(8);}
  94. ${CONSTRUCTING+
  95. /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
  96. we do not PROVIDE them. This is because the ctors.o startup
  97. code in libgcc defines them as common symbols, with the
  98. expectation that they will be overridden by the definitions
  99. here. If we PROVIDE the symbols then they will not be
  100. overridden and global constructors will not be run.
  101. See PR 22762 for more details.
  102. This does mean that it is not possible for a user to define
  103. their own __CTOR_LIST__ and __DTOR_LIST__ symbols; if they do,
  104. the content from those variables are included but the symbols
  105. defined here silently take precedence. If they truly need to
  106. be redefined, a custom linker script will have to be used.
  107. (The custom script can just be a copy of this script with the
  108. PROVIDE() qualifiers added).
  109. In particular this means that ld -Ur does not work, because
  110. the proper __CTOR_LIST__ set by ld -Ur is overridden by a
  111. bogus __CTOR_LIST__ set by the final link. See PR 46. */
  112. ___CTOR_LIST__ = .;
  113. __CTOR_LIST__ = .;
  114. LONG (-1); LONG (-1);
  115. KEEP (*(.ctors));
  116. KEEP (*(.ctor));
  117. KEEP (*(SORT_BY_NAME(.ctors.*)));
  118. LONG (0); LONG (0);
  119. }
  120. ${CONSTRUCTING+
  121. /* See comment about __CTOR_LIST__ above. The same reasoning
  122. applies here too. */
  123. ___DTOR_LIST__ = .;
  124. __DTOR_LIST__ = .;
  125. LONG (-1); LONG (-1);
  126. KEEP (*(.dtors));
  127. KEEP (*(.dtor));
  128. KEEP (*(SORT_BY_NAME(.dtors.*)));
  129. LONG (0); LONG (0);
  130. }
  131. ${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
  132. ${RELOCATING+/* ??? Why is .gcc_exc here? */}
  133. ${RELOCATING+ *(.gcc_exc)}
  134. ${RELOCATING+PROVIDE (etext = .);}
  135. ${RELOCATING+ KEEP (*(.gcc_except_table))}
  136. }
  137. /* The Cygwin32 library uses a section to avoid copying certain data
  138. on fork. This used to be named ".data$nocopy". The linker used
  139. to include this between __data_start__ and __data_end__, but that
  140. breaks building the cygwin32 dll. Instead, we name the section
  141. ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
  142. .data ${RELOCATING+BLOCK(__section_alignment__)} :
  143. {
  144. ${RELOCATING+__data_start__ = . ;}
  145. *(.data)
  146. ${RELOCATING+*(.data2)}
  147. ${R_DATA}
  148. KEEP(*(.jcr))
  149. ${RELOCATING+__data_end__ = . ;}
  150. ${RELOCATING+*(.data_cygwin_nocopy)}
  151. }
  152. .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
  153. {
  154. ${R_RDATA}
  155. . = ALIGN(4);
  156. ${RELOCATING+__rt_psrelocs_start = .;}
  157. ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
  158. ${RELOCATING+__rt_psrelocs_end = .;}
  159. }
  160. ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
  161. ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
  162. ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
  163. ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
  164. ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
  165. .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
  166. {
  167. KEEP (*(.eh_frame${RELOCATING+*}))
  168. }
  169. .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
  170. {
  171. KEEP(*(.pdata${RELOCATING+*}))
  172. }
  173. .xdata ${RELOCATING+BLOCK(__section_alignment__)} :
  174. {
  175. KEEP(*(.xdata${RELOCATING+*}))
  176. }
  177. .bss ${RELOCATING+BLOCK(__section_alignment__)} :
  178. {
  179. ${RELOCATING+__bss_start__ = . ;}
  180. *(.bss)
  181. *(COMMON)
  182. ${RELOCATING+__bss_end__ = . ;}
  183. }
  184. .edata ${RELOCATING+BLOCK(__section_alignment__)} :
  185. {
  186. *(.edata)
  187. }
  188. /DISCARD/ :
  189. {
  190. *(.debug\$S)
  191. *(.debug\$T)
  192. *(.debug\$F)
  193. *(.drectve)
  194. ${RELOCATING+ *(.note.GNU-stack)}
  195. ${RELOCATING+ *(.gnu.lto_*)}
  196. }
  197. .idata ${RELOCATING+BLOCK(__section_alignment__)} :
  198. {
  199. /* This cannot currently be handled with grouped sections.
  200. See pep.em:sort_sections. */
  201. ${R_IDATA234}
  202. ${RELOCATING+__IAT_start__ = .;}
  203. ${R_IDATA5}
  204. ${RELOCATING+__IAT_end__ = .;}
  205. ${R_IDATA67}
  206. }
  207. .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
  208. {
  209. ${RELOCATING+___crt_xc_start__ = . ;}
  210. ${R_CRT_XC}
  211. ${RELOCATING+___crt_xc_end__ = . ;}
  212. ${RELOCATING+___crt_xi_start__ = . ;}
  213. ${R_CRT_XI}
  214. ${RELOCATING+___crt_xi_end__ = . ;}
  215. ${RELOCATING+___crt_xl_start__ = . ;}
  216. ${R_CRT_XL}
  217. /* ___crt_xl_end__ is defined in the TLS Directory support code */
  218. ${RELOCATING+___crt_xp_start__ = . ;}
  219. ${R_CRT_XP}
  220. ${RELOCATING+___crt_xp_end__ = . ;}
  221. ${RELOCATING+___crt_xt_start__ = . ;}
  222. ${R_CRT_XT}
  223. ${RELOCATING+___crt_xt_end__ = . ;}
  224. }
  225. /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
  226. at the end of the .tls section. This is important because _tls_start MUST
  227. be at the beginning of the section to enable SECREL32 relocations with TLS
  228. data. */
  229. .tls ${RELOCATING+BLOCK(__section_alignment__)} :
  230. {
  231. ${RELOCATING+___tls_start__ = . ;}
  232. ${R_TLS}
  233. ${RELOCATING+___tls_end__ = . ;}
  234. }
  235. .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
  236. {
  237. /* end is deprecated, don't use it */
  238. ${RELOCATING+PROVIDE (end = .);}
  239. ${RELOCATING+PROVIDE ( _end = .);}
  240. ${RELOCATING+ __end__ = .;}
  241. }
  242. .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
  243. {
  244. ${R_RSRC}
  245. }
  246. .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
  247. {
  248. *(.reloc)
  249. }
  250. .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  251. {
  252. *(.stab)
  253. }
  254. .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  255. {
  256. *(.stabstr)
  257. }
  258. /* DWARF debug sections.
  259. Symbols in the DWARF debugging sections are relative to the beginning
  260. of the section. Unlike other targets that fake this by putting the
  261. section VMA at 0, the PE format will not allow it. */
  262. /* DWARF 1.1 and DWARF 2. */
  263. .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  264. {
  265. *(.debug_aranges)
  266. }
  267. .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  268. {
  269. *(.zdebug_aranges)
  270. }
  271. .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  272. {
  273. *(.debug_pubnames)
  274. }
  275. .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  276. {
  277. *(.zdebug_pubnames)
  278. }
  279. /* DWARF 2. */
  280. .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  281. {
  282. *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
  283. }
  284. .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  285. {
  286. *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
  287. }
  288. .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  289. {
  290. *(.debug_abbrev)
  291. }
  292. .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  293. {
  294. *(.zdebug_abbrev)
  295. }
  296. .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  297. {
  298. *(.debug_line)
  299. }
  300. .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  301. {
  302. *(.zdebug_line)
  303. }
  304. .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  305. {
  306. *(.debug_frame*)
  307. }
  308. .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  309. {
  310. *(.zdebug_frame*)
  311. }
  312. .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  313. {
  314. *(.debug_str)
  315. }
  316. .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  317. {
  318. *(.zdebug_str)
  319. }
  320. .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  321. {
  322. *(.debug_loc)
  323. }
  324. .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  325. {
  326. *(.zdebug_loc)
  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. /* SGI/MIPS DWARF 2 extensions. */
  337. .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  338. {
  339. *(.debug_weaknames)
  340. }
  341. .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  342. {
  343. *(.zdebug_weaknames)
  344. }
  345. .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  346. {
  347. *(.debug_funcnames)
  348. }
  349. .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  350. {
  351. *(.zdebug_funcnames)
  352. }
  353. .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  354. {
  355. *(.debug_typenames)
  356. }
  357. .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  358. {
  359. *(.zdebug_typenames)
  360. }
  361. .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  362. {
  363. *(.debug_varnames)
  364. }
  365. .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  366. {
  367. *(.zdebug_varnames)
  368. }
  369. /* DWARF 3. */
  370. .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  371. {
  372. *(.debug_pubtypes)
  373. }
  374. .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  375. {
  376. *(.zdebug_pubtypes)
  377. }
  378. .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  379. {
  380. *(.debug_ranges)
  381. }
  382. .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  383. {
  384. *(.zdebug_ranges)
  385. }
  386. /* DWARF 4. */
  387. .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  388. {
  389. *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
  390. }
  391. .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  392. {
  393. *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*})
  394. }
  395. /* DWARF 5. */
  396. .debug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  397. {
  398. *(.debug_addr)
  399. }
  400. .zdebug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  401. {
  402. *(.zdebug_addr)
  403. }
  404. .debug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  405. {
  406. *(.debug_line_str)
  407. }
  408. .zdebug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  409. {
  410. *(.zdebug_line_str)
  411. }
  412. .debug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  413. {
  414. *(.debug_loclists)
  415. }
  416. .zdebug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  417. {
  418. *(.zdebug_loclists)
  419. }
  420. .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  421. {
  422. *(.debug_macro)
  423. }
  424. .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  425. {
  426. *(.zdebug_macro)
  427. }
  428. .debug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  429. {
  430. *(.debug_names)
  431. }
  432. .zdebug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  433. {
  434. *(.zdebug_names)
  435. }
  436. .debug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  437. {
  438. *(.debug_rnglists)
  439. }
  440. .zdebug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  441. {
  442. *(.zdebug_rnglists)
  443. }
  444. .debug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  445. {
  446. *(.debug_str_offsets)
  447. }
  448. .zdebug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  449. {
  450. *(.zdebug_str_offsets)
  451. }
  452. .debug_sup ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  453. {
  454. *(.debug_sup)
  455. }
  456. /* For Go and Rust. */
  457. .debug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  458. {
  459. *(.debug_gdb_scripts)
  460. }
  461. .zdebug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
  462. {
  463. *(.zdebug_gdb_scripts)
  464. }
  465. }
  466. EOF