diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/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.") diff --git a/libcxx/lib/CMakeLists.txt b/libcxx/lib/CMakeLists.txt --- a/libcxx/lib/CMakeLists.txt +++ b/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. diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt --- a/libcxx/test/CMakeLists.txt +++ b/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) diff --git a/libcxx/test/lit.site.cfg.in b/libcxx/test/lit.site.cfg.in --- a/libcxx/test/lit.site.cfg.in +++ b/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@ diff --git a/libcxx/utils/libcxx/test/target_info.py b/libcxx/utils/libcxx/test/target_info.py --- a/libcxx/utils/libcxx/test/target_info.py +++ b/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]