Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Cherry picking changes from upstream compiler-rt which enable libFuzzer toolchain installation #12

Merged
merged 20 commits into from
Aug 29, 2017
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
68db78f
Prefer atos to llvm-symbolizer on Darwin
Jul 24, 2017
751af79
Splitting out test for Darwin for print-stack-trace:
Jul 24, 2017
6ee3b66
Add .pyc files to .gitignore to compiler-rt
Jul 24, 2017
c1647d9
[sanitizers] Sanitizer tests CMake clean up
Jul 27, 2017
39b1757
Revert "[sanitizers] Sanitizer tests CMake clean up"
Jul 27, 2017
162cb5b
[sanitizers] Sanitizer tests CMake clean up: try #2
Jul 28, 2017
9df31b0
[sanitizer tests CMake] Factor out CMake logic for compiling sanitize…
Jul 28, 2017
90de0a3
[sanitizers test CMake] further refactor testing CMake for tsan
Jul 28, 2017
e0580f0
[compiler-rt CMake] CMake refactoring: create directories in helper f…
Aug 15, 2017
75df44f
[compiler-rt CMake] NFC: Minor CMake refactoring.
Aug 15, 2017
a8b3139
[CMake compiler-rt] NFC: Minor CMake refactoring.
Aug 15, 2017
7595d00
[sanitizers CMake] NFC Refactor the logic for compiling and generatin…
Aug 15, 2017
2438506
Quickfix to the refactoring commit: typo in the link flags variable
Aug 15, 2017
a619405
Fix multi-architecture build for lib/xray.
Aug 21, 2017
6eb1ea2
[NFC CMake] Do not relink test targets every time in compiler-rt
Aug 21, 2017
6053f13
Move libFuzzer to compiler_rt.
Aug 21, 2017
46ef908
Remove check-fuzzer from check-all, as tests don't pass on some bots.
Aug 22, 2017
d051f77
[NFC] do not run linter on libFuzzer's tests.
Aug 22, 2017
78d2253
[libFuzzer] Move check for thread_local back into libFuzzer's CMake,
Aug 22, 2017
38c3efc
[libFuzzer] Fix libFuzzer flag propagation for standalone builds.
Aug 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -3,3 +3,4 @@ darwin_fat
clang_darwin
multi_arch
*.sw?
*.pyc
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -21,6 +21,12 @@ list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
)

if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CFG_RESOLVED_INTDIR "${CMAKE_CFG_INTDIR}/")
else()
set(CMAKE_CFG_RESOLVED_INTDIR "")
endif()

include(base-config-ix)
include(CompilerRTUtils)

@@ -30,6 +36,8 @@ option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
mark_as_advanced(COMPILER_RT_BUILD_XRAY)
option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)

set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOLEAN
"Build for a bare-metal target.")
83 changes: 65 additions & 18 deletions cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
@@ -202,10 +202,10 @@ function(add_compiler_rt_runtime name type)
set_target_properties(${libname} PROPERTIES
OUTPUT_NAME ${output_name_${libname}})
set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime")
if(LIB_LINK_LIBS)
target_link_libraries(${libname} ${LIB_LINK_LIBS})
endif()
if(${type} STREQUAL "SHARED")
if(LIB_LINK_LIBS)
target_link_libraries(${libname} ${LIB_LINK_LIBS})
endif()
if(WIN32 AND NOT CYGWIN AND NOT MINGW)
set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
@@ -287,24 +287,65 @@ if(MSVC)
list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations)
endif()

# Compile and register compiler-rt tests.
# generate_compiler_rt_tests(<output object files> <test_suite> <test_name>
# <test architecture>
# KIND <custom prefix>
# SUBDIR <subdirectory for testing binary>
# SOURCES <sources to compile>
# RUNTIME <tests runtime to link in>
# CFLAGS <compile-time flags>
# COMPILE_DEPS <compile-time dependencies>
# DEPS <dependencies>
# LINK_FLAGS <flags to use during linking>
# )
function(generate_compiler_rt_tests test_objects test_suite testname arch)
cmake_parse_arguments(TEST "" "KIND;RUNTIME;SUBDIR"
"SOURCES;COMPILE_DEPS;DEPS;CFLAGS;LINK_FLAGS" ${ARGN})

foreach(source ${TEST_SOURCES})
sanitizer_test_compile(
"${test_objects}" "${source}" "${arch}"
KIND ${TEST_KIND}
COMPILE_DEPS ${TEST_COMPILE_DEPS}
DEPS ${TEST_DEPS}
CFLAGS ${TEST_CFLAGS}
)
endforeach()

set(TEST_DEPS ${${test_objects}})

if(NOT "${TEST_RUNTIME}" STREQUAL "")
list(APPEND TEST_DEPS ${TEST_RUNTIME})
list(APPEND "${test_objects}" $<TARGET_FILE:${TEST_RUNTIME}>)
endif()

add_compiler_rt_test(${test_suite} "${testname}" "${arch}"
SUBDIR ${TEST_SUBDIR}
OBJECTS ${${test_objects}}
DEPS ${TEST_DEPS}
LINK_FLAGS ${TEST_LINK_FLAGS}
)
set("${test_objects}" "${${test_objects}}" PARENT_SCOPE)
endfunction()

# Link objects into a single executable with COMPILER_RT_TEST_COMPILER,
# using specified link flags. Make executable a part of provided
# test_suite.
# add_compiler_rt_test(<test_suite> <test_name>
# add_compiler_rt_test(<test_suite> <test_name> <arch>
# SUBDIR <subdirectory for binary>
# OBJECTS <object files>
# DEPS <deps (e.g. runtime libs)>
# LINK_FLAGS <link flags>)
macro(add_compiler_rt_test test_suite test_name)
function(add_compiler_rt_test test_suite test_name arch)
cmake_parse_arguments(TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
set(output_bin ${CMAKE_CURRENT_BINARY_DIR})
set(output_dir ${CMAKE_CURRENT_BINARY_DIR})
if(TEST_SUBDIR)
set(output_bin "${output_bin}/${TEST_SUBDIR}")
endif()
if(CMAKE_CONFIGURATION_TYPES)
set(output_bin "${output_bin}/${CMAKE_CFG_INTDIR}")
set(output_dir "${output_dir}/${TEST_SUBDIR}")
endif()
set(output_bin "${output_bin}/${test_name}")
set(output_dir "${output_dir}/${CMAKE_CFG_INTDIR}")
file(MAKE_DIRECTORY "${output_dir}")
set(output_bin "${output_dir}/${test_name}")
if(MSVC)
set(output_bin "${output_bin}.exe")
endif()
@@ -313,6 +354,10 @@ macro(add_compiler_rt_test test_suite test_name)
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND TEST_DEPS clang)
endif()

get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
list(APPEND TEST_LINK_FLAGS ${TARGET_LINK_FLAGS})

# If we're not on MSVC, include the linker flags from CMAKE but override them
# with the provided link flags. This ensures that flags which are required to
# link programs at all are included, but the changes needed for the test
@@ -323,16 +368,18 @@ macro(add_compiler_rt_test test_suite test_name)
set(TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}")
separate_arguments(TEST_LINK_FLAGS)
endif()
add_custom_target(${test_name}
COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS}
-o "${output_bin}"
add_custom_command(
OUTPUT "${output_bin}"
COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} -o "${output_bin}"
${TEST_LINK_FLAGS}
DEPENDS ${TEST_DEPS})
set_target_properties(${test_name} PROPERTIES FOLDER "Compiler-RT Tests")
DEPENDS ${TEST_DEPS}
)
add_custom_target(T${test_name} DEPENDS "${output_bin}")
set_target_properties(T${test_name} PROPERTIES FOLDER "Compiler-RT Tests")

# Make the test suite depend on the binary.
add_dependencies(${test_suite} ${test_name})
endmacro()
add_dependencies(${test_suite} T${test_name})
endfunction()

macro(add_compiler_rt_resource_file target_name file_name component)
set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
40 changes: 38 additions & 2 deletions cmake/Modules/CompilerRTCompile.cmake
Original file line number Diff line number Diff line change
@@ -24,12 +24,44 @@ function(translate_msvc_cflags out_flags msvc_flags)
set(${out_flags} "${clang_flags}" PARENT_SCOPE)
endfunction()

# Compile a sanitizer test with a freshly built clang
# for a given architecture, adding the result to the object list.
# - obj_list: output list of objects, populated by path
# of a generated object file.
# - source: source file of a test.
# - arch: architecture to compile for.
# sanitizer_test_compile(<obj_list> <source> <arch>
# KIND <custom namespace>
# COMPILE_DEPS <list of compile-time dependencies>
# DEPS <list of dependencies>
# CFLAGS <list of flags>
# )
function(sanitizer_test_compile obj_list source arch)
cmake_parse_arguments(TEST
"" "" "KIND;COMPILE_DEPS;DEPS;CFLAGS" ${ARGN})
get_filename_component(basename ${source} NAME)
set(output_obj
"${CMAKE_CFG_RESOLVED_INTDIR}${obj_list}.${basename}.${arch}${TEST_KIND}.o")

# Write out architecture-specific flags into TARGET_CFLAGS variable.
get_target_flags_for_arch(${arch} TARGET_CFLAGS)
set(COMPILE_DEPS ${TEST_COMPILE_DEPS})
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND COMPILE_DEPS ${TEST_DEPS})
endif()
clang_compile(${output_obj} ${source}
CFLAGS ${TEST_CFLAGS} ${TARGET_CFLAGS}
DEPS ${TEST_COMPILE_DEPS})
list(APPEND ${obj_list} ${output_obj})
set("${obj_list}" "${${obj_list}}" PARENT_SCOPE)
endfunction()

# Compile a source into an object file with COMPILER_RT_TEST_COMPILER using
# a provided compile flags and dependenices.
# clang_compile(<object> <source>
# CFLAGS <list of compile flags>
# DEPS <list of dependencies>)
macro(clang_compile object_file source)
function(clang_compile object_file source)
cmake_parse_arguments(SOURCE "" "" "CFLAGS;DEPS" ${ARGN})
get_filename_component(source_rpath ${source} REALPATH)
if(NOT COMPILER_RT_STANDALONE_BUILD)
@@ -39,6 +71,7 @@ macro(clang_compile object_file source)
list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx)
endif()
string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
string(REGEX MATCH "[.](m|mm)$" is_objc ${source_rpath})
if(is_cxx)
string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
else()
@@ -52,6 +85,9 @@ macro(clang_compile object_file source)
if (APPLE)
set(global_flags ${OSX_SYSROOT_FLAG} ${global_flags})
endif()
if (is_objc)
list(APPEND global_flags -ObjC)
endif()

# Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options
# which are not supported by Clang.
@@ -64,7 +100,7 @@ macro(clang_compile object_file source)
${source_rpath}
MAIN_DEPENDENCY ${source}
DEPENDS ${SOURCE_DEPS})
endmacro()
endfunction()

# On Darwin, there are no system-wide C++ headers and the just-built clang is
# therefore not able to compile C++ files unless they are copied/symlinked into
3 changes: 3 additions & 0 deletions cmake/base-config-ix.cmake
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
# runtime libraries.

include(CheckIncludeFile)
include(CheckCXXSourceCompiles)

check_include_file(unwind.h HAVE_UNWIND_H)

# Top level target used to build all compiler-rt libraries.
@@ -86,6 +88,7 @@ if(APPLE)
option(COMPILER_RT_ENABLE_IOS "Enable building for iOS" On)
option(COMPILER_RT_ENABLE_WATCHOS "Enable building for watchOS - Experimental" Off)
option(COMPILER_RT_ENABLE_TVOS "Enable building for tvOS - Experimental" Off)

else()
option(COMPILER_RT_DEFAULT_TARGET_ONLY "Build builtins only for the default target" Off)
endif()
15 changes: 14 additions & 1 deletion cmake/config-ix.cmake
Original file line number Diff line number Diff line change
@@ -164,6 +164,7 @@ set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64}
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
${MIPS32} ${MIPS64} ${PPC64} ${S390X})
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
set(ALL_FUZZER_SUPPORTED_ARCH x86_64)

if(APPLE)
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64})
@@ -383,7 +384,11 @@ if(APPLE)
SANITIZER_COMMON_SUPPORTED_ARCH)
list_intersect(XRAY_SUPPORTED_ARCH
ALL_XRAY_SUPPORTED_ARCH
SANITIZER_COMMON_SUPPORTED_ARCH)
SANITIZER_COMMON_SUPPORTED_ARCH)
list_intersect(FUZZER_SUPPORTED_ARCH
ALL_FUZZER_SUPPORTED_ARCH
ALL_SANITIZER_COMMON_SUPPORTED_ARCH)

else()
# Architectures supported by compiler-rt libraries.
filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
@@ -395,6 +400,7 @@ else()
filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH
${SANITIZER_COMMON_SUPPORTED_ARCH})
filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH})
filter_available_targets(FUZZER_SUPPORTED_ARCH ${ALL_FUZZER_SUPPORTED_ARCH})
filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH})
filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH})
filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_SUPPORTED_ARCH})
@@ -543,3 +549,10 @@ if (COMPILER_RT_HAS_SANITIZER_COMMON AND XRAY_SUPPORTED_ARCH AND
else()
set(COMPILER_RT_HAS_XRAY FALSE)
endif()

if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND
OS_NAME MATCHES "Darwin|Linux")
set(COMPILER_RT_HAS_FUZZER TRUE)
else()
set(COMPILER_RT_HAS_FUZZER FALSE)
endif()
4 changes: 4 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -46,3 +46,7 @@ endif()
if(COMPILER_RT_BUILD_XRAY)
compiler_rt_build_runtime(xray)
endif()

if(COMPILER_RT_BUILD_LIBFUZZER)
compiler_rt_build_runtime(fuzzer)
endif()
Loading