[PATCH] D28635: [libFuzzer] Portably disassemble and find calls to "sanitizer_cov_trace_pc_guard".
Marcos Pividori via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 14:10:22 PST 2017
mpividori updated this revision to Diff 85192.
mpividori added a comment.
@zturner , I update diff to include suggestions.
https://reviews.llvm.org/D28635
Files:
lib/Fuzzer/FuzzerTracePC.cpp
lib/Fuzzer/FuzzerUtil.h
lib/Fuzzer/FuzzerUtilPosix.cpp
lib/Fuzzer/FuzzerUtilWindows.cpp
Index: lib/Fuzzer/FuzzerUtilWindows.cpp
===================================================================
--- lib/Fuzzer/FuzzerUtilWindows.cpp
+++ lib/Fuzzer/FuzzerUtilWindows.cpp
@@ -178,6 +178,20 @@
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
#endif // LIBFUZZER_WINDOWS
Index: lib/Fuzzer/FuzzerUtilPosix.cpp
===================================================================
--- lib/Fuzzer/FuzzerUtilPosix.cpp
+++ lib/Fuzzer/FuzzerUtilPosix.cpp
@@ -118,6 +118,14 @@
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
#endif // LIBFUZZER_POSIX
Index: lib/Fuzzer/FuzzerUtil.h
===================================================================
--- lib/Fuzzer/FuzzerUtil.h
+++ lib/Fuzzer/FuzzerUtil.h
@@ -67,6 +67,10 @@
return CloneArgsWithoutX(Args, X, X);
}
+std::string DisassembleCmd(const std::string &FileName);
+
+std::string SearchRegexCmd(const std::string &Regex);
+
} // namespace fuzzer
#endif // LLVM_FUZZER_UTIL_H
Index: lib/Fuzzer/FuzzerTracePC.cpp
===================================================================
--- lib/Fuzzer/FuzzerTracePC.cpp
+++ lib/Fuzzer/FuzzerTracePC.cpp
@@ -18,6 +18,7 @@
#include "FuzzerExtFunctions.h"
#include "FuzzerIO.h"
#include "FuzzerTracePC.h"
+#include "FuzzerUtil.h"
#include "FuzzerValueBitMap.h"
#include <map>
#include <sanitizer/coverage_interface.h>
@@ -147,16 +148,20 @@
Printf("MODULE_WITH_COVERAGE: %s\n", ModuleName.c_str());
// sancov does not yet fully support DSOs.
// std::string Cmd = "sancov -print-coverage-pcs " + ModuleName;
- std::string Cmd = "objdump -d " + ModuleName +
- " | grep 'call.*__sanitizer_cov_trace_pc_guard' | awk -F: '{print $1}'";
+ std::string Cmd = DisassembleCmd(ModuleName) + " | " +
+ SearchRegexCmd("call.*__sanitizer_cov_trace_pc_guard");
std::string SanCovOutput;
if (!ExecuteCommandAndReadOutput(Cmd, &SanCovOutput)) {
Printf("INFO: Command failed: %s\n", Cmd.c_str());
continue;
}
std::istringstream ISS(SanCovOutput);
std::string S;
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);
if (!std::binary_search(CoveredOffsets.begin(), CoveredOffsets.end(),
PcOffset)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28635.85192.patch
Type: text/x-patch
Size: 3059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170120/9a4e0768/attachment.bin>
More information about the llvm-commits
mailing list