[compiler-rt] r229263 - tsan: fix build

Dmitry Vyukov dvyukov at google.com
Sat Feb 14 08:14:10 PST 2015


Author: dvyukov
Date: Sat Feb 14 10:14:10 2015
New Revision: 229263

URL: http://llvm.org/viewvc/llvm-project?rev=229263&view=rev
Log:
tsan: fix build

Revision 229127 introduced a bug:
zero value is not OK for trace headers,
because stack0 needs constructor call.
Instead unmap the unused part of trace after
all ctors have been executed.


Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h

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=229263&r1=229262&r2=229263&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Sat Feb 14 10:14:10 2015
@@ -67,14 +67,17 @@ static char thread_registry_placeholder[
 static ThreadContextBase *CreateThreadContext(u32 tid) {
   // Map thread trace when context is created.
   MapThreadTrace(GetThreadTrace(tid), TraceSize() * sizeof(Event));
-  MapThreadTrace(GetThreadTraceHeader(tid), sizeof(Trace));
-#if SANITIZER_DEBUG
+  const uptr hdr = GetThreadTraceHeader(tid);
+  MapThreadTrace(hdr, sizeof(Trace));
+  new((void*)hdr) Trace();
   // We are going to use only a small part of the trace with the default
   // value of history_size. However, the constructor writes to the whole trace.
-  // It writes mostly zeros, so freshly mmaped memory will do.
-  // The only non-zero field if mutex type used for debugging.
-  new(ThreadTrace(tid)) Trace();
-#endif
+  // Unmap the unused part.
+  uptr hdr_end = hdr + sizeof(Trace);
+  hdr_end -= sizeof(TraceHeader) * (kTraceParts - TraceParts());
+  hdr_end = RoundUp(hdr_end, GetPageSizeCached());
+  if (hdr_end < hdr + sizeof(Trace))
+    UnmapOrDie((void*)hdr_end, hdr + sizeof(Trace) - hdr_end);
   void *mem = internal_alloc(MBlockThreadContex, sizeof(ThreadContext));
   return new(mem) ThreadContext(tid);
 }

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h?rev=229263&r1=229262&r2=229263&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_trace.h Sat Feb 14 10:14:10 2015
@@ -54,13 +54,15 @@ struct TraceHeader {
 };
 
 struct Trace {
-  TraceHeader headers[kTraceParts];
   Mutex mtx;
 #ifndef SANITIZER_GO
   // Must be last to catch overflow as paging fault.
   // Go shadow stack is dynamically allocated.
   uptr shadow_stack[kShadowStackSize];
 #endif
+  // Must be the last field, because we unmap the unused part in
+  // CreateThreadContext.
+  TraceHeader headers[kTraceParts];
 
   Trace()
     : mtx(MutexTypeTrace, StatMtxTrace) {





More information about the llvm-commits mailing list