sanitizer_common: prohibit Mutex(LINKER_INITIALIZED)
authorDmitry Vyukov <dvyukov@google.com>
Wed, 28 Jul 2021 11:08:49 +0000 (13:08 +0200)
committerDmitry Vyukov <dvyukov@google.com>
Wed, 28 Jul 2021 13:09:44 +0000 (15:09 +0200)
Mutex does not support LINKER_INITIALIZED ctor.
But we used to support it with BlockingMutex.
To prevent potential bugs delete LINKER_INITIALIZED Mutex ctor.
Also mark existing ctor as explicit.

Depends on D106944.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D106945

compiler-rt/lib/sanitizer_common/sanitizer_mutex.h

index cbd1c25eb69f7c1b6776565f409b37ab8f6a4806..2d3db282f7c3bc905c2a0c163cbab4c0c56fceda 100644 (file)
@@ -111,7 +111,7 @@ struct MutexMeta {
 
 class CheckedMutex {
  public:
-  constexpr CheckedMutex(MutexType type)
+  explicit constexpr CheckedMutex(MutexType type)
 #if SANITIZER_CHECK_DEADLOCKS
       : type_(type)
 #endif
@@ -154,7 +154,8 @@ class CheckedMutex {
 // but this attribute is not supported by some older compilers.
 class MUTEX Mutex : CheckedMutex {
  public:
-  constexpr Mutex(MutexType type = MutexUnchecked) : CheckedMutex(type) {}
+  explicit constexpr Mutex(MutexType type = MutexUnchecked)
+      : CheckedMutex(type) {}
 
   void Lock() ACQUIRE() {
     CheckedMutex::Lock();
@@ -331,6 +332,7 @@ class MUTEX Mutex : CheckedMutex {
   static constexpr u64 kWriterLock = 1ull << (3 * kCounterWidth);
   static constexpr u64 kWriterSpinWait = 1ull << (3 * kCounterWidth + 1);
 
+  Mutex(LinkerInitialized) = delete;
   Mutex(const Mutex &) = delete;
   void operator=(const Mutex &) = delete;
 };