Skip to content

Commit 1c8e051

Browse files
committed
[libFuzzer] Remove lazy counters.
Summary: Lazy counters haven't improved performance for large fuzz targets. Reviewers: kcc Reviewed By: kcc Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67476 llvm-svn: 373403
1 parent 9b36c1c commit 1c8e051

11 files changed

+0
-70
lines changed

compiler-rt/lib/fuzzer/FuzzerDriver.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
708708
Options.FeaturesDir = Flags.features_dir;
709709
if (Flags.collect_data_flow)
710710
Options.CollectDataFlow = Flags.collect_data_flow;
711-
Options.LazyCounters = Flags.lazy_counters;
712711
if (Flags.stop_file)
713712
Options.StopFile = Flags.stop_file;
714713

compiler-rt/lib/fuzzer/FuzzerFlags.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ FUZZER_FLAG_INT(handle_term, 1, "If 1, try to intercept SIGTERM.")
123123
FUZZER_FLAG_INT(handle_xfsz, 1, "If 1, try to intercept SIGXFSZ.")
124124
FUZZER_FLAG_INT(handle_usr1, 1, "If 1, try to intercept SIGUSR1.")
125125
FUZZER_FLAG_INT(handle_usr2, 1, "If 1, try to intercept SIGUSR2.")
126-
FUZZER_FLAG_INT(lazy_counters, 0, "If 1, a performance optimization is"
127-
"enabled for the 8bit inline counters. "
128-
"Requires that libFuzzer successfully installs its SEGV handler")
129126
FUZZER_FLAG_INT(close_fd_mask, 0, "If 1, close stdout at startup; "
130127
"if 2, close stderr; if 3, close both. "
131128
"Be careful, this will also close e.g. stderr of asan.")

compiler-rt/lib/fuzzer/FuzzerLoop.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,6 @@ void Fuzzer::ReadAndExecuteSeedCorpora(Vector<SizedFile> &CorporaFiles) {
742742
uint8_t dummy = 0;
743743
ExecuteCallback(&dummy, 0);
744744

745-
// Protect lazy counters here, after the once-init code has been executed.
746-
if (Options.LazyCounters)
747-
TPC.ProtectLazyCounters();
748-
749745
if (CorporaFiles.empty()) {
750746
Printf("INFO: A corpus is not provided, starting from an empty corpus\n");
751747
Unit U({'\n'}); // Valid ASCII input.

compiler-rt/lib/fuzzer/FuzzerOptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct FuzzingOptions {
7575
bool HandleXfsz = false;
7676
bool HandleUsr1 = false;
7777
bool HandleUsr2 = false;
78-
bool LazyCounters = false;
7978
};
8079

8180
} // namespace fuzzer

compiler-rt/lib/fuzzer/FuzzerTracePC.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -67,45 +67,6 @@ void TracePC::HandleInline8bitCountersInit(uint8_t *Start, uint8_t *Stop) {
6767
NumInline8bitCounters += M.Size();
6868
}
6969

70-
// Mark all full page counter regions as PROT_NONE and set Enabled=false.
71-
// The first time the instrumented code hits such a protected/disabled
72-
// counter region we should catch a SEGV and call UnprotectLazyCounters,
73-
// which will mark the page as PROT_READ|PROT_WRITE and set Enabled=true.
74-
//
75-
// Whenever other functions iterate over the counters they should ignore
76-
// regions with Enabled=false.
77-
void TracePC::ProtectLazyCounters() {
78-
size_t NumPagesProtected = 0;
79-
IterateCounterRegions([&](Module::Region &R) {
80-
if (!R.OneFullPage) return;
81-
if (Mprotect(R.Start, R.Stop - R.Start, false)) {
82-
R.Enabled = false;
83-
NumPagesProtected++;
84-
}
85-
});
86-
if (NumPagesProtected)
87-
Printf("INFO: %zd pages of counters where protected;"
88-
" libFuzzer's SEGV handler must be installed\n",
89-
NumPagesProtected);
90-
}
91-
92-
bool TracePC::UnprotectLazyCounters(void *CounterPtr) {
93-
// Printf("UnprotectLazyCounters: %p\n", CounterPtr);
94-
if (!CounterPtr)
95-
return false;
96-
bool Done = false;
97-
uint8_t *Addr = reinterpret_cast<uint8_t *>(CounterPtr);
98-
IterateCounterRegions([&](Module::Region &R) {
99-
if (!R.OneFullPage || R.Enabled || Done) return;
100-
if (Addr >= R.Start && Addr < R.Stop)
101-
if (Mprotect(R.Start, R.Stop - R.Start, true)) {
102-
R.Enabled = true;
103-
Done = true;
104-
}
105-
});
106-
return Done;
107-
}
108-
10970
void TracePC::HandlePCsInit(const uintptr_t *Start, const uintptr_t *Stop) {
11071
const PCTableEntry *B = reinterpret_cast<const PCTableEntry *>(Start);
11172
const PCTableEntry *E = reinterpret_cast<const PCTableEntry *>(Stop);

compiler-rt/lib/fuzzer/FuzzerTracePC.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ class TracePC {
119119
void SetFocusFunction(const std::string &FuncName);
120120
bool ObservedFocusFunction();
121121

122-
void ProtectLazyCounters();
123-
bool UnprotectLazyCounters(void *CounterPtr);
124-
125122
struct PCTableEntry {
126123
uintptr_t PC, PCFlags;
127124
};

compiler-rt/lib/fuzzer/FuzzerUtil.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ void SetSignalHandler(const FuzzingOptions& Options);
5252

5353
void SleepSeconds(int Seconds);
5454

55-
bool Mprotect(void *Ptr, size_t Size, bool AllowReadWrite);
56-
5755
unsigned long GetPid();
5856

5957
size_t GetPeakRSSMb();

compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,6 @@ void CrashHandler(zx_handle_t *Event) {
305305

306306
} // namespace
307307

308-
bool Mprotect(void *Ptr, size_t Size, bool AllowReadWrite) {
309-
return false; // UNIMPLEMENTED
310-
}
311-
312308
// Platform specific functions.
313309
void SetSignalHandler(const FuzzingOptions &Options) {
314310
// Make sure information from libFuzzer and the sanitizers are easy to

compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static void (*upstream_segv_handler)(int, siginfo_t *, void *);
3737

3838
static void SegvHandler(int sig, siginfo_t *si, void *ucontext) {
3939
assert(si->si_signo == SIGSEGV);
40-
if (TPC.UnprotectLazyCounters(si->si_addr)) return;
4140
if (upstream_segv_handler)
4241
return upstream_segv_handler(sig, si, ucontext);
4342
Fuzzer::StaticCrashSignalCallback();
@@ -98,11 +97,6 @@ void SetTimer(int Seconds) {
9897
SetSigaction(SIGALRM, AlarmHandler);
9998
}
10099

101-
bool Mprotect(void *Ptr, size_t Size, bool AllowReadWrite) {
102-
return 0 == mprotect(Ptr, Size,
103-
AllowReadWrite ? (PROT_READ | PROT_WRITE) : PROT_NONE);
104-
}
105-
106100
void SetSignalHandler(const FuzzingOptions& Options) {
107101
if (Options.UnitTimeoutSec > 0)
108102
SetTimer(Options.UnitTimeoutSec / 2 + 1);

compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ static TimerQ Timer;
111111

112112
static void CrashHandler(int) { Fuzzer::StaticCrashSignalCallback(); }
113113

114-
bool Mprotect(void *Ptr, size_t Size, bool AllowReadWrite) {
115-
return false; // UNIMPLEMENTED
116-
}
117-
118114
void SetSignalHandler(const FuzzingOptions& Options) {
119115
HandlerOpt = &Options;
120116

compiler-rt/test/fuzzer/large.test

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
REQUIRES: linux
21
RUN: %cpp_compiler %S/LargeTest.cpp -o %t-LargeTest
32
RUN: %run %t-LargeTest -runs=10000
4-
RUN: %env_asan_opts=handle_segv=0 %run %t-LargeTest -runs=10000 -lazy_counters=1 2>&1 | FileCheck %s
5-
RUN: %run %t-LargeTest -runs=10000 -lazy_counters=1 2>&1 | FileCheck %s
63

74
CHECK: pages of counters where protected; libFuzzer's SEGV handler must be installed

0 commit comments

Comments
 (0)