bl_common.ld.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright (c) 2020-2022, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef BL_COMMON_LD_H
  7. #define BL_COMMON_LD_H
  8. #include <platform_def.h>
  9. #ifdef __aarch64__
  10. #define STRUCT_ALIGN 8
  11. #define BSS_ALIGN 16
  12. #else
  13. #define STRUCT_ALIGN 4
  14. #define BSS_ALIGN 8
  15. #endif
  16. #ifndef DATA_ALIGN
  17. #define DATA_ALIGN 1
  18. #endif
  19. #define CPU_OPS \
  20. . = ALIGN(STRUCT_ALIGN); \
  21. __CPU_OPS_START__ = .; \
  22. KEEP(*(.cpu_ops)) \
  23. __CPU_OPS_END__ = .;
  24. #define PARSER_LIB_DESCS \
  25. . = ALIGN(STRUCT_ALIGN); \
  26. __PARSER_LIB_DESCS_START__ = .; \
  27. KEEP(*(.img_parser_lib_descs)) \
  28. __PARSER_LIB_DESCS_END__ = .;
  29. #define RT_SVC_DESCS \
  30. . = ALIGN(STRUCT_ALIGN); \
  31. __RT_SVC_DESCS_START__ = .; \
  32. KEEP(*(.rt_svc_descs)) \
  33. __RT_SVC_DESCS_END__ = .;
  34. #if SPMC_AT_EL3
  35. #define EL3_LP_DESCS \
  36. . = ALIGN(STRUCT_ALIGN); \
  37. __EL3_LP_DESCS_START__ = .; \
  38. KEEP(*(.el3_lp_descs)) \
  39. __EL3_LP_DESCS_END__ = .;
  40. #else
  41. #define EL3_LP_DESCS
  42. #endif
  43. #define PMF_SVC_DESCS \
  44. . = ALIGN(STRUCT_ALIGN); \
  45. __PMF_SVC_DESCS_START__ = .; \
  46. KEEP(*(.pmf_svc_descs)) \
  47. __PMF_SVC_DESCS_END__ = .;
  48. #define FCONF_POPULATOR \
  49. . = ALIGN(STRUCT_ALIGN); \
  50. __FCONF_POPULATOR_START__ = .; \
  51. KEEP(*(.fconf_populator)) \
  52. __FCONF_POPULATOR_END__ = .;
  53. /*
  54. * Keep the .got section in the RO section as it is patched prior to enabling
  55. * the MMU and having the .got in RO is better for security. GOT is a table of
  56. * addresses so ensure pointer size alignment.
  57. */
  58. #define GOT \
  59. . = ALIGN(STRUCT_ALIGN); \
  60. __GOT_START__ = .; \
  61. *(.got) \
  62. __GOT_END__ = .;
  63. /*
  64. * The base xlat table
  65. *
  66. * It is put into the rodata section if PLAT_RO_XLAT_TABLES=1,
  67. * or into the bss section otherwise.
  68. */
  69. #define BASE_XLAT_TABLE \
  70. . = ALIGN(16); \
  71. __BASE_XLAT_TABLE_START__ = .; \
  72. *(.base_xlat_table) \
  73. __BASE_XLAT_TABLE_END__ = .;
  74. #if PLAT_RO_XLAT_TABLES
  75. #define BASE_XLAT_TABLE_RO BASE_XLAT_TABLE
  76. #define BASE_XLAT_TABLE_BSS
  77. #else
  78. #define BASE_XLAT_TABLE_RO
  79. #define BASE_XLAT_TABLE_BSS BASE_XLAT_TABLE
  80. #endif
  81. #define RODATA_COMMON \
  82. RT_SVC_DESCS \
  83. FCONF_POPULATOR \
  84. PMF_SVC_DESCS \
  85. PARSER_LIB_DESCS \
  86. CPU_OPS \
  87. GOT \
  88. BASE_XLAT_TABLE_RO \
  89. EL3_LP_DESCS
  90. /*
  91. * .data must be placed at a lower address than the stacks if the stack
  92. * protector is enabled. Alternatively, the .data.stack_protector_canary
  93. * section can be placed independently of the main .data section.
  94. */
  95. #define DATA_SECTION \
  96. .data . : ALIGN(DATA_ALIGN) { \
  97. __DATA_START__ = .; \
  98. *(SORT_BY_ALIGNMENT(.data*)) \
  99. __DATA_END__ = .; \
  100. }
  101. /*
  102. * .rela.dyn needs to come after .data for the read-elf utility to parse
  103. * this section correctly.
  104. */
  105. #if __aarch64__
  106. #define RELA_DYN_NAME .rela.dyn
  107. #define RELOC_SECTIONS_PATTERN *(.rela*)
  108. #else
  109. #define RELA_DYN_NAME .rel.dyn
  110. #define RELOC_SECTIONS_PATTERN *(.rel*)
  111. #endif
  112. #define RELA_SECTION \
  113. RELA_DYN_NAME : ALIGN(STRUCT_ALIGN) { \
  114. __RELA_START__ = .; \
  115. RELOC_SECTIONS_PATTERN \
  116. __RELA_END__ = .; \
  117. }
  118. #if !(defined(IMAGE_BL31) && RECLAIM_INIT_CODE)
  119. #define STACK_SECTION \
  120. .stacks (NOLOAD) : { \
  121. __STACKS_START__ = .; \
  122. *(.tzfw_normal_stacks) \
  123. __STACKS_END__ = .; \
  124. }
  125. #endif
  126. /*
  127. * If BL doesn't use any bakery lock then __PERCPU_BAKERY_LOCK_SIZE__
  128. * will be zero. For this reason, the only two valid values for
  129. * __PERCPU_BAKERY_LOCK_SIZE__ are 0 or the platform defined value
  130. * PLAT_PERCPU_BAKERY_LOCK_SIZE.
  131. */
  132. #ifdef PLAT_PERCPU_BAKERY_LOCK_SIZE
  133. #define BAKERY_LOCK_SIZE_CHECK \
  134. ASSERT((__PERCPU_BAKERY_LOCK_SIZE__ == 0) || \
  135. (__PERCPU_BAKERY_LOCK_SIZE__ == PLAT_PERCPU_BAKERY_LOCK_SIZE), \
  136. "PLAT_PERCPU_BAKERY_LOCK_SIZE does not match bakery lock requirements");
  137. #else
  138. #define BAKERY_LOCK_SIZE_CHECK
  139. #endif
  140. /*
  141. * Bakery locks are stored in normal .bss memory
  142. *
  143. * Each lock's data is spread across multiple cache lines, one per CPU,
  144. * but multiple locks can share the same cache line.
  145. * The compiler will allocate enough memory for one CPU's bakery locks,
  146. * the remaining cache lines are allocated by the linker script
  147. */
  148. #if !USE_COHERENT_MEM
  149. #define BAKERY_LOCK_NORMAL \
  150. . = ALIGN(CACHE_WRITEBACK_GRANULE); \
  151. __BAKERY_LOCK_START__ = .; \
  152. __PERCPU_BAKERY_LOCK_START__ = .; \
  153. *(.bakery_lock) \
  154. . = ALIGN(CACHE_WRITEBACK_GRANULE); \
  155. __PERCPU_BAKERY_LOCK_END__ = .; \
  156. __PERCPU_BAKERY_LOCK_SIZE__ = ABSOLUTE(__PERCPU_BAKERY_LOCK_END__ - __PERCPU_BAKERY_LOCK_START__); \
  157. . = . + (__PERCPU_BAKERY_LOCK_SIZE__ * (PLATFORM_CORE_COUNT - 1)); \
  158. __BAKERY_LOCK_END__ = .; \
  159. BAKERY_LOCK_SIZE_CHECK
  160. #else
  161. #define BAKERY_LOCK_NORMAL
  162. #endif
  163. /*
  164. * Time-stamps are stored in normal .bss memory
  165. *
  166. * The compiler will allocate enough memory for one CPU's time-stamps,
  167. * the remaining memory for other CPUs is allocated by the
  168. * linker script
  169. */
  170. #define PMF_TIMESTAMP \
  171. . = ALIGN(CACHE_WRITEBACK_GRANULE); \
  172. __PMF_TIMESTAMP_START__ = .; \
  173. KEEP(*(.pmf_timestamp_array)) \
  174. . = ALIGN(CACHE_WRITEBACK_GRANULE); \
  175. __PMF_PERCPU_TIMESTAMP_END__ = .; \
  176. __PERCPU_TIMESTAMP_SIZE__ = ABSOLUTE(. - __PMF_TIMESTAMP_START__); \
  177. . = . + (__PERCPU_TIMESTAMP_SIZE__ * (PLATFORM_CORE_COUNT - 1)); \
  178. __PMF_TIMESTAMP_END__ = .;
  179. /*
  180. * The .bss section gets initialised to 0 at runtime.
  181. * Its base address has bigger alignment for better performance of the
  182. * zero-initialization code.
  183. */
  184. #define BSS_SECTION \
  185. .bss (NOLOAD) : ALIGN(BSS_ALIGN) { \
  186. __BSS_START__ = .; \
  187. *(SORT_BY_ALIGNMENT(.bss*)) \
  188. *(COMMON) \
  189. BAKERY_LOCK_NORMAL \
  190. PMF_TIMESTAMP \
  191. BASE_XLAT_TABLE_BSS \
  192. __BSS_END__ = .; \
  193. }
  194. /*
  195. * The .xlat_table section is for full, aligned page tables (4K).
  196. * Removing them from .bss avoids forcing 4K alignment on
  197. * the .bss section. The tables are initialized to zero by the translation
  198. * tables library.
  199. */
  200. #define XLAT_TABLE_SECTION \
  201. .xlat_table (NOLOAD) : { \
  202. __XLAT_TABLE_START__ = .; \
  203. *(.xlat_table) \
  204. __XLAT_TABLE_END__ = .; \
  205. }
  206. #endif /* BL_COMMON_LD_H */