[PATCH] D28497: [libc++abi] Add a silent terminate handler to libcxxabi.

Tom Rybka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 15:42:18 PST 2017


trybka created this revision.
trybka added a reviewer: EricWF.
trybka added a subscriber: llvm-commits.
Herald added subscribers: mgorny, danalbert.

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.

On Android, debuggerd seems to actually handle unwinding and demangling, so
this code is unnecessary in certain cases. We would just like a way to turn it
off.


https://reviews.llvm.org/D28497

Files:
  CMakeLists.txt
  src/config.h
  src/cxa_default_handlers.cpp


Index: src/cxa_default_handlers.cpp
===================================================================
--- src/cxa_default_handlers.cpp
+++ 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
Index: src/config.h
===================================================================
--- src/config.h
+++ src/config.h
@@ -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
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -422,6 +422,10 @@
   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}")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28497.83725.patch
Type: text/x-patch
Size: 2274 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170109/ef8b9beb/attachment.bin>


More information about the llvm-commits mailing list