Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Commit b48c442

Browse files
author
kcc
committed
[libFuzzer] simplify TracePC::HandleTrace even further. Also, when dealing with -exit_on_src_pos, symbolize every PC only once
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285223 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 048162f commit b48c442

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

lib/Fuzzer/FuzzerLoop.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <algorithm>
1919
#include <cstring>
20+
#include <set>
2021
#include <memory>
2122

2223
#if defined(__has_include)
@@ -161,7 +162,6 @@ Fuzzer::Fuzzer(UserCallback CB, InputCorpus &Corpus, MutationDispatcher &MD,
161162
assert(!F);
162163
F = this;
163164
TPC.ResetMaps();
164-
TPC.ResetGuards();
165165
ResetCoverage();
166166
IsMyThread = true;
167167
if (Options.DetectLeaks && EF->__sanitizer_install_malloc_and_free_hooks)
@@ -381,9 +381,11 @@ void Fuzzer::SetMaxMutationLen(size_t MaxMutationLen) {
381381

382382
void Fuzzer::CheckExitOnSrcPosOrItem() {
383383
if (!Options.ExitOnSrcPos.empty()) {
384+
static auto *PCsSet = new std::set<uintptr_t>;
384385
for (size_t i = 1, N = TPC.GetNumPCs(); i < N; i++) {
385386
uintptr_t PC = TPC.GetPC(i);
386387
if (!PC) continue;
388+
if (!PCsSet->insert(PC).second) continue;
387389
std::string Descr = DescribePC("%L", PC);
388390
if (Descr.find(Options.ExitOnSrcPos) != std::string::npos) {
389391
Printf("INFO: found line matching '%s', exiting.\n",
@@ -510,8 +512,6 @@ void Fuzzer::ExecuteCallback(const uint8_t *Data, size_t Size) {
510512
UnitStartTime = system_clock::now();
511513
ResetCounters(); // Reset coverage right before the callback.
512514
TPC.ResetMaps();
513-
if (Options.UseCounters)
514-
TPC.ResetGuards();
515515
int Res = CB(DataCopy, Size);
516516
UnitStopTime = system_clock::now();
517517
(void)Res;
@@ -577,20 +577,17 @@ UnitVector Fuzzer::FindExtraUnits(const UnitVector &Initial,
577577
for (int Iter = 0; Iter < 10; Iter++) {
578578
ShuffleCorpus(&Res);
579579
TPC.ResetMaps();
580-
TPC.ResetGuards();
581580
Corpus.ResetFeatureSet();
582581
ResetCoverage();
583582

584583
for (auto &U : Initial) {
585584
TPC.ResetMaps();
586-
TPC.ResetGuards();
587585
RunOne(U);
588586
}
589587

590588
Tmp.clear();
591589
for (auto &U : Res) {
592590
TPC.ResetMaps();
593-
TPC.ResetGuards();
594591
if (RunOne(U))
595592
Tmp.push_back(U);
596593
}

lib/Fuzzer/FuzzerTracePC.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,8 @@ TracePC TPC;
3030
void TracePC::HandleTrace(uint32_t *Guard, uintptr_t PC) {
3131
uint32_t Idx = *Guard;
3232
if (!Idx) return;
33-
if (!PCs[Idx % kNumPCs])
34-
PCs[Idx % kNumPCs] = PC;
35-
uint8_t *CounterPtr = &Counters[Idx % kNumCounters];
36-
uint8_t Counter = *CounterPtr;
37-
if (UseCounters) {
38-
if (Counter < 128)
39-
*CounterPtr = Counter + 1;
40-
else
41-
*Guard = 0;
42-
} else {
43-
*CounterPtr = 1;
44-
*Guard = 0;
45-
}
33+
PCs[Idx % kNumPCs] = PC;
34+
Counters[Idx % kNumCounters]++;
4635
}
4736

4837
size_t TracePC::GetTotalPCCoverage() {
@@ -70,14 +59,6 @@ void TracePC::PrintModuleInfo() {
7059
Printf("\n");
7160
}
7261

73-
void TracePC::ResetGuards() {
74-
uint32_t N = 0;
75-
for (size_t M = 0; M < NumModules; M++)
76-
for (uint32_t *X = Modules[M].Start, *End = Modules[M].Stop; X < End; X++)
77-
*X = ++N;
78-
assert(N == NumGuards);
79-
}
80-
8162
size_t TracePC::FinalizeTrace(InputCorpus *C, size_t InputSize, bool Shrink) {
8263
if (!UsingTracePcGuard()) return 0;
8364
size_t Res = 0;

lib/Fuzzer/FuzzerTracePC.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class TracePC {
6969
void UpdateFeatureSet(size_t CurrentElementIdx, size_t CurrentElementSize);
7070
void PrintFeatureSet();
7171

72-
void ResetGuards();
73-
7472
void PrintModuleInfo();
7573

7674
void PrintCoverage();

0 commit comments

Comments
 (0)