diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index d2da0496b97f..875acc83be4e 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -208,6 +208,32 @@ macro(get_test_cc_for_arch arch cc_out cflags_out) endif() endmacro() +# Returns CFLAGS that should be used to run tests for the +# specific apple platform and architecture. +function(get_test_cflags_for_apple_platform platform arch cflags_out) + is_valid_apple_platform("${platform}" is_valid_platform) + if (NOT is_valid_platform) + message(FATAL_ERROR "\"${platform}\" is not a valid apple platform") + endif() + set(test_cflags "") + get_target_flags_for_arch(${arch} test_cflags) + list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS}) + string(REPLACE ";" " " test_cflags_str "${test_cflags}") + string(APPEND test_cflags_str "${COMPILER_RT_TEST_COMPILER_CFLAGS}") + set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE) +endfunction() + +function(is_valid_apple_platform platform is_valid_out) + set(is_valid FALSE) + if ("${platform}" STREQUAL "") + message(FATAL_ERROR "platform cannot be empty") + endif() + if ("${platform}" MATCHES "^(osx|((ios|watchos|tvos)(sim)?))$") + set(is_valid TRUE) + endif() + set(${is_valid_out} ${is_valid} PARENT_SCOPE) +endfunction() + set(ARM64 aarch64) set(ARM32 arm armhf) set(HEXAGON hexagon) diff --git a/compiler-rt/test/asan/CMakeLists.txt b/compiler-rt/test/asan/CMakeLists.txt index 1892c881849a..79e34a01619a 100644 --- a/compiler-rt/test/asan/CMakeLists.txt +++ b/compiler-rt/test/asan/CMakeLists.txt @@ -82,15 +82,22 @@ endforeach() # variable to select which iOS device or simulator to use, e.g.: # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6" if(APPLE) + # FIXME(dliew): This logic should be refactored to the way UBSan Darwin + # testing is done. set(EXCLUDE_FROM_ALL ON) set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER}) set(ASAN_TEST_DYNAMIC True) - foreach(arch ${DARWIN_iossim_ARCHS}) + list_intersect(ASAN_TEST_IOSSIM_ARCHS ASAN_SUPPORTED_ARCH DARWIN_iossim_ARCHS) + foreach(arch ${ASAN_TEST_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}") + get_test_cflags_for_apple_platform( + "${ASAN_TEST_APPLE_PLATFORM}" + "${ASAN_TEST_TARGET_ARCH}" + ASAN_TEST_TARGET_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) @@ -104,10 +111,14 @@ if(APPLE) DEPENDS ${ASAN_TEST_DEPS}) endforeach() - foreach (arch ${DARWIN_ios_ARCHS}) + list_intersect(ASAN_TEST_IOS_ARCHS ASAN_SUPPORTED_ARCH DARWIN_ios_ARCHS) + foreach (arch ${ASAN_TEST_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}") + get_test_cflags_for_apple_platform( + "${ASAN_TEST_APPLE_PLATFORM}" + "${arch}" + ASAN_TEST_TARGET_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) diff --git a/compiler-rt/test/fuzzer/CMakeLists.txt b/compiler-rt/test/fuzzer/CMakeLists.txt index 62161d0019bb..25bdcd2f0d97 100644 --- a/compiler-rt/test/fuzzer/CMakeLists.txt +++ b/compiler-rt/test/fuzzer/CMakeLists.txt @@ -89,12 +89,19 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") endif() if (APPLE) + # FIXME(dliew): This logic should be refactored to the way UBSan Darwin + # testing is done. set(EXCLUDE_FROM_ALL ON) - foreach(arch ${DARWIN_ios_ARCHS}) + list_intersect(FUZZER_TEST_IOS_ARCHS FUZZER_SUPPORTED_ARCH DARWIN_ios_ARCHS) + foreach(arch ${FUZZER_TEST_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}") + get_test_cflags_for_apple_platform( + "${LIBFUZZER_TEST_APPLE_PLATFORM}" + "${LIBFUZZER_TEST_TARGET_ARCH}" + LIBFUZZER_TEST_FLAGS + ) set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${LIBFUZZER_TEST_APPLE_PLATFORM}") string(TOUPPER ${arch} ARCH_UPPER_CASE) set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config") diff --git a/compiler-rt/test/tsan/CMakeLists.txt b/compiler-rt/test/tsan/CMakeLists.txt index f21fc2a3beec..9159e75129b0 100644 --- a/compiler-rt/test/tsan/CMakeLists.txt +++ b/compiler-rt/test/tsan/CMakeLists.txt @@ -49,39 +49,52 @@ endforeach() # variable to select which iOS device or simulator to use, e.g.: # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6" if(APPLE) + # FIXME(dliew): This logic should be refactored to the way UBSan Darwin + # testing is done. set(EXCLUDE_FROM_ALL ON) - set(TSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER}) - 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_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}") - string(TOUPPER ${arch} ARCH_UPPER_CASE) - set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config") - configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in - ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py - ) - add_lit_testsuite(check-tsan-iossim-${arch} "ThreadSanitizer iOS Simulator ${arch} tests" - ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ - DEPENDS ${TSAN_TEST_DEPS}) + list_intersect(TSAN_TEST_IOSSIM_ARCHS TSAN_SUPPORTED_ARCH DARWIN_iossim_ARCHS) + foreach(arch ${TSAN_TEST_IOSSIM_ARCHS}) + set(TSAN_TEST_APPLE_PLATFORM "iossim") + set(TSAN_TEST_TARGET_ARCH ${arch}) + get_test_cflags_for_apple_platform( + "${TSAN_TEST_APPLE_PLATFORM}" + "${TSAN_TEST_TARGET_ARCH}" + TSAN_TEST_TARGET_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") + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py + ) + add_lit_testsuite(check-tsan-iossim-${arch} "ThreadSanitizer iOS Simulator ${arch} tests" + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ + DEPENDS ${TSAN_TEST_DEPS}) + endforeach() - 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_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}") - string(TOUPPER ${arch} ARCH_UPPER_CASE) - set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config") - configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in - ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py - ) - add_lit_testsuite(check-tsan-ios-${arch} "ThreadSanitizer iOS Simulator ${arch} tests" - ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ - DEPENDS ${TSAN_TEST_DEPS}) + list_intersect(TSAN_TEST_IOS_ARCHS TSAN_SUPPORTED_ARCH DARWIN_ios_ARCHS) + foreach(arch ${TSAN_TEST_IOS_ARCHS}) + set(TSAN_TEST_APPLE_PLATFORM "ios") + set(TSAN_TEST_TARGET_ARCH ${arch}) + get_test_cflags_for_apple_platform( + "${TSAN_TEST_APPLE_PLATFORM}" + "${TSAN_TEST_TARGET_ARCH}" + TSAN_TEST_TARGET_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") + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py + ) + add_lit_testsuite(check-tsan-ios-${arch} "ThreadSanitizer iOS ${arch} tests" + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ + DEPENDS ${TSAN_TEST_DEPS}) + endforeach() set(EXCLUDE_FROM_ALL OFF) endif() diff --git a/compiler-rt/test/ubsan/CMakeLists.txt b/compiler-rt/test/ubsan/CMakeLists.txt index ee7032a915e9..9f30718dd1cd 100644 --- a/compiler-rt/test/ubsan/CMakeLists.txt +++ b/compiler-rt/test/ubsan/CMakeLists.txt @@ -101,22 +101,20 @@ if(APPLE) # variable to select which iOS device or simulator to use, e.g.: # SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6" set(EXCLUDE_FROM_ALL ON) - set(UBSAN_APPLE_PLATFORMS "") - if (COMPILER_RT_ENABLE_IOS) - list(APPEND UBSAN_APPLE_PLATFORMS ios iossim) - endif() - if (COMPILER_RT_ENABLE_WATCHOS) - list(APPEND UBSAN_APPLE_PLATFORMS watchos watchossim) - endif() - if (COMPILER_RT_ENABLE_TVOS) - list(APPEND UBSAN_APPLE_PLATFORMS tvos tvossim) - endif() + set(UBSAN_APPLE_PLATFORMS ${SANITIZER_COMMON_SUPPORTED_OS}) foreach(platform ${UBSAN_APPLE_PLATFORMS}) - foreach(arch ${DARWIN_${platform}_ARCHS}) - set(UBSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_${platform}_SYSROOT}") - if (";${UBSAN_SUPPORTED_ARCH};" MATCHES ";${arch};") - add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch}) - endif() + list_intersect( + UBSAN_TEST_${platform}_ARCHS + UBSAN_SUPPORTED_ARCH + DARWIN_${platform}_ARCHS + ) + foreach(arch ${UBSAN_TEST_${platform}_ARCHS}) + get_test_cflags_for_apple_platform( + "${platform}" + "${arch}" + UBSAN_TEST_TARGET_CFLAGS + ) + add_ubsan_device_testsuite("Standalone" ubsan ${platform} ${arch}) if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};") add_ubsan_device_testsuite("AddressSanitizer" asan ${platform} ${arch})