xstormy16.sc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 - two byte opcode for no-op (defaults to 0)
  9. # INITIAL_READONLY_SECTIONS - at start of text segment
  10. # OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
  11. # (e.g., .PARISC.milli)
  12. # OTHER_TEXT_SECTIONS - these get put in .text when relocating
  13. # OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
  14. # (e.g., .PARISC.global)
  15. # OTHER_SECTIONS - at the end
  16. # EXECUTABLE_SYMBOLS - symbols that must be defined for an
  17. # executable (e.g., _DYNAMIC_LINK)
  18. # TEXT_START_SYMBOLS - symbols that appear at the start of the
  19. # .text section.
  20. # DATA_START_SYMBOLS - symbols that appear at the start of the
  21. # .data section.
  22. # OTHER_GOT_SYMBOLS - symbols defined just before .got.
  23. # OTHER_GOT_SECTIONS - sections just after .got and .sdata.
  24. # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
  25. # .bss section besides __bss_start.
  26. # INPUT_FILES - INPUT command of files to always include
  27. # INIT_START, INIT_END - statements just before and just after
  28. # combination of .init sections.
  29. # FINI_START, FINI_END - statements just before and just after
  30. # combination of .fini sections.
  31. #
  32. # When adding sections, do note that the names of some sections are used
  33. # when specifying the start address of the next.
  34. #
  35. # Many sections come in three flavours. There is the 'real' section,
  36. # like ".data". Then there are the per-procedure or per-variable
  37. # sections, generated by -ffunction-sections and -fdata-sections in GCC,
  38. # and useful for --gc-sections, which for a variable "foo" might be
  39. # ".data.foo". Then there are the linkonce sections, for which the linker
  40. # eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
  41. # The exact correspondences are:
  42. #
  43. # Section Linkonce section
  44. # .text .gnu.linkonce.t.foo
  45. # .rodata .gnu.linkonce.r.foo
  46. # .data .gnu.linkonce.d.foo
  47. # .bss .gnu.linkonce.b.foo
  48. # .sdata .gnu.linkonce.s.foo
  49. # .sbss .gnu.linkonce.sb.foo
  50. # .sdata2 .gnu.linkonce.s2.foo
  51. # .sbss2 .gnu.linkonce.sb2.foo
  52. #
  53. # Each of these can also have corresponding .rel.* and .rela.* sections.
  54. test -z "$ENTRY" && ENTRY=_start
  55. test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  56. test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  57. if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
  58. test -z "${ELFSIZE}" && ELFSIZE=32
  59. test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
  60. CTOR=".ctors ${CONSTRUCTING-0} :
  61. {
  62. ${CONSTRUCTING+${CTOR_START}}
  63. /* gcc uses crtbegin.o to find the start of
  64. the constructors, so we make sure it is
  65. first. Because this is a wildcard, it
  66. doesn't matter if the user does not
  67. actually link against crtbegin.o; the
  68. linker won't look for a file to match a
  69. wildcard. The wildcard also means that it
  70. doesn't matter which directory crtbegin.o
  71. is in. */
  72. KEEP (*crtbegin.o(.ctors))
  73. KEEP (*crtbegin?.o(.ctors))
  74. /* We don't want to include the .ctor section from
  75. the crtend.o file until after the sorted ctors.
  76. The .ctor section from the crtend file contains the
  77. end of ctors marker and it must be last */
  78. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
  79. KEEP (*(SORT(.ctors.*)))
  80. KEEP (*(.ctors))
  81. ${CONSTRUCTING+${CTOR_END}}
  82. } > ROM"
  83. DTOR=" .dtors ${CONSTRUCTING-0} :
  84. {
  85. ${CONSTRUCTING+${DTOR_START}}
  86. KEEP (*crtbegin.o(.dtors))
  87. KEEP (*crtbegin?.o(.dtors))
  88. KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
  89. KEEP (*(SORT(.dtors.*)))
  90. KEEP (*(.dtors))
  91. ${CONSTRUCTING+${DTOR_END}}
  92. } > ROM"
  93. cat <<EOF
  94. /* Copyright (C) 2014-2015 Free Software Foundation, Inc.
  95. Copying and distribution of this script, with or without modification,
  96. are permitted in any medium without royalty provided the copyright
  97. notice and this notice are preserved. */
  98. OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
  99. "${LITTLE_OUTPUT_FORMAT}")
  100. OUTPUT_ARCH(${OUTPUT_ARCH})
  101. ${RELOCATING+ENTRY(${ENTRY})}
  102. ${RELOCATING+${LIB_SEARCH_DIRS}}
  103. ${RELOCATING+${EXECUTABLE_SYMBOLS}}
  104. ${RELOCATING+${INPUT_FILES}}
  105. ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
  106. if gld -r is used and the intermediate file has sections starting
  107. at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
  108. bug. But for now assigning the zero vmas works. */}
  109. /* There are two memory regions we care about, one from 0 through 0x7F00
  110. that is RAM and one from 0x8000 up which is ROM. */
  111. MEMORY
  112. {
  113. RAM (w) : ORIGIN = 0, LENGTH = 0x7F00
  114. ROM (!w) : ORIGIN = 0x8000, LENGTH = 0xFF8000
  115. }
  116. SECTIONS
  117. {
  118. .data ${RELOCATING-0} :
  119. {
  120. ${RELOCATING+__rdata = .;}
  121. ${RELOCATING+__data = .;}
  122. ${RELOCATING+${DATA_START_SYMBOLS}}
  123. *(.data)
  124. ${RELOCATING+*(.data.*)}
  125. ${RELOCATING+*(.gnu.linkonce.d.*)}
  126. ${CONSTRUCTING+SORT(CONSTRUCTORS)}
  127. } > RAM
  128. ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
  129. ${RELOCATING+${OTHER_GOT_SYMBOLS}}
  130. ${RELOCATING+${OTHER_GOT_SECTIONS}}
  131. ${RELOCATING+_edata = .;}
  132. ${RELOCATING+PROVIDE (edata = .);}
  133. ${RELOCATING+__bss_start = .;}
  134. ${RELOCATING+${OTHER_BSS_SYMBOLS}}
  135. .bss ${RELOCATING-0} :
  136. {
  137. *(.dynbss)
  138. *(.bss)
  139. ${RELOCATING+*(.bss.*)}
  140. ${RELOCATING+*(.gnu.linkonce.b.*)}
  141. *(COMMON)
  142. /* Align here to ensure that the .bss section occupies space up to
  143. _end. Align after .bss to ensure correct alignment even if the
  144. .bss section disappears because there are no input sections. */
  145. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  146. } > RAM
  147. ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
  148. ${RELOCATING+. = ALIGN(${ALIGNMENT});}
  149. ${RELOCATING+${OTHER_END_SYMBOLS}}
  150. ${RELOCATING+_end = .;}
  151. ${RELOCATING+__stack = .;}
  152. ${RELOCATING+PROVIDE (end = .);}
  153. /* Read-only sections in ROM. */
  154. .int_vec ${RELOCATING-0} : { *(.int_vec) } ${RELOCATING+> ROM}
  155. .rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)} } ${RELOCATING+> ROM}
  156. ${RELOCATING+${CTOR}}
  157. ${RELOCATING+${DTOR}}
  158. .jcr : { KEEP (*(.jcr)) } ${RELOCATING+> ROM}
  159. .eh_frame : { KEEP (*(.eh_frame)) } ${RELOCATING+> ROM}
  160. .gcc_except_table : { *(.gcc_except_table) *(.gcc_except_table.*) } ${RELOCATING+> ROM}
  161. .plt : { *(.plt) } ${RELOCATING+> ROM}
  162. .text ${RELOCATING-0} :
  163. {
  164. ${RELOCATING+${TEXT_START_SYMBOLS}}
  165. *(.text)
  166. ${RELOCATING+*(.text.*)}
  167. *(.stub)
  168. /* .gnu.warning sections are handled specially by elf32.em. */
  169. *(.gnu.warning)
  170. ${RELOCATING+*(.gnu.linkonce.t.*)}
  171. ${RELOCATING+${OTHER_TEXT_SECTIONS}}
  172. } ${RELOCATING+> ROM =${NOP-0}}
  173. .init ${RELOCATING-0} :
  174. {
  175. ${RELOCATING+${INIT_START}}
  176. KEEP (*(.init))
  177. ${RELOCATING+${INIT_END}}
  178. } ${RELOCATING+> ROM =${NOP-0}}
  179. .fini ${RELOCATING-0} :
  180. {
  181. ${RELOCATING+${FINI_START}}
  182. KEEP (*(.fini))
  183. ${RELOCATING+${FINI_END}}
  184. } ${RELOCATING+> ROM =${NOP-0}}
  185. ${RELOCATING+PROVIDE (__etext = .);}
  186. ${RELOCATING+PROVIDE (_etext = .);}
  187. ${RELOCATING+PROVIDE (etext = .);}
  188. ${RELOCATING+${OTHER_READONLY_SECTIONS}}
  189. /* Stabs debugging sections. */
  190. .stab 0 : { *(.stab) }
  191. .stabstr 0 : { *(.stabstr) }
  192. .stab.excl 0 : { *(.stab.excl) }
  193. .stab.exclstr 0 : { *(.stab.exclstr) }
  194. .stab.index 0 : { *(.stab.index) }
  195. .stab.indexstr 0 : { *(.stab.indexstr) }
  196. .comment 0 : { *(.comment) }
  197. EOF
  198. . $srcdir/scripttempl/DWARF.sc
  199. cat <<EOF
  200. ${RELOCATING+${OTHER_RELOCATING_SECTIONS}}
  201. /* These must appear regardless of ${RELOCATING}. */
  202. ${OTHER_SECTIONS}
  203. }
  204. EOF