[libcxx-commits] [libcxxabi] [libc++abi] Always enable -fvisibility=hidden (PR #207333)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 3 00:08:12 PDT 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/207333

Building with `-fvisibility=hidden` is generally a good idea, since it avoids unnecessary relocations when loading a dylib. For libc++abi this should be a no-op, since most things are annotated explicitly. By enabling `-fvisibility=hidden` we can remove these explicit annotations however.


>From 9608f114949d4982f59dc4005aa976f243e6c295 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Fri, 3 Jul 2026 09:03:45 +0200
Subject: [PATCH] [libc++abi] Always enable -fvisibility=hidden

---
 libcxxabi/src/CMakeLists.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index 1889d7d5a82de..fc66ce7187170 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -195,6 +195,7 @@ if (LIBCXXABI_SUPPORTS_SHARED_LIBRARY)
   # Build with -fsized-deallocation, which is default in recent versions of Clang.
   # TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
   target_add_compile_flags_if_supported(cxxabi_shared_objects PRIVATE -fsized-deallocation)
+  target_add_compile_flags_if_supported(cxxabi_shared_objects PRIVATE -fvisibility=hidden)
 
   add_library(cxxabi_shared SHARED)
   set_target_properties(cxxabi_shared
@@ -285,9 +286,9 @@ target_compile_options(cxxabi_static_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COM
 # Build with -fsized-deallocation, which is default in recent versions of Clang.
 # TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
 target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fsized-deallocation)
+target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility=hidden)
 
 if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
-  target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility=hidden)
   # If the hermetic library doesn't define the operator new/delete functions
   # then its code shouldn't declare them with hidden visibility.  They might
   # actually be provided by a shared library at link time.



More information about the libcxx-commits mailing list