lnkscript 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* Linker Script Original v1.3 by Jeff Frohwein */
  2. /* v1.0 - Original release */
  3. /* v1.1 - Added proper .data section support */
  4. /* v1.2 - Added support for c++ & iwram overlays */
  5. /* - Major contributions by Jason Wilkins. */
  6. /* v1.3 - .ewram section now can be used when */
  7. /* compiling for MULTIBOOT mode. This fixes */
  8. /* malloc() in DevKitAdvance which depends */
  9. /* on __eheap_start instead of end to define*/
  10. /* the starting location of heap space. */
  11. /* External global variable __gba_iwram_heap*/
  12. /* support added to allow labels end, _end, */
  13. /* & __end__ to point to end of iwram or */
  14. /* the end of ewram. */
  15. /* Additions by WinterMute */
  16. /* v1.4 - .sbss section added for unitialised */
  17. /* data in ewram */
  18. /* v1.5 - padding section added to stop EZF */
  19. /* stripping important data */
  20. /* This file is released into the public domain */
  21. /* for commercial or non-commercial use with no */
  22. /* restrictions placed upon it. */
  23. /* NOTE!!!: This linker script defines the RAM & */
  24. /* ROM start addresses. In order for it to work */
  25. /* properly, remove -Ttext and -Tbss linker */
  26. /* options from your makefile if they are */
  27. /* present. */
  28. /* You can use the following to view section */
  29. /* addresses in your .elf file: */
  30. /* objdump -h file.elf */
  31. /* Please note that empty sections may incorrectly*/
  32. /* list the lma address as the vma address for */
  33. /* some versions of objdump. */
  34. OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
  35. OUTPUT_ARCH(arm)
  36. ENTRY(_start)
  37. /* SEARCH_DIR(/bin/arm); */
  38. /* The linker script function "var1 += var2;" sometimes */
  39. /* reports incorrect values in the *.map file but the */
  40. /* actual value it calculates is usually, if not always, */
  41. /* correct. If you leave out the ". = ALIGN(4);" at the */
  42. /* end of each section then the return value of SIZEOF() */
  43. /* is sometimes incorrect and "var1 += var2;" appears to */
  44. /* not work as well. "var1 += var2" style functions are */
  45. /* avoided below as a result. */
  46. MEMORY {
  47. rom : ORIGIN = 0x08000000, LENGTH = 32M
  48. iwram : ORIGIN = 0x03000000, LENGTH = 32K
  49. ewram : ORIGIN = 0x02000000, LENGTH = 256K
  50. }
  51. /*
  52. __text_start = 0x8000000;
  53. __eheap_end = 0x2040000;
  54. __iwram_start = 0x3000000;
  55. __iwram_end = 0x3008000;
  56. __sp_irq = __iwram_end - 0x100;
  57. __sp_usr = __sp_irq - 0x100;
  58. */
  59. __text_start = ORIGIN(rom);
  60. /* __eheap_end = ORIGIN(ewram) + 0x40000; */
  61. __eheap_end = ORIGIN(ewram) + LENGTH(ewram);
  62. __iwram_start = ORIGIN(iwram);
  63. /* __iwram_end = ORIGIN(iwram) + 0x8000; */
  64. __iwram_end = ORIGIN(iwram) + LENGTH(iwram);
  65. __sp_irq = __iwram_end - 0x100;
  66. __sp_usr = __sp_irq - 0x100;
  67. SECTIONS
  68. {
  69. . = __text_start;
  70. .init :
  71. {
  72. KEEP (*(.init))
  73. . = ALIGN(4);
  74. } >rom =0xff
  75. .plt :
  76. {
  77. *(.plt)
  78. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  79. } >rom
  80. .text : /* ALIGN (4): */
  81. {
  82. *(EXCLUDE_FILE (*.iwram*) .text)
  83. *(.text.*)
  84. *(.stub)
  85. /* .gnu.warning sections are handled specially by elf32.em. */
  86. *(.gnu.warning)
  87. *(.gnu.linkonce.t*)
  88. *(.glue_7)
  89. *(.glue_7t)
  90. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  91. } >rom = 0xff
  92. __text_end = .;
  93. .fini :
  94. {
  95. KEEP (*(.fini))
  96. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  97. } >rom =0
  98. .rodata :
  99. {
  100. *(.rodata)
  101. *all.rodata*(*)
  102. *(.roda)
  103. *(.rodata.*)
  104. *(.gnu.linkonce.r*)
  105. SORT(CONSTRUCTORS)
  106. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  107. } >rom = 0xff
  108. .ctors :
  109. {
  110. /* gcc uses crtbegin.o to find the start of the constructors, so
  111. we make sure it is first. Because this is a wildcard, it
  112. doesn't matter if the user does not actually link against
  113. crtbegin.o; the linker won't look for a file to match a
  114. wildcard. The wildcard also means that it doesn't matter which
  115. directory crtbegin.o is in. */
  116. KEEP (*crtbegin.o(.ctors))
  117. KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
  118. KEEP (*(SORT(.ctors.*)))
  119. KEEP (*(.ctors))
  120. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  121. } >rom = 0
  122. .dtors :
  123. {
  124. KEEP (*crtbegin.o(.dtors))
  125. KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
  126. KEEP (*(SORT(.dtors.*)))
  127. KEEP (*(.dtors))
  128. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  129. } >rom = 0
  130. .jcr : { KEEP (*(.jcr)) } >rom
  131. .eh_frame :
  132. {
  133. KEEP (*(.eh_frame))
  134. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  135. } >rom = 0
  136. .gcc_except_table :
  137. {
  138. *(.gcc_except_table)
  139. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  140. } >rom = 0
  141. __iwram_lma = .;
  142. .iwram __iwram_start : AT (__iwram_lma)
  143. {
  144. __iwram_start = ABSOLUTE(.) ;
  145. *(.iwram)
  146. *iwram.*(.text)
  147. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  148. } >iwram = 0xff
  149. __data_lma = __iwram_lma + SIZEOF(.iwram) ;
  150. __iwram_end = . ;
  151. .bss ALIGN(4) :
  152. {
  153. __bss_start = ABSOLUTE(.);
  154. __bss_start__ = ABSOLUTE(.);
  155. *(.dynbss)
  156. *(.gnu.linkonce.b*)
  157. *(.bss*)
  158. *(COMMON)
  159. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  160. } >iwram
  161. __bss_end = . ;
  162. __bss_end__ = . ;
  163. .data ALIGN(4) : AT (__data_lma)
  164. {
  165. __data_start = ABSOLUTE(.);
  166. *(.data)
  167. *(.data.*)
  168. *(.gnu.linkonce.d*)
  169. CONSTRUCTORS
  170. . = ALIGN(4);
  171. } >iwram = 0xff
  172. __iwram_overlay_lma = __data_lma + SIZEOF(.data);
  173. __data_end = .;
  174. __iwram_overlay_start = . ;
  175. OVERLAY ALIGN(4) : NOCROSSREFS AT (__iwram_overlay_lma)
  176. {
  177. .iwram0 { *(.iwram0) . = ALIGN(4);}
  178. .iwram1 { *(.iwram1) . = ALIGN(4);}
  179. .iwram2 { *(.iwram2) . = ALIGN(4);}
  180. .iwram3 { *(.iwram3) . = ALIGN(4);}
  181. .iwram4 { *(.iwram4) . = ALIGN(4);}
  182. .iwram5 { *(.iwram5) . = ALIGN(4);}
  183. .iwram6 { *(.iwram6) . = ALIGN(4);}
  184. .iwram7 { *(.iwram7) . = ALIGN(4);}
  185. .iwram8 { *(.iwram8) . = ALIGN(4);}
  186. .iwram9 { *(.iwram9) . = ALIGN(4);}
  187. }>iwram = 0xff
  188. __ewram_lma = LOADADDR(.iwram0) + SIZEOF(.iwram0)+SIZEOF(.iwram1)+SIZEOF(.iwram2)+SIZEOF(.iwram3)+SIZEOF(.iwram4)+SIZEOF(.iwram5)+SIZEOF(.iwram6)+SIZEOF(.iwram7)+SIZEOF(.iwram8)+SIZEOF(.iwram9);
  189. __iwram_overlay_end = . ;
  190. __iheap_start = . ;
  191. __ewram_start = 0x2000000;
  192. .ewram __ewram_start : AT (__ewram_lma)
  193. {
  194. *(.ewram)
  195. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  196. }>ewram = 0xff
  197. __ewram_overlay_lma = __ewram_lma + SIZEOF(.ewram);
  198. .sbss ALIGN(4):
  199. {
  200. __sbss_start = ABSOLUTE(.);
  201. *(.sbss)
  202. . = ALIGN(4);
  203. } >ewram
  204. __sbss_end = .;
  205. __ewram_end = . ;
  206. __ewram_overlay_start = . ;
  207. OVERLAY ALIGN(4): NOCROSSREFS AT (__ewram_overlay_lma)
  208. {
  209. .ewram0 { *(.ewram0) . = ALIGN(4);}
  210. .ewram1 { *(.ewram1) . = ALIGN(4);}
  211. .ewram2 { *(.ewram2) . = ALIGN(4);}
  212. .ewram3 { *(.ewram3) . = ALIGN(4);}
  213. .ewram4 { *(.ewram4) . = ALIGN(4);}
  214. .ewram5 { *(.ewram5) . = ALIGN(4);}
  215. .ewram6 { *(.ewram6) . = ALIGN(4);}
  216. .ewram7 { *(.ewram7) . = ALIGN(4);}
  217. .ewram8 { *(.ewram8) . = ALIGN(4);}
  218. .ewram9 { *(.ewram9) . = ALIGN(4);}
  219. }>ewram = 0xff
  220. __pad_lma = LOADADDR(.ewram0) + SIZEOF(.ewram0)+SIZEOF(.ewram1)+SIZEOF(.ewram2)+SIZEOF(.ewram3)+SIZEOF(.ewram4)+SIZEOF(.ewram5)+SIZEOF(.ewram6)+SIZEOF(.ewram7)+SIZEOF(.ewram8)+SIZEOF(.ewram9);
  221. /* EZF Advance strips trailing 0xff bytes, add a pad section so nothing important is removed */
  222. .pad ALIGN(4) : AT (__pad_lma)
  223. {
  224. LONG(0x52416b64)
  225. LONG(0x4d)
  226. . = ALIGN(4); /* REQUIRED. LD is flaky without it. */
  227. } = 0xff
  228. __ewram_overlay_end = . ;
  229. __eheap_start = . ;
  230. _end = .;
  231. __end__ = _end ; /* v1.3 */
  232. PROVIDE (end = _end); /* v1.3 */
  233. /* Stabs debugging sections. */
  234. .stab 0 : { *(.stab) }
  235. .stabstr 0 : { *(.stabstr) }
  236. .stab.excl 0 : { *(.stab.excl) }
  237. .stab.exclstr 0 : { *(.stab.exclstr) }
  238. .stab.index 0 : { *(.stab.index) }
  239. .stab.indexstr 0 : { *(.stab.indexstr) }
  240. .comment 0 : { *(.comment) }
  241. /* DWARF debug sections.
  242. Symbols in the DWARF debugging sections are relative to the beginning
  243. of the section so we begin them at 0. */
  244. /* DWARF 1 */
  245. .debug 0 : { *(.debug) }
  246. .line 0 : { *(.line) }
  247. /* GNU DWARF 1 extensions */
  248. .debug_srcinfo 0 : { *(.debug_srcinfo) }
  249. .debug_sfnames 0 : { *(.debug_sfnames) }
  250. /* DWARF 1.1 and DWARF 2 */
  251. .debug_aranges 0 : { *(.debug_aranges) }
  252. .debug_pubnames 0 : { *(.debug_pubnames) }
  253. /* DWARF 2 */
  254. .debug_info 0 : { *(.debug_info) }
  255. .debug_abbrev 0 : { *(.debug_abbrev) }
  256. .debug_line 0 : { *(.debug_line) }
  257. .debug_frame 0 : { *(.debug_frame) }
  258. .debug_str 0 : { *(.debug_str) }
  259. .debug_loc 0 : { *(.debug_loc) }
  260. .debug_macinfo 0 : { *(.debug_macinfo) }
  261. /* SGI/MIPS DWARF 2 extensions */
  262. .debug_weaknames 0 : { *(.debug_weaknames) }
  263. .debug_funcnames 0 : { *(.debug_funcnames) }
  264. .debug_typenames 0 : { *(.debug_typenames) }
  265. .debug_varnames 0 : { *(.debug_varnames) }
  266. .stack 0x80000 : { _stack = .; *(.stack) }
  267. /* These must appear regardless of . */
  268. }