Index: libcxx/CMakeLists.txt =================================================================== --- libcxx/CMakeLists.txt +++ libcxx/CMakeLists.txt @@ -308,8 +308,12 @@ option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" ${LIBCXX_CONFIGURE_IDE_DEFAULT}) +set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF) +if (WIN32) + set(LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON) +endif() option(LIBCXX_HERMETIC_STATIC_LIBRARY - "Do not export any symbols from the static library." OFF) + "Do not export any symbols from the static library." ${LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT}) #=============================================================================== # Check option configurations @@ -888,7 +892,10 @@ # By default libc++ on Windows expects to use a shared library, which requires # the headers to use DLL import/export semantics. However when building a # static library only we modify the headers to disable DLL import/export. -if (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) +if (MINGW) # AND NOT LIBCXX_ENABLE_DLLIMPORT ? + message(STATUS "Generating custom __config that skips dllimport") + config_define(ON _LIBCPP_DISABLE_DLLIMPORT) +elseif (DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED) message(STATUS "Generating custom __config for non-DLL Windows build") config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) endif() Index: libcxx/include/__config =================================================================== --- libcxx/include/__config +++ libcxx/include/__config @@ -533,7 +533,7 @@ # define _LIBCPP_CRT_FUNC #endif -#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) +#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(_LIBCPP_DISABLE_DLLIMPORT) && !defined(_LIBCPP_BUILDING_LIBRARY)) # define _LIBCPP_DLL_VIS # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS Index: libcxx/include/__config_site.in =================================================================== --- libcxx/include/__config_site.in +++ libcxx/include/__config_site.in @@ -22,6 +22,7 @@ #cmakedefine _LIBCPP_HAS_THREAD_API_WIN32 #cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL #cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#cmakedefine _LIBCPP_DISABLE_DLLIMPORT #cmakedefine _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS #cmakedefine _LIBCPP_NO_VCRUNTIME #cmakedefine _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION @_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION@ Index: libcxx/src/CMakeLists.txt =================================================================== --- libcxx/src/CMakeLists.txt +++ libcxx/src/CMakeLists.txt @@ -300,7 +300,9 @@ append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) endif() target_compile_options(cxx_static PRIVATE ${CXX_STATIC_LIBRARY_FLAGS}) - target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) + # _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in __config_site + # too. Define it in the same way here, to avoid redefinition conflicts. + target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=) endif() list(APPEND LIBCXX_BUILD_TARGETS "cxx_static") Index: libcxx/test/libcxx/vendor/clang-cl/static-lib-exports.sh.cpp =================================================================== --- libcxx/test/libcxx/vendor/clang-cl/static-lib-exports.sh.cpp +++ libcxx/test/libcxx/vendor/clang-cl/static-lib-exports.sh.cpp @@ -12,8 +12,3 @@ // directives in clang-cl builds. // RUN: llvm-readobj --coff-directives "%{lib}/libc++.lib" | not grep -i "export:" > /dev/null - -// It's a known issue, that when building a shared library at the same time -// as the static library, the generated static library does contain dllexport -// directives. -// XFAIL: windows-dll Index: libcxx/test/libcxx/vendor/mingw/static-lib-exports.sh.cpp =================================================================== --- libcxx/test/libcxx/vendor/mingw/static-lib-exports.sh.cpp +++ libcxx/test/libcxx/vendor/mingw/static-lib-exports.sh.cpp @@ -12,8 +12,3 @@ // directives in MinGW builds. // RUN: llvm-readobj --coff-directives "%{lib}/libc++.a" | not grep -i "export:" > /dev/null - -// It's a known issue, that when building a shared library at the same time -// as the static library, the generated static library does contain dllexport -// directives. -// XFAIL: windows-dll Index: libcxx/test/support/test_macros.h =================================================================== --- libcxx/test/support/test_macros.h +++ libcxx/test/support/test_macros.h @@ -306,8 +306,7 @@ #define TEST_NOT_WIN32(...) __VA_ARGS__ #endif -#if (defined(_WIN32) && !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)) || \ - defined(__MVS__) || defined(_AIX) +#if defined(TEST_WINDOWS_DLL) ||defined(__MVS__) || defined(_AIX) // Macros for waiving cases when we can't count allocations done within // the library implementation. // @@ -325,8 +324,7 @@ #define TEST_SUPPORTS_LIBRARY_INTERNAL_ALLOCATIONS 1 #endif -#if (defined(_WIN32) && !defined(_MSC_VER) && \ - !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)) || \ +#if (defined(TEST_WINDOWS_DLL) && !defined(_MSC_VER)) || \ defined(__MVS__) // Normally, a replaced e.g. 'operator new' ends up used if the user code // does a call to e.g. 'operator new[]'; it's enough to replace the base Index: libcxx/utils/libcxx/test/features.py =================================================================== --- libcxx/utils/libcxx/test/features.py +++ libcxx/utils/libcxx/test/features.py @@ -219,7 +219,31 @@ DEFAULT_FEATURES += [ Feature(name='darwin', when=lambda cfg: '__APPLE__' in compilerMacros(cfg)), Feature(name='windows', when=lambda cfg: '_WIN32' in compilerMacros(cfg)), - Feature(name='windows-dll', when=lambda cfg: '_WIN32' in compilerMacros(cfg) and not '_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS' in compilerMacros(cfg)), + Feature(name='windows-dll', when=lambda cfg: '_WIN32' in compilerMacros(cfg) and programSucceeds(cfg, """ + #include + #include + void *ptr; + int main(int, char**) { + ptr = &std::cout; + if (GetModuleHandle("libc++.dll") || GetModuleHandle("c++.dll")) + return 0; + return 1; + } + """), actions=[AddCompileFlag('-DTEST_WINDOWS_DLL')]), +# #include +# #include +# #include +# int main(int, char**) { +# void *ptr = &std::cout; +# void *exe = GetModuleHandle(NULL); +# PIMAGE_DOS_HEADER dosheader = (PIMAGE_DOS_HEADER)exe; +# PIMAGE_NT_HEADERS ntheader = (PIMAGE_NT_HEADERS)((BYTE *)dosheader + dosheader->e_lfanew); +# PIMAGE_OPTIONAL_HEADER peheader = &ntheader->OptionalHeader; +# void *exeend = (BYTE*)exe + peheader->SizeOfImage; +# if (ptr >= exe && ptr <= exeend) +# return 1; +# return 0; +# } Feature(name='linux', when=lambda cfg: '__linux__' in compilerMacros(cfg)), Feature(name='netbsd', when=lambda cfg: '__NetBSD__' in compilerMacros(cfg)), Feature(name='freebsd', when=lambda cfg: '__FreeBSD__' in compilerMacros(cfg)) Index: libcxxabi/CMakeLists.txt =================================================================== --- libcxxabi/CMakeLists.txt +++ libcxxabi/CMakeLists.txt @@ -136,8 +136,12 @@ set(LIBCXXABI_LIBCXX_INCLUDES "" CACHE PATH "Specify path to libc++ includes.") +set(LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT OFF) +if (WIN32) + set(LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT ON) +endif() option(LIBCXXABI_HERMETIC_STATIC_LIBRARY - "Do not export any symbols from the static library." OFF) + "Do not export any symbols from the static library." ${LIBCXXABI_HERMETIC_STATIC_LIBRARY_DEFAULT}) set(LIBCXXABI_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" CACHE STRING "The path to the Lit testing configuration to use when running the tests. @@ -247,25 +251,6 @@ # it is being built as part of libcxx. add_definitions(-D_LIBCPP_BUILDING_LIBRARY) -# Disable DLL annotations on Windows for static builds. -if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED) - # If LIBCXX_ENABLE_SHARED isn't set (by the user on the cmake command - # line or via a cache file), use its expected default value (enabled). - if ((LIBCXX_ENABLE_SHARED OR NOT DEFINED LIBCXX_ENABLE_SHARED) AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) - # Building libcxxabi statically, but intending for it to be statically - # linked into a shared libcxx; keep dllexport enabled within libcxxabi, - # as the symbols will need to be exported from libcxx. - else() - # Regular static build; disable dllexports. - add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) - if (NOT LIBCXXABI_HERMETIC_STATIC_LIBRARY) - # TODO: Enable this warning message as soon as we're sure this is the solution. - # message(WARNING "Implicitly disabling dllexport on Win32 is not supported anymore. Please build with " - # "LIBCXXABI_HERMETIC_STATIC_LIBRARY=ON instead. This will become an error in LLVM 16.") - endif() - endif() -endif() - add_compile_flags_if_supported(-Werror=return-type) # Get warning flags Index: libcxxabi/src/CMakeLists.txt =================================================================== --- libcxxabi/src/CMakeLists.txt +++ libcxxabi/src/CMakeLists.txt @@ -248,10 +248,13 @@ if (LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS) target_add_compile_flags_if_supported(cxxabi_static_objects PRIVATE -fvisibility-global-new-delete-hidden) endif() + # _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS can be defined in libcxx's + # __config_site too. Define it in the same way here, to avoid redefinition + # conflicts. target_compile_definitions(cxxabi_static_objects PRIVATE _LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS - _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) + _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=) endif() if (LIBCXXABI_ENABLE_STATIC) Index: libunwind/CMakeLists.txt =================================================================== --- libunwind/CMakeLists.txt +++ libunwind/CMakeLists.txt @@ -93,8 +93,13 @@ message(FATAL_ERROR "libunwind CET support is not available for MSVC!") endif() +if (WIN32) + set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS TRUE) +else() + set(LIBUNWIND_DEFAULT_HIDE_SYMBOLS FALSE) +endif() option(LIBUNWIND_HIDE_SYMBOLS - "Do not export any symbols from the static library." OFF) + "Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS}) #=============================================================================== # Configure System @@ -304,11 +309,6 @@ add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() -# Disable DLL annotations on Windows for static builds. -if (WIN32 AND LIBUNWIND_ENABLE_STATIC AND NOT LIBUNWIND_ENABLE_SHARED) - add_definitions(-D_LIBUNWIND_HIDE_SYMBOLS) -endif() - if (C_SUPPORTS_COMMENT_LIB_PRAGMA) if (LIBUNWIND_HAS_DL_LIB) add_definitions(-D_LIBUNWIND_LINK_DL_LIB)