From 9d9b470e69acfca321f005490cfba14fe5247229 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Wed, 22 Jan 2020 16:26:45 -0800 Subject: [PATCH] [CMake] Refactor iOS simulator/device test configuration generation code for LibFuzzer. Summary: In order to do this `FUZZER_SUPPORTED_OS` had to be pulled out of `lib/fuzzer/CMakeLists.txt` and into the main config so we can use it from the `test/fuzzer/CMakeList.txt`. `FUZZER_SUPPORTED_OS` currently has the same value of `SANITIZER_COMMON_SUPPORTED_OS` which preserves the existing behaviour but this allows us in the future to adjust the supported platforms independent of `SANITIZER_COMMON_SUPPORTED_OS`. This mirrors the other sanitizers. For non-Apple platforms `FUZZER_SUPPORTED_OS` is not defined and surprisingly this was the behaviour before this patch because `SANITIZER_COMMON_SUPPORTED_OS` was actually empty. This appears to not matter right now because the functions that take an `OS` as an argument seem to ignore it on non-Apple platforms. While this change tries to be NFC it is technically not because we now generate an iossim config whereas previously we didn't. This seems like the right thing to do because the build system was configured to compile LibFuzzer for iossim but previously we weren't generating a lit test config for it. The device/simulator testing configs don't run by default anyway so this shouldn't break testing. This change relies on the get_capitalized_apple_platform() function added in a previous commit. rdar://problem/58798733 Reviewers: kubamracek, yln Subscribers: mgorny, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D73243 --- compiler-rt/cmake/config-ix.cmake | 3 ++ compiler-rt/lib/fuzzer/CMakeLists.txt | 2 - compiler-rt/test/fuzzer/CMakeLists.txt | 56 +++++++++++++++----------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index c1d0f65854bc8..d9e4b497d20fb 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -359,6 +359,7 @@ if(APPLE) set(PROFILE_SUPPORTED_OS osx) set(TSAN_SUPPORTED_OS osx) set(XRAY_SUPPORTED_OS osx) + set(FUZZER_SUPPORTED_OS osx) # Note: In order to target x86_64h on OS X the minimum deployment target must # be 10.8 or higher. @@ -442,6 +443,7 @@ if(APPLE) list(APPEND SANITIZER_COMMON_SUPPORTED_OS ${platform}sim) list(APPEND PROFILE_SUPPORTED_OS ${platform}sim) list(APPEND TSAN_SUPPORTED_OS ${platform}sim) + list(APPEND FUZZER_SUPPORTED_OS ${platform}sim) endif() foreach(arch ${DARWIN_${platform}sim_ARCHS}) list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) @@ -471,6 +473,7 @@ if(APPLE) if(DARWIN_${platform}_TSAN_ARCHS) list(APPEND TSAN_SUPPORTED_OS ${platform}) endif() + list(APPEND FUZZER_SUPPORTED_OS ${platform}) endif() foreach(arch ${DARWIN_${platform}_ARCHS}) list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) diff --git a/compiler-rt/lib/fuzzer/CMakeLists.txt b/compiler-rt/lib/fuzzer/CMakeLists.txt index 80409f9f68937..b5be6b89452e9 100644 --- a/compiler-rt/lib/fuzzer/CMakeLists.txt +++ b/compiler-rt/lib/fuzzer/CMakeLists.txt @@ -82,8 +82,6 @@ else() endif() endif() -set(FUZZER_SUPPORTED_OS ${SANITIZER_COMMON_SUPPORTED_OS}) - add_compiler_rt_component(fuzzer) add_compiler_rt_object_libraries(RTfuzzer diff --git a/compiler-rt/test/fuzzer/CMakeLists.txt b/compiler-rt/test/fuzzer/CMakeLists.txt index 5618096173ade..2e6e859709be7 100644 --- a/compiler-rt/test/fuzzer/CMakeLists.txt +++ b/compiler-rt/test/fuzzer/CMakeLists.txt @@ -89,31 +89,39 @@ 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) - - 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}) - 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") - 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-fuzzer-ios-${arch} "libFuzzer iOS ${arch} tests" - ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ - DEPENDS ${LIBFUZZER_TEST_DEPS}) - + set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER}) + set(FUZZER_APPLE_PLATFORMS ${FUZZER_SUPPORTED_OS}) + foreach(platform ${FUZZER_APPLE_PLATFORMS}) + if ("${platform}" STREQUAL "osx") + # Skip macOS because it's handled by the code above that builds tests for the host machine. + continue() + endif() + list_intersect( + FUZZER_TEST_${platform}_ARCHS + FUZZER_SUPPORTED_ARCH + DARWIN_${platform}_ARCHS + ) + foreach(arch ${FUZZER_TEST_${platform}_ARCHS}) + get_test_cflags_for_apple_platform( + "${platform}" + "${arch}" + LIBFUZZER_TEST_FLAGS + ) + string(TOUPPER "${arch}" ARCH_UPPER_CASE) + get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED) + set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config") + set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${platform}") + set(LIBFUZZER_TEST_APPLE_PLATFORM "${platform}") + set(LIBFUZZER_TEST_TARGET_ARCH "${arch}") + 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-fuzzer-${platform}-${arch} "libFuzzer ${platform} ${arch} tests" + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ + DEPENDS ${LIBFUZZER_TEST_DEPS}) + endforeach() endforeach() - set(EXCLUDE_FROM_ALL OFF) endif()