[libcxx-commits] [PATCH] D60794: [libcxx][CMake] Add an option to include -lgcc_s in the linker script

Tom Stellard via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 16 13:21:25 PDT 2019


tstellar created this revision.
tstellar added reviewers: mstorsjo, ldionne, phosek, EricWF.
Herald added subscribers: dexonsmith, christof, mgorny.
Herald added a project: libc++.

This adds the LIBCXXABI_USE_LIBGCC_UNWINDER cmake option, which is the
libgcc version of LIBCXXABI_USE_LLVM_UNWINDER.  When enabled, it will
add -lgcc_s to the libc++.so linker script, so that users will not
need to explicitly link to an unwind library when linking with libc++.so.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60794

Files:
  libcxx/CMakeLists.txt
  libcxx/lib/CMakeLists.txt
  libcxx/test/CMakeLists.txt
  libcxx/test/lit.site.cfg.in
  libcxx/utils/libcxx/test/target_info.py


Index: libcxx/utils/libcxx/test/target_info.py
===================================================================
--- libcxx/utils/libcxx/test/target_info.py
+++ libcxx/utils/libcxx/test/target_info.py
@@ -233,6 +233,7 @@
         enable_threads = ('libcpp-has-no-threads' not in
                           self.full_config.config.available_features)
         llvm_unwinder = self.full_config.get_lit_bool('llvm_unwinder', False)
+        libgcc_unwinder = self.full_config.get_lit_bool('libgcc_unwinder', False)
         libcxx_is_linker_script  = self.full_config.get_lit_bool('libcxx_is_linker_script', False)
         shared_libcxx = self.full_config.get_lit_bool('enable_shared', True)
         flags += ['-lm']
@@ -241,17 +242,26 @@
             if not shared_libcxx:
                 flags += ['-lrt']
         flags += ['-lc']
+
+        # Unwinder library link flag matrix.
+        #
+        # Linker Script | Yes | No
+        #-------------------------
+        # unwind        |  X  | unwind 
+        # libgcc        |  X  | gcc 
+        # None          | gcc | gcc
+        #
         if llvm_unwinder and not libcxx_is_linker_script:
             # FIXME: Why does llvm unwinder need -ldl?
             flags += ['-lunwind', '-ldl']
-        elif not llvm_unwinder:
+        elif not libcxx_is_linker_script or (not llvm_unwinder and not libgcc_unwinder):
             # If we aren't using llvm unwinder, then fallback to using libgcc's
             # unwind implementation.
             # FIXME: Why is -lgcc needed for the unwinder?
             flags += ['-lgcc_s', '-lgcc']
-        # If we are using a linker script and llvm_unwinder is eanbled, then we
-        # don't need to explicitly link against -lunwind, since the linker
-        # script will take care of that for us.
+        # If we are using a linker script and llvm_unwinder or libgcc_unwinder
+        # is eanbled, then we don't need to explicitly link against an unwind
+        # implementation, since the linker script will take care of that for us.
         builtins_lib = self.full_config.get_lit_conf('builtins_library')
         if builtins_lib:
             flags += [builtins_lib]
Index: libcxx/test/lit.site.cfg.in
===================================================================
--- libcxx/test/lit.site.cfg.in
+++ libcxx/test/lit.site.cfg.in
@@ -27,6 +27,7 @@
 
 config.executor                 = "@LIBCXX_EXECUTOR@"
 config.llvm_unwinder            = @LIBCXXABI_USE_LLVM_UNWINDER@
+config.libgcc_unwinder          = "@LIBCXXABI_USE_LIBGCC_UNWINDER@"
 config.libcxx_is_linker_script  = @LIBCXX_ENABLE_ABI_LINKER_SCRIPT@
 config.builtins_library         = "@LIBCXX_BUILTINS_LIBRARY@"
 config.has_libatomic            = @LIBCXX_HAS_ATOMIC_LIB@
Index: libcxx/test/CMakeLists.txt
===================================================================
--- libcxx/test/CMakeLists.txt
+++ libcxx/test/CMakeLists.txt
@@ -29,6 +29,7 @@
 pythonize_bool(LIBCXX_GENERATE_COVERAGE)
 pythonize_bool(LIBCXXABI_ENABLE_SHARED)
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
+pythonize_bool(LIBCXXABI_USE_LIBGCC_UNWINDER)
 pythonize_bool(LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
 pythonize_bool(LIBCXX_USE_COMPILER_RT)
 pythonize_bool(LIBCXX_HAS_ATOMIC_LIB)
Index: libcxx/lib/CMakeLists.txt
===================================================================
--- libcxx/lib/CMakeLists.txt
+++ libcxx/lib/CMakeLists.txt
@@ -99,6 +99,8 @@
   else()
     add_interface_library(unwind)
   endif()
+elseif (LIBCXXABI_USE_LIBGCC_UNWINDER)
+  add_interface_library(gcc_s)
 endif()
 
 # Setup flags.
Index: libcxx/CMakeLists.txt
===================================================================
--- libcxx/CMakeLists.txt
+++ libcxx/CMakeLists.txt
@@ -221,6 +221,12 @@
 option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
 option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
 
+option(LIBCXXABI_USE_LIBGCC_UNWINDER "Use libgcc unwind library" OFF)
+if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_USE_LIBGCC_UNWINDER)
+  message(FATAL_ERROR "Cannot specify both LIBCXXABI_USE_LLVM_UNWINDER and
+                       LIBCXXABI_USE_LIBGCC_UNWINDER.")
+endif()
+
 # Target options --------------------------------------------------------------
 option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS})
 set(LIBCXX_TARGET_TRIPLE "" CACHE STRING "Use alternate target triple.")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60794.195445.patch
Type: text/x-patch
Size: 4411 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190416/77b0ee94/attachment.bin>


More information about the libcxx-commits mailing list