From 2bcfeb612fa90ac6d7d86675610cab217ab5287d Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Tue, 22 Jun 2021 12:24:27 +0800 Subject: [PATCH] startup: Make __cxx_eh_arena_size_get return 0 if exceptions disabled This function is necessary to provide the emergency exception memory pool size for C++ code. Since our libstdc++ always has exceptions enabled, this function must exist here even if -fno-exception is set for user code. --- components/esp32/cpu_start.c | 12 ++++++++++-- components/esp32s2/cpu_start.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index c0877feb67..aa55946207 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -532,12 +532,20 @@ void start_cpu1_default(void) } #endif //!CONFIG_FREERTOS_UNICORE -#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS +/** + * This function overwrites a the same function of libsupc++ (part of libstdc++). + * Consequently, libsupc++ will then follow our configured exception emergency pool size. + * + * It will be called even with -fno-exception for user code since the stdlib still uses exceptions. + */ size_t __cxx_eh_arena_size_get(void) { +#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS return CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE; -} +#else + return 0; #endif +} static void do_global_ctors(void) { diff --git a/components/esp32s2/cpu_start.c b/components/esp32s2/cpu_start.c index 21b2e404a6..bdb8b25565 100644 --- a/components/esp32s2/cpu_start.c +++ b/components/esp32s2/cpu_start.c @@ -395,12 +395,20 @@ void start_cpu0_default(void) abort(); /* Only get to here if not enough free heap to start scheduler */ } -#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS +/** + * This function overwrites a the same function of libsupc++ (part of libstdc++). + * Consequently, libsupc++ will then follow our configured exception emergency pool size. + * + * It will be called even with -fno-exception for user code since the stdlib still uses exceptions. + */ size_t __cxx_eh_arena_size_get(void) { +#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS return CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE; -} +#else + return 0; #endif +} static void do_global_ctors(void) {