diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -474,6 +474,8 @@ 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 @@ 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 "$") + list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "$") else() - list(APPEND SANITIZER_CXX_ABI_LIBRARIES "$,unwind_shared,unwind_static>>") + list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "$,unwind_shared,unwind_static>>") endif() endif() @@ -561,6 +567,11 @@ 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) diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -38,6 +38,7 @@ # 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. diff --git a/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt b/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt --- a/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/gwp_asan/tests/CMakeLists.txt @@ -36,6 +36,7 @@ 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) diff --git a/compiler-rt/lib/interception/tests/CMakeLists.txt b/compiler-rt/lib/interception/tests/CMakeLists.txt --- a/compiler-rt/lib/interception/tests/CMakeLists.txt +++ b/compiler-rt/lib/interception/tests/CMakeLists.txt @@ -23,6 +23,7 @@ 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. diff --git a/compiler-rt/lib/memprof/tests/CMakeLists.txt b/compiler-rt/lib/memprof/tests/CMakeLists.txt --- a/compiler-rt/lib/memprof/tests/CMakeLists.txt +++ b/compiler-rt/lib/memprof/tests/CMakeLists.txt @@ -40,7 +40,9 @@ 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) diff --git a/compiler-rt/lib/orc/CMakeLists.txt b/compiler-rt/lib/orc/CMakeLists.txt --- a/compiler-rt/lib/orc/CMakeLists.txt +++ b/compiler-rt/lib/orc/CMakeLists.txt @@ -53,7 +53,9 @@ ${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}) diff --git a/compiler-rt/lib/orc/unittests/CMakeLists.txt b/compiler-rt/lib/orc/unittests/CMakeLists.txt --- a/compiler-rt/lib/orc/unittests/CMakeLists.txt +++ b/compiler-rt/lib/orc/unittests/CMakeLists.txt @@ -37,8 +37,8 @@ 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) diff --git a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt --- a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt @@ -74,6 +74,7 @@ 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. diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -36,6 +36,7 @@ # 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 diff --git a/compiler-rt/lib/tsan/tests/CMakeLists.txt b/compiler-rt/lib/tsan/tests/CMakeLists.txt --- a/compiler-rt/lib/tsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/CMakeLists.txt @@ -27,6 +27,7 @@ set(TSAN_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS} + ${COMPILER_RT_UNWINDER_LINK_LIBS} ${SANITIZER_TEST_CXX_LIBRARIES}) if(APPLE) diff --git a/compiler-rt/lib/xray/CMakeLists.txt b/compiler-rt/lib/xray/CMakeLists.txt --- a/compiler-rt/lib/xray/CMakeLists.txt +++ b/compiler-rt/lib/xray/CMakeLists.txt @@ -150,7 +150,9 @@ 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) diff --git a/compiler-rt/lib/xray/tests/CMakeLists.txt b/compiler-rt/lib/xray/tests/CMakeLists.txt --- a/compiler-rt/lib/xray/tests/CMakeLists.txt +++ b/compiler-rt/lib/xray/tests/CMakeLists.txt @@ -50,8 +50,8 @@ 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.