summaryrefslogtreecommitdiff
path: root/lib/tsan/rtl/tsan_sync.cc
AgeCommit message (Collapse)Author
2017-07-12tsan: give debug names to dense allocatorsDmitry Vyukov
Improves crash message on dense alloc overflow. Allows to understand what alloc overflowed. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307780 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
2017-02-02[tsan] Provide API for libraries for race detection on custom objectsKuba Mracek
This patch allows a non-instrumented library to call into TSan runtime, and tell us about "readonly" and "modifying" accesses to an arbitrary "object" and provide the caller and tag (type of object). This allows TSan to detect violations of API threading contracts where "read-only" methods can be called simulatenously from multiple threads, while modifying methods must be exclusive. Differential Revision: https://reviews.llvm.org/D28836 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293885 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-05-10tsan: fix another crash due to processorsDmitry Vyukov
Another stack where we try to free sync objects, but don't have a processors is: // ResetRange // __interceptor_munmap // __deallocate_stack // start_thread // clone Again, it is a latent bug that lead to memory leaks. Also, increase amount of memory we scan in MetaMap::ResetRange. Without that the test does not fail, as we fail to free the sync objects on stack. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269041 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-27tsan: fix windows Go supportDmitry Vyukov
Unmap can't unmap arbitrary regions on windows. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267716 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-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-03-27tsan: don't write to meta shadow unnecessarilyDmitry Vyukov
If user does malloc(1<<30), the write to meta shadow can cause excessive memory consumption. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@233373 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-12tsan: fix a bug in MetaMap::ResetRangeDmitry Vyukov
The bug was uncovered by NegativeTests.MmapTest from data-race-test suite, so port it as well. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@232032 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-12tsan: fix crash during __tsan_java_moveDmitry Vyukov
Munmap interceptor did not reset meta shadow for the range, and __tsan_java_move crashed because it encountered non-zero meta shadow for the destination. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@232029 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-08tsan: reapply 212531 and 212532 with a fixDmitry Vyukov
don't reset s->addr as well git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212565 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-08[TSan] Revert r212531 and r212532.Alexey Samsonov
They cause "check-tsan" command to hang. Details in r212532 review thread. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212562 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-08tsan: allow memory overlap in __tsan_java_moveDmitry Vyukov
JVM actually moves memory between overlapping ranges. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212560 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-08tsan: fix a potential hangDmitry Vyukov
idx0 is not updated in the branch, so if we take that branch idx0 will stay updated forever git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212532 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-08tsan: fix a bug in metamapDmitry Vyukov
The bug happens in the following case: Mutex is located at heap block beginning, when we call MutexDestroy, s->next is set to 0, so free can't find the MBlock related to the block. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212531 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-21tsan: fix code formattingDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@211429 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-03-20tsan: use stack depot for goroutine creation stacks (as C++ threads do)Dmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204326 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-14[tsan] rudimentary support for deadlock detector in tsan (nothing really ↵Kostya Serebryany
works yet except for a single tiny test). Also rename tsan's DeadlockDetector to InternalDeadlockDetector git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201407 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-16tsan: move shadow stack from thread descriptors to fixed addressesDmitry Vyukov
This allows to increase max shadow stack size to 64K, and reliably catch shadow stack overflows instead of silently corrupting memory. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192797 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-24tsan: fix crash when data race happens on out-of-bounds accesses.Dmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@180180 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-18tsan: smaller memory block headers (32b->16b)Dmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177312 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-18tsan: use StackDepot in sync object to store creation stacksDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177258 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-20tsan: java interface implementation skeletonDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@170707 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-18tsan: intercept fork() to prevent false race reports on fd'sDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@170433 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-06tsan: add mutexsets to reportsDmitry Vyukov
With this change reports say what mutexes the threads hold around the racy memory accesses. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@169493 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-06tsan: increase max shadow stack size + reduce memory consumption at the same ↵Dmitry Vyukov
time (by not memorizing full stacks in traces) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@163322 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-18tsan: proper handling of linker initialized mutexesDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162169 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-16tsan: better diagnostics for destroy of a locked mutex + a testDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162022 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-16tsan: support for linker initializer mutexes with static storage durationDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162021 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-15tsan: store sync objects in memory block headers + delete them when the ↵Dmitry Vyukov
block is freed git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@161959 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-27tasn: do not remember stack traces for sync objects for Go (they are not ↵Dmitry Vyukov
reported anyway) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@160861 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-16tsan: use dynamic shadow stack for GoDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@160288 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-22tsan: do not call malloc/free in memory access handling routine.Dmitry Vyukov
This improves signal-/fork-safety of instrumented programs. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158988 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-15[Sanitizer] Use DEFINE_REAL macro in TSan runtime to call libc ↵Alexey Samsonov
implementations of functions. Move strchr to sanitizer_libc. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158517 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-09[TSan] use efficient real_memcpy inside runtimeAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158260 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-07[Sanitizer] move placement_new definiton from TSan to common runtimeAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158145 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-04Remove file-type tags in .cc files in tsan/ and sanitizer_common/Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157928 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-22tsan: simple memory profilerDmitry Vyukov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@157248 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-10[tsan] First commit of ThreadSanitizer (TSan) run-time library.Kostya Serebryany
Algorithm description: http://code.google.com/p/thread-sanitizer/wiki/ThreadSanitizerAlgorithm Status: The tool is known to work on large real-life applications, but still has quite a few rough edges. Nothing is guaranteed yet. The tool works on x86_64 Linux. Support for 64-bit MacOS 10.7+ is planned for late 2012. Support for 32-bit OSes is doable, but problematic and not yet planed. Further commits coming: - tests - makefiles - documentation - clang driver patch The code was previously developed at http://code.google.com/p/data-race-test/source/browse/trunk/v2/ by Dmitry Vyukov and Kostya Serebryany with contributions from Timur Iskhodzhanov, Alexander Potapenko, Alexey Samsonov and Evgeniy Stepanov. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@156542 91177308-0d34-0410-b5e6-96231b3b80d8