sections.ld.in 10 KB

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