[compiler-rt] 7b302fc - tsan: strip top inlined internal frames

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 15 10:37:49 PDT 2021


Author: Dmitry Vyukov
Date: 2021-07-15T19:37:44+02:00
New Revision: 7b302fc9b04c7991cdb869b65316e0d72e41042e

URL: https://github.com/llvm/llvm-project/commit/7b302fc9b04c7991cdb869b65316e0d72e41042e
DIFF: https://github.com/llvm/llvm-project/commit/7b302fc9b04c7991cdb869b65316e0d72e41042e.diff

LOG: tsan: strip top inlined internal frames

The new GET_CURRENT_PC() can lead to spurious top inlined internal frames.
Here are 2 examples from bots, in both cases the malloc is supposed to be
the top frame (#0):

  WARNING: ThreadSanitizer: signal-unsafe call inside of a signal
    #0 __sanitizer::StackTrace::GetNextInstructionPc(unsigned long)
    #1 malloc

  Location is heap block of size 99 at 0xbe3800003800 allocated by thread T1:
    #0 __sanitizer::StackTrace::GetNextInstructionPc(unsigned long)
    #1 malloc

Let's strip these internal top frames from reports.
With other code changes I also observed some top frames
from __tsan::ScopedInterceptor, proactively remove these as well.

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

Added: 
    

Modified: 
    compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
index 706794fdad10..6c2d9a7e929a 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
@@ -47,7 +47,24 @@ void __tsan_on_report(const ReportDesc *rep) {
   (void)rep;
 }
 
-static void StackStripMain(SymbolizedStack *frames) {
+bool InternalFrame(const char *func) {
+  static const char *frames[] = {
+      "__tsan::ScopedInterceptor",
+      "__sanitizer::StackTrace",
+  };
+  for (auto frame : frames) {
+    if (!internal_strncmp(func, frame, internal_strlen(frame)))
+      return true;
+  }
+  return false;
+}
+
+static SymbolizedStack *StackStripMain(SymbolizedStack *frames) {
+  for (; frames && frames->info.function; frames = frames->next) {
+    // Remove top inlined frames from our interceptors.
+    if (!InternalFrame(frames->info.function))
+      break;
+  }
   SymbolizedStack *last_frame = nullptr;
   SymbolizedStack *last_frame2 = nullptr;
   for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
@@ -56,7 +73,7 @@ static void StackStripMain(SymbolizedStack *frames) {
   }
 
   if (last_frame2 == 0)
-    return;
+    return frames;
 #if !SANITIZER_GO
   const char *last = last_frame->info.function;
   const char *last2 = last_frame2->info.function;
@@ -69,7 +86,8 @@ static void StackStripMain(SymbolizedStack *frames) {
     last_frame->ClearAll();
     last_frame2->next = nullptr;
   // Strip global ctors init.
-  } else if (last && 0 == internal_strcmp(last, "__do_global_ctors_aux")) {
+  } else if (last && (0 == internal_strcmp(last, "__do_global_ctors_aux") ||
+                      0 == internal_strcmp(last, "__libc_csu_init"))) {
     last_frame->ClearAll();
     last_frame2->next = nullptr;
   // If both are 0, then we probably just failed to symbolize.
@@ -85,6 +103,7 @@ static void StackStripMain(SymbolizedStack *frames) {
   last_frame->ClearAll();
   last_frame2->next = nullptr;
 #endif
+  return frames;
 }
 
 ReportStack *SymbolizeStackId(u32 stack_id) {
@@ -118,10 +137,8 @@ static ReportStack *SymbolizeStack(StackTrace trace) {
     last->next = top;
     top = ent;
   }
-  StackStripMain(top);
-
   ReportStack *stack = ReportStack::New();
-  stack->frames = top;
+  stack->frames = StackStripMain(top);
   return stack;
 }
 


        


More information about the llvm-commits mailing list