diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:52:22 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:52:22 +0000 |
commit | 3a1720af1d7f43edc5b214cde0be11bfb94d077e (patch) | |
tree | 029e0ff2d5e3c0eaf2405fd8e669555fdf5e1297 /tools | |
parent | 8f3cadc28cb2bb9e8f9d69eeaaea1f57f2f7b2ab (diff) | |
download | src-vendor/compiler-rt.tar.gz src-vendor/compiler-rt.zip |
Vendor import of stripped compiler-rt trunk r375505, the last commitvendor/compiler-rt/compiler-rt-trunk-r375505vendor/compiler-rt
before the upstream Subversion repository was made read-only, and the
LLVM project migrated to GitHub:
https://llvm.org/svn/llvm-project/compiler-rt/trunk@375505
Notes
Notes:
svn path=/vendor/compiler-rt/dist/; revision=353944
svn path=/vendor/compiler-rt/compiler-rt-r375505/; revision=353945; tag=vendor/compiler-rt/compiler-rt-trunk-r375505
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/gwp_asan/CMakeLists.txt | 20 | ||||
-rw-r--r-- | tools/gwp_asan/stack_trace_compressor_fuzzer.cpp | 49 |
3 files changed, 70 insertions, 0 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000000..aa4aff34b1bb --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(gwp_asan) diff --git a/tools/gwp_asan/CMakeLists.txt b/tools/gwp_asan/CMakeLists.txt new file mode 100644 index 000000000000..b0f9f0cf9e5d --- /dev/null +++ b/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/tools/gwp_asan/stack_trace_compressor_fuzzer.cpp b/tools/gwp_asan/stack_trace_compressor_fuzzer.cpp new file mode 100644 index 000000000000..aa57fdaff636 --- /dev/null +++ b/tools/gwp_asan/stack_trace_compressor_fuzzer.cpp @@ -0,0 +1,49 @@ +#include <cstddef> +#include <cstdint> +#include <cstdio> +#include <cstdlib> +#include <vector> + +#include "gwp_asan/stack_trace_compressor.h" + +constexpr size_t kBytesForLargestVarInt = (sizeof(uintptr_t) * 8) / 7 + 1; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + size_t BufferSize = kBytesForLargestVarInt * Size / sizeof(uintptr_t); + std::vector<uint8_t> Buffer(BufferSize); + std::vector<uint8_t> Buffer2(BufferSize); + + // Unpack the fuzz bytes. + gwp_asan::compression::unpack(Data, Size, + reinterpret_cast<uintptr_t *>(Buffer2.data()), + BufferSize / sizeof(uintptr_t)); + + // Pack the fuzz bytes. + size_t BytesWritten = gwp_asan::compression::pack( + reinterpret_cast<const uintptr_t *>(Data), Size / sizeof(uintptr_t), + Buffer.data(), BufferSize); + + // Unpack the compressed buffer. + size_t DecodedElements = gwp_asan::compression::unpack( + Buffer.data(), BytesWritten, + reinterpret_cast<uintptr_t *>(Buffer2.data()), + BufferSize / sizeof(uintptr_t)); + + // Ensure that every element was encoded and decoded properly. + if (DecodedElements != Size / sizeof(uintptr_t)) + abort(); + + // Ensure that the compression and uncompression resulted in the same trace. + const uintptr_t *FuzzPtrs = reinterpret_cast<const uintptr_t *>(Data); + const uintptr_t *DecodedPtrs = + reinterpret_cast<const uintptr_t *>(Buffer2.data()); + for (size_t i = 0; i < Size / sizeof(uintptr_t); ++i) { + if (FuzzPtrs[i] != DecodedPtrs[i]) { + fprintf(stderr, "FuzzPtrs[%zu] != DecodedPtrs[%zu] (0x%zx vs. 0x%zx)", i, + i, FuzzPtrs[i], DecodedPtrs[i]); + abort(); + } + } + + return 0; +} |