link_defs.ld 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _LINK_DEFS_H_
  13. #define _LINK_DEFS_H_
  14. #include "hal_config.h"
  15. /**
  16. * default RO sections
  17. */
  18. #define DEF_RO _DEF_RO
  19. /**
  20. * default RW sections
  21. */
  22. #define DEF_RW _DEF_RW
  23. /**
  24. * default ZI sections
  25. */
  26. #define DEF_ZI _DEF_ZI
  27. /**
  28. * default ignore and discard sections
  29. */
  30. #define IGNORE_DISCARD_SECTS _IGNORE_DISCARD_SECTS
  31. /**
  32. * section with separated "VirtAddr" and "PhysAddr". It will define:
  33. * __name_start, __name_end, __name_load_address
  34. */
  35. #define LOAD_SECT(name) _LOAD_SECT(name)
  36. /**
  37. * section without separated "VirtAddr" and "PhysAddr". It will define:
  38. * __name_start, __name_end
  39. */
  40. #define NOAT_SECT(name) _NOAT_SECT(name)
  41. /**
  42. * section without separated "VirtAddr" and "PhysAddr", with alignment at the
  43. * end. It will define:
  44. * __name_start, __name_end
  45. */
  46. #define NOAT_SECT_ALIGNED(name, aligned) _NOAT_SECT_ALIGNED(name, aligned)
  47. /**
  48. * section with NOLOAD option. It will define:
  49. * __name_start, __name_end
  50. */
  51. #define NOLOAD_SECT(name) _NOLOAD_SECT(name)
  52. /**
  53. * section with NOLOAD option, withour content, with skip size.
  54. * It will define:
  55. * __name_start, __name_end
  56. */
  57. #define NOLOAD_SIZE_SECT(name, size) _NOLOAD_SIZE_SECT(name, size)
  58. /**
  59. * section with NOLOAD option, withour content, with specified end address.
  60. * It will define:
  61. * __name_start, __name_end
  62. */
  63. #define NOLOAD_END_SECT(name, end) _NOLOAD_END_SECT(name, end)
  64. /**
  65. * section with NOLOAD option, withour content, with skip size.
  66. * It will define:
  67. * __name_start, __name_end
  68. */
  69. #define NOLOAD_SIZE_SECT(name, size) _NOLOAD_SIZE_SECT(name, size)
  70. /**
  71. * dummy section just to define: __name
  72. */
  73. #define ANCHOR_SECT(name) _ANCHOR_SECT(name)
  74. /**
  75. * IMPLEMENTATIONS
  76. */
  77. #define _DEF_RO .text \
  78. .text.* \
  79. .gnu.linkonce.t.* \
  80. .rdata \
  81. .rodata \
  82. .rodata.* \
  83. .rodata1 \
  84. .gnu.linkonce.r.*
  85. #define _DEF_RW .data \
  86. .data.* \
  87. .sdata \
  88. .sdata.* \
  89. .data1 \
  90. .gnu.linkonce.d.*
  91. #define _DEF_ZI .bss \
  92. .bss.* \
  93. COMMON \
  94. .scommon \
  95. .sbss \
  96. .sbss.* \
  97. .sbss2 \
  98. .sbss2.* \
  99. .gnu.linkonce.b.*
  100. // It is important to let "__name_end" is the real end, not the aligned
  101. // end. For some sections, especially ".init_array", software will loop
  102. // the contents inside.
  103. //
  104. // All sections are cache line aligned.
  105. #define _LOAD_SECT(name) .name : { \
  106. __##name##_start = .; \
  107. name##_contents \
  108. __##name##_end = .; \
  109. . = ALIGN(CONFIG_CACHE_LINE_SIZE); \
  110. __##name##_load_start = LOADADDR(.name); \
  111. }
  112. #define _NOAT_SECT(name) .name : { \
  113. __##name##_start = .; \
  114. name##_contents \
  115. __##name##_end = .; \
  116. . = ALIGN(CONFIG_CACHE_LINE_SIZE); \
  117. }
  118. #define _NOLOAD_SECT(name) .name (NOLOAD) : { \
  119. __##name##_start = .; \
  120. name##_contents \
  121. __##name##_end = .; \
  122. . = ALIGN(CONFIG_CACHE_LINE_SIZE); \
  123. }
  124. // Section without contents, and size is specified
  125. #define _NOLOAD_SIZE_SECT(name, size) .name (NOLOAD) : {\
  126. __##name##_start = .; \
  127. . += size; \
  128. __##name##_end = .; \
  129. . = ALIGN(CONFIG_CACHE_LINE_SIZE); \
  130. }
  131. #define _NOLOAD_END_SECT(name, end) .name (NOLOAD) : { \
  132. __##name##_start = .; \
  133. . = end; \
  134. __##name##_end = .; \
  135. . = ALIGN(CONFIG_CACHE_LINE_SIZE); \
  136. }
  137. #define _NOAT_SECT_ALIGNED(name, aligned) .name : ALIGN(aligned) { \
  138. __##name##_start = .; \
  139. name##_contents \
  140. __##name##_end = .; \
  141. . = ALIGN(CONFIG_CACHE_LINE_SIZE); \
  142. }
  143. #define _ANCHOR_SECT(name) .name (NOLOAD) : { \
  144. __##name = .; \
  145. }
  146. #define IGNORE_SECT(name) name 0 : { *(name) }
  147. #define DISCARD_SECT(name) /DISCARD/ : { *(name) }
  148. #ifdef CONFIG_CPU_ARM
  149. #define _IGNORE_DISCARD_SECTS \
  150. IGNORE_SECT(.comment) \
  151. IGNORE_SECT(.ARM.attributes) \
  152. IGNORE_SECT(.iplt) \
  153. IGNORE_SECT(.igot.plt) \
  154. IGNORE_SECT(.rel.dyn) \
  155. IGNORE_SECT(.glue_7) \
  156. IGNORE_SECT(.glue_7t) \
  157. IGNORE_SECT(.vfp11_veneer) \
  158. IGNORE_SECT(.v4_bx) \
  159. DISCARD_SECT(.ARM.exidx*) \
  160. DISCARD_SECT(.gnu.linkonce.armexidx*) \
  161. #endif
  162. #endif