sections.ld.in 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*
  2. * SPDX-FileCopyrightText: 2022 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. /**
  11. * RTC fast memory holds RTC wake stub code,
  12. * including from any source file named rtc_wake_stub*.c
  13. */
  14. .rtc.text :
  15. {
  16. . = ALIGN(4);
  17. _rtc_fast_start = ABSOLUTE(.);
  18. mapping[rtc_text]
  19. *rtc_wake_stub*.*(.literal .text .literal.* .text.*)
  20. *(.rtc_text_end_test)
  21. /* 16B padding for possible CPU prefetch and 4B alignment for PMS split lines */
  22. . += _esp_memprot_prefetch_pad_size;
  23. . = ALIGN(4);
  24. _rtc_text_end = ABSOLUTE(.);
  25. } > lp_ram_seg
  26. /**
  27. * This section located in RTC FAST Memory area.
  28. * It holds data marked with RTC_FAST_ATTR attribute.
  29. * See the file "esp_attr.h" for more information.
  30. */
  31. .rtc.force_fast :
  32. {
  33. . = ALIGN(4);
  34. _rtc_force_fast_start = ABSOLUTE(.);
  35. mapping[rtc_force_fast]
  36. *(.rtc.force_fast .rtc.force_fast.*)
  37. . = ALIGN(4) ;
  38. _rtc_force_fast_end = ABSOLUTE(.);
  39. } > lp_ram_seg
  40. /**
  41. * RTC data section holds RTC wake stub
  42. * data/rodata, including from any source file
  43. * named rtc_wake_stub*.c and the data marked with
  44. * RTC_DATA_ATTR, RTC_RODATA_ATTR attributes.
  45. */
  46. .rtc.data :
  47. {
  48. _rtc_data_start = ABSOLUTE(.);
  49. mapping[rtc_data]
  50. *rtc_wake_stub*.*(.data .rodata .data.* .rodata.* .srodata.*)
  51. _rtc_data_end = ABSOLUTE(.);
  52. } > lp_ram_seg
  53. /* RTC bss, from any source file named rtc_wake_stub*.c */
  54. .rtc.bss (NOLOAD) :
  55. {
  56. _rtc_bss_start = ABSOLUTE(.);
  57. *rtc_wake_stub*.*(.bss .bss.* .sbss .sbss.*)
  58. *rtc_wake_stub*.*(COMMON)
  59. mapping[rtc_bss]
  60. _rtc_bss_end = ABSOLUTE(.);
  61. } > lp_ram_seg
  62. /**
  63. * This section holds data that should not be initialized at power up
  64. * and will be retained during deep sleep.
  65. * User data marked with RTC_NOINIT_ATTR will be placed
  66. * into this section. See the file "esp_attr.h" for more information.
  67. */
  68. .rtc_noinit (NOLOAD):
  69. {
  70. . = ALIGN(4);
  71. _rtc_noinit_start = ABSOLUTE(.);
  72. *(.rtc_noinit .rtc_noinit.*)
  73. . = ALIGN(4) ;
  74. _rtc_noinit_end = ABSOLUTE(.);
  75. } > lp_ram_seg
  76. /**
  77. * This section located in RTC SLOW Memory area.
  78. * It holds data marked with RTC_SLOW_ATTR attribute.
  79. * See the file "esp_attr.h" for more information.
  80. */
  81. .rtc.force_slow :
  82. {
  83. . = ALIGN(4);
  84. _rtc_force_slow_start = ABSOLUTE(.);
  85. *(.rtc.force_slow .rtc.force_slow.*)
  86. . = ALIGN(4) ;
  87. _rtc_force_slow_end = ABSOLUTE(.);
  88. } > lp_ram_seg
  89. /**
  90. * This section holds RTC data that should have fixed addresses.
  91. * The data are not initialized at power-up and are retained during deep sleep.
  92. */
  93. .rtc_reserved (NOLOAD):
  94. {
  95. . = ALIGN(4);
  96. _rtc_reserved_start = ABSOLUTE(.);
  97. /* New data can only be added here to ensure existing data are not moved.
  98. Because data have adhered to the end of the segment and code is relied on it.
  99. >> put new data here << */
  100. *(.rtc_timer_data_in_rtc_mem .rtc_timer_data_in_rtc_mem.*)
  101. KEEP(*(.bootloader_data_rtc_mem .bootloader_data_rtc_mem.*))
  102. _rtc_reserved_end = ABSOLUTE(.);
  103. } > rtc_reserved_seg
  104. _rtc_reserved_length = _rtc_reserved_end - _rtc_reserved_start;
  105. ASSERT((_rtc_reserved_length <= LENGTH(rtc_reserved_seg)),
  106. "RTC reserved segment data does not fit.")
  107. /* Get size of rtc slow data based on rtc_data_location alias */
  108. _rtc_slow_length = (ORIGIN(rtc_slow_seg) == ORIGIN(rtc_data_location))
  109. ? (_rtc_force_slow_end - _rtc_data_start)
  110. : (_rtc_force_slow_end - _rtc_force_slow_start);
  111. _rtc_fast_length = (ORIGIN(rtc_slow_seg) == ORIGIN(rtc_data_location))
  112. ? (_rtc_force_fast_end - _rtc_fast_start)
  113. : (_rtc_noinit_end - _rtc_fast_start);
  114. ASSERT((_rtc_slow_length <= LENGTH(rtc_slow_seg)),
  115. "RTC_SLOW segment data does not fit.")
  116. ASSERT((_rtc_fast_length <= LENGTH(rtc_data_seg)),
  117. "RTC_FAST segment data does not fit.")
  118. .tcm.text :
  119. {
  120. /* Code marked as running out of TCM */
  121. _tcm_text_start = ABSOLUTE(.);
  122. mapping[tcm_text]
  123. _tcm_text_end = ABSOLUTE(.);
  124. } > tcm_idram_seg
  125. .tcm.data :
  126. {
  127. _tcm_data_start = ABSOLUTE(.);
  128. mapping[tcm_data]
  129. _tcm_data_end = ABSOLUTE(.);
  130. . = ALIGN(4);
  131. } > tcm_idram_seg
  132. .iram0.text :
  133. {
  134. _iram_start = ABSOLUTE(.);
  135. /* Vectors go to start of IRAM */
  136. ASSERT(ABSOLUTE(.) % 0x40 == 0, "vector address must be 64 byte aligned");
  137. KEEP(*(.exception_vectors_table.text));
  138. KEEP(*(.exception_vectors.text));
  139. . = ALIGN(4);
  140. _invalid_pc_placeholder = ABSOLUTE(.);
  141. /* Code marked as running out of IRAM */
  142. _iram_text_start = ABSOLUTE(.);
  143. mapping[iram0_text]
  144. } > iram0_0_seg
  145. /* Marks the end of IRAM code segment */
  146. .iram0.text_end (NOLOAD) :
  147. {
  148. /* ESP32-C6 memprot requires 16B padding for possible CPU prefetch and 512B alignment for PMS split lines */
  149. . += _esp_memprot_prefetch_pad_size;
  150. . = ALIGN(_esp_memprot_align_size);
  151. /* iram_end_test section exists for use by memprot unit tests only */
  152. *(.iram_end_test)
  153. _iram_text_end = ABSOLUTE(.);
  154. } > iram0_0_seg
  155. .iram0.data :
  156. {
  157. . = ALIGN(16);
  158. _iram_data_start = ABSOLUTE(.);
  159. mapping[iram0_data]
  160. _iram_data_end = ABSOLUTE(.);
  161. } > iram0_0_seg
  162. .iram0.bss (NOLOAD) :
  163. {
  164. . = ALIGN(16);
  165. _iram_bss_start = ABSOLUTE(.);
  166. mapping[iram0_bss]
  167. _iram_bss_end = ABSOLUTE(.);
  168. . = ALIGN(16);
  169. _iram_end = ABSOLUTE(.);
  170. } > iram0_0_seg
  171. /**
  172. * This section is required to skip .iram0.text area because iram0_0_seg and
  173. * dram0_0_seg reflect the same address space on different buses.
  174. */
  175. .dram0.dummy (NOLOAD):
  176. {
  177. . = ORIGIN(dram0_0_seg) + _iram_end - _iram_start;
  178. } > dram0_0_seg
  179. .dram0.data :
  180. {
  181. _data_start = ABSOLUTE(.);
  182. *(.gnu.linkonce.d.*)
  183. *(.data1)
  184. __global_pointer$ = . + 0x800;
  185. *(.sdata)
  186. *(.sdata.*)
  187. *(.gnu.linkonce.s.*)
  188. *(.gnu.linkonce.s2.*)
  189. *(.jcr)
  190. mapping[dram0_data]
  191. _data_end = ABSOLUTE(.);
  192. . = ALIGN(4);
  193. } > dram0_0_seg
  194. /**
  195. * This section holds data that should not be initialized at power up.
  196. * The section located in Internal SRAM memory region. The macro _NOINIT
  197. * can be used as attribute to place data into this section.
  198. * See the "esp_attr.h" file for more information.
  199. */
  200. .noinit (NOLOAD):
  201. {
  202. . = ALIGN(4);
  203. _noinit_start = ABSOLUTE(.);
  204. *(.noinit .noinit.*)
  205. . = ALIGN(4) ;
  206. _noinit_end = ABSOLUTE(.);
  207. } > dram0_0_seg
  208. /* Shared RAM */
  209. .dram0.bss (NOLOAD) :
  210. {
  211. . = ALIGN (8);
  212. _bss_start = ABSOLUTE(.);
  213. mapping[dram0_bss]
  214. *(.dynsbss)
  215. *(.sbss)
  216. *(.sbss.*)
  217. *(.gnu.linkonce.sb.*)
  218. *(.scommon)
  219. *(.sbss2)
  220. *(.sbss2.*)
  221. *(.gnu.linkonce.sb2.*)
  222. *(.dynbss)
  223. *(.share.mem)
  224. *(.gnu.linkonce.b.*)
  225. . = ALIGN (8);
  226. _bss_end = ABSOLUTE(.);
  227. } > dram0_0_seg
  228. ASSERT(((_bss_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), "DRAM segment data does not fit.")
  229. .flash.text :
  230. {
  231. _stext = .;
  232. _instruction_reserved_start = ABSOLUTE(.); /* This is a symbol marking the flash.text start, this can be used for mmu driver to maintain virtual address */
  233. _text_start = ABSOLUTE(.);
  234. mapping[flash_text]
  235. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  236. *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */
  237. *(.fini.literal)
  238. *(.fini)
  239. *(.gnu.version)
  240. /** CPU will try to prefetch up to 16 bytes of
  241. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  242. * safe access to up to 16 bytes after the last real instruction, add
  243. * dummy bytes to ensure this
  244. */
  245. . += _esp_flash_mmap_prefetch_pad_size;
  246. _text_end = ABSOLUTE(.);
  247. _instruction_reserved_end = ABSOLUTE(.); /* This is a symbol marking the flash.text end, this can be used for mmu driver to maintain virtual address */
  248. _etext = .;
  249. /**
  250. * Similar to _iram_start, this symbol goes here so it is
  251. * resolved by addr2line in preference to the first symbol in
  252. * the flash.text segment.
  253. */
  254. _flash_cache_start = ABSOLUTE(0);
  255. } > default_code_seg
  256. /**
  257. * This dummy section represents the .flash.text section but in default_rodata_seg.
  258. * Thus, it must have its alignment and (at least) its size.
  259. */
  260. .flash_rodata_dummy (NOLOAD):
  261. {
  262. _flash_rodata_dummy_start = .;
  263. /* Start at the same alignment constraint than .flash.text */
  264. . = ALIGN(ALIGNOF(.flash.text));
  265. /* Create an empty gap as big as .flash.text section */
  266. . = . + SIZEOF(.flash.text);
  267. /* Prepare the alignment of the section above. Few bytes (0x20) must be
  268. * added for the mapping header. */
  269. . = ALIGN(_esp_mmu_block_size) + 0x20;
  270. } > default_rodata_seg
  271. .flash.appdesc : ALIGN(0x10)
  272. {
  273. _rodata_reserved_start = ABSOLUTE(.); /* This is a symbol marking the flash.rodata start, this can be used for mmu driver to maintain virtual address */
  274. _rodata_start = ABSOLUTE(.);
  275. *(.rodata_desc .rodata_desc.*) /* Should be the first. App version info. DO NOT PUT ANYTHING BEFORE IT! */
  276. *(.rodata_custom_desc .rodata_custom_desc.*) /* Should be the second. Custom app version info. DO NOT PUT ANYTHING BEFORE IT! */
  277. /* Create an empty gap within this section. Thanks to this, the end of this
  278. * section will match .flash.rodata's begin address. Thus, both sections
  279. * will be merged when creating the final bin image. */
  280. . = ALIGN(ALIGNOF(.flash.rodata));
  281. } > default_rodata_seg
  282. .flash.rodata : ALIGN(0x10)
  283. {
  284. _flash_rodata_start = ABSOLUTE(.);
  285. mapping[flash_rodata]
  286. *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
  287. *(.gnu.linkonce.r.*)
  288. *(.rodata1)
  289. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  290. *(.xt_except_table)
  291. *(.gcc_except_table .gcc_except_table.*)
  292. *(.gnu.linkonce.e.*)
  293. *(.gnu.version_r)
  294. . = (. + 7) & ~ 3;
  295. /*
  296. * C++ constructor and destructor tables
  297. * Don't include anything from crtbegin.o or crtend.o, as IDF doesn't use toolchain crt.
  298. *
  299. * RISC-V gcc is configured with --enable-initfini-array so it emits an .init_array section instead.
  300. * But the init_priority sections will be sorted for iteration in ascending order during startup.
  301. * The rest of the init_array sections is sorted for iteration in descending order during startup, however.
  302. * Hence a different section is generated for the init_priority functions which is iterated in
  303. * ascending order during startup. The corresponding code can be found in startup.c.
  304. */
  305. __init_priority_array_start = ABSOLUTE(.);
  306. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array.*))
  307. __init_priority_array_end = ABSOLUTE(.);
  308. __init_array_start = ABSOLUTE(.);
  309. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array))
  310. __init_array_end = ABSOLUTE(.);
  311. KEEP (*crtbegin.*(.dtors))
  312. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  313. KEEP (*(SORT(.dtors.*)))
  314. KEEP (*(.dtors))
  315. /* C++ exception handlers table: */
  316. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  317. *(.xt_except_desc)
  318. *(.gnu.linkonce.h.*)
  319. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  320. *(.xt_except_desc_end)
  321. *(.dynamic)
  322. *(.gnu.version_d)
  323. /* Addresses of memory regions reserved via SOC_RESERVE_MEMORY_REGION() */
  324. soc_reserved_memory_region_start = ABSOLUTE(.);
  325. KEEP (*(.reserved_memory_address))
  326. soc_reserved_memory_region_end = ABSOLUTE(.);
  327. /* System init functions registered via ESP_SYSTEM_INIT_FN */
  328. _esp_system_init_fn_array_start = ABSOLUTE(.);
  329. KEEP (*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*)))
  330. _esp_system_init_fn_array_end = ABSOLUTE(.);
  331. _rodata_end = ABSOLUTE(.);
  332. /* Literals are also RO data. */
  333. _lit4_start = ABSOLUTE(.);
  334. *(*.lit4)
  335. *(.lit4.*)
  336. *(.gnu.linkonce.lit4.*)
  337. _lit4_end = ABSOLUTE(.);
  338. . = ALIGN(4);
  339. _thread_local_start = ABSOLUTE(.);
  340. *(.tdata)
  341. *(.tdata.*)
  342. *(.tbss)
  343. *(.tbss.*)
  344. _thread_local_end = ABSOLUTE(.);
  345. . = ALIGN(ALIGNOF(.eh_frame));
  346. } > default_rodata_seg
  347. /* Keep this section shall be at least aligned on 4 */
  348. .eh_frame : ALIGN(8)
  349. {
  350. __eh_frame = ABSOLUTE(.);
  351. KEEP (*(.eh_frame))
  352. __eh_frame_end = ABSOLUTE(.);
  353. /* Guarantee that this section and the next one will be merged by making
  354. * them adjacent. */
  355. . = ALIGN(ALIGNOF(.eh_frame_hdr));
  356. } > default_rodata_seg
  357. /* To avoid any exception in C++ exception frame unwinding code, this section
  358. * shall be aligned on 8. */
  359. .eh_frame_hdr : ALIGN(8)
  360. {
  361. __eh_frame_hdr = ABSOLUTE(.);
  362. KEEP (*(.eh_frame_hdr))
  363. __eh_frame_hdr_end = ABSOLUTE(.);
  364. } > default_rodata_seg
  365. /*
  366. This section is a place where we dump all the rodata which aren't used at runtime,
  367. so as to avoid binary size increase
  368. */
  369. .flash.rodata_noload (NOLOAD) :
  370. {
  371. /*
  372. This is a symbol marking the flash.rodata end, this can be used for mmu driver to maintain virtual address
  373. We don't need to include the noload rodata in this section
  374. */
  375. _rodata_reserved_end = ABSOLUTE(.);
  376. . = ALIGN (4);
  377. mapping[rodata_noload]
  378. } > default_rodata_seg
  379. /* Marks the end of data, bss and possibly rodata */
  380. .dram0.heap_start (NOLOAD) :
  381. {
  382. . = ALIGN (16);
  383. _heap_start = ABSOLUTE(.);
  384. } > dram0_0_seg
  385. }
  386. ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),
  387. "IRAM0 segment data does not fit.")
  388. ASSERT(((_heap_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)),
  389. "DRAM segment data does not fit.")