[llvm-commits] [compiler-rt] r162902 - in /compiler-rt/trunk/lib: sanitizer_common/ sanitizer_common/tests/ tsan/output_tests/ tsan/rtl/
Dmitry Vyukov
dvyukov at google.com
Thu Aug 30 06:57:25 PDT 2012
Done in r162908.
On Thu, Aug 30, 2012 at 5:27 PM, Kostya Serebryany <kcc at google.com> wrote:
>
>
> On Thu, Aug 30, 2012 at 5:02 PM, Dmitry Vyukov <dvyukov at google.com> wrote:
>
>> Author: dvyukov
>> Date: Thu Aug 30 08:02:30 2012
>> New Revision: 162902
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=162902&view=rev
>> Log:
>> tsan: use stack depot to describe heap blocks
>>
>> Added:
>> compiler-rt/trunk/lib/tsan/output_tests/race_on_heap.cc
>> Modified:
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc
>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.h
>>
>> compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
>> compiler-rt/trunk/lib/tsan/output_tests/race_on_mutex.c
>> compiler-rt/trunk/lib/tsan/output_tests/simple_stack.c
>> compiler-rt/trunk/lib/tsan/output_tests/simple_stack2.cc
>> compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
>> compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc
>> compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h
>> compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc
>> compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
>> compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
>> compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
>> compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h
>> (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator64.h Thu
>> Aug 30 08:02:30 2012
>> @@ -176,7 +176,16 @@
>> return (reinterpret_cast<uptr>(p) / kRegionSize) % kNumClasses;
>> }
>>
>> - uptr GetActuallyAllocatedSize(void *p) {
>> + static void *GetBlockBegin(void *p) {
>> + uptr u = (uptr)p;
>> + uptr s = GetActuallyAllocatedSize(p);
>> + uptr regBeg = u & ~(kRegionSize - 1);
>> + uptr regOff = u - regBeg;
>> + uptr begin = regBeg + regOff / s * s;
>>
>
>
> Why you don't use GetChunkIdx()?
> In your implementation you have 64-bit division, while GetChunkIdx uses
> faster 32-bit division
>
>
>
>> + return (void*)begin;
>> + }
>> +
>> + static uptr GetActuallyAllocatedSize(void *p) {
>> CHECK(PointerIsMine(p));
>> return SizeClassMap::Size(GetSizeClass(p));
>> }
>> @@ -415,6 +424,16 @@
>> return GetHeader(p) + 1;
>> }
>>
>> + void *GetBlockBegin(void *p) {
>> + SpinMutexLock l(&mutex_);
>> + for (Header *l = list_; l; l = l->next) {
>> + void *b = GetUser(l);
>> + if (p >= b && p < (u8*)b + l->size)
>> + return b;
>> + }
>> + return 0;
>> + }
>> +
>> private:
>> struct Header {
>> uptr size;
>> @@ -512,6 +531,12 @@
>> return secondary_.GetMetaData(p);
>> }
>>
>> + void *GetBlockBegin(void *p) {
>> + if (primary_.PointerIsMine(p))
>> + return primary_.GetBlockBegin(p);
>> + return secondary_.GetBlockBegin(p);
>> + }
>> +
>> uptr GetActuallyAllocatedSize(void *p) {
>> if (primary_.PointerIsMine(p))
>> return primary_.GetActuallyAllocatedSize(p);
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc
>> (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.cc Thu
>> Aug 30 08:02:30 2012
>> @@ -33,7 +33,7 @@
>> u32 seq;
>> } depot;
>>
>> -static uptr hash(uptr *stack, uptr size) {
>> +static uptr hash(const uptr *stack, uptr size) {
>> return 0;
>> }
>>
>> @@ -51,7 +51,7 @@
>> return s;
>> }
>>
>> -u32 StackDepotPut(uptr *stack, uptr size) {
>> +u32 StackDepotPut(const uptr *stack, uptr size) {
>> if (stack == 0 || size == 0)
>> return 0;
>> uptr h = hash(stack, size);
>> @@ -71,7 +71,7 @@
>> return s->id;
>> }
>>
>> -uptr *StackDepotGet(u32 id, uptr *size) {
>> +const uptr *StackDepotGet(u32 id, uptr *size) {
>> if (id == 0)
>> return 0;
>> SpinMutexLock l(&depot.mtx);
>>
>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.h?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.h
>> (original)
>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stackdepot.h Thu Aug
>> 30 08:02:30 2012
>> @@ -20,9 +20,9 @@
>> // StackDepot efficiently stores huge amounts of stack traces.
>>
>> // Maps stack trace to an unique id.
>> -u32 StackDepotPut(uptr *stack, uptr size);
>> +u32 StackDepotPut(const uptr *stack, uptr size);
>> // Retrieves a stored stack trace by the id.
>> -uptr *StackDepotGet(u32 id, uptr *size);
>> +const uptr *StackDepotGet(u32 id, uptr *size);
>>
>> } // namespace __sanitizer
>>
>>
>> Modified:
>> compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> ---
>> compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
>> (original)
>> +++
>> compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
>> Thu Aug 30 08:02:30 2012
>> @@ -21,7 +21,7 @@
>> uptr s1[] = {1, 2, 3, 4, 5};
>> u32 i1 = StackDepotPut(s1, ARRAY_SIZE(s1));
>> uptr sz1 = 0;
>> - uptr *sp1 = StackDepotGet(i1, &sz1);
>> + const uptr *sp1 = StackDepotGet(i1, &sz1);
>> EXPECT_NE(sp1, (uptr*)0);
>> EXPECT_EQ(sz1, ARRAY_SIZE(s1));
>> EXPECT_EQ(internal_memcmp(sp1?:s1, s1, sizeof(s1)), 0);
>> @@ -29,14 +29,20 @@
>>
>> TEST(SanitizerCommon, StackDepotAbsent) {
>> uptr sz1 = 0;
>> - uptr *sp1 = StackDepotGet(-10, &sz1);
>> + const uptr *sp1 = StackDepotGet(-10, &sz1);
>> EXPECT_EQ(sp1, (uptr*)0);
>> }
>>
>> -TEST(SanitizerCommon, StackDepotZero) {
>> +TEST(SanitizerCommon, StackDepotEmptyStack) {
>> u32 i1 = StackDepotPut(0, 0);
>> uptr sz1 = 0;
>> - uptr *sp1 = StackDepotGet(i1, &sz1);
>> + const uptr *sp1 = StackDepotGet(i1, &sz1);
>> + EXPECT_EQ(sp1, (uptr*)0);
>> +}
>> +
>> +TEST(SanitizerCommon, StackDepotZeroId) {
>> + uptr sz1 = 0;
>> + const uptr *sp1 = StackDepotGet(0, &sz1);
>> EXPECT_EQ(sp1, (uptr*)0);
>> }
>>
>> @@ -46,7 +52,7 @@
>> u32 i2 = StackDepotPut(s1, ARRAY_SIZE(s1));
>> EXPECT_EQ(i1, i2);
>> uptr sz1 = 0;
>> - uptr *sp1 = StackDepotGet(i1, &sz1);
>> + const uptr *sp1 = StackDepotGet(i1, &sz1);
>> EXPECT_NE(sp1, (uptr*)0);
>> EXPECT_EQ(sz1, ARRAY_SIZE(s1));
>> EXPECT_EQ(internal_memcmp(sp1?:s1, s1, sizeof(s1)), 0);
>>
>> Added: compiler-rt/trunk/lib/tsan/output_tests/race_on_heap.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/output_tests/race_on_heap.cc?rev=162902&view=auto
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/output_tests/race_on_heap.cc (added)
>> +++ compiler-rt/trunk/lib/tsan/output_tests/race_on_heap.cc Thu Aug 30
>> 08:02:30 2012
>> @@ -0,0 +1,46 @@
>> +#include <pthread.h>
>> +#include <stdlib.h>
>> +#include <stdio.h>
>> +
>> +void *Thread1(void *p) {
>> + *(int*)p = 42;
>> + return 0;
>> +}
>> +
>> +void *Thread2(void *p) {
>> + *(int*)p = 44;;
>> + return 0;
>> +}
>> +
>> +void *alloc() {
>> + return malloc(99);
>> +}
>> +
>> +void *AllocThread(void*) {
>> + return alloc();
>> +}
>> +
>> +int main() {
>> + void *p = 0;
>> + pthread_t t[2];
>> + pthread_create(&t[0], 0, AllocThread, 0);
>> + pthread_join(t[0], &p);
>> + fprintf(stderr, "addr=%p\n", p);
>> + pthread_create(&t[0], 0, Thread1, (char*)p + 16);
>> + pthread_create(&t[1], 0, Thread2, (char*)p + 16);
>> + pthread_join(t[0], 0);
>> + pthread_join(t[1], 0);
>> + return 0;
>> +}
>> +
>> +// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
>> +// CHECK: WARNING: ThreadSanitizer: data race
>> +//...
>> +// CHECK: Location is heap block of size 99 at [[ADDR]] allocated by
>> thread 1:
>> +// CHECK: #0 alloc
>> +// CHECK: #1 AllocThread
>> +//...
>> +// CHECK: Thread 1 (finished) created at:
>> +// CHECK: #0 pthread_create
>> +// CHECK: #1 main
>> +
>>
>> Modified: compiler-rt/trunk/lib/tsan/output_tests/race_on_mutex.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/output_tests/race_on_mutex.c?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/output_tests/race_on_mutex.c (original)
>> +++ compiler-rt/trunk/lib/tsan/output_tests/race_on_mutex.c Thu Aug 30
>> 08:02:30 2012
>> @@ -34,8 +34,8 @@
>>
>> // CHECK: WARNING: ThreadSanitizer: data race
>> // CHECK-NEXT: Read of size 1 at {{.*}} by thread 2:
>> -// CHECK-NEXT: #0 pthread_mutex_lock {{.*}} ({{.*}})
>> -// CHECK-NEXT: #1 Thread2 {{.*}}race_on_mutex.c:19{{(:3)?}} ({{.*}})
>> -// CHECK-NEXT: Previous write of size 1 at {{.*}} by thread 1:
>> +// CHECK-NEXT: #0 pthread_mutex_lock
>> +// CHECK-NEXT: #1 Thread2{{.*}} {{.*}}race_on_mutex.c:19{{(:3)?}}
>> ({{.*}})
>> +// CHECK: Previous write of size 1 at {{.*}} by thread 1:
>> // CHECK-NEXT: #0 pthread_mutex_init {{.*}} ({{.*}})
>> -// CHECK-NEXT: #1 Thread1 {{.*}}race_on_mutex.c:10{{(:3)?}} ({{.*}})
>> +// CHECK-NEXT: #1 Thread1{{.*}} {{.*}}race_on_mutex.c:10{{(:3)?}}
>> ({{.*}})
>>
>> Modified: compiler-rt/trunk/lib/tsan/output_tests/simple_stack.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/output_tests/simple_stack.c?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/output_tests/simple_stack.c (original)
>> +++ compiler-rt/trunk/lib/tsan/output_tests/simple_stack.c Thu Aug 30
>> 08:02:30 2012
>> @@ -48,18 +48,18 @@
>>
>> // CHECK: WARNING: ThreadSanitizer: data race
>> // CHECK-NEXT: Write of size 4 at {{.*}} by thread 1:
>> -// CHECK-NEXT: #0 foo1 {{.*}}simple_stack.c:8{{(:3)?}} ({{.*}})
>> -// CHECK-NEXT: #1 bar1 {{.*}}simple_stack.c:13{{(:3)?}} ({{.*}})
>> -// CHECK-NEXT: #2 Thread1 {{.*}}simple_stack.c:27{{(:3)?}} ({{.*}})
>> -// CHECK-NEXT: Previous read of size 4 at {{.*}} by thread 2:
>> -// CHECK-NEXT: #0 foo2 {{.*}}simple_stack.c:17{{(:26)?}} ({{.*}})
>> -// CHECK-NEXT: #1 bar2 {{.*}}simple_stack.c:22{{(:3)?}} ({{.*}})
>> -// CHECK-NEXT: #2 Thread2 {{.*}}simple_stack.c:32{{(:3)?}} ({{.*}})
>> -// CHECK-NEXT: Thread 1 (running) created at:
>> +// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack.c:8{{(:3)?}} ({{.*}})
>> +// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack.c:13{{(:3)?}}
>> ({{.*}})
>> +// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack.c:27{{(:3)?}}
>> ({{.*}})
>> +// CHECK: Previous read of size 4 at {{.*}} by thread 2:
>> +// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack.c:17{{(:26)?}}
>> ({{.*}})
>> +// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack.c:22{{(:3)?}}
>> ({{.*}})
>> +// CHECK-NEXT: #2 Thread2{{.*}} {{.*}}simple_stack.c:32{{(:3)?}}
>> ({{.*}})
>> +// CHECK: Thread 1 (running) created at:
>> // CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})
>> -// CHECK-NEXT: #1 StartThread {{.*}}simple_stack.c:37{{(:3)?}}
>> ({{.*}})
>> -// CHECK-NEXT: #2 main {{.*}}simple_stack.c:42{{(:3)?}} ({{.*}})
>> -// CHECK-NEXT: Thread 2 ({{.*}}) created at:
>> +// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:37{{(:3)?}}
>> ({{.*}})
>> +// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:42{{(:3)?}}
>> ({{.*}})
>> +// CHECK: Thread 2 ({{.*}}) created at:
>> // CHECK-NEXT: #0 pthread_create {{.*}} ({{.*}})
>> -// CHECK-NEXT: #1 StartThread {{.*}}simple_stack.c:37{{(:3)?}}
>> ({{.*}})
>> -// CHECK-NEXT: #2 main {{.*}}simple_stack.c:43{{(:3)?}} ({{.*}})
>> +// CHECK-NEXT: #1 StartThread{{.*}} {{.*}}simple_stack.c:37{{(:3)?}}
>> ({{.*}})
>> +// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack.c:43{{(:3)?}}
>> ({{.*}})
>>
>> Modified: compiler-rt/trunk/lib/tsan/output_tests/simple_stack2.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/output_tests/simple_stack2.cc?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/output_tests/simple_stack2.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/output_tests/simple_stack2.cc Thu Aug 30
>> 08:02:30 2012
>> @@ -40,7 +40,7 @@
>> // CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cc:8{{(:3)?}}
>> ({{.*}})
>> // CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cc:13{{(:3)?}}
>> ({{.*}})
>> // CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cc:27{{(:3)?}}
>> ({{.*}})
>> -// CHECK-NEXT: Previous read of size 4 at {{.*}} by main thread:
>> +// CHECK: Previous read of size 4 at {{.*}} by main thread:
>> // CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cc:17{{(:28)?}}
>> ({{.*}})
>> // CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cc:22{{(:3)?}}
>> ({{.*}})
>> // CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cc:34{{(:3)?}}
>> ({{.*}})
>>
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc Thu Aug 30 08:02:30 2012
>> @@ -12,6 +12,7 @@
>>
>> //===----------------------------------------------------------------------===//
>> #include "sanitizer_common/sanitizer_common.h"
>> #include "sanitizer_common/sanitizer_placement_new.h"
>> +#include "sanitizer_common/sanitizer_stackdepot.h"
>> #include "tsan_mman.h"
>> #include "tsan_rtl.h"
>> #include "tsan_report.h"
>> @@ -19,8 +20,8 @@
>>
>> namespace __tsan {
>>
>> -extern char allocator_placeholder[];
>> -INLINE Allocator *allocator() {
>> +static char allocator_placeholder[sizeof(Allocator)] ALIGNED(64);
>> +Allocator *allocator() {
>> return reinterpret_cast<Allocator*>(&allocator_placeholder);
>> }
>>
>> @@ -49,6 +50,11 @@
>> return 0;
>> MBlock *b = (MBlock*)allocator()->GetMetaData(p);
>> b->size = sz;
>> + b->alloc_tid = thr->unique_id;
>> + b->alloc_stack_id = 0;
>> + if (thr->shadow_stack_pos) // May happen during bootstrap.
>> + b->alloc_stack_id = StackDepotPut(thr->shadow_stack,
>> + thr->shadow_stack_pos - thr->shadow_stack);
>> if (CTX() && CTX()->initialized) {
>> MemoryRangeImitateWrite(thr, pc, (uptr)p, sz);
>> }
>> @@ -102,7 +108,7 @@
>> }
>>
>> MBlock *user_mblock(ThreadState *thr, void *p) {
>> - CHECK_GT(thr->in_rtl, 0);
>> + // CHECK_GT(thr->in_rtl, 0);
>> CHECK_NE(p, (void*)0);
>> return (MBlock*)allocator()->GetMetaData(p);
>> }
>>
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.cc Thu Aug 30 08:02:30 2012
>> @@ -141,7 +141,7 @@
>> TsanPrintf("ThreadSanitizer: internal deadlock detected\n");
>> TsanPrintf("ThreadSanitizer: can't lock %d while under %zu\n",
>> t, (uptr)max_idx);
>> - Die();
>> + CHECK(0);
>> }
>> }
>>
>> @@ -256,4 +256,8 @@
>> #endif
>> }
>>
>> +void Mutex::CheckLocked() {
>> + CHECK_NE(atomic_load(&state_, memory_order_relaxed), 0);
>> +}
>> +
>> } // namespace __tsan
>>
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_mutex.h Thu Aug 30 08:02:30 2012
>> @@ -45,6 +45,8 @@
>> void ReadLock();
>> void ReadUnlock();
>>
>> + void CheckLocked();
>> +
>> private:
>> atomic_uintptr_t state_;
>> #if TSAN_DEBUG
>>
>> 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=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_report.cc Thu Aug 30 08:02:30 2012
>> @@ -58,6 +58,7 @@
>> else
>> TsanPrintf(" (%p)\n", (void*)ent->pc);
>> }
>> + TsanPrintf("\n");
>> }
>>
>> static void PrintMop(const ReportMop *mop, bool first) {
>> @@ -77,8 +78,12 @@
>> TsanPrintf(" Location is global '%s' of size %zu at %zx %s:%d\n",
>> loc->name, loc->size, loc->addr, loc->file, loc->line);
>> } else if (loc->type == ReportLocationHeap) {
>> - TsanPrintf(" Location is heap of size %zu at %zx allocated "
>> - "by thread %d:\n", loc->size, loc->addr, loc->tid);
>> + TsanPrintf(" Location is heap block of size %zu at %p allocated",
>> + loc->size, loc->addr);
>> + if (loc->tid == 0)
>> + TsanPrintf(" by main thread:\n");
>> + else
>> + TsanPrintf(" by thread %d:\n", loc->tid);
>> PrintStack(loc->stack);
>> } else if (loc->type == ReportLocationStack) {
>> TsanPrintf(" Location is stack of thread %d:\n", loc->tid);
>>
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Thu Aug 30 08:02:30 2012
>> @@ -32,7 +32,6 @@
>>
>> #ifndef TSAN_GO
>> THREADLOCAL char cur_thread_placeholder[sizeof(ThreadState)] ALIGNED(64);
>> -char allocator_placeholder[sizeof(Allocator)] ALIGNED(64);
>> #endif
>> static char ctx_placeholder[sizeof(Context)] ALIGNED(64);
>>
>> @@ -52,7 +51,7 @@
>> }
>>
>> // The objects are allocated in TLS, so one may rely on
>> zero-initialization.
>> -ThreadState::ThreadState(Context *ctx, int tid, u64 epoch,
>> +ThreadState::ThreadState(Context *ctx, int tid, int unique_id, u64 epoch,
>> uptr stk_addr, uptr stk_size,
>> uptr tls_addr, uptr tls_size)
>> : fast_state(tid, epoch)
>> @@ -63,6 +62,7 @@
>> // , in_rtl()
>> , shadow_stack_pos(&shadow_stack[0])
>> , tid(tid)
>> + , unique_id(unique_id)
>> , stk_addr(stk_addr)
>> , stk_size(stk_size)
>> , tls_addr(tls_addr)
>>
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Thu Aug 30 08:02:30 2012
>> @@ -42,6 +42,8 @@
>> struct MBlock {
>> Mutex mtx;
>> uptr size;
>> + u32 alloc_tid;
>> + u32 alloc_stack_id;
>> SyncVar *head;
>> };
>>
>> @@ -60,6 +62,7 @@
>> typedef LargeMmapAllocator SecondaryAllocator;
>> typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
>> SecondaryAllocator> Allocator;
>> +Allocator *allocator();
>> #endif
>>
>> void TsanPrintf(const char *format, ...);
>> @@ -270,6 +273,7 @@
>> #endif
>> u64 stat[StatCnt];
>> const int tid;
>> + const int unique_id;
>> int in_rtl;
>> bool is_alive;
>> const uptr stk_addr;
>> @@ -286,7 +290,7 @@
>> // If set, malloc must not be called.
>> int nomalloc;
>>
>> - explicit ThreadState(Context *ctx, int tid, u64 epoch,
>> + explicit ThreadState(Context *ctx, int tid, int unique_id, u64 epoch,
>> uptr stk_addr, uptr stk_size,
>> uptr tls_addr, uptr tls_size);
>> };
>>
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_report.cc Thu Aug 30 08:02:30
>> 2012
>> @@ -13,6 +13,7 @@
>>
>> #include "sanitizer_common/sanitizer_libc.h"
>> #include "sanitizer_common/sanitizer_placement_new.h"
>> +#include "sanitizer_common/sanitizer_stackdepot.h"
>> #include "tsan_platform.h"
>> #include "tsan_rtl.h"
>> #include "tsan_suppressions.h"
>> @@ -150,6 +151,10 @@
>> }
>>
>> void ScopedReport::AddThread(const ThreadContext *tctx) {
>> + for (uptr i = 0; i < rep_->threads.Size(); i++) {
>> + if (rep_->threads[i]->id == tctx->tid)
>> + return;
>> + }
>> void *mem = internal_alloc(MBlockReportThread, sizeof(ReportThread));
>> ReportThread *rt = new(mem) ReportThread();
>> rep_->threads.PushBack(rt);
>> @@ -158,6 +163,17 @@
>> rt->stack = SymbolizeStack(tctx->creation_stack);
>> }
>>
>> +static ThreadContext *FindThread(int unique_id) {
>> + CTX()->thread_mtx.CheckLocked();
>> + for (unsigned i = 0; i < kMaxTid; i++) {
>> + ThreadContext *tctx = CTX()->threads[i];
>> + if (tctx && tctx->unique_id == unique_id) {
>> + return tctx;
>> + }
>> + }
>> + return 0;
>> +}
>> +
>> void ScopedReport::AddMutex(const SyncVar *s) {
>> void *mem = internal_alloc(MBlockReportMutex, sizeof(ReportMutex));
>> ReportMutex *rm = new(mem) ReportMutex();
>> @@ -167,6 +183,35 @@
>> }
>>
>> void ScopedReport::AddLocation(uptr addr, uptr size) {
>> + if (addr == 0)
>> + return;
>> +#ifndef TSAN_GO
>> + if (allocator()->PointerIsMine((void*)addr)) {
>> + MBlock *b = user_mblock(0, (void*)addr);
>> + ThreadContext *tctx = FindThread(b->alloc_tid);
>> + void *mem = internal_alloc(MBlockReportLoc, sizeof(ReportLocation));
>> + ReportLocation *loc = new(mem) ReportLocation();
>> + rep_->locs.PushBack(loc);
>> + loc->type = ReportLocationHeap;
>> + loc->addr = (uptr)allocator()->GetBlockBegin((void*)addr);
>> + loc->size = b->size;
>> + loc->tid = tctx ? tctx->tid : b->alloc_tid;
>> + loc->name = 0;
>> + loc->file = 0;
>> + loc->line = 0;
>> + loc->stack = 0;
>> + uptr ssz = 0;
>> + const uptr *stack = StackDepotGet(b->alloc_stack_id, &ssz);
>> + if (stack) {
>> + StackTrace trace;
>> + trace.Init(stack, ssz);
>> + loc->stack = SymbolizeStack(trace);
>> + }
>> + if (tctx)
>> + AddThread(tctx);
>> + return;
>> + }
>> +#endif
>> ReportStack *symb = SymbolizeData(addr);
>> if (symb) {
>> void *mem = internal_alloc(MBlockReportLoc, sizeof(ReportLocation));
>> @@ -181,6 +226,7 @@
>> loc->line = symb->line;
>> loc->stack = 0;
>> internal_free(symb);
>> + return;
>> }
>> }
>>
>> @@ -353,7 +399,7 @@
>> }
>>
>> // Ensure that we have at least something for the current thread.
>> - CHECK_EQ(traces[0].IsEmpty(), false);
>> + DCHECK_EQ(traces[0].IsEmpty(), false);
>>
>> for (uptr i = 0; i < kMop; i++) {
>> FastState s(thr->racy_state[i]);
>> @@ -363,6 +409,8 @@
>> rep.AddThread(tctx);
>> }
>>
>> + rep.AddLocation(addr_min, addr_max - addr_min);
>> +
>> if (!OutputReport(rep, rep.GetReport()->mops[0]->stack))
>> return;
>>
>>
>> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc
>> URL:
>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc?rev=162902&r1=162901&r2=162902&view=diff
>>
>> ==============================================================================
>> --- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc (original)
>> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc Thu Aug 30 08:02:30
>> 2012
>> @@ -171,8 +171,9 @@
>> tctx->status = ThreadStatusRunning;
>> tctx->epoch0 = tctx->epoch1 + 1;
>> tctx->epoch1 = (u64)-1;
>> - new(thr) ThreadState(CTX(), tid, tctx->epoch0, stk_addr, stk_size,
>> - tls_addr, tls_size);
>> + new(thr) ThreadState(CTX(), tid, tctx->unique_id,
>> + tctx->epoch0, stk_addr, stk_size,
>> + tls_addr, tls_size);
>> #ifdef TSAN_GO
>> // Setup dynamic shadow stack.
>> const int kInitStackSize = 8;
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120830/9ac9e3f4/attachment.html>
More information about the llvm-commits
mailing list