Skip to content

Commit 2e398f1

Browse files
committed
[libcxxabi] Don't process exceptions in cxa_handlers when they're disabled
When exceptions are disabled, avoid their processing altogether. This avoids pulling in the depenency on demangler significantly reducing binary size when statically linking against libc++abi built without exception support. Differential Revision: https://reviews.llvm.org/D64191 llvm-svn: 365944
1 parent 6d75a9e commit 2e398f1

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

libcxxabi/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ include(CMakeDependentOption)
4343
include(HandleCompilerRT)
4444

4545
# Define options.
46-
option(LIBCXXABI_ENABLE_EXCEPTIONS "Use exceptions." ON)
46+
option(LIBCXXABI_ENABLE_EXCEPTIONS
47+
"Provide support for exceptions in the runtime.
48+
When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
4749
option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
4850
option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
4951
option(LIBCXXABI_ENABLE_PIC "Build Position-Independent Code, even in static library" ON)

libcxxabi/src/cxa_default_handlers.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static const char* cause = "uncaught";
2525
__attribute__((noreturn))
2626
static void demangling_terminate_handler()
2727
{
28+
#ifndef _LIBCXXABI_NO_EXCEPTIONS
2829
// If there might be an uncaught exception
2930
using namespace __cxxabiv1;
3031
__cxa_eh_globals* globals = __cxa_get_globals_fast();
@@ -71,6 +72,7 @@ static void demangling_terminate_handler()
7172
abort_message("terminating with %s foreign exception", cause);
7273
}
7374
}
75+
#endif
7476
// Else just note that we're terminating
7577
abort_message("terminating");
7678
}

libcxxabi/src/cxa_handlers.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ __attribute__((noreturn))
7373
void
7474
terminate() _NOEXCEPT
7575
{
76+
#ifndef _LIBCXXABI_NO_EXCEPTIONS
7677
// If there might be an uncaught exception
7778
using namespace __cxxabiv1;
7879
__cxa_eh_globals* globals = __cxa_get_globals_fast();
@@ -87,6 +88,7 @@ terminate() _NOEXCEPT
8788
__terminate(exception_header->terminateHandler);
8889
}
8990
}
91+
#endif
9092
__terminate(get_terminate());
9193
}
9294

0 commit comments

Comments
 (0)