diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt @@ -43,6 +43,28 @@ append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS) append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS) +# Link to the apropriate unwind lib, if any. +if(COMPILER_RT_USE_LLVM_UNWINDER) + set(SCUDO_LINK_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS} dl) +elseif(COMPILER_RT_HAS_GWP_ASAN AND "${LLVM_NATIVE_ARCH}" STREQUAL "ARM") + # On ARM, we must link against an unwind lib when GWPAsan is used, otherwise + # we get undefined references to __aeabi_unwind_cpp_pr* symbols. + # This is because object files compiled with -funwind-tables end up + # referencing these symbols on ARM, while on other architectures, such as + # x86_64 and AArch64, only the .eh_frame section is added, but no references + # to an unwind library are made. + # As COMPILER_RT_USE_LLVM_UNWINDER must be set for compiler-rt to be linked + # against libunwind, only libgcc_s/libgcc needs to be handled here. + if (COMPILER_RT_HAS_GCC_S_LIB) + set(SCUDO_LINK_LIBS gcc_s) + elseif (COMPILER_RT_HAS_GCC_LIB) + set(SCUDO_LINK_LIBS gcc) + else() + message(FATAL_ERROR + "COMPILER_RT_USE_LLVM_UNWINDER is false and libgcc_s/libgcc was not found") + endif() +endif() + if(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH) list(APPEND SCUDO_CFLAGS "--sysroot=${COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH}") endif() @@ -146,8 +168,6 @@ endif() -set(SCUDO_LINK_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS}) - if(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC) include_directories(${COMPILER_RT_BINARY_DIR}/../libc/include/)