sections.ld.in 12 KB

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