From 50a1c697127749eec567d14819d549b63af1242f Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Tue, 29 Jan 2019 23:37:20 +0000 Subject: [PATCH] [libFuzzer] remove deprecated support for -fsanitize-coverage=trace-pc[-guard] llvm-svn: 352564 --- compiler-rt/lib/fuzzer/FuzzerTracePC.cpp | 21 ++++++++++-------- .../fuzzer/deprecated-instrumentation.test | 4 ++++ compiler-rt/test/fuzzer/dump_coverage.test | 22 ------------------- compiler-rt/test/fuzzer/trace-pc.test | 3 --- 4 files changed, 16 insertions(+), 34 deletions(-) create mode 100644 compiler-rt/test/fuzzer/deprecated-instrumentation.test delete mode 100644 compiler-rt/test/fuzzer/dump_coverage.test delete mode 100644 compiler-rt/test/fuzzer/trace-pc.test diff --git a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp index b6b11f085792..695eee2fa93e 100644 --- a/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerTracePC.cpp @@ -416,16 +416,20 @@ uintptr_t TracePC::GetMaxStackOffset() const { return InitialStack - __sancov_lowest_stack; // Stack grows down } +void WarnAboutDeprecatedInstrumentation(const char *flag) { + Printf("libFuzzer does not support %s any more.\n" + "Please either migrate to a compiler that supports -fsanitize=fuzzer\n" + "or use an older version of libFuzzer\n", flag); + exit(1); +} + } // namespace fuzzer extern "C" { ATTRIBUTE_INTERFACE ATTRIBUTE_NO_SANITIZE_ALL void __sanitizer_cov_trace_pc_guard(uint32_t *Guard) { - uintptr_t PC = reinterpret_cast(GET_CALLER_PC()); - uint32_t Idx = *Guard; - __sancov_trace_pc_pcs[Idx] = PC; - __sancov_trace_pc_guard_8bit_counters[Idx]++; + fuzzer::WarnAboutDeprecatedInstrumentation("-fsanitize-coverage=trace-pc"); } // Best-effort support for -fsanitize-coverage=trace-pc, which is available @@ -433,15 +437,14 @@ void __sanitizer_cov_trace_pc_guard(uint32_t *Guard) { ATTRIBUTE_INTERFACE ATTRIBUTE_NO_SANITIZE_ALL void __sanitizer_cov_trace_pc() { - uintptr_t PC = reinterpret_cast(GET_CALLER_PC()); - uintptr_t Idx = PC & (((uintptr_t)1 << fuzzer::TracePC::kTracePcBits) - 1); - __sancov_trace_pc_pcs[Idx] = PC; - __sancov_trace_pc_guard_8bit_counters[Idx]++; + fuzzer::WarnAboutDeprecatedInstrumentation( + "-fsanitize-coverage=trace-pc-guard"); } ATTRIBUTE_INTERFACE void __sanitizer_cov_trace_pc_guard_init(uint32_t *Start, uint32_t *Stop) { - fuzzer::TPC.HandleInit(Start, Stop); + fuzzer::WarnAboutDeprecatedInstrumentation( + "-fsanitize-coverage=trace-pc-guard"); } ATTRIBUTE_INTERFACE diff --git a/compiler-rt/test/fuzzer/deprecated-instrumentation.test b/compiler-rt/test/fuzzer/deprecated-instrumentation.test new file mode 100644 index 000000000000..7192aba556ae --- /dev/null +++ b/compiler-rt/test/fuzzer/deprecated-instrumentation.test @@ -0,0 +1,4 @@ +CHECK: libFuzzer does not support -fsanitize-coverage=trace-pc +RUN: %cpp_compiler %S/SimpleTest.cpp -c -o %t-SimpleTest.o -fsanitize-coverage=trace-pc +RUN: %cpp_compiler %t-SimpleTest.o -o %t-SimpleTest +RUN: not %run %t-SimpleTest 2>&1 | FileCheck %s diff --git a/compiler-rt/test/fuzzer/dump_coverage.test b/compiler-rt/test/fuzzer/dump_coverage.test deleted file mode 100644 index 803a4fbb8a05..000000000000 --- a/compiler-rt/test/fuzzer/dump_coverage.test +++ /dev/null @@ -1,22 +0,0 @@ -# FIXME: Disabled on Windows because -fPIC cannot be used to compile for Windows. -UNSUPPORTED: freebsd, windows -RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSO1.cpp -fPIC -shared -o %dynamiclib1 %ld_flags_rpath_so1 -RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSO2.cpp -fPIC -shared -o %dynamiclib2 %ld_flags_rpath_so2 -RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/DSOTestMain.cpp %S/DSOTestExtra.cpp %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t-DSOTest - -RUN: %cpp_compiler -fsanitize-coverage=0 -fsanitize-coverage=trace-pc-guard %S/NullDerefTest.cpp -o %t-NullDerefTest - -RUN: rm -rf %t_workdir && mkdir -p %t_workdir -RUN: env ASAN_OPTIONS=coverage_dir='"%t_workdir"' not %run %t-NullDerefTest -dump_coverage=1 2>&1 | FileCheck %s -RUN: sancov -covered-functions %t-NullDerefTest %t_workdir/*.sancov | FileCheck %s --check-prefix=SANCOV -RUN: env ASAN_OPTIONS=coverage_dir='"%t_workdir"' %run %t-DSOTest -dump_coverage=1 -runs=0 2>&1 | FileCheck -allow-deprecated-dag-overlap %s --check-prefix=DSO -RUN: env ASAN_OPTIONS=coverage_dir='"%t_workdir"' not %run %t-NullDerefTest -dump_coverage=0 2>&1 | FileCheck %s --check-prefix=NOCOV - -CHECK: SanitizerCoverage: {{.*}}NullDerefTest.{{.*}}.sancov: {{.*}} PCs written -SANCOV: LLVMFuzzerTestOneInput - -DSO: SanitizerCoverage: {{.*}}DSOTest.{{.*}}.sancov: {{.*}} PCs written -DSO-DAG: SanitizerCoverage: {{.*}}.{{.*}}.sancov: {{.*}} PCs written -DSO-DAG: SanitizerCoverage: {{.*}}2.{{.*}}.sancov: {{.*}} PCs written - -NOCOV-NOT: SanitizerCoverage: {{.*}} PCs written diff --git a/compiler-rt/test/fuzzer/trace-pc.test b/compiler-rt/test/fuzzer/trace-pc.test deleted file mode 100644 index 30049331e360..000000000000 --- a/compiler-rt/test/fuzzer/trace-pc.test +++ /dev/null @@ -1,3 +0,0 @@ -RUN: %cpp_compiler %S/SimpleTest.cpp -fsanitize-coverage=0 -fsanitize-coverage=trace-pc -o %t-SimpleTest-TracePC -CHECK: BINGO -RUN: not %run %t-SimpleTest-TracePC -runs=1000000 -seed=1 2>&1 | FileCheck %s