Skip to content

Commit

Permalink
fix(cxx): use __cxa_throw() stub in case exceptions disabled
Browse files Browse the repository at this point in the history
Reduces binary size since the linker will drop some code due to --gc-sections.
  • Loading branch information
Lapshin committed May 7, 2024
1 parent 1f3f65b commit dcf6b54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion components/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ if(NOT CONFIG_CXX_EXCEPTIONS)
_Unwind_Resume_or_Rethrow
_Unwind_Backtrace
__cxa_call_unexpected
__gxx_personality_v0)
__gxx_personality_v0
__cxa_throw
__cxa_allocate_exception)

foreach(wrap ${WRAP_FUNCTIONS})
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}")
Expand Down
12 changes: 12 additions & 0 deletions components/cxx/cxx_exception_stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,16 @@ extern "C" _Unwind_Reason_Code __wrap___gxx_personality_v0 (int version,
return abort_return<_Unwind_Reason_Code>();
}

// Reduces binary size since the linker will drop some code due to --gc-sections.
extern "C" void __wrap___cxa_allocate_exception(void)
{
abort();
}

// Reduces binary size since the linker will drop some code due to --gc-sections.
extern "C" void __wrap___cxa_throw(void)
{
abort();
}

#endif // CONFIG_COMPILER_CXX_EXCEPTIONS

0 comments on commit dcf6b54

Please sign in to comment.