summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/tests/unit
Commit message (Collapse)AuthorAgeFilesLines
* compiler-rt: Rename .cc file in lib/tsan/tests/{rtl,unit} to .cppNico Weber2019-08-0111-18/+19
| | | | | | Like r367463, but for tsan/tests/{rtl,unit}. llvm-svn: 367566
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-1910-40/+30
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [TSan] Report proper error on allocator failures instead of CHECK(0)-ingAlex Shlyapnikov2018-06-181-40/+5
| | | | | | | | | | | | | | | | | | | | | | Summary: Following up on and complementing D44404 and other sanitizer allocators. Currently many allocator specific errors (OOM, for example) are reported as a text message and CHECK(0) termination, no stack, no details, not too helpful nor informative. To improve the situation, detailed and structured common errors were defined and reported under the appropriate conditions. Common tests were generalized a bit to cover a slightly different TSan stack reporting format, extended to verify errno value and returned pointer value check is now explicit to facilitate debugging. Reviewers: dvyukov Subscribers: srhines, kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D48087 llvm-svn: 334975
* Move __tsan::Vector to __sanitizerKamil Rytarowski2017-12-042-45/+1
| | | | | | | | | | | | | | | | | | | | | Summary: The low-fat STL-like vector container will be reused in MSan. It is needed to implement an atexit(3) interceptor on NetBSD/amd64 in MSan. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc Reviewed By: dvyukov Subscribers: kubamracek, mgorny, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40726 llvm-svn: 319650
* [tsan] Check for pvalloc overlowKostya Kortchinsky2017-08-021-1/+7
| | | | | | | | | | | | | | | | | | Summary: `CheckForPvallocOverflow` was introduced with D35818 to detect when pvalloc would wrap when rounding up to the next multiple of the page size. Add this check to TSan's pvalloc implementation. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D36245 llvm-svn: 309897
* [Sanitizers] TSan allocator set errno on failure.Alex Shlyapnikov2017-07-241-6/+77
| | | | | | | | | | | | | | | | | | Summary: Set proper errno code on allocation failures and change realloc, pvalloc, aligned_alloc, memalign and posix_memalign implementation to satisfy their man-specified requirements. Modify allocator API implementation to bring it closer to other sanitizers allocators. Reviewers: dvyukov Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D35690 llvm-svn: 308929
* tsan: optimize sync clock memory consumptionDmitry Vyukov2017-07-141-5/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change implements 2 optimizations of sync clocks that reduce memory consumption: Use previously unused first level block space to store clock elements. Currently a clock for 100 threads consumes 3 512-byte blocks: 2 64-bit second level blocks to store clock elements +1 32-bit first level block to store indices to second level blocks Only 8 bytes of the first level block are actually used. With this change such clock consumes only 2 blocks. Share similar clocks differing only by a single clock entry for the current thread. When a thread does several release operations on fresh sync objects without intervening acquire operations in between (e.g. initialization of several fields in ctor), the resulting clocks differ only by a single entry for the current thread. This change reuses a single clock for such release operations. The current thread time (which is different for different clocks) is stored in dirty entries. We are experiencing issues with a large program that eats all 64M clock blocks (32GB of non-flushable memory) and crashes with dense allocator overflow. Max number of threads in the program is ~170 which is currently quite unfortunate (consume 4 blocks per clock). Currently it crashes after consuming 60+ GB of memory. The first optimization brings clock block consumption down to ~40M and allows the program to work. The second optimization further reduces block consumption to "modest" 16M blocks (~8GB of RAM) and reduces overall RAM consumption to ~30GB. Measurements on another real world C++ RPC benchmark show RSS reduction from 3.491G to 3.186G and a modest speedup of ~5%. Go parallel client/server HTTP benchmark: https://github.com/golang/benchmarks/blob/master/http/http.go shows RSS reduction from 320MB to 240MB and a few percent speedup. Reviewed in https://reviews.llvm.org/D35323 llvm-svn: 308018
* tsan: prepare clock for future changesDmitry Vyukov2017-07-121-15/+17
| | | | | | | Pass ClockCache to ThreadClock::set and introduce ThreadCache::ResetCached. For now both are unused, but will reduce future diffs. llvm-svn: 307784
* tsan: add another test for clock growthDmitry Vyukov2017-07-121-0/+36
| | | | llvm-svn: 307777
* Follow-up for r277458: Update the tsan_mman_test.cc unit test.Kuba Brecka2016-08-021-4/+4
| | | | llvm-svn: 277463
* tsan: don't create sync objects on acquireDmitry Vyukov2016-06-271-7/+7
| | | | | | | Creating sync objects on acquire is pointless: acquire of a just created sync object if a no-op. llvm-svn: 273862
* tsan: change tsan/Go interface for obtaining the current ProcessorDmitry Vyukov2016-04-271-7/+7
| | | | | | | | | | | | | | | 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. llvm-svn: 267703
* tsan: split thread into logical and physical stateDmitry Vyukov2016-04-271-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 267678
* [sanitizer] On OS X, verify that interceptors work and abort if not, take 2Kuba Brecka2016-03-171-0/+6
| | | | | | | | | | On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES. TSan unit tests run with a statically linked runtime, where interceptors don't work. To avoid aborting the process in this case, the patch replaces `DisableReexec()` with a weak `ReexecDisabled()` function which is defined to return true in unit tests. Differential Revision: http://reviews.llvm.org/D18212 llvm-svn: 263695
* tsan: revert r262037Dmitry Vyukov2016-02-261-7/+7
| | | | | | Broke aarch64 and darwin bots. llvm-svn: 262046
* tsan: split thread into logical and physical stateDmitry Vyukov2016-02-261-7/+7
| | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 262037
* [tsan] Fix CallocOverflow unit test on OS XKuba Brecka2015-11-241-1/+3
| | | | | | | | On OS X, interceptors don't work in unit tests, so calloc() calls the system allocator. We need to use user_calloc() instead. Differential Revision: http://reviews.llvm.org/D14918 llvm-svn: 253979
* [tsan] Add TSan unit test support for OS XKuba Brecka2015-11-111-3/+4
| | | | | | | | This patch enables building and running TSan unit tests on OS X. Differential Revision: http://reviews.llvm.org/D14546 llvm-svn: 252731
* [Sanitizers] Unify the semantics and usage of "exitcode" runtime flag across ↵Alexey Samsonov2015-08-211-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | all sanitizers. Summary: Merge "exitcode" flag from ASan, LSan, TSan and "exit_code" from MSan into one entity. Additionally, make sure sanitizer_common now uses the value of common_flags()->exitcode when dying on error, so that this flag will automatically work for other sanitizers (UBSan and DFSan) as well. User-visible changes: * "exit_code" MSan runtime flag is now deprecated. If explicitly specified, this flag will take precedence over "exitcode". The users are encouraged to migrate to the new version. * __asan_set_error_exit_code() and __msan_set_exit_code() functions are removed. With few exceptions, we don't support changing runtime flags during program execution - we can't make them thread-safe. The users should use __sanitizer_set_death_callback() that would call _exit() with proper exit code instead. * Plugin tools (LSan and UBSan) now inherit the exit code of the parent tool. In particular, this means that ASan would now crash the program with exit code "1" instead of "23" if it detects leaks. Reviewers: kcc, eugenis Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12120 llvm-svn: 245734
* [TSan] Fix -Werror=sign-compare warning. NFC.Alexey Samsonov2015-01-301-2/+2
| | | | llvm-svn: 227527
* Remove TSAN_DEBUG in favor of SANITIZER_DEBUG.Alexey Samsonov2015-01-032-2/+2
| | | | llvm-svn: 225111
* [TSan] Use StackTrace from sanitizer_common where applicableAlexey Samsonov2014-11-031-45/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 221194
* [TSan] Fix signed-compare warning in the unit testAlexey Samsonov2014-11-031-1/+1
| | | | llvm-svn: 221190
* tsan: support mmap(MAP_32BIT)Dmitry Vyukov2014-10-241-1/+1
| | | | | | | | | Allow user memory in the first TB of address space. This also enabled non-pie binaries and freebsd. Fixes issue: https://code.google.com/p/thread-sanitizer/issues/detail?id=5 llvm-svn: 220571
* [TSan] Use common flags in the same way as all the other sanitizersAlexey Samsonov2014-09-101-72/+0
| | | | llvm-svn: 217559
* tsan: allocate vector clocks using slab allocatorDmitry Vyukov2014-08-052-25/+106
| | | | | | | | | | 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. llvm-svn: 214912
* tsan: remove special handling of false reports coming from JVMDmitry Vyukov2014-07-151-4/+0
| | | | | | There is now a more common functionality in the form of called_from_lib suppressions. llvm-svn: 213057
* tsan: reapply 212531 and 212532 with a fixDmitry Vyukov2014-07-081-0/+12
| | | | | | don't reset s->addr as well llvm-svn: 212565
* [TSan] Revert r212531 and r212532.Alexey Samsonov2014-07-081-12/+0
| | | | | | They cause "check-tsan" command to hang. Details in r212532 review thread. llvm-svn: 212562
* tsan: fix a bug in metamapDmitry Vyukov2014-07-081-0/+12
| | | | | | | | | 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. llvm-svn: 212531
* Generalize sanitizer allocator public interface.Alexey Samsonov2014-07-071-27/+18
| | | | | | | | | | | | | | Introduce new public header <sanitizer/allocator_interface.h> and a set of functions __sanitizer_get_ownership(), __sanitizer_malloc_hook() etc. that will eventually replace their tool-specific equivalents (__asan_get_ownership(), __msan_get_ownership() etc.). Tool-specific functions are now deprecated and implemented as stubs redirecting to __sanitizer_ versions (which are implemented differently in each tool). Replace all uses of __xsan_ versions with __sanitizer_ versions in unit and lit tests. llvm-svn: 212469
* [TSan] Equalize the behavior of __tsan_get_allocated_size and ↵Alexey Samsonov2014-07-011-5/+6
| | | | | | | | | | | user_alloc_usable_size. The former used to crash with a null deref if it was given a not owned pointer, while the latter returned 0. Now they both return 0. This is still not the best possible behavior: it is better to print an error report with a stack trace, pointing to the error in user code, as we do in ASan. llvm-svn: 212112
* tsan: optimize memory access functionsDmitry Vyukov2014-05-301-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The optimization is two-fold: First, the algorithm now uses SSE instructions to handle all 4 shadow slots at once. This makes processing faster. Second, if shadow contains the same access, we do not store the event into trace. This increases effective trace size, that is, tsan can remember up to 10x more previous memory accesses. Perofrmance impact: Before: [ OK ] DISABLED_BENCH.Mop8Read (2461 ms) [ OK ] DISABLED_BENCH.Mop8Write (1836 ms) After: [ OK ] DISABLED_BENCH.Mop8Read (1204 ms) [ OK ] DISABLED_BENCH.Mop8Write (976 ms) But this measures only fast-path. On large real applications the speedup is ~20%. Trace size impact: On app1: Memory accesses : 1163265870 Including same : 791312905 (68%) on app2: Memory accesses : 166875345 Including same : 150449689 (90%) 90% of filtered events means that trace size is effectively 10x larger. llvm-svn: 209897
* tsan: refactor storage of meta information for heap blocks and sync objectsDmitry Vyukov2014-05-293-54/+144
| | | | | | | | | | | | | | | 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 llvm-svn: 209810
* tsan: better reports for "double lock of a mutex"Dmitry Vyukov2014-04-251-0/+4
| | | | | | | + fixes crashes due to races on symbolizer, see: https://code.google.com/p/thread-sanitizer/issues/detail?id=55 llvm-svn: 207204
* tsan: reduce number of iterations in the testDmitry Vyukov2014-04-231-1/+1
| | | | | | otherwise it runs for 50 seconds in debug mode llvm-svn: 206950
* tsan: fix vector clocksDmitry Vyukov2014-04-112-5/+45
| | | | | | | the new optimizations break when thread ids gets reused (clocks go backwards) add the necessary tests as well llvm-svn: 206035
* [tsan] Fix more warnings in TSan tests.Evgeniy Stepanov2014-03-251-33/+33
| | | | llvm-svn: 204715
* [tsan] Fix compiler warnings in TSan tests.Evgeniy Stepanov2014-03-251-2/+2
| | | | llvm-svn: 204712
* tsan: optimize vector clock operationsDmitry Vyukov2014-03-241-48/+241
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 204656
* tsan: yet another attempt to fix pthread_cond interceptorsDmitry Vyukov2014-03-171-0/+4
| | | | | | | | | | | Make behavior introduced in r202820 conditional (under legacy_pthread_cond flag). The new issue that we've hit with the satellite pthread_cond_t struct is that pthread_condattr_getpshared does not work (satellite data is not shared between processes). The idea is that most processes do not use pthread 2.2.5. The rare ones that use (2.2.5 is dated by 2002) must specify legacy_pthread_cond=1 on their own risk. llvm-svn: 204032
* [Sanitizer] Teach external symbolizer to work with addr2line if ↵Alexey Samsonov2014-02-121-1/+5
| | | | | | llvm-symbolizer is unavailable. Allow this mode in TSan. llvm-svn: 201218
* tsan: do not deadlock on forkDmitry Vyukov2014-01-241-0/+4
| | | | | | | | | | | | | Currently correct programs can deadlock after fork, because atomic operations and async-signal-safe calls are not async-signal-safe under tsan. With this change: - if a single-threaded program forks, the child continues running with verification enabled (the tsan background thread is recreated as well) - if a multi-threaded program forks, then the child runs with verification disabled (memory accesses, atomic operations and interceptors are disabled); it's expected that it will exec soon anyway - if the child tries to create more threads after multi-threaded fork, the program aborts with error message - die_after_fork flag is added that allows to continue running, but all bets are off http://llvm-reviews.chandlerc.com/D2614 llvm-svn: 199993
* tsan: remove in_rtl counterDmitry Vyukov2013-12-246-21/+0
| | | | | | | | This is intended to address the following problem. Episodically we see CHECK-failures when recursive interceptors call back into user code. Effectively we are not "in_rtl" at this point, but it's very complicated and fragile to properly maintain in_rtl property. Instead get rid of it. It was used mostly for sanity CHECKs, which basically never uncover real problems. Instead introduce ignore_interceptors flag, which is used in very few narrow places to disable recursive interceptors (e.g. during runtime initialization). llvm-svn: 197979
* [Sanitizer] Always initialize a Symbolizer (even if 'symbolize' is false).Alexey Samsonov2013-12-171-1/+1
| | | | | | | | | If 'symbolize' flag is not set, we still want to transform virtual address to module+offset pair in the call to Symbolizer::SymbolizeCode(). See https://code.google.com/p/address-sanitizer/issues/detail?id=251 for more details. llvm-svn: 197491
* tsan: do not leave verbosity>0 in testsDmitry Vyukov2013-11-271-2/+2
| | | | llvm-svn: 195833
* tsan: fix flags parsingDmitry Vyukov2013-11-271-0/+207
| | | | | | | | - running_on_valgrind was not parsed in some contexts - refactor code a bit - add comprehensive tests for flags parsing llvm-svn: 195831
* tsan: move shadow stack from thread descriptors to fixed addressesDmitry Vyukov2013-10-161-0/+9
| | | | | | | | This allows to increase max shadow stack size to 64K, and reliably catch shadow stack overflows instead of silently corrupting memory. llvm-svn: 192797
* [TSan] Use Clang to compile and link TSan unit tests with TSan runtimeAlexey Samsonov2013-09-112-4/+24
| | | | llvm-svn: 190503
* [tsan] make calloc crash instead of returning 0 on overflow (controlled by ↵Kostya Serebryany2013-09-061-1/+3
| | | | | | the allocator_may_return_null flag) llvm-svn: 190135
OpenPOWER on IntegriCloud