common.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Linker script for libmaple.
  3. *
  4. * Original author "lanchon" from ST forums, with modifications by LeafLabs.
  5. */
  6. OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
  7. /*
  8. * Configure other libraries we want in the link.
  9. *
  10. * libgcc, libc, and libm are common across supported toolchains.
  11. * However, some toolchains require additional archives which aren't
  12. * present everywhere (e.g. ARM's gcc-arm-embedded releases).
  13. *
  14. * To hack around this, we let the build system specify additional
  15. * archives by putting the right extra_libs.inc (in a directory under
  16. * toolchains/) in our search path.
  17. */
  18. GROUP(libgcc.a libc.a libm.a)
  19. INCLUDE extra_libs.inc
  20. /*
  21. * These force the linker to search for vector table symbols.
  22. *
  23. * These symbols vary by STM32 family (and also within families).
  24. * It's up to the build system to configure the link's search path
  25. * properly for the target MCU.
  26. */
  27. INCLUDE vector_symbols.inc
  28. /* STM32 vector table. */
  29. EXTERN(__stm32_vector_table)
  30. /* C runtime initialization function. */
  31. EXTERN(start_c)
  32. /* main entry point */
  33. EXTERN(main)
  34. /* Initial stack pointer value. Relocated to RAM */
  35. EXTERN(__msp_init)
  36. PROVIDE(__msp_init = ORIGIN(ram) + LENGTH(ram));
  37. /* Reset vector and chip reset entry point */
  38. EXTERN(__start__)
  39. ENTRY(__start__)
  40. PROVIDE(__exc_reset = __start__);
  41. /* Heap boundaries, for libmaple */
  42. EXTERN(_lm_heap_start);
  43. EXTERN(_lm_heap_end);
  44. SECTIONS
  45. {
  46. .text :
  47. {
  48. __text_start__ = .;
  49. /*
  50. * STM32 vector table. Leave this here. Yes, really.
  51. */
  52. *(.stm32.interrupt_vector)
  53. /*
  54. * Program code and vague linking
  55. */
  56. *(.text .text.* .gnu.linkonce.t.*)
  57. *(.plt)
  58. *(.gnu.warning)
  59. *(.glue_7t) *(.glue_7) *(.vfp11_veneer)
  60. *(.ARM.extab* .gnu.linkonce.armextab.*)
  61. *(.gcc_except_table)
  62. *(.eh_frame_hdr)
  63. *(.eh_frame)
  64. . = ALIGN(4);
  65. KEEP(*(.init))
  66. . = ALIGN(4);
  67. __preinit_array_start = .;
  68. KEEP (*(.preinit_array))
  69. __preinit_array_end = .;
  70. . = ALIGN(4);
  71. __init_array_start = .;
  72. KEEP (*(SORT(.init_array.*)))
  73. KEEP (*(.init_array))
  74. __init_array_end = .;
  75. . = ALIGN(0x4);
  76. KEEP (*crtbegin.o(.ctors))
  77. KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
  78. KEEP (*(SORT(.ctors.*)))
  79. KEEP (*crtend.o(.ctors))
  80. . = ALIGN(4);
  81. KEEP(*(.fini))
  82. . = ALIGN(4);
  83. __fini_array_start = .;
  84. KEEP (*(.fini_array))
  85. KEEP (*(SORT(.fini_array.*)))
  86. __fini_array_end = .;
  87. KEEP (*crtbegin.o(.dtors))
  88. KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
  89. KEEP (*(SORT(.dtors.*)))
  90. KEEP (*crtend.o(.dtors))
  91. } > REGION_TEXT
  92. /*
  93. * End of text
  94. */
  95. .text.align :
  96. {
  97. . = ALIGN(8);
  98. __text_end__ = .;
  99. } > REGION_TEXT
  100. /*
  101. * .ARM.exidx exception unwinding; mandated by ARM's C++ ABI
  102. */
  103. __exidx_start = .;
  104. .ARM.exidx :
  105. {
  106. *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  107. } > REGION_RODATA
  108. __exidx_end = .;
  109. /*
  110. * Read-only data
  111. */
  112. .rodata :
  113. {
  114. *(.rodata .rodata.* .gnu.linkonce.r.*)
  115. /* .USER_FLASH: We allow users to allocate into Flash here */
  116. *(.USER_FLASH)
  117. /* ROM image configuration; for C startup */
  118. . = ALIGN(4);
  119. _lm_rom_img_cfgp = .;
  120. LONG(LOADADDR(.data));
  121. /*
  122. * Heap: Linker scripts may choose a custom heap by overriding
  123. * _lm_heap_start and _lm_heap_end. Otherwise, the heap is in
  124. * internal SRAM, beginning after .bss, and growing towards
  125. * the stack.
  126. *
  127. * I'm shoving these here naively; there's probably a cleaner way
  128. * to go about this. [mbolivar]
  129. */
  130. _lm_heap_start = DEFINED(_lm_heap_start) ? _lm_heap_start : __bss_end__;
  131. _lm_heap_end = DEFINED(_lm_heap_end) ? _lm_heap_end : __msp_init;
  132. } > REGION_RODATA
  133. /*
  134. * .data
  135. */
  136. .data :
  137. {
  138. . = ALIGN(8);
  139. __data_start__ = .;
  140. *(.got.plt) *(.got)
  141. *(.data .data.* .gnu.linkonce.d.*)
  142. . = ALIGN(8);
  143. __data_end__ = .;
  144. } > REGION_DATA AT> REGION_RODATA
  145. /*
  146. * .bss
  147. */
  148. .bss :
  149. {
  150. . = ALIGN(8);
  151. __bss_start__ = .;
  152. *(.bss .bss.* .gnu.linkonce.b.*)
  153. *(COMMON)
  154. . = ALIGN (8);
  155. __bss_end__ = .;
  156. _end = __bss_end__;
  157. } > REGION_BSS
  158. /*
  159. * Debugging sections
  160. */
  161. .stab 0 (NOLOAD) : { *(.stab) }
  162. .stabstr 0 (NOLOAD) : { *(.stabstr) }
  163. /* DWARF debug sections.
  164. * Symbols in the DWARF debugging sections are relative to the beginning
  165. * of the section so we begin them at 0. */
  166. /* DWARF 1 */
  167. .debug 0 : { *(.debug) }
  168. .line 0 : { *(.line) }
  169. /* GNU DWARF 1 extensions */
  170. .debug_srcinfo 0 : { *(.debug_srcinfo) }
  171. .debug_sfnames 0 : { *(.debug_sfnames) }
  172. /* DWARF 1.1 and DWARF 2 */
  173. .debug_aranges 0 : { *(.debug_aranges) }
  174. .debug_pubnames 0 : { *(.debug_pubnames) }
  175. /* DWARF 2 */
  176. .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
  177. .debug_abbrev 0 : { *(.debug_abbrev) }
  178. .debug_line 0 : { *(.debug_line) }
  179. .debug_frame 0 : { *(.debug_frame) }
  180. .debug_str 0 : { *(.debug_str) }
  181. .debug_loc 0 : { *(.debug_loc) }
  182. .debug_macinfo 0 : { *(.debug_macinfo) }
  183. /* SGI/MIPS DWARF 2 extensions */
  184. .debug_weaknames 0 : { *(.debug_weaknames) }
  185. .debug_funcnames 0 : { *(.debug_funcnames) }
  186. .debug_typenames 0 : { *(.debug_typenames) }
  187. .debug_varnames 0 : { *(.debug_varnames) }
  188. .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
  189. .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) }
  190. /DISCARD/ : { *(.note.GNU-stack) }
  191. }