Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++abi] Introduce LIBCXXABI_ENABLE_DEMANGLER #132130

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

michael-kenzel
Copy link
Contributor

This change introduces a LIBCXXABI_ENABLE_DEMANGLER CMake option that allows turning off the demangler API from being included in the build. This can be useful when trying to build a minimal version of libc++abi, e.g., for a baremetal target. The demangler is quite heavy in dependencies on libraries that are not easily available on such a target, and is not an essential component. As discussed in #72948, LIBCXXABI_NON_DEMANGLING_TERMINATE is removed, its functionality is now tied to the new LIBCXXABI_ENABLE_DEMANGLER option.

@michael-kenzel michael-kenzel requested a review from a team as a code owner March 20, 2025 01:17
@llvmbot llvmbot added the libc++abi libc++abi C++ Runtime Library. Not libc++. label Mar 20, 2025
@michael-kenzel
Copy link
Contributor Author

Note: this is the requested resubmission of #72948

@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2025

@llvm/pr-subscribers-libcxxabi

Author: Michael Kenzel (michael-kenzel)

Changes

This change introduces a LIBCXXABI_ENABLE_DEMANGLER CMake option that allows turning off the demangler API from being included in the build. This can be useful when trying to build a minimal version of libc++abi, e.g., for a baremetal target. The demangler is quite heavy in dependencies on libraries that are not easily available on such a target, and is not an essential component. As discussed in #72948, LIBCXXABI_NON_DEMANGLING_TERMINATE is removed, its functionality is now tied to the new LIBCXXABI_ENABLE_DEMANGLER option.


Full diff: https://github.com/llvm/llvm-project/pull/132130.diff

2 Files Affected:

  • (modified) libcxxabi/CMakeLists.txt (+4-3)
  • (modified) libcxxabi/src/CMakeLists.txt (+6-1)
diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index 6dcfc51e55321..1c1247e165340 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -46,6 +46,9 @@ include(CMakeDependentOption)
 include(HandleCompilerRT)
 
 # Define options.
+option(LIBCXXABI_ENABLE_DEMANGLER
+  "Provide support for demangling in the runtime.
+   When disabled, libc++abi does not support the name demangler API." ON)
 option(LIBCXXABI_ENABLE_EXCEPTIONS
   "Provide support for exceptions in the runtime.
   When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
@@ -129,8 +132,6 @@ 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.")
@@ -431,7 +432,7 @@ if (LIBCXXABI_SILENT_TERMINATE)
   add_definitions(-DLIBCXXABI_SILENT_TERMINATE)
 endif()
 
-if (LIBCXXABI_NON_DEMANGLING_TERMINATE)
+if (NOT LIBCXXABI_ENABLE_DEMANGLER)
   add_definitions(-DLIBCXXABI_NON_DEMANGLING_TERMINATE)
 endif()
 
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 0a6fc892a4f69..4167845c9713d 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -3,7 +3,6 @@ set(LIBCXXABI_SOURCES
   # C++ABI files
   cxa_aux_runtime.cpp
   cxa_default_handlers.cpp
-  cxa_demangle.cpp
   cxa_exception_storage.cpp
   cxa_guard.cpp
   cxa_handlers.cpp
@@ -19,6 +18,12 @@ set(LIBCXXABI_SOURCES
   private_typeinfo.cpp
 )
 
+if (LIBCXXABI_ENABLE_DEMANGLER)
+  list(APPEND LIBCXXABI_SOURCES
+    cxa_demangle.cpp
+  )
+endif()
+
 if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS)
   list(APPEND LIBCXXABI_SOURCES
     stdlib_new_delete.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++abi libc++abi C++ Runtime Library. Not libc++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants