diff options
-rwxr-xr-x | compiler-rt/lib/tsan/go/buildgo.sh | 4 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/go/tsan_go.cc | 31 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_platform.h | 3 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc | 5 |
4 files changed, 24 insertions, 19 deletions
diff --git a/compiler-rt/lib/tsan/go/buildgo.sh b/compiler-rt/lib/tsan/go/buildgo.sh index c4cff836c93..36813ae3e1d 100755 --- a/compiler-rt/lib/tsan/go/buildgo.sh +++ b/compiler-rt/lib/tsan/go/buildgo.sh @@ -33,9 +33,9 @@ for F in $SRCS; do cat $F >> gotsan.cc done -CFLAGS=" -I../rtl -I../.. -I../../sanitizer_common -fPIC -g -Wall -Werror -ffreestanding -fno-exceptions -DTSAN_GO -DSANITIZER_GO" +CFLAGS=" -I../rtl -I../.. -I../../sanitizer_common -fPIC -g -Wall -Werror -ffreestanding -fno-exceptions -DTSAN_GO -DSANITIZER_GO -DTSAN_SHADOW_COUNT=4" if [ "$DEBUG" == "" ]; then - CFLAGS+=" -DTSAN_DEBUG=0 -O3 -fno-omit-frame-pointer" + CFLAGS+=" -DTSAN_DEBUG=0 -O3 -fomit-frame-pointer" else CFLAGS+=" -DTSAN_DEBUG=1 -g" fi diff --git a/compiler-rt/lib/tsan/go/tsan_go.cc b/compiler-rt/lib/tsan/go/tsan_go.cc index 9f4df9ed2e5..11f14dac2c9 100644 --- a/compiler-rt/lib/tsan/go/tsan_go.cc +++ b/compiler-rt/lib/tsan/go/tsan_go.cc @@ -22,7 +22,7 @@ struct ThreadStatePlaceholder { uptr opaque[sizeof(ThreadState) / sizeof(uptr) + kCacheLineSize]; }; -static ThreadStatePlaceholder *threads; +static ThreadState *goroutines[kMaxTid]; void InitializeInterceptors() { } @@ -139,11 +139,15 @@ enum Tsan1EventType { LAST_EVENT // Should not appear. }; +static void AllocGoroutine(int tid) { + goroutines[tid] = (ThreadState*)internal_alloc(MBlockThreadContex, + sizeof(ThreadState)); + internal_memset(goroutines[tid], 0, sizeof(ThreadState)); +} + void __tsan_init() { - threads = (ThreadStatePlaceholder*)internal_alloc(MBlockThreadContex, - kMaxTid * sizeof(ThreadStatePlaceholder)); - //!!! internal_memset(threads, 0, kMaxTid * sizeof(ThreadStatePlaceholder)); - ThreadState *thr = (ThreadState*)&threads[0]; + AllocGoroutine(0); + ThreadState *thr = goroutines[0]; thr->in_rtl++; Initialize(thr); thr->in_rtl--; @@ -151,7 +155,7 @@ void __tsan_init() { void __tsan_fini() { // FIXME: Not necessary thread 0. - ThreadState *thr = (ThreadState*)&threads[0]; + ThreadState *thr = goroutines[0]; thr->in_rtl++; int res = Finalize(thr); thr->in_rtl--; @@ -159,9 +163,7 @@ void __tsan_fini() { } void __tsan_event(int typ, int tid, void *pc, void *addr, int info) { - //if (typ != READ && typ != WRITE && typ != SBLOCK_ENTER) - // Printf("typ=%d tid=%d pc=%p addr=%p info=%d\n", typ, tid, pc, addr, info); - ThreadState *thr = (ThreadState*)&threads[tid]; + ThreadState *thr = goroutines[tid]; switch (typ) { case READ: MemoryAccess(thr, (uptr)pc, (uptr)addr, 0, false); @@ -195,23 +197,22 @@ void __tsan_event(int typ, int tid, void *pc, void *addr, int info) { case FREE: break; case THR_START: { - //Printf("typ=%d tid=%d pc=%p addr=%p info=%d\n", typ, tid, pc, addr, info); if (tid == 0) return; - ThreadState *parent = (ThreadState*)&threads[info]; + ThreadState *parent = goroutines[info]; + AllocGoroutine(tid); + thr = goroutines[tid]; thr->in_rtl++; parent->in_rtl++; int tid2 = ThreadCreate(parent, (uptr)pc, 0, true); - CHECK_EQ(tid2, tid); ThreadStart(thr, tid2); parent->in_rtl--; thr->in_rtl--; break; } default: - thr->in_rtl++; - Printf("Event: typ=%d thr=%d\n", typ, tid); - thr->in_rtl--; + Printf("Unknown event type %d\n", typ); + Die(); } } diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h b/compiler-rt/lib/tsan/rtl/tsan_platform.h index 15051454497..30137982ef4 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_platform.h +++ b/compiler-rt/lib/tsan/rtl/tsan_platform.h @@ -43,7 +43,8 @@ static const uptr kLinuxAppMemMsk = 0x7c0000000000ULL; #define MemToShadow(addr) \ (((addr) & ~(kLinuxAppMemMsk | (kShadowCell - 1))) * kShadowCnt) #else -#define MemToShadow(addr) (((addr) * kShadowCnt) | kLinuxShadowMsk) +#define MemToShadow(addr) \ + ((((addr) & ~(kShadowCell - 1)) * kShadowCnt) | kLinuxShadowMsk) #endif static const uptr kLinuxShadowBeg = MemToShadow(kLinuxAppMemBeg); diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc index bc842754812..3c8b1fd3926 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc @@ -43,7 +43,6 @@ bool WEAK OnReport(const ReportDesc *rep, bool suppressed) { } static void StackStripMain(ReportStack *stack) { -#ifndef TSAN_GO ReportStack *last_frame = 0; ReportStack *last_frame2 = 0; const char *prefix = "__interceptor_"; @@ -65,6 +64,7 @@ static void StackStripMain(ReportStack *stack) { if (last_frame2 == 0) return; const char *last = last_frame->func; +#ifndef TSAN_GO const char *last2 = last_frame2->func; // Strip frame above 'main' if (last2 && 0 == internal_strcmp(last2, "main")) { @@ -83,6 +83,9 @@ static void StackStripMain(ReportStack *stack) { // due to our fault. TsanPrintf("Bottom stack frame of stack %zx is missed\n", stack->pc); } +#else + if (last && 0 == internal_strcmp(last, "schedunlock")) + last_frame2->next = 0; #endif } |