Skip to content

Commit f698a1b

Browse files
yaqwsxigrr
authored andcommitted
Add missing support for C++ exceptions
Specifying -fexceptions for the compiler is not enough. - add necessary zero padding after .eh_frame section - link .gcc_except_table_table in a way flash script does not complain - call __registrer_frame_info before global constructors Kudos jcmvbkbc for the necessary help.
1 parent 90f1d42 commit f698a1b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

components/esp32/cpu_start.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ extern volatile int port_xSchedulerRunning[2];
9292

9393
static const char* TAG = "cpu_start";
9494

95+
struct object { long placeholder[ 10 ]; };
96+
void __register_frame_info (const void *begin, struct object *ob);
97+
extern char __eh_frame[];
98+
9599
/*
96100
* We arrive here after the bootloader finished loading the program from flash. The hardware is mostly uninitialized,
97101
* and the app CPU is in reset. We do have a stack, so we can do the initialization in C.
@@ -188,7 +192,7 @@ void IRAM_ATTR call_start_cpu1()
188192
"wsr %0, vecbase\n" \
189193
::"r"(&_init_start));
190194

191-
ets_set_appcpu_boot_addr(0);
195+
ets_set_appcpu_boot_addr(0);
192196
cpu_configure_region_protection();
193197

194198
#if CONFIG_CONSOLE_UART_NONE
@@ -315,6 +319,9 @@ void start_cpu1_default(void)
315319

316320
static void do_global_ctors(void)
317321
{
322+
static struct object ob;
323+
__register_frame_info( __eh_frame, &ob );
324+
318325
void (**p)(void);
319326
for (p = &__init_array_end - 1; p >= &__init_array_start; --p) {
320327
(*p)();

components/esp32/ld/esp32.common.ld

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ SECTIONS
151151
*(.rodata1)
152152
__XT_EXCEPTION_TABLE_ = ABSOLUTE(.);
153153
*(.xt_except_table)
154-
*(.gcc_except_table)
154+
*(.gcc_except_table .gcc_except_table.*)
155155
*(.gnu.linkonce.e.*)
156156
*(.gnu.version_r)
157-
*(.eh_frame)
158157
. = (. + 3) & ~ 3;
158+
__eh_frame = ABSOLUTE(.);
159+
KEEP(*(.eh_frame))
160+
. = (. + 7) & ~ 3;
159161
/* C++ constructor and destructor tables, properly ordered: */
160162
__init_array_start = ABSOLUTE(.);
161163
KEEP (*crtbegin.o(.ctors))

0 commit comments

Comments
 (0)