sections.ld.in 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /* Default entry point */
  7. ENTRY(call_start_cpu0);
  8. SECTIONS
  9. {
  10. .iram0.text :
  11. {
  12. _iram_start = ABSOLUTE(.);
  13. /* Vectors go to start of IRAM */
  14. ASSERT(ABSOLUTE(.) % 0x100 == 0, "vector address must be 256 byte aligned");
  15. KEEP(*(.exception_vectors.text));
  16. . = ALIGN(4);
  17. _invalid_pc_placeholder = ABSOLUTE(.);
  18. /* Code marked as running out of IRAM */
  19. _iram_text_start = ABSOLUTE(.);
  20. mapping[iram0_text]
  21. } > iram0_0_seg
  22. /**
  23. * This section is required to skip .iram0.text area because iram0_0_seg and
  24. * dram0_0_seg reflect the same address space on different buses.
  25. */
  26. .dram0.dummy (NOLOAD):
  27. {
  28. . = ORIGIN(dram0_0_seg) + _iram_end - _iram_start;
  29. } > dram0_0_seg
  30. .dram0.data :
  31. {
  32. _data_start = ABSOLUTE(.);
  33. *(.gnu.linkonce.d.*)
  34. *(.data1)
  35. __global_pointer$ = . + 0x800;
  36. *(.sdata)
  37. *(.sdata.*)
  38. *(.gnu.linkonce.s.*)
  39. *(.gnu.linkonce.s2.*)
  40. *(.jcr)
  41. mapping[dram0_data]
  42. _data_end = ABSOLUTE(.);
  43. . = ALIGN(4);
  44. } > dram0_0_seg
  45. /**
  46. * This section holds data that should not be initialized at power up.
  47. * The section located in Internal SRAM memory region. The macro _NOINIT
  48. * can be used as attribute to place data into this section.
  49. * See the "esp_attr.h" file for more information.
  50. */
  51. .noinit (NOLOAD):
  52. {
  53. . = ALIGN(4);
  54. _noinit_start = ABSOLUTE(.);
  55. *(.noinit .noinit.*)
  56. . = ALIGN(4) ;
  57. _noinit_end = ABSOLUTE(.);
  58. } > dram0_0_seg
  59. /* Shared RAM */
  60. .dram0.bss (NOLOAD) :
  61. {
  62. . = ALIGN (8);
  63. _bss_start = ABSOLUTE(.);
  64. mapping[dram0_bss]
  65. *(.dynsbss)
  66. *(.sbss)
  67. *(.sbss.*)
  68. *(.gnu.linkonce.sb.*)
  69. *(.scommon)
  70. *(.sbss2)
  71. *(.sbss2.*)
  72. *(.gnu.linkonce.sb2.*)
  73. *(.dynbss)
  74. *(.share.mem)
  75. *(.gnu.linkonce.b.*)
  76. . = ALIGN (8);
  77. _bss_end = ABSOLUTE(.);
  78. } > dram0_0_seg
  79. ASSERT(((_bss_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), "DRAM segment data does not fit.")
  80. .flash.text :
  81. {
  82. _stext = .;
  83. _instruction_reserved_start = ABSOLUTE(.);
  84. _text_start = ABSOLUTE(.);
  85. mapping[flash_text]
  86. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  87. *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */
  88. *(.fini.literal)
  89. *(.fini)
  90. *(.gnu.version)
  91. /** CPU will try to prefetch up to 16 bytes of
  92. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  93. * safe access to up to 16 bytes after the last real instruction, add
  94. * dummy bytes to ensure this
  95. */
  96. . += _esp_flash_mmap_prefetch_pad_size;
  97. _text_end = ABSOLUTE(.);
  98. _instruction_reserved_end = ABSOLUTE(.);
  99. _etext = .;
  100. /**
  101. * Similar to _iram_start, this symbol goes here so it is
  102. * resolved by addr2line in preference to the first symbol in
  103. * the flash.text segment.
  104. */
  105. _flash_cache_start = ABSOLUTE(0);
  106. } > default_code_seg
  107. /**
  108. * This dummy section represents the .flash.text section but in default_rodata_seg.
  109. * Thus, it must have its alignment and (at least) its size.
  110. */
  111. .flash_rodata_dummy (NOLOAD):
  112. {
  113. _flash_rodata_dummy_start = .;
  114. /* Start at the same alignment constraint than .flash.text */
  115. . = ALIGN(ALIGNOF(.flash.text));
  116. /* Create an empty gap as big as .flash.text section */
  117. . = . + SIZEOF(.flash.text);
  118. /* Prepare the alignment of the section above. Few bytes (0x20) must be
  119. * added for the mapping header. */
  120. . = ALIGN(_esp_mmu_block_size) + 0x20;
  121. _rodata_reserved_start = .;
  122. } > default_rodata_seg
  123. .flash.appdesc : ALIGN(0x10)
  124. {
  125. _rodata_start = ABSOLUTE(.);
  126. *(.rodata_desc .rodata_desc.*) /* Should be the first. App version info. DO NOT PUT ANYTHING BEFORE IT! */
  127. *(.rodata_custom_desc .rodata_custom_desc.*) /* Should be the second. Custom app version info. DO NOT PUT ANYTHING BEFORE IT! */
  128. /* Create an empty gap within this section. Thanks to this, the end of this
  129. * section will match .flash.rodata's begin address. Thus, both sections
  130. * will be merged when creating the final bin image. */
  131. . = ALIGN(ALIGNOF(.flash.rodata));
  132. } >default_rodata_seg
  133. .flash.rodata : ALIGN(0x10)
  134. {
  135. _flash_rodata_start = ABSOLUTE(.);
  136. mapping[flash_rodata]
  137. *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
  138. *(.gnu.linkonce.r.*)
  139. *(.rodata1)
  140. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  141. *(.xt_except_table)
  142. *(.gcc_except_table .gcc_except_table.*)
  143. *(.gnu.linkonce.e.*)
  144. *(.gnu.version_r)
  145. . = (. + 7) & ~ 3;
  146. /*
  147. * C++ constructor and destructor tables
  148. * Don't include anything from crtbegin.o or crtend.o, as IDF doesn't use toolchain crt.
  149. *
  150. * RISC-V gcc is configured with --enable-initfini-array so it emits an .init_array section instead.
  151. * But the init_priority sections will be sorted for iteration in ascending order during startup.
  152. * The rest of the init_array sections is sorted for iteration in descending order during startup, however.
  153. * Hence a different section is generated for the init_priority functions which is iterated in
  154. * ascending order during startup. The corresponding code can be found in startup.c.
  155. */
  156. __init_priority_array_start = ABSOLUTE(.);
  157. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array.*))
  158. __init_priority_array_end = ABSOLUTE(.);
  159. __init_array_start = ABSOLUTE(.);
  160. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array))
  161. __init_array_end = ABSOLUTE(.);
  162. KEEP (*crtbegin.*(.dtors))
  163. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  164. KEEP (*(SORT(.dtors.*)))
  165. KEEP (*(.dtors))
  166. /* C++ exception handlers table: */
  167. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  168. *(.xt_except_desc)
  169. *(.gnu.linkonce.h.*)
  170. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  171. *(.xt_except_desc_end)
  172. *(.dynamic)
  173. *(.gnu.version_d)
  174. /* Addresses of memory regions reserved via SOC_RESERVE_MEMORY_REGION() */
  175. soc_reserved_memory_region_start = ABSOLUTE(.);
  176. KEEP (*(.reserved_memory_address))
  177. soc_reserved_memory_region_end = ABSOLUTE(.);
  178. /* System init functions registered via ESP_SYSTEM_INIT_FN */
  179. _esp_system_init_fn_array_start = ABSOLUTE(.);
  180. KEEP (*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*)))
  181. _esp_system_init_fn_array_end = ABSOLUTE(.);
  182. _rodata_end = ABSOLUTE(.);
  183. /* Literals are also RO data. */
  184. _lit4_start = ABSOLUTE(.);
  185. *(*.lit4)
  186. *(.lit4.*)
  187. *(.gnu.linkonce.lit4.*)
  188. _lit4_end = ABSOLUTE(.);
  189. . = ALIGN(4);
  190. _thread_local_start = ABSOLUTE(.);
  191. *(.tdata)
  192. *(.tdata.*)
  193. *(.tbss)
  194. *(.tbss.*)
  195. _thread_local_end = ABSOLUTE(.);
  196. _rodata_reserved_end = ABSOLUTE(.);
  197. . = ALIGN(ALIGNOF(.eh_frame));
  198. } > default_rodata_seg
  199. /* Keep this section shall be at least aligned on 4 */
  200. .eh_frame : ALIGN(8)
  201. {
  202. __eh_frame = ABSOLUTE(.);
  203. KEEP (*(.eh_frame))
  204. __eh_frame_end = ABSOLUTE(.);
  205. /* Guarantee that this section and the next one will be merged by making
  206. * them adjacent. */
  207. . = ALIGN(ALIGNOF(.eh_frame_hdr));
  208. } > default_rodata_seg
  209. /* To avoid any exception in C++ exception frame unwinding code, this section
  210. * shall be aligned on 8. */
  211. .eh_frame_hdr : ALIGN(8)
  212. {
  213. __eh_frame_hdr = ABSOLUTE(.);
  214. KEEP (*(.eh_frame_hdr))
  215. __eh_frame_hdr_end = ABSOLUTE(.);
  216. } > default_rodata_seg
  217. .flash.rodata_noload (NOLOAD) :
  218. {
  219. . = ALIGN (4);
  220. mapping[rodata_noload]
  221. } > default_rodata_seg
  222. /* Marks the end of IRAM code segment */
  223. .iram0.text_end (NOLOAD) :
  224. {
  225. /* ESP32-C2 memprot requires 16B padding for possible CPU prefetch and 512B alignment for PMS split lines */
  226. . += _esp_memprot_prefetch_pad_size;
  227. . = ALIGN(_esp_memprot_align_size);
  228. /* iram_end_test section exists for use by memprot unit tests only */
  229. *(.iram_end_test)
  230. _iram_text_end = ABSOLUTE(.);
  231. } > iram0_0_seg
  232. .iram0.data :
  233. {
  234. . = ALIGN(16);
  235. _iram_data_start = ABSOLUTE(.);
  236. mapping[iram0_data]
  237. _iram_data_end = ABSOLUTE(.);
  238. } > iram0_0_seg
  239. .iram0.bss (NOLOAD) :
  240. {
  241. . = ALIGN(16);
  242. _iram_bss_start = ABSOLUTE(.);
  243. mapping[iram0_bss]
  244. _iram_bss_end = ABSOLUTE(.);
  245. . = ALIGN(16);
  246. _iram_end = ABSOLUTE(.);
  247. } > iram0_0_seg
  248. /* Marks the end of data, bss and possibly rodata */
  249. .dram0.heap_start (NOLOAD) :
  250. {
  251. . = ALIGN (16);
  252. _heap_start = ABSOLUTE(.);
  253. } > dram0_0_seg
  254. }
  255. ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),
  256. "IRAM0 segment data does not fit.")
  257. ASSERT(((_heap_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)),
  258. "DRAM segment data does not fit.")