linker-tool-gcc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (c) 2013-2014, Wind River Systems, Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief GCC toolchain linker defs
  9. *
  10. * This header file defines the necessary macros used by the linker script for
  11. * use with the GCC linker.
  12. */
  13. #ifndef ZEPHYR_INCLUDE_LINKER_LINKER_TOOL_GCC_H_
  14. #define ZEPHYR_INCLUDE_LINKER_LINKER_TOOL_GCC_H_
  15. #include <sys/mem_manage.h>
  16. #if defined(CONFIG_ARM)
  17. #if defined(CONFIG_BIG_ENDIAN)
  18. #define OUTPUT_FORMAT_ "elf32-bigarm"
  19. #else
  20. #define OUTPUT_FORMAT_ "elf32-littlearm"
  21. #endif
  22. OUTPUT_FORMAT(OUTPUT_FORMAT_)
  23. #elif defined(CONFIG_ARM64)
  24. OUTPUT_FORMAT("elf64-littleaarch64")
  25. #elif defined(CONFIG_ARC)
  26. #if defined(CONFIG_64BIT)
  27. OUTPUT_FORMAT("elf64-littlearc")
  28. #else
  29. OUTPUT_FORMAT("elf32-littlearc", "elf32-bigarc", "elf32-littlearc")
  30. #endif
  31. #elif defined(CONFIG_X86)
  32. #if defined(CONFIG_X86_64)
  33. OUTPUT_FORMAT("elf64-x86-64")
  34. OUTPUT_ARCH("i386:x86-64")
  35. #else
  36. OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
  37. OUTPUT_ARCH("i386")
  38. #endif
  39. #elif defined(CONFIG_NIOS2)
  40. OUTPUT_FORMAT("elf32-littlenios2", "elf32-bignios2", "elf32-littlenios2")
  41. #elif defined(CONFIG_RISCV)
  42. OUTPUT_ARCH("riscv")
  43. #ifdef CONFIG_64BIT
  44. OUTPUT_FORMAT("elf64-littleriscv")
  45. #else
  46. OUTPUT_FORMAT("elf32-littleriscv")
  47. #endif
  48. #elif defined(CONFIG_XTENSA)
  49. /* Not needed */
  50. #elif defined(CONFIG_ARCH_POSIX)
  51. /* Not needed */
  52. #elif defined(CONFIG_SPARC)
  53. OUTPUT_FORMAT("elf32-sparc")
  54. #else
  55. #error Arch not supported.
  56. #endif
  57. /*
  58. * The GROUP_START() and GROUP_END() macros are used to define a group
  59. * of sections located in one memory area, such as RAM, ROM, etc.
  60. * The <where> parameter is the name of the memory area.
  61. */
  62. #define GROUP_START(where)
  63. #define GROUP_END(where)
  64. /**
  65. * @def GROUP_LINK_IN
  66. *
  67. * Route memory to a specified memory area
  68. *
  69. * The GROUP_LINK_IN() macro is located at the end of the section
  70. * description and tells the linker that this section is located in
  71. * the memory area specified by 'where' argument.
  72. *
  73. * This macro is intentionally undefined for CONFIG_MMU systems when
  74. * CONFIG_KERNEL_VM_BASE is not the same as CONFIG_SRAM_BASE_ADDRESS,
  75. * as both the LMA and VMA destinations must be known for all sections
  76. * as this corresponds to physical vs. virtual location.
  77. *
  78. * @param where Destination memory area
  79. */
  80. #if defined(CONFIG_ARCH_POSIX)
  81. #define GROUP_LINK_IN(where)
  82. #elif !defined(Z_VM_KERNEL)
  83. #define GROUP_LINK_IN(where) > where
  84. #endif
  85. /**
  86. * @def GROUP_ROM_LINK_IN
  87. *
  88. * Route memory for a read-only section
  89. *
  90. * The GROUP_ROM_LINK_IN() macro is located at the end of the section
  91. * description and tells the linker that this a read-only section
  92. * that is physically placed at the 'lregion` argument.
  93. *
  94. * If CONFIG_XIP is active, the 'lregion' area is flash memory.
  95. *
  96. * If CONFIG_MMU is active, the vregion argument will be used to
  97. * determine where this is located in the virtual memory map, otherwise
  98. * it is ignored.
  99. *
  100. * @param vregion Output VMA (only used if CONFIG_MMU where LMA != VMA)
  101. * @param lregion Output LMA
  102. */
  103. #if defined(CONFIG_ARCH_POSIX)
  104. #define GROUP_ROM_LINK_IN(vregion, lregion)
  105. #elif defined(Z_VM_KERNEL)
  106. #define GROUP_ROM_LINK_IN(vregion, lregion) > vregion AT > lregion
  107. #else
  108. #define GROUP_ROM_LINK_IN(vregion, lregion) > lregion
  109. #endif
  110. /**
  111. * @def GROUP_DATA_LINK_IN
  112. *
  113. * Route memory for read-write sections that are loaded.
  114. *
  115. * Used for initialized data sections that on XIP platforms must be copied at
  116. * startup.
  117. *
  118. * @param vregion Output VMA
  119. * @param lregion Output LMA (only used if CONFIG_MMU if VMA != LMA,
  120. * or CONFIG_XIP)
  121. */
  122. #if defined(CONFIG_ARCH_POSIX)
  123. #define GROUP_DATA_LINK_IN(vregion, lregion)
  124. #elif defined(CONFIG_XIP) || defined(Z_VM_KERNEL)
  125. #define GROUP_DATA_LINK_IN(vregion, lregion) > vregion AT > lregion
  126. #else
  127. #define GROUP_DATA_LINK_IN(vregion, lregion) > vregion
  128. #endif
  129. /**
  130. * @def GROUP_NOLOAD_LINK_IN
  131. *
  132. * Route memory for read-write sections that are NOT loaded; typically this
  133. * is only used for 'BSS' and 'noinit'.
  134. *
  135. * @param vregion Output VMA
  136. * @param lregion Output LMA (only used if CONFIG_MMU if VMA != LMA,
  137. * corresponds to physical location)
  138. */
  139. #if defined(CONFIG_ARCH_POSIX)
  140. #define GROUP_NOLOAD_LINK_IN(vregion, lregion)
  141. #elif defined(Z_VM_KERNEL)
  142. #define GROUP_NOLOAD_LINK_IN(vregion, lregion) > vregion AT > lregion
  143. #elif defined(CONFIG_XIP)
  144. #define GROUP_NOLOAD_LINK_IN(vregion, lregion) > vregion AT > vregion
  145. #else
  146. #define GROUP_NOLOAD_LINK_IN(vregion, lregion) > vregion
  147. #endif
  148. /**
  149. * @def SECTION_PROLOGUE
  150. *
  151. * The SECTION_PROLOGUE() macro is used to define the beginning of a section.
  152. *
  153. * On MMU systems where VMA != LMA there is an implicit ALIGN_WITH_INPUT
  154. * specified.
  155. *
  156. * @param name Name of the output sectio
  157. * @param options Section options, such as (NOLOAD), or left blank
  158. * @param align Alignment directives, such as SUBALIGN(). ALIGN() itself is
  159. * not allowed. May be blank.
  160. */
  161. #ifdef Z_VM_KERNEL
  162. /* If we have a virtual memory map we need ALIGN_WITH_INPUT in all sections */
  163. #define SECTION_PROLOGUE(name, options, align) \
  164. name options : ALIGN_WITH_INPUT align
  165. #else
  166. #define SECTION_PROLOGUE(name, options, align) \
  167. name options : align
  168. #endif
  169. /**
  170. * @def SECTION_DATA_PROLOGUE
  171. *
  172. * Same as for SECTION_PROLOGUE(), except that this one must be used
  173. * for data sections which on XIP platforms will have differing
  174. * virtual and load addresses (i.e. they'll be copied into RAM at
  175. * program startup). Such a section must also use
  176. * GROUP_DATA_LINK_IN to specify the correct output load address.
  177. *
  178. * This is equivalent to SECTION_PROLOGUE() on non-XIP systems.
  179. * On XIP systems there is an implicit ALIGN_WITH_INPUT specified.
  180. *
  181. * @param name Name of the output sectio
  182. * @param options Section options, or left blank
  183. * @param align Alignment directives, such as SUBALIGN(). ALIGN() itself is
  184. * not allowed. May be blank.
  185. */
  186. #if defined(CONFIG_XIP)
  187. #define SECTION_DATA_PROLOGUE(name, options, align) \
  188. name options : ALIGN_WITH_INPUT align
  189. #else
  190. #define SECTION_DATA_PROLOGUE(name, options, align) \
  191. SECTION_PROLOGUE(name, options, align)
  192. #endif
  193. #define COMMON_SYMBOLS *(COMMON)
  194. #endif /* ZEPHYR_INCLUDE_LINKER_LINKER_TOOL_GCC_H_ */