From a9eeddb616f0100cff76ffd23253dca2bac77420 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 21 Jul 2022 11:52:17 +0200 Subject: [PATCH] tsan: remove tracking of racy addresses We used to deduplicate based on the race address to prevent lots of repeated reports about the same race. But now we clear the shadow for the racy address in DoReportRace: // This prevents trapping on this address in future. for (uptr i = 0; i < kShadowCnt; i++) StoreShadow(&shadow_mem[i], i == 0 ? Shadow::kRodata : Shadow::kEmpty); It should have the same effect of not reporting duplicates (and actually better because it's automatically reset when the memory is reallocated). So drop the address deduplication code. Both simpler and faster. Reviewed By: melver Differential Revision: https://reviews.llvm.org/D130240 --- compiler-rt/lib/tsan/rtl/tsan_flags.inc | 4 --- compiler-rt/lib/tsan/rtl/tsan_rtl.cpp | 1 - compiler-rt/lib/tsan/rtl/tsan_rtl.h | 1 - compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp | 31 ------------------- .../lib/tsan/tests/unit/tsan_flags_test.cpp | 4 --- compiler-rt/test/tsan/stress.cpp | 2 +- 6 files changed, 1 insertion(+), 42 deletions(-) diff --git a/compiler-rt/lib/tsan/rtl/tsan_flags.inc b/compiler-rt/lib/tsan/rtl/tsan_flags.inc index c6a5fb8bc984..731d776cc893 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_flags.inc +++ b/compiler-rt/lib/tsan/rtl/tsan_flags.inc @@ -23,10 +23,6 @@ TSAN_FLAG(bool, enable_annotations, true, TSAN_FLAG(bool, suppress_equal_stacks, true, "Suppress a race report if we've already output another race report " "with the same stack.") -TSAN_FLAG(bool, suppress_equal_addresses, true, - "Suppress a race report if we've already output another race report " - "on the same address.") - TSAN_FLAG(bool, report_bugs, true, "Turns off bug reporting entirely (useful for benchmarking).") TSAN_FLAG(bool, report_thread_leaks, true, "Report thread leaks at exit?") diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp index 825a9d791ecc..e0a142c1de02 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp @@ -368,7 +368,6 @@ Context::Context() }), racy_mtx(MutexTypeRacy), racy_stacks(), - racy_addresses(), fired_suppressions_mtx(MutexTypeFired), slot_mtx(MutexTypeSlots), resetting() { diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index c8d3c48a0c0c..1ca80f390949 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -316,7 +316,6 @@ struct Context { Mutex racy_mtx; Vector racy_stacks; - Vector racy_addresses; // Number of fired suppressions may be large enough. Mutex fired_suppressions_mtx; InternalMmapVector fired_suppressions; diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp index 4cf8816489df..65fba470a795 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp @@ -629,35 +629,6 @@ static bool HandleRacyStacks(ThreadState *thr, VarSizeStackTrace traces[2]) { return false; } -static bool FindRacyAddress(const RacyAddress &ra0) { - for (uptr i = 0; i < ctx->racy_addresses.Size(); i++) { - RacyAddress ra2 = ctx->racy_addresses[i]; - uptr maxbeg = max(ra0.addr_min, ra2.addr_min); - uptr minend = min(ra0.addr_max, ra2.addr_max); - if (maxbeg < minend) { - VPrintf(2, "ThreadSanitizer: suppressing report as doubled (addr)\n"); - return true; - } - } - return false; -} - -static bool HandleRacyAddress(ThreadState *thr, uptr addr_min, uptr addr_max) { - if (!flags()->suppress_equal_addresses) - return false; - RacyAddress ra0 = {addr_min, addr_max}; - { - ReadLock lock(&ctx->racy_mtx); - if (FindRacyAddress(ra0)) - return true; - } - Lock lock(&ctx->racy_mtx); - if (FindRacyAddress(ra0)) - return true; - ctx->racy_addresses.PushBack(ra0); - return false; -} - bool OutputReport(ThreadState *thr, const ScopedReport &srep) { // These should have been checked in ShouldReport. // It's too late to check them here, we have already taken locks. @@ -761,8 +732,6 @@ void ReportRace(ThreadState *thr, RawShadow *shadow_mem, Shadow cur, Shadow old, uptr addr_max = max(end0, end1); if (IsExpectedReport(addr_min, addr_max - addr_min)) return; - if (HandleRacyAddress(thr, addr_min, addr_max)) - return; ReportType rep_typ = ReportTypeRace; if ((typ0 & kAccessVptr) && (typ1 & kAccessFree)) diff --git a/compiler-rt/lib/tsan/tests/unit/tsan_flags_test.cpp b/compiler-rt/lib/tsan/tests/unit/tsan_flags_test.cpp index 1e6dfe597ad7..9a2dfd5988eb 100644 --- a/compiler-rt/lib/tsan/tests/unit/tsan_flags_test.cpp +++ b/compiler-rt/lib/tsan/tests/unit/tsan_flags_test.cpp @@ -34,7 +34,6 @@ TEST(Flags, DefaultValues) { static const char *options1 = " enable_annotations=0" " suppress_equal_stacks=0" - " suppress_equal_addresses=0" " report_bugs=0" " report_thread_leaks=0" " report_destroy_locked=0" @@ -58,7 +57,6 @@ static const char *options1 = static const char *options2 = " enable_annotations=true" " suppress_equal_stacks=true" - " suppress_equal_addresses=true" " report_bugs=true" " report_thread_leaks=true" " report_destroy_locked=true" @@ -82,7 +80,6 @@ static const char *options2 = void VerifyOptions1(Flags *f) { EXPECT_EQ(f->enable_annotations, 0); EXPECT_EQ(f->suppress_equal_stacks, 0); - EXPECT_EQ(f->suppress_equal_addresses, 0); EXPECT_EQ(f->report_bugs, 0); EXPECT_EQ(f->report_thread_leaks, 0); EXPECT_EQ(f->report_destroy_locked, 0); @@ -106,7 +103,6 @@ void VerifyOptions1(Flags *f) { void VerifyOptions2(Flags *f) { EXPECT_EQ(f->enable_annotations, true); EXPECT_EQ(f->suppress_equal_stacks, true); - EXPECT_EQ(f->suppress_equal_addresses, true); EXPECT_EQ(f->report_bugs, true); EXPECT_EQ(f->report_thread_leaks, true); EXPECT_EQ(f->report_destroy_locked, true); diff --git a/compiler-rt/test/tsan/stress.cpp b/compiler-rt/test/tsan/stress.cpp index 9e1b3edfeb54..d1f0933aced0 100644 --- a/compiler-rt/test/tsan/stress.cpp +++ b/compiler-rt/test/tsan/stress.cpp @@ -1,7 +1,7 @@ // This run stresses global reset happenning concurrently with everything else. // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=flush_memory_ms=1:flush_symbolizer_ms=1:memory_limit_mb=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NORACE // This run stresses race reporting happenning concurrently with everything else. -// RUN: %clangxx_tsan -O1 %s -DRACE=1 -o %t && %env_tsan_opts=suppress_equal_stacks=0:suppress_equal_addresses=0 %deflake %run %t | FileCheck %s --check-prefix=CHECK-RACE +// RUN: %clangxx_tsan -O1 %s -DRACE=1 -o %t && %env_tsan_opts=suppress_equal_stacks=0 %deflake %run %t | FileCheck %s --check-prefix=CHECK-RACE #include "test.h" #include #include