[compiler-rt] r313309 - [asan] Remove ErrorStackOverflow

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 14 15:43:53 PDT 2017


Author: vitalybuka
Date: Thu Sep 14 15:43:53 2017
New Revision: 313309

URL: http://llvm.org/viewvc/llvm-project?rev=313309&view=rev
Log:
[asan] Remove ErrorStackOverflow

Summary:
The only difference from ErrorDeadlySignal is reporting code and it lives in
sanitizer common.

Part of https://github.com/google/sanitizers/issues/637

Reviewers: eugenis, alekseyshl, filcab

Subscribers: llvm-commits, kubamracek

Differential Revision: https://reviews.llvm.org/D37868

Modified:
    compiler-rt/trunk/lib/asan/asan_errors.cc
    compiler-rt/trunk/lib/asan/asan_errors.h
    compiler-rt/trunk/lib/asan/asan_posix.cc
    compiler-rt/trunk/lib/asan/asan_report.cc
    compiler-rt/trunk/lib/asan/asan_report.h

Modified: compiler-rt/trunk/lib/asan/asan_errors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_errors.cc?rev=313309&r1=313308&r2=313309&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_errors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_errors.cc Thu Sep 14 15:43:53 2017
@@ -22,56 +22,56 @@
 
 namespace __asan {
 
-void ErrorStackOverflow::Print() {
-  Decorator d;
-  Printf("%s", d.Warning());
-  Report(
-      "ERROR: AddressSanitizer: %s on address %p"
-      " (pc %p bp %p sp %p T%d)\n",
-      scariness.GetDescription(), (void *)signal.addr, (void *)signal.pc,
-      (void *)signal.bp, (void *)signal.sp, tid);
-  Printf("%s", d.Default());
-  scariness.Print();
-  BufferedStackTrace stack;
-  GetStackTraceWithPcBpAndContext(&stack, kStackTraceMax, signal.pc, signal.bp,
-                                  signal.context,
-                                  common_flags()->fast_unwind_on_fatal);
-  stack.Print();
-  ReportErrorSummary(scariness.GetDescription(), &stack);
-}
-
 void ErrorDeadlySignal::Print() {
-  Decorator d;
-  Printf("%s", d.Warning());
-  const char *description = signal.Describe();
-  Report(
-      "ERROR: AddressSanitizer: %s on unknown address %p (pc %p bp %p sp %p "
-      "T%d)\n",
-      description, (void *)signal.addr, (void *)signal.pc, (void *)signal.bp,
-      (void *)signal.sp, tid);
-  Printf("%s", d.Default());
-  if (signal.pc < GetPageSizeCached())
-    Report("Hint: pc points to the zero page.\n");
-  if (signal.is_memory_access) {
-    const char *access_type =
-        signal.write_flag == SignalContext::WRITE
-            ? "WRITE"
-            : (signal.write_flag == SignalContext::READ ? "READ" : "UNKNOWN");
-    Report("The signal is caused by a %s memory access.\n", access_type);
-    if (signal.addr < GetPageSizeCached())
-      Report("Hint: address points to the zero page.\n");
+  if (signal.IsStackOverflow()) {
+    Decorator d;
+    Printf("%s", d.Warning());
+    Report(
+        "ERROR: AddressSanitizer: %s on address %p"
+        " (pc %p bp %p sp %p T%d)\n",
+        scariness.GetDescription(), (void *)signal.addr, (void *)signal.pc,
+        (void *)signal.bp, (void *)signal.sp, tid);
+    Printf("%s", d.Default());
+    scariness.Print();
+    BufferedStackTrace stack;
+    GetStackTraceWithPcBpAndContext(&stack, kStackTraceMax, signal.pc,
+                                    signal.bp, signal.context,
+                                    common_flags()->fast_unwind_on_fatal);
+    stack.Print();
+    ReportErrorSummary(scariness.GetDescription(), &stack);
+  } else {
+    Decorator d;
+    Printf("%s", d.Warning());
+    const char *description = signal.Describe();
+    Report(
+        "ERROR: AddressSanitizer: %s on unknown address %p (pc %p bp %p sp %p "
+        "T%d)\n",
+        description, (void *)signal.addr, (void *)signal.pc, (void *)signal.bp,
+        (void *)signal.sp, tid);
+    Printf("%s", d.Default());
+    if (signal.pc < GetPageSizeCached())
+      Report("Hint: pc points to the zero page.\n");
+    if (signal.is_memory_access) {
+      const char *access_type =
+          signal.write_flag == SignalContext::WRITE
+              ? "WRITE"
+              : (signal.write_flag == SignalContext::READ ? "READ" : "UNKNOWN");
+      Report("The signal is caused by a %s memory access.\n", access_type);
+      if (signal.addr < GetPageSizeCached())
+        Report("Hint: address points to the zero page.\n");
+    }
+    MaybeReportNonExecRegion(signal.pc);
+    scariness.Print();
+    BufferedStackTrace stack;
+    GetStackTraceWithPcBpAndContext(&stack, kStackTraceMax, signal.pc,
+                                    signal.bp, signal.context,
+                                    common_flags()->fast_unwind_on_fatal);
+    stack.Print();
+    MaybeDumpInstructionBytes(signal.pc);
+    MaybeDumpRegisters(signal.context);
+    Printf("AddressSanitizer can not provide additional info.\n");
+    ReportErrorSummary(description, &stack);
   }
-  MaybeReportNonExecRegion(signal.pc);
-  scariness.Print();
-  BufferedStackTrace stack;
-  GetStackTraceWithPcBpAndContext(&stack, kStackTraceMax, signal.pc, signal.bp,
-                                  signal.context,
-                                  common_flags()->fast_unwind_on_fatal);
-  stack.Print();
-  MaybeDumpInstructionBytes(signal.pc);
-  MaybeDumpRegisters(signal.context);
-  Printf("AddressSanitizer can not provide additional info.\n");
-  ReportErrorSummary(description, &stack);
 }
 
 void ErrorDoubleFree::Print() {

Modified: compiler-rt/trunk/lib/asan/asan_errors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_errors.h?rev=313309&r1=313308&r2=313309&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_errors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_errors.h Thu Sep 14 15:43:53 2017
@@ -27,19 +27,6 @@ struct ErrorBase {
   u32 tid;
 };
 
-struct ErrorStackOverflow : ErrorBase {
-  SignalContext signal;
-  // VS2013 doesn't implement unrestricted unions, so we need a trivial default
-  // constructor
-  ErrorStackOverflow() = default;
-  ErrorStackOverflow(u32 tid, const SignalContext &sig)
-      : ErrorBase(tid), signal(sig) {
-    scariness.Clear();
-    scariness.Scare(10, "stack-overflow");
-  }
-  void Print();
-};
-
 struct ErrorDeadlySignal : ErrorBase {
   SignalContext signal;
   // VS2013 doesn't implement unrestricted unions, so we need a trivial default
@@ -48,20 +35,20 @@ struct ErrorDeadlySignal : ErrorBase {
   ErrorDeadlySignal(u32 tid, const SignalContext &sig)
       : ErrorBase(tid), signal(sig) {
     scariness.Clear();
-    if (signal.is_memory_access) {
-      if (signal.addr < GetPageSizeCached()) {
-        scariness.Scare(10, "null-deref");
-      } else if (signal.addr == signal.pc) {
-        scariness.Scare(60, "wild-jump");
-      } else if (signal.write_flag == SignalContext::WRITE) {
-        scariness.Scare(30, "wild-addr-write");
-      } else if (signal.write_flag == SignalContext::READ) {
-        scariness.Scare(20, "wild-addr-read");
-      } else {
-        scariness.Scare(25, "wild-addr");
-      }
-    } else {
+    if (signal.IsStackOverflow()) {
+      scariness.Scare(10, "stack-overflow");
+    } else if (!signal.is_memory_access) {
       scariness.Scare(10, "signal");
+    } else if (signal.addr < GetPageSizeCached()) {
+      scariness.Scare(10, "null-deref");
+    } else if (signal.addr == signal.pc) {
+      scariness.Scare(60, "wild-jump");
+    } else if (signal.write_flag == SignalContext::WRITE) {
+      scariness.Scare(30, "wild-addr-write");
+    } else if (signal.write_flag == SignalContext::READ) {
+      scariness.Scare(20, "wild-addr-read");
+    } else {
+      scariness.Scare(25, "wild-addr");
     }
   }
   void Print();
@@ -304,7 +291,6 @@ struct ErrorGeneric : ErrorBase {
 
 // clang-format off
 #define ASAN_FOR_EACH_ERROR_KIND(macro)         \
-  macro(StackOverflow)                          \
   macro(DeadlySignal)                           \
   macro(DoubleFree)                             \
   macro(NewDeleteSizeMismatch)                  \

Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=313309&r1=313308&r2=313309&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Thu Sep 14 15:43:53 2017
@@ -37,10 +37,7 @@ void AsanOnDeadlySignal(int signo, void
   ScopedDeadlySignal signal_scope(GetCurrentThread());
   StartReportDeadlySignal();
   SignalContext sig(siginfo, context);
-  if (sig.IsStackOverflow())
-    ReportStackOverflow(sig);
-  else
-    ReportDeadlySignal(sig);
+  ReportDeadlySignal(sig);
 }
 
 // ---------------------- TSD ---------------- {{{1

Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=313309&r1=313308&r2=313309&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Thu Sep 14 15:43:53 2017
@@ -260,12 +260,6 @@ StaticSpinMutex ScopedInErrorReport::loc
 u32 ScopedInErrorReport::reporting_thread_tid_ = kInvalidTid;
 ErrorDescription ScopedInErrorReport::current_error_;
 
-void ReportStackOverflow(const SignalContext &sig) {
-  ScopedInErrorReport in_report(/*fatal*/ true);
-  ErrorStackOverflow error(GetCurrentTidOrInvalid(), sig);
-  in_report.ReportError(error);
-}
-
 void ReportDeadlySignal(const SignalContext &sig) {
   ScopedInErrorReport in_report(/*fatal*/ true);
   ErrorDeadlySignal error(GetCurrentTidOrInvalid(), sig);

Modified: compiler-rt/trunk/lib/asan/asan_report.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.h?rev=313309&r1=313308&r2=313309&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.h (original)
+++ compiler-rt/trunk/lib/asan/asan_report.h Thu Sep 14 15:43:53 2017
@@ -46,7 +46,6 @@ bool ParseFrameDescription(const char *f
 // Different kinds of error reports.
 void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write,
                         uptr access_size, u32 exp, bool fatal);
-void ReportStackOverflow(const SignalContext &sig);
 void ReportDeadlySignal(const SignalContext &sig);
 void ReportNewDeleteSizeMismatch(uptr addr, uptr delete_size,
                                  BufferedStackTrace *free_stack);




More information about the llvm-commits mailing list