[PATCH] D158052: [llvm-exegesis] Add explicit error for segmenetation faults

Aiden Grossman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 22:25:07 PDT 2023


aidengrossman created this revision.
Herald added a subscriber: mstojanovic.
Herald added a project: All.
aidengrossman requested review of this revision.
Herald added subscribers: llvm-commits, courbet.
Herald added a project: LLVM.

When benchmarking certain snippets that access memory, segmentation
faults are a very real possibility if the memory annotations are not
perfect. These situtations are currently difficult to debug as there is
no indication of which addresses need to be mapped. This patch adds in
support for printing the address a segmentation fault occurred at to
make it easier to gather this information.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158052

Files:
  llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
  llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
  llvm/tools/llvm-exegesis/lib/Error.cpp
  llvm/tools/llvm-exegesis/lib/Error.h


Index: llvm/tools/llvm-exegesis/lib/Error.h
===================================================================
--- llvm/tools/llvm-exegesis/lib/Error.h
+++ llvm/tools/llvm-exegesis/lib/Error.h
@@ -51,6 +51,21 @@
   std::string Msg;
 };
 
+// A class representing segmentation faults specifically. Holds information
+// about where specifically the segmentation fault occurred.
+class SnippetSegfaultCrash : public ErrorInfo<SnippetSegfaultCrash> {
+public:
+  static char ID;
+  SnippetSegfaultCrash(const void *Addr) : Address((intptr_t)Addr) {}
+
+  void log(raw_ostream &OS) const override;
+
+  std::error_code convertToErrorCode() const override;
+
+private:
+  intptr_t Address;
+};
+
 } // namespace exegesis
 } // namespace llvm
 
Index: llvm/tools/llvm-exegesis/lib/Error.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/Error.cpp
+++ llvm/tools/llvm-exegesis/lib/Error.cpp
@@ -27,5 +27,15 @@
   return inconvertibleErrorCode();
 }
 
+char SnippetSegfaultCrash::ID;
+
+void SnippetSegfaultCrash::log(raw_ostream &OS) const {
+  OS << "A segmentation fault occurred at address " + Twine::utohexstr(Address);
+}
+
+std::error_code SnippetSegfaultCrash::convertToErrorCode() const {
+  return inconvertibleErrorCode();
+}
+
 } // namespace exegesis
 } // namespace llvm
Index: llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -334,6 +334,9 @@
                                  Twine(strerror(errno)));
     }
 
+    if (ChildSignalInfo.si_signo == SIGSEGV)
+      return make_error<SnippetSegfaultCrash>(ChildSignalInfo.si_addr);
+
     return make_error<SnippetCrash>(
         "The benchmarking subprocess sent unexpected signal: " +
         Twine(strsignal(ChildSignalInfo.si_signo)));
@@ -526,7 +529,7 @@
   auto NewMeasurements = runMeasurements(**Executor);
 
   if (Error E = NewMeasurements.takeError()) {
-    if (!E.isA<SnippetCrash>())
+    if (!E.isA<SnippetCrash>() && !E.isA<SnippetSegfaultCrash>())
       return std::move(E);
     InstrBenchmark.Error = toString(std::move(E));
     return std::move(InstrBenchmark);
Index: llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
===================================================================
--- llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
+++ llvm/test/tools/llvm-exegesis/X86/latency/subprocess-segfault.s
@@ -2,7 +2,7 @@
 
 # RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mode=latency -snippets-file=%s -execution-mode=subprocess | FileCheck %s
 
-# CHECK: error:           'The benchmarking subprocess sent unexpected signal: Segmentation fault'
+# CHECK: error:           A segmentation fault occurred at address 20000
 
-# LLVM-EXEGESIS-DEFREG RBX 0
+# LLVM-EXEGESIS-DEFREG RBX 20000
 movq (%rbx), %rax


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158052.550614.patch
Type: text/x-patch
Size: 2956 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230816/639c4f2b/attachment.bin>


More information about the llvm-commits mailing list