elfarcv2.sc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #
  2. # Unusual variables checked by this code:
  3. # NOP - four byte opcode for no-op (defaults to 0)
  4. # NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
  5. # empty.
  6. # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
  7. # (e.g., .PARISC.milli)
  8. # When adding sections, do note that the names of some sections are used
  9. # when specifying the start address of the next.
  10. #
  11. test -z "$ENTRY" && ENTRY=start
  12. test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  13. test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  14. # If we request a big endian toolchain, give a big endian linker
  15. test -z "$GOT" && GOT=".got ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) } ${RELOCATING+ > ${DATA_MEMORY}}"
  16. test "${ARC_ENDIAN}" = "big" && OUTPUT_FORMAT=${BIG_OUTPUT_FORMAT}
  17. if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
  18. test -z "${ELFSIZE}" && ELFSIZE=32
  19. test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
  20. test "$LD_FLAG" = "N" && DATA_ADDR=.
  21. CTOR=".ctors ${CONSTRUCTING-0} :
  22. {
  23. ${CONSTRUCTING+${CTOR_START}}
  24. /* gcc uses crtbegin.o to find the start of
  25. the constructors, so we make sure it is
  26. first. Because this is a wildcard, it
  27. doesn't matter if the user does not
  28. actually link against crtbegin.o; the
  29. linker won't look for a file to match a
  30. wildcard. The wildcard also means that it
  31. doesn't matter which directory crtbegin.o
  32. is in. */
  33. KEEP (*crtbegin*.o(.ctors))
  34. /* We don't want to include the .ctor section from
  35. from the crtend.o file until after the sorted ctors.
  36. The .ctor section from the crtend file contains the
  37. end of ctors marker and it must be last */
  38. KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors))
  39. KEEP (*(SORT(.ctors.*)))
  40. KEEP (*(.ctors))
  41. ${CONSTRUCTING+${CTOR_END}}
  42. } ${RELOCATING+ > ${DATA_MEMORY}}"
  43. DTOR=".dtors ${CONSTRUCTING-0} :
  44. {
  45. ${CONSTRUCTING+${DTOR_START}}
  46. KEEP (*crtbegin*.o(.dtors))
  47. KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors))
  48. KEEP (*(SORT(.dtors.*)))
  49. KEEP (*(.dtors))
  50. ${CONSTRUCTING+${DTOR_END}}
  51. } ${RELOCATING+ > ${DATA_MEMORY}}"
  52. IVT="
  53. /* If the 'ivtbase_addr' symbol is defined, it indicates the base address of
  54. the interrupt vectors. See description of INT_VECTOR_BASE register. */
  55. .ivt DEFINED (ivtbase_addr) ? ivtbase_addr : 0x00 :
  56. {
  57. ${RELOCATING+ PROVIDE (__ivtbase_addr = .); }
  58. KEEP (*(.ivt));
  59. } ${RELOCATING+ > ${STARTUP_MEMORY}}"
  60. if test -z "${NO_SMALL_DATA}"; then
  61. SBSS=".sbss ${RELOCATING-0} :
  62. {
  63. ${RELOCATING+PROVIDE (__sbss_start = .);}
  64. ${RELOCATING+PROVIDE (___sbss_start = .);}
  65. *(.dynsbss)
  66. *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
  67. *(.scommon)
  68. ${RELOCATING+PROVIDE (__sbss_end = .);}
  69. ${RELOCATING+PROVIDE (___sbss_end = .);}
  70. } ${RELOCATING+ > ${SDATA_MEMORY}}"
  71. SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) } ${RELOCATING+ > ${SDATA_MEMORY}}"
  72. SDATA="/* We want the small data sections together, so single-instruction offsets
  73. can access them all, and initialized data all before uninitialized, so
  74. we can shorten the on-disk segment size. */
  75. .sdata ${RELOCATING-0} :
  76. {
  77. ${RELOCATING+${SDATA_START_SYMBOLS}}
  78. *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
  79. ${RELOCATING+_edata = .;}
  80. ${RELOCATING+PROVIDE (edata = .);}
  81. } ${RELOCATING+ > ${SDATA_MEMORY}}"
  82. SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) } ${RELOCATING+ > ${SDATA_MEMORY}}"
  83. REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
  84. .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
  85. REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
  86. .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
  87. REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
  88. .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
  89. REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
  90. .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
  91. fi
  92. #
  93. # We provide two emulations: a fixed on that defines some memory banks
  94. # and a configurable one that includes a user provided memory definition.
  95. #
  96. case $GENERIC_BOARD in
  97. yes|1|YES)
  98. MEMORY_DEF="
  99. /* Get memory banks definition from some user configuration file.
  100. This file must be located in some linker directory (search path
  101. with -L<dir>). See fixed memory banks emulation script. */
  102. INCLUDE memory.x;
  103. "
  104. ;;
  105. *)
  106. MEMORY_DEF="
  107. /* Fixed definition of the available memory banks.
  108. See generic emulation script for a user defined configuration. */
  109. MEMORY
  110. {
  111. ICCM : ORIGIN = 0x00000000, LENGTH = ${ICCM_SIZE}
  112. DCCM : ORIGIN = ${RAM_START_ADDR}, LENGTH = ${RAM_SIZE}
  113. }
  114. "
  115. ;;
  116. esac
  117. cat <<EOF
  118. OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", "${LITTLE_OUTPUT_FORMAT}")
  119. OUTPUT_ARCH(${OUTPUT_ARCH})
  120. ${RELOCATING+ENTRY(${ENTRY})}
  121. ${RELOCATING+${LIB_SEARCH_DIRS}}
  122. ${RELOCATING+${EXECUTABLE_SYMBOLS}}
  123. ${RELOCATING+${MEMORY_DEF}}
  124. SECTIONS
  125. {
  126. ${RELOCATING+${IVT}}
  127. /* Read-only sections, merged into text segment: */
  128. ${TEXT_DYNAMIC+${DYNAMIC}}
  129. .hash ${RELOCATING-0} : { *(.hash) }
  130. .dynsym ${RELOCATING-0} : { *(.dynsym) }
  131. .dynstr ${RELOCATING-0} : { *(.dynstr) }
  132. .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
  133. .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
  134. .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
  135. .rel.init ${RELOCATING-0} : { *(.rel.init) }
  136. .rela.init ${RELOCATING-0} : { *(.rela.init) }
  137. .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
  138. .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
  139. .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
  140. .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
  141. .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
  142. .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
  143. .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
  144. .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
  145. .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
  146. .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
  147. .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
  148. .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
  149. .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
  150. .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
  151. .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
  152. .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
  153. .rel.got ${RELOCATING-0} : { *(.rel.got) }
  154. .rela.got ${RELOCATING-0} : { *(.rela.got) }
  155. ${REL_SDATA}
  156. ${REL_SBSS}
  157. ${REL_SDATA2}
  158. ${REL_SBSS2}
  159. .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
  160. .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
  161. .text ${RELOCATING-0} :
  162. {
  163. ${RELOCATING+${TEXT_START_SYMBOLS}}
  164. ${RELOCATING+ . = ALIGN(4);}
  165. ${RELOCATING+${INIT_START}}
  166. KEEP (*(SORT_NONE(.init)))
  167. ${RELOCATING+${INIT_END}}
  168. /* Start here after reset. */
  169. ${RELOCATING+ . = ALIGN(4);}
  170. KEEP (*crt0.o(.text.__startup))
  171. /* Remaining code. */
  172. ${RELOCATING+ . = ALIGN(4);}
  173. *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
  174. /* .gnu.warning sections are handled specially by elf.em. */
  175. *(.gnu.warning)
  176. ${RELOCATING+${OTHER_TEXT_SECTIONS}}
  177. } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
  178. .fini ${RELOCATING-0} :
  179. {
  180. ${RELOCATING+${FINI_START}}
  181. KEEP (*(SORT_NONE(.fini)))
  182. ${RELOCATING+${FINI_END}}
  183. ${RELOCATING+PROVIDE (__etext = .);}
  184. ${RELOCATING+PROVIDE (_etext = .);}
  185. ${RELOCATING+PROVIDE (etext = .);}
  186. } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
  187. .jcr ${RELOCATING-0} :
  188. {
  189. KEEP (*(.jcr))
  190. } ${RELOCATING+> ${TEXT_MEMORY}}
  191. .eh_frame ${RELOCATING-0} :
  192. {
  193. KEEP (*(.eh_frame))
  194. } ${RELOCATING+> ${TEXT_MEMORY}}
  195. .gcc_except_table ${RELOCATING-0} :
  196. {
  197. *(.gcc_except_table) *(.gcc_except_table.*)
  198. } ${RELOCATING+> ${TEXT_MEMORY}}
  199. .plt ${RELOCATING-0} :
  200. {
  201. *(.plt)
  202. } ${RELOCATING+> ${TEXT_MEMORY}}
  203. .jlitab ${RELOCATING-0} :
  204. {
  205. ${RELOCATING+${JLI_START_TABLE}}
  206. jlitab*.o:(.jlitab*) *(.jlitab*)
  207. } ${RELOCATING+> ${TEXT_MEMORY}}
  208. .rodata ${RELOCATING-0} :
  209. {
  210. *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)}
  211. } ${RELOCATING+> ${TEXT_MEMORY}}
  212. .rodata1 ${RELOCATING-0} : { *(.rodata1) } ${RELOCATING+> ${TEXT_MEMORY}}
  213. ${RELOCATING+${OTHER_READONLY_SECTIONS}}
  214. /* Start of the data section image in ROM. */
  215. ${RELOCATING+__data_image = .;}
  216. ${RELOCATING+PROVIDE (__data_image = .);}
  217. .data ${RELOCATING-0} :
  218. {
  219. ${RELOCATING+ PROVIDE (__data_start = .) ; }
  220. /* --gc-sections will delete empty .data. This leads to wrong start
  221. addresses for subsequent sections because -Tdata= from the command
  222. line will have no effect, see PR13697. Thus, keep .data */
  223. KEEP (*(.data))
  224. ${RELOCATING+${DATA_START_SYMBOLS}}
  225. ${RELOCATING+*(.data.* .gnu.linkonce.d.*)}
  226. ${CONSTRUCTING+SORT(CONSTRUCTORS)}
  227. } ${RELOCATING+ > ${DATA_MEMORY}}
  228. ${GOT}
  229. ${RELOCATING+${CTOR}}
  230. ${RELOCATING+${DTOR}}
  231. ${RELOCATING+${SDATA}}
  232. ${RELOCATING+${SDATA2}}
  233. ${RELOCATING+${SBSS}}
  234. ${RELOCATING+${SBSS2}}
  235. .bss ${RELOCATING-0} :
  236. {
  237. ${RELOCATING+*(.dynbss)}
  238. *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
  239. ${RELOCATING+*(COMMON)
  240. /* Align here to ensure that the .bss section occupies space up to
  241. _end. Align after .bss to ensure correct alignment even if the
  242. .bss section disappears because there are no input sections. */
  243. . = ALIGN(${ALIGNMENT});}
  244. ${RELOCATING+_end = .;}
  245. ${RELOCATING+PROVIDE (end = .);}
  246. } ${RELOCATING+ > ${DATA_MEMORY}}
  247. /* Global data not cleared after reset. */
  248. .noinit ${RELOCATING-0}:
  249. {
  250. *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*})
  251. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  252. ${RELOCATING+ PROVIDE (__start_heap = .) ; }
  253. } ${RELOCATING+ > ${DATA_MEMORY}}
  254. ${RELOCATING+ PROVIDE (__stack_top = (ORIGIN (${DATA_MEMORY}) + LENGTH (${DATA_MEMORY}) - 1) & -4);}
  255. ${RELOCATING+ PROVIDE (__end_heap = ORIGIN (${DATA_MEMORY}) + LENGTH (${DATA_MEMORY}) - 1);}
  256. /* Stabs debugging sections. */
  257. .stab 0 : { *(.stab) }
  258. .stabstr 0 : { *(.stabstr) }
  259. .stab.excl 0 : { *(.stab.excl) }
  260. .stab.exclstr 0 : { *(.stab.exclstr) }
  261. .stab.index 0 : { *(.stab.index) }
  262. .stab.indexstr 0 : { *(.stab.indexstr) }
  263. .comment 0 : { *(.comment) }
  264. .note.gnu.build-id : { *(.note.gnu.build-id) }
  265. EOF
  266. . $srcdir/scripttempl/DWARF.sc
  267. cat <<EOF
  268. /* ARC Extension Sections */
  269. .arcextmap 0 : { *(.arcextmap.*) }
  270. }
  271. EOF