elf32sh-symbian.sc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 text 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. # ATTRS_SECTIONS - at the end
  17. # OTHER_SECTIONS - at the end
  18. # EXECUTABLE_SYMBOLS - symbols that must be defined for an
  19. # executable (e.g., _DYNAMIC_LINK)
  20. # TEXT_START_SYMBOLS - symbols that appear at the start of the
  21. # .text section.
  22. # DATA_START_SYMBOLS - symbols that appear at the start of the
  23. # .data section.
  24. # OTHER_GOT_SYMBOLS - symbols defined just before .got.
  25. # OTHER_GOT_SECTIONS - sections just after .got.
  26. # OTHER_SDATA_SECTIONS - sections just after .sdata.
  27. # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
  28. # .bss section besides __bss_start.
  29. # DATA_PLT - .plt should be in data segment, not text segment.
  30. # BSS_PLT - .plt should be in bss segment
  31. # TEXT_DYNAMIC - .dynamic in text segment, not data segment.
  32. # EMBEDDED - whether this is for an embedded system.
  33. # SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
  34. # start address of shared library.
  35. # INPUT_FILES - INPUT command of files to always include
  36. # WRITABLE_RODATA - if set, the .rodata section should be writable
  37. # INIT_START, INIT_END - statements just before and just after
  38. # combination of .init sections.
  39. # FINI_START, FINI_END - statements just before and just after
  40. # combination of .fini sections.
  41. # STACK_ADDR - start of a .stack section.
  42. # OTHER_SYMBOLS - symbols to place right at the end of the script.
  43. #
  44. # When adding sections, do note that the names of some sections are used
  45. # when specifying the start address of the next.
  46. #
  47. # Many sections come in three flavours. There is the 'real' section,
  48. # like ".data". Then there are the per-procedure or per-variable
  49. # sections, generated by -ffunction-sections and -fdata-sections in GCC,
  50. # and useful for --gc-sections, which for a variable "foo" might be
  51. # ".data.foo". Then there are the linkonce sections, for which the linker
  52. # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
  53. # The exact correspondences are:
  54. #
  55. # Section Linkonce section
  56. # .text .gnu.linkonce.t.foo
  57. # .rodata .gnu.linkonce.r.foo
  58. # .data .gnu.linkonce.d.foo
  59. # .bss .gnu.linkonce.b.foo
  60. # .sdata .gnu.linkonce.s.foo
  61. # .sbss .gnu.linkonce.sb.foo
  62. # .sdata2 .gnu.linkonce.s2.foo
  63. # .sbss2 .gnu.linkonce.sb2.foo
  64. # .debug_info .gnu.linkonce.wi.foo
  65. # .tdata .gnu.linkonce.td.foo
  66. # .tbss .gnu.linkonce.tb.foo
  67. #
  68. # Each of these can also have corresponding .rel.* and .rela.* sections.
  69. test -z "$ENTRY" && ENTRY=_start
  70. test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  71. test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  72. if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
  73. test -z "${ELFSIZE}" && ELFSIZE=32
  74. test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
  75. test "$LD_FLAG" = "N" && DATA_ADDR=.
  76. test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
  77. test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
  78. test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }"
  79. DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
  80. DATA_SEGMENT_END=""
  81. if test -n "${COMMONPAGESIZE}"; then
  82. DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
  83. DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
  84. fi
  85. INTERP=".interp ALIGN(4) : { *(.interp) }"
  86. PLT=".plt : { *(.plt) } :dynamic :dyn"
  87. DYNAMIC=".dynamic : { *(.dynamic) } :dynamic :dyn"
  88. RODATA=".rodata ALIGN(4) : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
  89. DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.directive) *(.gnu.lto_*) }"
  90. test -z "$GOT" && GOT=".got ${RELOCATING-0} : { *(.got.plt) *(.got) } :dynamic :dyn"
  91. INIT_ARRAY=".init_array ${RELOCATING-0} :
  92. {
  93. ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__init_array_start = .);}}
  94. KEEP (*(SORT(.init_array.*)))
  95. KEEP (*(.init_array))
  96. ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__init_array_end = .);}}
  97. }"
  98. FINI_ARRAY=".fini_array ${RELOCATING-0} :
  99. {
  100. ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__fini_array_start = .);}}
  101. KEEP (*(SORT(.fini_array.*)))
  102. KEEP (*(.fini_array))
  103. ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__fini_array_end = .);}}
  104. }"
  105. CTOR=".ctors ALIGN(4) :
  106. {
  107. ${CONSTRUCTING+${CTOR_START}}
  108. /* gcc uses crtbegin.o to find the start of
  109. the constructors, so we make sure it is
  110. first. Because this is a wildcard, it
  111. doesn't matter if the user does not
  112. actually link against crtbegin.o; the
  113. linker won't look for a file to match a
  114. wildcard. The wildcard also means that it
  115. doesn't matter which directory crtbegin.o
  116. is in. */
  117. KEEP (*crtbegin.o(.ctors))
  118. KEEP (*crtbegin?.o(.ctors))
  119. /* We don't want to include the .ctor section from
  120. the crtend.o file until after the sorted ctors.
  121. The .ctor section from the crtend file contains the
  122. end of ctors marker and it must be last */
  123. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
  124. KEEP (*(SORT(.ctors.*)))
  125. KEEP (*(.ctors))
  126. ${CONSTRUCTING+${CTOR_END}}
  127. } :text"
  128. DTOR=".dtors ALIGN(4) :
  129. {
  130. ${CONSTRUCTING+${DTOR_START}}
  131. KEEP (*crtbegin.o(.dtors))
  132. KEEP (*crtbegin?.o(.dtors))
  133. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
  134. KEEP (*(SORT(.dtors.*)))
  135. KEEP (*(.dtors))
  136. ${CONSTRUCTING+${DTOR_END}}
  137. } :text"
  138. STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
  139. {
  140. ${RELOCATING+_stack = .;}
  141. *(.stack)
  142. } :data"
  143. # If this is for an embedded system, don't add SIZEOF_HEADERS.
  144. if [ -z "$EMBEDDED" ]; then
  145. test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
  146. else
  147. test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
  148. fi
  149. cat <<EOF
  150. /* Copyright (C) 2014-2015 Free Software Foundation, Inc.
  151. Copying and distribution of this script, with or without modification,
  152. are permitted in any medium without royalty provided the copyright
  153. notice and this notice are preserved. */
  154. OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
  155. "${LITTLE_OUTPUT_FORMAT}")
  156. OUTPUT_ARCH(${OUTPUT_ARCH})
  157. ${RELOCATING+ENTRY(${ENTRY})}
  158. ${RELOCATING+${LIB_SEARCH_DIRS}}
  159. ${RELOCATING+/* Do we need any of these for elf?
  160. __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
  161. ${RELOCATING+${EXECUTABLE_SYMBOLS}}
  162. ${RELOCATING+${INPUT_FILES}}
  163. ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
  164. if gld -r is used and the intermediate file has sections starting
  165. at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
  166. bug. But for now assigning the zero vmas works. */}
  167. PHDRS
  168. {
  169. headers PT_PHDR PHDRS ;
  170. text PT_LOAD ;
  171. data PT_LOAD ;
  172. dyn PT_LOAD FLAGS (0) ;
  173. dynamic PT_DYNAMIC ;
  174. }
  175. SECTIONS
  176. {
  177. /* Read-only sections, merged into text segment: */
  178. ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}}
  179. ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
  180. ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0};}}
  181. ${CREATE_SHLIB-${INTERP}}
  182. ${INITIAL_READONLY_SECTIONS}
  183. .init ALIGN(4) :
  184. {
  185. ${RELOCATING+${INIT_START}}
  186. KEEP (*(.init))
  187. ${RELOCATING+${INIT_END}}
  188. } :text =${NOP-0}
  189. .text ALIGN(4) :
  190. {
  191. ${RELOCATING+${TEXT_START_SYMBOLS}}
  192. *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
  193. /* .gnu.warning sections are handled specially by elf32.em. */
  194. *(.gnu.warning)
  195. ${RELOCATING+${OTHER_TEXT_SECTIONS}}
  196. } =${NOP-0}
  197. ${RELOCATING+${CTOR}}
  198. ${RELOCATING+${DTOR}}
  199. .fini ALIGN(4) :
  200. {
  201. ${RELOCATING+${FINI_START}}
  202. KEEP (*(.fini))
  203. ${RELOCATING+${FINI_END}}
  204. } =${NOP-0}
  205. ${RELOCATING+PROVIDE (__etext = .);}
  206. ${RELOCATING+PROVIDE (_etext = .);}
  207. ${RELOCATING+PROVIDE (etext = .);}
  208. ${WRITABLE_RODATA-${RODATA}}
  209. .rodata1 ALIGN(4) : { *(.rodata1) }
  210. ExportTable ALIGN(4) : { KEEP (*(ExportTable)) }
  211. .eh_frame_hdr ALIGN(4) : { *(.eh_frame_hdr) } :text
  212. /* Adjust the address for the data segment. We want to adjust up to
  213. the same address within the page on the next page up. */
  214. . = ALIGN(128) + (. & (128 - 1));
  215. .preinit_array ${RELOCATING-0} :
  216. {
  217. ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__preinit_array_start = .);}}
  218. KEEP (*(.preinit_array))
  219. ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (__preinit_array_end = .);}}
  220. }
  221. ${RELOCATING+${INIT_ARRAY}}
  222. ${RELOCATING+${FINI_ARRAY}}
  223. ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
  224. ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
  225. ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
  226. .data ALIGN(4) :
  227. {
  228. ${RELOCATING+${DATA_START_SYMBOLS}}
  229. *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
  230. ${CONSTRUCTING+SORT(CONSTRUCTORS)}
  231. } :data
  232. .data1 ALIGN(4) : { *(.data1) } :data
  233. .tdata ALIGN(4) : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) } :data
  234. .tbss ALIGN(4) : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} } :data
  235. .eh_frame ALIGN(4) : { KEEP (*(.eh_frame)) } :data
  236. .gcc_except_table ALIGN(4) : { *(.gcc_except_table) } :data
  237. ${WRITABLE_RODATA+${RODATA}}
  238. ${OTHER_READWRITE_SECTIONS}
  239. ${SDATA}
  240. ${OTHER_SDATA_SECTIONS}
  241. ${RELOCATING+_edata = .;}
  242. ${RELOCATING+PROVIDE (edata = .);}
  243. ${RELOCATING+__bss_start = .;}
  244. ${RELOCATING+${OTHER_BSS_SYMBOLS}}
  245. ${BSS_PLT+${PLT}}
  246. .bss ALIGN(4) :
  247. {
  248. *(.dynbss)
  249. *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
  250. *(COMMON)
  251. /* Align here to ensure that the .bss section occupies space up to
  252. _end. Align after .bss to ensure correct alignment even if the
  253. .bss section disappears because there are no input sections. */
  254. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  255. } :data
  256. ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
  257. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  258. ${RELOCATING+${OTHER_END_SYMBOLS}}
  259. ${RELOCATING+_end = .;}
  260. ${RELOCATING+PROVIDE (end = .);}
  261. ${RELOCATING+${DATA_SEGMENT_END}}
  262. ${TEXT_DYNAMIC-${DYNAMIC}}
  263. ${TEXT_DYNAMIC+${DYNAMIC}}
  264. .hash ${RELOCATING-0} : { *(.hash) } :dynamic :dyn
  265. .dynsym ${RELOCATING-0} : { *(.dynsym) } :dynamic :dyn
  266. .dynstr ${RELOCATING-0} : { *(.dynstr) } :dynamic :dyn
  267. ${DATA_PLT-${BSS_PLT-${PLT}}}
  268. .got.plt : { *(.got.plt) } :dynamic :dyn
  269. .gnu.version ${RELOCATING-0} : { *(.gnu.version) }
  270. .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
  271. .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
  272. EOF
  273. if [ "x$COMBRELOC" = x ]; then
  274. COMBRELOCCAT=cat
  275. else
  276. COMBRELOCCAT="cat > $COMBRELOC"
  277. fi
  278. eval $COMBRELOCCAT <<EOF
  279. .rel.init ${RELOCATING-0} : { *(.rel.init) }
  280. .rela.init ${RELOCATING-0} : { *(.rela.init) }
  281. .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
  282. .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
  283. .rel.fini ${RELOCATING-0} : { *(.rel.fini) }
  284. .rela.fini ${RELOCATING-0} : { *(.rela.fini) }
  285. .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
  286. .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
  287. ${OTHER_READONLY_RELOC_SECTIONS}
  288. .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
  289. .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
  290. .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
  291. .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
  292. .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
  293. .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
  294. .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
  295. .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
  296. .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
  297. .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
  298. .rel.got ${RELOCATING-0} : { *(.rel.got) }
  299. .rela.got ${RELOCATING-0} : { *(.rela.got) }
  300. ${OTHER_GOT_RELOC_SECTIONS}
  301. .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
  302. .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
  303. EOF
  304. if [ -n "$COMBRELOC" ]; then
  305. cat <<EOF
  306. .rel.dyn ${RELOCATING-0} :
  307. {
  308. EOF
  309. sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC
  310. cat <<EOF
  311. }
  312. .rela.dyn ${RELOCATING-0} :
  313. {
  314. EOF
  315. sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC
  316. cat <<EOF
  317. }
  318. EOF
  319. fi
  320. cat <<EOF
  321. .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
  322. .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
  323. ${OTHER_PLT_RELOC_SECTIONS}
  324. /* Stabs debugging sections. */
  325. .stab 0 : { *(.stab) }
  326. .stabstr 0 : { *(.stabstr) }
  327. .stab.excl 0 : { *(.stab.excl) }
  328. .stab.exclstr 0 : { *(.stab.exclstr) }
  329. .stab.index 0 : { *(.stab.index) }
  330. .stab.indexstr 0 : { *(.stab.indexstr) }
  331. .comment 0 : { *(.comment) }
  332. EOF
  333. . $srcdir/scripttempl/DWARF.sc
  334. cat <<EOF
  335. ${STACK_ADDR+${STACK}}
  336. ${ATTRS_SECTIONS}
  337. ${OTHER_SECTIONS}
  338. ${RELOCATING+${OTHER_SYMBOLS}}
  339. ${RELOCATING+${DISCARDED}}
  340. }
  341. EOF