forked from OSchip/llvm-project
[libFuzzer] Portably disassemble and find calls to sanitizer_cov_trace_pc_guard.
Instead of directly using objdump, which is not present on Windows, we consider different tools depending on the platform. For Windows, we consider dumpbin and llvm-objdump. Differential Revision: https://reviews.llvm.org/D28635 llvm-svn: 292739
This commit is contained in:
parent
60cc2fbba1
commit
62c8fc571a
|
@ -18,6 +18,7 @@
|
||||||
#include "FuzzerExtFunctions.h"
|
#include "FuzzerExtFunctions.h"
|
||||||
#include "FuzzerIO.h"
|
#include "FuzzerIO.h"
|
||||||
#include "FuzzerTracePC.h"
|
#include "FuzzerTracePC.h"
|
||||||
|
#include "FuzzerUtil.h"
|
||||||
#include "FuzzerValueBitMap.h"
|
#include "FuzzerValueBitMap.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
@ -141,8 +142,8 @@ void TracePC::PrintCoverage() {
|
||||||
Printf("MODULE_WITH_COVERAGE: %s\n", ModuleName.c_str());
|
Printf("MODULE_WITH_COVERAGE: %s\n", ModuleName.c_str());
|
||||||
// sancov does not yet fully support DSOs.
|
// sancov does not yet fully support DSOs.
|
||||||
// std::string Cmd = "sancov -print-coverage-pcs " + ModuleName;
|
// std::string Cmd = "sancov -print-coverage-pcs " + ModuleName;
|
||||||
std::string Cmd = "objdump -d " + ModuleName +
|
std::string Cmd = DisassembleCmd(ModuleName) + " | " +
|
||||||
" | grep 'call.*__sanitizer_cov_trace_pc_guard' | awk -F: '{print $1}'";
|
SearchRegexCmd("call.*__sanitizer_cov_trace_pc_guard");
|
||||||
std::string SanCovOutput;
|
std::string SanCovOutput;
|
||||||
if (!ExecuteCommandAndReadOutput(Cmd, &SanCovOutput)) {
|
if (!ExecuteCommandAndReadOutput(Cmd, &SanCovOutput)) {
|
||||||
Printf("INFO: Command failed: %s\n", Cmd.c_str());
|
Printf("INFO: Command failed: %s\n", Cmd.c_str());
|
||||||
|
@ -151,6 +152,10 @@ void TracePC::PrintCoverage() {
|
||||||
std::istringstream ISS(SanCovOutput);
|
std::istringstream ISS(SanCovOutput);
|
||||||
std::string S;
|
std::string S;
|
||||||
while (std::getline(ISS, S, '\n')) {
|
while (std::getline(ISS, S, '\n')) {
|
||||||
|
size_t PcOffsetEnd = S.find(':');
|
||||||
|
if (PcOffsetEnd == std::string::npos)
|
||||||
|
continue;
|
||||||
|
S.resize(PcOffsetEnd);
|
||||||
uintptr_t PcOffset = std::stol(S, 0, 16);
|
uintptr_t PcOffset = std::stol(S, 0, 16);
|
||||||
if (!std::binary_search(CoveredOffsets.begin(), CoveredOffsets.end(),
|
if (!std::binary_search(CoveredOffsets.begin(), CoveredOffsets.end(),
|
||||||
PcOffset)) {
|
PcOffset)) {
|
||||||
|
|
|
@ -67,6 +67,10 @@ inline std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
|
||||||
return CloneArgsWithoutX(Args, X, X);
|
return CloneArgsWithoutX(Args, X, X);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string DisassembleCmd(const std::string &FileName);
|
||||||
|
|
||||||
|
std::string SearchRegexCmd(const std::string &Regex);
|
||||||
|
|
||||||
} // namespace fuzzer
|
} // namespace fuzzer
|
||||||
|
|
||||||
#endif // LLVM_FUZZER_UTIL_H
|
#endif // LLVM_FUZZER_UTIL_H
|
||||||
|
|
|
@ -118,6 +118,14 @@ const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
|
||||||
return memmem(Data, DataLen, Patt, PattLen);
|
return memmem(Data, DataLen, Patt, PattLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string DisassembleCmd(const std::string &FileName) {
|
||||||
|
return "objdump -d " + FileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SearchRegexCmd(const std::string &Regex) {
|
||||||
|
return "grep '" + Regex + "'";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace fuzzer
|
} // namespace fuzzer
|
||||||
|
|
||||||
#endif // LIBFUZZER_POSIX
|
#endif // LIBFUZZER_POSIX
|
||||||
|
|
|
@ -178,6 +178,20 @@ const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string DisassembleCmd(const std::string &FileName) {
|
||||||
|
if (ExecuteCommand("dumpbin > nul") == 0)
|
||||||
|
return "dumpbin /disasm " + FileName;
|
||||||
|
if (ExecuteCommand("llvm-objdump > nul") == 0)
|
||||||
|
return "llvm-objdump -d " + FileName;
|
||||||
|
Printf("libFuzzer: couldn't find tool to disassemble (dumpbin, "
|
||||||
|
"llvm-objdump)\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SearchRegexCmd(const std::string &Regex) {
|
||||||
|
return "findstr /r \"" + Regex + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace fuzzer
|
} // namespace fuzzer
|
||||||
|
|
||||||
#endif // LIBFUZZER_WINDOWS
|
#endif // LIBFUZZER_WINDOWS
|
||||||
|
|
Loading…
Reference in New Issue