summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorMarcos Pividori <mpividori@google.com>2017-01-22 01:58:26 +0000
committerMarcos Pividori <mpividori@google.com>2017-01-22 01:58:26 +0000
commit62c8fc571a345f8f2e462aa8451849d4d2dd48d8 (patch)
treeec86e96b77858135d7bfdc489787e7be16badc82 /llvm/lib
parent60cc2fbba11aa2f856049cd81bc4c7275ba94da5 (diff)
downloadbcm5719-llvm-62c8fc571a345f8f2e462aa8451849d4d2dd48d8.tar.gz
bcm5719-llvm-62c8fc571a345f8f2e462aa8451849d4d2dd48d8.zip
[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
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Fuzzer/FuzzerTracePC.cpp9
-rw-r--r--llvm/lib/Fuzzer/FuzzerUtil.h4
-rw-r--r--llvm/lib/Fuzzer/FuzzerUtilPosix.cpp8
-rw-r--r--llvm/lib/Fuzzer/FuzzerUtilWindows.cpp14
4 files changed, 33 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerTracePC.cpp b/llvm/lib/Fuzzer/FuzzerTracePC.cpp
index 71f4b66f8bb..53454371f3e 100644
--- a/llvm/lib/Fuzzer/FuzzerTracePC.cpp
+++ b/llvm/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 <set>
@@ -141,8 +142,8 @@ void TracePC::PrintCoverage() {
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());
@@ -151,6 +152,10 @@ void TracePC::PrintCoverage() {
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)) {
diff --git a/llvm/lib/Fuzzer/FuzzerUtil.h b/llvm/lib/Fuzzer/FuzzerUtil.h
index 08058c56e4c..f84fd9ef0fc 100644
--- a/llvm/lib/Fuzzer/FuzzerUtil.h
+++ b/llvm/lib/Fuzzer/FuzzerUtil.h
@@ -67,6 +67,10 @@ inline std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
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
diff --git a/llvm/lib/Fuzzer/FuzzerUtilPosix.cpp b/llvm/lib/Fuzzer/FuzzerUtilPosix.cpp
index e8d48dc81a3..0161309fbf8 100644
--- a/llvm/lib/Fuzzer/FuzzerUtilPosix.cpp
+++ b/llvm/lib/Fuzzer/FuzzerUtilPosix.cpp
@@ -118,6 +118,14 @@ const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
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
diff --git a/llvm/lib/Fuzzer/FuzzerUtilWindows.cpp b/llvm/lib/Fuzzer/FuzzerUtilWindows.cpp
index 3ca1f2c8f56..b9e039f81e5 100644
--- a/llvm/lib/Fuzzer/FuzzerUtilWindows.cpp
+++ b/llvm/lib/Fuzzer/FuzzerUtilWindows.cpp
@@ -178,6 +178,20 @@ const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
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
OpenPOWER on IntegriCloud