[GWP-ASan] Remove c++ standard lib dependency.

Remove c++ standard library dependency for now for @phosek. They have a
complicated build system that breaks with the fuzzer target here.

Also added a todo to remedy later.

Differential Revision: https://reviews.llvm.org/D66568

llvm-svn: 369606
This commit is contained in:
Petr Hosek 2019-08-22 00:22:56 +00:00
parent 0202c3596c
commit 3dd2258519
2 changed files with 17 additions and 17 deletions

View File

@ -108,8 +108,11 @@ if (COMPILER_RT_HAS_GWP_ASAN)
${GWP_ASAN_HEADERS}) ${GWP_ASAN_HEADERS})
set_target_properties( set_target_properties(
stack_trace_compressor_fuzzer PROPERTIES FOLDER "Fuzzers") stack_trace_compressor_fuzzer PROPERTIES FOLDER "Fuzzers")
target_compile_options(
stack_trace_compressor_fuzzer PRIVATE -fsanitize=fuzzer-no-link) # TODO(phosek): Remove -nostdlib++ and remove the "no c++ standard library
# for compiler-rt" dependency here.
target_compile_options(stack_trace_compressor_fuzzer
PRIVATE -nostdlib++ -fsanitize=fuzzer-no-link)
set_target_properties( set_target_properties(
stack_trace_compressor_fuzzer PROPERTIES LINK_FLAGS -fsanitize=fuzzer) stack_trace_compressor_fuzzer PROPERTIES LINK_FLAGS -fsanitize=fuzzer)
add_dependencies(stack_trace_compressor_fuzzer fuzzer) add_dependencies(stack_trace_compressor_fuzzer fuzzer)

View File

@ -1,8 +1,7 @@
#include <cstddef> #include <stddef.h>
#include <cstdint> #include <stdint.h>
#include <cstdio> #include <stdio.h>
#include <cstdlib> #include <stdlib.h>
#include <vector>
#include "gwp_asan/stack_trace_compressor.h" #include "gwp_asan/stack_trace_compressor.h"
@ -10,23 +9,22 @@ constexpr size_t kBytesForLargestVarInt = (sizeof(uintptr_t) * 8) / 7 + 1;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
size_t BufferSize = kBytesForLargestVarInt * Size / sizeof(uintptr_t); size_t BufferSize = kBytesForLargestVarInt * Size / sizeof(uintptr_t);
std::vector<uint8_t> Buffer(BufferSize); uint8_t *Buffer = reinterpret_cast<uint8_t *>(malloc(BufferSize));
std::vector<uint8_t> Buffer2(BufferSize); uint8_t *Buffer2 = reinterpret_cast<uint8_t *>(malloc(BufferSize));
// Unpack the fuzz bytes. // Unpack the fuzz bytes.
gwp_asan::compression::unpack(Data, Size, gwp_asan::compression::unpack(Data, Size,
reinterpret_cast<uintptr_t *>(Buffer2.data()), reinterpret_cast<uintptr_t *>(Buffer2),
BufferSize / sizeof(uintptr_t)); BufferSize / sizeof(uintptr_t));
// Pack the fuzz bytes. // Pack the fuzz bytes.
size_t BytesWritten = gwp_asan::compression::pack( size_t BytesWritten =
reinterpret_cast<const uintptr_t *>(Data), Size / sizeof(uintptr_t), gwp_asan::compression::pack(reinterpret_cast<const uintptr_t *>(Data),
Buffer.data(), BufferSize); Size / sizeof(uintptr_t), Buffer, BufferSize);
// Unpack the compressed buffer. // Unpack the compressed buffer.
size_t DecodedElements = gwp_asan::compression::unpack( size_t DecodedElements = gwp_asan::compression::unpack(
Buffer.data(), BytesWritten, Buffer, BytesWritten, reinterpret_cast<uintptr_t *>(Buffer2),
reinterpret_cast<uintptr_t *>(Buffer2.data()),
BufferSize / sizeof(uintptr_t)); BufferSize / sizeof(uintptr_t));
// Ensure that every element was encoded and decoded properly. // Ensure that every element was encoded and decoded properly.
@ -35,8 +33,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
// Ensure that the compression and uncompression resulted in the same trace. // Ensure that the compression and uncompression resulted in the same trace.
const uintptr_t *FuzzPtrs = reinterpret_cast<const uintptr_t *>(Data); const uintptr_t *FuzzPtrs = reinterpret_cast<const uintptr_t *>(Data);
const uintptr_t *DecodedPtrs = const uintptr_t *DecodedPtrs = reinterpret_cast<const uintptr_t *>(Buffer2);
reinterpret_cast<const uintptr_t *>(Buffer2.data());
for (size_t i = 0; i < Size / sizeof(uintptr_t); ++i) { for (size_t i = 0; i < Size / sizeof(uintptr_t); ++i) {
if (FuzzPtrs[i] != DecodedPtrs[i]) { if (FuzzPtrs[i] != DecodedPtrs[i]) {
fprintf(stderr, "FuzzPtrs[%zu] != DecodedPtrs[%zu] (0x%zx vs. 0x%zx)", i, fprintf(stderr, "FuzzPtrs[%zu] != DecodedPtrs[%zu] (0x%zx vs. 0x%zx)", i,