Commit Graph

1239 Commits

Author SHA1 Message Date
Kostya Serebryany c69bf1b4c0 [asan,tsan,msan] move the memcmp interceptor from asan/tsan to sanitizer_common. This may potentially lead to more reports from msan as it now sees the reads inside memcmp. To disable, use the flag intercept_memcmp=0. Likewise, it may potentially cause new races to appear due to more strict memcmp checking (flag strict_memcmp=1)
llvm-svn: 243595
2015-07-29 23:53:08 +00:00
Dmitry Vyukov d161fcba17 tsan: fix shift overflow
3<<30 fits into 32-bit unsigned, but does not fit into int.
Found by ubsan.

llvm-svn: 243241
2015-07-26 07:45:26 +00:00
Ismail Pazarbasi 0193c3a40e __tsan::ThreadCreate takes incorrect value for detached argument
Summary:
PTHREAD_CREATE_DETACHED has a different value on Mac OS X. Since both
PTHREAD_CREATE_JOINABLE and PTHREAD_CREATE_DETACHED are non-zero,
`__tsan::ThreadCreate` always creates detached threads.

Reviewers: kcc, samsonov, glider

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D10606

llvm-svn: 243151
2015-07-24 20:00:49 +00:00
Evgeniy Stepanov 5a268b10b3 [sanitizer] Implement logging to syslog.
Previously, Android target had a logic of duplicating all sanitizer
output to logcat. This change extends it to all posix platforms via
the use of syslog, controlled by log_to_syslog flag. Enabled by
default on Android, off everywhere else.

A bit of cmake magic is required to allow Printf() to call a libc
function. I'm adding a stub implementation to support no-libc builds
like dfsan and safestack.

This is a second attempt. I believe I've fixed all the issues that
prompted the revert: Mac build, and all kinds of non-CMake builds
(there are 3 of those).

llvm-svn: 243051
2015-07-23 22:05:20 +00:00
Evgeniy Stepanov df9ed542b5 [sanitizer] Implement include_if_exists with process name substitution.
include_if_exists=/path/to/sanitizer/options reads flags from the
file if it is present. "%b" in the include file path (for both
variants of the flag) is replaced with the basename of the main
executable.

llvm-svn: 242853
2015-07-21 23:03:13 +00:00
Alexey Samsonov f40c1076c9 [TSan] Fix dl_iterate_phdr callback for the case when info->dlpi_name is overwritten by user.
llvm-svn: 241876
2015-07-10 00:03:54 +00:00
Dmitry Vyukov 1d9b5e6ece tsan: fix handling of condition variable destruction
POSIX states that "It shall be safe to destroy an initialized condition
variable upon which no threads are currently blocked", and later clarifies
"A condition variable can be destroyed immediately after all the threads
that are blocked on it are awakened) (in examples section). Tsan reported
such destruction as a data race.
Fixes https://llvm.org/bugs/show_bug.cgi?id=23616
Reviewed in http://reviews.llvm.org/D10693

llvm-svn: 241082
2015-06-30 17:23:29 +00:00
Evgeniy Stepanov 856b11199f [asan] Fix SanitizerCommon.PthreadDestructorIterations test on Android L.
On Android L, TSD destructors run 8 times instead of 4.
Back to 4 times on the current master branch (as well as on K).

llvm-svn: 240992
2015-06-29 20:28:55 +00:00
Dmitry Vyukov ffb551b2b0 tsan: implement suppressions for top frame only
The new suppression type is called "race_top" and is matched only against top frame in report stacks.
This is required for situations when we want to suppress a race in a "thread pool" or "event loop" implementation.
If we simply use "race:ThreadPool::Execute" suppression, that can suppress everything in the program.

Reviewed in http://reviews.llvm.org/D10686

llvm-svn: 240949
2015-06-29 14:38:31 +00:00
Dmitry Vyukov 7c63340586 tsan: fix handling of dup2
Previously tsan modelled dup2(oldfd, newfd) as write on newfd.
We hit several cases where the write lead to false positives:
1. Some software dups a closed pipe in place of a socket before closing
   the socket (to prevent races actually).
2. Some daemons dup /dev/null in place of stdin/stdout.
On the other hand we have not seen cases when write here catches real bugs.
So model dup2 as read on newfd instead.

llvm-svn: 240687
2015-06-25 20:32:04 +00:00
Dmitry Vyukov b89a69dac6 tsan: merge function definition and declaration
llvm-svn: 240633
2015-06-25 11:45:45 +00:00
Dmitry Vyukov d58df749c1 tsan: fix false positive between dlopen and dl_iterate_phdr
We see false reports between dlopen and dl_iterate_phdr.
This happens because tsan does not see dynamic linker
internal synchronization. Unpoison module names
in dl_iterate_phdr callback.

llvm-svn: 240576
2015-06-24 19:49:32 +00:00
Dmitry Vyukov c871c03550 tsan: don't print external PCs in reports
They are meaningless.

llvm-svn: 240539
2015-06-24 13:04:12 +00:00
Dmitry Vyukov 89e0d57157 tsan: fix unbounded memory consumption for large mallocs
This happens only in corner cases, but we observed this on a real app.
See the test for description of the exact scenario that lead to unbounded memory consumption.

llvm-svn: 240535
2015-06-24 11:51:41 +00:00
Filipe Cabecinhas 7af0a1cb84 CMake: Stop using LLVM's custom parse_arguments. NFC
Summary:
Use CMake's cmake_parse_arguments() instead.
It's called in a slightly different way, but supports all our use cases.
It's in CMake 2.8.8, which is our minimum supported version.

CMake 3.0 doc (roughly the same. No direct link to 2.8.8 doc):
http://www.cmake.org/cmake/help/v3.0/module/CMakeParseArguments.html?highlight=cmake_parse_arguments

Since I was already changing these calls, I changed ARCH and LIB into
ARCHS and LIBS to make it more clear that they're lists of arguments.

Reviewers: eugenis, samsonov, beanz

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D10529

llvm-svn: 240120
2015-06-19 03:39:24 +00:00
Dmitry Vyukov 70dd0e2087 tsan: mark meta shadow as NOHUGEPAGE
Meta shadow is compressing and we don't flush it,
so it makes sense to mark it as NOHUGEPAGE to not over-allocate memory.
On one program it reduces memory consumption from 5GB to 2.5GB.

llvm-svn: 240028
2015-06-18 16:57:37 +00:00
Alexey Samsonov b412c47934 [CMake] Remove redundant checks in TSan CMakeLists.txt
llvm-svn: 239956
2015-06-17 22:24:49 +00:00
Chris Bieneman 6bd006f31a [CMake] Cleanup add_compiler_rt_object_library to be platform-agnostic
Summary:
This change takes darwin-specific goop that was scattered around CMakeLists files and spread between add_compiler_rt_object_library and add_compiler_rt_darwin_object_library and moves it all under add_compiler_rt_object_library.

The goal of this is to try to push platform handling as low in the utility functions as possible.

Reviewers: rnk, samsonov

Reviewed By: rnk, samsonov

Subscribers: rnk, rsmith, llvm-commits

Differential Revision: http://reviews.llvm.org/D10250

llvm-svn: 239498
2015-06-10 23:55:07 +00:00
Yury Gribov c019a57099 [ASan] Make binary name reader cross-platform.
Differential Revision: http://reviews.llvm.org/D10213

llvm-svn: 239020
2015-06-04 07:29:43 +00:00
Filipe Cabecinhas 215046bf98 [sanitizer_common] Added VS-style output for source locations
Summary:
With this patch, we have a flag to toggle displaying source locations in
the regular style:
file:line:column

or Visual Studio style:
file(line,column)

This way, they get picked up on the Visual Studio output window and one
can double-click them to get to that file location.

Reviewers: samsonov, rnk

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D10113

llvm-svn: 239000
2015-06-04 01:20:06 +00:00
Evgeniy Stepanov 42fb96652b [sanitizer] Add -lrt to dyndd link line.
llvm-svn: 238626
2015-05-29 22:57:15 +00:00
Evgeniy Stepanov 8e9c70be7f Add descriptive names to sanitizer entries in /proc/self/maps. Helps debugging.
This is done by creating a named shared memory region, unlinking it
and setting up a private (i.e. copy-on-write) mapping of that instead
of a regular anonymous mapping. I've experimented with regular
(sparse) files, but they can not be scaled to the size of MSan shadow
mapping, at least on Linux/X86_64 and ext3 fs.

Controlled by a common flag, decorate_proc_maps, disabled by default.

This patch has a few shortcomings:
* not all mappings are annotated, especially in TSan.
* our handling of memset() of shadow via mmap() puts small anonymous
  mappings inside larger named mappings, which looks ugly and can, in
  theory, hit the mapping number limit.

llvm-svn: 238621
2015-05-29 22:31:28 +00:00
Yury Gribov 0ca65fd83d [sanitizer] More string interceptors: strstr, strcasestr, strspn, strcspn, strpbrk.
Patch by Maria Guseva.

Differential Revision: http://reviews.llvm.org/D9017

llvm-svn: 238406
2015-05-28 09:24:33 +00:00
Evgeniy Stepanov 7f6290ca9a [sanitizer] Recognize static TLS in __tls_get_addr interceptor.
Current code tries to find the dynamic TLS header to the left of the
TLS block without checking that it's not a static TLS allocation.

llvm-svn: 237495
2015-05-16 00:34:15 +00:00
Dmitry Vyukov da6d5b919d tsan: add memory access functions that accept pc
This is required for Java support, as real PCs don't work for Java.

llvm-svn: 236484
2015-05-05 08:09:46 +00:00
Dmitry Vyukov 25c94eb152 tsan: fix a bug memory access handling
We incorrectly replaced shadow slots
when the new value is not stronger than the old one.
The bug can lead to false negatives.
The bug was detected by Go race test suite:
https://github.com/golang/go/issues/10589

llvm-svn: 236008
2015-04-28 18:08:42 +00:00
Alexey Samsonov dc99a9c7a1 [TSan] Attempt to fix old Makefile build.
llvm-svn: 235960
2015-04-28 01:27:17 +00:00
Alexey Samsonov 72078b3cff Export __ubsan_* symbols from MSan and TSan runtimes.
llvm-svn: 235958
2015-04-28 01:20:34 +00:00
Alexey Samsonov b3053d9cbe Allow UBSan+MSan and UBSan+TSan combinations (Clang part).
Embed UBSan runtime into TSan and MSan runtimes in the same as we do
in ASan. Extend UBSan test suite to also run tests for these
combinations.

llvm-svn: 235954
2015-04-28 00:56:48 +00:00
Alexey Samsonov 56d6fc81a5 Introduce tsan_cxx and msan_cxx libraries (compiler-rt part).
For now tsan_cxx and msan_cxx contain only operator new/delete
replacements. In the future, when we add support for running UBSan+TSan
and UBSan+MSan, they will also contain bits ubsan_cxx runtime.

llvm-svn: 235928
2015-04-27 22:08:09 +00:00
Alexey Samsonov 0eafe5df71 [TSan] Move new/delete interceptors into a separate source file. NFC.
llvm-svn: 235906
2015-04-27 19:33:55 +00:00
Dmitry Vyukov 8586e2352b tsan: fix handling of pthread_detach
Fixes https://llvm.org/bugs/show_bug.cgi?id=23235

If pthread_create is followed by pthread_detach,
the new thread may not acquire synchronize with
the parent thread.

llvm-svn: 235293
2015-04-20 10:35:10 +00:00
Dmitry Vyukov 57f2e64c06 tsan: fix parsing of second_deadlock_stack flag
It was broken during flag parsing refactoring.
Enable test for the flag.

llvm-svn: 234878
2015-04-14 10:32:33 +00:00
Alexander Kornienko d829812f65 Use 'override/final' instead of 'virtual' for overridden methods
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

llvm-svn: 234680
2015-04-11 02:44:24 +00:00
Timur Iskhodzhanov ea1f332b79 Split Mprotect into MmapNoAccess and MprotectNoAccess to be more portable
On Windows, we have to know if a memory to be protected is mapped or not.
On POSIX, Mprotect was semantically different from mprotect most people know.

llvm-svn: 234602
2015-04-10 15:02:19 +00:00
Timur Iskhodzhanov e8a6fbbfd3 Use WriteToFile instead of internal_write in non-POSIX code
llvm-svn: 234487
2015-04-09 14:11:25 +00:00
Timur Iskhodzhanov 3745303c5b Move some POSIX-specific functions from sanitizer_libc.h to a new sanitizer_posix.h
llvm-svn: 234418
2015-04-08 17:08:24 +00:00
Timur Iskhodzhanov daa9e2d4e8 [Sanitizers] Make OpenFile more portable
llvm-svn: 234410
2015-04-08 16:03:22 +00:00
Dmitry Vyukov 8e39c404a0 tsan: handle async signals while blocked in pthread_cond_wait
Fixes https://code.google.com/p/thread-sanitizer/issues/detail?id=91

llvm-svn: 234394
2015-04-08 07:48:52 +00:00
Dmitry Vyukov 1e5b9f4131 sanitizer: new "strict_string_checks" run-time flag
This patch is related to Issue 346: moar string interceptors: strstr, strcasestr, strcspn, strpbrk
As was suggested in original review http://reviews.llvm.org/D6056 a new "strict_string_checks" run-time flag introduced.
The flag support applied for existing common, asan, msan and tsan interceptors. New asan tests added.

Change by Maria Guseva reviewed in http://reviews.llvm.org/D7123

llvm-svn: 234187
2015-04-06 18:00:26 +00:00
Dmitry Vyukov 19300f856b tsan: fix munmap interceptor
MetaMap::ResetRange/FreeRange rounds the range up to at least kMetaShadowSize.
This is requried for e.g. free(malloc(0)). However, munmap returns EINVAL
and do not unmap any memory when length arguments is equal to 0.
So don't free meta shadow in this case as well.

llvm-svn: 234145
2015-04-06 07:57:32 +00:00
Viktor Kutuzov eff2d98ecc [Tsan] Do not sanitize memset() and other functions during initialization
Differential Revision: http://reviews.llvm.org/D8544

llvm-svn: 233378
2015-03-27 14:12:28 +00:00
Dmitry Vyukov 2034ce665a tsan: don't write to meta shadow unnecessarily
If user does malloc(1<<30), the write to meta shadow
can cause excessive memory consumption.

llvm-svn: 233373
2015-03-27 12:22:44 +00:00
Alexey Samsonov 6279a07eaa [TSan] Disable -Wno-maybe-uninitialized in yet another place.
llvm-svn: 233044
2015-03-24 00:38:43 +00:00
Alexey Samsonov 58e4835779 [TSan] Fixup for r233038: restrict the -Wno-maybe-uninitialized flag to GCC only.
llvm-svn: 233042
2015-03-23 23:44:38 +00:00
Alexey Samsonov 543e966142 [TSan] Disable noisy GCC warning.
llvm-svn: 233038
2015-03-23 23:29:39 +00:00
Alexander Potapenko b9c928bd10 [libsanitizer] Fix OpenFile() usage in TSan and DFSan.
This is a follow-up for r232936.

llvm-svn: 232937
2015-03-23 10:32:28 +00:00
Viktor Kutuzov a7d323e996 [Tsan] Do not sanitize memcpy() during thread initialization on FreeBSD
Differential Revision: http://reviews.llvm.org/D8324

llvm-svn: 232381
2015-03-16 14:42:21 +00:00
Viktor Kutuzov 285dd51b7b [Tsan] Do not declare std_suppressions when not used
Differential Revision: http://reviews.llvm.org/D8288

llvm-svn: 232074
2015-03-12 18:14:42 +00:00
Viktor Kutuzov 07a21dc46d [Tsan] Adjust SA_SIGINFO and SIG_SETMASK values on FreeBSD.
Differential Revision: http://reviews.llvm.org/D8176

llvm-svn: 232073
2015-03-12 18:12:43 +00:00
Dmitry Vyukov b75212878f tsan: fix a bug in MetaMap::ResetRange
The bug was uncovered by NegativeTests.MmapTest from
data-race-test suite, so port it as well.

llvm-svn: 232032
2015-03-12 12:48:19 +00:00
Dmitry Vyukov a60829a1b6 tsan: fix crash during __tsan_java_move
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.

llvm-svn: 232029
2015-03-12 11:24:16 +00:00
Dmitry Vyukov b79ac88155 asan: fix signal handling during stoptheworld
The problem is that without SA_RESTORER flag, kernel ignores the handler. So tracer actually did not setup any handler.
Add SA_RESTORER flag when setting up handlers.
Add a test that causes SIGSEGV in stoptheworld callback.
Move SignalContext from asan to sanitizer_common to print better diagnostics about signal in the tracer thread.

http://reviews.llvm.org/D8005

llvm-svn: 230978
2015-03-02 17:36:02 +00:00
Alexey Samsonov 0b0cafc8fc [Sanitizer] Print column number in SUMMARY line if it's available.
llvm-svn: 230721
2015-02-27 02:29:25 +00:00
Alexey Samsonov 1f5bcbe918 Re-land part of r230171: fix GoTsanRuntimeCheck with ccache.
llvm-svn: 230247
2015-02-23 19:35:42 +00:00
Dmitri Gribenko 9cbc6f42aa Revert r230171 "TSan runtime: unbreak the build with ccache"
It broke a buildbot with a non-clang (?) compiler.

llvm-svn: 230174
2015-02-22 12:20:05 +00:00
Dmitri Gribenko bc4c42c345 TSan runtime: unbreak the build with ccache
llvm-svn: 230171
2015-02-22 11:04:59 +00:00
Alexey Samsonov d1c318657b [Sanitizer] Refactor SuppressionContext class.
SuppressionContext is no longer a singleton, shared by all sanitizers,
but a regular class. Each of ASan, LSan, UBSan and TSan now have their
own SuppressionContext, which only parses suppressions specific to
that sanitizer.

"suppressions" flag is moved away from common flags into tool-specific
flags, so the user now may pass
  ASAN_OPTIONS=suppressions=asan_supp.txt LSAN_OPIONS=suppressions=lsan_supp.txt
in a single invocation.

llvm-svn: 230026
2015-02-20 17:41:59 +00:00
Mohit K. Bhakkad 846de99fbd [TSan][MIPS64] Fix few more test cases for MIPS64
Patch by Sagar Thakur

Reviewers: dvyukov, samsonov, kcc.

Subscribers:  dsanders, mohit.bhakkad, Anand.Takale, llvm-commits.

Differential Revision: http://reviews.llvm.org/D7290

llvm-svn: 230002
2015-02-20 09:32:45 +00:00
Mohit K. Bhakkad a46d5a7438 [TSan][MIPS] Adding support for MIPS64
Patch by Sagar Thakur

Reviewers: dvyukov, samsonov, petarj, kcc, dsanders.

Subscribers:  mohit.bhakkad, Anand.Takale, llvm-commits.

Differential Revision: http://reviews.llvm.org/D6291

llvm-svn: 229972
2015-02-20 06:42:41 +00:00
Alexey Samsonov 1ec3c5bc99 [Sanitizer] Drop LibIgnore dependency on SuppressionContext. NFC.
Let each LibIgnore user (for now it's only TSan) manually go
through SuppressionContext and pass ignored library templates to
LibIgnore.

llvm-svn: 229924
2015-02-19 22:56:49 +00:00
Alexey Samsonov d311566e1a Remove support for building sanitizers from Makefile/autoconf build on Linux.
This is a re-application of r229554 restricted to Linux build only.
Apple still uses Makefile/autoconf to build Clang and sanitizers.

llvm-svn: 229756
2015-02-18 22:26:49 +00:00
Dmitry Vyukov 2a80437038 tsan: add -Wno-maybe-uninitialized to mingw gcc build flags
As per discussion with David Blaikie here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150216/260289.html

llvm-svn: 229657
2015-02-18 09:37:31 +00:00
Matthias Braun c0a2279099 Revert "Remove support for building sanitizers from Makefile/autoconf build."
This reverts commit r229556.

Reverting this for now as internal apple builds rely on this
functionality.

llvm-svn: 229585
2015-02-17 23:30:51 +00:00
Alexey Samsonov e194dfa6be [TSan] Provide default values for compile definitions.
Provide defaults for TSAN_COLLECT_STATS and TSAN_NO_HISTORY.
Replace #ifdef directives with #if. This fixes a bug introduced
in r229112, where building TSan runtime with -DTSAN_COLLECT_STATS=0
would still enable stats collection and reporting.

llvm-svn: 229581
2015-02-17 23:23:10 +00:00
Alexey Samsonov d907016dd0 Remove support for building sanitizers from Makefile/autoconf build.
They autotools build has a number of missing features, supports less
OS, architectures, build configurations, doesn't have any tests and
is hard to support in sync with CMake build.

llvm-svn: 229556
2015-02-17 21:53:45 +00:00
Dmitry Vyukov 620ebaa9c1 tsan: remove everything related to rss/background thread in Go mode
In Go mode the background thread is not started (internal_thread_start is empty).
There is no sense in having this code compiled in.
Also removes dependency on sanitizer_linux_libcdep.cc which is good,
ideally Go runtime does not depend on libc at all.

llvm-svn: 229396
2015-02-16 14:49:34 +00:00
Dmitry Vyukov 1236868f85 tsan: fix windows build script
add missing source files
+ add -std=c++11 as it is now required to build compiler-rt

llvm-svn: 229393
2015-02-16 13:54:32 +00:00
Dmitry Vyukov 13fd535bcb tsan: fix shadow memory mapping on windows
llvm-svn: 229391
2015-02-16 13:52:04 +00:00
Dmitry Vyukov a3bdbadfd2 tsan: fix build
Revision 229127 introduced a bug:
zero value is not OK for trace headers,
because stack0 needs constructor call.
Instead unmap the unused part of trace after
all ctors have been executed.

llvm-svn: 229263
2015-02-14 16:14:10 +00:00
Dmitry Vyukov 6aaedb0829 tsan: always subtract one from program counters
Go has a pending change to pass proper PCs to tsan:
https://go-review.googlesource.com/#/c/4902/
So now we can always subtract one from PCs.

llvm-svn: 229262
2015-02-14 16:06:22 +00:00
Dmitry Vyukov 8a9d23bf53 tsan: don't initialize trace header in release mode
We are going to use only a small part of the trace with the default
value of history_size. However, the constructor writes to the whole trace.
It writes mostly zeros, so freshly mmaped memory will do.
The only non-zero field if mutex type used for debugging.

Reduces per-goroutine overhead by 8K.

https://code.google.com/p/thread-sanitizer/issues/detail?id=89

llvm-svn: 229127
2015-02-13 17:39:03 +00:00
Dmitry Vyukov b57e39e310 tsan: fix build
llvm-svn: 229120
2015-02-13 16:08:43 +00:00
Dmitry Vyukov 816bf44ac6 tsan: reduce history size in Go mode
The ContainsSameAccess optimization substantially reduces pressure
on trace by eliminating duplicate accesses. So now we can reduce
default trace size to reduce per-goroutine memory consumption.
Current default size is 64K events, new -- 32K events.
In either case user can change it with GORACE env var.

Reduces per-goroutine memory consumption from 356K to 226K.

llvm-svn: 229117
2015-02-13 15:59:23 +00:00
Dmitry Vyukov 05841b1e39 tsan: disable deadlock detector in Go mode
Go does not use that.
https://code.google.com/p/thread-sanitizer/issues/detail?id=89

llvm-svn: 229116
2015-02-13 15:44:50 +00:00
Dmitry Vyukov a22870ec7a tsan: remove internal deadlock detector from ThreadState in Go mode
Go does not use that.
https://code.google.com/p/thread-sanitizer/issues/detail?id=89

llvm-svn: 229115
2015-02-13 15:37:11 +00:00
Dmitry Vyukov c30c5f7d9d tsan: reduce size of vector clock in Go mode
Go does not have freed memory.
Reduces per-goroutine overhead from 455K to 356K.

https://code.google.com/p/thread-sanitizer/issues/detail?id=89

llvm-svn: 229113
2015-02-13 15:32:34 +00:00
Dmitry Vyukov 41f4eba02d tsan: remove stats from ThreadState ifndef TSAN_COLLECT_STATS
Issue 89: Uses a lot of memory for each goroutine
https://code.google.com/p/thread-sanitizer/issues/detail?id=89

llvm-svn: 229112
2015-02-13 15:25:47 +00:00
Dmitry Vyukov af3b09663b tsan: fix stack printing
strip_path_prefix was not stripped from file names.

llvm-svn: 229106
2015-02-13 14:27:43 +00:00
Alexey Samsonov 1225816a2d [Sanitizer] Change InitializeFlags() signatures. NFC.
These functions are always used to initialize singleton flags(), as
well as other global data (common_flags()).

llvm-svn: 228894
2015-02-12 00:36:42 +00:00
Yury Gribov 8f848ff5ed [ASan] Add use_madv_dontdump flag.
Differential Revision: http://reviews.llvm.org/D7294

llvm-svn: 227959
2015-02-03 10:15:15 +00:00
Alexey Samsonov ec80d97c77 [TSan] Fix remaining bashism in buildgo.sh script.
llvm-svn: 227893
2015-02-02 23:14:46 +00:00
Alexey Samsonov d45837155d [TSan] Update check_analyze.sh expectations to match trunk Clang output.
llvm-svn: 227877
2015-02-02 22:17:23 +00:00
Alexey Samsonov 1270c530e8 [TSan] Fix Go sanity check script.
llvm-svn: 227870
2015-02-02 22:07:39 +00:00
Alexey Samsonov 46fe4a640d [TSan] Add Go runtime sanity check to CMake build.
llvm-svn: 227852
2015-02-02 20:37:28 +00:00
Alexey Samsonov c91ffd2c8f [TSan] Build runtime with -msse3 flag.
llvm-svn: 227850
2015-02-02 20:37:25 +00:00
Alexey Samsonov a11a86b9ce [TSan] Fix Go build.
llvm-svn: 227634
2015-01-30 23:04:57 +00:00
Viktor Kutuzov 07e6c00171 [Sanitizers] Introduce GET_LINK_MAP_BY_DLOPEN_HANDLE() macro
Differential Revision: http://reviews.llvm.org/D7233

llvm-svn: 227570
2015-01-30 12:43:52 +00:00
Alexey Samsonov 8b3334d909 [TSan] Fix -Werror=sign-compare warning. NFC.
llvm-svn: 227527
2015-01-30 01:02:12 +00:00
Dmitry Vyukov 312ad250ff tsan: properly instrument unaligned accesses
If a memory access is unaligned, emit __tsan_unaligned_read/write
callbacks instead of __tsan_read/write.
Required to change semantics of __tsan_unaligned_read/write to not do the user memory.
But since they were unused (other than through __sanitizer_unaligned_load/store) this is fine.
Fixes long standing issue 17:
https://code.google.com/p/thread-sanitizer/issues/detail?id=17

llvm-svn: 227230
2015-01-27 20:19:12 +00:00
Dmitry Vyukov 48846ba570 tsan: use hacky call only on x86_64
required for mips64 and aarch64 ports

llvm-svn: 226829
2015-01-22 14:13:56 +00:00
Viktor Kutuzov 1f01782e5c [Sanitizers] Intercept opendir()
Differential Revision: http://reviews.llvm.org/D6968

llvm-svn: 226648
2015-01-21 08:54:01 +00:00
Dmitry Vyukov 8070ac6bd6 tsan: don't unroll memory access loop in debug mode
MemoryAccess function consumes ~4K of stack in debug mode,
in significant part due to the unrolled loop.
And gtest gives only 4K of stack to death test
threads, which causes stack overflows in debug mode.

llvm-svn: 226644
2015-01-21 08:09:13 +00:00
Kostya Serebryany c6338ac943 [asan] use MADV_NOHUGEPAGE for shadow to reduce the actual memory usage
llvm-svn: 226636
2015-01-21 02:05:31 +00:00
Evgeniy Stepanov f074b3c2de [asan] Allow changing verbosity in activation flags.
This change removes some debug output in asan_flags.cc that
was reading the verbosity level before all the flags were parsed.

llvm-svn: 226566
2015-01-20 13:21:20 +00:00
Dmitry Vyukov cc5e40811b tsan: remove TSAN_SHADOW_COUNT
TSAN_SHADOW_COUNT is defined to 4 in all environments.
Other values of TSAN_SHADOW_COUNT were never tested and
were broken by recent changes to shadow mapping.
Remove it as there is no reason to fix nor maintain it.

llvm-svn: 226466
2015-01-19 15:01:07 +00:00
Evgeniy Stepanov a2edd9159a [sanitizer] Make unrecognized flags not fatal.
Print a warning at verbosity=1 and higher instead of dying immediately.

llvm-svn: 226458
2015-01-19 12:22:57 +00:00
Evgeniy Stepanov f294d5b829 [sanitizer] Flag parser rewrite.
The new parser is a lot stricter about syntax, reports unrecognized
flags, and will make it easier to implemented some of the planned features.

llvm-svn: 226169
2015-01-15 15:13:43 +00:00
Ehsan Akhgari d918614586 Fix two extra semicolon warnings
Reviewers: timurrrr

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6890

llvm-svn: 225635
2015-01-12 17:03:02 +00:00
Alexey Samsonov 7eba6dfdaa [TSan] Fix Go build.
llvm-svn: 225336
2015-01-07 02:12:41 +00:00
Alexey Samsonov 03499e920b [Sanitizer] Change the runtime flag representation.
This mirrors r225239 to all the rest sanitizers:
ASan, DFSan, LSan, MSan, TSan, UBSan.

Now the runtime flag type, name, default value and
description is located in the single place in the
.inc file.

llvm-svn: 225327
2015-01-07 00:38:00 +00:00
Alexey Samsonov 6239ebc1c2 [Sanitizer] Improve unit tests in COMPILER_RT_DEBUG=ON mode.
Propagate -DSANITIZER_DEBUG definition to unit tests.
Make sure unit tests depend on compiler-rt headers.

llvm-svn: 225298
2015-01-06 20:58:40 +00:00
Alexey Samsonov df3aeb8e71 Remove TSAN_DEBUG in favor of SANITIZER_DEBUG.
llvm-svn: 225111
2015-01-03 04:29:12 +00:00
Alexey Samsonov 3b1885448a Replace DCHECK with DCHECK_LE where appropriate.
llvm-svn: 225110
2015-01-03 04:29:05 +00:00
Alexey Samsonov c426c337ed Revert "Revert r224736: "[Sanitizer] Make CommonFlags immutable after initialization.""
Fix test failures by introducing CommonFlags::CopyFrom() to make sure
compiler doesn't insert memcpy() calls into runtime code.

Original commit message:
Protect CommonFlags singleton by adding const qualifier to
common_flags() accessor. The only ways to modify the flags are
SetCommonFlagsDefaults(), ParseCommonFlagsFromString() and
OverrideCommonFlags() functions, which are only supposed to be
called during initialization.

llvm-svn: 225088
2015-01-02 21:28:37 +00:00
Chandler Carruth 6173e869eb Revert r224736: "[Sanitizer] Make CommonFlags immutable after initialization."
We've got some internal users that either aren't compatible with this or
have found a bug with it. Either way, this is an isolated cleanup and so
I'm reverting it to un-block folks while we investigate. Alexey and
I will be working on fixing everything up so this can be re-committed
soon. Sorry for the noise and any inconvenience.

llvm-svn: 225079
2015-01-02 09:59:38 +00:00
Dmitry Vyukov bda655004e tsan: fix trace initialization during thread id reuse
The current code leaves the first event in the trace part uninitialized
(from the previous thread). It can cause unpredictable behavior
during stack/mutexset restoration.
Initialize the first event to a fake harmless memory access.

llvm-svn: 224834
2014-12-25 10:32:25 +00:00
Dmitry Vyukov 10070626b7 tsan: fix style
Usually we roll the variable declaration into the condition in cases like this.

llvm-svn: 224755
2014-12-23 07:21:23 +00:00
Alexey Samsonov b430f6e17a [Sanitizer] Make CommonFlags immutable after initialization.
Summary:
Protect CommonFlags singleton by adding const qualifier to
common_flags() accessor. The only ways to modify the flags are
SetCommonFlagsDefaults(), ParseCommonFlagsFromString() and
OverrideCommonFlags() functions, which are only supposed to be
called during initialization.

Test Plan: regression test suite

Reviewers: kcc, eugenis, glider

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6741

llvm-svn: 224736
2014-12-22 21:46:10 +00:00
Dmitry Vyukov c1a04162ba tsan: reset stack0 in the first partition of thread trace
stack0/mset0 contained bogus values from the previous thread
that used the same id

llvm-svn: 224702
2014-12-22 12:32:52 +00:00
Dmitry Vyukov 8f9911b571 tsan: fix debugging output
llvm-svn: 224701
2014-12-22 12:31:32 +00:00
Dmitry Vyukov 732b128129 tsan: add acquire/release functions to java interface
they are required to handle synchronization on volatile/final fields

llvm-svn: 224697
2014-12-22 09:44:56 +00:00
Alexey Samsonov 2f8c8d59b2 [Sanitizer] Refactor CommonFlags interface. NFC.
Add CommonFlags::SetDefaults() and CommonFlags::ParseFromString(),
so that this object can be easily tested. Enforce
that ParseCommonFlagsFromString() and SetCommonFlagsDefaults()
work only with singleton CommonFlags, shared across all sanitizer
runtimes.

llvm-svn: 224617
2014-12-19 21:40:04 +00:00
Dmitry Vyukov 7fe690ce12 tsan: intercept closedir
llvm-svn: 224575
2014-12-19 14:29:40 +00:00
Dmitry Vyukov f6fab7adcf tsan: disable __tls_get_addr interceptor
see the added comments for details, it's messy

llvm-svn: 224531
2014-12-18 18:39:55 +00:00
Dmitry Vyukov f7790012a5 tsan: fix data races between signal handler and sigaction
signal handler reads sa_sigaction when a concurrent sigaction call can modify it
as the result in could try to call SIG_DFL or a partially overwritten function pointer

llvm-svn: 224530
2014-12-18 18:31:47 +00:00
Dmitry Vyukov e1881269f8 tsan: don't crash with NULL deref during reporting
tctx==NULL crash observed during deadlock reporting.
There seems to be some bugs in the deadlock detector,
but it is still useful to be more robust during reporting.

llvm-svn: 224508
2014-12-18 10:19:32 +00:00
Dmitry Vyukov a4cd69217b tsan: disable flaky debug check
see the comment for details

llvm-svn: 224507
2014-12-18 10:17:01 +00:00
Kostya Serebryany 43eb7735f2 [asan] new flag: hard_rss_limit_mb
llvm-svn: 224353
2014-12-16 19:13:01 +00:00
Alexey Samsonov 6334f46db8 [Sanitizer] Introduce Allocator::may_return_null bool flag.
Summary:
Turn "allocator_may_return_null" common flag into an
Allocator::may_return_null bool flag. We want to make sure
that common flags are immutable after initialization. There
are cases when we want to change this flag in the allocator
at runtime: e.g. in unit tests and during ASan activation
on Android.

Test Plan: regression test suite, real-life applications

Reviewers: kcc, eugenis

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6623

llvm-svn: 224148
2014-12-12 20:07:35 +00:00
Dmitry Vyukov 4bde5c42b0 tsan: don't subtract one from fake PCs
These are fake and not actual PCs, more like function IDs.
Pass them to external symbolizer untouched.

llvm-svn: 224022
2014-12-11 16:12:16 +00:00
Alexey Samsonov 20962292e8 [DD] Don't store the second copy of CommonFlags inside DDFlags.
llvm-svn: 223909
2014-12-10 02:30:04 +00:00
Alexey Samsonov c2485cab33 [CMake] Make sure dd is built as a part of compiler-rt.
Remove unused variables and definitions in CMake files
for TSan and DD (deadlock detector).

llvm-svn: 223908
2014-12-10 02:14:15 +00:00
Kostya Serebryany 83ed889bbd [tsan] remove TSAN_GO in favor of SANITIZER_GO
llvm-svn: 223732
2014-12-09 01:31:14 +00:00
Kostya Serebryany 6c54a6b5dd [asan] move GetRSS from tsan to sanitizer_common
llvm-svn: 223730
2014-12-09 01:22:59 +00:00
Dmitry Vyukov bf253a3d3f tsan: protect trace memory range on startup
so that user does not map something there ahead of us

llvm-svn: 223456
2014-12-05 10:06:06 +00:00
Alexey Samsonov 656c29b08f Replace InternalScopedBuffer<char> with InternalScopedString where applicable.
Summary: No functionality change.

Test Plan: make check-all

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6472

llvm-svn: 223164
2014-12-02 22:20:11 +00:00
Alexey Samsonov 0e90668f14 Simplify Symbolizer::SymbolizePC() interface.
Return a linked list of AddressInfo objects, instead of using an array of
these objects as an output parameter. This simplifies the code in callers
of this function (especially TSan).

Fix a few memory leaks from internal allocator, when the returned
AddressInfo objects were not properly cleared.

llvm-svn: 223145
2014-12-02 19:48:40 +00:00
Viktor Kutuzov fbd6ec09df [Tsan] Do not flush all streams on exit
Differential Revision: http://reviews.llvm.org/D6462

llvm-svn: 223121
2014-12-02 14:59:51 +00:00
Dmitry Vyukov 1f84559b7d tsan: fix Go build
llvm-svn: 222342
2014-11-19 10:43:11 +00:00
Dmitry Vyukov bd167973b4 tsan: add description of AcquireGlobal function
llvm-svn: 222228
2014-11-18 06:44:43 +00:00
Alexey Samsonov 4925fd4b05 Fix -Wcast-qual warnings in sanitizers
llvm-svn: 221936
2014-11-13 22:40:59 +00:00
Alexey Samsonov fbaaed6b58 [Sanitizer] Introduce "stack_trace_format" runtime flag.
This flag can be used to specify the format of stack frames - user
can now provide a string with placeholders, which should be printed
for each stack frame with placeholders replaced with actual data.
For example "%p" will be replaced by PC, "%s" will be replaced by
the source file name etc.

"DEFAULT" value enforces default stack trace format currently used in
all the sanitizers except TSan.

This change also implements __sanitizer_print_stack_trace interface
function in TSan.

llvm-svn: 221469
2014-11-06 18:43:45 +00:00
Alexey Samsonov 70f3897b0a [Sanitizer] Introduce generic stack frame rendering machinery
Summary:
This commit introduces function __sanitizer::RenderFrame()
that allows to render the contents of AddressInfo (essentially, symbolized stack frame)
using the custom format string. This function can be used to
implement stack frame formatting for both ThreadSanitizer and
generic StackTrace::Print(), used in another places. This paves the
way towards allowing user to control the format of stack frames,
obtaining them in any format he desires, and/or enforcing the consistent
output from all sanitizers.

Test Plan: compiler-rt test suite

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6140

llvm-svn: 221409
2014-11-05 22:44:36 +00:00
Alexey Samsonov 860a1abf1d [TSan] Refactor/simplify ReportLocation structure.
# Make DataInfo (describing a global) a member of ReportLocation
    to avoid unnecessary copies and allocations.
  # Introduce a constructor and a factory method, so that
    all structure users don't have to go to internal allocator directly.
  # Remove unused fields (file/line).

No functionality change.

llvm-svn: 221302
2014-11-04 22:07:57 +00:00
Alexey Samsonov 0b622f1d64 Correct the usage of DataInfo structure in TSan
llvm-svn: 221297
2014-11-04 21:26:56 +00:00
Alexey Samsonov e3754634c0 [TSan] Make ReportStack contain __sanitizer::AddressInfo object.
AddressInfo contains the results of symbolization. Store this object
directly in the symbolized stack, instead of copying data around and
making unnecessary memory allocations.

No functionality change.

llvm-svn: 221294
2014-11-04 20:52:37 +00:00
Alexey Samsonov 26ca05ad96 [Sanitizer] Get rid of unnecessary allocations in StripModuleName. NFC.
llvm-svn: 221287
2014-11-04 19:34:29 +00:00
Alexey Samsonov 3931dca7ec [TSan] Keep original function and filename in ReportStack.
TSan used to do the following transformations with data obtained
from the symbolizer:
1) Strip "__interceptor_" prefix from function name.
2) Use "strip_path_prefix" runtime flag to strip filepath.

Now these transformations are performed right before the stack trace
is printed, and ReportStack structure contains original information.

This seems like a right thing to do - stripping is a detail of report
formatting implementation, and should belong there. We should, for
example, use original path to source file when we apply suppressions.

This change also make "strip_path_prefix" flag behavior in TSan
consistent with all the other sanitizers - now it should actually
match *the prefix* of path, not some substring. E.g. earlier TSan
would turn "/usr/lib/libfoo.so" into "libfoo.so" even if strip_path_prefix
was "/lib/".

Finally, strings obtained from symbolizer come from internal allocator,
and "stripping" them early by incrementing a "char*" ensures they can
never be properly deallocated, which is a bug.

llvm-svn: 221283
2014-11-04 18:41:38 +00:00
Alexey Samsonov 8f1632d5c1 [TSan] Don't strip binary/library name until the moment we print it.
This commit changes the place where TSan runtime turns full path
to binary or shared library into its basename
(/usr/foo/mybinary -> mybinary). Instead of doing it as early as possible
(when we obtained the full path from the symbolizer), we now do it as
late as possible (right before printing the error report).

This seems like a right thing to do - stripping to basename is a detail
of report formatting implementation, and should belong there. Also, we
might need the full path at some point - for example, to match the
suppressions.

llvm-svn: 221225
2014-11-04 01:55:20 +00:00
Alexey Samsonov 7acb67607b [TSan] Remove bogus unused global variables
llvm-svn: 221195
2014-11-03 22:46:13 +00:00
Alexey Samsonov 40733a8024 [TSan] Use StackTrace from sanitizer_common where applicable
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
2014-11-03 22:23:44 +00:00
Alexey Samsonov 46ecdeecc4 [TSan} Build Go version with -std=c++11
llvm-svn: 221192
2014-11-03 22:18:12 +00:00
Alexey Samsonov e6bbcfa3df [TSan] Fix signed-compare warning in the unit test
llvm-svn: 221190
2014-11-03 22:17:39 +00:00
Viktor Kutuzov adf81dbcc6 [Tsan] Fix references to renamed variables in DPrintf()
Differential Revision: http://reviews.llvm.org/D5993

llvm-svn: 220674
2014-10-27 11:22:24 +00:00
Viktor Kutuzov 9deb007191 [Tsan] Make calloc() to not track allocated space unless thread is completely initialized
Differential Revision: http://reviews.llvm.org/D5992

llvm-svn: 220673
2014-10-27 11:19:08 +00:00
Viktor Kutuzov a58fed9ab7 [Tsan] Fix guessing data range on FreeBSD
Differential Revision: http://reviews.llvm.org/D5990

llvm-svn: 220672
2014-10-27 11:14:24 +00:00
Alexey Samsonov 3741ab82ba Change StackDepot interface to use StackTrace more extensively
llvm-svn: 220637
2014-10-26 06:23:07 +00:00
Alexey Samsonov 6e7af8156f Fixup deadlock sanitizer after r220635
llvm-svn: 220636
2014-10-26 05:43:17 +00:00
Alexey Samsonov 9c85927012 [Sanitizer] Make StackTrace a lightweight reference to array of PCs, and
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

llvm-svn: 220635
2014-10-26 03:35:14 +00:00