[PATCH] [libcxx] Add support for linking libc++ against a static ABI library.

Eric Fiselier eric at efcs.ca
Mon Mar 2 14:16:13 PST 2015


Hi mclow.lists, danalbert, jroelofs,

This patch add the CMake option `LIBCXX_ENABLE_STATIC_ABI_LIBRARY` which, when enabled, will link libc++ against the static version of the ABI library.

http://reviews.llvm.org/D8017

Files:
  CMakeLists.txt
  cmake/Modules/HandleLibCXXABI.cmake
  lib/CMakeLists.txt
  test/CMakeLists.txt

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -61,6 +61,7 @@
    This option may only be used when LIBCXX_ENABLE_THREADS=OFF." ON)
 option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON)
 option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
+option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF)
 set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.")
 set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.")
 if (LIBCXX_BUILT_STANDALONE)
@@ -68,6 +69,14 @@
       "Define the sanitizer used to build the library and tests")
 endif()
 
+if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+  if (APPLE)
+    message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X")
+  else()
+    message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option")
+  endif()
+endif()
+
 set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++)
 if (NOT LIBCXX_CXX_ABI)
   if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
Index: cmake/Modules/HandleLibCXXABI.cmake
===================================================================
--- cmake/Modules/HandleLibCXXABI.cmake
+++ cmake/Modules/HandleLibCXXABI.cmake
@@ -78,7 +78,11 @@
 elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
   if (LIBCXX_CXX_ABI_INTREE)
     # Link against just-built "cxxabi" target.
-    set(CXXABI_LIBNAME cxxabi)
+    if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+        set(CXXABI_LIBNAME cxxabi_static)
+    else()
+        set(CXXABI_LIBNAME cxxabi_shared)
+    endif()
     set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE)
   else()
     # Assume c++abi is installed in the system, rely on -lc++abi link flag.
Index: lib/CMakeLists.txt
===================================================================
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -38,8 +38,18 @@
   add_dependencies(cxx LIBCXX_CXX_ABI_DEPS)
 endif()
 
+set(libraries "")
+if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+    list(APPEND libraries "-Wl,--whole-archive")
+    list(APPEND libraries "-Wl,-Bstatic")
+    list(APPEND libraries "${LIBCXX_CXX_ABI_LIBRARY}")
+    list(APPEND libraries "-Wl,-Bdynamic")
+    list(APPEND libraries "-Wl,--no-whole-archive")
+else()
+    list(APPEND libraries "${LIBCXX_CXX_ABI_LIBRARY}")
+endif()
+
 # Generate library list.
-set(libraries ${LIBCXX_CXX_ABI_LIBRARY})
 append_if(libraries LIBCXX_HAS_PTHREAD_LIB pthread)
 append_if(libraries LIBCXX_HAS_C_LIB c)
 append_if(libraries LIBCXX_HAS_M_LIB m)
Index: test/CMakeLists.txt
===================================================================
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -44,6 +44,11 @@
   pythonize_bool(LIBCXX_BUILD_32_BITS)
   pythonize_bool(LIBCXX_ENABLE_THREADS)
   pythonize_bool(LIBCXX_ENABLE_MONOTONIC_CLOCK)
+  # The tests shouldn't link to any ABI library when it has been linked into
+  # libc++ statically.
+  if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+    set(LIBCXX_CXX_ABI_LIBNAME "none")
+  endif()
   set(LIBCXX_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
       "TargetInfo to use when setting up test environment.")
   set(LIBCXX_EXECUTOR "None" CACHE STRING

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8017.21039.patch
Type: text/x-patch
Size: 3218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150302/1b89373a/attachment.bin>


More information about the cfe-commits mailing list