[libcxxabi] r291946 - [libc++abi] Add a silent terminate handler to libcxxabi.

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 13 11:22:27 PST 2017


Author: jyknight
Date: Fri Jan 13 13:22:26 2017
New Revision: 291946

URL: http://llvm.org/viewvc/llvm-project?rev=291946&view=rev
Log:
[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

Modified:
    libcxxabi/trunk/CMakeLists.txt
    libcxxabi/trunk/src/config.h
    libcxxabi/trunk/src/cxa_default_handlers.cpp

Modified: libcxxabi/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=291946&r1=291945&r2=291946&view=diff
==============================================================================
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Fri Jan 13 13:22:26 2017
@@ -433,6 +433,10 @@ if (LIBCXXABI_USE_LLVM_UNWINDER)
   add_definitions(-DLIBCXXABI_USE_LLVM_UNWINDER=1)
 endif()
 
+if (LIBCXXABI_SILENT_TERMINATE)
+  add_definitions(-DLIBCXXABI_SILENT_TERMINATE=1)
+endif()
+
 string(REPLACE ";" " " LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXXABI_CXX_FLAGS}")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCXXABI_C_FLAGS}")

Modified: libcxxabi/trunk/src/config.h
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/config.h?rev=291946&r1=291945&r2=291946&view=diff
==============================================================================
--- libcxxabi/trunk/src/config.h (original)
+++ libcxxabi/trunk/src/config.h Fri Jan 13 13:22:26 2017
@@ -23,4 +23,11 @@
 #  define LIBCXXABI_BAREMETAL 0
 #endif
 
+// The default terminate handler attempts to demangle uncaught exceptions, which
+// causes extra I/O and demangling code to be pulled in.
+// Set this to make the terminate handler default to a silent alternative.
+#ifndef LIBCXXABI_SILENT_TERMINATE
+#  define LIBCXXABI_SILENT_TERMINATE 0
+#endif
+
 #endif // LIBCXXABI_CONFIG_H

Modified: libcxxabi/trunk/src/cxa_default_handlers.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_default_handlers.cpp?rev=291946&r1=291945&r2=291946&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_default_handlers.cpp (original)
+++ libcxxabi/trunk/src/cxa_default_handlers.cpp Fri Jan 13 13:22:26 2017
@@ -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 @@ static void default_terminate_handler()
 }
 
 __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




More information about the cfe-commits mailing list