ld.script 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /****************************************************************************
  2. * boards/risc-v/nr5m100/nr5m100-nexys4/scripts/ld.script
  3. *
  4. * Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
  5. * Copyright (C) 2016 Ken Pettit.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. * Ken Pettit <pettitkd@gmail.com>
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. * 3. Neither the name NuttX nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ****************************************************************************/
  37. /*======================================================================*/
  38. /* Linker script for nr5m100_nexys board */
  39. /*======================================================================*/
  40. /*----------------------------------------------------------------------*/
  41. /* Setup */
  42. /*----------------------------------------------------------------------*/
  43. /* The OUTPUT_ARCH command specifies the machine architecture where the
  44. * argument is one of the names used in the BFD library. More
  45. * specifically one of the entires in bfd/cpu-mips.c
  46. */
  47. OUTPUT_ARCH( "riscv" )
  48. /* Define the memory regions were we put stuff */
  49. MEMORY
  50. {
  51. sram (rwx) : ORIGIN = 0x20000000, LENGTH = 384K
  52. }
  53. stack_size = 4096;
  54. /* Define the beginning and ending stack */
  55. __stack_start = ORIGIN(sram) + LENGTH(sram);
  56. __stack_end = __stack_start - stack_size;
  57. /* The ENTRY command specifies the entry point (ie. first instruction to
  58. * execute). The symbol _start is defined in crt0.S
  59. */
  60. ENTRY( __reset )
  61. /* The GROUP command is special since the listed archives will be
  62. * searched repeatedly until there are no new undefined references. We
  63. * need this since -lc depends on -lgloss and -lgloss depends on -lc. I
  64. * thought gcc would automatically include -lgcc when needed, but
  65. * idt32.ld includes it explicitly here and I was seeing link errors
  66. * without it.
  67. */
  68. /*GROUP( -lc -lgloss -lgcc ) */
  69. GROUP( -lc )
  70. /*----------------------------------------------------------------------*/
  71. /* Sections */
  72. /*----------------------------------------------------------------------*/
  73. /* This is where we specify how the input sections map to output
  74. * sections. The .= commands set the location counter, and the
  75. * sections are inserted in increasing address order according to the
  76. * location counter. The following statement will take all of the .bar
  77. * input sections and reloate them into the .foo output section which
  78. * starts at address 0x1000.
  79. *
  80. * . = 0.x1000;
  81. * .foo : { *(.bar) }
  82. *
  83. * If we wrap an input specification with a KEEP command then it
  84. * prevents it from being eliminted during "link-time garbage
  85. * collection". I'm not sure what this is, so I just followed what was
  86. * done in idt32.ld.
  87. *
  88. * We can also set a global external symbol to a specific address in the
  89. * output binary with this syntax:
  90. *
  91. * _etext = .;
  92. * PROVIDE( etext = . );
  93. *
  94. * This will set the global symbol _ftext to the current location. If we
  95. * wrap this in a PROVIDE commad, the symbol will only be set if it is
  96. * not defined. We do this with symbols which don't begin with an
  97. * underscore since technically in ansi C someone might have a function
  98. * with the same name (eg. etext).
  99. *
  100. * If we need to label the beginning of a section we need to make sure
  101. * that the linker doesn't insert an orphan section inbetween where we
  102. * set the symbol and the actual begining of the section. We can do that
  103. * by assigning the location dot to itself.
  104. *
  105. * . = .
  106. * _ftext = .;
  107. * .text :
  108. * { }
  109. *
  110. */
  111. SECTIONS
  112. {
  113. /*--------------------------------------------------------------------*/
  114. /* Startup vectors
  115. /*--------------------------------------------------------------------*/
  116. . = 0x20000000;
  117. _vectors = .;
  118. /* vectors: Program code section */
  119. .vectors :
  120. {
  121. *(.text.vec)
  122. *(.text.vec.*)
  123. *(.gnu.linkonce.t.*)
  124. }
  125. _evectors = .;
  126. /*--------------------------------------------------------------------*/
  127. /* Code and read-only segment */
  128. /*--------------------------------------------------------------------*/
  129. /* Begining of code and text segment */
  130. . = 0x20000030;
  131. _ftext = .;
  132. PROVIDE( eprol = . );
  133. /* text: Program code section */
  134. .text :
  135. {
  136. _stext = ABSOLUTE(.);
  137. *(.text)
  138. *(.text.*)
  139. *(.gnu.linkonce.t.*)
  140. }
  141. /* init: Code to execute before main (called by crt0.S) */
  142. .init :
  143. {
  144. KEEP( *(.init) )
  145. }
  146. /* fini: Code to execute after main (called by crt0.S) */
  147. .fini :
  148. {
  149. KEEP( *(.fini) )
  150. }
  151. /* rodata: Read-only data */
  152. _rodata = .;
  153. .rodata :
  154. {
  155. *(.rdata)
  156. *(.rodata)
  157. *(.rodata.*)
  158. *(.gnu.linkonce.r.*)
  159. }
  160. /* End of code and read-only segment */
  161. PROVIDE( etext = . );
  162. _etext = .;
  163. /*--------------------------------------------------------------------*/
  164. /* Global constructor/destructor segement */
  165. /*--------------------------------------------------------------------*/
  166. .preinit_array :
  167. {
  168. PROVIDE_HIDDEN (__preinit_array_start = .);
  169. KEEP (*(.preinit_array))
  170. PROVIDE_HIDDEN (__preinit_array_end = .);
  171. }
  172. .init_array :
  173. {
  174. PROVIDE_HIDDEN (__init_array_start = .);
  175. KEEP (*(SORT(.init_array.*)))
  176. KEEP (*(.init_array ))
  177. PROVIDE_HIDDEN (__init_array_end = .);
  178. }
  179. .fini_array :
  180. {
  181. PROVIDE_HIDDEN (__fini_array_start = .);
  182. KEEP (*(SORT(.fini_array.*)))
  183. KEEP (*(.fini_array ))
  184. PROVIDE_HIDDEN (__fini_array_end = .);
  185. }
  186. /*--------------------------------------------------------------------*/
  187. /* Other misc gcc segments (this was in idt32.ld) */
  188. /*--------------------------------------------------------------------*/
  189. /* I am not quite sure about these sections but it seems they are for
  190. * C++ exception handling. I think .jcr is for "Java Class
  191. * Registration" but it seems to end up in C++ binaries as well.
  192. */
  193. .eh_frame_hdr : { *(.eh_frame_hdr) }
  194. .eh_frame : { KEEP( *(.eh_frame) ) }
  195. .gcc_except_table : { *(.gcc_except_table) }
  196. .jcr : { KEEP (*(.jcr)) }
  197. /*--------------------------------------------------------------------*/
  198. /* Initialized data segment */
  199. /*--------------------------------------------------------------------*/
  200. /* Start of initialized data segment */
  201. . = ALIGN(16);
  202. _fdata = .;
  203. /* data: Writable data */
  204. _sdata = .;
  205. .data :
  206. {
  207. *(.data)
  208. *(.data.*)
  209. *(.gnu.linkonce.d.*)
  210. }
  211. /* End of initialized data segment */
  212. . = ALIGN(4);
  213. PROVIDE( edata = . );
  214. _edata = .;
  215. /* Have _gp point to middle of sdata/sbss to maximize displacement range */
  216. . = ALIGN(16);
  217. _gp = . + 0x7FF0;
  218. /* Writable small data segment */
  219. .sdata :
  220. {
  221. *(.sdata)
  222. *(.sdata.*)
  223. *(.srodata.*)
  224. . = ALIGN(16);
  225. *(.gnu.linkonce.s.*)
  226. }
  227. /*--------------------------------------------------------------------*/
  228. /* Uninitialized data segment */
  229. /*--------------------------------------------------------------------*/
  230. /* Start of uninitialized data segment */
  231. . = ALIGN(8);
  232. _fbss = .;
  233. /* Writable uninitialized small data segment */
  234. .sbss :
  235. {
  236. *(.sbss)
  237. *(.sbss.*)
  238. *(.gnu.linkonce.sb.*)
  239. }
  240. /* bss: Uninitialized writeable data section */
  241. _bss_start = .;
  242. .bss :
  243. {
  244. *(.bss)
  245. *(.bss.*)
  246. *(.gnu.linkonce.b.*)
  247. *(COMMON)
  248. }
  249. . = ALIGN(4);
  250. _bss_end = .;
  251. _ebss = .;
  252. /* End of uninitialized data segment (used by syscalls.c for heap) */
  253. . = ALIGN(16);
  254. PROVIDE( end = . );
  255. _end = ALIGN(16);
  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. .debug_abbrev 0 : { *(.debug_abbrev) }
  265. .debug_info 0 : { *(.debug_info) }
  266. .debug_line 0 : { *(.debug_line) }
  267. .debug_pubnames 0 : { *(.debug_pubnames) }
  268. .debug_aranges 0 : { *(.debug_aranges) }
  269. }