Skip to content

Commit 9fd92e8

Browse files
committed
fix(cxx): use __cxa_throw() stub in case exceptions disabled
Reduces binary size since the linker will drop some code due to --gc-sections.
1 parent d42e894 commit 9fd92e8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
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

0 commit comments

Comments
 (0)