[llvm-commits] [compiler-rt] r156991 - in /compiler-rt/trunk/lib/tsan: rtl/tsan_flags.cc rtl/tsan_flags.h rtl/tsan_interceptors.cc rtl/tsan_mman.cc rtl/tsan_rtl.cc rtl/tsan_rtl.h rtl/tsan_rtl_thread.cc rtl/tsan_suppressions.cc rtl/tsan_suppressions.h unit_tests/tsan_flags_test.cc unit_tests/tsan_suppressions_test.cc

Dmitry Vyukov dvyukov at google.com
Thu May 17 08:00:28 PDT 2012


Author: dvyukov
Date: Thu May 17 10:00:27 2012
New Revision: 156991

URL: http://llvm.org/viewvc/llvm-project?rev=156991&view=rev
Log:
tsan: remove shutdown code
tsan runtime shutdown is problematic for 2 reasons:
1. others crash during shutdown
2. we have to override user exit status (don't know it and can't return from atexit handler)

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_mman.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_thread.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h
    compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc
    compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc?rev=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Thu May 17 10:00:27 2012
@@ -40,8 +40,8 @@
   f->report_thread_leaks = true;
   f->report_signal_unsafe = true;
   f->force_seq_cst_atomics = false;
-  f->strip_path_prefix = internal_strdup("");
-  f->suppressions = internal_strdup("");
+  f->strip_path_prefix = "";
+  f->suppressions = "";
   f->exitcode = 66;
   f->log_fileno = 2;
   f->atexit_sleep_ms = 1000;
@@ -65,11 +65,6 @@
   Flag(env, &f->verbosity, "verbosity");
 }
 
-void FinalizeFlags(Flags *flags) {
-  internal_free((void*)flags->strip_path_prefix);
-  internal_free((void*)flags->suppressions);
-}
-
 static const char *GetFlagValue(const char *env, const char *name,
                                 const char **end) {
   if (env == 0)

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h?rev=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.h Thu May 17 10:00:27 2012
@@ -50,7 +50,6 @@
 
 Flags *flags();
 void InitializeFlags(Flags *flags, const char *env);
-void FinalizeFlags(Flags *flags);
 }
 
 #endif  // TSAN_FLAGS_H

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu May 17 10:00:27 2012
@@ -195,7 +195,8 @@
     usleep(flags()->atexit_sleep_ms * 1000);
   }
   int status = Finalize(cur_thread());
-  _exit(status);
+  if (status)
+    _exit(status);
 }
 
 TSAN_INTERCEPTOR(int, atexit, void (*f)()) {

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=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc Thu May 17 10:00:27 2012
@@ -94,44 +94,16 @@
   return b;
 }
 
-#if TSAN_DEBUG
-struct InternalMBlock {
-  static u32 const kMagic = 0xBCEBC041;
-  u32 magic;
-  u32 typ;
-  u64 sz;
-};
-#endif
-
 void *internal_alloc(MBlockType typ, uptr sz) {
   ThreadState *thr = cur_thread();
   CHECK_GT(thr->in_rtl, 0);
-#if TSAN_DEBUG
-  InternalMBlock *b = (InternalMBlock*)Alloc(sizeof(InternalMBlock) + sz);
-  b->magic = InternalMBlock::kMagic;
-  b->typ = typ;
-  b->sz = sz;
-  thr->int_alloc_cnt[typ] += 1;
-  thr->int_alloc_siz[typ] += sz;
-  void *p = b + 1;
-  return p;
-#else
   return Alloc(sz);
-#endif
 }
 
 void internal_free(void *p) {
   ThreadState *thr = cur_thread();
   CHECK_GT(thr->in_rtl, 0);
-#if TSAN_DEBUG
-  InternalMBlock *b = (InternalMBlock*)p - 1;
-  CHECK_EQ(b->magic, InternalMBlock::kMagic);
-  thr->int_alloc_cnt[b->typ] -= 1;
-  thr->int_alloc_siz[b->typ] -= b->sz;
-  Free(b);
-#else
   Free(p);
-#endif
 }
 
 }  // namespace __tsan

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=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Thu May 17 10:00:27 2012
@@ -120,11 +120,7 @@
   Context *ctx = __tsan::ctx;
   bool failed = false;
 
-  // Be very careful beyond that point.
-  // All bets are off. Everything is destroyed.
-  ThreadFinish(thr);
   ThreadFinalize(thr);
-  FinalizeFlags(&ctx->flags);
 
   if (ctx->nreported) {
     failed = true;
@@ -138,27 +134,7 @@
   }
 
   StatOutput(ctx->stat);
-  FinalizeSuppressions();
-  FinalizePlatform();
-
-  const int exitcode = failed ? flags()->exitcode : 0;
-  const int log_fileno = flags()->log_fileno;
-  __tsan::ctx->~Context();
-  __tsan::ctx = 0;
-
-  InternalAllocStatAggregate(ctx, thr);
-
-  for (int i = 0; i < (int)MBlockTypeCount; i++) {
-    if (ctx->int_alloc_cnt[i] == 0 && ctx->int_alloc_siz[i] == 0)
-      continue;
-    InternalScopedBuf<char> tmp(1024);
-    Snprintf(tmp, tmp.Size(), "ThreadSanitizer: Internal memory leak: "
-        "type=%d count=%lld size=%lld\n",
-        (int)i, ctx->int_alloc_cnt[i], ctx->int_alloc_siz[i]);
-    internal_write(log_fileno, tmp, internal_strlen(tmp));
-  }
-
-  return exitcode;
+  return failed ? flags()->exitcode : 0;
 }
 
 static void TraceSwitch(ThreadState *thr) {
@@ -417,15 +393,6 @@
     thr->fast_state.ClearIgnoreBit();
 }
 
-void InternalAllocStatAggregate(Context *ctx, ThreadState *thr) {
-  for (int i = 0; i < (int)MBlockTypeCount; i++) {
-    ctx->int_alloc_cnt[i] += thr->int_alloc_cnt[i];
-    ctx->int_alloc_siz[i] += thr->int_alloc_siz[i];
-    thr->int_alloc_cnt[i] = 0;
-    thr->int_alloc_siz[i] = 0;
-  }
-}
-
 #if TSAN_DEBUG
 void build_consistency_debug() {}
 #else

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=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Thu May 17 10:00:27 2012
@@ -246,8 +246,6 @@
   uptr shadow_stack[kShadowStackSize];
   ThreadClock clock;
   u64 stat[StatCnt];
-  u64 int_alloc_cnt[MBlockTypeCount];
-  u64 int_alloc_siz[MBlockTypeCount];
   const int tid;
   int in_rtl;
   int func_call_count;
@@ -386,7 +384,6 @@
   void operator = (const ScopedReport&);
 };
 
-void InternalAllocStatAggregate(Context *ctx, ThreadState *thr);
 void StatAggregate(u64 *dst, u64 *src);
 void StatOutput(u64 *stat);
 void ALWAYS_INLINE INLINE StatInc(ThreadState *thr, StatType typ, u64 n = 1) {

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=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl_thread.cc Thu May 17 10:00:27 2012
@@ -45,8 +45,6 @@
     if (tctx == 0)
       continue;
     MaybeReportThreadLeak(tctx);
-    DestroyAndFree(tctx);
-    ctx->threads[i] = 0;
   }
 }
 
@@ -222,7 +220,6 @@
 
   thr->~ThreadState();
   StatAggregate(ctx->stat, thr->stat);
-  InternalAllocStatAggregate(ctx, thr);
   tctx->thr = 0;
 }
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc?rev=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc Thu May 17 10:00:27 2012
@@ -125,25 +125,11 @@
   return head;
 }
 
-void SuppressionFree(Suppression *supp) {
-  while (supp) {
-    Suppression *tmp = supp;
-    supp = tmp->next;
-    internal_free(tmp->func);
-    internal_free(tmp);
-  }
-}
-
 void InitializeSuppressions() {
   char *supp = ReadFile(flags()->suppressions);
   g_suppressions = SuppressionParse(supp);
 }
 
-void FinalizeSuppressions() {
-  SuppressionFree(g_suppressions);
-  g_suppressions = 0;
-}
-
 bool IsSuppressed(ReportType typ, const ReportStack *stack) {
   if (g_suppressions == 0 || stack == 0)
     return false;

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h?rev=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.h Thu May 17 10:00:27 2012
@@ -34,9 +34,9 @@
   SuppressionType type;
   char *func;
 };
+
 Suppression *SuppressionParse(const char* supp);
 bool SuppressionMatch(char *templ, const char *str);
-void SuppressionFree(Suppression *supp);
 
 }  // namespace __tsan
 

Modified: compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc?rev=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc (original)
+++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc Thu May 17 10:00:27 2012
@@ -81,27 +81,21 @@
 
   InitializeFlags(&f, 0);
   EXPECT_EQ(0, strcmp(f.strip_path_prefix, ""));
-  FinalizeFlags(&f);
 
   InitializeFlags(&f, "strip_path_prefix");
   EXPECT_EQ(0, strcmp(f.strip_path_prefix, ""));
-  FinalizeFlags(&f);
 
   InitializeFlags(&f, "--strip_path_prefix=");
   EXPECT_EQ(0, strcmp(f.strip_path_prefix, ""));
-  FinalizeFlags(&f);
 
   InitializeFlags(&f, "--strip_path_prefix=abc");
   EXPECT_EQ(0, strcmp(f.strip_path_prefix, "abc"));
-  FinalizeFlags(&f);
 
   InitializeFlags(&f, "--strip_path_prefix='abc zxc'");
   EXPECT_EQ(0, strcmp(f.strip_path_prefix, "abc zxc"));
-  FinalizeFlags(&f);
 
   InitializeFlags(&f, "--strip_path_prefix=\"abc zxc\"");
   EXPECT_EQ(0, strcmp(f.strip_path_prefix, "abc zxc"));
-  FinalizeFlags(&f);
 }
 
 }  // namespace __tsan

Modified: compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc?rev=156991&r1=156990&r2=156991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc (original)
+++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc Thu May 17 10:00:27 2012
@@ -41,7 +41,6 @@
   EXPECT_EQ(0, strcmp(supp->func, "foo"));
   supp = supp->next;
   EXPECT_EQ((Suppression*)0, supp);
-  SuppressionFree(supp0);
 }
 
 TEST(Suppressions, Parse2) {
@@ -61,7 +60,6 @@
   EXPECT_EQ(0, strcmp(supp->func, "bar"));
   supp = supp->next;
   EXPECT_EQ((Suppression*)0, supp);
-  SuppressionFree(supp0);
 }
 
 TEST(Suppressions, Parse3) {
@@ -79,7 +77,6 @@
   EXPECT_EQ(0, strcmp(supp->func, "foo"));
   supp = supp->next;
   EXPECT_EQ((Suppression*)0, supp);
-  SuppressionFree(supp0);
 }
 
 TEST(Suppressions, ParseType) {
@@ -104,7 +101,6 @@
   EXPECT_EQ(0, strcmp(supp->func, "foo"));
   supp = supp->next;
   EXPECT_EQ((Suppression*)0, supp);
-  SuppressionFree(supp0);
 }
 
 static bool MyMatch(const char *templ, const char *func) {





More information about the llvm-commits mailing list