[compiler-rt] r221225 - [TSan] Don't strip binary/library name until the moment we print it.

Alexey Samsonov vonosmas at gmail.com
Mon Nov 3 17:55:21 PST 2014


Author: samsonov
Date: Mon Nov  3 19:55:20 2014
New Revision: 221225

URL: http://llvm.org/viewvc/llvm-project?rev=221225&view=rev
Log:
[TSan] Don't strip binary/library name until the moment we print it.

This commit changes the place where TSan runtime turns full path
to binary or shared library into its basename
(/usr/foo/mybinary -> mybinary). Instead of doing it as early as possible
(when we obtained the full path from the symbolizer), we now do it as
late as possible (right before printing the error report).

This seems like a right thing to do - stripping to basename is a detail
of report formatting implementation, and should belong there. Also, we
might need the full path at some point - for example, to match the
suppressions.

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc
    compiler-rt/trunk/test/tsan/global_race.cc
    compiler-rt/trunk/test/tsan/simple_stack2.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc?rev=221225&r1=221224&r2=221225&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc Mon Nov  3 19:55:20 2014
@@ -102,10 +102,13 @@ void PrintStack(const ReportStack *ent)
     Printf("    #%d %s %s:%d", i, ent->func, ent->file, ent->line);
     if (ent->col)
       Printf(":%d", ent->col);
-    if (ent->module && ent->offset)
-      Printf(" (%s+%p)\n", ent->module, (void*)ent->offset);
-    else
+    if (ent->module && ent->offset) {
+      char *stripped_module = StripModuleName(ent->module);
+      Printf(" (%s+%p)\n", stripped_module, (void*)ent->offset);
+      InternalFree(stripped_module);
+    } else {
       Printf(" (%p)\n", (void*)ent->pc);
+    }
   }
   Printf("\n");
 }
@@ -147,8 +150,10 @@ static void PrintLocation(const ReportLo
   bool print_stack = false;
   Printf("%s", d.Location());
   if (loc->type == ReportLocationGlobal) {
+    char *stripped_module = StripModuleName(loc->module);
     Printf("  Location is global '%s' of size %zu at %p (%s+%p)\n\n",
-               loc->name, loc->size, loc->addr, loc->module, loc->offset);
+               loc->name, loc->size, loc->addr, stripped_module, loc->offset);
+    InternalFree(stripped_module);
   } else if (loc->type == ReportLocationHeap) {
     char thrbuf[kThreadBufSize];
     Printf("  Location is heap block of size %zu at %p allocated by %s:\n",

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc?rev=221225&r1=221224&r2=221225&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_symbolize.cc Mon Nov  3 19:55:20 2014
@@ -46,7 +46,8 @@ ReportStack *NewReportStackEntry(uptr ad
 
 static ReportStack *NewReportStackEntry(const AddressInfo &info) {
   ReportStack *ent = NewReportStackEntry(info.address);
-  ent->module = StripModuleName(info.module);
+  if (info.module)
+    ent->module = internal_strdup(info.module);
   ent->offset = info.module_offset;
   if (info.function)
     ent->func = internal_strdup(info.function);
@@ -127,7 +128,8 @@ ReportLocation *SymbolizeData(uptr addr)
                                                         sizeof(ReportLocation));
   internal_memset(ent, 0, sizeof(*ent));
   ent->type = ReportLocationGlobal;
-  ent->module = StripModuleName(info.module);
+  if (info.module)
+    ent->module = internal_strdup(info.module);
   ent->offset = info.module_offset;
   if (info.name)
     ent->name = internal_strdup(info.name);

Modified: compiler-rt/trunk/test/tsan/global_race.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/global_race.cc?rev=221225&r1=221224&r2=221225&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/global_race.cc (original)
+++ compiler-rt/trunk/test/tsan/global_race.cc Mon Nov  3 19:55:20 2014
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %T/global_race_bin && %deflake %run %T/global_race_bin | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
@@ -24,5 +24,5 @@ int main() {
 
 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
 // CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'GlobalData' of size 40 at [[ADDR]] ({{.*}}+0x{{[0-9,a-f]+}})
+// CHECK: Location is global 'GlobalData' of size 40 at [[ADDR]] (global_race_bin+0x{{[0-9,a-f]+}})
 

Modified: compiler-rt/trunk/test/tsan/simple_stack2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/simple_stack2.cc?rev=221225&r1=221224&r2=221225&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/simple_stack2.cc (original)
+++ compiler-rt/trunk/test/tsan/simple_stack2.cc Mon Nov  3 19:55:20 2014
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %T/simple_stack2_bin && %deflake %run %T/simple_stack2_bin | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -44,10 +44,10 @@ int main() {
 
 // CHECK:      WARNING: ThreadSanitizer: data race
 // CHECK-NEXT:   Write of size 4 at {{.*}} by thread T1:
-// CHECK-NEXT:     #0 foo1{{.*}} {{.*}}simple_stack2.cc:9{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #1 bar1{{.*}} {{.*}}simple_stack2.cc:16{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #2 Thread1{{.*}} {{.*}}simple_stack2.cc:34{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #0 foo1{{.*}} {{.*}}simple_stack2.cc:9{{(:3)?}} (simple_stack2_bin+{{.*}})
+// CHECK-NEXT:     #1 bar1{{.*}} {{.*}}simple_stack2.cc:16{{(:3)?}} (simple_stack2_bin+{{.*}})
+// CHECK-NEXT:     #2 Thread1{{.*}} {{.*}}simple_stack2.cc:34{{(:3)?}} (simple_stack2_bin+{{.*}})
 // CHECK:        Previous read of size 4 at {{.*}} by main thread:
-// CHECK-NEXT:     #0 foo2{{.*}} {{.*}}simple_stack2.cc:20{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #1 bar2{{.*}} {{.*}}simple_stack2.cc:29{{(:3)?}} ({{.*}})
-// CHECK-NEXT:     #2 main{{.*}} {{.*}}simple_stack2.cc:41{{(:3)?}} ({{.*}})
+// CHECK-NEXT:     #0 foo2{{.*}} {{.*}}simple_stack2.cc:20{{(:3)?}} (simple_stack2_bin+{{.*}})
+// CHECK-NEXT:     #1 bar2{{.*}} {{.*}}simple_stack2.cc:29{{(:3)?}} (simple_stack2_bin+{{.*}})
+// CHECK-NEXT:     #2 main{{.*}} {{.*}}simple_stack2.cc:41{{(:3)?}} (simple_stack2_bin+{{.*}})





More information about the llvm-commits mailing list