[libcxx-commits] [libcxxabi] [libcxxabi] Don't enable -fvisibility=hidden on Windows (PR #207943)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 7 02:17:41 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxxabi
Author: Martin Storsjö (mstorsjo)
<details>
<summary>Changes</summary>
This option is supported (and hence gets added by the target_add_compile_flags_if_supported function) on Windows, but using hidden/default visibility should be mutually exclusive to using dllexport vs no dllexport.
In asserts enabled builds of Clang, building with -fvisibility=hidden caused errors like this:
dllexport GlobalValue must have default or protected visibility
ptr @<!-- -->_ZTIv
[...]
fatal error: error in backend: Broken module found, compilation aborted!
Since we're using dllexport on Windows to limit which symbols get exported, don't try to use -fvisibility=hidden. (If we'd use that option, we would also need to use per-symbol attributes to mark symbols with default visibility for the symbols that we do want exported.)
This fixes Windows builds with Clang with asserts enabled, after cb942d009a5ed029ce20d9b75b3604f551f0cb56.
---
Full diff: https://github.com/llvm/llvm-project/pull/207943.diff
1 Files Affected:
- (modified) libcxxabi/src/CMakeLists.txt (+8-2)
``````````diff
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index fc66ce7187170..6809ae452228f 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -195,7 +195,10 @@ 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)
+ if (NOT WIN32)
+ # We use dllexport on Windows, and that is mutually exclusive with visibility attributes.
+ target_add_compile_flags_if_supported(cxxabi_shared_objects PRIVATE -fvisibility=hidden)
+ endif()
add_library(cxxabi_shared SHARED)
set_target_properties(cxxabi_shared
@@ -286,7 +289,10 @@ 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 (NOT WIN32)
+ # We use dllexport on Windows, and that is mutually exclusive with visibility attributes.
+ target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility=hidden)
+endif()
if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
# If the hermetic library doesn't define the operator new/delete functions
``````````
</details>
https://github.com/llvm/llvm-project/pull/207943
More information about the libcxx-commits
mailing list