Index: cmake/Modules/AddCompilerRT.cmake =================================================================== --- cmake/Modules/AddCompilerRT.cmake +++ cmake/Modules/AddCompilerRT.cmake @@ -342,9 +342,9 @@ endif() endfunction() -# when cross compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help +# when cross compiling or using a non-default toolchain, COMPILER_RT_TOOLCHAIN_CFLAGS help # in compilation and linking of unittests. -string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}") +string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TOOLCHAIN_CFLAGS}") set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS}) # Unittests support. @@ -554,6 +554,8 @@ set(PASSTHROUGH_VARIABLES CMAKE_C_COMPILER_TARGET CMAKE_CXX_COMPILER_TARGET + CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN + CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_EXE_LINKER_FLAGS Index: cmake/base-config-ix.cmake =================================================================== --- cmake/base-config-ix.cmake +++ cmake/base-config-ix.cmake @@ -219,4 +219,12 @@ endif() set(COMPILER_RT_OS_SUFFIX "") endif() + # Set up options associated with the toolchain. + if(COMPILER_RT_TEST_COMPILER_CFLAGS) + # COMPILER_RT_TEST_COMPILER_CFLAGS is used for cross-compiling. + set(COMPILER_RT_TOOLCHAIN_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS}) + elseif(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN AND COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang") + # Use the non-default toolchain specified for the build when compiling tests. + set(COMPILER_RT_TOOLCHAIN_CFLAGS "--gcc-toolchain=${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}") + endif() endmacro() Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -199,6 +199,7 @@ if(APPLE) list(APPEND ${cflags_out} ${DARWIN_osx_CFLAGS}) endif() + list(APPEND ${cflags_out} ${COMPILER_RT_TOOLCHAIN_CFLAGS}) string(REPLACE ";" " " ${cflags_out} "${${cflags_out}}") endif() endmacro() Index: lib/interception/tests/CMakeLists.txt =================================================================== --- lib/interception/tests/CMakeLists.txt +++ lib/interception/tests/CMakeLists.txt @@ -21,6 +21,9 @@ -Werror=sign-compare -Wno-non-virtual-dtor) +set(INTERCEPTION_TEST_LINK_FLAGS_COMMON + ${COMPILER_RT_UNITTEST_LINK_FLAGS}) + # -gline-tables-only must be enough for these tests, so use it if possible. if(COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang") list(APPEND INTERCEPTION_TEST_CFLAGS_COMMON -gline-tables-only) Index: lib/msan/tests/CMakeLists.txt =================================================================== --- lib/msan/tests/CMakeLists.txt +++ lib/msan/tests/CMakeLists.txt @@ -47,6 +47,7 @@ -mllvm -msan-keep-going=1 ) set(MSAN_UNITTEST_LINK_FLAGS + ${COMPILER_RT_UNITTEST_LINK_FLAGS} -fsanitize=memory # Don't need -stdlib=libc++ because we explicitly list libc++.a in the linker # inputs. @@ -73,7 +74,7 @@ endif() clang_link_shared(${output_so} OBJECTS ${SOURCE_OBJECTS} - LINK_FLAGS ${TARGET_LINK_FLAGS} ${SOURCE_LINK_FLAGS} + LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS} ${TARGET_LINK_FLAGS} ${SOURCE_LINK_FLAGS} DEPS ${SOURCE_DEPS}) list(APPEND ${so_list} ${output_so}) endmacro() Index: lib/sanitizer_common/tests/CMakeLists.txt =================================================================== --- lib/sanitizer_common/tests/CMakeLists.txt +++ lib/sanitizer_common/tests/CMakeLists.txt @@ -59,6 +59,8 @@ -Wno-non-virtual-dtor -Wno-gnu-zero-variadic-macro-arguments) +set(SANITIZER_TEST_LINK_FLAGS_COMMON ${COMPILER_RT_UNITTEST_LINK_FLAGS}) + # -gline-tables-only must be enough for these tests, so use it if possible. if(COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang") list(APPEND SANITIZER_TEST_CFLAGS_COMMON -gline-tables-only) Index: lib/scudo/standalone/tests/CMakeLists.txt =================================================================== --- lib/scudo/standalone/tests/CMakeLists.txt +++ lib/scudo/standalone/tests/CMakeLists.txt @@ -15,7 +15,7 @@ set(SCUDO_TEST_ARCH ${SCUDO_SUPPORTED_ARCH}) # gtests requires c++ -set(LINK_FLAGS) +set(LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS}) foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) list(APPEND LINK_FLAGS -l${lib}) endforeach() Index: lib/tsan/tests/CMakeLists.txt =================================================================== --- lib/tsan/tests/CMakeLists.txt +++ lib/tsan/tests/CMakeLists.txt @@ -15,7 +15,7 @@ set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH}) -set(LINK_FLAGS) +set(LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS}) foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) list(APPEND LINK_FLAGS -l${lib}) endforeach() Index: lib/xray/tests/CMakeLists.txt =================================================================== --- lib/xray/tests/CMakeLists.txt +++ lib/xray/tests/CMakeLists.txt @@ -47,7 +47,10 @@ endfunction() set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH}) -set(XRAY_UNITTEST_LINK_FLAGS ${CMAKE_THREAD_LIBS_INIT}) +set(XRAY_UNITTEST_LINK_FLAGS + ${COMPILER_RT_UNITTEST_LINK_FLAGS} + ${CMAKE_THREAD_LIBS_INIT} + ) if (NOT APPLE) # Needed by LLVMSupport. Index: test/asan/CMakeLists.txt =================================================================== --- test/asan/CMakeLists.txt +++ test/asan/CMakeLists.txt @@ -89,7 +89,7 @@ foreach(arch ${DARWIN_iossim_ARCHS}) set(ASAN_TEST_APPLE_PLATFORM "iossim") set(ASAN_TEST_TARGET_ARCH ${arch}) - set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") + set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TOOLCHAIN_CFLAGS}") set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}") get_bits_for_arch(${arch} ASAN_TEST_BITS) string(TOUPPER ${arch} ARCH_UPPER_CASE) @@ -106,7 +106,7 @@ foreach (arch ${DARWIN_ios_ARCHS}) set(ASAN_TEST_APPLE_PLATFORM "ios") set(ASAN_TEST_TARGET_ARCH ${arch}) - set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") + set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TOOLCHAIN_CFLAGS}") set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-${ASAN_TEST_APPLE_PLATFORM}") get_bits_for_arch(${arch} ASAN_TEST_BITS) string(TOUPPER ${arch} ARCH_UPPER_CASE) Index: test/fuzzer/CMakeLists.txt =================================================================== --- test/fuzzer/CMakeLists.txt +++ test/fuzzer/CMakeLists.txt @@ -91,7 +91,7 @@ foreach(arch ${DARWIN_ios_ARCHS}) set(LIBFUZZER_TEST_APPLE_PLATFORM "ios") set(LIBFUZZER_TEST_TARGET_ARCH ${arch}) - set(LIBFUZZER_TEST_FLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") + set(LIBFUZZER_TEST_FLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TOOLCHAIN_CFLAGS}") set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${LIBFUZZER_TEST_APPLE_PLATFORM}") string(TOUPPER ${arch} ARCH_UPPER_CASE) set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config") Index: test/lit.common.configured.in =================================================================== --- test/lit.common.configured.in +++ test/lit.common.configured.in @@ -7,7 +7,7 @@ # Generic config options for all compiler-rt lit tests. set_default("target_triple", "@COMPILER_RT_DEFAULT_TARGET_TRIPLE@") -set_default("target_cflags", "@COMPILER_RT_TEST_COMPILER_CFLAGS@") +set_default("target_cflags", "@COMPILER_RT_TOOLCHAIN_CFLAGS@") set_default("host_arch", "@HOST_ARCH@") set_default("target_arch", "@COMPILER_RT_DEFAULT_TARGET_ARCH@") set_default("host_os", "@HOST_OS@") Index: test/tsan/CMakeLists.txt =================================================================== --- test/tsan/CMakeLists.txt +++ test/tsan/CMakeLists.txt @@ -53,7 +53,7 @@ set(TSAN_TEST_APPLE_PLATFORM "iossim") set(arch "x86_64") set(TSAN_TEST_TARGET_ARCH ${arch}) - set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") + set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TOOLCHAIN_CFLAGS}") set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}") string(TOUPPER ${arch} ARCH_UPPER_CASE) set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config") @@ -68,7 +68,7 @@ set(TSAN_TEST_APPLE_PLATFORM "ios") set(arch "arm64") set(TSAN_TEST_TARGET_ARCH ${arch}) - set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") + set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TOOLCHAIN_CFLAGS}") set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}") string(TOUPPER ${arch} ARCH_UPPER_CASE) set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")