[compiler-rt][CMake] Set --unwindlib=none when using LLVM libunwind

We already link libunwind explicitly so avoid trying to link toolchain's
default libunwind which may be missing. This matches what we already do
for libcxx and libcxxabi.

Differential Revision: https://reviews.llvm.org/D129472
This commit is contained in:
Petr Hosek 2022-07-11 08:08:37 +00:00
parent 5da5483ffb
commit 6699f55488
12 changed files with 32 additions and 9 deletions

View File

@ -474,6 +474,8 @@ append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS)
append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS)
# Set common link flags.
# TODO: We should consider using the same model as libc++, that is use either
# -nostdlib++ and --unwindlib=none if supported, or -nodefaultlibs otherwise.
append_list_if(C_SUPPORTS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS)
append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
@ -533,10 +535,14 @@ string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_
set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS})
if(COMPILER_RT_USE_LLVM_UNWINDER)
# We're linking directly against the libunwind that we're building so don't
# try to link in the toolchain's default libunwind which may be missing.
append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none COMPILER_RT_COMMON_LINK_FLAGS)
append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none COMPILER_RT_UNITTEST_LINK_FLAGS)
if (COMPILER_RT_ENABLE_STATIC_UNWINDER)
list(APPEND SANITIZER_CXX_ABI_LIBRARIES "$<TARGET_LINKER_FILE:unwind_static>")
list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "$<TARGET_LINKER_FILE:unwind_static>")
else()
list(APPEND SANITIZER_CXX_ABI_LIBRARIES "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:unwind_shared>,unwind_shared,unwind_static>>")
list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:unwind_shared>,unwind_shared,unwind_static>>")
endif()
endif()
@ -561,6 +567,11 @@ endif()
macro(append_libcxx_libs var)
if (${var}_INTREE)
# TODO: We don't need to add --unwindlib=none to SANITIZER_COMMON_LINK_FLAGS
# because we added -nodefaultlibs there earlier, and adding would result in
# a warning, but if we switch to -nostdlib++, we would need to add it here.
# append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SANITIZER_COMMON_LINK_FLAGS)
if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND))
list(APPEND ${var}_LIBRARIES unwind_static)
elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)

View File

@ -38,6 +38,7 @@ append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros ASAN_U
# during cross compilation
set(ASAN_UNITTEST_COMMON_LINK_FLAGS
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_TEST_CXX_LIBRARIES})
# -gline-tables-only must be enough for ASan, so use it if possible.

View File

@ -36,6 +36,7 @@ set_target_properties(GwpAsanUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
set(GWP_ASAN_UNITTEST_LINK_FLAGS
${COMPILER_RT_UNITTEST_LINK_FLAGS} -ldl
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_TEST_CXX_LIBRARIES})
list(APPEND GWP_ASAN_UNITTEST_LINK_FLAGS --driver-mode=g++)
if(NOT WIN32)

View File

@ -23,6 +23,7 @@ set(INTERCEPTION_TEST_CFLAGS_COMMON
set(INTERCEPTION_TEST_LINK_FLAGS_COMMON
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_TEST_CXX_LIBRARIES})
# -gline-tables-only must be enough for these tests, so use it if possible.

View File

@ -40,7 +40,9 @@ if(NOT WIN32)
list(APPEND MEMPROF_UNITTEST_LINK_FLAGS -pthread)
endif()
set(MEMPROF_UNITTEST_LINK_LIBRARIES ${SANITIZER_TEST_CXX_LIBRARIES})
set(MEMPROF_UNITTEST_LINK_LIBRARIES
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_TEST_CXX_LIBRARIES})
list(APPEND MEMPROF_UNITTEST_LINK_LIBRARIES "dl")
if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST MEMPROF_SUPPORTED_ARCH)

View File

@ -53,7 +53,9 @@ set(ORC_CFLAGS
${COMPILER_RT_COMMON_CFLAGS}
${COMPILER_RT_CXX_CFLAGS})
set(ORC_LINK_FLAGS ${COMPILER_RT_COMMON_LINK_FLAGS})
set(ORC_LINK_LIBS ${COMPILER_RT_CXX_LINK_LIBS})
set(ORC_LINK_LIBS
${COMPILER_RT_UNWINDER_LINK_LIBS}
${COMPILER_RT_CXX_LINK_LIBS})
# Allow the ORC runtime to reference LLVM headers.
foreach (DIR ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})

View File

@ -37,8 +37,8 @@ set(ORC_TEST_ARCH ${ORC_SUPPORTED_ARCH})
set(ORC_UNITTEST_LINK_FLAGS
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${CMAKE_THREAD_LIBS_INIT}
${COMPILER_RT_CXX_LINK_LIBS}
)
${COMPILER_RT_UNWINDER_LINK_LIBS}
${COMPILER_RT_CXX_LINK_LIBS})
if(APPLE)
darwin_filter_host_archs(ORC_SUPPORTED_ARCH ORC_TEST_ARCH)

View File

@ -74,6 +74,7 @@ set(SANITIZER_TEST_CFLAGS_COMMON
set(SANITIZER_TEST_LINK_FLAGS_COMMON
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_TEST_CXX_LIBRARIES})
# -gline-tables-only must be enough for these tests, so use it if possible.

View File

@ -36,6 +36,7 @@ set(SCUDO_TEST_ARCH ${SCUDO_STANDALONE_SUPPORTED_ARCH})
# gtests requires c++
set(SCUDO_UNITTEST_LINK_FLAGS
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_TEST_CXX_LIBRARIES})
list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie)
# Linking against libatomic is required with some compilers

View File

@ -27,6 +27,7 @@ set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH})
set(TSAN_UNITTEST_LINK_FLAGS
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${COMPILER_RT_UNWINDER_LINK_LIBS}
${SANITIZER_TEST_CXX_LIBRARIES})
if(APPLE)

View File

@ -150,7 +150,9 @@ append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format XRAY_CFLAGS)
append_rtti_flag(OFF XRAY_CFLAGS)
set(XRAY_LINK_FLAGS ${COMPILER_RT_COMMON_LINK_FLAGS})
set(XRAY_LINK_LIBS ${COMPILER_RT_CXX_LINK_LIBS})
set(XRAY_LINK_LIBS
${COMPILER_RT_UNWINDER_LINK_LIBS}
${COMPILER_RT_CXX_LINK_LIBS})
append_list_if(
COMPILER_RT_HAS_XRAY_COMPILER_FLAG XRAY_SUPPORTED=1 XRAY_COMMON_DEFINITIONS)

View File

@ -50,8 +50,8 @@ set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH})
set(XRAY_UNITTEST_LINK_FLAGS
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${CMAKE_THREAD_LIBS_INIT}
${COMPILER_RT_CXX_LINK_LIBS}
)
${COMPILER_RT_UNWINDER_LINK_LIBS}
${COMPILER_RT_CXX_LINK_LIBS})
if (NOT APPLE)
# Needed by LLVMSupport.