forked from OSchip/llvm-project
[libFuzzer] don't call GetPreviousInstructionPc on the hot path -- only when dumping the PCs
llvm-svn: 293117
This commit is contained in:
parent
7117e698bf
commit
7c021afef2
|
@ -188,9 +188,19 @@ void TracePC::PrintCoverage() {
|
|||
}
|
||||
}
|
||||
|
||||
inline ALWAYS_INLINE uintptr_t GetPreviousInstructionPc(uintptr_t PC) {
|
||||
// TODO: this implementation is x86 only.
|
||||
// see sanitizer_common GetPreviousInstructionPc for full implementation.
|
||||
return PC - 1;
|
||||
}
|
||||
|
||||
void TracePC::DumpCoverage() {
|
||||
if (EF->__sanitizer_dump_coverage)
|
||||
EF->__sanitizer_dump_coverage(PCs, GetNumPCs());
|
||||
if (EF->__sanitizer_dump_coverage) {
|
||||
std::vector<uintptr_t> PCsCopy(GetNumPCs());
|
||||
for (size_t i = 0; i < GetNumPCs(); i++)
|
||||
PCsCopy[i] = PCs[i] ? GetPreviousInstructionPc(PCs[i]) : 0;
|
||||
EF->__sanitizer_dump_coverage(PCsCopy.data(), PCsCopy.size());
|
||||
}
|
||||
}
|
||||
|
||||
// Value profile.
|
||||
|
@ -244,18 +254,12 @@ void TracePC::HandleCmp(uintptr_t PC, T Arg1, T Arg2) {
|
|||
HandleValueProfile(Idx);
|
||||
}
|
||||
|
||||
inline ALWAYS_INLINE uintptr_t GetPreviousInstructionPc(void* pc) {
|
||||
// TODO: this implementation is x86 only.
|
||||
// see sanitizer_common GetPreviousInstructionPc for full implementation.
|
||||
return reinterpret_cast<uintptr_t>(pc) - 1;
|
||||
}
|
||||
|
||||
} // namespace fuzzer
|
||||
|
||||
extern "C" {
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_pc_guard(uint32_t *Guard) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleTrace(Guard, PC);
|
||||
}
|
||||
|
||||
|
@ -266,31 +270,31 @@ void __sanitizer_cov_trace_pc_guard_init(uint32_t *Start, uint32_t *Stop) {
|
|||
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_pc_indir(uintptr_t Callee) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleCallerCallee(PC, Callee);
|
||||
}
|
||||
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_cmp8(uint64_t Arg1, uint64_t Arg2) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleCmp(PC, Arg1, Arg2);
|
||||
}
|
||||
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_cmp4(uint32_t Arg1, uint32_t Arg2) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleCmp(PC, Arg1, Arg2);
|
||||
}
|
||||
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_cmp2(uint16_t Arg1, uint16_t Arg2) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleCmp(PC, Arg1, Arg2);
|
||||
}
|
||||
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_cmp1(uint8_t Arg1, uint8_t Arg2) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleCmp(PC, Arg1, Arg2);
|
||||
}
|
||||
|
||||
|
@ -302,7 +306,7 @@ void __sanitizer_cov_trace_switch(uint64_t Val, uint64_t *Cases) {
|
|||
// Skip the most common and the most boring case.
|
||||
if (Vals[N - 1] < 256 && Val < 256)
|
||||
return;
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
size_t i;
|
||||
uint64_t Token = 0;
|
||||
for (i = 0; i < N; i++) {
|
||||
|
@ -321,19 +325,19 @@ void __sanitizer_cov_trace_switch(uint64_t Val, uint64_t *Cases) {
|
|||
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_div4(uint32_t Val) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleCmp(PC, Val, (uint32_t)0);
|
||||
}
|
||||
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_div8(uint64_t Val) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleCmp(PC, Val, (uint64_t)0);
|
||||
}
|
||||
|
||||
ATTRIBUTE_INTERFACE
|
||||
void __sanitizer_cov_trace_gep(uintptr_t Idx) {
|
||||
uintptr_t PC = fuzzer::GetPreviousInstructionPc(__builtin_return_address(0));
|
||||
uintptr_t PC = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
|
||||
fuzzer::TPC.HandleCmp(PC, Idx, (uintptr_t)0);
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
Loading…
Reference in New Issue