From 19b855fe3ea4253a2d6ccde11dbee53269eb1762 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 17 May 2012 15:00:27 +0000 Subject: [PATCH] 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) llvm-svn: 156991 --- compiler-rt/lib/tsan/rtl/tsan_flags.cc | 9 ++---- compiler-rt/lib/tsan/rtl/tsan_flags.h | 1 - compiler-rt/lib/tsan/rtl/tsan_interceptors.cc | 3 +- compiler-rt/lib/tsan/rtl/tsan_mman.cc | 28 ----------------- compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 35 +--------------------- compiler-rt/lib/tsan/rtl/tsan_rtl.h | 3 -- compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc | 3 -- compiler-rt/lib/tsan/rtl/tsan_suppressions.cc | 14 --------- compiler-rt/lib/tsan/rtl/tsan_suppressions.h | 2 +- compiler-rt/lib/tsan/unit_tests/tsan_flags_test.cc | 6 ---- .../lib/tsan/unit_tests/tsan_suppressions_test.cc | 4 --- 11 files changed, 6 insertions(+), 102 deletions(-) diff --git a/compiler-rt/lib/tsan/rtl/tsan_flags.cc b/compiler-rt/lib/tsan/rtl/tsan_flags.cc index 77abd5b..95594c4 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_flags.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_flags.cc @@ -40,8 +40,8 @@ void InitializeFlags(Flags *f, const char *env) { 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 @@ void InitializeFlags(Flags *f, const char *env) { 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) diff --git a/compiler-rt/lib/tsan/rtl/tsan_flags.h b/compiler-rt/lib/tsan/rtl/tsan_flags.h index 1bad405..7a3c4af 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_flags.h +++ b/compiler-rt/lib/tsan/rtl/tsan_flags.h @@ -50,7 +50,6 @@ struct Flags { Flags *flags(); void InitializeFlags(Flags *flags, const char *env); -void FinalizeFlags(Flags *flags); } #endif // TSAN_FLAGS_H diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc index 3d22181..10b0581 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc @@ -195,7 +195,8 @@ static void finalize(void *arg) { usleep(flags()->atexit_sleep_ms * 1000); } int status = Finalize(cur_thread()); - _exit(status); + if (status) + _exit(status); } TSAN_INTERCEPTOR(int, atexit, void (*f)()) { diff --git a/compiler-rt/lib/tsan/rtl/tsan_mman.cc b/compiler-rt/lib/tsan/rtl/tsan_mman.cc index 124d5ca..93b97b8 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_mman.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_mman.cc @@ -94,44 +94,16 @@ MBlock *user_mblock(ThreadState *thr, void *p) { 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 diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index b6638276..28006f00 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -120,11 +120,7 @@ int Finalize(ThreadState *thr) { 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 @@ int Finalize(ThreadState *thr) { } 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 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 @@ void IgnoreCtl(ThreadState *thr, bool write, bool begin) { 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 diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index d789adb..2233774 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -246,8 +246,6 @@ struct ThreadState { 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 @@ class ScopedReport { 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) { diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc index b444077..fb44949 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc @@ -45,8 +45,6 @@ void ThreadFinalize(ThreadState *thr) { if (tctx == 0) continue; MaybeReportThreadLeak(tctx); - DestroyAndFree(tctx); - ctx->threads[i] = 0; } } @@ -222,7 +220,6 @@ void ThreadFinish(ThreadState *thr) { thr->~ThreadState(); StatAggregate(ctx->stat, thr->stat); - InternalAllocStatAggregate(ctx, thr); tctx->thr = 0; } diff --git a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc index d743614..a27a4bf 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc @@ -125,25 +125,11 @@ Suppression *SuppressionParse(const char* supp) { 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; diff --git a/compiler-rt/lib/tsan/rtl/tsan_suppressions.h b/compiler-rt/lib/tsan/rtl/tsan_suppressions.h index 06d7307..606ca6f 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_suppressions.h +++ b/compiler-rt/lib/tsan/rtl/tsan_suppressions.h @@ -34,9 +34,9 @@ struct Suppression { SuppressionType type; char *func; }; + Suppression *SuppressionParse(const char* supp); bool SuppressionMatch(char *templ, const char *str); -void SuppressionFree(Suppression *supp); } // namespace __tsan diff --git a/compiler-rt/lib/tsan/unit_tests/tsan_flags_test.cc b/compiler-rt/lib/tsan/unit_tests/tsan_flags_test.cc index 2e63011..197792e 100644 --- a/compiler-rt/lib/tsan/unit_tests/tsan_flags_test.cc +++ b/compiler-rt/lib/tsan/unit_tests/tsan_flags_test.cc @@ -81,27 +81,21 @@ TEST(Flags, ParseStr) { 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 diff --git a/compiler-rt/lib/tsan/unit_tests/tsan_suppressions_test.cc b/compiler-rt/lib/tsan/unit_tests/tsan_suppressions_test.cc index dbedeb2..1c0ff1b 100644 --- a/compiler-rt/lib/tsan/unit_tests/tsan_suppressions_test.cc +++ b/compiler-rt/lib/tsan/unit_tests/tsan_suppressions_test.cc @@ -41,7 +41,6 @@ TEST(Suppressions, Parse) { EXPECT_EQ(0, strcmp(supp->func, "foo")); supp = supp->next; EXPECT_EQ((Suppression*)0, supp); - SuppressionFree(supp0); } TEST(Suppressions, Parse2) { @@ -61,7 +60,6 @@ TEST(Suppressions, Parse2) { EXPECT_EQ(0, strcmp(supp->func, "bar")); supp = supp->next; EXPECT_EQ((Suppression*)0, supp); - SuppressionFree(supp0); } TEST(Suppressions, Parse3) { @@ -79,7 +77,6 @@ TEST(Suppressions, Parse3) { EXPECT_EQ(0, strcmp(supp->func, "foo")); supp = supp->next; EXPECT_EQ((Suppression*)0, supp); - SuppressionFree(supp0); } TEST(Suppressions, ParseType) { @@ -104,7 +101,6 @@ TEST(Suppressions, ParseType) { 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) { -- 2.7.4