From: Kostya Serebryany Date: Tue, 28 Feb 2017 23:23:48 +0000 (+0000) Subject: [libFuzzer] remove usage of the old coverage instrumentation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27a5a291849e54c1b4ff03fb453e0fca319e0901;p=llvm [libFuzzer] remove usage of the old coverage instrumentation git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296536 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Fuzzer/FuzzerExtFunctions.def b/lib/Fuzzer/FuzzerExtFunctions.def index 91c9b07b665..926d4b42ed4 100644 --- a/lib/Fuzzer/FuzzerExtFunctions.def +++ b/lib/Fuzzer/FuzzerExtFunctions.def @@ -29,13 +29,10 @@ EXT_FUNC(LLVMFuzzerCustomCrossOver, size_t, EXT_FUNC(__lsan_enable, void, (), false); EXT_FUNC(__lsan_disable, void, (), false); EXT_FUNC(__lsan_do_recoverable_leak_check, int, (), false); -EXT_FUNC(__sanitizer_get_number_of_counters, size_t, (), false); EXT_FUNC(__sanitizer_install_malloc_and_free_hooks, int, (void (*malloc_hook)(const volatile void *, size_t), void (*free_hook)(const volatile void *)), false); -EXT_FUNC(__sanitizer_get_total_unique_caller_callee_pairs, size_t, (), false); -EXT_FUNC(__sanitizer_get_total_unique_coverage, size_t, (), true); EXT_FUNC(__sanitizer_print_memory_profile, int, (size_t), false); EXT_FUNC(__sanitizer_print_stack_trace, void, (), true); EXT_FUNC(__sanitizer_symbolize_pc, void, @@ -43,10 +40,7 @@ EXT_FUNC(__sanitizer_symbolize_pc, void, EXT_FUNC(__sanitizer_get_module_and_offset_for_pc, int, (void *pc, char *module_path, size_t module_path_len,void **pc_offset), false); -EXT_FUNC(__sanitizer_reset_coverage, void, (), true); EXT_FUNC(__sanitizer_set_death_callback, void, (void (*)(void)), true); EXT_FUNC(__sanitizer_set_report_fd, void, (void*), false); -EXT_FUNC(__sanitizer_update_counter_bitset_and_clear_counters, uintptr_t, - (uint8_t*), false); EXT_FUNC(__sanitizer_dump_coverage, void, (const uintptr_t *, uintptr_t), false); diff --git a/lib/Fuzzer/FuzzerInternal.h b/lib/Fuzzer/FuzzerInternal.h index 31c6585a91d..1ae457f2d50 100644 --- a/lib/Fuzzer/FuzzerInternal.h +++ b/lib/Fuzzer/FuzzerInternal.h @@ -138,11 +138,6 @@ private: void DumpCurrentUnit(const char *Prefix); void DeathCallback(); - void ResetEdgeCoverage(); - void ResetCounters(); - void PrepareCounters(Fuzzer::Coverage *C); - bool RecordMaxCoverage(Fuzzer::Coverage *C); - void AllocateCurrentUnitData(); uint8_t *CurrentUnitData = nullptr; std::atomic CurrentUnitSize; diff --git a/lib/Fuzzer/FuzzerLoop.cpp b/lib/Fuzzer/FuzzerLoop.cpp index d15f2e20df4..f9c3192ffcd 100644 --- a/lib/Fuzzer/FuzzerLoop.cpp +++ b/lib/Fuzzer/FuzzerLoop.cpp @@ -61,57 +61,6 @@ static void MissingExternalApiFunction(const char *FnName) { // Only one Fuzzer per process. static Fuzzer *F; -void Fuzzer::ResetEdgeCoverage() { - CHECK_EXTERNAL_FUNCTION(__sanitizer_reset_coverage); - EF->__sanitizer_reset_coverage(); -} - -void Fuzzer::ResetCounters() { - if (Options.UseCounters) - EF->__sanitizer_update_counter_bitset_and_clear_counters(0); -} - -void Fuzzer::PrepareCounters(Fuzzer::Coverage *C) { - if (Options.UseCounters) { - size_t NumCounters = EF->__sanitizer_get_number_of_counters(); - C->CounterBitmap.resize(NumCounters); - } -} - -// Records data to a maximum coverage tracker. Returns true if additional -// coverage was discovered. -bool Fuzzer::RecordMaxCoverage(Fuzzer::Coverage *C) { - bool Res = false; - - uint64_t NewBlockCoverage = EF->__sanitizer_get_total_unique_coverage(); - if (NewBlockCoverage > C->BlockCoverage) { - Res = true; - C->BlockCoverage = NewBlockCoverage; - } - - if (Options.UseIndirCalls && - EF->__sanitizer_get_total_unique_caller_callee_pairs) { - uint64_t NewCallerCalleeCoverage = - EF->__sanitizer_get_total_unique_caller_callee_pairs(); - if (NewCallerCalleeCoverage > C->CallerCalleeCoverage) { - Res = true; - C->CallerCalleeCoverage = NewCallerCalleeCoverage; - } - } - - if (Options.UseCounters) { - uint64_t CounterDelta = - EF->__sanitizer_update_counter_bitset_and_clear_counters( - C->CounterBitmap.data()); - if (CounterDelta > 0) { - Res = true; - C->CounterBitmapBits += CounterDelta; - } - } - - return Res; -} - // Leak detection is expensive, so we first check if there were more mallocs // than frees (using the sanitizer malloc hooks) and only then try to call lsan. struct MallocFreeTracer { @@ -506,11 +455,6 @@ size_t Fuzzer::RunOne(const uint8_t *Data, size_t Size) { })) Res = NumFeatures; - if (!TPC.UsingTracePcGuard()) { - if (!Res && RecordMaxCoverage(&MaxCoverage)) - Res = 1; - } - auto TimeOfUnit = duration_cast(UnitStopTime - UnitStartTime).count(); if (!(TotalNumberOfRuns & (TotalNumberOfRuns - 1)) && @@ -544,7 +488,6 @@ void Fuzzer::ExecuteCallback(const uint8_t *Data, size_t Size) { CurrentUnitSize = Size; AllocTracer.Start(Options.TraceMalloc); UnitStartTime = system_clock::now(); - ResetCounters(); // Reset coverage right before the callback. TPC.ResetMaps(); RunningCB = true; int Res = CB(DataCopy, Size); @@ -767,9 +710,7 @@ void Fuzzer::MutateAndTestOne() { } void Fuzzer::ResetCoverage() { - ResetEdgeCoverage(); MaxCoverage.Reset(); - PrepareCounters(&MaxCoverage); } void Fuzzer::Loop() {