Skip to content

Commit 285ba1f

Browse files
committed
Merge branch 'fix/reduce-binary-size_v5.3' into 'release/v5.3'
Reduce binary size (v5.3) See merge request espressif/esp-idf!30654
2 parents 5c9392d + 9fd92e8 commit 285ba1f

File tree

13 files changed

+211
-63
lines changed

13 files changed

+211
-63
lines changed

components/cxx/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ if(NOT CONFIG_CXX_EXCEPTIONS)
3939
_Unwind_Resume_or_Rethrow
4040
_Unwind_Backtrace
4141
__cxa_call_unexpected
42-
__gxx_personality_v0)
42+
__gxx_personality_v0
43+
__cxa_throw
44+
__cxa_allocate_exception)
4345

4446
foreach(wrap ${WRAP_FUNCTIONS})
4547
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}")

components/cxx/cxx_exception_stubs.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,16 @@ extern "C" _Unwind_Reason_Code __wrap___gxx_personality_v0(int version,
178178
return abort_return<_Unwind_Reason_Code>();
179179
}
180180

181+
// Reduces binary size since the linker will drop some code due to --gc-sections.
182+
extern "C" void __wrap___cxa_allocate_exception(void)
183+
{
184+
abort();
185+
}
186+
187+
// Reduces binary size since the linker will drop some code due to --gc-sections.
188+
extern "C" void __wrap___cxa_throw(void)
189+
{
190+
abort();
191+
}
192+
181193
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS

components/esp_system/ld/esp32/sections.ld.in

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,15 @@ SECTIONS
352352
__XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
353353
*(.xt_except_desc_end)
354354

355+
#if CONFIG_COMPILER_CXX_EXCEPTIONS
355356
ALIGNED_SYMBOL(4, __eh_frame)
356357
KEEP(*(.eh_frame))
357358
/**
358359
* As we are not linking with crtend.o, which includes the CIE terminator
359360
* (see __FRAME_END__ in libgcc sources), it is manually provided here.
360361
*/
361362
LONG(0);
363+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS
362364

363365
/**
364366
* C++ constructor tables.
@@ -500,12 +502,20 @@ SECTIONS
500502
*/
501503
.xt.prop 0 :
502504
{
503-
KEEP (*(.xt.prop .gnu.linkonce.prop.*))
505+
KEEP (*(.xt.prop .xt.prop.* .gnu.linkonce.prop.*))
504506
}
505507

506508
.xt.lit 0 :
507509
{
508-
KEEP (*(.xt.lit .gnu.linkonce.p.*))
510+
KEEP (*(.xt.lit .xt.lit.* .gnu.linkonce.p.*))
511+
}
512+
513+
/DISCARD/ :
514+
{
515+
*(.eh_frame_hdr)
516+
#if !CONFIG_COMPILER_CXX_EXCEPTIONS
517+
*(.eh_frame)
518+
#endif // !CONFIG_COMPILER_CXX_EXCEPTIONS
509519
}
510520
}
511521

components/esp_system/ld/esp32c2/sections.ld.in

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,21 @@ SECTIONS
233233

234234
.eh_frame_hdr :
235235
{
236+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
236237
ALIGNED_SYMBOL(4, __eh_frame_hdr)
237238

238239
KEEP (*(.eh_frame_hdr))
239240

240241
__eh_frame_hdr_end = ABSOLUTE(.);
242+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
243+
241244
. = ALIGN(ALIGNOF(.eh_frame));
242245
} > default_rodata_seg
243246
ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame)
244247

245248
.eh_frame :
246249
{
250+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
247251
ALIGNED_SYMBOL(4, __eh_frame)
248252

249253
KEEP (*(.eh_frame))
@@ -254,6 +258,8 @@ SECTIONS
254258
LONG(0);
255259

256260
__eh_frame_end = ABSOLUTE(.);
261+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
262+
257263
. = ALIGN(ALIGNOF(.flash.tdata));
258264
} > default_rodata_seg
259265
ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata)
@@ -339,13 +345,20 @@ SECTIONS
339345
ALIGNED_SYMBOL(16, _heap_start)
340346
} > dram0_0_seg
341347

342-
/**
343-
* Discarding .rela.* sections results in the following mapping:
344-
* .rela.text.* -> .text.*
345-
* .rela.data.* -> .data.*
346-
* And so forth...
347-
*/
348-
/DISCARD/ : { *(.rela.*) }
348+
/DISCARD/ :
349+
{
350+
/**
351+
* Discarding .rela.* sections results in the following mapping:
352+
* .rela.text.* -> .text.*
353+
* .rela.data.* -> .data.*
354+
* And so forth...
355+
*/
356+
*(.rela.*)
357+
#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
358+
*(.eh_frame_hdr)
359+
*(.eh_frame)
360+
#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
361+
}
349362
}
350363

351364
ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),

components/esp_system/ld/esp32c3/sections.ld.in

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,21 @@ SECTIONS
351351

352352
.eh_frame_hdr :
353353
{
354+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
354355
ALIGNED_SYMBOL(4, __eh_frame_hdr)
355356

356357
KEEP (*(.eh_frame_hdr))
357358

358359
__eh_frame_hdr_end = ABSOLUTE(.);
360+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
361+
359362
. = ALIGN(ALIGNOF(.eh_frame));
360363
} > default_rodata_seg
361364
ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame)
362365

363366
.eh_frame :
364367
{
368+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
365369
ALIGNED_SYMBOL(4, __eh_frame)
366370

367371
KEEP (*(.eh_frame))
@@ -372,6 +376,8 @@ SECTIONS
372376
LONG(0);
373377

374378
__eh_frame_end = ABSOLUTE(.);
379+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
380+
375381
. = ALIGN(ALIGNOF(.flash.tdata));
376382
} > default_rodata_seg
377383
ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata)
@@ -451,13 +457,20 @@ SECTIONS
451457
ALIGNED_SYMBOL(16, _heap_start)
452458
} > dram0_0_seg
453459

454-
/**
455-
* Discarding .rela.* sections results in the following mapping:
456-
* .rela.text.* -> .text.*
457-
* .rela.data.* -> .data.*
458-
* And so forth...
459-
*/
460-
/DISCARD/ : { *(.rela.*) }
460+
/DISCARD/ :
461+
{
462+
/**
463+
* Discarding .rela.* sections results in the following mapping:
464+
* .rela.text.* -> .text.*
465+
* .rela.data.* -> .data.*
466+
* And so forth...
467+
*/
468+
*(.rela.*)
469+
#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
470+
*(.eh_frame_hdr)
471+
*(.eh_frame)
472+
#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
473+
}
461474
}
462475

463476
ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),

components/esp_system/ld/esp32c5/beta3/sections.ld.in

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,21 @@ SECTIONS
374374

375375
.eh_frame_hdr :
376376
{
377+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
377378
ALIGNED_SYMBOL(4, __eh_frame_hdr)
378379

379380
KEEP (*(.eh_frame_hdr))
380381

381382
__eh_frame_hdr_end = ABSOLUTE(.);
383+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
384+
382385
. = ALIGN(ALIGNOF(.eh_frame));
383386
} > default_rodata_seg
384387
ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame)
385388

386389
.eh_frame :
387390
{
391+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
388392
ALIGNED_SYMBOL(4, __eh_frame)
389393

390394
KEEP (*(.eh_frame))
@@ -395,6 +399,8 @@ SECTIONS
395399
LONG(0);
396400

397401
__eh_frame_end = ABSOLUTE(.);
402+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
403+
398404
. = ALIGN(ALIGNOF(.flash.tdata));
399405
} > default_rodata_seg
400406
ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata)
@@ -442,13 +448,20 @@ SECTIONS
442448
ALIGNED_SYMBOL(16, _heap_start)
443449
} > dram0_0_seg
444450

445-
/**
446-
* Discarding .rela.* sections results in the following mapping:
447-
* .rela.text.* -> .text.*
448-
* .rela.data.* -> .data.*
449-
* And so forth...
450-
*/
451-
/DISCARD/ : { *(.rela.*) }
451+
/DISCARD/ :
452+
{
453+
/**
454+
* Discarding .rela.* sections results in the following mapping:
455+
* .rela.text.* -> .text.*
456+
* .rela.data.* -> .data.*
457+
* And so forth...
458+
*/
459+
*(.rela.*)
460+
#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
461+
*(.eh_frame_hdr)
462+
*(.eh_frame)
463+
#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
464+
}
452465
}
453466

454467
ASSERT(((_iram_end - ORIGIN(iram0_0_seg)) <= LENGTH(iram0_0_seg)),

components/esp_system/ld/esp32c5/mp/sections.ld.in

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,21 @@ SECTIONS
374374

375375
.eh_frame_hdr :
376376
{
377+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
377378
ALIGNED_SYMBOL(4, __eh_frame_hdr)
378379

379380
KEEP (*(.eh_frame_hdr))
380381

381382
__eh_frame_hdr_end = ABSOLUTE(.);
383+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
384+
382385
. = ALIGN(ALIGNOF(.eh_frame));
383386
} > default_rodata_seg
384387
ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame)
385388

386389
.eh_frame :
387390
{
391+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
388392
ALIGNED_SYMBOL(4, __eh_frame)
389393

390394
KEEP (*(.eh_frame))
@@ -395,6 +399,8 @@ SECTIONS
395399
LONG(0);
396400

397401
__eh_frame_end = ABSOLUTE(.);
402+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
403+
398404
. = ALIGN(ALIGNOF(.flash.tdata));
399405
} > default_rodata_seg
400406
ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata)
@@ -442,13 +448,20 @@ SECTIONS
442448
ALIGNED_SYMBOL(16, _heap_start)
443449
} > sram_seg
444450

445-
/**
446-
* Discarding .rela.* sections results in the following mapping:
447-
* .rela.text.* -> .text.*
448-
* .rela.data.* -> .data.*
449-
* And so forth...
450-
*/
451-
/DISCARD/ : { *(.rela.*) }
451+
/DISCARD/ :
452+
{
453+
/**
454+
* Discarding .rela.* sections results in the following mapping:
455+
* .rela.text.* -> .text.*
456+
* .rela.data.* -> .data.*
457+
* And so forth...
458+
*/
459+
*(.rela.*)
460+
#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
461+
*(.eh_frame_hdr)
462+
*(.eh_frame)
463+
#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
464+
}
452465
}
453466

454467
ASSERT(((_iram_end - ORIGIN(sram_seg)) <= LENGTH(sram_seg)),

components/esp_system/ld/esp32c6/sections.ld.in

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,21 @@ SECTIONS
364364

365365
.eh_frame_hdr :
366366
{
367+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
367368
ALIGNED_SYMBOL(4, __eh_frame_hdr)
368369

369370
KEEP (*(.eh_frame_hdr))
370371

371372
__eh_frame_hdr_end = ABSOLUTE(.);
373+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
374+
372375
. = ALIGN(ALIGNOF(.eh_frame));
373376
} > default_rodata_seg
374377
ASSERT_SECTIONS_GAP(.eh_frame_hdr, .eh_frame)
375378

376379
.eh_frame :
377380
{
381+
#if CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
378382
ALIGNED_SYMBOL(4, __eh_frame)
379383

380384
KEEP (*(.eh_frame))
@@ -385,6 +389,8 @@ SECTIONS
385389
LONG(0);
386390

387391
__eh_frame_end = ABSOLUTE(.);
392+
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME
393+
388394
. = ALIGN(ALIGNOF(.flash.tdata));
389395
} > default_rodata_seg
390396
ASSERT_SECTIONS_GAP(.eh_frame, .flash.tdata)
@@ -432,11 +438,18 @@ SECTIONS
432438
ALIGNED_SYMBOL(16, _heap_start)
433439
} > sram_seg
434440

435-
/**
436-
* Discarding .rela.* sections results in the following mapping:
437-
* .rela.text.* -> .text.*
438-
* .rela.data.* -> .data.*
439-
* And so forth...
440-
*/
441-
/DISCARD/ : { *(.rela.*) }
441+
/DISCARD/ :
442+
{
443+
/**
444+
* Discarding .rela.* sections results in the following mapping:
445+
* .rela.text.* -> .text.*
446+
* .rela.data.* -> .data.*
447+
* And so forth...
448+
*/
449+
*(.rela.*)
450+
#if !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
451+
*(.eh_frame_hdr)
452+
*(.eh_frame)
453+
#endif // !(CONFIG_COMPILER_CXX_EXCEPTIONS || CONFIG_ESP_SYSTEM_USE_EH_FRAME)
454+
}
442455
}

0 commit comments

Comments
 (0)