2017-08-22 07:25:50 +08:00
|
|
|
set(LIBFUZZER_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
|
|
|
|
if (NOT COMPILER_RT_STANDALONE_BUILD)
|
2018-07-17 03:41:49 +08:00
|
|
|
list(APPEND LIBFUZZER_TEST_DEPS fuzzer asan ubsan)
|
|
|
|
if (COMPILER_RT_HAS_MSAN)
|
|
|
|
list(APPEND LIBFUZZER_TEST_DEPS msan)
|
|
|
|
endif()
|
|
|
|
if (COMPILER_RT_HAS_DFSAN)
|
|
|
|
list(APPEND LIBFUZZER_TEST_DEPS dfsan)
|
|
|
|
endif()
|
2018-07-13 02:52:10 +08:00
|
|
|
if(NOT APPLE AND COMPILER_RT_HAS_LLD)
|
|
|
|
list(APPEND LIBFUZZER_TEST_DEPS lld)
|
|
|
|
endif()
|
2017-08-22 07:25:50 +08:00
|
|
|
endif()
|
|
|
|
|
2019-04-28 17:44:53 +08:00
|
|
|
set(FUZZER_TEST_ARCH ${FUZZER_SUPPORTED_ARCH})
|
2018-06-22 05:19:43 +08:00
|
|
|
if (APPLE)
|
2019-04-28 17:44:53 +08:00
|
|
|
darwin_filter_host_archs(FUZZER_SUPPORTED_ARCH FUZZER_TEST_ARCH)
|
2018-06-22 05:19:43 +08:00
|
|
|
endif()
|
|
|
|
|
2017-08-22 07:25:50 +08:00
|
|
|
if(COMPILER_RT_INCLUDE_TESTS)
|
|
|
|
list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
|
Add FuzzedDataProvider helper class / single header library.
Summary:
This class is useful for writing fuzz target that have multiple inputs.
Current CL imports the existing `FuzzedDataProvider` from Chromium
without any modifications. Feel free to review it thoroughly, if you're
interested, but I'd prefer changing the class in a follow up CL.
The CL also introduces an exhaustive test for the library, as the behavior
of `FuzzedDataProvider` must not change over time.
In follow up CLs I'm planning on changing some implementation details
(I can share a doc with some comments to be addressed). After that, we
will document how `FuzzedDataProvider` should be used.
I have tested this on Linux, Windows and Mac platforms.
Reviewers: morehouse, metzman, kcc
Reviewed By: morehouse
Subscribers: metzman, thakis, rnk, mgorny, ormris, delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D62733
llvm-svn: 363071
2019-06-11 22:30:18 +08:00
|
|
|
list(APPEND LIBFUZZER_TEST_DEPS FuzzedDataProviderUnitTests)
|
2017-08-22 07:25:50 +08:00
|
|
|
endif()
|
|
|
|
|
2018-01-18 04:39:14 +08:00
|
|
|
add_custom_target(check-fuzzer)
|
2017-08-22 07:25:50 +08:00
|
|
|
|
|
|
|
if(COMPILER_RT_INCLUDE_TESTS)
|
|
|
|
# libFuzzer unit tests.
|
|
|
|
configure_lit_site_cfg(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
|
2018-01-18 04:39:14 +08:00
|
|
|
add_lit_testsuite(check-fuzzer-unit "Running Fuzzer unit tests"
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/unit
|
|
|
|
DEPENDS ${LIBFUZZER_TEST_DEPS})
|
|
|
|
set_target_properties(check-fuzzer-unit PROPERTIES FOLDER "Compiler-RT Tests")
|
|
|
|
add_dependencies(check-fuzzer check-fuzzer-unit)
|
2017-08-22 07:25:50 +08:00
|
|
|
endif()
|
|
|
|
|
2018-01-18 04:39:14 +08:00
|
|
|
macro(test_fuzzer stdlib)
|
|
|
|
cmake_parse_arguments(TEST "" "" "DEPS" ${ARGN})
|
|
|
|
string(REPLACE "+" "x" stdlib_name ${stdlib})
|
|
|
|
string(REPLACE "-" ";" stdlib_list ${stdlib_name})
|
|
|
|
set(STDLIB_CAPITALIZED "")
|
|
|
|
foreach(part IN LISTS stdlib_list)
|
|
|
|
string(SUBSTRING ${part} 0 1 first_letter)
|
|
|
|
string(TOUPPER ${first_letter} first_letter)
|
|
|
|
string(REGEX REPLACE "^.(.*)" "${first_letter}\\1" part "${part}")
|
|
|
|
set(STDLIB_CAPITALIZED "${STDLIB_CAPITALIZED}${part}")
|
|
|
|
endforeach()
|
2019-04-28 17:44:53 +08:00
|
|
|
foreach(arch ${FUZZER_TEST_ARCH})
|
2018-01-18 04:39:14 +08:00
|
|
|
set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
|
|
|
|
get_test_cc_for_arch(${arch} LIBFUZZER_TEST_COMPILER LIBFUZZER_TEST_FLAGS)
|
2017-08-22 07:25:50 +08:00
|
|
|
|
2019-05-01 01:58:55 +08:00
|
|
|
set(LIBFUZZER_TEST_TARGET_ARCH ${arch})
|
2018-06-20 21:33:42 +08:00
|
|
|
set(LIBFUZZER_TEST_APPLE_PLATFORM "osx")
|
|
|
|
|
2018-01-18 04:39:14 +08:00
|
|
|
set(LIBFUZZER_TEST_STDLIB ${stdlib})
|
2017-08-22 07:25:50 +08:00
|
|
|
|
2018-01-18 04:39:14 +08:00
|
|
|
string(TOUPPER ${arch} ARCH_UPPER_CASE)
|
|
|
|
set(CONFIG_NAME ${ARCH_UPPER_CASE}${STDLIB_CAPITALIZED}${OS_NAME}Config)
|
2017-08-22 08:54:57 +08:00
|
|
|
|
2018-01-18 04:39:14 +08:00
|
|
|
# LIT-based libFuzzer tests.
|
|
|
|
configure_lit_site_cfg(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
|
|
|
|
)
|
2018-01-17 08:42:48 +08:00
|
|
|
|
2018-05-25 07:55:53 +08:00
|
|
|
add_lit_testsuite(check-fuzzer-${stdlib_name}-${arch}
|
2018-06-22 05:19:24 +08:00
|
|
|
"Running libFuzzer ${stdlib} tests for arch ${arch}"
|
2018-05-25 07:55:53 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
|
2018-01-18 04:39:14 +08:00
|
|
|
DEPENDS ${LIBFUZZER_TEST_DEPS})
|
|
|
|
if(TEST_DEPS)
|
2018-05-25 07:55:53 +08:00
|
|
|
add_dependencies(check-fuzzer-${stdlib_name}-${arch} ${TEST_DEPS})
|
2018-01-18 04:39:14 +08:00
|
|
|
endif()
|
2018-05-25 07:55:53 +08:00
|
|
|
set_target_properties(check-fuzzer-${stdlib_name}-${arch}
|
|
|
|
PROPERTIES FOLDER "Compiler-RT Tests")
|
|
|
|
add_dependencies(check-fuzzer check-fuzzer-${stdlib_name}-${arch})
|
2018-01-18 04:39:14 +08:00
|
|
|
endforeach()
|
|
|
|
endmacro()
|
2018-01-18 01:24:56 +08:00
|
|
|
|
2018-01-18 04:39:14 +08:00
|
|
|
test_fuzzer("default")
|
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
|
|
|
|
if(TARGET cxx_shared)
|
|
|
|
test_fuzzer("libc++" DEPS cxx_shared)
|
|
|
|
endif()
|
|
|
|
if(TARGET cxx_static)
|
|
|
|
test_fuzzer("static-libc++" DEPS cxx_static)
|
|
|
|
endif()
|
|
|
|
endif()
|
2018-06-15 04:46:07 +08:00
|
|
|
|
|
|
|
if (APPLE)
|
|
|
|
set(EXCLUDE_FROM_ALL ON)
|
|
|
|
|
Revert r363633 "[CMake] Fix the value of `config.target_cflags` for non-macOS Apple platforms. Attempt #2."
This caused Chromium's clang package to stop building, see comment on
https://reviews.llvm.org/D61242 for details.
> Summary:
> The main problem here is that `-*-version_min=` was not being passed to
> the compiler when building test cases. This can cause problems when
> testing on devices running older OSs because Clang would previously
> assume the minimum deployment target is the the latest OS in the SDK
> which could be much newer than what the device is running.
>
> Previously the generated value looked like this:
>
> `-arch arm64 -isysroot
> <path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk`
>
> With this change it now looks like:
>
> `-arch arm64 -stdlib=libc++ -miphoneos-version-min=8.0 -isysroot
> <path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk`
>
> This mirrors the setting of `config.target_cflags` on macOS.
>
> This change is made for ASan, LibFuzzer, TSan, and UBSan.
>
> To implement this a new `get_test_cflags_for_apple_platform()` function
> has been added that when given an Apple platform name and architecture
> returns a string containing the C compiler flags to use when building
> tests. This also calls a new helper function `is_valid_apple_platform()`
> that validates Apple platform names.
>
> This is the second attempt at landing the patch. The first attempt (r359305)
> had to be reverted (r359327) due to a buildbot failure. The problem was
> that calling `get_test_cflags_for_apple_platform()` can trigger a CMake
> error if the provided architecture is not supported by the current
> CMake configuration. Previously, this could be triggered by passing
> `-DCOMPILER_RT_ENABLE_IOS=OFF` to CMake. The root cause is that we were
> generating test configurations for a list of architectures without
> checking if the relevant Sanitizer actually supported that architecture.
> We now intersect the list of architectures for an Apple platform
> with `<SANITIZER>_SUPPORTED_ARCH` (where `<SANITIZER>` is a Sanitizer
> name) to iterate through the correct list of architectures.
>
> rdar://problem/50124489
>
> Reviewers: kubamracek, yln, vsk, juliehockett, phosek
>
> Subscribers: mgorny, javed.absar, kristof.beyls, #sanitizers, llvm-commits
>
> Tags: #llvm, #sanitizers
>
> Differential Revision: https://reviews.llvm.org/D61242
llvm-svn: 363779
2019-06-19 17:09:39 +08:00
|
|
|
foreach(arch ${DARWIN_ios_ARCHS})
|
2018-06-20 21:33:42 +08:00
|
|
|
set(LIBFUZZER_TEST_APPLE_PLATFORM "ios")
|
2018-06-15 04:46:07 +08:00
|
|
|
set(LIBFUZZER_TEST_TARGET_ARCH ${arch})
|
Revert r363633 "[CMake] Fix the value of `config.target_cflags` for non-macOS Apple platforms. Attempt #2."
This caused Chromium's clang package to stop building, see comment on
https://reviews.llvm.org/D61242 for details.
> Summary:
> The main problem here is that `-*-version_min=` was not being passed to
> the compiler when building test cases. This can cause problems when
> testing on devices running older OSs because Clang would previously
> assume the minimum deployment target is the the latest OS in the SDK
> which could be much newer than what the device is running.
>
> Previously the generated value looked like this:
>
> `-arch arm64 -isysroot
> <path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk`
>
> With this change it now looks like:
>
> `-arch arm64 -stdlib=libc++ -miphoneos-version-min=8.0 -isysroot
> <path_to_xcode>/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk`
>
> This mirrors the setting of `config.target_cflags` on macOS.
>
> This change is made for ASan, LibFuzzer, TSan, and UBSan.
>
> To implement this a new `get_test_cflags_for_apple_platform()` function
> has been added that when given an Apple platform name and architecture
> returns a string containing the C compiler flags to use when building
> tests. This also calls a new helper function `is_valid_apple_platform()`
> that validates Apple platform names.
>
> This is the second attempt at landing the patch. The first attempt (r359305)
> had to be reverted (r359327) due to a buildbot failure. The problem was
> that calling `get_test_cflags_for_apple_platform()` can trigger a CMake
> error if the provided architecture is not supported by the current
> CMake configuration. Previously, this could be triggered by passing
> `-DCOMPILER_RT_ENABLE_IOS=OFF` to CMake. The root cause is that we were
> generating test configurations for a list of architectures without
> checking if the relevant Sanitizer actually supported that architecture.
> We now intersect the list of architectures for an Apple platform
> with `<SANITIZER>_SUPPORTED_ARCH` (where `<SANITIZER>` is a Sanitizer
> name) to iterate through the correct list of architectures.
>
> rdar://problem/50124489
>
> Reviewers: kubamracek, yln, vsk, juliehockett, phosek
>
> Subscribers: mgorny, javed.absar, kristof.beyls, #sanitizers, llvm-commits
>
> Tags: #llvm, #sanitizers
>
> Differential Revision: https://reviews.llvm.org/D61242
llvm-svn: 363779
2019-06-19 17:09:39 +08:00
|
|
|
set(LIBFUZZER_TEST_FLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
|
2018-06-20 21:33:42 +08:00
|
|
|
set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${LIBFUZZER_TEST_APPLE_PLATFORM}")
|
2018-06-15 04:46:07 +08:00
|
|
|
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.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
|
|
|
|
)
|
|
|
|
add_lit_testsuite(check-fuzzer-ios-${arch} "libFuzzer iOS ${arch} tests"
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
|
|
|
|
DEPENDS ${LIBFUZZER_TEST_DEPS})
|
|
|
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set(EXCLUDE_FROM_ALL OFF)
|
|
|
|
endif()
|