From ae56e593b90c61eda160d03398e953cc5c6037b3 Mon Sep 17 00:00:00 2001 From: Mitch Phillips Date: Tue, 27 Aug 2019 18:28:07 +0000 Subject: [PATCH] Add GWP-ASan fuzz target to compiler-rt/tools. Summary: @eugenis to approve addition of //compiler-rt/tools. @pree-jackie please confirm that this WFY. D66494 introduced the GWP-ASan stack_trace_compressor_fuzzer. Building fuzz targets in compiler-rt is a new affair, and has some challenges: - If the host compiler doesn't have compiler-rt, the -fsanitize=fuzzer may not be able to link against `libclang_rt.fuzzer*`. - Things in compiler-rt generally aren't built when you want to build with sanitizers using `-DLLVM_USE_SANITIZER`. This tricky to work around, so we create the new tools directory so that we can build fuzz targets with sanitizers. This has the added bonus of fixing the problem above as well, as we can now just guard the fuzz target build to only be done with `-DLLVM_USE_SANITIZE_COVERAGE=On`. Reviewers: eugenis, pree-jackie Reviewed By: eugenis, pree-jackie Subscribers: dberris, mgorny, #sanitizers, llvm-commits, eugenis, pree-jackie, lebedev.ri, vitalybuka, morehouse Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D66776 llvm-svn: 370094 --- compiler-rt/CMakeLists.txt | 2 ++ compiler-rt/lib/gwp_asan/CMakeLists.txt | 23 ------------------- compiler-rt/tools/CMakeLists.txt | 1 + compiler-rt/tools/gwp_asan/CMakeLists.txt | 20 ++++++++++++++++ .../stack_trace_compressor_fuzzer.cpp | 0 5 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 compiler-rt/tools/CMakeLists.txt create mode 100644 compiler-rt/tools/gwp_asan/CMakeLists.txt rename compiler-rt/{lib => tools}/gwp_asan/stack_trace_compressor_fuzzer.cpp (100%) diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index bf419a633e4..d28fd20d581 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -513,3 +513,5 @@ if(COMPILER_RT_INCLUDE_TESTS) endif() endif() endif() + +add_subdirectory(tools) diff --git a/compiler-rt/lib/gwp_asan/CMakeLists.txt b/compiler-rt/lib/gwp_asan/CMakeLists.txt index 552a447ea1b..84839e63f8e 100644 --- a/compiler-rt/lib/gwp_asan/CMakeLists.txt +++ b/compiler-rt/lib/gwp_asan/CMakeLists.txt @@ -98,29 +98,6 @@ if (COMPILER_RT_HAS_GWP_ASAN) SOURCES optional/backtrace_sanitizer_common.cpp ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} CFLAGS ${GWP_ASAN_CFLAGS} ${SANITIZER_COMMON_CFLAGS}) - - # Build the stack trace compressor fuzzer. Note that clang versions 4.* did - # not have -fsanitize=fuzzer, and Clang versions 5.* didn't have - # -fsanitize=fuzzer-no-link. In general, the way we build fuzz targets in LLVM - # core is to link it against a dummy main when DLLVM_USE_SANITIZE_COVERAGE - # isn't specified. Instead, here we only build fuzz targets if clang version - # is >= 6.0. - if (COMPILER_RT_BUILD_LIBFUZZER AND - "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND - NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) - add_executable(stack_trace_compressor_fuzzer - stack_trace_compressor_fuzzer.cpp - ${GWP_ASAN_SOURCES} - ${GWP_ASAN_HEADERS}) - set_target_properties( - stack_trace_compressor_fuzzer PROPERTIES FOLDER "Fuzzers") - target_compile_options( - stack_trace_compressor_fuzzer PRIVATE -fsanitize=fuzzer-no-link) - set_target_properties( - stack_trace_compressor_fuzzer PROPERTIES LINK_FLAGS -fsanitize=fuzzer) - add_dependencies(stack_trace_compressor_fuzzer fuzzer) - add_dependencies(gwp_asan stack_trace_compressor_fuzzer) - endif() endif() if(COMPILER_RT_INCLUDE_TESTS) diff --git a/compiler-rt/tools/CMakeLists.txt b/compiler-rt/tools/CMakeLists.txt new file mode 100644 index 00000000000..aa4aff34b1b --- /dev/null +++ b/compiler-rt/tools/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(gwp_asan) diff --git a/compiler-rt/tools/gwp_asan/CMakeLists.txt b/compiler-rt/tools/gwp_asan/CMakeLists.txt new file mode 100644 index 00000000000..b0f9f0cf9e5 --- /dev/null +++ b/compiler-rt/tools/gwp_asan/CMakeLists.txt @@ -0,0 +1,20 @@ +# Build the stack trace compressor fuzzer. This will require Clang >= 6.0.0, as +# -fsanitize=fuzzer-no-link was not a valid command line flag prior to this. +if (LLVM_USE_SANITIZE_COVERAGE) + add_executable(stack_trace_compressor_fuzzer + ../../lib/gwp_asan/stack_trace_compressor.cpp + ../../lib/gwp_asan/stack_trace_compressor.h + stack_trace_compressor_fuzzer.cpp) + set_target_properties( + stack_trace_compressor_fuzzer PROPERTIES FOLDER "Fuzzers") + target_compile_options( + stack_trace_compressor_fuzzer PRIVATE -fsanitize=fuzzer-no-link) + set_target_properties( + stack_trace_compressor_fuzzer PROPERTIES LINK_FLAGS -fsanitize=fuzzer) + target_include_directories( + stack_trace_compressor_fuzzer PRIVATE ../../lib/) + + if (TARGET gwp_asan) + add_dependencies(gwp_asan stack_trace_compressor_fuzzer) + endif() +endif() diff --git a/compiler-rt/lib/gwp_asan/stack_trace_compressor_fuzzer.cpp b/compiler-rt/tools/gwp_asan/stack_trace_compressor_fuzzer.cpp similarity index 100% rename from compiler-rt/lib/gwp_asan/stack_trace_compressor_fuzzer.cpp rename to compiler-rt/tools/gwp_asan/stack_trace_compressor_fuzzer.cpp