From: Dan Albert Date: Thu, 21 Jan 2021 21:27:14 +0000 (-0800) Subject: [libc++abi] Add an option to avoid demangling in terminate. X-Git-Tag: llvmorg-13-init~560 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=866d480fe0549d616bfdd69986dd07a7b2dc5b52;p=platform%2Fupstream%2Fllvm.git [libc++abi] Add an option to avoid demangling in terminate. 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. Reviewed By: #libc_abi, compnerd Differential Revision: https://reviews.llvm.org/D88189 --- diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt index c8ab9d7..ede8bd7 100644 --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -146,6 +146,8 @@ option(LIBCXXABI_BAREMETAL "Build libc++abi for baremetal targets." OFF) # 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.") @@ -452,6 +454,10 @@ if (LIBCXXABI_SILENT_TERMINATE) 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() diff --git a/libcxxabi/src/cxa_default_handlers.cpp b/libcxxabi/src/cxa_default_handlers.cpp index d2f823d..a24ee01 100644 --- a/libcxxabi/src/cxa_default_handlers.cpp +++ b/libcxxabi/src/cxa_default_handlers.cpp @@ -45,6 +45,7 @@ static void demangling_terminate_handler() exception_header + 1; const __shim_type_info* thrown_type = static_cast(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 @@ static void demangling_terminate_handler() 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(&typeid(std::exception));