Commit Graph

5781 Commits

Author SHA1 Message Date
Kuba Brecka 06bbca9ec4 [tsan] Add TSan __tsan_atomic* functions to tsan_interface.h
To avoid using the public header (tsan_interface_atomic.h), which has different data types, let's add all the __tsan_atomic* functions to tsan_interface.h. 

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

llvm-svn: 265663
2016-04-07 11:59:36 +00:00
Kuba Brecka 399af93242 [tsan] Add interceptors for dispatch_apply
Adding an interceptor with two more release+acquire pairs to avoid false positives with dispatch_apply.

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

llvm-svn: 265662
2016-04-07 11:52:51 +00:00
Kuba Brecka e316bb61b3 [tsan] Add XPC support (OS X)
XPC APIs have async callbacks, and we need some more happen-before edges to avoid false positives. This patch add them, plus a test case (sorry for the long boilerplate code, but XPC just needs all that).

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

llvm-svn: 265661
2016-04-07 11:47:11 +00:00
Kuba Brecka cecb7faea2 [tsan] Add support for dispatch event sources
GCD has APIs for event sources, we need some more release-acquire pairs to avoid false positives in TSan.

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

llvm-svn: 265660
2016-04-07 11:38:53 +00:00
Kuba Brecka 33c15c91a6 [tsan] Fix synchronization in dispatch_sync
In the interceptor for dispatch_sync, we're currently missing synchronization between the callback and the code *after* the call to dispatch_sync. This patch fixes this by adding an extra release+acquire pair to dispatch_sync() and similar APIs. Added a testcase.

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

llvm-svn: 265659
2016-04-07 11:33:44 +00:00
Xinliang David Li 5d2e06a34b sync up with master copy
llvm-svn: 265609
2016-04-06 22:30:14 +00:00
Yabin Cui c7db569cc1 [tsan] Fix freebsd build.
Summary:
Freebsd doesn't have <sys/personality.h>, so call personality() only in
SANITIZER_LINUX.

Reviewers: llvm-commits, dvyukov, zatrazz, rengolin, beanz

Subscribers: beanz, emaste

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

llvm-svn: 265378
2016-04-05 05:37:48 +00:00
Yabin Cui e3f558ba14 [tsan] Disable randomized address space on aarch64 linux.
Summary:
After patch https://lkml.org/lkml/2015/12/21/340 is introduced in
linux kernel, the random gap between stack and heap is increased
from 128M to 36G on 39-bit aarch64. And it is almost impossible
to cover this big range. So we need to disable randomized virtual
space on aarch64 linux.

Reviewers: llvm-commits, zatrazz, dvyukov, rengolin

Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines

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

llvm-svn: 265366
2016-04-04 23:48:25 +00:00
Dmitry Vyukov 0d9b7bc9ad tsan: fix ignore handling in signal handlers
We've reset thr->ignore_reads_and_writes, but forget to do
thr->fast_state.ClearIgnoreBit(). So ignores were not effective
reset and fast_state.ignore_bit was corrupted if signal handler
itself uses ignores.

Properly reset/restore fast_state.ignore_bit around signal handlers.

llvm-svn: 265288
2016-04-04 10:52:59 +00:00
Kuba Brecka d0e83a6eb2 [sanitizer] Make AtosSymbolizer more resilient when symbolicating a zero address
llvm-svn: 265269
2016-04-03 19:13:03 +00:00
Reid Kleckner 1992ac75db Fix warnings uncovered by building with clang-cl
Move ifdefs to avoid unused static helpers. Move alignment attribute so
that it is respected in GCC and MSVC.

llvm-svn: 265153
2016-04-01 17:09:12 +00:00
Reid Kleckner a8e5c0c200 Fix a load of -Wunknown-pragma warnings from clang-cl
llvm-svn: 265152
2016-04-01 17:09:08 +00:00
Chris Bieneman ac400900da [Darwin] [Builtins] Cleaning up OS X exclude lists. NFC.
This just gets rid of a bunch of empty object file warnings. It doesn't impact the generated archives.

llvm-svn: 264751
2016-03-29 17:34:13 +00:00
Chris Bieneman 8de525696f [Darwin] [Builtins] Remove multi3 from the exclude list.
This addresses PR27077. For some historical reason Darwin wasn't shipping multi3 in the compiler builtin library or in the OS builtin library. This caused building ffmpeg to fail because Polly was generating calls to multi3. It is easy enough to just add the builtin.

llvm-svn: 264750
2016-03-29 17:24:23 +00:00
Chris Bieneman c4613f457a [Darwin] [Builtins] Cleaning up 10.4 exclude lists NFC
This just gets rid of a bunch of empty object file warnings. It doesn't impact the generated archives.

llvm-svn: 264749
2016-03-29 17:24:21 +00:00
Adam Nemet fadba5d4d4 [PGO] More comments how function pointers for indirect calls are mapped
to function names

Summary:
Hopefully this will make it easier for the next person to figure all
this out...

Reviewers: bogner, davidxl

Subscribers: davidxl, cfe-commits

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

llvm-svn: 264680
2016-03-28 22:16:29 +00:00
Sean Silva c2feac75fd [libprofile] Handle '\\' in __llvm_profile_recursive_mkdir
This is implicitly needed at least by gcc-flag-compatibility.test

The thing that needs it is the `\` preceding the "default.profraw"
appended internally by clang when doing `-fprofile-use=`.

Clang uses `\` because is uses sys::path::append which will use `\` on a
Windows host. This is wrong, but I don't think there's an easy way to
solve it (maybe just always using `/` since places that accept `\` also
tend to accept `/`, but not the other way around).

llvm-svn: 264665
2016-03-28 21:32:46 +00:00
Ryan Govostes dc91fe5d8b [asan] Add runtime support for __asan_(un)register_image_globals
This change introduces routines that register and unregister all
instrumented globals in a loaded executable image.

These routines are only implemented on Darwin, where globals metadata
is expected to be placed in the __DATA,__asan_globals section.

Review: http://reviews.llvm.org/D16841
llvm-svn: 264644
2016-03-28 20:28:17 +00:00
Kuba Brecka 0d026d9e9e [tsan] Fix a crash when exiting the main thread (e.g. dispatch_main)
This patch fixes the custom ThreadState destruction on OS X to avoid crashing when dispatch_main calls pthread_exit which quits the main thread.

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

llvm-svn: 264627
2016-03-28 19:36:25 +00:00
Adam Nemet a68d755774 [PGO] Update r264612 to use C-style comment
llvm-svn: 264615
2016-03-28 18:47:44 +00:00
Adam Nemet 42a6fe199f [PGO] Comment how function pointers for indirect calls are mapped to function names
Summary:
Hopefully this will make it easier for the next person to figure all
this out...

Reviewers: bogner, davidxl

Subscribers: llvm-commits

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

llvm-svn: 264612
2016-03-28 18:29:36 +00:00
Kostya Serebryany b48f8f09b1 [asan] bump the scariness score of read-after-frees (based on feedback from the Chrome security team)
llvm-svn: 264481
2016-03-26 00:00:19 +00:00
Derek Bruening e988af9073 [sanitizer] Add memset, memmove, and memcpy to the common interceptors
Summary:
Currently, sanitizer_common_interceptors.inc has an implicit, undocumented
assumption that the sanitizer including it has previously declared
interceptors for memset and memmove.  Since the memset, memmove, and memcpy
routines require interception by many sanitizers, we add them to the
set of common interceptions, both to address the undocumented assumption
and to speed future tool development.  They are intercepted under a new
flag intercept_intrin.

The tsan interceptors are removed in favor of the new common versions.  The
asan and msan interceptors for these are more complex (they incur extra
interception steps and their function bodies are exposed to the compiler)
so they opt out of the common versions and keep their own.

Reviewers: vitalybuka

Subscribers: zhaoqin, llvm-commits, kcc

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

llvm-svn: 264451
2016-03-25 19:33:45 +00:00
Reid Kleckner 3b0290570b [asan] Intercept all Heap* related imports from ucrtbase.dll
ucrtbase.dll appears to be built with some kind of cross-module
inlining, because there are calls to imported Heap* routines sprinkled
throughout the code. This inlining defeats our attempts to hotpatch
malloc, _malloc_base, and related functions. Failing to intercept an
allocation or deallocation results in a crash when the program attempts
to deallocate or reallocate memory with the wrong allocator.

This change patches the IAT of ucrtbase.dll to replace the addresses of
the imported Heap* functions with implementations provided by ASan.  We
don't globally intercept the win32 Heap* functions because they are
typically used by system DLLs that run before ASan initializes.
Eventually, we may want to intercept them, but for now I think this is
the minimal change that will keep ASan stable.

Reviewers: samsonov

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

llvm-svn: 264327
2016-03-24 20:19:48 +00:00
Kuba Brecka 3bab18d4af [tsan] Fix fork() and fork-based tests for OS X
On OS X, fork() under TSan asserts (in debug builds only) because REAL(fork) calls some intercepted functions, which check that no internal locks are held via CheckNoLocks(). But the wrapper of fork intentionally holds some locks. This patch fixes that by using ScopedIgnoreInterceptors during the call to REAL(fork). After that, all the fork-based tests seem to pass on OS X, so let's just remove all the UNSUPPORTED: darwin annotations we have.

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

llvm-svn: 264261
2016-03-24 11:54:33 +00:00
Kuba Brecka 46b9363683 [tsan] Use direct syscalls for internal_mmap and internal_munmap on OS X
On OS X, internal_mmap just uses mmap, which can invoke callbacks into libmalloc (e.g. when MallocStackLogging is enabled). This can subsequently call other intercepted functions, and this breaks our Darwin-specific ThreadState initialization. Let's use direct syscalls in internal_mmap and internal_munmap. Added a testcase.

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

llvm-svn: 264259
2016-03-24 11:50:21 +00:00
Derek Bruening b584410b80 [sanitizer] Add strnlen to the common interceptors
Summary:
Adds strnlen to the common interceptors, under the existing flag
intercept_strlen.

Removes the now-duplicate strnlen interceptor from asan and msan.
This adds strnlen to tsan, which previously did not intercept it.

Adds a new test of strnlen to the sanitizer_common test cases.

Reviewers: samsonov

Subscribers: zhaoqin, llvm-commits, kcc

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

llvm-svn: 264195
2016-03-23 21:24:28 +00:00
Reid Kleckner 03d703bb62 [asan] Export new and delete operators on Windows
This is necessary to support the dynamic CRT (/MD) with VS2015. In
VS2015, these symbols are no longer imported from a DLL, they provided
statically by msvcrt.lib. This means our approach of hotpatching the DLL
no longer works.

By exporting the symbols, we end up relying on the same mechanism that
we use to intercept symbols in the static CRT (/MT) case. The ASan
runtime always needs to appear first on the link line, and the linker
searches for symbol definitions from left to right. This means we can
stop hotpatching operator new and delete in the CRT, which is nice.

I think that the only reason we weren't exporting the symbols already is
because MSVC doesn't allow you to do it directly with
__declspec(dllexport). Instead, we can use
`#pragma comment(linker, "/export:foo")`, which is most of what the
attribute does under the hood. It does mean we have to write down the
mangled names of the operators, but that's not too bad.

llvm-svn: 264190
2016-03-23 20:45:52 +00:00
Renato Golin c8622e8cde Revert "[tsan] Disable randomized address space on linux aarch64."
This reverts commits r264068 and r264079, and they were breaking the build and
weren't reverted in time, nor they exhibited expected behaviour from the
reviewers. There is more to discuss than just a test fix.

llvm-svn: 264150
2016-03-23 11:24:30 +00:00
Derek Bruening bffdcde03d Test commit to verify repository access and fix a typo.
llvm-svn: 264112
2016-03-22 22:32:03 +00:00
Yabin Cui 28f367d7b3 [tsan] Fix check-tsan build by using CHECK_NE.
Reviewers: llvm-commits, srhines, dvyukov

Subscribers: srhines

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

llvm-svn: 264079
2016-03-22 18:12:18 +00:00
Yabin Cui 909e600abd [tsan] Disable randomized address space on linux aarch64.
Summary:
After patch https://lkml.org/lkml/2015/12/21/340 is introduced in
linux kernel, the random gap between stack and heap is increased
from 128M to 36G on 39-bit aarch64. And it is almost impossible
to cover this big range. So I think we need to disable randomized
virtual space on aarch64 linux.

Reviewers: kcc, llvm-commits, eugenis, zatrazz, dvyukov, rengolin

Subscribers: rengolin, aemerson, tberghammer, danalbert, srhines, enh

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

llvm-svn: 264068
2016-03-22 17:16:26 +00:00
Reid Kleckner d83633f552 [asan] Add ucrtbase.dll to the list of DLLs to intercept
Reduces number of test failures in check-asan-dynamic with VS 2015.

llvm-svn: 264061
2016-03-22 15:46:50 +00:00
Reid Kleckner 2310c658d8 [asan] Add one more x86 encoding to the interceptor for strrchr
llvm-svn: 264060
2016-03-22 15:46:43 +00:00
Reid Kleckner f2be78c07e Move -fms-compatibility-version=19 into target cflags
This reduces cflags duplication and allows us to build
sanitizer_common/tests with clang and the VS 2015 STL.

llvm-svn: 264017
2016-03-22 01:14:36 +00:00
Reid Kleckner ea4ae806bb Wrap 81 character line to satisfy linter
llvm-svn: 264014
2016-03-22 00:53:04 +00:00
Reid Kleckner 23d0fde535 [asan] Intercept strdup on Windows
Some unit tests were failing because we didn't intercept strdup.  It
turns out it works just fine on 2013 and 2015 with a small patch to the
interception logic.

llvm-svn: 264013
2016-03-22 00:52:47 +00:00
Reid Kleckner 79d2451cd7 [asan] Also apply r264006 to asan_win_dynamic_runtime_thunk.cc
llvm-svn: 264011
2016-03-22 00:34:53 +00:00
Reid Kleckner 81f7729c3d [asan] Set the unhandled exception filter slightly later during startup
VS 2015 moved the priority of their exception filter initializer from
XIY to XCAA. We now set ours to XCAB, which makes it run after both CRT
versions but before user constructors, as it should.

Fixes null_deref.cc and a variety of related tests with VS 2015. Only 4
failures remain.

llvm-svn: 264006
2016-03-21 23:51:21 +00:00
Reid Kleckner ed051774ba [asan] Add new _*_base interceptors for VS 2015
There are some places in the CRT (such as mbctype) that directly call
_malloc_base. If you are incrementally linking a binary with ASan from
before this change, this change appears to result in a linker error.
Retrying the link succeeds for some reason.

llvm-svn: 264005
2016-03-21 23:51:17 +00:00
Evgeniy Stepanov 7923ce692e [asan] Add strrchr to asan_win_dll_thunk.
"dll_host.cc" test says there is a mismatch.

llvm-svn: 263998
2016-03-21 22:42:15 +00:00
Evgeniy Stepanov accf390a75 [sanitizer] Add strchr* to the common interceptors
Adds strchr, strchrnul, and strrchr to the common interceptors, under a new
common flag intercept_strchr.

Removes the now-duplicate strchr interceptor from asan and all 3
interceptors from tsan. Previously, asan did not intercept strchrnul, but
does now; previously, msan did not intercept strchr, strchrnul, or strrchr,
but does now.

http://reviews.llvm.org/D18329

Patch by Derek Bruening!

llvm-svn: 263992
2016-03-21 21:36:17 +00:00
Mike Aizatsky 5d17878101 [sanitizier] initializing common flags.
Summary: Without SetDefaults() CommonFlags contain garbage.

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

llvm-svn: 263985
2016-03-21 20:53:20 +00:00
Reid Kleckner a4192a743a [asan] Pass -fms-compatibility-version=19 with VS 2015
This resolves errors about char16_t and char32_t when compiling 2015 STL
headers with clang.

llvm-svn: 263973
2016-03-21 19:37:30 +00:00
Reid Kleckner d2f05f52b4 [asan] Update hotpatch code for VS 2015 memset implementation
In VS 2015, the memset fill parameter is zero extended from one byte
instead of being copied wholesale.

The issue reproduces with existing tests if you use VS2015.

llvm-svn: 263966
2016-03-21 18:23:07 +00:00
Kuba Brecka 4b3833df7d [tsan] Add some NULL pointer checks into the debugging API
`__tsan_get_report_thread` and others can crash if a stack trace is missing, let's add the missing checks.

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

llvm-svn: 263939
2016-03-21 12:12:44 +00:00
Saleem Abdulrasool 61e970607e builtins: make __clear_cache work on Linux-ARM
__clear_cache on Android is identical to the version on Linux.  Use __linux__
instead of __ANDROID__ as __linux__ is defined for Linux and Android.

llvm-svn: 263833
2016-03-18 21:06:06 +00:00
Saleem Abdulrasool fb21509509 builtins: port __clear_cache to Windows ARM
Support __clear_cache on Windows on ARM using the `FlushInstructionCache`
library call.

llvm-svn: 263832
2016-03-18 21:06:03 +00:00
Mike Aizatsky 6d8a876159 [sancov] common flags initialization.
Summary:
Introducing InitializeCommonFlags accross all sanitizers to simplify
common flags management.

Setting coverage=1 when html_cov_report is requested.

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

llvm-svn: 263820
2016-03-18 19:28:07 +00:00
Kuba Brecka 911e229f30 [tsan] Add interceptor for pthread_cond_timedwait_relative_np
On OS X, we have pthread_cond_timedwait_relative_np. TSan needs to intercept this API to avoid false positives when using condition variables.

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

llvm-svn: 263782
2016-03-18 10:54:11 +00:00
Kuba Brecka 493028e8e2 Removing a non-intentional debug output that got committed in r263695.
llvm-svn: 263698
2016-03-17 09:27:40 +00:00
Kuba Brecka 4c80867ecf [sanitizer] On OS X, verify that interceptors work and abort if not, take 2
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
2016-03-17 08:37:25 +00:00
Kuba Brecka 46bf454d18 [tsan] Detect uses of uninitialized, destroyed and invalid mutexes
This patch adds a new TSan report type, ReportTypeMutexInvalidAccess, which is triggered when pthread_mutex_lock or pthread_mutex_unlock returns EINVAL (this means the mutex is invalid, uninitialized or already destroyed).

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

llvm-svn: 263641
2016-03-16 15:39:20 +00:00
Mohit K. Bhakkad beb155b4fa [ASAN] Add support for mips/mips64 android
Patch by Duane Sand

Reviewers: samsonov

Subscribers: duanesand, jaydeep, sagar, llvm-commits, filcab.

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

llvm-svn: 263621
2016-03-16 08:23:10 +00:00
Alexey Samsonov 9b4bbeabcc [ASan] Make sure unittest works if sized-delete is enabled by default.
llvm-svn: 263575
2016-03-15 19:07:56 +00:00
Kuba Brecka 0fb87f77ae Revert r263551 due to a test failure.
llvm-svn: 263553
2016-03-15 15:53:39 +00:00
Kuba Brecka 69b5943a05 [sanitizer] On OS X, verify that interceptors work and abort if not
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.

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

llvm-svn: 263551
2016-03-15 14:30:28 +00:00
Nico Weber 39a02a7bed Fix bad regression from r263077 when building with MSVC.
That change did:

  -#if defined(__BIG_ENDIAN__)
  +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__

If __BYTE_ORDER__ and __ORDER_BIG_ENDIAN__ aren't defined, like
they are with MSVC, this condition is true (0 == 0).

Fixes PR26919.

llvm-svn: 263324
2016-03-12 01:57:31 +00:00
Mohit K. Bhakkad f4cc1fc7e9 [Sanitizer][MIPS] internal lstat and fstat for mips64
Reviewers: dvyukov

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 263218
2016-03-11 10:51:03 +00:00
Mohit K. Bhakkad ac4bd45f02 [Compiler-rt] Fix ioctl codes for MIPS in sanitizer_ioctl_test
Reviewers: samsonov

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 263199
2016-03-11 05:57:20 +00:00
Alexey Samsonov ed3d347e25 [sanitizer] Add strlen to the common interceptors
Summary:
Adds strlen to the common interceptors, under a new common flag
intercept_strlen.  This provides better sharing of interception code among
sanitizers and cleans up the inconsistent type declarations of the
previously duplicated interceptors.

Removes the now-duplicate strlen interceptor from asan, msan, and tsan.
The entry check semantics are normalized now for msan and asan, whose
private strlen interceptors contained multiple layers of checks that
included impossible-to-reach code.  The new semantics are identical to the
old: bypass interception if in the middle of init or if both on Mac and not
initialized; else, call the init routine and proceed.

Patch by Derek Bruening!

Reviewers: samsonov, vitalybuka

Subscribers: llvm-commits, kcc, zhaoqin

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

llvm-svn: 263177
2016-03-11 00:45:49 +00:00
Alexey Samsonov 92a46991b5 [UBSan] Improve bufferization of UBSan error reports.
Summary:
Use InternalScopedString more extensively. This reduces the number of
write() syscalls, and reduces the chance that UBSan output will be
mixed with program output.

Reviewers: vitalybuka

Subscribers: kcc, llvm-commits

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

llvm-svn: 263176
2016-03-11 00:37:02 +00:00
Reid Kleckner ad04914a53 [Windows] Fix UnmapOrDie and MmapAlignedOrDie
Now ASan can return virtual memory to the underlying OS. Portable
sanitizer runtime code needs to be aware that UnmapOrDie cannot unmap
part of previous mapping.

In particular, this required changing how we implement MmapAlignedOrDie
on Windows, which is what Allocator32 uses.

The new code first attempts to allocate memory of the given size, and if
it is appropriately aligned, returns early. If not, it frees the memory
and attempts to reserve size + alignment bytes. In this region there
must be an aligned address. We then free the oversized mapping and
request a new mapping at the aligned address immediately after. However,
a thread could allocate that virtual address in between our free and
allocation, so we have to retry if that allocation fails. The existing
thread creation stress test managed to trigger this condition, so the
code isn't totally untested.

Reviewers: samsonov

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

llvm-svn: 263160
2016-03-10 20:47:26 +00:00
Dimitry Andric b45bf0af91 Retrieve command line arguments and environment correctly on FreeBSD
Summary:
Recently I saw the test `TestCases/Posix/print_cmdline.cc` failing on
FreeBSD, with "expected string not found in input".  This is because
asan could not retrieve the command line arguments properly.

In `lib/sanitizer_common/sanitizer_linux.cc`, this is taken care of by
the `GetArgsAndEnv()` function, but it uses `__libc_stack_end` to get at
the required data.  This variable does not exist on BSDs; the regular
way to retrieve the arguments and environment information is via the
`kern.ps_strings` sysctl.

I added this functionality in sanitizer_linux.cc, as a separate #ifdef
block in `GetArgsAndEnv()`.  Also, `ReadNullSepFileToArray()` becomes
unused due to this change.  (It won't work on FreeBSD anyway, since
`/proc` is not mounted by default.)

Reviewers: kcc, emaste, joerg, davide

Subscribers: llvm-commits, emaste

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

llvm-svn: 263157
2016-03-10 20:22:02 +00:00
Kuba Brecka a1496f7c37 [tsan] Add TSan debugger APIs
Currently, TSan only reports everything in a formatted textual form. The idea behind this patch is to provide a consistent API that can be used to query information contained in a TSan-produced report. User can use these APIs either in a debugger (via a script or directly), or they can use it directly from the process (e.g. in the __tsan_on_report callback). ASan already has a similar API, see http://reviews.llvm.org/D4466.

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

llvm-svn: 263126
2016-03-10 17:00:29 +00:00
Alexey Samsonov c1424fc7c8 sanitizer: Fix endianness checks for gcc
Summary:
__BIG_ENDIAN__ and __LITTLE_ENDIAN__ are not supported by gcc, which
eg. for ubsan Value::getFloatValue will silently fall through to
the little endian branch, breaking display of float values by ubsan.
Use __BYTE_ORDER__ == __ORDER_BIG/LITTLE_ENDIAN__ as the condition
instead, which is supported by both clang and gcc.

Noticed while porting ubsan to s390x.

Patch by Marcin Kościelnicki!

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

llvm-svn: 263077
2016-03-09 23:39:40 +00:00
Xinliang David Li 5f58c27d79 Fix test failure on darwin-i386
llvm-svn: 263065
2016-03-09 21:45:37 +00:00
Logan Chien 5b7b9e946c Add ARM EHABI support to gcc_personality_v0.
Until now the only exception APIs supported by gcc_personality_v0
are DWARF EH and SJLJ. This adds support for ARM EHABI as well.

This is achieved by
a) changing the function signature on ARM EHABI,
b) unwinding the stack before returning _URC_CONTINUE_UNWIND.

See "Exception Handling ABI for the ARM Architecture" for details
(http://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf).

Patch by Timon Van Overveldt.

llvm-svn: 263010
2016-03-09 13:20:17 +00:00
Mohit K. Bhakkad 9e168987b9 [Compiler-rt][MIPS] Defining macros for MIPS archs
Reviewers: samsonov

Subscribers: filcab, jaydeep, sagar, llvm-commits

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

llvm-svn: 263000
2016-03-09 07:57:20 +00:00
Filipe Cabecinhas 19aeaf76df [Fix r262785] Fix missing declaration when COMPILER_RT_BOOL_CMPXCHG was used but InstrProfilingUtil.h wasn't included.
Also fixed declaration which still had the pre-r262788 name.

llvm-svn: 262827
2016-03-07 13:42:17 +00:00
Xinliang David Li 09fecac354 cleanup: remove dead preprocessing branch /nfc
llvm-svn: 262792
2016-03-06 04:56:55 +00:00
Xinliang David Li 44fd38856c [PGO] cleanup: move one support method into InstrProfilingUtil.h /NFC
llvm-svn: 262791
2016-03-06 04:52:45 +00:00
Xinliang David Li cf1a8d6912 [PGO] internal API name cleanups (for better consistency)
llvm-svn: 262788
2016-03-06 04:18:13 +00:00
Xinliang David Li cf2f829be6 Minor cleanup
move a function def to InstrProfilingUtil.c

llvm-svn: 262785
2016-03-06 00:55:20 +00:00
Vedant Kumar e55855f362 [GCDA] Unlock arc file before closing it
The GCDA writer closed the arc file before unlocking it. This causes an
EBADF while unlocking the file, and opens us up to racy behavior.

Fixes PR26847.

llvm-svn: 262779
2016-03-05 20:10:25 +00:00
Filipe Cabecinhas b08c76f5f8 [cmake] Address Samsonov's post-commit review of r262723
Reviewers: samsonov

Subscribers: llvm-commits

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

llvm-svn: 262770
2016-03-05 10:01:04 +00:00
Xinliang David Li 31f251f1f0 [PGO] Add API to check compatibility of profile data in buffer
This is needed by client which uses in-process merge API.

llvm-svn: 262736
2016-03-04 18:58:30 +00:00
Xinliang David Li 6534a8a837 Fix api visibility
llvm-svn: 262734
2016-03-04 18:33:49 +00:00
Filipe Cabecinhas 8144d3b091 [ubsan/cmake] Make sure we end up adding -frtti to ubsan_type_hash_itanium.cc, even if -fno-rtti is the default for the platform
llvm-svn: 262723
2016-03-04 17:02:06 +00:00
Alexey Samsonov 4362a994d2 [TSan] Fix compiler warning in Go sanity test.
llvm-svn: 262680
2016-03-04 00:56:15 +00:00
Xinliang David Li dd12e9a8c0 [PGO] Add API for profile merge from buffer
Differential Revision: http://reviews.llvm.org/D17831

llvm-svn: 262644
2016-03-03 18:54:46 +00:00
Sean Silva 6470f7615c Add some minimal portability code paths for PS4.
Summary:
Hi David, SCE folks,

What is implemented in this patch is enough for the upstream libprofile to
work for PGO with the PS4 game codebase I tested ("game7" for you SCE
folks; this is with a standalone build of compiler-rt).

The first change, which is simple, is to stub out gethostname. PS4
doesn't have a simple analog for this that doesn't bring in extra
OS libraries, so for now we do not support `%h` expansion.
This is consistent with internal B#136272.

The second change implies future work, but is a simple change at present.
PS4 does not have `getenv`, so for now we will introduce a shim.
This obviously makes it impossible for many of the tests to be run since
they require setting `LLVM_PROFILE_FILE=`.

I see two paths forward:

1. In the tests we are already wrapping execution with `%run` and so by
   setting a PS4-specific expansion for `%run` we can pass the information
   in another way We can adapt the getenv shim as appropriate.
   We will need to experiment with this internally.
   Maggie, Phillip, Filipe? Any ideas? Maybe ping me internally since we
   may need to get into some PS4 vagaries. I'm thinking a fake getenv
   library that uses some side channel for communication.

2. Another possibility which is more verbose is to use a separate clang
   invocation with `-profile-generate=<filename>` to set the filename in
   each test.
   This might require redundant clang invocations though which may be
   undesirable for upstream. David, thoughts?
   Also, this is a fairly libprofile-specific workaround, so it e.g.
   doesn't help Filipe's ASan work.
   Overall, this approach sounds like a bit of a hack to me.

Small detail:
InstrProfilingPort.h seems like the natural place for the getenv shim,
but GCDAProfiling.c needs it as well. InstrProfilingUtil.h is currently
the only header common between InstrProfilingFile.c and GCDAProfiling.c.
I can move the shim to InstrProfilingPort.h and add an include to
GCDAProfiling.c as per your preference David.

Reviewers: davidxl, MaggieYi, phillip.power, filcab

Subscribers: simon.f.whittaker, slingn, probinson, llvm-commits

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

llvm-svn: 262527
2016-03-02 22:05:46 +00:00
Dmitry Vyukov a029b79e1a tsan: describe heap/data locations in Go
llvm-svn: 262343
2016-03-01 15:38:12 +00:00
Dmitry Vyukov f5fcdd268f sanitizer_common: silence compiler warning
llvm-svn: 262342
2016-03-01 15:36:42 +00:00
Mohit K. Bhakkad 1d1493219c [Compiler-rt][MIPS] Correct Dynamic Thread Vector offset for MIPS
Reviewers: samsonov

Subscribers: dsanders, jaydeep, sagar, llvm-commits

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

llvm-svn: 262303
2016-03-01 05:56:33 +00:00
Filipe Cabecinhas b7692bc3e9 [UBSan] Fix isDerivedFromAtOffset on iOS ARM64
Summary:
iOS on ARM64 doesn't unique RTTI.
Ref: clang's iOS64CXXABI::shouldRTTIBeUnique()

Due to this, pointer-equality will not necessarily work in this
architecture, across dylib boundaries.

dynamic_cast<>() will (as expected) still work, since Apple ships with
one prepared for this, but we can't rely on the type names being
pointer-equal.

I've limited the expensive strcmp check to the specific architecture
which needs it.

Example which triggers this bug:

lib.h:
  struct X {
    virtual ~X() {}
  };
  X *libCall();

lib.mm:
  X *libCall() {
    return new X;
  }

prog.mm:
  int main() {
    X *px = libCall();
    delete px;
  }

Expected output: Nothing
Actual output:
<unknown>: runtime error: member call on address 0x00017001ef50 which does not point to an object of type 'X'
0x00017001ef50: note: object is of type 'X'
 00 00 00 00  60 00 0f 00 01 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for ‘X’

Reviewers: kubabrecka, samsonov, eugenis, rsmith

Subscribers: aemerson, llvm-commits, rengolin

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

llvm-svn: 262147
2016-02-27 19:57:44 +00:00
Dmitry Vyukov 7f022ae4c2 tsan: revert r262037
Broke aarch64 and darwin bots.

llvm-svn: 262046
2016-02-26 18:26:48 +00:00
Dmitry Vyukov b8868b9bea tsan: split thread into logical and physical state
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
2016-02-26 16:57:14 +00:00
Mohit K. Bhakkad fac2e248c4 [MSan] Endianness should not matter while printing a byte
Reviewers: eugenis

Subscribers: jaydeep, sagar, llvm-commits

Differential Revision: http://reviews.llvm.org/D17264
Differential Revision: http://reviews.llvm.org/D17563

llvm-svn: 261982
2016-02-26 06:44:10 +00:00
Sagar Thakur 63cecb3653 [MSAN] Fix test SmallPreAllocatedStackThread for MIPS
Summary: Msan was intercepting version 2.1 of the pthread_create function which was making it to crash in libc because __pthread_create_2_1 modifies the stack attributes of the thread. Intercepting the correct version fixes the test SmallPreAllocatedStackThread.

Reviewers: eugenis, samsonov
Subscribers: llvm-commits, mohit.bhakkad, jaydeep
Differential: http://reviews.llvm.org/D17603
llvm-svn: 261980
2016-02-26 05:56:54 +00:00
Vedant Kumar b850251d3e [profile] Compute number of data entries correctly
Compiler-rt miscalculates the number of entries in the __llvm_prf_data section
on i386 Darwin. This results in a number of test failures (which we started
catching after r261344).

The fix we attempted earlier is insufficient (r261683). It caused some tests to
start passing again, but that hid the fact that we drop some data entries.

This patch should fix the real problem. It fixes the way we compute DataSize by
taking into account the way the Darwin linker lays out __llvm_prf_data.

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

llvm-svn: 261957
2016-02-26 02:49:41 +00:00
Xinliang David Li 1a436dd704 Sync up with master
llvm-svn: 261947
2016-02-26 00:56:31 +00:00
Alexey Samsonov 07f9c0f558 [Sanitizer] Protect against compiler-inserted memcpy() in InternalMmapVector::push_back().
llvm-svn: 261909
2016-02-25 18:12:30 +00:00
Maxim Ostapenko 50ca4464c4 [sanitizer] Fix third parameter in COMMON_INTERCEPTOR_WRITE_RANGE in recv and recvfrom interceptors.
Pass res instead of len as third parameter to COMMON_INTERCEPTOR_WRITE_RANGE,
because otherwise we can write to unrelated memory (in MSan) or get wrong report (in ASan).

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

llvm-svn: 261898
2016-02-25 17:07:38 +00:00
Maxim Ostapenko b9fd2e0015 [sanitizer] Disable recv and recvfrom interceptors on Windows.
Trying to fix sanitizer-windows buildbot by disabling new interceptors on Windows.

llvm-svn: 261844
2016-02-25 09:36:20 +00:00
Maxim Ostapenko 7389936f57 [sanitizer] Move recvmsg and recv interceptors to sanitizer_common.
This patch moves recv and recvfrom interceptors from MSan and TSan to
sanitizer_common to enable them in ASan.

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

llvm-svn: 261841
2016-02-25 08:44:25 +00:00
Mohit K. Bhakkad 72c3cce484 [Compiler-rt][MSan]Fix shmat testcase: Pass SHMLBA-alligned address to shmat
Reviewers: samsonov

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 261837
2016-02-25 08:07:44 +00:00
Saleem Abdulrasool 2b972dfebb builtins: adjust the clobbers list for android __clear_cache
Adjust the clobbers list.  This use to work with older versions of gcc, but now
will error on newer versions (tested against 5.3) (as well as clang).

Patch by Tee Hao Wei!

llvm-svn: 261821
2016-02-25 04:04:37 +00:00
Alexey Samsonov ee7023f79a [tests] Portability fixup for r261713.
llvm-svn: 261715
2016-02-24 01:28:51 +00:00
Alexey Samsonov 0dc3d24d5d [tests] Resolve old TODOs in ASan unit tests.
llvm-svn: 261713
2016-02-24 00:41:29 +00:00
Chris Bieneman 86792ea718 [CMake] Assign components and dependencies during add_compiler_rt_resource_file
This makes it so that component-based installations will include resource files (i.e. blacklists). My next patch will add support for component-based installations.

llvm-svn: 261699
2016-02-23 21:50:39 +00:00
Vedant Kumar 120f6301ed [profile] Fix iteration over profile data entries
Fix a crash when gathering value profile data on i386 Darwin.

The Darwin linker shrinks sections containing aligned structures when
padding is not explicitly added to the end of the structure. When
iterating over these structures, be sure to not walk past the end of the
section.

No tests added, since running `ninja check-profile` on i386 Darwin is
enough to reproduce the original crash.

llvm-svn: 261683
2016-02-23 20:46:14 +00:00
Dmitry Vyukov 0c202893ae tsan: clean up code after r261658
llvm-svn: 261660
2016-02-23 17:58:23 +00:00
Dmitry Vyukov b2be098026 tsan: fix signal handling in ignored libraries
The first issue is that we longjmp from ScopedInterceptor scope
when called from an ignored lib. This leaves thr->in_ignored_lib set.
This, in turn, disables handling of sigaction. This, in turn,
corrupts tsan state since signals delivered asynchronously.
Another issue is that we can ignore synchronization in asignal
handler, if the signal is delivered into an IgnoreSync region.
Since signals are generally asynchronous, they should ignore
memory access/synchronization/interceptor ignores.
This could lead to false positives in signal handlers.

llvm-svn: 261658
2016-02-23 17:16:26 +00:00
Alexey Samsonov 8e3cbde27d [Sanitizer] Introduce ListOfModules object and use it to replace GetListOfModules().
Summary:
This removes the hard limit on the number of loaded modules (used to be
16K), and makes it easier to use LoadedModules w/o causing a memory
leak: ListOfModules owns the modules, and makes sure to properly clean
them in destructor.

Remove filtering functionality that is only needed in one place (LSan).

Reviewers: aizatsky

Subscribers: llvm-commits, kcc

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

llvm-svn: 261554
2016-02-22 18:52:51 +00:00
Mohit K. Bhakkad 452417ac12 [MSan] Make unaligned load/store functions compatible for both endians
Reviewers: eugenis

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 261513
2016-02-22 06:16:28 +00:00
Andrey Turetskiy bc0122bca9 [CMake] Add partial support for MSVC in compiler-rt builtins, by Roman Shirokiy.
This enables MSVC build of complex number arithmetic compiler-rt builtins.

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

llvm-svn: 261432
2016-02-20 12:56:04 +00:00
Mike Aizatsky 635ade9305 [sancov] use GetLoadedModules for list of modules rather than sanitizer's list.
llvm-svn: 261376
2016-02-19 22:55:21 +00:00
Richard Trieu ec3d332748 Change comma to semi-colon, no functionality change.
Cleanup for upcoming Clang warning -Wcomma.

llvm-svn: 261269
2016-02-18 22:07:42 +00:00
Reid Kleckner 0765fbc332 [WinASan] Fix page size and mmap granularity confusion
We were erroneously reporting 16K as the page size on Windows because
the code that does the shadow mapping was using page size instead of
allocation granularity. After fixing that, we can resolve the FIXMEs in
the Windows implementations of GetPageSize and GetMmapGranularity by
calling GetSystemInfo instead of returning hard-coded, incorrect
answers.

llvm-svn: 261233
2016-02-18 17:58:22 +00:00
Ed Maste 371310e1ae [tsan] Disable sysroot flag on FreeBSD
FreeBSD does not install a number of Clang-provided headers for the
compiler in the base system due to incompatibilities between FreeBSD's     
and Clang's versions. As a workaround do not use --sysroot=. on FreeBSD    
until this is addressed.

llvm.org/pr26651
Differential Revision:	http://reviews.llvm.org/D17383

llvm-svn: 261229
2016-02-18 17:35:30 +00:00
Jonas Hahnfeld 9bf3acd5ff [compiler-rt] Return correct size of struct pthread for glibc-2.12.2
There seems to be a difference between 2.12.1 and 2.12.2 in 64-bit build.
Tested on Scientific Linux 6.6, based on RHEL.

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

llvm-svn: 261193
2016-02-18 07:08:26 +00:00
Ed Maste cef252ea4c [tsan] Fix signal number definitions for FreeBSD
The change in r253983 for OS X also applies to FreeBSD.

llvm-svn: 261121
2016-02-17 18:25:27 +00:00
Ed Maste a36d555c33 [tsan] Fix build warnings on FreeBSD
The change in r252165 for OS X applies to FreeBSD as well.

llvm-svn: 261120
2016-02-17 18:22:50 +00:00
Jonas Hahnfeld ffed72bbeb [compiler-rt][msan] Ensure initialisation before calling __msan_unpoison
__msan_unpoison uses intercepted memset which currently leads to a SEGV
when linking with libc++ under CentOS 7.

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

llvm-svn: 261073
2016-02-17 07:12:18 +00:00
Evgeniy Stepanov f55ebf0e39 [msan] Extend prlimit test.
llvm-svn: 261049
2016-02-17 01:34:56 +00:00
Evgeniy Stepanov d308f92d02 [msan] Intercept prlimit.
llvm-svn: 261048
2016-02-17 01:26:57 +00:00
Mohit K. Bhakkad 6987e59cd1 [Compiler-rt][MSan][MIPS] Resolve gethostbyname_r_erange for MIPS
Reviewers: eugenis, kcc, samsonov

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 260946
2016-02-16 08:33:37 +00:00
Zia Ansari 3cc265458f Fixed non-NULL terminating array bug in SanitizerCommon.StartSubprocessTest that caused them to fail sometimes and act flaky.
Differential Revision: http://reviews.llvm.org/D17228

llvm-svn: 260876
2016-02-15 05:11:51 +00:00
Dimitry Andric 042c4858b0 Fix lib/tsan/go/buildgo.sh for FreeBSD after r243051.
FreeBSD also needs to have sanitizer_linux_libcdep.cc included,
otherwise linking will fail with "undefined reference to
`__sanitizer::GetRSS()'".

While here, tabify the FreeBSD part, similar to the other parts.

llvm-svn: 260839
2016-02-14 00:26:32 +00:00
Alexey Samsonov 5b79ede65a [TSan] Adjust expectation for check_analyze.sh
r260695 caused extra push/pop instruction pair in __tsan_read1
implementation. Still, that change in InstCombine is believed to
be good, as it reduces the number of instructions performed.

Adjust the expectations to match the newly generated code.

llvm-svn: 260775
2016-02-13 00:55:58 +00:00
Evgeniy Stepanov e1556e5dd5 Fix MemorySanitizer.ptrtoint test on big-endian targets.
llvm-svn: 260749
2016-02-12 22:00:22 +00:00
Alexey Samsonov eb649bcfb9 [LSan] Print more helpful error message if LSan crashes during leak detection.
llvm-svn: 260717
2016-02-12 20:20:51 +00:00
Mike Aizatsky 92cbbfcd89 [sancov] improved object files handling.
Updating sancov invocation on html_cov_dump.

sancov change: http://reviews.llvm.org/D17169

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

llvm-svn: 260629
2016-02-12 00:29:24 +00:00
Alexey Samsonov 027729c566 [LSan] Fix a crash when LSan hits a guard page while scanning thread stack for pointers.
Summary:
In some cases stack pointer register (SP) doesn't point into the thread
stack: e.g. if one is using swapcontext(). In this case LSan
conservatively tries to scan the whole thread stack for pointers.
However, thread stack (at least in glibc implementation) may also
include guard pages, causing LSan to crash when it's reading from them.

One of the solutions is to use a pthread_attr_getguardsize() to adjust
the calculated stack boundaries. However, here we're just using
IsAccessibleMemoryRange to skip guard pages and make the code (slightly)
less platform-specific.

Reviewers: kcc

Subscribers: llvm-commits

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

llvm-svn: 260554
2016-02-11 18:07:17 +00:00
Reid Kleckner ceda883e4d [Windows] Fill in read/write information in SignalContext
Implements https://github.com/google/sanitizers/issues/653

llvm-svn: 260539
2016-02-11 16:44:35 +00:00
Reid Kleckner 5c10fa3f9a Silence MSVC warning about non-void prototypes
It thinks that these functions don't match the function pointer type
that they are passed with:

GCDAProfiling.c(578) : warning C4113: 'void (__cdecl *)()' differs in parameter lists from 'void (__cdecl *)(void)'
GCDAProfiling.c(579) : warning C4113: 'void (__cdecl *)()' differs in parameter lists from 'void (__cdecl *)(void)'
GCDAProfiling.c(580) : warning C4113: 'void (__cdecl *)()' differs in parameter lists from 'void (__cdecl *)(void)'

llvm-svn: 260475
2016-02-11 00:22:43 +00:00
Richard Smith 7814f7dafd Don't assume that there is only one strchr overload in the global namespace;
that's not true in general. Instead, use a preference order to pick the
standard C++ signature 'char*(char*, int)' where possible and fall back to the
C signature 'char*(const char*, int)' only when it's unavailable.

llvm-svn: 260425
2016-02-10 20:02:04 +00:00
Kostya Serebryany 8c4b9ff921 [asan] update the scariness score: tweak a few weights and add tests
llvm-svn: 260327
2016-02-09 23:46:43 +00:00
Evgeniy Stepanov aa42f29221 [asan] Fix build on Windows and PowerPC.
llvm-svn: 260175
2016-02-09 00:28:57 +00:00
Evgeniy Stepanov 0d7839d0d3 [asan] Fix Windows build.
llvm-svn: 260167
2016-02-08 23:01:06 +00:00
Evgeniy Stepanov bc937a10a2 [asan] Remove leftover debug print statement.
llvm-svn: 260165
2016-02-08 22:54:46 +00:00
Evgeniy Stepanov 52f6c262d9 [asan] Implement SEGV read vs write detection for ARM and AArch64.
llvm-svn: 260163
2016-02-08 22:50:25 +00:00
Rong Xu 05ddacc01c [PGO] Update InstrProfData.inc to sync with llvm
Sync InstrProfData.inc with the one in llvm.

llvm-svn: 260148
2016-02-08 21:18:18 +00:00
George Burgess IV ce1437abaa Fix typo in asan_flags.
Patch by Michael Stapelberg.

llvm-svn: 260147
2016-02-08 21:10:00 +00:00
Kostya Serebryany bc130af434 [asan] fix the Windows build (MSVC says: cannot specify explicit initializer for arrays)
llvm-svn: 260132
2016-02-08 19:33:36 +00:00
Kostya Serebryany e4ddfd14f1 [asan] re-commit r259961, this time making the test Linux-Only
llvm-svn: 260128
2016-02-08 19:21:08 +00:00
Xinliang David Li 73fe6ce118 Fix windows build bot failure
llvm-svn: 260120
2016-02-08 18:27:04 +00:00
Xinliang David Li 5b7e2e2fa7 [PGO] Enable compression in pgo instrumentation
This reduces sizes of instrumented object files, final binaries,
process images, and raw profile data.

The format of the indexed profile data remain the same.

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

llvm-svn: 260118
2016-02-08 18:14:02 +00:00
Maxim Ostapenko 9ab99ab985 [asan] Introduce new approach for ODR violation detection based on odr indicator symbols.
This is a compiler-rt part of this http://reviews.llvm.org/D15642 patch. Here,
we add a new approach for ODR violation detection.
Instead of using __asan_region_is_poisoned(g->beg, g->size_with_redzone) on
global address (that would return false now due to using private alias), we can
use new globally visible indicator symbol to perform the check.

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

llvm-svn: 260076
2016-02-08 08:39:59 +00:00
Nico Weber d64186f5da Revert r259961, r259978, r259981.
The "sanitizer-windows" buildbot has been failing for two days because of this:

FAILED: cl.exe asan_report.cc
asan_scariness_score.h(60) : error C2536:
  '__asan::ScarinessScore::__asan::ScarinessScore::descr' :
      cannot specify explicit initializer for arrays
asan_scariness_score.h(60) : see declaration of '__asan::ScarinessScore::descr'

llvm-svn: 260059
2016-02-07 21:41:37 +00:00
Dimitry Andric 927e986ac4 Fix build on FreeBSD after r259741.
On FreeBSD, the uc_mcontext member of ucontext_t has a member called
mc_err, which corresponds to the Linux member gregs[REG_ERR].

Reviewed by:	rdivacky@FreeBSD.org

llvm-svn: 260046
2016-02-07 17:40:45 +00:00
Kostya Serebryany c02ed2a8e2 [asan] properly report an un-aligned global variable instead of just crashing
llvm-svn: 259979
2016-02-06 03:22:24 +00:00
Kostya Serebryany 23a6822976 [asan] add an experimental feature that prints the scariness score of the error message. To enable it use ASAN_OPTIONS=print_scariness=1
llvm-svn: 259961
2016-02-06 00:29:44 +00:00
Chih-Hung Hsieh c2fab48145 builtins: Fix struct __emutls_control to match GCC
The type of size and align in struct __emutls_control must be
  typedef unsigned int gcc_word __attribute__((mode(word)));
to match GCC. When gcc_word is larger than size_t, which is the case
for x32, the upper extra bits are all zeros. We can use variables of
size_t to operate on size and align.

Fix one trivial C99 warning about mixed declaration and code.

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

llvm-svn: 259824
2016-02-04 20:26:00 +00:00
Mohit K. Bhakkad 4199f3df29 [TSan] Fix PrintMatchedSuppressions: Read hit count for suppression atomically
Reviewers: dvyukov.
Subscribers: jaydeep, sagar, dsanders, llvm-commits.
Differential Revision: http://reviews.llvm.org/D16845

llvm-svn: 259755
2016-02-04 05:28:48 +00:00
Kostya Serebryany 0e05d6eb9c [asan] fix the non-x86 build
llvm-svn: 259745
2016-02-04 02:33:48 +00:00
Kostya Serebryany 2b9be25066 [asan] When catching a signal caused by a memory access, print if it's a READ or a WRITE. This touches win/mac files which I have not tested, if a win/mac bot fails I'll try to quick-fix
llvm-svn: 259741
2016-02-04 02:02:09 +00:00
Evgeniy Stepanov 73583d5f2d [cfi] Safe handling of unaddressable vtable pointers (compiler-rt).
Avoid crashing when printing diagnostics for vtable-related CFI
errors. In diagnostic mode, the frontend does an additional check of
the vtable pointer against the set of all known vtable addresses and
lets the runtime handler know if it is safe to inspect the vtable.

http://reviews.llvm.org/D16824

llvm-svn: 259717
2016-02-03 22:19:04 +00:00
Xinliang David Li 305bf59335 Sync up with master file
llvm-svn: 259627
2016-02-03 04:09:02 +00:00
Anna Zaks 14a9c07fbf [asan] Remove redundant elif
This is a fixup to r259451.

llvm-svn: 259588
2016-02-02 22:05:47 +00:00
Daniel Sanders 2ec482a347 Re-commit r259512: [tsan] Add a libc++ and lit testsuite for each ${TSAN_SUPPORTED_ARCH}.
Summary:
This is a workaround to a problem in the 3.8 release that affects MIPS and
possibly other targets where the default is not supported but a sibling is
supported.

When TSAN_SUPPORTED_ARCH is not empty, cmake currently attempts to build a
tsan'd libcxx as well as test tsan for the default target regardless of whether
the default target is supported or not. This causes problems on MIPS32 since
tsan is supported for MIPS64 but not MIPS32.

This patch causes cmake to only build the libcxx and run the lit test-suite for
archictures in ${TSAN_SUPPORTED_ARCH}

This re-commit fixes an issue where 'check-tsan' continued to look for the
tsan'd libc++ in the directory it used to be built in.

Reviewers: hans, samsonov

Subscribers: tberghammer, llvm-commits, danalbert, srhines, dvyukov

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

llvm-svn: 259542
2016-02-02 18:43:53 +00:00
Alexey Samsonov f54e67dcc9 Cast the fifth arg to mremap to void *
Summary:
Since the prototype of mremap is

```
void *mremap(void *old_address, size_t old_size, size_t new_size,
             int flags, ... /* void *new_address*/);
```
we need to cast new_address to void * when calling mremap.  Otherwise,
the wrong value will be passed to mremap on x32.

Patch by H.J Lu!

Reviewers: kcc, eugenis, samsonov

Subscribers: samsonov, llvm-commits

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

llvm-svn: 259540
2016-02-02 18:36:28 +00:00
Daniel Sanders bac108ac5f Revert r259512 - [tsan] Add a libc++ and lit testsuite for each ${TSAN_SUPPORTED_ARCH}.
check-tsan does not pick up the correct libc++.so. It succeeded on my machine
by picking up the libc++.so that was built before making this change.

llvm-svn: 259519
2016-02-02 16:05:52 +00:00
Daniel Sanders 470c2acc7c [tsan] Add a libc++ and lit testsuite for each ${TSAN_SUPPORTED_ARCH}.
Summary:
This is a workaround to a problem in the 3.8 release that affects MIPS and
possibly other targets where the default is not supported but a sibling is
supported.

When TSAN_SUPPORTED_ARCH is not empty, cmake currently attempts to build a
tsan'd libcxx as well as test tsan for the default target regardless of whether
the default target is supported or not. This causes problems on MIPS32 since
tsan is supported for MIPS64 but not MIPS32.

This patch causes cmake to only build the libcxx and run the lit test-suite for
archictures in ${TSAN_SUPPORTED_ARCH}

Reviewers: hans, samsonov

Subscribers: tberghammer, llvm-commits, danalbert, srhines, dvyukov

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

llvm-svn: 259512
2016-02-02 15:04:35 +00:00
Maxim Ostapenko 4a3c7fa441 [asan] Fix internal CHECK failure on double free in recovery mode.
This patches fixes https://github.com/google/sanitizers/issues/639

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

llvm-svn: 259473
2016-02-02 07:32:24 +00:00
Anna Zaks c77a080bdb [asan] Add iOS support.
llvm-svn: 259451
2016-02-02 02:01:17 +00:00
Ismail Donmez 7bf46bfcdf Fix build with VS2015
llvm-svn: 259301
2016-01-30 07:14:31 +00:00
Vedant Kumar a06e8ca6c5 [profile] Support hostname expansion in LLVM_PROFILE_FILE
This patch adds support for expanding "%h" out to the machine hostname
in the LLVM_PROFILE_FILE environment variable.

Patch by Daniel Waters!

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

llvm-svn: 259272
2016-01-29 23:52:11 +00:00
Evgeniy Stepanov dfef2cf502 [cfi] Simplify the code in CfiSlowPathCommon.
llvm-svn: 259085
2016-01-28 19:58:26 +00:00
Xinliang David Li ec8d086c64 Minor cleanup /NFC
llvm-svn: 259068
2016-01-28 18:37:43 +00:00
Evgeniy Stepanov 4a09234cb7 [cfi] Fix recovery from out-of-bounds vtable error.
llvm-svn: 259007
2016-01-28 00:37:54 +00:00
Mike Aizatsky c22e72e6b0 GetArgv returns null on widnows, do not crash
llvm-svn: 259005
2016-01-28 00:31:49 +00:00
Mike Aizatsky adc0a67a55 using /system/bin/sh on android in tests.
Subscribers: tberghammer, danalbert, srhines

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

llvm-svn: 259001
2016-01-27 23:58:23 +00:00
Mike Aizatsky 2654299d6a [sanitizers] generating html report on coverage dump
Subscribers: tberghammer, danalbert, srhines

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

llvm-svn: 258999
2016-01-27 23:51:36 +00:00
Evgeniy Stepanov 7cced3ba82 [cfi] Disable vtable diagnostics when no cxxabi.
This should fix the build on Mac 10.8 and earlier.

llvm-svn: 258988
2016-01-27 21:15:10 +00:00
Mike Aizatsky 48c26de04e [sanitizers] using execv instead of execve with null env.
Differential Revision: http://reviews.llvm.org/D16646

llvm-svn: 258983
2016-01-27 20:35:18 +00:00
Evgeniy Stepanov ecfa524ee3 [cfi] Fix gcc build.
llvm-svn: 258977
2016-01-27 19:33:00 +00:00
Xinliang David Li 763545c6d7 Sync up with master file
llvm-svn: 258890
2016-01-27 00:14:15 +00:00
Evgeniy Stepanov a25dde68d9 [cfi] Exclude __cfi_slowpath_diag from the non-diag rtl.
Calls to __cfi_slowpath_diag are only emitted when building with
diagnostics, and linking the diag rtl.

llvm-svn: 258881
2016-01-26 23:42:41 +00:00
Evgeniy Stepanov 40d7d02d3d [cfi] Better handling of wild target address.
This change enables diagnostics when the target address for a CFI
check is out of bounds of any known library, or even not in the
limits of the address space. This happens when casting pointers to
uninitialized memory.

Ubsan code does not yet handle some of these situations correctly,
so it is still possible to see a segmentation fault instead of a
proper diagnostic message once in a while.

llvm-svn: 258879
2016-01-26 23:36:28 +00:00
Mike Aizatsky abae3a44af [sanitizers] execve & waitpid on mac.
llvm-svn: 258874
2016-01-26 22:53:52 +00:00
Chris Bieneman 63a81b1415 Remove autoconf support for building runtime libraries.
Summary:
This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html

    "I am the punishment of God... If [autoconf] had not committed great sins, God would not have sent a punishment like me upon [it]."
    -Genghis Khan

Reviewers: chandlerc, grosbach, bob.wilson, zaks.anna, kubabrecka, samsonov, echristo

Subscribers: iains, llvm-commits

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

llvm-svn: 258863
2016-01-26 21:31:12 +00:00
Evgeniy Stepanov 79685810f1 [cfi] Hide runtime implementation in a namespace.
Move all internal stuff into namespace __cfi.
Remove the double underscore prefix from anything that's now inside
the namespace.

llvm-svn: 258859
2016-01-26 21:06:26 +00:00
Evgeniy Stepanov a9e0584cce [cfi] Support for dlopen and dlclose.
Add dlopen/dlclose interceptors to update CFI shadow for loaded/unloaded libraries.

llvm-svn: 258857
2016-01-26 20:53:09 +00:00
Mike Aizatsky 4a93316c8c [sanitizers] extracted process management functions
Differential Revision: http://reviews.llvm.org/D16546

llvm-svn: 258849
2016-01-26 20:10:01 +00:00
Evgeniy Stepanov 226965259d [cfi] Cross-DSO CFI diagnostic mode (compiler-rt part)
* add __cfi_slowpath_diag with a 3rd parameter which is a pointer to
  the diagnostic info for the ubsan handlers.
*__cfi_check gets a 3rd parameter as well.
* unify vcall/cast/etc and icall diagnostic info format, and merge
  the handlers to have a single entry point (actually two points due
  to abort/noabort variants).
* tests

Note that this comes with a tiny overhead in the non-diag mode:
cfi_slowpath must pass 0 as the 3rd argument to cfi_check.

llvm-svn: 258744
2016-01-25 23:34:38 +00:00
Xinliang David Li 2409d0ff06 sync up InstrProfData.h -- typo fix
llvm-svn: 258717
2016-01-25 20:38:40 +00:00
Mike Aizatsky 92f0f7c2f3 Revert "[sanitizers] extracted process management functions"
This reverts commit e5b34d5a2bf4c882bc647dd26a8cea2adc76f63c.

llvm-svn: 258713
2016-01-25 19:52:25 +00:00
Mike Aizatsky e71c99c7e2 fixed clang-tidy config
llvm-svn: 258711
2016-01-25 19:43:55 +00:00
Mike Aizatsky 53849fee26 [sanitizers] extracted process management functions
Differential Revision: http://reviews.llvm.org/D16542

llvm-svn: 258710
2016-01-25 19:43:52 +00:00
Evgeniy Stepanov 2531584daa [asan] Don't use sysconf(_SC_PAGESIZE) on Android.
This is broken in the current (post-MNC) master branch.
Use EXEC_PAGESIZE instead, the same as on x86 Linux.

This change fixes startup crashes in the existing tests on AOSP
master.

llvm-svn: 258706
2016-01-25 19:25:20 +00:00
Mike Aizatsky 6e9b970805 .clang-tidy for sanitizer package to override root llvm style
Summary:
sanitizer-common follows Google code style, override
clang-tidy config.

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

llvm-svn: 258449
2016-01-21 23:21:31 +00:00
Alexey Samsonov 25f5913ddf [MSan] Clear parameters shadow before invoking malloc/free hooks.
MSan runtime is not itself instrumented, so we need to explicitly
clear shadow for function arguments before calling user-provided
functions from runtime (e.g. we already do this for several
interceptors).

I'm still crafting a test case that would demonstrate this issue
reliably, and will commit it later today.

llvm-svn: 258339
2016-01-20 19:56:04 +00:00
Kostya Serebryany af69f1c690 [asan] print an additional hint when reporting a container overflow
llvm-svn: 258337
2016-01-20 19:49:12 +00:00
Mike Aizatsky 7d866cb145 using const instead of constexpr: MSVC troubles
llvm-svn: 258253
2016-01-19 23:46:27 +00:00
Mike Aizatsky dba78e676f [sancov] NFC: simplifying DumpOffsets.
Summary: Extracting GetRangeOffset function before report-on-dump
functionality.

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

llvm-svn: 258211
2016-01-19 22:47:38 +00:00
Nico Weber 72f564f818 Fix another -Wexpansion-to-defined warning in compiler-rt.
llvm-svn: 258202
2016-01-19 22:07:55 +00:00
Nico Weber 82210fbc1e Fix -Wexpansion-to-defined warnings in compiler-rt.
llvm-svn: 258200
2016-01-19 22:02:12 +00:00
Dmitry Vyukov f8f2d46002 tsan: add back __tls_get_addr interceptor
Removal of the interceptor broke libtsan interface in gcc:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68824
Add back a simple interceptor.

llvm-svn: 258119
2016-01-19 12:28:00 +00:00
Maxim Ostapenko 1965cc6258 [asan] Optionally print reproducer cmdline in ASan reports.
Differential Revision: http://reviews.llvm.org/D16070

llvm-svn: 258037
2016-01-18 07:55:12 +00:00
Yabin Cui f7ebaf889a [tsan] Do nothing in ScopedInterceptor's destructor if thr is not inited.
Summary:
It is part of http://reviews.llvm.org/D15301, but missed when I committed
that patch.

Reviewers: kubabrecka, kcc, eugenis, llvm-commits, dvyukov

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

llvm-svn: 258021
2016-01-17 21:33:42 +00:00
Peter Collingbourne d73cd4ab01 Attempt to fix sanitizer-windows bot.
llvm-svn: 257978
2016-01-16 01:15:19 +00:00
Alexey Samsonov 95cd990588 [LSan] Ignore all allocations made inside pthread_create.
Thread stack/TLS may be stored by libpthread for future reuse after
thread destruction, and the linked list it's stored in doesn't
even hold valid pointers to the objects, the latter are calculated
by obscure pointer arithmetic.

With this change applied, LSan test suite passes with
"use_ld_allocations" flag defaulted to "false". It still requires more
testing to check if the default can be switched.

llvm-svn: 257975
2016-01-16 00:57:25 +00:00
Peter Collingbourne 5788e1259b Introduce stats and stats_client libraries.
This is part of a new statistics gathering feature for the sanitizers.
See clang/docs/SanitizerStats.rst for further info and docs.

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

llvm-svn: 257972
2016-01-16 00:31:29 +00:00
Yabin Cui 19e8c0e2f7 [tsan] Fix some tiny errors.
Summary:
1. Fix spell error for sigaction.
2. Make line_length <= 80.

Reviewers: llvm-commits, eugenis, kcc, dvyukov

Subscribers: tberghammer, danalbert, srhines

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

llvm-svn: 257872
2016-01-15 06:21:46 +00:00
Yabin Cui bd3a772e9f [tsan] Store the pointer to ThreadState in TLS slot on Android.
Summary:
1. Android doesn't support __thread keyword. So allocate ThreadState
dynamically and store its pointer in one TLS slot provided by Android.
2. On Android, intercepted functions can be called before ThreadState
is initialized. So add test of thr_->is_inited in some places.
3. On Android, intercepted functions can be called after ThreadState
is destroyed. So add a fake dead_thread_state to represent all
destroyed ThreadStates. And that is also why we don't store the pointer
to ThreadState in shadow memory of pthread_self().

Reviewers: kcc, eugenis, dvyukov

Subscribers: kubabrecka, llvm-commits, tberghammer, danalbert, srhines

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

llvm-svn: 257866
2016-01-15 03:39:04 +00:00
Yabin Cui 66e5db99b3 [tsan] Use internal_sigfillset to replace REAL(sigfillset).
Summary:
Android doesn't intercept sigfillset, so REAL(sigfillset) is null.
And we can use internal_sigfillset() for all cases.

Reviewers: kcc, eugenis, kubabrecka, dvyukov

Subscribers: llvm-commits, tberghammer, danalbert

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

llvm-svn: 257862
2016-01-15 02:59:23 +00:00
Peter Collingbourne d2f24b62b5 Unbreak Windows build.
llvm-svn: 257860
2016-01-15 02:51:26 +00:00
Peter Collingbourne b825bf32b7 sanitizer_common: C++ify the IntrusiveList iterator interface.
llvm-svn: 257858
2016-01-15 02:19:20 +00:00
Alexey Samsonov 1f242d6a77 [LSan] Add "use_ld_allocations" flag to disable old way of DTLS handling.
This flag allows to disable old way of determining dynamic TLS by
filtering out allocations from dynamic linker. This will be eventually
superseded by __tls_get_addr interceptor (see r257785), after we:
1) Test it in several supported environments
2) Deal with existing problems (currently we can't find a pointer to
  DTV which is calloc()-ed in pthread_create).

llvm-svn: 257789
2016-01-14 19:16:05 +00:00
Alexey Samsonov 5535c51606 [LSan] Use __tls_get_addr interceptor to keep track of dynamic TLS.
Summary:
We have a way to keep track of allocated DTLS segments: let's use it
in LSan. Although this code is fragile and relies on glibc
implementation details, in some cases it proves to be better than
existing way of tracking DTLS in LSan: marking as "reachable" all
memory chunks allocated directly by "ld".

The plan is to eventually get rid of the latter, once we are sure
it's safe to remove.

Reviewers: kcc

Subscribers: llvm-commits

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

llvm-svn: 257785
2016-01-14 18:50:09 +00:00
Sumanth Gundapaneni b76bf106b1 Fix the cross compilation of unit tests. NFC (second attempt)
With COMPILER_RT_INCLUDE_TESTS turned ON and in a cross compiling
environment, the unit tests fail to link. This patch does the following changes

>Rename COMPILER_RT_TEST_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS to reflect the 
way it's used.
>Add COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS so 
that cross-compiler would be able to build/compile the unit tests
>Add COMPILER_RT_UNITTEST_LINKFLAGS to COMPILER_RT_UNITTEST_CFLAGS so 
that cross-compiler would be able to link the unit tests (if needed)

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

llvm-svn: 257783
2016-01-14 18:18:49 +00:00
Kuba Brecka 0626dd0d3b [tsan] Introduce a "ignore_interceptors_accesses" option
On OS X, TSan already passes all unit and lit tests, but for real-world applications (even very simple ones), we currently produce a lot of false positive reports about data races. This makes TSan useless at this point, because the noise dominates real bugs. This introduces a runtime flag, "ignore_interceptors_accesses", off by default, which makes TSan ignore all memory accesses that happen from interceptors. This will significantly lower the coverage and miss a lot of bugs, but it eliminates most of the current false positives on OS X.

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

llvm-svn: 257760
2016-01-14 12:24:37 +00:00
Kuba Brecka 9f5fde7081 [tsan] Fix the value of PTHREAD_MUTEX_RECURSIVE for OS X and FreeBSD
The value of the constant PTHREAD_MUTEX_RECURSIVE is not "1" on FreeBSD and OS X.

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

llvm-svn: 257758
2016-01-14 12:12:58 +00:00
Xinliang David Li c6615cdce5 sync up with master file
llvm-svn: 257746
2016-01-14 06:23:53 +00:00
Alexey Samsonov 38b3130c7a [Sanitizer] Pass proper values to DTLS_on_libc_memalign.
Fix a surprising typo: the old code used to think that dynamic TLS
segments were several times larger than they actually are.

llvm-svn: 257722
2016-01-14 00:04:37 +00:00
Hans Wennborg 7b9d2b6c87 Revert r257686 "With COMPILER_RT_INCLUDE_TESTS turned ON and in a cross compiling"
This broke the build. For example, from
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/1191/steps/cmake%20stage%201/logs/stdio:

	-- Compiler-RT supported architectures: aarch64
	CMake Error at projects/compiler-rt/cmake/Modules/AddCompilerRT.cmake:170 (string):
		string sub-command REPLACE requires at least four arguments.
	Call Stack (most recent call first):
		projects/compiler-rt/lib/CMakeLists.txt:4 (include)

llvm-svn: 257694
2016-01-13 22:50:24 +00:00
Sumanth Gundapaneni 2d2f2b5c80 With COMPILER_RT_INCLUDE_TESTS turned ON and in a cross compiling
environment, the unit tests fail to link. This patch does the following changes

>Rename COMPILER_RT_TEST_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS to reflect the 
way it's used.
>Add COMPILER_RT_TEST_COMPILER_CFLAGS to COMPILER_RT_UNITTEST_CFLAGS so that 
cross-compiler would be able to build/compile the unit tests
>Add COMPILER_RT_UNITTEST_LINKFLAGS to COMPILER_RT_UNITTEST_CFLAGS so that 
cross-compiler would be able to link the unit tests (if needed)

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

llvm-svn: 257686
2016-01-13 22:09:47 +00:00
Dan Gohman 746cd84e3c [WebAssembly] Enable the builtins library for WebAssembly.
llvm-svn: 257619
2016-01-13 16:56:15 +00:00
Dan Gohman 01731fc150 [WebAssembly] clang supports int128_t on wasm32 in addition to wasm64.
llvm-svn: 257618
2016-01-13 16:47:51 +00:00
Kostya Serebryany e3580956ea [libFuzzer] extend the weak memcmp/strcmp/strncmp interceptors to receive the result of the computations. With that, don't do any mutations if memcmp/etc returned 0
llvm-svn: 257423
2016-01-12 00:43:42 +00:00
Evgeniy Stepanov 6742d75952 [cfi] Fix __cfi_slowpath and __cfi_check signature.
The first argument is uint64_t, not uintptr_t.

llvm-svn: 257233
2016-01-08 23:42:30 +00:00
Xinliang David Li d85c32cdfa Fix typo in comment
llvm-svn: 257232
2016-01-08 23:42:28 +00:00
Xinliang David Li a692421adb [PGO] Add runtime hook so that IR instrumentation can override version
IR level instrumentation needs to override version with variant bits.
No change for FE instrumentation is needed. Test case is added to
detect version mismatch.

llvm-svn: 257230
2016-01-08 23:31:57 +00:00
Xinliang David Li f5a58834c1 [PGO] Introducing version mask macro/NFC (sync)
llvm-svn: 257225
2016-01-08 22:55:54 +00:00
Kostya Serebryany abc2c998d2 [tsan] don't crash on closedir(0)
llvm-svn: 257223
2016-01-08 22:48:19 +00:00
Xinliang David Li bc1197e3ca Sync up InstrProfData.inc
llvm-svn: 257195
2016-01-08 19:22:05 +00:00
Xinliang David Li bfb5d7c71b [PGO] Use new macro introduced/NFC
llvm-svn: 257147
2016-01-08 06:03:19 +00:00
Peter Collingbourne f6594a06f7 profile: Do not pass -fPIC on Windows.
Unbreaks clang-cl build (cl warns on this flag, clang-cl errors on it).

llvm-svn: 257136
2016-01-08 02:03:25 +00:00
Vedant Kumar 750a629555 [profile] Add comments to portability macros for readability (NFC)
llvm-svn: 257126
2016-01-08 00:49:34 +00:00
Xinliang David Li d2fb0f68f4 Sync up InstrProfData.inc
llvm-svn: 257124
2016-01-08 00:39:51 +00:00
Xinliang David Li 911a4fb324 Sync up InstrProfData.inc file
llvm-svn: 257109
2016-01-07 22:47:04 +00:00
Kuba Brecka 490b7f8b6d Follow-up fix for r256988 to unbreak the Linux buildbot.
llvm-svn: 257042
2016-01-07 09:14:41 +00:00
Anna Zaks 56c302fee6 [sanitizers] Log all output to CrashReport on OS X
Log all of sanitizers' output (not just ASan bug reports) to CrashReport,
which simplifies diagnosing failed checks as well as other errors. This
also allows to strip the color sequences early from the printed buffer,
which is more efficient than what we had perviously.

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

llvm-svn: 256988
2016-01-06 23:15:01 +00:00
Nathan Slingerland 2517253184 [compiler-rt] Fix empty translation unit warning
Change to not compile in WindowsMMap.c on anything except WIN32.

llvm-svn: 256947
2016-01-06 16:55:21 +00:00
Nathan Slingerland ba86c9279b [PGO] Enable building compiler-rt profile support library on Windows
Summary: This change configures Windows builds to build the complier-rt profile support library (clang_rt.profile-i386.lib). Windows API incompatibilities in the compiler-rt profile lib are also fixed.

Reviewers: davidxl, dnovillo

Subscribers: llvm-commits

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

llvm-svn: 256848
2016-01-05 17:27:01 +00:00
Mike Aizatsky cc56ac3669 [sancov] adding internal function
llvm-svn: 256806
2016-01-05 02:09:54 +00:00
Mike Aizatsky 54fc6575c5 [sancov] coverage pc buffer
Differential Revision: http://reviews.llvm.org/D15871

llvm-svn: 256804
2016-01-05 01:49:39 +00:00
Xinliang David Li 74ec5db4bd [PGO] Sync up template file with master
llvm-svn: 256722
2016-01-04 01:22:55 +00:00
Xinliang David Li 4eb2cd64ff [PGO] Sync up template file with master
llvm-svn: 256711
2016-01-03 18:36:30 +00:00
Xinliang David Li 3e0e6e75d7 [PGO]: Eliminate custom typedefs in the FreeBSD case
Patch by: Sean Bruno 

Use o/s provided sys/types.h to bring in Profiling types.

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

llvm-svn: 256647
2015-12-30 19:18:55 +00:00
Xinliang David Li cda3bc2062 [PGO]: Refactor VP data writer
Extract the buffered filer writer code used by value profile 
writer and turn it into common/sharable buffered fileIO 
interfaces. Added a test case for the buffered file writer and
rewrite the VP dumping using the new APIs.

llvm-svn: 256604
2015-12-29 23:54:41 +00:00
Dimitry Andric 2d82f915c2 For the asan_symbolize.py script, use addr2line as the default system
symbolizer on FreeBSD too.  This allows the asan-symbolize-bad-path.cc
test to succeed.

llvm-svn: 256578
2015-12-29 21:36:34 +00:00
Xinliang David Li 54dd683726 [PGO]: Do not update Data->Value field during profile write.
The profile reader no longer depends on this field to be updated and point
to owning func's vp data. The VP data also no longer needs to be allocated
in a contiguous memory space.

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

llvm-svn: 256543
2015-12-29 07:13:59 +00:00
Evgeniy Stepanov f02b782aa7 [cfi] Fix handling of uninstrumented libraries.
CFI shadow for non-CFI libraries should be "unchecked", not "invalid".

llvm-svn: 256285
2015-12-22 21:40:09 +00:00
Xinliang David Li baf55d8266 [PGO] Move buffer write callback to a common file
This is a NFC refactoring enabling code sharing by file writer.

llvm-svn: 256264
2015-12-22 18:57:15 +00:00
Nico Weber 6341a79387 fix a gcc warning
llvm-svn: 256256
2015-12-22 17:22:25 +00:00
Adhemerval Zanella b2910ea67e [compiler-rt] [tsan] Add support for PIE build on AArch64
This patch adds PIE executable support for aarch64-linux.  It adds
two more segments:

- 0x05500000000-0x05600000000: 39-bits PIE program segments
- 0x2aa00000000-0x2ab00000000: 42-bits PIE program segments

Fortunately it is possible to use the same transformation formula for
the new segments range with some adjustments in shadow to memory
formula (it adds a constant offset based on the VMA size).

A simple testcase is also added, however it is disabled on x86 due the
fact it might fail on newer kernels [1].

[1] https://git.kernel.org/linus/d1fd836dcf00d2028c700c7e44d2c23404062c90

llvm-svn: 256184
2015-12-21 19:27:57 +00:00
Kostya Serebryany 1d1be3dd88 [asan] fix fopen interceptor to not crash if path is NULL
llvm-svn: 256182
2015-12-21 19:22:26 +00:00
Xinliang David Li d1c84b078a [PGO] testing _WIN64 instead of _WIN32
llvm-svn: 256129
2015-12-20 19:55:15 +00:00
Xinliang David Li f82944db76 [PGO] Implement BOOL_CMPXCHG for Windows
llvm-svn: 256128
2015-12-20 19:11:44 +00:00
Xinliang David Li f48a1f54dd [PGO] Fix build failure with MSVC
llvm-svn: 256103
2015-12-19 19:16:32 +00:00
Alexey Samsonov 081a24e3a7 [UBSan] Implement runtime suppressions (PR25066).
Summary:
Add the ability to suppress UBSan reports for files/functions/modules
at runtime. The user can now pass UBSAN_OPTIONS=suppressions=supp.txt
with the contents of the form:

signed-integer-overflow:file-with-known-overflow.cpp
alignment:function_doing_unaligned_access
vptr:shared_object_with_vptr_failures.so

Suppression categories match the arguments passed to -fsanitize=
flag (although, see below). There is no overhead if suppressions are
not provided. Otherwise there is extra overhead for symbolization.

Limitations:
1) sometimes suppressions need debug info / symbol table to function
   properly (although sometimes frontend generates enough info to
   do the match).
2) it's only possible to suppress recoverable UB kinds - if you've
   built the code with -fno-sanitize-recover=undefined, suppressions
   will not work.
3) categories are fine-grained check kinds, not groups like "undefined"
   or "integer", so you can't write "undefined:file_with_ub.cc".

Reviewers: rsmith, kcc

Subscribers: cfe-commits

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

llvm-svn: 256018
2015-12-18 19:56:42 +00:00
Kuba Brecka 3aac36ad01 Revert r255996 ("[tsan] Add a DCHECK to verify __tsan_read* and __tsan_write function aren't called from ScopedInterceptor").
There are some test failures on the Linux buildbots.

llvm-svn: 255997
2015-12-18 13:52:08 +00:00
Kuba Brecka 15dd456236 [tsan] Add a DCHECK to verify __tsan_read* and __tsan_write function aren't called from ScopedInterceptor
Interceptors using ScopedInteceptor should never call into user's code before the ScopedInterceptor is out of scope (and its destructor is called). Let's add a DCHECK to enforce that.

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

llvm-svn: 255996
2015-12-18 13:08:15 +00:00
Kuba Brecka f9cc9d7392 [tsan] Fix scoping of ScopedInteceptor in libdispatch support
Some interceptors in tsan_libdispatch_mac.cc currently wrongly use TSAN_SCOPED_INTERCEPTOR/ScopedInterceptor. Its constructor can start ignoring memory accesses, and the destructor the stops this -- however, e.g. dispatch_sync can call user's code, so the ignoring will extend to user's code as well. This is not expected and we should only limit the scope of ScopedInterceptor to TSan code.  This patch introduces annotations that mark the beginning and ending of a callback into user's code.

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

llvm-svn: 255995
2015-12-18 11:16:24 +00:00
Xinliang David Li 01d06100dd Fix typo in MSC path
llvm-svn: 255938
2015-12-17 23:37:30 +00:00
Xinliang David Li abfd553c2b [PGO] cleanup: unify prefix for portability macros
llvm-svn: 255748
2015-12-16 03:29:15 +00:00
Evgeniy Stepanov 72b0111ce6 [cfi] Exclude ubsan runtime library from non-diag CFI builds.
Split the CFI runtime in two: cfi and cfi_diag. The latter includes
UBSan runtime to allow printing diagnostics.

llvm-svn: 255735
2015-12-16 00:38:41 +00:00
Evgeniy Stepanov 702a773988 [cfi] Fix GCC build.
llvm-svn: 255733
2015-12-16 00:34:30 +00:00
Evgeniy Stepanov b99d6c8b2a [cfi] Fix shadow sanity check.
The current check may break if the starting address in fill_shadow is
not page-aligned.

llvm-svn: 255725
2015-12-16 00:18:04 +00:00
Evgeniy Stepanov da1cf9287c Cross-DSO control flow integrity (compiler-rt part).
This is an initial version of the runtime cross-DSO CFI support
library.

It contains a number of FIXMEs, ex. it does not support the
diagnostic mode nor dlopen/dlclose, but it works and can be tested.
Diagnostic mode, in particular, would require some refactoring (we'd
like to gather all CFI hooks in the UBSan library into one function
so that we could easier pass the diagnostic information down to
__cfi_check). It will be implemented later.

Once the diagnostic mode is in, I plan to create a second test
configuration to run all existing tests in both modes. For now, this
patch includes only a few new cross-DSO tests.

llvm-svn: 255695
2015-12-15 23:00:33 +00:00
Xinliang David Li 1fbae3b76a [PGO] Improve prof library portability
Patch by: Johan Engelen

Introduce LLVM_LIBRARY_WEAK macro. Define LLVM_LIBRARY_WEAK
and LLVM_LIBRARY_VISIBIITY for MSVC

llvm-svn: 255688
2015-12-15 22:38:18 +00:00
Xinliang David Li be49271399 [PGO] Open file with explict binary mode
Patch by: Johan Engelen

On windows, opening in text mode will result in
line ending chars to be appended leading to
profile corruption.

llvm-svn: 255684
2015-12-15 22:18:11 +00:00
Kostya Serebryany 354bbb2ccd [asan] add option: handle_sigill
llvm-svn: 255588
2015-12-15 00:33:45 +00:00
Evgeniy Stepanov 04621bd888 [msan] Intercept ctermid, ctermid_r.
llvm-svn: 255566
2015-12-14 22:57:49 +00:00
Bill Schmidt e193989c17 [TSAN, PPC64] Fix obvious typo of supported virtual memory sizes
llvm-svn: 255507
2015-12-14 16:26:00 +00:00
Adhemerval Zanella ac764fabb8 [compiler-rt] [msan] Variadic support for AArch64
Now with variadic support for msan on aarch6 there is no need for
XFAIL signal_stress_test anymore.  Also to garantee aligned stores
for the FP/SIMD arguments enforce the '__msan_va_arg_tls' alignment
to sizeof the SIMD register (16).

llvm-svn: 255496
2015-12-14 14:15:32 +00:00
Kuba Brecka 2cdb522a5a [tsan] Update dispatch_group support to avoid using a disposed group object
We're using the dispatch group itself to synchronize (to call Release() and Acquire() on it), but in dispatch group notifications, the group can already be disposed/deallocated. This causes a later assertion failure at `DCHECK_EQ(*meta, 0);` in `MetaMap::AllocBlock` when the same memory is reused (note that the failure only happens in debug builds).

Fixing this by retaining the group and releasing it in the notification. Adding a stress test case that reproduces this.

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

llvm-svn: 255494
2015-12-14 13:32:57 +00:00
Adhemerval Zanella eaf1162687 [compiler-rt] [safestack] Enable for aarch64
This patch enables the safestack for aarch64. The frontend already have
it enabled on all supported architectures and no adjustment is required
in llvm.

The compiler-rt adjustments are basically add on the cmake configuration
to enable the tests and fix the pagesize debug check by getting its
value at runtime (since aarch64 has multiple pagesize depending of
kernel configuration).

llvm-svn: 255345
2015-12-11 17:38:38 +00:00
Xinliang David Li 449133d8b4 [PGO] Split value profiling runtime into its own file
Value profile runtime depends on libc which breaks
buffer API implemenation with current file organization.

Test case is also updated to check more symbols.

llvm-svn: 255294
2015-12-10 20:24:09 +00:00
Xinliang David Li 060037e0d2 Sync up with master
llvm-svn: 255293
2015-12-10 20:14:13 +00:00
Xinliang David Li 497c51cb8a [PGO] Move impl specific decl to InstrProfilingInternal.h (NFC)
llvm-svn: 255290
2015-12-10 19:50:04 +00:00
Alexey Samsonov c63c0d1cc0 [TSan] Try harder to avoid compiler-generated memcpy calls.
check_memcpy test added in r254959 fails on some configurations due to
memcpy() calls inserted by Clang. Try harder to avoid them by using
internal_memcpy() where applicable.

llvm-svn: 255287
2015-12-10 19:24:27 +00:00
Xinliang David Li e8c18a1bd1 [PGO] Move target-dependent macro to InstrProfilingPort.h (NFC)
llvm-svn: 255285
2015-12-10 19:20:25 +00:00
Xinliang David Li 26bcd193a8 [PGO] Header file cleanup (NFC)
InstrProfiling.h file declares profile runtime public APIs.
It has become a dumping place for many different things, which
needs cleanups. In this change, core type declarations and 
portability macros are moved to a new file InstrProfilingPort.h.

llvm-svn: 255270
2015-12-10 18:17:01 +00:00
Xinliang David Li b247bfb23b [PGO] use COMPILER_RT_HAS_ATOMTICS macro
llvm-svn: 255266
2015-12-10 17:27:53 +00:00
Yury Gribov 90a36c5ba1 [asan] Use atomic_uintptr_t instead of atomic_uint64_t in SuppressErrorReport.
Some targets (e.g. Mips) don't have 64-bit atomics, so using atomic_uint64_t
leads to build failures. Use atomic_uintptr_t to avoid such errors.

Patch by Max Ostapenko. 

llvm-svn: 255242
2015-12-10 11:07:19 +00:00
Yury Gribov 6bfade1b81 [asan] Suppress duplicated errors in ASan recovery mode.
Patch by Max Ostapenko.

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

llvm-svn: 255228
2015-12-10 08:08:53 +00:00
Chris Bieneman 5c64ddfa88 Revert "[CMake] Provide options for toggling on and off various runtime libraries."
This reverts r255170. This change caused a bunch of bot failures and needs to be revised.

llvm-svn: 255184
2015-12-10 00:40:58 +00:00
Xinliang David Li bf56c0a512 [PGO] Add cmake check to determine atomics op availability
This allows the profile runtime to pick the right impl
for cmp&swap for a given target.

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

llvm-svn: 255173
2015-12-09 22:46:49 +00:00
Chris Bieneman e82ad46f15 [CMake] Provide options for toggling on and off various runtime libraries.
Summary:
Rather than having to add new "experimental" options each time someone wants to work on bringing a sanitizer to a new platform, this patch makes options for all of them.

The default values for the options are set by the platform checks that would have enabled them, but they can be overridden on or off.

Reviewers: kubabrecka, samsonov

Subscribers: llvm-commits

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

llvm-svn: 255170
2015-12-09 22:45:03 +00:00
Yabin Cui 7f48808882 [tsan] Move emptyset/oldset to ThreadSignalContext.
Summary:
Android doesn't support __thread keyword. So move emptyset/oldset
from THREADLOCAL to ThreadSignalContext.

Reviewers: kcc, eugenis, dvyukov

Subscribers: llvm-commits, tberghammer, danalbert

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

llvm-svn: 255168
2015-12-09 22:40:31 +00:00
Yabin Cui 4ddbe8508a [tsan] Use REAL(malloc) instead of __libc_malloc for Android.
Summary:
Android doesn't have __libc_malloc and related allocation
functions. As its dynamic linker doesn't use malloc, so
we can use REAL(malloc) to replace __libc_malloc safely.

Reviewers: kcc, eugenis, dvyukov

Subscribers: llvm-commits, tberghammer, danalbert, srhines

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

llvm-svn: 255167
2015-12-09 22:32:38 +00:00
Yabin Cui 903ab8a2a3 [tsan] Disable interceptors not supported in Android.
Reviewers: kcc, eugenis, dvyukov

Subscribers: llvm-commits, tberghammer, danalbert, srhines

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

llvm-svn: 255164
2015-12-09 22:23:47 +00:00
Hans Wennborg 63011e91d1 asan_win_dynamic_runtime_thunk.cc: declare atexit
MSVC apparently makes atexit available even without including stdlib.h,
but clang-cl does not. This makes the file build also with clang-cl.

llvm-svn: 255160
2015-12-09 21:43:03 +00:00
Alexey Samsonov 9c54984d43 [TSan] Try harder to avoid compiler-generated memset calls.
check_memcpy test added in r254959 fails on some configurations due to
memset() calls inserted by Clang. Try harder to avoid them:
* Explicitly use internal_memset() instead of empty braced-initializer.
* Replace "new T()" with "new T", as the former generates zero-initialization
  for structs in C++11.

llvm-svn: 255136
2015-12-09 18:48:10 +00:00
Yabin Cui d28ffacc99 [tsan] Define sigaction_t for Android.
Reviewers: kcc, eugenis, dvyukov

Subscribers: llvm-commits, tberghammer, danalbert, srhines

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

llvm-svn: 255135
2015-12-09 18:37:27 +00:00
Bill Schmidt 4514a87c4d Avoid extended mnemonic 'mfvrsave' in assembly code
llvm-svn: 255116
2015-12-09 15:18:30 +00:00
Alexey Samsonov aff20ac3bd [UBSan] Clarify the way we disable de-duplication of reports from unrecoverable handlers.
Let unrecoverable handlers be responsbile for killing the
program with Die(), and let functions which print the error
report know if it's going to happen. Re-write the comments to
describe the situation.

llvm-svn: 255081
2015-12-09 00:12:57 +00:00
Alexey Samsonov b4a852f219 [UBSan] Remove "-fsanitize=" prefix from ubsan_checks.inc. NFC.
llvm-svn: 255075
2015-12-08 23:29:36 +00:00
Alexey Samsonov 46442df8de [UBSan] Always calculate ErrorType (kind of UB) before printing a report.
Currently, this is an NFC. However, knowing out the kind of error
report before we bring up all the reporting machinery (implemented in
ScopedReport class) is important once we teach UBSan runtime
suppressions.

llvm-svn: 255074
2015-12-08 23:29:33 +00:00
Xinliang David Li 27e48f4e4e Fix typo
llvm-svn: 255068
2015-12-08 22:51:40 +00:00
Bill Schmidt 6b63d576c3 [PPC64, TSAN] Provide setjmp interceptor support for PPC64
This patch provides the assembly support for setjmp/longjmp for use
with the thread sanitizer.  This is a big more complicated than for
aarch64, because sibcalls are only legal under our ABIs if the TOC
pointer is unchanged.  Since the true setjmp function trashes the TOC
pointer, and we have to leave the stack in a correct state, we emulate
the setjmp function rather than branching to it.

We also need to materialize the TOC for cases where the _setjmp code
is called from libc.  This is done differently under the ELFv1 and
ELFv2 ABIs.

llvm-svn: 255059
2015-12-08 22:14:34 +00:00
Bill Schmidt 2979162732 [PPC64, TSAN] LLVM basic enablement of thread sanitizer for PPC64 (BE and LE)
This patch is by Simone Atzeni with portions by Adhemerval Zanella.

This contains the LLVM patches to enable the thread sanitizer for
PPC64, both big- and little-endian.  Two different virtual memory
sizes are supported:  Old kernels use a 44-bit address space, while
newer kernels require a 46-bit address space.

There are two companion patches that will be added shortly.  There is
a Clang patch to actually turn on the use of the thread sanitizer for
PPC64.  There is also a patch that I wrote to provide interceptor
support for setjmp/longjmp on PPC64.

Patch discussion at reviews.llvm.org/D12841.

llvm-svn: 255057
2015-12-08 21:54:39 +00:00
Alexey Samsonov 02824d0e59 [TSan] Remove legacy Makefile.old!
Summary:
It was barely supported for a several years for now, somewhat
rotten and doesn't correspond to the way we build/test TSan runtime
in Clang anymore.

CMake build has proper compile flags, library layout, build
dependencies etc.

Shell scripts that depended on the output of Makefile.old are
either obsolete now (check_cmake.sh), or moved to lit tests
(check_memcpy.sh), or kept as a standalone scripts not suitable
for generic test suite, but invoked on bots (check_analyze.sh).

It is not used on bots anymore: all "interesting" configurations
(gcc/clang as a host compiler; debug/release build types) are now
tested via CMake.

Reviewers: dvyukov, kcc

Subscribers: llvm-commits

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

llvm-svn: 255032
2015-12-08 17:59:33 +00:00
Alexey Samsonov f49d159c8a [CMake] Remove debug output leftovers.
llvm-svn: 255031
2015-12-08 17:59:30 +00:00
Dmitry Vyukov eee690b29a tsan: fix test invisible barrier
Another attempt at fixing tsan_invisible_barrier.
Current implementation causes:
https://llvm.org/bugs/show_bug.cgi?id=25643

There were several unsuccessful iterations for this functionality:

Initially it was implemented in user code using REAL(pthread_barrier_wait). But pthread_barrier_wait is not supported on MacOS. Futexes are linux-specific for this matter.
Then we switched to atomics+usleep(10). But usleep produced parasitic "as-if synchronized via sleep" messages in reports which failed some output tests.
Then we switched to atomics+sched_yield. But this produced tons of tsan- visible events, which lead to "failed to restore stack trace" failures.
Move implementation into runtime and use internal_sched_yield in the wait loop.
This way tsan should see no events from the barrier, so not trace overflows and
no "as-if synchronized via sleep" messages.

llvm-svn: 255030
2015-12-08 17:54:47 +00:00
Kuba Brecka 25dba9b781 [tsan] Add dispatch_group API interceptors and synchronization
This patch adds release and acquire semantics for dispatch groups, plus a test case.

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

llvm-svn: 255020
2015-12-08 14:54:43 +00:00
Kuba Brecka 1956244e5a [tsan] Fix memcmp interceptor to correctly use COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED
The memcmp interceptor checks COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED only after it calls COMMON_INTERCEPTOR_ENTER, which causes an early process launch crash when running TSan in iOS simulator. Let's fix this by checking COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED as the very first thing in the interceptor.

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

llvm-svn: 255019
2015-12-08 14:48:21 +00:00
Alexey Samsonov d20a13023b [TSan] Enforce TSan runtime doesn't include system headers with --sysroot flag.
llvm-svn: 254966
2015-12-07 23:21:36 +00:00
Alexey Samsonov dc37ee2226 [TSan] Port check_memcpy.sh script to a regular lit test.
Check that TSan runtime doesn't contain compiler-inserted calls
to memset/memmove functions.

In future, we may consider moving this test to test/sanitizer_common,
as we don't want to have compiler-inserted memcpy/memmove calls in
any sanitizer runtime.

llvm-svn: 254955
2015-12-07 21:53:59 +00:00
Xinliang David Li 55d927a4fd [PGO] Stop leaking libc function to buffer API impl
llvm-svn: 254943
2015-12-07 21:18:16 +00:00
Alexey Samsonov a8bf5099d6 [TSan] Slightly improve check_analyze script.
De-hardcode path to TSan-ified executable: pass it as an input to
the scripts. Fix them so that they don't write to the current
directory. Remove their invocation from Makefile.old: they are
broken there anyway, as check_analyze.sh now matches trunk Clang.

llvm-svn: 254936
2015-12-07 20:18:50 +00:00
Alexey Samsonov 5d47be186d [TSan] Delete legacy test_output.sh script.
This script is superseded by lit test suite integrated into CMake
for quite a while now. It doesn't support many tests, and require
custom hacks for a few other.

llvm-svn: 254932
2015-12-07 19:40:33 +00:00
Xinliang David Li 5bbbcbb3dc Use macro for common code pattern (NFC)
llvm-svn: 254831
2015-12-05 03:14:53 +00:00
Alexey Samsonov a330293af7 [CMake] Add COMPILER_RT_TSAN_DEBUG_OUTPUT option.
This option builds TSan runtime with extra debug printfs
and stats collection. This build configuration is developer-only
and should rarely be used, but we need to keep it to make sure
it doesn't bitrot.

llvm-svn: 254818
2015-12-05 01:37:17 +00:00
Dan Albert c8bdae1074 Check multilib dir for asan_device_setup.
Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 254789
2015-12-04 22:51:03 +00:00
Evgeniy Stepanov 2f107ce132 [asan] Remove the use of system properties on Android.
System properties are not accessible through NDK (we've been using
hacks to get to them) and they are unavailable during ASan
initialization in .preinit_array. Use environment variables and
files instead (ex. ASAN_OPTIONS=include_if_exists=/path).

No test changes. This feature was not tested because the properties
are system-wide and would conflict with the parallel test runner. Yet
another reason to get rid of it.

llvm-svn: 254783
2015-12-04 22:28:27 +00:00