[libcxx-commits] [PATCH] D88189: [libc++abi] Add an option to avoid demangling in terminate.

Dan Albert via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 23 16:08:31 PDT 2020


danalbert created this revision.
danalbert added a reviewer: EricWF.
danalbert added a project: libc++abi.
Herald added subscribers: libcxx-commits, mgorny.
Herald added a reviewer: libc++abi.
danalbert requested review of this revision.

We've been using this patch in Android so we can avoid including the
demangler in libc++.so. It comes with a rather large cost in RSS and
isn't commonly needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88189

Files:
  libcxxabi/CMakeLists.txt
  libcxxabi/src/cxa_default_handlers.cpp


Index: libcxxabi/src/cxa_default_handlers.cpp
===================================================================
--- libcxxabi/src/cxa_default_handlers.cpp
+++ libcxxabi/src/cxa_default_handlers.cpp
@@ -45,6 +45,7 @@
                         exception_header + 1;
                 const __shim_type_info* thrown_type =
                     static_cast<const __shim_type_info*>(exception_header->exceptionType);
+#if !defined(LIBCXXABI_NON_DEMANGLING_TERMINATE)
                 // Try to get demangled name of thrown_type
                 int status;
                 char buf[1024];
@@ -52,6 +53,9 @@
                 const char* name = __cxa_demangle(thrown_type->name(), buf, &len, &status);
                 if (status != 0)
                     name = thrown_type->name();
+#else
+                const char* name = thrown_type->name();
+#endif
                 // If the uncaught exception can be caught with std::exception&
                 const __shim_type_info* catch_type =
                     static_cast<const __shim_type_info*>(&typeid(std::exception));
Index: libcxxabi/CMakeLists.txt
===================================================================
--- libcxxabi/CMakeLists.txt
+++ libcxxabi/CMakeLists.txt
@@ -121,6 +121,8 @@
 # The default terminate handler attempts to demangle uncaught exceptions, which
 # causes extra I/O and demangling code to be pulled in.
 option(LIBCXXABI_SILENT_TERMINATE "Set this to make the terminate handler default to a silent alternative" OFF)
+option(LIBCXXABI_NON_DEMANGLING_TERMINATE "Set this to make the terminate handler
+avoid demangling" OFF)
 
 if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
   message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
@@ -423,6 +425,10 @@
   add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
 endif()
 
+if (LIBCXXABI_NON_DEMANGLING_TERMINATE)
+  add_definitions(-DLIBCXXABI_NON_DEMANGLING_TERMINATE)
+endif()
+
 if (LIBCXXABI_BAREMETAL)
     add_definitions(-DLIBCXXABI_BAREMETAL)
 endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88189.293886.patch
Type: text/x-patch
Size: 2031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200923/5364b0d1/attachment.bin>


More information about the libcxx-commits mailing list