mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(esp_system): xtensa: refactor linker scripts and reduce binary size for C++ apps
This commit is contained in:
@@ -185,9 +185,6 @@ _heap_start = _heap_low_start;
|
||||
/* Heap ends at top of dram0_0_seg */
|
||||
_heap_end = 0x40000000;
|
||||
|
||||
_data_seg_org = ORIGIN(rtc_data_seg);
|
||||
|
||||
|
||||
/* RTC fast memory shares the same range for both data and instructions */
|
||||
REGION_ALIAS("rtc_data_seg", rtc_iram_seg );
|
||||
|
||||
|
||||
@@ -24,11 +24,7 @@ SECTIONS
|
||||
|
||||
*(.rtc.entry.literal .rtc.entry.text)
|
||||
|
||||
mapping[rtc_text]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[rtc_text]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(rtc_text)
|
||||
|
||||
*rtc_wake_stub*.*(.literal .text .literal.* .text.*)
|
||||
*(.rtc_text_end_test)
|
||||
@@ -51,11 +47,7 @@ SECTIONS
|
||||
{
|
||||
ALIGNED_SYMBOL(4, _rtc_force_fast_start)
|
||||
|
||||
mapping[rtc_force_fast]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[rtc_force_fast]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(rtc_force_fast)
|
||||
|
||||
*(.rtc.force_fast .rtc.force_fast.*)
|
||||
|
||||
@@ -74,11 +66,7 @@ SECTIONS
|
||||
{
|
||||
_rtc_data_start = ABSOLUTE(.);
|
||||
|
||||
mapping[rtc_data]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[rtc_data]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(rtc_data)
|
||||
|
||||
*rtc_wake_stub*.*(.data .rodata .data.* .rodata.*)
|
||||
|
||||
@@ -93,11 +81,7 @@ SECTIONS
|
||||
*rtc_wake_stub*.*(.bss .bss.*)
|
||||
*rtc_wake_stub*.*(COMMON)
|
||||
|
||||
mapping[rtc_bss]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[rtc_bss]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(rtc_bss)
|
||||
|
||||
_rtc_bss_end = ABSOLUTE(.);
|
||||
} > rtc_data_location
|
||||
@@ -114,7 +98,7 @@ SECTIONS
|
||||
{
|
||||
ALIGNED_SYMBOL(4, _rtc_noinit_start)
|
||||
|
||||
mapping[rtc_noinit]
|
||||
SECTION_MAPPINGS(rtc_noinit)
|
||||
|
||||
*(.rtc_noinit .rtc_noinit.*)
|
||||
|
||||
@@ -213,13 +197,7 @@ SECTIONS
|
||||
/* Code marked as running out of IRAM */
|
||||
_iram_text_start = ABSOLUTE(.);
|
||||
|
||||
mapping[iram0_text]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[iram0_text]
|
||||
FAST_REFLASHING_PADDING;
|
||||
/* mutable libs end */
|
||||
|
||||
SECTION_MAPPINGS_WITH_PADDING(iram0_text)
|
||||
} > iram0_0_seg
|
||||
|
||||
/**
|
||||
@@ -228,8 +206,7 @@ SECTIONS
|
||||
*/
|
||||
.dram0.dummy (NOLOAD):
|
||||
{
|
||||
/* MAX() uses unsigned long arithmetic. Add offset to prevent underflow when _iram_end < _diram_i_start */
|
||||
. = ORIGIN(dram0_0_seg) + MAX(_iram_end - _diram_i_start + (_diram_i_start - ORIGIN(iram0_0_seg)), (_diram_i_start - ORIGIN(iram0_0_seg))) - (_diram_i_start - ORIGIN(iram0_0_seg));
|
||||
. = ORIGIN(dram0_0_seg) + ((_iram_end > _diram_i_start) ? (_iram_end - _diram_i_start) : 0);
|
||||
} > dram0_0_seg
|
||||
|
||||
.dram0.data :
|
||||
@@ -243,12 +220,7 @@ SECTIONS
|
||||
*(.gnu.linkonce.s2.*)
|
||||
*(.jcr)
|
||||
|
||||
mapping[dram0_data]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[dram0_data]
|
||||
FAST_REFLASHING_PADDING;
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS_WITH_PADDING(dram0_data)
|
||||
|
||||
_data_end = ABSOLUTE(.);
|
||||
} > dram0_0_seg
|
||||
@@ -273,15 +245,7 @@ SECTIONS
|
||||
{
|
||||
ALIGNED_SYMBOL(8, _bss_start)
|
||||
|
||||
/**
|
||||
* ldgen places all bss-related data to mapping[dram0_bss]
|
||||
* (See components/esp_system/app.lf).
|
||||
*/
|
||||
mapping[dram0_bss]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[dram0_bss]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(dram0_bss)
|
||||
|
||||
ALIGNED_SYMBOL(8, _bss_end)
|
||||
} > dram0_0_seg
|
||||
@@ -299,12 +263,7 @@ SECTIONS
|
||||
_instruction_reserved_start = ABSOLUTE(.);
|
||||
_text_start = ABSOLUTE(.);
|
||||
|
||||
mapping[flash_text]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[flash_text]
|
||||
FAST_REFLASHING_PADDING;
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS_WITH_PADDING(flash_text)
|
||||
|
||||
*(.stub)
|
||||
*(.gnu.warning)
|
||||
@@ -378,7 +337,7 @@ SECTIONS
|
||||
{
|
||||
_flash_rodata_start = ABSOLUTE(.);
|
||||
|
||||
mapping[flash_rodata]
|
||||
SECTION_MAPPINGS_WITH_PADDING(flash_rodata)
|
||||
|
||||
*(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */
|
||||
*(.gnu.linkonce.r.*)
|
||||
@@ -396,16 +355,6 @@ SECTIONS
|
||||
__XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
|
||||
*(.xt_except_desc_end)
|
||||
|
||||
#if EH_FRAME_LINKING_ENABLED
|
||||
ALIGNED_SYMBOL(4, __eh_frame)
|
||||
KEEP(*(.eh_frame))
|
||||
/**
|
||||
* As we are not linking with crtend.o, which includes the CIE terminator
|
||||
* (see __FRAME_END__ in libgcc sources), it is manually provided here.
|
||||
*/
|
||||
LONG(0);
|
||||
#endif // EH_FRAME_LINKING_ENABLED
|
||||
|
||||
/**
|
||||
* C++ constructor tables.
|
||||
*
|
||||
@@ -431,11 +380,6 @@ SECTIONS
|
||||
KEEP (*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*)))
|
||||
_esp_system_init_fn_array_end = ABSOLUTE(.);
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[flash_rodata]
|
||||
FAST_REFLASHING_PADDING;
|
||||
/* mutable libs end */
|
||||
|
||||
_rodata_end = ABSOLUTE(.);
|
||||
|
||||
/* Literals are also RO data. */
|
||||
@@ -444,9 +388,37 @@ SECTIONS
|
||||
*(.lit4.*)
|
||||
*(.gnu.linkonce.lit4.*)
|
||||
_lit4_end = ABSOLUTE(.);
|
||||
. = ALIGN(ALIGNOF(SECTION_AFTER_FLASH_RODATA));
|
||||
} > default_rodata_seg
|
||||
ASSERT_SECTIONS_GAP(.flash.rodata, SECTION_AFTER_FLASH_RODATA)
|
||||
|
||||
/* TLS data. */
|
||||
ALIGNED_SYMBOL(4, _thread_local_start)
|
||||
#if EH_FRAME_LINKING_ENABLED
|
||||
.eh_frame :
|
||||
{
|
||||
ALIGNED_SYMBOL(4, __eh_frame)
|
||||
|
||||
KEEP (*(.eh_frame))
|
||||
/**
|
||||
* As we are not linking with crtend.o, which includes the CIE terminator
|
||||
* (see __FRAME_END__ in libgcc sources), it is manually provided here.
|
||||
*/
|
||||
LONG(0);
|
||||
|
||||
__eh_frame_end = ABSOLUTE(.);
|
||||
|
||||
. = ALIGN(ALIGNOF(.flash.tdata));
|
||||
} > default_rodata_seg
|
||||
#endif // EH_FRAME_LINKING_ENABLED
|
||||
|
||||
.flash.tdata :
|
||||
{
|
||||
/* Keep tdata and tbss sections contiguous (no gaps between them).
|
||||
* The TLS runtime code calculates offsets assuming these sections are
|
||||
* adjacent. Gaps would cause incorrect address calculations, leading
|
||||
* to accessing wrong memory.
|
||||
*/
|
||||
/* tdata sections */
|
||||
_thread_local_data_start = ABSOLUTE(.);
|
||||
#if CONFIG_LIBC_PICOLIBC
|
||||
_picolibc_reent_stub_start = ABSOLUTE(.);
|
||||
KEEP(*(.tdata.errno))
|
||||
@@ -458,15 +430,18 @@ SECTIONS
|
||||
#endif // CONFIG_LIBC_PICOLIBC_NEWLIB_COMPATIBILITY
|
||||
_picolibc_reent_stub_end = ABSOLUTE(.);
|
||||
#endif // CONFIG_LIBC_PICOLIBC
|
||||
*(.tdata)
|
||||
*(.tdata.*)
|
||||
*(.tbss)
|
||||
*(.tbss.*)
|
||||
_thread_local_end = ABSOLUTE(.);
|
||||
*(.tdata .tdata.* .gnu.linkonce.td.*)
|
||||
_thread_local_data_end = ABSOLUTE(.);
|
||||
/* tbss sections */
|
||||
_thread_local_bss_start = ABSOLUTE(.);
|
||||
*(.tbss .tbss.* .gnu.linkonce.tb.*)
|
||||
*(.tcommon .tcommon.*)
|
||||
_thread_local_bss_end = ABSOLUTE(.);
|
||||
} > default_rodata_seg
|
||||
_tls_section_alignment = ALIGNOF(.flash.tdata);
|
||||
ASSERT_PICOLIBC_REENT_STUB()
|
||||
|
||||
_flash_rodata_align = ALIGNOF(.flash.rodata);
|
||||
ASSERT(_thread_local_data_end == _thread_local_bss_start,
|
||||
"tdata and tbss must be contiguous.")
|
||||
|
||||
/**
|
||||
* This section contains all the rodata that is not used
|
||||
@@ -481,11 +456,7 @@ SECTIONS
|
||||
*/
|
||||
_rodata_reserved_end = ABSOLUTE(.);
|
||||
|
||||
mapping[rodata_noload]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[rodata_noload]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(rodata_noload)
|
||||
} > default_rodata_seg
|
||||
|
||||
/**
|
||||
@@ -505,11 +476,7 @@ SECTIONS
|
||||
{
|
||||
_ext_ram_bss_start = ABSOLUTE(.);
|
||||
|
||||
mapping[extern_ram]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[extern_ram]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(extern_ram)
|
||||
|
||||
ALIGNED_SYMBOL(4, _ext_ram_bss_end)
|
||||
} > extern_ram_seg
|
||||
@@ -524,6 +491,7 @@ SECTIONS
|
||||
{
|
||||
_ext_ram_noinit_start = ABSOLUTE(.);
|
||||
|
||||
SECTION_MAPPINGS(extram_noinit)
|
||||
*(.ext_ram_noinit*)
|
||||
|
||||
ALIGNED_SYMBOL(4, _ext_ram_noinit_end)
|
||||
@@ -547,11 +515,7 @@ SECTIONS
|
||||
{
|
||||
ALIGNED_SYMBOL(4, _iram_data_start)
|
||||
|
||||
mapping[iram0_data]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[iram0_data]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(iram0_data)
|
||||
|
||||
ALIGNED_SYMBOL(4, _iram_data_end)
|
||||
} > iram0_0_seg
|
||||
@@ -560,11 +524,7 @@ SECTIONS
|
||||
{
|
||||
ALIGNED_SYMBOL(4, _iram_bss_start)
|
||||
|
||||
mapping[iram0_bss]
|
||||
|
||||
/* mutable libs begin */
|
||||
mutable[iram0_bss]
|
||||
/* mutable libs end */
|
||||
SECTION_MAPPINGS(iram0_bss)
|
||||
|
||||
_iram_bss_end = ABSOLUTE(.);
|
||||
ALIGNED_SYMBOL(4, _iram_end)
|
||||
@@ -577,7 +537,8 @@ SECTIONS
|
||||
ALIGNED_SYMBOL(8, _heap_low_start)
|
||||
} > dram0_0_seg
|
||||
|
||||
#include "elf_misc.ld.in"
|
||||
#include "ld.debug.sections"
|
||||
#include "ld.discard.sections"
|
||||
}
|
||||
|
||||
ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),
|
||||
|
||||
Reference in New Issue
Block a user