[libcxx-commits] [libcxxabi] [libcxxabi] Don't enable -fvisibility=hidden on Windows (PR #207943)
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 7 02:17:08 PDT 2026
https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/207943
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.
>From 983bb575bf736c41de4da140753456c21980911a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Tue, 7 Jul 2026 12:12:48 +0300
Subject: [PATCH] [libcxxabi] Don't enable -fvisibility=hidden on Windows
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.
---
libcxxabi/src/CMakeLists.txt | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
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
More information about the libcxx-commits
mailing list