iq2000.sc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. # Copyright (C) 2014-2015 Free Software Foundation, Inc.
  2. #
  3. # Copying and distribution of this file, with or without modification,
  4. # are permitted in any medium without royalty provided the copyright
  5. # notice and this notice are preserved.
  6. #
  7. # Unusual variables checked by this code:
  8. # NOP - four byte opcode for no-op (defaults to 0)
  9. # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
  10. # INITIAL_READONLY_SECTIONS - at start of data segment
  11. # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
  12. # (e.g., .PARISC.milli)
  13. # OTHER_TEXT_SECTIONS - these get put in .text when relocating
  14. # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
  15. # (e.g., .PARISC.global)
  16. # OTHER_SECTIONS - at the end
  17. # EXECUTABLE_SYMBOLS - symbols that must be defined for an
  18. # executable (e.g., _DYNAMIC_LINK)
  19. # TEXT_START_SYMBOLS - symbols that appear at the start of the
  20. # .text section.
  21. # DATA_START_SYMBOLS - symbols that appear at the start of the
  22. # .data section.
  23. # OTHER_GOT_SYMBOLS - symbols defined just before .got.
  24. # OTHER_GOT_SECTIONS - sections just after .got.
  25. # OTHER_SDATA_SECTIONS - sections just after .sdata.
  26. # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
  27. # .bss section besides __bss_start.
  28. # DATA_PLT - .plt should be in data segment, not text segment.
  29. # BSS_PLT - .plt should be in bss segment
  30. # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
  31. # EMBEDDED - whether this is for an embedded system.
  32. # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
  33. # start address of shared library.
  34. # INPUT_FILES - INPUT command of files to always include
  35. # WRITABLE_RODATA - if set, the .rodata section should be writable
  36. # INIT_START, INIT_END - statements just before and just after
  37. # combination of .init sections.
  38. # FINI_START, FINI_END - statements just before and just after
  39. # combination of .fini sections.
  40. #
  41. # When adding sections, do note that the names of some sections are used
  42. # when specifying the start address of the next.
  43. #
  44. # Many sections come in three flavours. There is the 'real' section,
  45. # like ".data". Then there are the per-procedure or per-variable
  46. # sections, generated by -ffunction-sections and -fdata-sections in GCC,
  47. # and useful for --gc-sections, which for a variable "foo" might be
  48. # ".data.foo". Then there are the linkonce sections, for which the linker
  49. # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
  50. # The exact correspondences are:
  51. #
  52. # Section Linkonce section
  53. # .text .gnu.linkonce.t.foo
  54. # .rodata .gnu.linkonce.r.foo
  55. # .data .gnu.linkonce.d.foo
  56. # .bss .gnu.linkonce.b.foo
  57. # .sdata .gnu.linkonce.s.foo
  58. # .sbss .gnu.linkonce.sb.foo
  59. # .sdata2 .gnu.linkonce.s2.foo
  60. # .sbss2 .gnu.linkonce.sb2.foo
  61. #
  62. # Each of these can also have corresponding .rel.* and .rela.* sections.
  63. test -z "$ENTRY" && ENTRY=_start
  64. test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  65. test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  66. if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
  67. test -z "${ELFSIZE}" && ELFSIZE=32
  68. test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
  69. test "$LD_FLAG" = "N" && DATA_ADDR=.
  70. INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
  71. PLT=".plt ${RELOCATING-0} : { *(.plt) }"
  72. DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }"
  73. RODATA=".rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)} }"
  74. SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2) ${RELOCATING+*(.sbss2.*)} ${RELOCATING+*(.gnu.linkonce.sb2.*)} }"
  75. SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2) ${RELOCATING+*(.sdata2.*)} ${RELOCATING+*(.gnu.linkonce.s2.*)} }"
  76. CTOR=".ctors ${CONSTRUCTING-0} :
  77. {
  78. ${CONSTRUCTING+${CTOR_START}}
  79. /* gcc uses crtbegin.o to find the start of
  80. the constructors, so we make sure it is
  81. first. Because this is a wildcard, it
  82. doesn't matter if the user does not
  83. actually link against crtbegin.o; the
  84. linker won't look for a file to match a
  85. wildcard. The wildcard also means that it
  86. doesn't matter which directory crtbegin.o
  87. is in. */
  88. KEEP (*crtbegin.o(.ctors))
  89. KEEP (*crtbegin?.o(.ctors))
  90. /* We don't want to include the .ctor section from
  91. the crtend.o file until after the sorted ctors.
  92. The .ctor section from the crtend file contains the
  93. end of ctors marker and it must be last */
  94. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
  95. KEEP (*(SORT(.ctors.*)))
  96. KEEP (*(.ctors))
  97. ${CONSTRUCTING+${CTOR_END}}
  98. }"
  99. DTOR=" .dtors ${CONSTRUCTING-0} :
  100. {
  101. ${CONSTRUCTING+${DTOR_START}}
  102. KEEP (*crtbegin.o(.dtors))
  103. KEEP (*crtbegin?.o(.dtors))
  104. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
  105. KEEP (*(SORT(.dtors.*)))
  106. KEEP (*(.dtors))
  107. ${CONSTRUCTING+${DTOR_END}}
  108. }"
  109. # If this is for an embedded system, don't add SIZEOF_HEADERS.
  110. if [ -z "$EMBEDDED" ]; then
  111. test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
  112. else
  113. test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
  114. fi
  115. cat <<EOF
  116. /* Copyright (C) 2014-2015 Free Software Foundation, Inc.
  117. Copying and distribution of this script, with or without modification,
  118. are permitted in any medium without royalty provided the copyright
  119. notice and this notice are preserved. */
  120. OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
  121. "${LITTLE_OUTPUT_FORMAT}")
  122. OUTPUT_ARCH(${OUTPUT_ARCH})
  123. ${RELOCATING+ENTRY(${ENTRY})}
  124. ${RELOCATING+${LIB_SEARCH_DIRS}}
  125. ${RELOCATING+/* Do we need any of these for elf?
  126. __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
  127. ${RELOCATING+${EXECUTABLE_SYMBOLS}}
  128. ${RELOCATING+${INPUT_FILES}}
  129. ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
  130. if gld -r is used and the intermediate file has sections starting
  131. at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
  132. bug. But for now assigning the zero vmas works. */}
  133. SECTIONS
  134. {
  135. ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
  136. ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
  137. ${CREATE_SHLIB-${INTERP}}
  138. ${TEXT_DYNAMIC+${DYNAMIC}}
  139. EOF
  140. if [ "x$COMBRELOC" = x ]; then
  141. COMBRELOCCAT=cat
  142. else
  143. COMBRELOCCAT="cat > $COMBRELOC"
  144. fi
  145. eval $COMBRELOCCAT <<EOF
  146. .rel.init ${RELOCATING-0} : { *(.rel.init) }
  147. .rela.init ${RELOCATING-0} : { *(.rela.init) }
  148. .rel.text ${RELOCATING-0} :
  149. {
  150. *(.rel.text)
  151. ${RELOCATING+*(.rel.text.*)}
  152. ${RELOCATING+*(.rel.gnu.linkonce.t.*)}
  153. }
  154. .rela.text ${RELOCATING-0} :
  155. {
  156. *(.rela.text)
  157. ${RELOCATING+*(.rela.text.*)}
  158. ${RELOCATING+*(.rela.gnu.linkonce.t.*)}
  159. }
  160. .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
  161. .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
  162. .rel.rodata ${RELOCATING-0} :
  163. {
  164. *(.rel.rodata)
  165. ${RELOCATING+*(.rel.rodata.*)}
  166. ${RELOCATING+*(.rel.gnu.linkonce.r.*)}
  167. }
  168. .rela.rodata ${RELOCATING-0} :
  169. {
  170. *(.rela.rodata)
  171. ${RELOCATING+*(.rela.rodata.*)}
  172. ${RELOCATING+*(.rela.gnu.linkonce.r.*)}
  173. }
  174. ${OTHER_READONLY_RELOC_SECTIONS}
  175. .rel.data ${RELOCATING-0} :
  176. {
  177. *(.rel.data)
  178. ${RELOCATING+*(.rel.data.*)}
  179. ${RELOCATING+*(.rel.gnu.linkonce.d.*)}
  180. }
  181. .rela.data ${RELOCATING-0} :
  182. {
  183. *(.rela.data)
  184. ${RELOCATING+*(.rela.data.*)}
  185. ${RELOCATING+*(.rela.gnu.linkonce.d.*)}
  186. }
  187. .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
  188. .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
  189. .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
  190. .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
  191. .rel.got ${RELOCATING-0} : { *(.rel.got) }
  192. .rela.got ${RELOCATING-0} : { *(.rela.got) }
  193. ${OTHER_GOT_RELOC_SECTIONS}
  194. .rel.sdata ${RELOCATING-0} :
  195. {
  196. *(.rel.sdata)
  197. ${RELOCATING+*(.rel.sdata.*)}
  198. ${RELOCATING+*(.rel.gnu.linkonce.s.*)}
  199. }
  200. .rela.sdata ${RELOCATING-0} :
  201. {
  202. *(.rela.sdata)
  203. ${RELOCATING+*(.rela.sdata.*)}
  204. ${RELOCATING+*(.rela.gnu.linkonce.s.*)}
  205. }
  206. .rel.sbss ${RELOCATING-0} :
  207. {
  208. *(.rel.sbss)
  209. ${RELOCATING+*(.rel.sbss.*)}
  210. ${RELOCATING+*(.rel.gnu.linkonce.sb.*)}
  211. }
  212. .rela.sbss ${RELOCATING-0} :
  213. {
  214. *(.rela.sbss)
  215. ${RELOCATING+*(.rela.sbss.*)}
  216. ${RELOCATING+*(.rela.gnu.linkonce.sb.*)}
  217. }
  218. .rel.sdata2 ${RELOCATING-0} :
  219. {
  220. *(.rel.sdata2)
  221. ${RELOCATING+*(.rel.sdata2.*)}
  222. ${RELOCATING+*(.rel.gnu.linkonce.s2.*)}
  223. }
  224. .rela.sdata2 ${RELOCATING-0} :
  225. {
  226. *(.rela.sdata2)
  227. ${RELOCATING+*(.rela.sdata2.*)}
  228. ${RELOCATING+*(.rela.gnu.linkonce.s2.*)}
  229. }
  230. .rel.sbss2 ${RELOCATING-0} :
  231. {
  232. *(.rel.sbss2)
  233. ${RELOCATING+*(.rel.sbss2.*)}
  234. ${RELOCATING+*(.rel.gnu.linkonce.sb2.*)}
  235. }
  236. .rela.sbss2 ${RELOCATING-0} :
  237. {
  238. *(.rela.sbss2)
  239. ${RELOCATING+*(.rela.sbss2.*)}
  240. ${RELOCATING+*(.rela.gnu.linkonce.sb2.*)}
  241. }
  242. .rel.bss ${RELOCATING-0} :
  243. {
  244. *(.rel.bss)
  245. ${RELOCATING+*(.rel.bss.*)}
  246. ${RELOCATING+*(.rel.gnu.linkonce.b.*)}
  247. }
  248. .rela.bss ${RELOCATING-0} :
  249. {
  250. *(.rela.bss)
  251. ${RELOCATING+*(.rela.bss.*)}
  252. ${RELOCATING+*(.rela.gnu.linkonce.b.*)}
  253. }
  254. EOF
  255. if [ -n "$COMBRELOC" ]; then
  256. cat <<EOF
  257. .rel.dyn :
  258. {
  259. EOF
  260. sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
  261. cat <<EOF
  262. }
  263. .rela.dyn :
  264. {
  265. EOF
  266. sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
  267. cat <<EOF
  268. }
  269. EOF
  270. fi
  271. cat <<EOF
  272. .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
  273. .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
  274. ${OTHER_PLT_RELOC_SECTIONS}
  275. .init ${RELOCATING-0} :
  276. {
  277. ${RELOCATING+${INIT_START}}
  278. KEEP (*(.init))
  279. ${RELOCATING+${INIT_END}}
  280. } =${NOP-0}
  281. ${DATA_PLT-${BSS_PLT-${PLT}}}
  282. .text ${RELOCATING-0} :
  283. {
  284. ${RELOCATING+${TEXT_START_SYMBOLS}}
  285. *(.text)
  286. ${RELOCATING+*(.text.*)}
  287. *(.stub)
  288. /* .gnu.warning sections are handled specially by elf32.em. */
  289. *(.gnu.warning)
  290. ${RELOCATING+*(.gnu.linkonce.t.*)}
  291. ${RELOCATING+${OTHER_TEXT_SECTIONS}}
  292. } =${NOP-0}
  293. .fini ${RELOCATING-0} :
  294. {
  295. ${RELOCATING+${FINI_START}}
  296. KEEP (*(.fini))
  297. ${RELOCATING+${FINI_END}}
  298. } =${NOP-0}
  299. ${RELOCATING+PROVIDE (__etext = .);}
  300. ${RELOCATING+PROVIDE (_etext = .);}
  301. ${RELOCATING+PROVIDE (etext = .);}
  302. /* Adjust the address for the data segment. We want to adjust up to
  303. the same address within the page on the next page up. */
  304. ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
  305. ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
  306. .data ${RELOCATING-0} :
  307. {
  308. ${RELOCATING+${DATA_START_SYMBOLS}}
  309. *(.data)
  310. ${RELOCATING+*(.data.*)}
  311. ${RELOCATING+*(.gnu.linkonce.d.*)}
  312. ${CONSTRUCTING+SORT(CONSTRUCTORS)}
  313. }
  314. .data1 ${RELOCATING-0} : { *(.data1) }
  315. .eh_frame ${RELOCATING-0} :
  316. {
  317. ${RELOCATING+PROVIDE (__eh_frame_begin = .);}
  318. *(.eh_frame)
  319. LONG (0);
  320. ${RELOCATING+PROVIDE (__eh_frame_end = .);}
  321. } ${RELOCATING+}
  322. .gcc_except_table : { *(.gcc_except_table) }
  323. ${INITIAL_READONLY_SECTIONS}
  324. .hash ${RELOCATING-0} : { *(.hash) }
  325. .dynsym ${RELOCATING-0} : { *(.dynsym) }
  326. .dynstr ${RELOCATING-0} : { *(.dynstr) }
  327. .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
  328. .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
  329. .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
  330. ${RODATA}
  331. .rodata1 ${RELOCATING-0} : { *(.rodata1) }
  332. ${CREATE_SHLIB-${SDATA2}}
  333. ${CREATE_SHLIB-${SBSS2}}
  334. ${RELOCATING+${OTHER_READONLY_SECTIONS}}
  335. ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
  336. ${TEXT_DYNAMIC-${DYNAMIC}}
  337. ${RELOCATING+${CTOR}}
  338. ${RELOCATING+${DTOR}}
  339. .jcr : { KEEP (*(.jcr)) }
  340. ${DATA_PLT+${PLT}}
  341. ${RELOCATING+${OTHER_GOT_SYMBOLS}}
  342. .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
  343. ${RELOCATING+${OTHER_GOT_SECTIONS}}
  344. ${CREATE_SHLIB+${SDATA2}}
  345. ${CREATE_SHLIB+${SBSS2}}
  346. /* We want the small data sections together, so single-instruction offsets
  347. can access them all, and initialized data all before uninitialized, so
  348. we can shorten the on-disk segment size. */
  349. .sdata ${RELOCATING-0} :
  350. {
  351. ${RELOCATING+${SDATA_START_SYMBOLS}}
  352. *(.sdata)
  353. ${RELOCATING+*(.sdata.*)}
  354. ${RELOCATING+*(.gnu.linkonce.s.*)}
  355. }
  356. ${RELOCATING+${OTHER_SDATA_SECTIONS}}
  357. ${RELOCATING+_edata = .;}
  358. ${RELOCATING+PROVIDE (edata = .);}
  359. ${RELOCATING+__bss_start = .;}
  360. ${RELOCATING+${OTHER_BSS_SYMBOLS}}
  361. .sbss ${RELOCATING-0} :
  362. {
  363. ${RELOCATING+PROVIDE (__sbss_start = .);}
  364. ${RELOCATING+PROVIDE (___sbss_start = .);}
  365. *(.dynsbss)
  366. *(.sbss)
  367. ${RELOCATING+*(.sbss.*)}
  368. ${RELOCATING+*(.gnu.linkonce.sb.*)}
  369. *(.scommon)
  370. ${RELOCATING+PROVIDE (__sbss_end = .);}
  371. ${RELOCATING+PROVIDE (___sbss_end = .);}
  372. }
  373. ${BSS_PLT+${PLT}}
  374. .bss ${RELOCATING-0} :
  375. {
  376. *(.dynbss)
  377. *(.bss)
  378. ${RELOCATING+*(.bss.*)}
  379. ${RELOCATING+*(.gnu.linkonce.b.*)}
  380. *(COMMON)
  381. /* Align here to ensure that the .bss section occupies space up to
  382. _end. Align after .bss to ensure correct alignment even if the
  383. .bss section disappears because there are no input sections. */
  384. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  385. }
  386. ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
  387. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  388. ${RELOCATING+${OTHER_END_SYMBOLS}}
  389. ${RELOCATING+_end = .;}
  390. ${RELOCATING+PROVIDE (end = .);}
  391. /* Stabs debugging sections. */
  392. .stab 0 : { *(.stab) }
  393. .stabstr 0 : { *(.stabstr) }
  394. .stab.excl 0 : { *(.stab.excl) }
  395. .stab.exclstr 0 : { *(.stab.exclstr) }
  396. .stab.index 0 : { *(.stab.index) }
  397. .stab.indexstr 0 : { *(.stab.indexstr) }
  398. .comment 0 : { *(.comment) }
  399. EOF
  400. . $srcdir/scripttempl/DWARF.sc
  401. cat <<EOF
  402. ${RELOCATING+${OTHER_RELOCATING_SECTIONS}}
  403. /* These must appear regardless of ${RELOCATING}. */
  404. ${OTHER_SECTIONS}
  405. }
  406. EOF