sections.ld.in 12 KB

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