Commit Graph

413 Commits

Author SHA1 Message Date
Vitaly Buka 2890105eab [tsan] Disable user_malloc test which fails glibc 2.24
llvm-svn: 313069
2017-09-12 20:03:39 +00:00
Kamil Rytarowski 08e525ea06 Add NetBSD support in test/tsan/thread_name*.cc
Summary:
A snipped from the documentation of thread_setname_np(3):

NAME
     pthread_getname_np - get and set descriptive name of a thread

LIBRARY
     POSIX Threads Library (libpthread, -lpthread)

SYNOPSIS
     #include <pthread.h>

     int
     pthread_getname_np(pthread_t thread, char *name, size_t len);

     int
     pthread_setname_np(pthread_t thread, const char *name, void *arg);

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc

Reviewed By: dvyukov

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 312159
2017-08-30 19:40:47 +00:00
Dmitry Vyukov 780b462840 tsan: fix darwin build
Runtime hooks do not seem to work on darwin. The test failed on builder:
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/34882/consoleFull#7286766538254eaf0-7326-4999-85b0-388101f2d404
Move the test to Linux dir.

llvm-svn: 311776
2017-08-25 15:18:48 +00:00
Dmitry Vyukov 714ac2e781 tsan: don't pass bogus PCs to __tsan_symbolize_external
See the added comment for an explanation.

Reviewed in https://reviews.llvm.org/D37107

llvm-svn: 311768
2017-08-25 08:52:28 +00:00
Alex Shlyapnikov 132689243e [Sanitizers] TSan allocator set errno on failure.
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
2017-07-24 21:22:59 +00:00
Vitaly Buka a016feb7a1 [tsan] Disable test with debug runtime
Test expects at least -O1 compiled runtime.

llvm-svn: 308121
2017-07-16 01:05:37 +00:00
Kuba Mracek 7004b7cf0d Add explicit CMake targets for ASan/TSan iOS Simulator testing and update the instructions how to run them.
llvm-svn: 307844
2017-07-12 21:02:48 +00:00
Dmitry Vyukov 05d297080e tsan: add test for __tsan_java_find
The test should have been added in 289682
"tsan: allow Java VM iterate over allocated objects"
but I forgot to avn add.

Author: Alexander Smundak (asmundak)
Reviewed in https://reviews.llvm.org/D27720

llvm-svn: 307776
2017-07-12 12:23:31 +00:00
Kuba Mracek 21ad3fd3c5 Fix-up for r307537: We need to #include stdint.h to get int32_t.
llvm-svn: 307557
2017-07-10 17:11:52 +00:00
Kuba Mracek 872cb7086c Fixup whitespace.
llvm-svn: 307538
2017-07-10 15:19:14 +00:00
Kuba Mracek 91f3fa5f31 [tsan] Add support for running TSan tests on iOS simulator and devices
Differential Revision: https://reviews.llvm.org/D35157

llvm-svn: 307537
2017-07-10 15:00:55 +00:00
Kuba Mracek 7149ca04ad [tsan] Use pthread_sigmask instead of sigprocmask to block signals in a thread on Darwin
On Darwin, sigprocmask changes the signal mask for the entire process. This has some unwanted consequences, because e.g. internal_start_thread wants to disable signals only in the current thread (to make the new thread inherit the signal mask), which is currently broken on Darwin. This patch switches to pthread_sigmask.

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

llvm-svn: 307212
2017-07-05 22:17:44 +00:00
Hiroshi Inoue 03656aa3dc fix trivial typos in comments; NFC
llvm-svn: 307005
2017-07-03 06:44:05 +00:00
Alex Shlyapnikov 4b450685d3 [Sanitizers] Operator new() interceptors always die on allocation error
Summary:
Operator new interceptors behavior is now controlled by their nothrow
property as well as by allocator_may_return_null flag value:

- allocator_may_return_null=* + new()        - die on allocation error
- allocator_may_return_null=0 + new(nothrow) - die on allocation error
- allocator_may_return_null=1 + new(nothrow) - return null

Ideally new() should throw std::bad_alloc exception, but that is not
trivial to achieve, hence TODO.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 306604
2017-06-28 21:58:57 +00:00
Dmitry Vyukov dc2a38cdf2 tsan: fix reading of mutex flags
SyncVar::IsFlagSet returns true if any flag is set.
This is wrong. Check the actual requested flag.

llvm-svn: 305281
2017-06-13 09:37:51 +00:00
Vedant Kumar cecb1121bb Mark the tsan strerror_r test as unsupported on Darwin
llvm-svn: 304944
2017-06-07 21:10:35 +00:00
Vedant Kumar 3e95c498aa Revert "Fix tsan test for Darwin. NFCI."
This reverts commit r304941. Vitaly Buka writes:
"Actually it depends on return value.
Test is for char* version of function. It will probably fail for int
version."

llvm-svn: 304943
2017-06-07 21:10:33 +00:00
Vedant Kumar a302ae096e Fix tsan test for Darwin. NFCI.
On Darwin, strerror_r returns an int, not a char*. I don't think this
test really depends on what strerror_r returns, so I've used something
else in place of the result of the call to strerror_r.

llvm-svn: 304941
2017-06-07 20:43:15 +00:00
Vitaly Buka d9bc851fb3 [tsan]: Fix GNU version of strerror_r interceptor
GNU version of strerror_r returns a result pointer that doesn't match the input
buffer. The result pointer is in fact a pointer to some internal storage.
TSAN was recording a write to this location, which was incorrect.

Fixed https://github.com/google/sanitizers/issues/696

llvm-svn: 304858
2017-06-07 01:53:38 +00:00
Kuba Mracek a7cad4fcb7 [tsan] Detect races on modifying accesses in Swift code
This patch allows the Swift compiler to emit calls to `__tsan_external_write` before starting any modifying access, which will cause TSan to detect races on arrays, dictionaries and other classes defined in non-instrumented modules. Races on collections from the Swift standard library and user-defined structs and a frequent cause of subtle bugs and it's important that TSan detects those on top of existing LLVM IR instrumentation, which already detects races in direct memory accesses.

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

llvm-svn: 302050
2017-05-03 16:51:01 +00:00
Bill Seurer 6a47ba2ee0 [powerpc] deactivate flakey tests on powerpc64le
These test cases occassionally fail when run on powerpc64le:

ignore_lib1.cc
ignore_lib5.cc
TestCases/Posix/current_allocated_bytes.cc
rtl/TsanRtlTest/Posix.ThreadLocalAccesses
TestCases/Posix/coverage-fork-direct.cc

The failures cause false problem reports to be sent to developers whose
code had nothing to do with the failures.  Reactivate them when the real
problems are fixed.

This could also be related to the same problems as with the tests
ThreadedOneSizeMallocStressTest, ThreadedMallocStressTest, ManyThreadsTest,
and several others that do not run reliably on powerpc.

llvm-svn: 301798
2017-05-01 13:56:04 +00:00
Tim Northover 8488991bb8 TSan: update line number after XFAIL on iOS.
llvm-svn: 301560
2017-04-27 16:21:50 +00:00
Kuba Mracek 3cb973f791 XFAIL the TSan XPC tests on iOS. XPC isn't available on iOS.
llvm-svn: 301459
2017-04-26 20:29:30 +00:00
Kuba Mracek dd13e4e0b0 [tsan] Include __tsan_external_* API from a header file instead of declaring them manually. NFC.
Differential Revision: https://reviews.llvm.org/D32384

llvm-svn: 301190
2017-04-24 16:48:30 +00:00
Kuba Mracek 264b6de4b0 [tsan] Remove the extra word "object" from description of external races
Differential Revision: https://reviews.llvm.org/D32383

llvm-svn: 301189
2017-04-24 16:42:29 +00:00
Kuba Mracek 276e94eb74 [tsan] Add a test for "external" API that checks the dup suppression is based on the caller PC
We need to make sure that the "external" API isn't dup'ing all data races into a single one (because the stack might look the same) and suppressing all external races. This works now, so just adding a test for that.

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

llvm-svn: 301011
2017-04-21 17:49:19 +00:00
Kuba Mracek 2e4e7d04d2 [tsan] Ignore memory accesses for libignored modules for "external" races
On Darwin, the setting ignore_noninstrumented_modules is used to suppress false positives in code that users don't have control of. The recently added "external" API (which can be used to detect races on objects provided by system libraries, but the race is actually user's fault) ignores this flag and it can report issues in non-instrumented modules. This patch fixes that.

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

llvm-svn: 301000
2017-04-21 17:18:14 +00:00
Kuba Mracek 894da66320 [tsan] Don't report bugs from interceptors called from libignored modules
This patch make sure we don't report deadlocks and other bug types when we're inside an interceptor that was called from a noninstrumented module (when ignore_noninstrumented_modules=1 is set). Adding a testcase that shows that deadlock detection still works on Darwin (to make sure we're not silencing too many reports).

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

llvm-svn: 300998
2017-04-21 16:44:27 +00:00
Benjamin Kramer 25bdb98a98 [tsan] Add missing include for uint64_t in test.
llvm-svn: 300484
2017-04-17 19:55:12 +00:00
Kuba Mracek ceb30b0717 [sanitizer] Introduce tid_t as a typedef for OS-provided thread IDs
We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD).

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

llvm-svn: 300473
2017-04-17 18:17:38 +00:00
Vitaly Buka 2bca1a9f40 [tsan] Fall-back to IPv6 if IPv4 is not available.
Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 299885
2017-04-10 21:03:21 +00:00
Kuba Mracek 0bf5ec2812 [tsan] Add interceptor for xpc_connection_cancel to avoid false positives
TSan reports a false positive when using xpc_connection_cancel. We're missing a happens-before edge from xpc_connection_cancel to the event handler on the same connection.

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

llvm-svn: 299086
2017-03-30 15:48:25 +00:00
Sam McCall cf95f24a07 Add --std=c++11 to tests that #include <atomic>
llvm-svn: 298836
2017-03-27 09:45:38 +00:00
Kuba Mracek a1737293fc [tsan] Only Acquire/Release GCD queues if they're not NULL
While it's usually a bug to call GCD APIs, such as dispatch_after, with NULL as a queue, this often "somehow" works and TSan should maintain binary compatibility with existing code. This patch makes sure we don't try to call Acquire and Release on NULL queues, and add one such testcase for dispatch_after.

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

llvm-svn: 298820
2017-03-26 20:59:23 +00:00
Dmitry Vyukov 8096a8c86f tsan: add new mutex annotations
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

llvm-svn: 298809
2017-03-26 15:27:04 +00:00
Kuba Mracek d8789fdf0b Update debug_external.cc testcase to use TSan-invisible barriers to reduce flakiness.
llvm-svn: 298707
2017-03-24 16:37:02 +00:00
Kuba Mracek 38ded5a37f Update the Darwin/external.cc testcase to use rpath. This means we can move the test output executables and still be able to run them.
llvm-svn: 298682
2017-03-24 03:53:44 +00:00
Dmitry Vyukov 3bf24449b0 tsan: fix pie_no_aslr test
It failed on clang-cmake-aarch64-39vma.
Restrict it to x86_64 only.

llvm-svn: 298383
2017-03-21 15:37:48 +00:00
Dmitry Vyukov de033e6cdb tsan: support __ATOMIC_HLE_ACQUIRE/RELEASE flags
HLE flags can be combined with memory order in atomic operations.
Currently tsan runtime crashes on e.g. IsStoreOrder(mo) in atomic store
if any of these additional flags are specified.

Filter these flags out.
See the comment as to why it is safe.

llvm-svn: 298378
2017-03-21 14:28:55 +00:00
Dmitry Vyukov ae9f13855b tsan: add test for pie/no aslr
Just ensure that such combination works.

llvm-svn: 298372
2017-03-21 13:44:01 +00:00
Kuba Mracek c90b79c585 Re-commit of r295318, which was reverted due to AArch64 flakiness. Moving the test to Darwin only.
llvm-svn: 295801
2017-02-22 01:13:34 +00:00
Diana Picus 99141cc7ca Revert "[tsan] Provide external tags (object types) via debugging API"
This reverts commit r295318 as the test is flaky on AArch64.

llvm-svn: 295667
2017-02-20 15:26:12 +00:00
Kuba Mracek 3e81c2675e [tsan] Provide external tags (object types) via debugging API
In D28836, we added a way to tag heap objects and thus provide object types into report. This patch exposes this information into the debugging API.

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

llvm-svn: 295318
2017-02-16 14:02:32 +00:00
Kuba Mracek 53fc965b48 Fixup for r293885: Update external.cc testcase to include the forgotten stdlib.h.
llvm-svn: 295002
2017-02-13 23:28:06 +00:00
Bill Seurer f2611acfec [powerpc] deactivate user_malloc.cc tsan test on powerpc64le
This test fails consistently on Ubuntu 16.xx powerpc64 LE systems.
The cause is being investigated and in the meantime disable it so
the buildbots can run cleanly.

llvm-svn: 293939
2017-02-02 21:32:07 +00:00
Kuba Mracek aa78ad5fea [tsan] Provide API for libraries for race detection on custom objects
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

llvm-svn: 293885
2017-02-02 13:17:05 +00:00
Kuba Mracek bba1d40589 [tsan] Properly describe GCD worker threads in reports
When dealing with GCD worker threads, TSan currently prints weird things like "created by thread T-1" and "[failed to restore the stack]" in reports. This patch avoids that and instead prints "Thread T3 (...) is a GCD worker thread".

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

llvm-svn: 293882
2017-02-02 12:54:21 +00:00
Kuba Mracek 6393aa3a62 [tsan] Fix os_id of main thread
Currently, os_id of the main thread contains the PID instead of a thread ID. Let's fix this.

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

llvm-svn: 293201
2017-01-26 19:20:30 +00:00
Kuba Mracek e4c1dd2c08 [tsan] Enable ignore_noninstrumented_modules=1 on Darwin by default
TSan recently got the "ignore_noninstrumented_modules" flag, which disables tracking of read and writes that come from noninstrumented modules (via interceptors). This is a way of suppressing false positives coming from system libraries and other noninstrumented code. This patch turns this on by default on Darwin, where it's supposed to replace the previous solution, "ignore_interceptors_accesses", which disables tracking in *all* interceptors. The new approach should re-enable TSan's ability to find races via interceptors on Darwin.

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

llvm-svn: 292981
2017-01-24 21:37:50 +00:00
Kuba Mracek 245318cb05 [lit] Limit parallelism of sanitizer tests on Darwin [compiler-rt part, take 2]
Running lit tests and unit tests of ASan and TSan on macOS has very bad performance when running with a high number of threads. This is caused by xnu (the macOS kernel), which currently doesn't handle mapping and unmapping of sanitizer shadow regions (reserved VM which are several terabytes large) very well. The situation is so bad that increasing the number of threads actually makes the total testing time larger. The macOS buildbots are affected by this. Note that we can't easily limit the number of sanitizer testing threads without affecting the rest of the tests.

This patch adds a special "group" into lit, and limits the number of concurrently running tests in this group. This helps solve the contention problem, while still allowing other tests to run in full, that means running lit with -j8 will still with 8 threads, and parallelism is only limited in sanitizer tests.

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

llvm-svn: 292549
2017-01-20 00:25:01 +00:00