summaryrefslogtreecommitdiff
path: root/lib/tsan/rtl/tsan_rtl_mutex.cc
AgeCommit message (Collapse)Author
2017-10-20[tsan] Add Mutex annotation flag for constant-initialized ↵Dmitry Vyukov
__tsan_mutex_linker_init behavior Add a new flag, _⁠_tsan_mutex_not_static, which has the opposite sense of _⁠_tsan_mutex_linker_init. When the new _⁠_tsan_mutex_not_static flag is passed to _⁠_tsan_mutex_destroy, tsan ignores the destruction unless the mutex was also created with the _⁠_tsan_mutex_not_static flag. This is useful for constructors that otherwise woud set _⁠_tsan_mutex_linker_init but cannot, because they are declared constexpr. Google has a custom mutex with two constructors, a "linker initialized" constructor that relies on zero-initialization and sets ⁠_⁠_tsan_mutex_linker_init, and a normal one which sets no tsan flags. The "linker initialized" constructor is morally constexpr, but we can't declare it constexpr because of the need to call into tsan as a side effect. With this new flag, the normal c'tor can set _⁠_tsan_mutex_not_static, the "linker initialized" constructor can rely on tsan's lazy initialization, and _⁠_tsan_mutex_destroy can still handle both cases correctly. Author: Greg Falcon (gfalcon) Reviewed in: https://reviews.llvm.org/D39095 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@316209 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-12tsan: prepare clock for future changesDmitry Vyukov
Pass ClockCache to ThreadClock::set and introduce ThreadCache::ResetCached. For now both are unused, but will reduce future diffs. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307784 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-01tsan: support linker init flag in __tsan_mutex_destroyDmitry Vyukov
For a linker init mutex with lazy flag setup (no __tsan_mutex_create call), it is possible that no lock/unlock happened before the destroy call. Then when destroy runs we still don't know that it is a linker init mutex and will emulate a memory write. This in turn can lead to false positives as the mutex is in fact linker initialized. Support linker init flag in destroy annotation to resolve this. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301795 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-26tsan: add new mutex annotationsDmitry Vyukov
There are several problems with the current annotations (AnnotateRWLockCreate and friends): - they don't fully support deadlock detection (we need a hook _before_ mutex lock) - they don't support insertion of random artificial delays to perturb execution (again we need a hook _before_ mutex lock) - they don't support setting extended mutex attributes like read/write reentrancy (only "linker init" was bolted on) - they don't support setting mutex attributes if a mutex don't have a "constructor" (e.g. static, Java, Go mutexes) - they don't ignore synchronization inside of lock/unlock operations which leads to slowdown and false negatives The new annotations solve of the above problems. See tsan_interface.h for the interface specification and comments. Reviewed in https://reviews.llvm.org/D31093 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298809 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-28tsan: always define SANITIZER_GODmitry Vyukov
Currently we either define SANITIZER_GO for Go or don't define it at all for C++. This works fine with preprocessor (ifdef/ifndef/defined), but does not work for C++ if statements (e.g. if (SANITIZER_GO) {...}). Also this is different from majority of SANITIZER_FOO macros which are always defined to either 0 or 1. Always define SANITIZER_GO to either 0 or 1. This allows to use SANITIZER_GO in expressions and in flag default values. Also remove kGoMode and kCppMode, which were meant to be used in expressions, but they are not defined in sanitizer_common code, so SANITIZER_GO become prevalent. Also convert some preprocessor checks to C++ if's or ternary expressions. Majority of this change is done mechanically with: sed "s#ifdef SANITIZER_GO#if SANITIZER_GO#g" sed "s#ifndef SANITIZER_GO#if \!SANITIZER_GO#g" sed "s#defined(SANITIZER_GO)#SANITIZER_GO#g" git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@285443 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-27tsan: don't create sync objects on acquireDmitry Vyukov
Creating sync objects on acquire is pointless: acquire of a just created sync object if a no-op. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@273862 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-03tsan: rely on AnnotateRWLockCreateStatic to detect linker-initialized mutexesDmitry Vyukov
The new annotation was added a while ago, but was not actually used. Use the annotation to detect linker-initialized mutexes instead of the broken IsGlobalVar which has both false positives and false negatives. Remove IsGlobalVar mess. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271663 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-27tsan: change tsan/Go interface for obtaining the current ProcessorDmitry Vyukov
Current interface assumes that Go calls ProcWire/ProcUnwire to establish the association between thread and proc. With the wisdom of hindsight, this interface does not work very well. I had to sprinkle Go scheduler with wire/unwire calls, and any mistake leads to hard to debug crashes. This is not something one wants to maintian. Fortunately, there is a simpler solution. We can ask Go runtime as to what is the current Processor, and that question is very easy to answer on Go side. Switch to such interface. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267703 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-27tsan: split thread into logical and physical stateDmitry Vyukov
This is reincarnation of http://reviews.llvm.org/D17648 with the bug fix pointed out by Adhemerval (zatrazz). Currently ThreadState holds both logical state (required for race-detection algorithm, user-visible) and physical state (various caches, most notably malloc cache). Move physical state in a new Process entity. Besides just being the right thing from abstraction point of view, this solves several problems: Cache everything on P level in Go. Currently we cache on a mix of goroutine and OS thread levels. This unnecessary increases memory consumption. Properly handle free operations in Go. Frees are issue by GC which don't have goroutine context. As the result we could not do anything more than just clearing shadow. For example, we leaked sync objects and heap block descriptors. This will allow to get rid of libc malloc in Go (now we have Processor context for internal allocator cache). This in turn will allow to get rid of dependency on libc entirely. Potentially we can make Processor per-CPU in C++ mode instead of per-thread, which will reduce resource consumption. The distinction between Thread and Processor is currently used only by Go, C++ creates Processor per OS thread, which is equivalent to the current scheme. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267678 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-16[tsan] Detect uses of uninitialized, destroyed and invalid mutexesKuba Brecka
This patch adds a new TSan report type, ReportTypeMutexInvalidAccess, which is triggered when pthread_mutex_lock or pthread_mutex_unlock returns EINVAL (this means the mutex is invalid, uninitialized or already destroyed). Differential Revision: http://reviews.llvm.org/D18132 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@263641 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-26tsan: revert r262037Dmitry Vyukov
Broke aarch64 and darwin bots. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@262046 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-26tsan: split thread into logical and physical stateDmitry Vyukov
Currently ThreadState holds both logical state (required for race-detection algorithm, user-visible) and physical state (various caches, most notably malloc cache). Move physical state in a new Process entity. Besides just being the right thing from abstraction point of view, this solves several problems: 1. Cache everything on P level in Go. Currently we cache on a mix of goroutine and OS thread levels. This unnecessary increases memory consumption. 2. Properly handle free operations in Go. Frees are issue by GC which don't have goroutine context. As the result we could not do anything more than just clearing shadow. For example, we leaked sync objects and heap block descriptors. 3. This will allow to get rid of libc malloc in Go (now we have Processor context for internal allocator cache). This in turn will allow to get rid of dependency on libc entirely. 4. Potentially we can make Processor per-CPU in C++ mode instead of per-thread, which will reduce resource consumption. The distinction between Thread and Processor is currently used only by Go, C++ creates Processor per OS thread, which is equivalent to the current scheme. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@262037 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-01[tsan] workaround for a crash in deadlock detector, bug ↵Kostya Serebryany
https://github.com/google/sanitizers/issues/594 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@246592 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-11Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko
The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix \ -format git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@234680 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-09[tsan] remove TSAN_GO in favor of SANITIZER_GOKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223732 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-03[TSan] Use StackTrace from sanitizer_common where applicableAlexey Samsonov
Summary: This change removes `__tsan::StackTrace` class. There are now three alternatives: # Lightweight `__sanitizer::StackTrace`, which doesn't own a buffer of PCs. It is used in functions that need stack traces in read-only mode, and helps to prevent unnecessary allocations/copies (e.g. for StackTraces fetched from StackDepot). # `__sanitizer::BufferedStackTrace`, which stores buffer of PCs in a constant array. It is used in TraceHeader (non-Go version) # `__tsan::VarSizeStackTrace`, which owns buffer of PCs, dynamically allocated via TSan internal allocator. Test Plan: compiler-rt test suite Reviewers: dvyukov, kcc Reviewed By: kcc Subscribers: llvm-commits, kcc Differential Revision: http://reviews.llvm.org/D6004 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@221194 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-26[Sanitizer] Make StackTrace a lightweight reference to array of PCs, andAlexey Samsonov
introduce a BufferedStackTrace class, which owns this array. Summary: This change splits __sanitizer::StackTrace class into a lightweight __sanitizer::StackTrace, which doesn't own array of PCs, and BufferedStackTrace, which owns it. This would allow us to simplify the interface of StackDepot, and eventually merge __sanitizer::StackTrace with __tsan::StackTrace. Test Plan: regression test suite. Reviewers: kcc, dvyukov Reviewed By: dvyukov Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5985 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@220635 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-10[TSan] Use common flags in the same way as all the other sanitizersAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217559 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-05tsan: allocate vector clocks using slab allocatorDmitry Vyukov
Vector clocks is the most actively allocated object in tsan runtime. Current internal allocator is not scalable enough to handle allocation of clocks in scalable way (too small caches). This changes transforms clocks to 2-level array with 512-byte blocks. Since all blocks are of the same size, it's possible to cache them more efficiently in per-thread caches. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@214912 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-08[tsan] fix deadlock detector's interoperation with java locks ↵Kostya Serebryany
(https://code.google.com/p/thread-sanitizer/issues/detail?id=67) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212529 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-08[tsan] fix pthread_rwlock_tryrdlock interceptor, don't try to detect ↵Kostya Serebryany
deadlocks when reporting bad unlock git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212526 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-06tsan: fix mutex in Go modeDmitry Vyukov
In Go it's legal to unlock from a different goroutine. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210358 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-06tsan: disable reporting of mutex misuses in GoDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210353 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-05[TSan] Reduce the stack frame size of ReportDeadlockAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210301 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-29tsan: refactor storage of meta information for heap blocks and sync objectsDmitry Vyukov
The new storage (MetaMap) is based on direct shadow (instead of a hashmap + per-block lists). This solves a number of problems: - eliminates quadratic behaviour in SyncTab::GetAndLock (https://code.google.com/p/thread-sanitizer/issues/detail?id=26) - eliminates contention in SyncTab - eliminates contention in internal allocator during allocation of sync objects - removes a bunch of ad-hoc code in java interface - reduces java shadow from 2x to 1/2x - allows to memorize heap block meta info for Java and Go - allows to cleanup sync object meta info for Go - which in turn enabled deadlock detector for Go git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209810 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-28tsan: refactor suppressions machineryDmitry Vyukov
The refactoring makes suppressions more flexible and allow to suppress based on arbitrary number of stacks. In particular it fixes: https://code.google.com/p/thread-sanitizer/issues/detail?id=64 "Make it possible to suppress deadlock reports by any stack (not just first)" git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209757 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-25tsan: allow to suppress all reportsDmitry Vyukov
Fixes issue https://code.google.com/p/thread-sanitizer/issues/detail?id=45 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@207218 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-25tsan: better reports for "unlock of an unlocked mutex"Dmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@207211 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-25tsan: better reports for "read lock of a write locked mutex"Dmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@207209 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-25tsan: improve "read unlock of a write locked mutex" reportDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@207208 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-25tsan: better report for bad mutex unlocksDmitry Vyukov
+ fixes crashes due to races on symbolizer, see https://code.google.com/p/thread-sanitizer/issues/detail?id=55 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@207206 91177308-0d34-0410-b5e6-96231b3b80d8
2014-04-25tsan: better reports for "double lock of a mutex"Dmitry Vyukov
+ fixes crashes due to races on symbolizer, see: https://code.google.com/p/thread-sanitizer/issues/detail?id=55 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@207204 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-24tsan: optimize vector clock operationsDmitry Vyukov
Make vector clock operations O(1) for several important classes of use cases. See comments for details. Below are stats from a large server app, 77% of all clock operations are handled as O(1). Clock acquire : 25983645 empty clock : 6288080 fast from release-store : 14917504 contains my tid : 4515743 repeated (fast) : 2141428 full (slow) : 2636633 acquired something : 1426863 Clock release : 2544216 resize : 6241 fast1 : 197693 fast2 : 1016293 fast3 : 2007 full (slow) : 1797488 was acquired : 709227 clear tail : 1 last overflow : 0 Clock release store : 3446946 resize : 200516 fast : 469265 slow : 2977681 clear tail : 0 Clock acquire-release : 820028 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204656 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-21[sanitizer] print threads in deadlock reportKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204461 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-21[sanitizer] more human-readable deadlock reportsKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204454 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-20tsan: deobfuscate global ctx variableDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204327 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-19tsan: add test for second_deadlock_stack flagDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204240 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-19tsan: preliminary support for Go deadlock detectorDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204228 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-19[sanitizer] deadlock detector: a) initial support for suppressions, b) be ↵Kostya Serebryany
more robust in case we failed to extract a stack trace for one of the locks git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204225 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-17[sanitizer] make the deadlock detector print 2*N stack traces on ↵Kostya Serebryany
lock-order-inversion with N locks (i.e. print stack traces for both lock acquisitions in every edge in the graph). More improvements to follow git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204042 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-17[tsan] fox the GO buildKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204037 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-17[sanitizer] fix build warnings; add an output test for the deadlock detecorKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204035 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-17[sanitizer] print more stack traces when reporting a deadlock (even more to ↵Kostya Serebryany
come) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204034 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-13[sanitizer] in bitvector-based deadlock detector split onLock into ↵Kostya Serebryany
onLockBefore and onLockAfter hooks git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@203796 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-05tsan: implement new version of standalong deadlock detectorDmitry Vyukov
intercept pthread_cond (it is required to properly track state of mutexes) detect cycles in mutex graph git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202975 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-28tsan: refactor deadlock detectorDmitry Vyukov
Introduce DDetector interface between the tool and the DD itself. It will help to experiment with other DD implementation, as well as reuse DD in other tools. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202485 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-27[sanitizer] do not acquire a global mutex in deadlock detector when dealing ↵Kostya Serebryany
with Unlock (it is essentially a thread-local operation) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202401 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-25[sanitizer] minimal support for recursive locks indeadlock detectorKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202153 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-25[sanitizer] support pthread_rwlock_rd* in deadlock detectorKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202132 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-25[sanitizer] partially support pthread_rwlock_* (no rd* form yet)Kostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@202128 91177308-0d34-0410-b5e6-96231b3b80d8