diff --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt index db077b565da4d7b27b6592e3ff0235087e2df8a2..60caa5c4ffc90667b06c38f6d22b3037fc19e8f5 100644 --- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt @@ -140,6 +140,7 @@ set(SANITIZER_HEADERS sanitizer_syscall_linux_x86_64.inc sanitizer_syscall_linux_aarch64.inc sanitizer_thread_registry.h + sanitizer_vector.h sanitizer_win.h) include_directories(..) diff --git a/compiler-rt/lib/tsan/rtl/tsan_vector.h b/compiler-rt/lib/sanitizer_common/sanitizer_vector.h similarity index 78% rename from compiler-rt/lib/tsan/rtl/tsan_vector.h rename to compiler-rt/lib/sanitizer_common/sanitizer_vector.h index a7fb3fa58d54365eb4f8c992a15b1db17ee6fd5c..25cfeed35f223f2c535f74109e8a81102777fa76 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_vector.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_vector.h @@ -1,4 +1,4 @@ -//===-- tsan_vector.h -------------------------------------------*- C++ -*-===// +//===-- sanitizer_vector.h -------------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -7,38 +7,37 @@ // //===----------------------------------------------------------------------===// // -// This file is a part of ThreadSanitizer (TSan), a race detector. +// This file is shared between sanitizers run-time libraries. // //===----------------------------------------------------------------------===// // Low-fat STL-like vector container. -#ifndef TSAN_VECTOR_H -#define TSAN_VECTOR_H +#ifndef SANITIZER_VECTOR_H +#define SANITIZER_VECTOR_H -#include "tsan_defs.h" -#include "tsan_mman.h" +#include "sanitizer_common/sanitizer_allocator_internal.h" +#include "sanitizer_common/sanitizer_libc.h" -namespace __tsan { +namespace __sanitizer { template class Vector { public: - explicit Vector(MBlockType typ) - : typ_(typ) - , begin_() + explicit Vector() + : begin_() , end_() , last_() { } ~Vector() { if (begin_) - internal_free(begin_); + InternalFree(begin_); } void Reset() { if (begin_) - internal_free(begin_); + InternalFree(begin_); begin_ = 0; end_ = 0; last_ = 0; @@ -91,7 +90,6 @@ class Vector { } private: - const MBlockType typ_; T *begin_; T *end_; T *last_; @@ -109,10 +107,10 @@ class Vector { cap = 16; if (cap < size) cap = size; - T *p = (T*)internal_alloc(typ_, cap * sizeof(T)); + T *p = (T*)InternalAlloc(cap * sizeof(T)); if (cap0) { internal_memcpy(p, begin_, cap0 * sizeof(T)); - internal_free(begin_); + InternalFree(begin_); } begin_ = p; end_ = begin_ + size; @@ -122,6 +120,6 @@ class Vector { Vector(const Vector&); void operator=(const Vector&); }; -} // namespace __tsan +} // namespace __sanitizer -#endif // #ifndef TSAN_VECTOR_H +#endif // #ifndef SANITIZER_VECTOR_H diff --git a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt index 2e55257dab2ed0b6f597651baf41ff53ea310665..1bccaa78f39bd69a2bab41978361695443951f75 100644 --- a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt @@ -34,7 +34,8 @@ set(SANITIZER_UNITTESTS sanitizer_suppressions_test.cc sanitizer_symbolizer_test.cc sanitizer_test_main.cc - sanitizer_thread_registry_test.cc) + sanitizer_thread_registry_test.cc + sanitizer_vector_test.cc) set(SANITIZER_TEST_HEADERS sanitizer_pthread_wrappers.h diff --git a/compiler-rt/lib/tsan/tests/unit/tsan_vector_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc similarity index 74% rename from compiler-rt/lib/tsan/tests/unit/tsan_vector_test.cc rename to compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc index c54ac1ee6de94c0178415307bf916ebd5849f2b1..33ed14e190c521617cb2da536fdaebbffccd1141 100644 --- a/compiler-rt/lib/tsan/tests/unit/tsan_vector_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_vector_test.cc @@ -1,4 +1,4 @@ -//===-- tsan_vector_test.cc -----------------------------------------------===// +//===-- sanitizer_vector_test.cc ------------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -7,17 +7,16 @@ // //===----------------------------------------------------------------------===// // -// This file is a part of ThreadSanitizer (TSan), a race detector. +// This file is a part of *Sanitizer runtime. // //===----------------------------------------------------------------------===// -#include "tsan_vector.h" -#include "tsan_rtl.h" +#include "sanitizer_common/sanitizer_vector.h" #include "gtest/gtest.h" -namespace __tsan { +namespace __sanitizer { TEST(Vector, Basic) { - Vector v(MBlockScopedBuf); + Vector v; EXPECT_EQ(v.Size(), (uptr)0); v.PushBack(42); EXPECT_EQ(v.Size(), (uptr)1); @@ -29,7 +28,7 @@ TEST(Vector, Basic) { } TEST(Vector, Stride) { - Vector v(MBlockScopedBuf); + Vector v; for (int i = 0; i < 1000; i++) { v.PushBack(i); EXPECT_EQ(v.Size(), (uptr)(i + 1)); @@ -40,4 +39,4 @@ TEST(Vector, Stride) { } } -} // namespace __tsan +} // namespace __sanitizer diff --git a/compiler-rt/lib/tsan/CMakeLists.txt b/compiler-rt/lib/tsan/CMakeLists.txt index 145cd623d84aad3604a4a6b3e7efa6474424bc69..b85762bb8cd360b5cf384fbc8d29ed964fd02e66 100644 --- a/compiler-rt/lib/tsan/CMakeLists.txt +++ b/compiler-rt/lib/tsan/CMakeLists.txt @@ -93,8 +93,7 @@ set(TSAN_HEADERS rtl/tsan_symbolize.h rtl/tsan_sync.h rtl/tsan_trace.h - rtl/tsan_update_shadow_word_inl.h - rtl/tsan_vector.h) + rtl/tsan_update_shadow_word_inl.h) set(TSAN_RUNTIME_LIBRARIES) add_compiler_rt_component(tsan) diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc index f3c354fa291890a93b267912eb04c16dd2b7ac21..b6e8693686e45191ce8844e3bb74878c40acac01 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc @@ -200,7 +200,7 @@ struct InterceptorContext { Vector AtExitStack; InterceptorContext() - : libignore(LINKER_INITIALIZED), AtExitStack(MBlockAtExit) { + : libignore(LINKER_INITIALIZED), AtExitStack() { } }; diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc b/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc index f68a0468de53b15dd2a51da13cb987d2b70247bf..a7922a42e42cedb06219c37bd73e851ab5f671bd 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc @@ -14,6 +14,7 @@ #include "sanitizer_common/sanitizer_internal_defs.h" #include "sanitizer_common/sanitizer_placement_new.h" #include "sanitizer_common/sanitizer_stacktrace.h" +#include "sanitizer_common/sanitizer_vector.h" #include "tsan_interface_ann.h" #include "tsan_mutex.h" #include "tsan_report.h" @@ -21,7 +22,6 @@ #include "tsan_mman.h" #include "tsan_flags.h" #include "tsan_platform.h" -#include "tsan_vector.h" #define CALLERPC ((uptr)__builtin_return_address(0)) @@ -185,10 +185,10 @@ void PrintMatchedBenignRaces() { int unique_count = 0; int hit_count = 0; int add_count = 0; - Vector hit_matched(MBlockScopedBuf); + Vector hit_matched; CollectMatchedBenignRaces(&hit_matched, &unique_count, &hit_count, &ExpectRace::hitcount); - Vector add_matched(MBlockScopedBuf); + Vector add_matched; CollectMatchedBenignRaces(&add_matched, &unique_count, &add_count, &ExpectRace::addcount); if (hit_matched.Size()) { diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cc b/compiler-rt/lib/tsan/rtl/tsan_report.cc index be5d6b7ea364972a4b6dfd0037f47e1094616d67..af47076968d3553b1b38aacd760ad4c31eead823 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_report.cc @@ -48,18 +48,18 @@ class Decorator: public __sanitizer::SanitizerCommonDecorator { ReportDesc::ReportDesc() : tag(kExternalTagNone) - , stacks(MBlockReportStack) - , mops(MBlockReportMop) - , locs(MBlockReportLoc) - , mutexes(MBlockReportMutex) - , threads(MBlockReportThread) - , unique_tids(MBlockReportThread) + , stacks() + , mops() + , locs() + , mutexes() + , threads() + , unique_tids() , sleep() , count() { } ReportMop::ReportMop() - : mset(MBlockReportMutex) { + : mset() { } ReportDesc::~ReportDesc() { diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.h b/compiler-rt/lib/tsan/rtl/tsan_report.h index bc1582f90fe4bdd464734c1459695d3f976f9df5..cdc999c6af1de8dbf1c59f98247c384a1c3b1880 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.h +++ b/compiler-rt/lib/tsan/rtl/tsan_report.h @@ -14,8 +14,8 @@ #define TSAN_REPORT_H #include "sanitizer_common/sanitizer_symbolizer.h" +#include "sanitizer_common/sanitizer_vector.h" #include "tsan_defs.h" -#include "tsan_vector.h" namespace __tsan { diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index 8e12fb67f441fd6e7dd5f989164241722ff60800..17b820977c26615532d9876e6d75de71c31efa83 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -102,8 +102,8 @@ Context::Context() , thread_registry(new(thread_registry_placeholder) ThreadRegistry( CreateThreadContext, kMaxTid, kThreadQuarantineSize, kMaxTidReuse)) , racy_mtx(MutexTypeRacy, StatMtxRacy) - , racy_stacks(MBlockRacyStacks) - , racy_addresses(MBlockRacyAddresses) + , racy_stacks() + , racy_addresses() , fired_suppressions_mtx(MutexTypeFired, StatMtxFired) , fired_suppressions(8) , clock_alloc("clock allocator") { @@ -121,7 +121,7 @@ ThreadState::ThreadState(Context *ctx, int tid, int unique_id, u64 epoch, // , ignore_interceptors() , clock(tid, reuse_count) #if !SANITIZER_GO - , jmp_bufs(MBlockJmpBuf) + , jmp_bufs() #endif , tid(tid) , unique_id(unique_id) diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index 8967a4b5257b07227686619d1ef272a6ea062a1c..7d44ccae989320f0dd937fae0a230b2c9b759f24 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -34,12 +34,13 @@ #include "sanitizer_common/sanitizer_libignore.h" #include "sanitizer_common/sanitizer_suppressions.h" #include "sanitizer_common/sanitizer_thread_registry.h" +#include "sanitizer_common/sanitizer_vector.h" #include "tsan_clock.h" #include "tsan_defs.h" #include "tsan_flags.h" +#include "tsan_mman.h" #include "tsan_sync.h" #include "tsan_trace.h" -#include "tsan_vector.h" #include "tsan_report.h" #include "tsan_platform.h" #include "tsan_mutexset.h" diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc index 37b2768053f1603af65f5598d78ce569aa1ac2b1..cc582ab50190c94abf81b4b9a395fb558acf4db0 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc @@ -393,7 +393,7 @@ void RestoreStack(int tid, const u64 epoch, VarSizeStackTrace *stk, const u64 ebegin = RoundDown(eend, kTracePartSize); DPrintf("#%d: RestoreStack epoch=%zu ebegin=%zu eend=%zu partidx=%d\n", tid, (uptr)epoch, (uptr)ebegin, (uptr)eend, partidx); - Vector stack(MBlockReportStack); + Vector stack; stack.Resize(hdr->stack0.size + 64); for (uptr i = 0; i < hdr->stack0.size; i++) { stack[i] = hdr->stack0.trace[i]; @@ -659,7 +659,7 @@ void ReportRace(ThreadState *thr) { return; // MutexSet is too large to live on stack. - Vector mset_buffer(MBlockScopedBuf); + Vector mset_buffer; mset_buffer.Resize(sizeof(MutexSet) / sizeof(u64) + 1); MutexSet *mset2 = new(&mset_buffer[0]) MutexSet(); diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc index 83fab082afe3a78c5dd4b928eea6580c480a1d54..e4d65b9a909bea6669e42b8c472204f28e78b91a 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc @@ -211,7 +211,7 @@ void ThreadFinalize(ThreadState *thr) { if (!flags()->report_thread_leaks) return; ThreadRegistryLock l(ctx->thread_registry); - Vector leaks(MBlockScopedBuf); + Vector leaks; ctx->thread_registry->RunCallbackForEachThreadLocked( MaybeReportThreadLeak, &leaks); for (uptr i = 0; i < leaks.Size(); i++) { diff --git a/compiler-rt/lib/tsan/tests/unit/CMakeLists.txt b/compiler-rt/lib/tsan/tests/unit/CMakeLists.txt index 6898f641d6a005f0dcb322cefe5f09df1383e297..c08508d507917ba3f20fc7d5a637f24a03d4c5ec 100644 --- a/compiler-rt/lib/tsan/tests/unit/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/unit/CMakeLists.txt @@ -6,8 +6,7 @@ set(TSAN_UNIT_TEST_SOURCES tsan_shadow_test.cc tsan_stack_test.cc tsan_sync_test.cc - tsan_unit_test_main.cc - tsan_vector_test.cc) + tsan_unit_test_main.cc) add_tsan_unittest(TsanUnitTest SOURCES ${TSAN_UNIT_TEST_SOURCES})