From 8f1632d5c1e32912365f5673d832e0e8c8080a89 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Tue, 4 Nov 2014 01:55:20 +0000 Subject: [PATCH] [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. llvm-svn: 221225 --- compiler-rt/lib/tsan/rtl/tsan_report.cc | 13 +++++++++---- compiler-rt/lib/tsan/rtl/tsan_symbolize.cc | 6 ++++-- compiler-rt/test/tsan/global_race.cc | 4 ++-- compiler-rt/test/tsan/simple_stack2.cc | 14 +++++++------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cc b/compiler-rt/lib/tsan/rtl/tsan_report.cc index c5b5c74..e237290 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_report.cc @@ -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 ReportLocation *loc) { 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", diff --git a/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc b/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc index d2ce6f3..451e6eb 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_symbolize.cc @@ -46,7 +46,8 @@ ReportStack *NewReportStackEntry(uptr addr) { 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); diff --git a/compiler-rt/test/tsan/global_race.cc b/compiler-rt/test/tsan/global_race.cc index d74b4d5..f4e8bc8 100644 --- a/compiler-rt/test/tsan/global_race.cc +++ b/compiler-rt/test/tsan/global_race.cc @@ -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 #include #include @@ -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]+}}) diff --git a/compiler-rt/test/tsan/simple_stack2.cc b/compiler-rt/test/tsan/simple_stack2.cc index ae1c27b..df3d31e 100644 --- a/compiler-rt/test/tsan/simple_stack2.cc +++ b/compiler-rt/test/tsan/simple_stack2.cc @@ -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 #include #include @@ -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+{{.*}}) -- 2.7.4