From d42e894a744a5469ffa2e7733d3e6ab9cfe000a8 Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Wed, 24 Apr 2024 20:39:52 +0400 Subject: [PATCH 1/2] fix(system): discard eh_frame sections if disabled in sdkconfig --- components/esp_system/ld/esp32/sections.ld.in | 14 ++++++++-- .../esp_system/ld/esp32c2/sections.ld.in | 27 ++++++++++++++----- .../esp_system/ld/esp32c3/sections.ld.in | 27 ++++++++++++++----- .../ld/esp32c5/beta3/sections.ld.in | 27 ++++++++++++++----- .../esp_system/ld/esp32c5/mp/sections.ld.in | 27 ++++++++++++++----- .../esp_system/ld/esp32c6/sections.ld.in | 27 ++++++++++++++----- .../esp_system/ld/esp32c61/sections.ld.in | 27 ++++++++++++++----- .../esp_system/ld/esp32h2/sections.ld.in | 27 ++++++++++++++----- .../esp_system/ld/esp32p4/sections.ld.in | 27 ++++++++++++++----- .../esp_system/ld/esp32s2/sections.ld.in | 14 ++++++++-- .../esp_system/ld/esp32s3/sections.ld.in | 14 ++++++++-- 11 files changed, 196 insertions(+), 62 deletions(-) diff --git a/components/esp_system/ld/esp32/sections.ld.in b/components/esp_system/ld/esp32/sections.ld.in index 19c395cbe5..b67d6af10d 100644 --- a/components/esp_system/ld/esp32/sections.ld.in +++ b/components/esp_system/ld/esp32/sections.ld.in @@ -352,6 +352,7 @@ SECTIONS __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); *(.xt_except_desc_end) +#if CONFIG_COMPILER_CXX_EXCEPTIONS ALIGNED_SYMBOL(4, __eh_frame) KEEP(*(.eh_frame)) /** @@ -359,6 +360,7 @@ SECTIONS * (see __FRAME_END__ in libgcc sources), it is manually provided here. */ LONG(0); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS /** * C++ constructor tables. @@ -500,12 +502,20 @@ SECTIONS */ .xt.prop 0 : { - KEEP (*(.xt.prop .gnu.linkonce.prop.*)) + KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*)) } .xt.lit 0 : { - KEEP (*(.xt.lit .gnu.linkonce.p.*)) + KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*)) + } + + /DISCARD/ : + { + *(.eh_frame_hdr) +#if !CONFIG_COMPILER_CXX_EXCEPTIONS + *(.eh_frame) +#endif // !CONFIG_COMPILER_CXX_EXCEPTIONS } } diff --git a/components/esp_system/ld/esp32c2/sections.ld.in b/components/esp_system/ld/esp32c2/sections.ld.in index 42c906acad..43255d8d93 100644 --- a/components/esp_system/ld/esp32c2/sections.ld.in +++ b/components/esp_system/ld/esp32c2/sections.ld.in @@ -233,17 +233,21 @@ SECTIONS .eh_frame_hdr : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame_hdr) KEEP (*(.eh_frame_hdr)) __eh_frame_hdr_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.eh_frame)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame) .eh_frame : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame) KEEP (*(.eh_frame)) @@ -254,6 +258,8 @@ SECTIONS LONG(0); __eh_frame_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.flash.tdata)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata) @@ -339,13 +345,20 @@ SECTIONS ALIGNED_SYMBOL(16, _heap_start) } > dram0_0_seg - /** - * Discarding .rela.* sections results in the following mapping: - * .rela.text.* -> .text.* - * .rela.data.* -> .data.* - * And so forth... - */ - /DISCARD/ : { *(.rela.*) } + /DISCARD/ : + { + /** + * Discarding .rela.* sections results in the following mapping: + * .rela.text.* -> .text.* + * .rela.data.* -> .data.* + * And so forth... + */ + *(.rela.*) +#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + *(.eh_frame_hdr) + *(.eh_frame) +#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + } } ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), diff --git a/components/esp_system/ld/esp32c3/sections.ld.in b/components/esp_system/ld/esp32c3/sections.ld.in index f5962dd6f0..c8c29d8cd5 100644 --- a/components/esp_system/ld/esp32c3/sections.ld.in +++ b/components/esp_system/ld/esp32c3/sections.ld.in @@ -351,17 +351,21 @@ SECTIONS .eh_frame_hdr : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame_hdr) KEEP (*(.eh_frame_hdr)) __eh_frame_hdr_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.eh_frame)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame) .eh_frame : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame) KEEP (*(.eh_frame)) @@ -372,6 +376,8 @@ SECTIONS LONG(0); __eh_frame_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.flash.tdata)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata) @@ -451,13 +457,20 @@ SECTIONS ALIGNED_SYMBOL(16, _heap_start) } > dram0_0_seg - /** - * Discarding .rela.* sections results in the following mapping: - * .rela.text.* -> .text.* - * .rela.data.* -> .data.* - * And so forth... - */ - /DISCARD/ : { *(.rela.*) } + /DISCARD/ : + { + /** + * Discarding .rela.* sections results in the following mapping: + * .rela.text.* -> .text.* + * .rela.data.* -> .data.* + * And so forth... + */ + *(.rela.*) +#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + *(.eh_frame_hdr) + *(.eh_frame) +#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + } } ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), diff --git a/components/esp_system/ld/esp32c5/beta3/sections.ld.in b/components/esp_system/ld/esp32c5/beta3/sections.ld.in index c18b9510f2..16533c7af6 100644 --- a/components/esp_system/ld/esp32c5/beta3/sections.ld.in +++ b/components/esp_system/ld/esp32c5/beta3/sections.ld.in @@ -374,17 +374,21 @@ SECTIONS .eh_frame_hdr : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame_hdr) KEEP (*(.eh_frame_hdr)) __eh_frame_hdr_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.eh_frame)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame) .eh_frame : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame) KEEP (*(.eh_frame)) @@ -395,6 +399,8 @@ SECTIONS LONG(0); __eh_frame_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.flash.tdata)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata) @@ -442,13 +448,20 @@ SECTIONS ALIGNED_SYMBOL(16, _heap_start) } > dram0_0_seg - /** - * Discarding .rela.* sections results in the following mapping: - * .rela.text.* -> .text.* - * .rela.data.* -> .data.* - * And so forth... - */ - /DISCARD/ : { *(.rela.*) } + /DISCARD/ : + { + /** + * Discarding .rela.* sections results in the following mapping: + * .rela.text.* -> .text.* + * .rela.data.* -> .data.* + * And so forth... + */ + *(.rela.*) +#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + *(.eh_frame_hdr) + *(.eh_frame) +#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + } } ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)), diff --git a/components/esp_system/ld/esp32c5/mp/sections.ld.in b/components/esp_system/ld/esp32c5/mp/sections.ld.in index c0b76d0af2..91013909f6 100644 --- a/components/esp_system/ld/esp32c5/mp/sections.ld.in +++ b/components/esp_system/ld/esp32c5/mp/sections.ld.in @@ -374,17 +374,21 @@ SECTIONS .eh_frame_hdr : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame_hdr) KEEP (*(.eh_frame_hdr)) __eh_frame_hdr_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.eh_frame)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame) .eh_frame : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame) KEEP (*(.eh_frame)) @@ -395,6 +399,8 @@ SECTIONS LONG(0); __eh_frame_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.flash.tdata)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata) @@ -442,13 +448,20 @@ SECTIONS ALIGNED_SYMBOL(16, _heap_start) } > sram_seg - /** - * Discarding .rela.* sections results in the following mapping: - * .rela.text.* -> .text.* - * .rela.data.* -> .data.* - * And so forth... - */ - /DISCARD/ : { *(.rela.*) } + /DISCARD/ : + { + /** + * Discarding .rela.* sections results in the following mapping: + * .rela.text.* -> .text.* + * .rela.data.* -> .data.* + * And so forth... + */ + *(.rela.*) +#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + *(.eh_frame_hdr) + *(.eh_frame) +#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + } } ASSERT(((_iram_end - ORIGIN(sram_seg)) <= LENGTH(sram_seg)), diff --git a/components/esp_system/ld/esp32c6/sections.ld.in b/components/esp_system/ld/esp32c6/sections.ld.in index 2af3405154..cfd95dd74d 100644 --- a/components/esp_system/ld/esp32c6/sections.ld.in +++ b/components/esp_system/ld/esp32c6/sections.ld.in @@ -364,17 +364,21 @@ SECTIONS .eh_frame_hdr : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame_hdr) KEEP (*(.eh_frame_hdr)) __eh_frame_hdr_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.eh_frame)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame) .eh_frame : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame) KEEP (*(.eh_frame)) @@ -385,6 +389,8 @@ SECTIONS LONG(0); __eh_frame_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.flash.tdata)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata) @@ -432,11 +438,18 @@ SECTIONS ALIGNED_SYMBOL(16, _heap_start) } > sram_seg - /** - * Discarding .rela.* sections results in the following mapping: - * .rela.text.* -> .text.* - * .rela.data.* -> .data.* - * And so forth... - */ - /DISCARD/ : { *(.rela.*) } + /DISCARD/ : + { + /** + * Discarding .rela.* sections results in the following mapping: + * .rela.text.* -> .text.* + * .rela.data.* -> .data.* + * And so forth... + */ + *(.rela.*) +#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + *(.eh_frame_hdr) + *(.eh_frame) +#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + } } diff --git a/components/esp_system/ld/esp32c61/sections.ld.in b/components/esp_system/ld/esp32c61/sections.ld.in index c0b76d0af2..91013909f6 100644 --- a/components/esp_system/ld/esp32c61/sections.ld.in +++ b/components/esp_system/ld/esp32c61/sections.ld.in @@ -374,17 +374,21 @@ SECTIONS .eh_frame_hdr : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame_hdr) KEEP (*(.eh_frame_hdr)) __eh_frame_hdr_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.eh_frame)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame) .eh_frame : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame) KEEP (*(.eh_frame)) @@ -395,6 +399,8 @@ SECTIONS LONG(0); __eh_frame_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.flash.tdata)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata) @@ -442,13 +448,20 @@ SECTIONS ALIGNED_SYMBOL(16, _heap_start) } > sram_seg - /** - * Discarding .rela.* sections results in the following mapping: - * .rela.text.* -> .text.* - * .rela.data.* -> .data.* - * And so forth... - */ - /DISCARD/ : { *(.rela.*) } + /DISCARD/ : + { + /** + * Discarding .rela.* sections results in the following mapping: + * .rela.text.* -> .text.* + * .rela.data.* -> .data.* + * And so forth... + */ + *(.rela.*) +#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + *(.eh_frame_hdr) + *(.eh_frame) +#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + } } ASSERT(((_iram_end - ORIGIN(sram_seg)) <= LENGTH(sram_seg)), diff --git a/components/esp_system/ld/esp32h2/sections.ld.in b/components/esp_system/ld/esp32h2/sections.ld.in index 2af3405154..cfd95dd74d 100644 --- a/components/esp_system/ld/esp32h2/sections.ld.in +++ b/components/esp_system/ld/esp32h2/sections.ld.in @@ -364,17 +364,21 @@ SECTIONS .eh_frame_hdr : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame_hdr) KEEP (*(.eh_frame_hdr)) __eh_frame_hdr_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.eh_frame)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame) .eh_frame : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame) KEEP (*(.eh_frame)) @@ -385,6 +389,8 @@ SECTIONS LONG(0); __eh_frame_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.flash.tdata)); } > default_rodata_seg ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata) @@ -432,11 +438,18 @@ SECTIONS ALIGNED_SYMBOL(16, _heap_start) } > sram_seg - /** - * Discarding .rela.* sections results in the following mapping: - * .rela.text.* -> .text.* - * .rela.data.* -> .data.* - * And so forth... - */ - /DISCARD/ : { *(.rela.*) } + /DISCARD/ : + { + /** + * Discarding .rela.* sections results in the following mapping: + * .rela.text.* -> .text.* + * .rela.data.* -> .data.* + * And so forth... + */ + *(.rela.*) +#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + *(.eh_frame_hdr) + *(.eh_frame) +#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + } } diff --git a/components/esp_system/ld/esp32p4/sections.ld.in b/components/esp_system/ld/esp32p4/sections.ld.in index 2f0ff2d0f0..9b5667b18e 100644 --- a/components/esp_system/ld/esp32p4/sections.ld.in +++ b/components/esp_system/ld/esp32p4/sections.ld.in @@ -406,17 +406,21 @@ SECTIONS .eh_frame_hdr : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame_hdr) KEEP (*(.eh_frame_hdr)) __eh_frame_hdr_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.eh_frame)); } > rodata_seg_low ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame) .eh_frame : { +#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME ALIGNED_SYMBOL(4, __eh_frame) KEEP (*(.eh_frame)) @@ -427,6 +431,8 @@ SECTIONS LONG(0); __eh_frame_end = ABSOLUTE(.); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME + . = ALIGN(ALIGNOF(.flash.tdata)); } > rodata_seg_low ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata) @@ -508,11 +514,18 @@ SECTIONS ALIGNED_SYMBOL(16, _heap_start_high) } > sram_high - /** - * Discarding .rela.* sections results in the following mapping: - * .rela.text.* -> .text.* - * .rela.data.* -> .data.* - * And so forth... - */ - /DISCARD/ : { *(.rela.*) } + /DISCARD/ : + { + /** + * Discarding .rela.* sections results in the following mapping: + * .rela.text.* -> .text.* + * .rela.data.* -> .data.* + * And so forth... + */ + *(.rela.*) +#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + *(.eh_frame_hdr) + *(.eh_frame) +#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME) + } } diff --git a/components/esp_system/ld/esp32s2/sections.ld.in b/components/esp_system/ld/esp32s2/sections.ld.in index f177a766fe..a6a5e4c806 100644 --- a/components/esp_system/ld/esp32s2/sections.ld.in +++ b/components/esp_system/ld/esp32s2/sections.ld.in @@ -335,6 +335,7 @@ SECTIONS __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); *(.xt_except_desc_end) +#if CONFIG_COMPILER_CXX_EXCEPTIONS ALIGNED_SYMBOL(4, __eh_frame) KEEP(*(.eh_frame)) /** @@ -342,6 +343,7 @@ SECTIONS * (see __FRAME_END__ in libgcc sources), it is manually provided here. */ LONG(0); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS /** * C++ constructor tables. @@ -464,12 +466,20 @@ SECTIONS */ .xt.prop 0 : { - KEEP (*(.xt.prop .gnu.linkonce.prop.*)) + KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*)) } .xt.lit 0 : { - KEEP (*(.xt.lit .gnu.linkonce.p.*)) + KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*)) + } + + /DISCARD/ : + { + *(.eh_frame_hdr) +#if !CONFIG_COMPILER_CXX_EXCEPTIONS + *(.eh_frame) +#endif // !CONFIG_COMPILER_CXX_EXCEPTIONS } } diff --git a/components/esp_system/ld/esp32s3/sections.ld.in b/components/esp_system/ld/esp32s3/sections.ld.in index 553c4f2e25..6eabbd5026 100644 --- a/components/esp_system/ld/esp32s3/sections.ld.in +++ b/components/esp_system/ld/esp32s3/sections.ld.in @@ -362,6 +362,7 @@ SECTIONS __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); *(.xt_except_desc_end) +#if CONFIG_COMPILER_CXX_EXCEPTIONS ALIGNED_SYMBOL(4, __eh_frame) KEEP(*(.eh_frame)) /** @@ -369,6 +370,7 @@ SECTIONS * (see __FRAME_END__ in libgcc sources), it is manually provided here. */ LONG(0); +#endif // CONFIG_COMPILER_CXX_EXCEPTIONS /** * C++ constructor tables. @@ -497,12 +499,20 @@ SECTIONS */ .xt.prop 0 : { - KEEP (*(.xt.prop .gnu.linkonce.prop.*)) + KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*)) } .xt.lit 0 : { - KEEP (*(.xt.lit .gnu.linkonce.p.*)) + KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*)) + } + + /DISCARD/ : + { + *(.eh_frame_hdr) +#if !CONFIG_COMPILER_CXX_EXCEPTIONS + *(.eh_frame) +#endif // !CONFIG_COMPILER_CXX_EXCEPTIONS } } From 9fd92e8bf44333aaac1b95f3768ca89107ac041d Mon Sep 17 00:00:00 2001 From: Alexey Lapshin Date: Thu, 25 Apr 2024 23:44:22 +0400 Subject: [PATCH 2/2] fix(cxx): use __cxa_throw() stub in case exceptions disabled Reduces binary size since the linker will drop some code due to --gc-sections. --- components/cxx/CMakeLists.txt | 4 +++- components/cxx/cxx_exception_stubs.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/components/cxx/CMakeLists.txt b/components/cxx/CMakeLists.txt index 228414599c..a14aa9b148 100644 --- a/components/cxx/CMakeLists.txt +++ b/components/cxx/CMakeLists.txt @@ -39,7 +39,9 @@ if(NOT CONFIG_CXX_EXCEPTIONS) _Unwind_Resume_or_Rethrow _Unwind_Backtrace __cxa_call_unexpected - __gxx_personality_v0) + __gxx_personality_v0 + __cxa_throw + __cxa_allocate_exception) foreach(wrap ${WRAP_FUNCTIONS}) target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}") diff --git a/components/cxx/cxx_exception_stubs.cpp b/components/cxx/cxx_exception_stubs.cpp index 827d40dd81..7e794755c0 100644 --- a/components/cxx/cxx_exception_stubs.cpp +++ b/components/cxx/cxx_exception_stubs.cpp @@ -178,4 +178,16 @@ extern "C" _Unwind_Reason_Code __wrap___gxx_personality_v0(int version, return abort_return<_Unwind_Reason_Code>(); } +// Reduces binary size since the linker will drop some code due to --gc-sections. +extern "C" void __wrap___cxa_allocate_exception(void) +{ + abort(); +} + +// Reduces binary size since the linker will drop some code due to --gc-sections. +extern "C" void __wrap___cxa_throw(void) +{ + abort(); +} + #endif // CONFIG_COMPILER_CXX_EXCEPTIONS