summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2018-11-26 21:48:55 +0000
committerVitaly Buka <vitalybuka@google.com>2018-11-26 21:48:55 +0000
commitdfe8474e489d63998c582a96e1504a6152f74321 (patch)
tree40be1646058906f3288ff09021a9a7cfb4e31ca4
parentdb87ced890a6f949895ddbd233d752dfed5a65c2 (diff)
downloadbcm5719-llvm-dfe8474e489d63998c582a96e1504a6152f74321.tar.gz
bcm5719-llvm-dfe8474e489d63998c582a96e1504a6152f74321.zip
[cfi] Help sanstats to find binary if they are not at the original location
Summary: By default sanstats search binaries at the same location where they were when stats was collected. Sometime you can not print report immediately or you need to move post-processing to another workstation. To support this use-case when original binary is missing sanstats will fall-back to directory with sanstats file. Reviewers: pcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D53857 llvm-svn: 347601
-rw-r--r--llvm/test/tools/sanstats/elf.test10
-rw-r--r--llvm/tools/sanstats/sanstats.cpp8
2 files changed, 17 insertions, 1 deletions
diff --git a/llvm/test/tools/sanstats/elf.test b/llvm/test/tools/sanstats/elf.test
index 44a1268a320..54878a1d526 100644
--- a/llvm/test/tools/sanstats/elf.test
+++ b/llvm/test/tools/sanstats/elf.test
@@ -25,6 +25,16 @@
# RUN: sanstats %t.stats | FileCheck %s
+# Test that if binaries are not in the original location then sanstats
+# searches them next to the stats file.
+# RUN: mkdir -p %t.dir
+# RUN: mv -f %t1.o %t2.o %t.dir
+# RUN: sanstats %t.stats | FileCheck %s --check-prefix=INVALID
+# RUN: mv -f %t.stats %t.dir/copy.stats
+# RUN: cd %t.dir && sanstats copy.stats | FileCheck %s
+
+# INVALID: <invalid>
+# CHECK-NOT: <invalid>
# CHECK: 0x0000000000000000 /tmp{{[/\\]}}f.c:1 f1 cfi-vcall 1
# CHECK: 0x0000000000000010 /tmp{{[/\\]}}f.c:2 f2 cfi-nvcall 2
# CHECK: 0x0000000000000020 /tmp{{[/\\]}}f.c:3 f3 cfi-derived-cast 3
diff --git a/llvm/tools/sanstats/sanstats.cpp b/llvm/tools/sanstats/sanstats.cpp
index 214aeeab5ab..a345e9f06be 100644
--- a/llvm/tools/sanstats/sanstats.cpp
+++ b/llvm/tools/sanstats/sanstats.cpp
@@ -15,7 +15,9 @@
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
#include "llvm/Transforms/Utils/SanitizerStats.h"
#include <stdint.h>
@@ -52,7 +54,11 @@ const char *ReadModule(char SizeofPtr, const char *Begin, const char *End) {
++Begin;
if (Begin == End)
return nullptr;
- StringRef Filename(FilenameBegin, Begin - FilenameBegin);
+ std::string Filename(FilenameBegin, Begin - FilenameBegin);
+
+ if (!llvm::sys::fs::exists(Filename))
+ Filename = std::string(llvm::sys::path::parent_path(ClInputFile)) +
+ std::string(llvm::sys::path::filename(Filename));
++Begin;
if (Begin == End)
OpenPOWER on IntegriCloud