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: 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")