sections.ld.in 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. /**
  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. } > rtc_iram_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. } > rtc_data_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. } > rtc_data_location
  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. } > rtc_data_location
  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. } > rtc_data_location
  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. } > rtc_slow_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. .iram0.text :
  119. {
  120. _iram_start = ABSOLUTE(.);
  121. /* Vectors go to start of IRAM */
  122. ASSERT(ABSOLUTE(.) % 0x100 == 0, "vector address must be 256 byte aligned");
  123. KEEP(*(.exception_vectors_table.text));
  124. KEEP(*(.exception_vectors.text));
  125. . = ALIGN(4);
  126. _invalid_pc_placeholder = ABSOLUTE(.);
  127. /* Code marked as running out of IRAM */
  128. _iram_text_start = ABSOLUTE(.);
  129. mapping[iram0_text]
  130. } > iram0_0_seg
  131. /**
  132. * This section is required to skip .iram0.text area because iram0_0_seg and
  133. * dram0_0_seg reflect the same address space on different buses.
  134. */
  135. .dram0.dummy (NOLOAD):
  136. {
  137. . = ORIGIN(dram0_0_seg) + _iram_end - _iram_start;
  138. } > dram0_0_seg
  139. .dram0.data :
  140. {
  141. _data_start = ABSOLUTE(.);
  142. *(.gnu.linkonce.d.*)
  143. *(.data1)
  144. __global_pointer$ = . + 0x800;
  145. *(.sdata)
  146. *(.sdata.*)
  147. *(.gnu.linkonce.s.*)
  148. *(.gnu.linkonce.s2.*)
  149. *(.jcr)
  150. mapping[dram0_data]
  151. _data_end = ABSOLUTE(.);
  152. . = ALIGN(4);
  153. } > dram0_0_seg
  154. /**
  155. * This section holds data that should not be initialized at power up.
  156. * The section located in Internal SRAM memory region. The macro _NOINIT
  157. * can be used as attribute to place data into this section.
  158. * See the "esp_attr.h" file for more information.
  159. */
  160. .noinit (NOLOAD):
  161. {
  162. . = ALIGN(4);
  163. _noinit_start = ABSOLUTE(.);
  164. *(.noinit .noinit.*)
  165. . = ALIGN(4) ;
  166. _noinit_end = ABSOLUTE(.);
  167. } > dram0_0_seg
  168. /* Shared RAM */
  169. .dram0.bss (NOLOAD) :
  170. {
  171. . = ALIGN (8);
  172. _bss_start = ABSOLUTE(.);
  173. mapping[dram0_bss]
  174. *(.dynsbss)
  175. *(.sbss)
  176. *(.sbss.*)
  177. *(.gnu.linkonce.sb.*)
  178. *(.scommon)
  179. *(.sbss2)
  180. *(.sbss2.*)
  181. *(.gnu.linkonce.sb2.*)
  182. *(.dynbss)
  183. *(.share.mem)
  184. *(.gnu.linkonce.b.*)
  185. . = ALIGN (8);
  186. _bss_end = ABSOLUTE(.);
  187. } > dram0_0_seg
  188. ASSERT(((_bss_end - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)), "DRAM segment data does not fit.")
  189. .flash.text :
  190. {
  191. _stext = .;
  192. _instruction_reserved_start = ABSOLUTE(.); /* This is a symbol marking the flash.text start, this can be used for mmu driver to maintain virtual address */
  193. _text_start = ABSOLUTE(.);
  194. mapping[flash_text]
  195. *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
  196. *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */
  197. *(.fini.literal)
  198. *(.fini)
  199. *(.gnu.version)
  200. /** CPU will try to prefetch up to 16 bytes of
  201. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  202. * safe access to up to 16 bytes after the last real instruction, add
  203. * dummy bytes to ensure this
  204. */
  205. . += _esp_flash_mmap_prefetch_pad_size;
  206. _text_end = ABSOLUTE(.);
  207. _instruction_reserved_end = ABSOLUTE(.); /* This is a symbol marking the flash.text end, this can be used for mmu driver to maintain virtual address */
  208. _etext = .;
  209. /**
  210. * Similar to _iram_start, this symbol goes here so it is
  211. * resolved by addr2line in preference to the first symbol in
  212. * the flash.text segment.
  213. */
  214. _flash_cache_start = ABSOLUTE(0);
  215. } > default_code_seg
  216. /**
  217. * This dummy section represents the .flash.text section but in default_rodata_seg.
  218. * Thus, it must have its alignment and (at least) its size.
  219. */
  220. .flash_rodata_dummy (NOLOAD):
  221. {
  222. _flash_rodata_dummy_start = .;
  223. /* Start at the same alignment constraint than .flash.text */
  224. . = ALIGN(ALIGNOF(.flash.text));
  225. /* Create an empty gap as big as .flash.text section */
  226. . = . + SIZEOF(.flash.text);
  227. /* Prepare the alignment of the section above. Few bytes (0x20) must be
  228. * added for the mapping header. */
  229. . = ALIGN(_esp_mmu_block_size) + 0x20;
  230. } > default_rodata_seg
  231. .flash.appdesc : ALIGN(0x10)
  232. {
  233. _rodata_reserved_start = ABSOLUTE(.); /* This is a symbol marking the flash.rodata start, this can be used for mmu driver to maintain virtual address */
  234. _rodata_start = ABSOLUTE(.);
  235. *(.rodata_desc .rodata_desc.*) /* Should be the first. App version info. DO NOT PUT ANYTHING BEFORE IT! */
  236. *(.rodata_custom_desc .rodata_custom_desc.*) /* Should be the second. Custom app version info. DO NOT PUT ANYTHING BEFORE IT! */
  237. /* Create an empty gap within this section. Thanks to this, the end of this
  238. * section will match .flash.rodata's begin address. Thus, both sections
  239. * will be merged when creating the final bin image. */
  240. . = ALIGN(ALIGNOF(.flash.rodata));
  241. } >default_rodata_seg
  242. .flash.rodata : ALIGN(0x10)
  243. {
  244. _flash_rodata_start = ABSOLUTE(.);
  245. mapping[flash_rodata]
  246. *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
  247. *(.gnu.linkonce.r.*)
  248. *(.rodata1)
  249. __XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
  250. *(.xt_except_table)
  251. *(.gcc_except_table .gcc_except_table.*)
  252. *(.gnu.linkonce.e.*)
  253. *(.gnu.version_r)
  254. . = (. + 7) & ~ 3;
  255. /*
  256. * C++ constructor and destructor tables
  257. * Don't include anything from crtbegin.o or crtend.o, as IDF doesn't use toolchain crt.
  258. *
  259. * RISC-V gcc is configured with --enable-initfini-array so it emits an .init_array section instead.
  260. * But the init_priority sections will be sorted for iteration in ascending order during startup.
  261. * The rest of the init_array sections is sorted for iteration in descending order during startup, however.
  262. * Hence a different section is generated for the init_priority functions which is iterated in
  263. * ascending order during startup. The corresponding code can be found in startup.c.
  264. */
  265. __init_priority_array_start = ABSOLUTE(.);
  266. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array.*))
  267. __init_priority_array_end = ABSOLUTE(.);
  268. __init_array_start = ABSOLUTE(.);
  269. KEEP (*(EXCLUDE_FILE (*crtend.* *crtbegin.*) .init_array))
  270. __init_array_end = ABSOLUTE(.);
  271. KEEP (*crtbegin.*(.dtors))
  272. KEEP (*(EXCLUDE_FILE (*crtend.*) .dtors))
  273. KEEP (*(SORT(.dtors.*)))
  274. KEEP (*(.dtors))
  275. /* C++ exception handlers table: */
  276. __XT_EXCEPTION_DESCS_ = ABSOLUTE(.);
  277. *(.xt_except_desc)
  278. *(.gnu.linkonce.h.*)
  279. __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
  280. *(.xt_except_desc_end)
  281. *(.dynamic)
  282. *(.gnu.version_d)
  283. /* Addresses of memory regions reserved via SOC_RESERVE_MEMORY_REGION() */
  284. soc_reserved_memory_region_start = ABSOLUTE(.);
  285. KEEP (*(.reserved_memory_address))
  286. soc_reserved_memory_region_end = ABSOLUTE(.);
  287. /* System init functions registered via ESP_SYSTEM_INIT_FN */
  288. _esp_system_init_fn_array_start = ABSOLUTE(.);
  289. KEEP (*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*)))
  290. _esp_system_init_fn_array_end = ABSOLUTE(.);
  291. _rodata_end = ABSOLUTE(.);
  292. /* Literals are also RO data. */
  293. _lit4_start = ABSOLUTE(.);
  294. *(*.lit4)
  295. *(.lit4.*)
  296. *(.gnu.linkonce.lit4.*)
  297. _lit4_end = ABSOLUTE(.);
  298. . = ALIGN(4);
  299. _thread_local_start = ABSOLUTE(.);
  300. *(.tdata)
  301. *(.tdata.*)
  302. *(.tbss)
  303. *(.tbss.*)
  304. _thread_local_end = ABSOLUTE(.);
  305. . = ALIGN(ALIGNOF(.eh_frame));
  306. } > default_rodata_seg
  307. /* Keep this section shall be at least aligned on 4 */
  308. .eh_frame : ALIGN(8)
  309. {
  310. __eh_frame = ABSOLUTE(.);
  311. KEEP (*(.eh_frame))
  312. __eh_frame_end = ABSOLUTE(.);
  313. /* Guarantee that this section and the next one will be merged by making
  314. * them adjacent. */
  315. . = ALIGN(ALIGNOF(.eh_frame_hdr));
  316. } > default_rodata_seg
  317. /* To avoid any exception in C++ exception frame unwinding code, this section
  318. * shall be aligned on 8. */
  319. .eh_frame_hdr : ALIGN(8)
  320. {
  321. __eh_frame_hdr = ABSOLUTE(.);
  322. KEEP (*(.eh_frame_hdr))
  323. __eh_frame_hdr_end = ABSOLUTE(.);
  324. } > default_rodata_seg
  325. /*
  326. This section is a place where we dump all the rodata which aren't used at runtime,
  327. so as to avoid binary size increase
  328. */
  329. .flash.rodata_noload (NOLOAD) :
  330. {
  331. /*
  332. This is a symbol marking the flash.rodata end, this can be used for mmu driver to maintain virtual address
  333. We don't need to include the noload rodata in this section
  334. */
  335. _rodata_reserved_end = ABSOLUTE(.);
  336. . = ALIGN (4);
  337. mapping[rodata_noload]
  338. } > default_rodata_seg
  339. /* Marks the end of IRAM code segment */
  340. .iram0.text_end (NOLOAD) :
  341. {
  342. /* iram_end_test section exists for use by Memprot unit tests only */
  343. *(.iram_end_test)
  344. /* ESP32-C3 memprot requires 16B padding for possible CPU prefetch and 512B alignment for PMS split lines */
  345. . += _esp_memprot_prefetch_pad_size;
  346. . = ALIGN(_esp_memprot_align_size);
  347. _iram_text_end = ABSOLUTE(.);
  348. } > iram0_0_seg
  349. .iram0.data :
  350. {
  351. . = ALIGN(16);
  352. _iram_data_start = ABSOLUTE(.);
  353. mapping[iram0_data]
  354. _iram_data_end = ABSOLUTE(.);
  355. } > iram0_0_seg
  356. .iram0.bss (NOLOAD) :
  357. {
  358. . = ALIGN(16);
  359. _iram_bss_start = ABSOLUTE(.);
  360. mapping[iram0_bss]
  361. _iram_bss_end = ABSOLUTE(.);
  362. . = ALIGN(16);
  363. _iram_end = ABSOLUTE(.);
  364. } > iram0_0_seg
  365. /* Marks the end of data, bss and possibly rodata */
  366. .dram0.heap_start (NOLOAD) :
  367. {
  368. . = ALIGN (16);
  369. _heap_start = ABSOLUTE(.);
  370. } > dram0_0_seg
  371. }
  372. ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),
  373. "IRAM0 segment data does not fit.")
  374. ASSERT(((_heap_start - ORIGIN(dram0_0_seg)) <= LENGTH(dram0_0_seg)),
  375. "DRAM segment data does not fit.")