[llvm] r284132 - [libFuzzer] reapply r283946: refactoring to speed things up, NFC. Now with a fix for gcc build
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 13 09:19:09 PDT 2016
Author: kcc
Date: Thu Oct 13 11:19:09 2016
New Revision: 284132
URL: http://llvm.org/viewvc/llvm-project?rev=284132&view=rev
Log:
[libFuzzer] reapply r283946: refactoring to speed things up, NFC. Now with a fix for gcc build
Modified:
llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp?rev=284132&r1=284131&r2=284132&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.cpp Thu Oct 13 11:19:09 2016
@@ -64,7 +64,7 @@ void TracePC::PrintModuleInfo() {
void TracePC::ResetGuards() {
uint32_t N = 0;
for (size_t M = 0; M < NumModules; M++)
- for (uint32_t *X = Modules[M].Start; X < Modules[M].Stop; X++)
+ for (uint32_t *X = Modules[M].Start, *End = Modules[M].Stop; X < End; X++)
*X = ++N;
assert(N == NumGuards);
}
@@ -163,24 +163,18 @@ void TracePC::AddValueForStrcmp(void *ca
TPC.HandleValueProfile((PC & 4095) | (Idx << 12));
}
+template <class T>
ATTRIBUTE_TARGET_POPCNT
-static void AddValueForCmp(void *PCptr, uint64_t Arg1, uint64_t Arg2) {
- uintptr_t PC = reinterpret_cast<uintptr_t>(PCptr);
+#ifdef __clang__ // g++ can't handle this __attribute__ here :(
+__attribute__((always_inline))
+#endif // __clang__
+void TracePC::HandleCmp(void *PC, T Arg1, T Arg2) {
+ uintptr_t PCuint = reinterpret_cast<uintptr_t>(PC);
uint64_t ArgDistance = __builtin_popcountl(Arg1 ^ Arg2) + 1; // [1,65]
- uintptr_t Idx = ((PC & 4095) + 1) * ArgDistance;
- TPC.HandleValueProfile(Idx);
-}
-
-static void AddValueForSingleVal(void *PCptr, uintptr_t Val) {
- if (!Val) return;
- uintptr_t PC = reinterpret_cast<uintptr_t>(PCptr);
- uint64_t ArgDistance = __builtin_popcountl(Val) - 1; // [0,63]
- uintptr_t Idx = (PC & 4095) | (ArgDistance << 12);
- TPC.HandleValueProfile(Idx);
+ uintptr_t Idx = ((PCuint & 4095) + 1) * ArgDistance;
+ HandleValueProfile(Idx);
}
-
-
} // namespace fuzzer
extern "C" {
@@ -201,28 +195,21 @@ void __sanitizer_cov_trace_pc_indir(uint
fuzzer::TPC.HandleCallerCallee(PC, Callee);
}
-// TODO: this one will not be used with the newest clang. Remove it.
-__attribute__((visibility("default")))
-void __sanitizer_cov_trace_cmp(uint64_t SizeAndType, uint64_t Arg1,
- uint64_t Arg2) {
- fuzzer::AddValueForCmp(__builtin_return_address(0), Arg1, Arg2);
-}
-
__attribute__((visibility("default")))
-void __sanitizer_cov_trace_cmp8(uint64_t Arg1, int64_t Arg2) {
- fuzzer::AddValueForCmp(__builtin_return_address(0), Arg1, Arg2);
+void __sanitizer_cov_trace_cmp8(uint64_t Arg1, uint64_t Arg2) {
+ fuzzer::TPC.HandleCmp(__builtin_return_address(0), Arg1, Arg2);
}
__attribute__((visibility("default")))
-void __sanitizer_cov_trace_cmp4(uint32_t Arg1, int32_t Arg2) {
- fuzzer::AddValueForCmp(__builtin_return_address(0), Arg1, Arg2);
+void __sanitizer_cov_trace_cmp4(uint32_t Arg1, uint32_t Arg2) {
+ fuzzer::TPC.HandleCmp(__builtin_return_address(0), Arg1, Arg2);
}
__attribute__((visibility("default")))
-void __sanitizer_cov_trace_cmp2(uint16_t Arg1, int16_t Arg2) {
- fuzzer::AddValueForCmp(__builtin_return_address(0), Arg1, Arg2);
+void __sanitizer_cov_trace_cmp2(uint16_t Arg1, uint16_t Arg2) {
+ fuzzer::TPC.HandleCmp(__builtin_return_address(0), Arg1, Arg2);
}
__attribute__((visibility("default")))
-void __sanitizer_cov_trace_cmp1(uint8_t Arg1, int8_t Arg2) {
- fuzzer::AddValueForCmp(__builtin_return_address(0), Arg1, Arg2);
+void __sanitizer_cov_trace_cmp1(uint8_t Arg1, uint8_t Arg2) {
+ fuzzer::TPC.HandleCmp(__builtin_return_address(0), Arg1, Arg2);
}
__attribute__((visibility("default")))
@@ -232,20 +219,20 @@ void __sanitizer_cov_trace_switch(uint64
char *PC = (char*)__builtin_return_address(0);
for (size_t i = 0; i < N; i++)
if (Val != Vals[i])
- fuzzer::AddValueForCmp(PC + i, Val, Vals[i]);
+ fuzzer::TPC.HandleCmp(PC + i, Val, Vals[i]);
}
__attribute__((visibility("default")))
void __sanitizer_cov_trace_div4(uint32_t Val) {
- fuzzer::AddValueForSingleVal(__builtin_return_address(0), Val);
+ fuzzer::TPC.HandleCmp(__builtin_return_address(0), Val, (uint32_t)0);
}
__attribute__((visibility("default")))
void __sanitizer_cov_trace_div8(uint64_t Val) {
- fuzzer::AddValueForSingleVal(__builtin_return_address(0), Val);
+ fuzzer::TPC.HandleCmp(__builtin_return_address(0), Val, (uint64_t)0);
}
__attribute__((visibility("default")))
void __sanitizer_cov_trace_gep(uintptr_t Idx) {
- fuzzer::AddValueForSingleVal(__builtin_return_address(0), Idx);
+ fuzzer::TPC.HandleCmp(__builtin_return_address(0), Idx, (uintptr_t)0);
}
} // extern "C"
Modified: llvm/trunk/lib/Fuzzer/FuzzerTracePC.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerTracePC.h?rev=284132&r1=284131&r2=284132&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerTracePC.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerTracePC.h Thu Oct 13 11:19:09 2016
@@ -25,6 +25,7 @@ class TracePC {
void HandleInit(uint32_t *start, uint32_t *stop);
void HandleCallerCallee(uintptr_t Caller, uintptr_t Callee);
void HandleValueProfile(size_t Value) { ValueProfileMap.AddValue(Value); }
+ template <class T> void HandleCmp(void *PC, T Arg1, T Arg2);
size_t GetTotalPCCoverage() { return TotalPCCoverage; }
void ResetTotalPCCoverage() { TotalPCCoverage = 0; }
void SetUseCounters(bool UC) { UseCounters = UC; }
@@ -32,8 +33,7 @@ class TracePC {
size_t FinalizeTrace(InputCorpus *C, size_t InputSize, bool Shrink);
bool UpdateValueProfileMap(ValueBitMap *MaxValueProfileMap) {
return UseValueProfile && MaxValueProfileMap->MergeFrom(ValueProfileMap);
- }
-
+ }
size_t GetNewPCIDs(uintptr_t **NewPCIDsPtr) {
*NewPCIDsPtr = NewPCIDs;
More information about the llvm-commits
mailing list