[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
This commit is contained in:
Dan Liew 2020-01-22 16:26:45 -08:00
parent 06569361d0
commit 9d9b470e69
3 changed files with 35 additions and 26 deletions

View File

@ -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})

View File

@ -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

View File

@ -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()