[libcxx-commits] [libcxx] bedf657 - [runtimes] Default LIB*_HERMETIC_STATIC_LIBRARY to ON on Windows

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 18 10:38:04 PDT 2022


Author: Martin Storsjö
Date: 2022-05-18T20:31:51+03:00
New Revision: bedf657d0f4c54ffe9ef4303382657a74296b544

URL: https://github.com/llvm/llvm-project/commit/bedf657d0f4c54ffe9ef4303382657a74296b544
DIFF: https://github.com/llvm/llvm-project/commit/bedf657d0f4c54ffe9ef4303382657a74296b544.diff

LOG: [runtimes] Default LIB*_HERMETIC_STATIC_LIBRARY to ON on Windows

(In the case of libunwind, the cmake option is called
LIBUNWIND_HIDE_SYMBOLS, but it has the same effect as
LIBCXX_HERMETIC_STATIC_LIBRARY and
LIBCXXABI_HERMETIC_STATIC_LIBRARY.)

Previously, the same issue was dealt with by setting a project wide
define (_LIBUNWIND_HIDE_SYMBOLS,
_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS and
_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) if only building a static
library.  If building both static and shared at the same time, this
wasn't set, and the static library would contain dllexport directives.

The LIB*_HERMETIC_STATIC_LIBRARY and LIBUNWIND_HIDE_SYMBOLS cmake
options only apply the defines to the static library in the build,
even if building both static and shared at the same time.

(This could only be done use after the object libraries were
enabled, as a shared libcxx needs libcxxabi object files built
with dllexports included.)

This allows removing inelegant code for deciding how to build the
libcxxabi static library and a TODO comment that suggested that
users should need to start setting an option, which they shouldn't
need to. Finally, this gets rid of two XFAILs in tests.

Differential Revision: https://reviews.llvm.org/D125715

Added: 
    

Modified: 
    libcxx/CMakeLists.txt
    libcxx/src/CMakeLists.txt
    libcxx/test/libcxx/vendor/clang-cl/static-lib-exports.sh.cpp
    libcxx/test/libcxx/vendor/mingw/static-lib-exports.sh.cpp
    libcxxabi/CMakeLists.txt
    libcxxabi/src/CMakeLists.txt
    libunwind/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 2b2c42cf8ff6e..ec4c2e408ca90 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -315,8 +315,12 @@ endif()
 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

diff  --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt
index 962f6f54e28f2..42f41719eec23 100644
--- a/libcxx/src/CMakeLists.txt
+++ b/libcxx/src/CMakeLists.txt
@@ -300,7 +300,9 @@ if (LIBCXX_ENABLE_STATIC)
       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")

diff  --git a/libcxx/test/libcxx/vendor/clang-cl/static-lib-exports.sh.cpp b/libcxx/test/libcxx/vendor/clang-cl/static-lib-exports.sh.cpp
index 35f2221bf1c25..fb66c4a28fa08 100644
--- a/libcxx/test/libcxx/vendor/clang-cl/static-lib-exports.sh.cpp
+++ b/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

diff  --git a/libcxx/test/libcxx/vendor/mingw/static-lib-exports.sh.cpp b/libcxx/test/libcxx/vendor/mingw/static-lib-exports.sh.cpp
index 7af240ebe2854..7dfedb761f0c7 100644
--- a/libcxx/test/libcxx/vendor/mingw/static-lib-exports.sh.cpp
+++ b/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

diff  --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index aa5ab9a0086b2..791ff6c75df72 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -136,8 +136,12 @@ endif()
 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 @@ add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY)
 # 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

diff  --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index e19f33c55a29f..afaed4fea326c 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -248,10 +248,13 @@ if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
   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)

diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 4d1f7be659faf..5a06805f05f18 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -93,8 +93,13 @@ if (LIBUNWIND_ENABLE_CET AND MSVC)
   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 @@ if (MSVC)
   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)


        


More information about the libcxx-commits mailing list