Skip to content

Commit ad76a4f

Browse files
Gary-Hobsonxiaoxiang781216
authored andcommitted
libcxxabi: libcxxabi enables exceptions by default
In the following code, even though the application does not use exceptions, an exception is still thrown in libcxx If libcxxabi is not enabled, the toolchain default implementation will be used. However, arm-gcc does not enable thread support by default, which will cause errors in a multi-threaded environment. Therefore, we need to use libcxxabi to ensure normal functions in a multi-threaded environment. using namespace std; void foo(bool recur); int bar(bool recur) { if (recur) { foo(false); } return 0xFAFAFA; } void foo(bool recur) { static int i = bar(recur); cout << "Static is:" << i << "\n"; } int main(int argc, char *argv[]) { foo(true); return 0; } Signed-off-by: yinshengkai <[email protected]>
1 parent b721f2c commit ad76a4f

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

libs/libxx/libcxxabi.cmake

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ list(APPEND SRCS stdlib_exception.cpp stdlib_new_delete.cpp
7575
# Internal files
7676
list(APPEND SRCS abort_message.cpp fallback_malloc.cpp private_typeinfo.cpp)
7777

78-
if(CONFIG_CXX_EXCEPTION)
79-
add_compile_definitions(LIBCXXABI_ENABLE_EXCEPTIONS)
80-
list(APPEND SRCS cxa_exception.cpp cxa_personality.cpp)
81-
else()
82-
list(APPEND SRCS cxa_noexception.cpp)
83-
endif()
78+
# Always compile libcxxabi with exception
79+
list(APPEND SRCS cxa_exception.cpp cxa_personality.cpp)
80+
target_compile_options(libcxxabi PRIVATE -fexceptions)
8481

8582
if(CONFIG_LIBCXXABI)
8683
add_compile_definitions(LIBCXX_BUILDING_LIBCXXABI)
@@ -100,6 +97,16 @@ if(CONFIG_SIM_UBSAN OR CONFIG_MM_UBSAN)
10097
target_compile_options(libcxxabi PRIVATE -fno-sanitize=vptr)
10198
endif()
10299

100+
# Fix compilation error on ARM32:libcxxabi/src/cxa_personality.cpp:594:22:
101+
# error: '_URC_FATAL_PHASE1_ERROR' was not declared in this scope 594 |
102+
# results.reason = _URC_FATAL_PHASE1_ERROR;
103+
if(CONFIG_ARCH_ARM)
104+
target_compile_definitions(libcxxabi
105+
PRIVATE _URC_FATAL_PHASE2_ERROR=_URC_FAILURE)
106+
target_compile_definitions(libcxxabi
107+
PRIVATE _URC_FATAL_PHASE1_ERROR=_URC_FAILURE)
108+
endif()
109+
103110
target_sources(libcxxabi PRIVATE ${TARGET_SRCS})
104111
target_compile_options(libcxxabi PRIVATE -frtti)
105112
target_include_directories(

libs/libxx/libcxxabi.defs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ CPPSRCS += stdlib_exception.cpp stdlib_new_delete.cpp stdlib_stdexcept.cpp stdli
6565
# Internal files
6666
CPPSRCS += abort_message.cpp fallback_malloc.cpp private_typeinfo.cpp
6767

68-
ifeq ($(CONFIG_CXX_EXCEPTION), y)
69-
CXXFLAGS += ${DEFINE_PREFIX}LIBCXXABI_ENABLE_EXCEPTIONS
68+
# Always compile libcxxabi with exception
7069
CPPSRCS += cxa_exception.cpp cxa_personality.cpp
71-
else
72-
CPPSRCS += cxa_noexception.cpp
70+
CXXFLAGS += -fexceptions
71+
72+
# Fix compilation error on ARM32:
73+
# libcxxabi/src/cxa_personality.cpp:594:22: error: '_URC_FATAL_PHASE1_ERROR' was not declared in this scope
74+
# 594 | results.reason = _URC_FATAL_PHASE1_ERROR;
75+
ifeq ($(CONFIG_ARCH_ARM),y)
76+
CXXFLAGS += -D_URC_FATAL_PHASE2_ERROR=_URC_FAILURE -D_URC_FATAL_PHASE1_ERROR=_URC_FAILURE
7377
endif
7478

7579
# RTTI is required for building the libcxxabi library

0 commit comments

Comments
 (0)