elfarcv2.sc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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} : { *(.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. if test -z "${NO_SMALL_DATA}"; then
  53. SBSS=".sbss ${RELOCATING-0} :
  54. {
  55. ${RELOCATING+PROVIDE (__sbss_start = .);}
  56. ${RELOCATING+PROVIDE (___sbss_start = .);}
  57. *(.dynsbss)
  58. *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
  59. *(.scommon)
  60. ${RELOCATING+PROVIDE (__sbss_end = .);}
  61. ${RELOCATING+PROVIDE (___sbss_end = .);}
  62. } ${RELOCATING+ > ${SDATA_MEMORY}}"
  63. SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) } ${RELOCATING+ > ${SDATA_MEMORY}}"
  64. SDATA="/* We want the small data sections together, so single-instruction offsets
  65. can access them all, and initialized data all before uninitialized, so
  66. we can shorten the on-disk segment size. */
  67. .sdata ${RELOCATING-0} :
  68. {
  69. ${RELOCATING+${SDATA_START_SYMBOLS}}
  70. *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
  71. ${RELOCATING+_edata = .;}
  72. ${RELOCATING+PROVIDE (edata = .);}
  73. } ${RELOCATING+ > ${SDATA_MEMORY}}"
  74. SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) } ${RELOCATING+ > ${SDATA_MEMORY}}"
  75. REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
  76. .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
  77. REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
  78. .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
  79. REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
  80. .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
  81. REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
  82. .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
  83. fi
  84. #
  85. # We provide two emulations: a fixed on that defines some memory banks
  86. # and a configurable one that includes a user provided memory definition.
  87. #
  88. case $GENERIC_BOARD in
  89. yes|1|YES)
  90. MEMORY_DEF="
  91. /* Get memory banks definition from some user configuration file.
  92. This file must be located in some linker directory (search path
  93. with -L<dir>). See fixed memory banks emulation script. */
  94. INCLUDE memory.x;
  95. "
  96. ;;
  97. *)
  98. MEMORY_DEF="
  99. /* Fixed definition of the available memory banks.
  100. See generic emulation script for a user defined configuration. */
  101. MEMORY
  102. {
  103. ICCM : ORIGIN = 0x00000000, LENGTH = ${ICCM_SIZE}
  104. DCCM : ORIGIN = ${RAM_START_ADDR}, LENGTH = ${RAM_SIZE}
  105. }
  106. /* Setup the stack on the top of the data memory bank. */
  107. PROVIDE (__stack_top = (${RAM_START_ADDR} + ${RAM_SIZE} - 1) & -4);
  108. PROVIDE (__end_heap = ${RAM_START_ADDR} + ${RAM_SIZE} - 1);
  109. "
  110. ;;
  111. esac
  112. cat <<EOF
  113. OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", "${LITTLE_OUTPUT_FORMAT}")
  114. OUTPUT_ARCH(${OUTPUT_ARCH})
  115. ${RELOCATING+ENTRY(${ENTRY})}
  116. ${RELOCATING+${LIB_SEARCH_DIRS}}
  117. ${RELOCATING+${EXECUTABLE_SYMBOLS}}
  118. ${RELOCATING+${MEMORY_DEF}}
  119. SECTIONS
  120. {
  121. .ivt 0x00 :
  122. {
  123. KEEP (*(.ivt));
  124. } ${RELOCATING+ > ${STARTUP_MEMORY}}
  125. .startup 0x100:
  126. {
  127. KEEP (*crt0.o(.text.__startup))
  128. } ${RELOCATING+ > ${STARTUP_MEMORY}}
  129. /* Read-only sections, merged into text segment: */
  130. ${TEXT_DYNAMIC+${DYNAMIC}}
  131. .hash ${RELOCATING-0} : { *(.hash) }
  132. .dynsym ${RELOCATING-0} : { *(.dynsym) }
  133. .dynstr ${RELOCATING-0} : { *(.dynstr) }
  134. .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
  135. .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) }
  136. .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) }
  137. .rel.init ${RELOCATING-0} : { *(.rel.init) }
  138. .rela.init ${RELOCATING-0} : { *(.rela.init) }
  139. .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
  140. .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
  141. .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
  142. .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
  143. .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
  144. .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
  145. .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
  146. .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
  147. .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
  148. .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
  149. .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
  150. .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
  151. .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
  152. .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
  153. .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
  154. .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
  155. .rel.got ${RELOCATING-0} : { *(.rel.got) }
  156. .rela.got ${RELOCATING-0} : { *(.rela.got) }
  157. ${REL_SDATA}
  158. ${REL_SBSS}
  159. ${REL_SDATA2}
  160. ${REL_SBSS2}
  161. .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
  162. .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
  163. .jcr : { KEEP (*(.jcr)) } ${RELOCATING+> ${TEXT_MEMORY}}
  164. .eh_frame : { KEEP (*(.eh_frame)) } ${RELOCATING+> ${TEXT_MEMORY}}
  165. .gcc_except_table : { *(.gcc_except_table) *(.gcc_except_table.*) } ${RELOCATING+> ${TEXT_MEMORY}}
  166. .plt : { *(.plt) } ${RELOCATING+> ${TEXT_MEMORY}}
  167. .rodata ${RELOCATING-0} :
  168. {
  169. *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)}
  170. } ${RELOCATING+> ${TEXT_MEMORY}}
  171. .rodata1 ${RELOCATING-0} : { *(.rodata1) } ${RELOCATING+> ${TEXT_MEMORY}}
  172. .init ${RELOCATING-0} :
  173. {
  174. ${RELOCATING+${INIT_START}}
  175. KEEP (*(.init))
  176. ${RELOCATING+${INIT_END}}
  177. } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
  178. .text ${RELOCATING-0} :
  179. {
  180. ${RELOCATING+${TEXT_START_SYMBOLS}}
  181. *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
  182. /* .gnu.warning sections are handled specially by elf32.em. */
  183. *(.gnu.warning)
  184. ${RELOCATING+${OTHER_TEXT_SECTIONS}}
  185. } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
  186. .fini ${RELOCATING-0} :
  187. {
  188. ${RELOCATING+${FINI_START}}
  189. KEEP (*(.fini))
  190. ${RELOCATING+${FINI_END}}
  191. ${RELOCATING+PROVIDE (__etext = .);}
  192. ${RELOCATING+PROVIDE (_etext = .);}
  193. ${RELOCATING+PROVIDE (etext = .);}
  194. } ${RELOCATING+ > ${TEXT_MEMORY}} =${NOP-0}
  195. ${RELOCATING+${OTHER_READONLY_SECTIONS}}
  196. /* Start of the data section image in ROM. */
  197. ${RELOCATING+__data_image = .;}
  198. ${RELOCATING+PROVIDE (__data_image = .);}
  199. .data ${RELOCATING-0} :
  200. {
  201. ${RELOCATING+ PROVIDE (__data_start = .) ; }
  202. /* --gc-sections will delete empty .data. This leads to wrong start
  203. addresses for subsequent sections because -Tdata= from the command
  204. line will have no effect, see PR13697. Thus, keep .data */
  205. KEEP (*(.data))
  206. ${RELOCATING+${DATA_START_SYMBOLS}}
  207. *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
  208. ${CONSTRUCTING+SORT(CONSTRUCTORS)}
  209. } ${RELOCATING+ > ${DATA_MEMORY}}
  210. ${GOT}
  211. ${RELOCATING+${CTOR}}
  212. ${RELOCATING+${DTOR}}
  213. ${RELOCATING+${SDATA}}
  214. ${RELOCATING+${SDATA2}}
  215. ${RELOCATING+${SBSS}}
  216. ${RELOCATING+${SBSS2}}
  217. .bss ${RELOCATING-0} :
  218. {
  219. *(.dynbss)
  220. *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
  221. *(COMMON)
  222. /* Align here to ensure that the .bss section occupies space up to
  223. _end. Align after .bss to ensure correct alignment even if the
  224. .bss section disappears because there are no input sections. */
  225. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  226. ${RELOCATING+_end = .;}
  227. ${RELOCATING+PROVIDE (end = .);}
  228. } ${RELOCATING+ > ${DATA_MEMORY}}
  229. /* Global data not cleared after reset. */
  230. .noinit ${RELOCATING-0}:
  231. {
  232. *(.noinit*)
  233. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  234. ${RELOCATING+ PROVIDE (__start_heap = .) ; }
  235. } ${RELOCATING+ > ${DATA_MEMORY}}
  236. /* Stabs debugging sections. */
  237. .stab 0 : { *(.stab) }
  238. .stabstr 0 : { *(.stabstr) }
  239. .stab.excl 0 : { *(.stab.excl) }
  240. .stab.exclstr 0 : { *(.stab.exclstr) }
  241. .stab.index 0 : { *(.stab.index) }
  242. .stab.indexstr 0 : { *(.stab.indexstr) }
  243. .comment 0 : { *(.comment) }
  244. /* DWARF debug sections.
  245. Symbols in the DWARF debugging sections are relative to the beginning
  246. of the section so we begin them at 0. */
  247. /* DWARF 1 */
  248. .debug 0 : { *(.debug) }
  249. .line 0 : { *(.line) }
  250. /* GNU DWARF 1 extensions */
  251. .debug_srcinfo 0 : { *(.debug_srcinfo) }
  252. .debug_sfnames 0 : { *(.debug_sfnames) }
  253. /* DWARF 1.1 and DWARF 2 */
  254. .debug_aranges 0 : { *(.debug_aranges) }
  255. .debug_pubnames 0 : { *(.debug_pubnames) }
  256. /* DWARF 2 */
  257. .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
  258. .debug_abbrev 0 : { *(.debug_abbrev) }
  259. .debug_line 0 : { *(.debug_line) }
  260. .debug_frame 0 : { *(.debug_frame) }
  261. .debug_str 0 : { *(.debug_str) }
  262. .debug_loc 0 : { *(.debug_loc) }
  263. .debug_macinfo 0 : { *(.debug_macinfo) }
  264. /* DWARF 3 */
  265. .debug_pubtypes 0 : { *(.debug_pubtypes) }
  266. .debug_ranges 0 : { *(.debug_ranges) }
  267. /* DWARF Extension. */
  268. .debug_macro 0 : { *(.debug_macro) }
  269. /* ARC Extension Sections */
  270. .arcextmap 0 : { *(.gnu.linkonce.arcextmap.*) }
  271. }
  272. EOF