[libc++abi] Add a silent terminate handler to libcxxabi.
The current std::terminate_handler pulls in some string code, some I/O
code, and more. Since it is automatically setup as the default, this
means that any trivial binary linking against libcxxabi will get this
extra bloat.
This patch allows disabling it as a build-time option, if you want to
avoid the extra bloat.
Patch by Tom Rybka!
Reviewers: EricWF
Subscribers: danalbert, llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D28497
git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@291946 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/cxa_default_handlers.cpp b/src/cxa_default_handlers.cpp
index 09350e7..a1ea296 100644
--- a/src/cxa_default_handlers.cpp
+++ b/src/cxa_default_handlers.cpp
@@ -12,6 +12,7 @@
#include <stdexcept>
#include <new>
#include <exception>
+#include <cstdlib>
#include "abort_message.h"
#include "config.h" // For __sync_swap
#include "cxxabi.h"
@@ -22,7 +23,7 @@
static const char* cause = "uncaught";
__attribute__((noreturn))
-static void default_terminate_handler()
+static void demangling_terminate_handler()
{
// If there might be an uncaught exception
using namespace __cxxabiv1;
@@ -78,12 +79,19 @@
}
__attribute__((noreturn))
-static void default_unexpected_handler()
+static void demangling_unexpected_handler()
{
cause = "unexpected";
std::terminate();
}
+#if !LIBCXXABI_SILENT_TERMINATE
+static std::terminate_handler default_terminate_handler = demangling_terminate_handler;
+static std::terminate_handler default_unexpected_handler = demangling_unexpected_handler;
+#else
+static std::terminate_handler default_terminate_handler = std::abort;
+static std::terminate_handler default_unexpected_handler = std::abort;
+#endif
//
// Global variables that hold the pointers to the current handler