2017-08-22 07:25:50 +08:00
|
|
|
set(LIBFUZZER_SOURCES
|
|
|
|
FuzzerCrossOver.cpp
|
|
|
|
FuzzerDriver.cpp
|
|
|
|
FuzzerExtFunctionsDlsym.cpp
|
|
|
|
FuzzerExtFunctionsDlsymWin.cpp
|
|
|
|
FuzzerExtFunctionsWeak.cpp
|
|
|
|
FuzzerExtraCounters.cpp
|
|
|
|
FuzzerIO.cpp
|
|
|
|
FuzzerIOPosix.cpp
|
|
|
|
FuzzerIOWindows.cpp
|
|
|
|
FuzzerLoop.cpp
|
|
|
|
FuzzerMerge.cpp
|
|
|
|
FuzzerMutate.cpp
|
|
|
|
FuzzerSHA1.cpp
|
2018-03-17 06:40:55 +08:00
|
|
|
FuzzerShmemFuchsia.cpp
|
2017-08-22 07:25:50 +08:00
|
|
|
FuzzerShmemPosix.cpp
|
|
|
|
FuzzerShmemWindows.cpp
|
|
|
|
FuzzerTracePC.cpp
|
|
|
|
FuzzerUtil.cpp
|
|
|
|
FuzzerUtilDarwin.cpp
|
[libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.
- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
FuzzerIO.h are implemented by extending the header guards in
FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
the launchpad library.
- The experimental equivalence server is not currently supported, so
FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
Any future implementation will likely involve VMOs.
Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.
Patch By: aarongreen
Reviewers: kcc, morehouse, flowerhack, phosek
Reviewed By: kcc, phosek, Eugene.Zelenko
Subscribers: srhines, mgorny, Eugene.Zelenko
Differential Revision: https://reviews.llvm.org/D40974
llvm-svn: 320210
2017-12-09 06:54:44 +08:00
|
|
|
FuzzerUtilFuchsia.cpp
|
2017-08-22 07:25:50 +08:00
|
|
|
FuzzerUtilLinux.cpp
|
|
|
|
FuzzerUtilPosix.cpp
|
|
|
|
FuzzerUtilWindows.cpp
|
|
|
|
)
|
|
|
|
|
2017-08-23 02:34:28 +08:00
|
|
|
CHECK_CXX_SOURCE_COMPILES("
|
|
|
|
static thread_local int blah;
|
|
|
|
int main() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
" HAS_THREAD_LOCAL)
|
|
|
|
|
2017-08-29 03:44:19 +08:00
|
|
|
set(LIBFUZZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
|
|
|
|
|
2018-01-18 04:39:14 +08:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH)
|
2018-01-21 09:01:53 +08:00
|
|
|
list(APPEND LIBFUZZER_CFLAGS -nostdinc++ -D_LIBCPP_ABI_VERSION=Fuzzer)
|
2018-02-01 21:57:24 +08:00
|
|
|
# Remove -stdlib= which is unused when passing -nostdinc++.
|
|
|
|
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
2018-01-18 04:39:14 +08:00
|
|
|
endif()
|
|
|
|
|
2017-10-14 05:57:43 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer LIBFUZZER_CFLAGS)
|
|
|
|
|
2017-08-22 07:25:50 +08:00
|
|
|
if (CMAKE_CXX_FLAGS MATCHES "fsanitize-coverage")
|
2017-08-29 03:44:19 +08:00
|
|
|
list(APPEND LIBFUZZER_CFLAGS -fno-sanitize-coverage=trace-pc-guard,edge,trace-cmp,indirect-calls,8bit-counters)
|
2017-08-22 07:25:50 +08:00
|
|
|
endif()
|
2017-08-29 03:44:19 +08:00
|
|
|
|
2017-08-23 02:34:28 +08:00
|
|
|
if(NOT HAS_THREAD_LOCAL)
|
2017-08-29 03:44:19 +08:00
|
|
|
list(APPEND LIBFUZZER_CFLAGS -Dthread_local=__thread)
|
2017-08-23 02:34:28 +08:00
|
|
|
endif()
|
2017-08-22 07:25:50 +08:00
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
set(FUZZER_SUPPORTED_OS osx)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_compiler_rt_object_libraries(RTfuzzer
|
|
|
|
OS ${FUZZER_SUPPORTED_OS}
|
|
|
|
ARCHS ${FUZZER_SUPPORTED_ARCH}
|
|
|
|
SOURCES ${LIBFUZZER_SOURCES}
|
|
|
|
CFLAGS ${LIBFUZZER_CFLAGS})
|
|
|
|
|
|
|
|
add_compiler_rt_object_libraries(RTfuzzer_main
|
|
|
|
OS ${FUZZER_SUPPORTED_OS}
|
|
|
|
ARCHS ${FUZZER_SUPPORTED_ARCH}
|
|
|
|
SOURCES FuzzerMain.cpp
|
|
|
|
CFLAGS ${LIBFUZZER_CFLAGS})
|
|
|
|
|
|
|
|
add_compiler_rt_runtime(clang_rt.fuzzer
|
|
|
|
STATIC
|
|
|
|
OS ${FUZZER_SUPPORTED_OS}
|
|
|
|
ARCHS ${FUZZER_SUPPORTED_ARCH}
|
|
|
|
OBJECT_LIBS RTfuzzer RTfuzzer_main
|
|
|
|
CFLAGS ${LIBFUZZER_CFLAGS}
|
|
|
|
PARENT_TARGET fuzzer)
|
|
|
|
|
|
|
|
add_compiler_rt_runtime(clang_rt.fuzzer_no_main
|
|
|
|
STATIC
|
|
|
|
OS ${FUZZER_SUPPORTED_OS}
|
|
|
|
ARCHS ${FUZZER_SUPPORTED_ARCH}
|
|
|
|
OBJECT_LIBS RTfuzzer
|
|
|
|
CFLAGS ${LIBFUZZER_CFLAGS}
|
|
|
|
PARENT_TARGET fuzzer)
|
|
|
|
|
2018-01-18 04:39:14 +08:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH)
|
|
|
|
macro(partially_link_libcxx name dir arch)
|
|
|
|
set(cxx_${arch}_merge_dir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${arch}_merge.dir")
|
|
|
|
file(MAKE_DIRECTORY ${cxx_${arch}_merge_dir})
|
|
|
|
add_custom_command(TARGET clang_rt.${name}-${arch} POST_BUILD
|
2018-03-08 02:14:09 +08:00
|
|
|
COMMAND ${CMAKE_LINKER} --whole-archive "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>" --no-whole-archive ${dir}/lib/libc++.a -r -o ${name}.o
|
2018-01-18 04:39:14 +08:00
|
|
|
COMMAND ${CMAKE_OBJCOPY} --localize-hidden ${name}.o
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>"
|
|
|
|
COMMAND ${CMAKE_AR} qcs "$<TARGET_LINKER_FILE:clang_rt.${name}-${arch}>" ${name}.o
|
|
|
|
WORKING_DIRECTORY ${cxx_${arch}_merge_dir}
|
|
|
|
)
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
foreach(arch ${FUZZER_SUPPORTED_ARCH})
|
|
|
|
get_target_flags_for_arch(${arch} TARGET_CFLAGS)
|
|
|
|
set(LIBCXX_${arch}_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_fuzzer_${arch})
|
|
|
|
add_custom_libcxx(libcxx_fuzzer_${arch} ${LIBCXX_${arch}_PREFIX}
|
|
|
|
CFLAGS ${TARGET_CFLAGS}
|
2018-01-21 09:01:53 +08:00
|
|
|
-D_LIBCPP_ABI_VERSION=Fuzzer
|
2018-01-18 04:39:14 +08:00
|
|
|
-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=1
|
|
|
|
-fvisibility=hidden
|
2018-04-14 07:05:14 +08:00
|
|
|
CMAKE_ARGS -DCMAKE_CXX_COMPILER_WORKS=ON
|
|
|
|
-DLIBCXX_ENABLE_EXCEPTIONS=OFF
|
2018-01-20 17:21:00 +08:00
|
|
|
-DLIBCXX_CXX_ABI=none)
|
2018-03-08 02:14:09 +08:00
|
|
|
target_compile_options(RTfuzzer.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
|
2018-01-21 09:01:53 +08:00
|
|
|
add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch}-build)
|
2018-03-08 02:14:09 +08:00
|
|
|
target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
|
2018-01-21 09:01:53 +08:00
|
|
|
add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch}-build)
|
2018-01-18 04:39:14 +08:00
|
|
|
partially_link_libcxx(fuzzer_no_main ${LIBCXX_${arch}_PREFIX} ${arch})
|
|
|
|
partially_link_libcxx(fuzzer ${LIBCXX_${arch}_PREFIX} ${arch})
|
|
|
|
endforeach()
|
2018-03-10 10:00:18 +08:00
|
|
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia" AND HAVE_LIBCXX)
|
|
|
|
foreach(arch ${FUZZER_SUPPORTED_ARCH})
|
|
|
|
add_dependencies(RTfuzzer.${arch} cxx)
|
|
|
|
add_dependencies(RTfuzzer_main.${arch} cxx)
|
|
|
|
endforeach()
|
2018-01-18 04:39:14 +08:00
|
|
|
endif()
|
|
|
|
|
2017-08-22 07:25:50 +08:00
|
|
|
if(COMPILER_RT_INCLUDE_TESTS)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|