Commit Graph

6237 Commits

Author SHA1 Message Date
Dmitry Vyukov 9c5bab23ee tsan: fix build after 287632
1. Mac does not have MAP_32BIT.
Define it to 0 if it is not defined.

2. We are lacking nolibc stub for ListOfModules::init.
Add it.

llvm-svn: 287634
2016-11-22 11:09:35 +00:00
Dmitry Vyukov 5c5d4766f8 tsan: switch libignore from /proc/self/maps to dl_iterate_phdr
/proc/self/maps can't be read atomically, this leads to episodic
crashes in libignore as it thinks that a module is loaded twice.
See the new test for an example.
dl_iterate_phdr does not have this problem.
Switch libignore to dl_iterate_phdr.

llvm-svn: 287632
2016-11-22 09:49:11 +00:00
Dmitry Vyukov 8b2ddfeb0b tsan: mark cur_thread_placeholder definition as initial-exec
See https://sourceware.org/bugzilla/show_bug.cgi?id=20805 and
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78294 for context.
Previously we marked only declaration as initial-exec. But compilers treat
initial-exec attribute somewhat differently. Mark definition as well.

llvm-svn: 287629
2016-11-22 08:59:17 +00:00
Dean Michael Berris bad8f0feb4 [XRay] Support AArch64 in compiler-rt
This patch adds XRay support in compiler-rt for AArch64 targets.
This patch is one of a series:

LLVM: https://reviews.llvm.org/D26412
Clang: https://reviews.llvm.org/D26415

Author: rSerge

Reviewers: rengolin, dberris

Subscribers: aemerson, mgorny, llvm-commits, iid_iunknown

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

llvm-svn: 287517
2016-11-21 03:20:43 +00:00
Martin Storsjo 8c59680ac2 builtins: Allow building windows arm functions for mingw
When building with clang/LLVM in MSVC mode, the msvcrt libraries contain
these functions.

When building in a mingw environment, we need to provide them somehow,
e.g. via compiler-rt.

The aeabi divmod functions work in the same way as the corresponding
__rt_*div* functions for windows, but their parameters are swapped.
The functions for converting float to integer and vice versa are the
same as their aeabi equivalents, only with different function names.

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

llvm-svn: 287465
2016-11-19 21:22:38 +00:00
Mike Aizatsky 7594ec3355 rename InternalBinarySearch to InternalLowerBound
Summary: The new name better corresponds to its logic.

Reviewers: kcc

Subscribers: kubabrecka

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

llvm-svn: 287377
2016-11-18 20:48:52 +00:00
Saleem Abdulrasool 865a671fa2 builtins: repair the builtins build with clang 3.8
When the C unwinding personality was corrected to match the ARM EHABI
specification, the unwind header in clang was updated with necessary
declarations.  However, when building with an older compiler, we would not have
the necessary declarations.  This would result in a build failure.  Provide a
supplementary header to ensure that the necessary declarations are present for
the build of the C unwinding personality.

Note that this is NOT an ABI break.  It merely is a compile time failure due to
the constants not being present.  The constants here are reproduced
equivalently.  This header should permit building with clang[<3.9] as well as
gcc.

Addresses PR31035!

llvm-svn: 287359
2016-11-18 18:21:06 +00:00
Mike Aizatsky 1e0093eb87 [sanitizers] specifying style for global constant
Subscribers: kubabrecka

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

llvm-svn: 287268
2016-11-17 21:57:43 +00:00
Reid Kleckner 39950b0f92 [asan] Create a .ASAN$G(A-Z) section for global registration
Summary:
The expectation is that new instrumented code will add global variable
metadata to the .ASAN$GL section, and we will use this new code to
iterate over it.

This technique seems to break when using incremental linking, which
seems to align every global to a 256 byte boundary. Presumably this is
so that it can incrementally cope with global changing size. Clang
already passes -incremental:no as a linker flag when you invoke it to do
the link step.

The two tests added for this feature will fail until the LLVM
instrumentation change in D26770 lands, so they are marked XFAIL for
now.

Reviewers: pcc, kcc, mehdi_amini, kubabrecka

Subscribers: llvm-commits, mgorny

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

llvm-svn: 287246
2016-11-17 19:02:53 +00:00
Michal Gorny a07c531ef9 [tests] Use __SSE2__ (rather than __i686__...) for SSE2 ASAN test
Use the __SSE2__ to determine whether SSE2 is enabled in the ASAN tests
rather than relying on either of the __i686__ and __x86_64__. The former
is only set with explicit -march=i686, and therefore misses most of
the x86 CPUs that support SSE2. __SSE2__ is in turn defined if
the current settings (-march, -msse2) indicate that SSE2 is supported
which should be more reliable.

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

llvm-svn: 287245
2016-11-17 18:41:54 +00:00
Mike Aizatsky 423405b19f adding operator* to help working with primitive values
Subscribers: kubabrecka

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

llvm-svn: 287144
2016-11-16 19:35:37 +00:00
Diana Picus 87d025f1ce [XRay][compiler-rt] Attempt to fix ARM buildbots after r287068
Include xray_defs.h in xray_arm.cc (seems to be the only one that doesn't
include it).

Buildbot errors:
[...]/compiler-rt/lib/xray/xray_arm.cc:31:58: error: expected initializer before 'XRAY_NEVER_INSTRUMENT'
 inline static uint32_t getMovwMask(const uint32_t Value) XRAY_NEVER_INSTRUMENT {

llvm-svn: 287089
2016-11-16 09:32:23 +00:00
Mike Aizatsky ff3bdbac35 fixing binary search for cases when element is not in array
Subscribers: kubabrecka

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

llvm-svn: 287078
2016-11-16 04:03:27 +00:00
Dean Michael Berris 4031e4b95d [XRay][compiler-rt] Disable XRay instrumentation of the XRay runtime.
Summary:
Adds a CMake check for whether the compiler used to build the XRay
library supports XRay-instrumentation. If the compiler we're using does
support the `-fxray-instrument` flag (i.e. recently-built Clang), we
define the XRAY_NEVER_INSTRUMENT macro that then makes sure that the
XRay runtime functions never get XRay-instrumented.

This prevents potential weirdness involved with building the XRay
library with a Clang that supports XRay-instrumentation, and is
attempting to XRay-instrument the build of compiler-rt.

Reviewers: majnemer, rSerge, echristo

Subscribers: mehdi_amini, llvm-commits, mgorny

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

llvm-svn: 287068
2016-11-16 01:01:13 +00:00
Reid Kleckner c9b27ba11d Allow users to call ASan's deadly exception report mechanism
Users often have their own unhandled exception filters installed. ASan
already goes to great lengths to install its own filter, but our core
wars with Chrome crashpad have escalated to the point that its time to
declare a truce. By exposing this hook, they can call us directly when
they want ASan crash reporting without worrying about who initializes
when.

llvm-svn: 287040
2016-11-15 21:54:58 +00:00
Kuba Brecka 5b2e4e3c66 [tsan] Call pthread interceptors directly in TSan RTL unit tests
On Darwin, we're running the TSan unit tests without interceptors. To make sure TSan observes all the pthread events (thread creating, thread join, condvar signal, etc.) in tsan_posix.cc, we should call the pthread interceptors directly, as we already do in tsan_test_util_posix.cc. This fixes some flaky failures on Darwin bots.

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

llvm-svn: 287026
2016-11-15 21:00:55 +00:00
Reid Kleckner 34652925cb [asan] Reduce prototype duplication with decltype
NFC

llvm-svn: 287000
2016-11-15 18:38:41 +00:00
Reid Kleckner 0d7c42c7ab [asan] Don't assert that a target is within 2GB on 32-bit Windows
Summary:
In a 32-bit address space, PC-relative jump targets are wrapped, so a
direct branch at 0x90000001 can reach address 0x10000000 with a
displacement of 0x7FFFFFFFF. This can happen in applications, such as
Chrome, that are linked with /LARGEADDRESSAWARE.

Reviewers: etienneb

Subscribers: mgorny, llvm-commits

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

llvm-svn: 286997
2016-11-15 18:29:17 +00:00
Kuba Brecka b0dd454a1a [tsan] Add support for C++ exceptions into TSan (call __tsan_func_exit during unwinding), compiler-rt part
This adds support for TSan C++ exception handling, where we need to add extra calls to __tsan_func_exit when a function is exitted via exception mechanisms. Otherwise the shadow stack gets corrupted (leaked). This patch moves and enhances the existing implementation of EscapeEnumerator that finds all possible function exit points, and adds extra EH cleanup blocks where needed.

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

llvm-svn: 286894
2016-11-14 21:41:33 +00:00
Reid Kleckner e1e344ed05 [asan/win] Delay load dbghelp.dll to delay ucrtbase.dll initialization
Summary:
ASan needs to initialize before ucrtbase.dll so that it can intercept
all of its heap allocations. New versions of dbghelp.dll depend on
ucrtbase.dll, which means both of those DLLs will initialize before the
dynamic ASan runtime. By lazily loading dbghelp.dll with LoadLibrary, we
avoid the issue.

Eventually, I would like to remove our dbghelp.dll dependency in favor
of always using llvm-symbolizer.exe, but this seems like an acceptable
interim solution.

Fixes PR30903

Reviewers: etienneb

Subscribers: kubabrecka, mgorny, llvm-commits

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

llvm-svn: 286848
2016-11-14 17:37:50 +00:00
Vitaly Buka c557191b21 [asan] Fix strncmp and strncasecmp interceptors
Summary:
In non-strict mode we will check memory access for both strings from beginning
to either:
  1. 0-char
  2. size
  3. different chars

In strict mode we will check from beginning to either:
  1. 0-char
  2. size

Previously in strict mode we always checked up to the 0-char.

Reviewers: kcc, eugenis

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 286708
2016-11-12 04:32:31 +00:00
Anna Zaks be15addffe [tsan] Expose __tsan_ignore_thread_begin and __tsan_ignore_thread_end in TSan interface
This patch is needed to implement the function attribute that disable TSan checking at run time.

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

llvm-svn: 286658
2016-11-11 22:43:12 +00:00
Reid Kleckner 2a2bc7293e [asan/win] Fix wrong TerminateProcess exit code
Add a test for it.

llvm-svn: 286608
2016-11-11 17:51:51 +00:00
Reid Kleckner 949f9b9f64 [asan/win] Move breakpoint from Abort to internal__exit
Now that we use TerminateProcess, the debugger doesn't stop on program
exit. Add this breakpoint so that the debugger stops after asan reports
an error and is prepared to exit the program.

llvm-svn: 286501
2016-11-10 20:44:05 +00:00
Kostya Serebryany 56cec3d662 [lsan] fix a rare lsan false positive: ensure that we don't re-sort the chunks_ array while iterating over it. A test is hard to create, but I've added a consistency check that fires w/o the fix on existing tests. The bug analysis and the initial patch were provided by Pierre Bourdon
llvm-svn: 286478
2016-11-10 17:27:28 +00:00
Reid Kleckner 76b4261082 [asan/win] Use TerminateProcess when we want to exit abnormally
ExitProcess still runs some code which can lead to ASan interceptors
running after CHECK failure. This can lead to deadlock if it CHECK fails
again. Avoid that mess by really exiting immediately.

llvm-svn: 286395
2016-11-09 21:27:58 +00:00
Jonas Hahnfeld 8530137de5 Pacify lint check
llvm-svn: 286346
2016-11-09 08:36:45 +00:00
Reid Kleckner d092107b0e [asan/win] Add init hooks to .CRT$XLAB
Summary:
User applications may register hooks in the .CRT$XL* callback list,
which is called very early by the loader. This is very common in
Chromium:
https://cs.chromium.org/search/?q=CRT.XL&sq=package:chromium&type=cs

This has flown under the radar for a long time because the loader
appears to catch exceptions originating from these callbacks. It's a
real problem when you're debugging an asan application, though, since it
makes the program crash early.

The solution is to add our own callback to this list, and sort it very
early in the list like we do elsewhere. Also add a test with such an
instrumented callback, and test that it gets called with asan.

Reviewers: etienneb

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 286290
2016-11-08 20:45:45 +00:00
Dmitry Vyukov 62f99cc486 tsan: more precise handling of atomic stores
Atomic stores terminate release sequences on the atomic variable,
and must use ReleaseStore primitive instead of Release.
This was broken in r192355 during a refactoring.
Restore correct behavior and add a test.

llvm-svn: 286211
2016-11-08 05:34:50 +00:00
Evgeniy Stepanov 11d3b27959 [asan] Fix asan-rt bitness issues in asan_device_setup on Android.
asan_device_setup script is using LD_PRELOAD to inject the ASan
runtime library into the Zygote process. This breaks when the Zygote
or any of its descendants spawn a process with different bitness due
to the fact that the ASan-RT library name includes the target
architecture.

The fix is to preload the library through a symlink which has the
same name in lib and lib64.

llvm-svn: 286188
2016-11-08 00:59:58 +00:00
Reid Kleckner 3501fdcb30 [asan] Add more dynamic CRT mode tests
Only tests using %clang_cl_asan were using the dynamic CRT before this.
The unit tests and lit tests using %clangxx_asan were using the static
CRT. Many cross-platform tests fail with the dynamic CRT, so I had to
add win32-(static|dynamic)-asan lit features.

Also deletes some redundant tests in TestCases/Windows that started
failing with this switch.

llvm-svn: 285821
2016-11-02 15:39:08 +00:00
Dean Michael Berris 0d86810158 [XRay][x86_64] Define a tail exit trampoline.
Summary:
We define a new trampoline that's a hybrid between the exit and entry
trampolines with the following properties:

- Saves all of the callee-saved registers according to the x86_64
  calling conventions.
- Indicate to the log handler function being called that this is a
  function exit event.

This fixes a bug that is a result of not saving enough of the register
states, and that the log handler is clobbering registers that would be
used by the function being tail-exited into manifesting as runtime
errors.

Reviewers: rSerge, echristo, majnemer

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 285787
2016-11-02 04:11:29 +00:00
Kuba Brecka 1f7deb8908 [tsan] Implement WriteMemoryProfile for Darwin
TSan’s memory usage profiling currently doesn’t work on Darwin. This patch implements measuring the amount of resident and dirty memory for each memory region. I also removed the GetShadowMemoryConsumption function, which seems to be unused.

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

llvm-svn: 285630
2016-10-31 20:17:13 +00:00
Kuba Brecka 0222eacf0f [tsan] Add support for GCD target queues
GCD (libdispatch) has a concept of “target queues”: Each queue has either an implicit or explicit target queue, where the task is handed over to when it’s time to execute it. For example, a concurrent queue can have a serial target queue (effectively making the first queue serial), or multiple queues can have the same serial target queue (which means tasks in all the queues are mutually excluded). Thus we need to acquire-release semantics on the full “chain” of target queues.

This patch changes the way we Acquire() and Release() when executing tasks in queues. Now we’ll walk the chain of target queues and synchronize on each queue that is serial (or when dealing with a barrier block). This should avoid false positives when using dispatch_set_target_queue().

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

llvm-svn: 285613
2016-10-31 18:28:02 +00:00
Reid Kleckner 18817c35be [ASan] Initialize cloned dynamic runtime global variables earlier
Otherwise __asan_dynamic_memory_address will be zero during static
initialization and instrumented code will crash immediately.

Fixes PR30810

Patch by David Major

llvm-svn: 285600
2016-10-31 17:13:02 +00:00
Saleem Abdulrasool 2678d023ca build: give aliases the same visibility
ARM EABI also uses function aliases.  Ensure that those aliased functions are
given proper visibility annotations.

llvm-svn: 285478
2016-10-28 23:37:50 +00:00
Saleem Abdulrasool 2594717436 builtins: ensure that VISIBILITY_HIDDEN is defined properly
The CMake build system had missed this macro as part of the build of the
builtins.  This would result in the builtins exporting symbols which are
implemented in assembly with global visibility.  Ensure that the assembly
optimized routines are given the same visibility as the C routines.

llvm-svn: 285477
2016-10-28 23:19:03 +00:00
Dmitry Vyukov 1a75379b24 tsan: add a hook to obtain number of reports
Requested in:
https://github.com/golang/go/issues/15972
Will help to fail individual test cases with races.

llvm-svn: 285455
2016-10-28 21:25:37 +00:00
Dmitry Vyukov 0b00a7fc6e tsan: round Go shadow to page boundary
There is a corner case reported in Go issue tracker:
https://github.com/golang/go/issues/17065
On darwin data/bss segments may not be aligned to page bounary
and mmap seems to be behaving differently than on linux
(shrinks instead of enlarge unaligned regions).

Explicitly round shadow to page bounary before mapping
to avoid any such problems.

llvm-svn: 285454
2016-10-28 21:24:29 +00:00
Dmitry Vyukov 8ee6f0c30f tsan: set disable_coredump=0 by default for Go
Go maps shadow memory lazily, so we don't have the huge multi-TB mapping.
Virtual memory consumption is proportional to normal memory usage.
Also in Go core dumps are enabled explicitly with GOTRACEBACK=crash,
if user explicitly requests a core that must be on purpose.

So don't disable core dumps by default.

llvm-svn: 285451
2016-10-28 20:52:22 +00:00
Dmitry Vyukov 5dc443619e tsan: always define SANITIZER_GO
Currently we either define SANITIZER_GO for Go or don't define it at all for C++.
This works fine with preprocessor (ifdef/ifndef/defined), but does not work
for C++ if statements (e.g. if (SANITIZER_GO) {...}). Also this is different
from majority of SANITIZER_FOO macros which are always defined to either 0 or 1.

Always define SANITIZER_GO to either 0 or 1.
This allows to use SANITIZER_GO in expressions and in flag default values.

Also remove kGoMode and kCppMode, which were meant to be used in expressions,
but they are not defined in sanitizer_common code, so SANITIZER_GO become prevalent.

Also convert some preprocessor checks to C++ if's or ternary expressions.

Majority of this change is done mechanically with:
sed "s#ifdef SANITIZER_GO#if SANITIZER_GO#g"
sed "s#ifndef SANITIZER_GO#if \!SANITIZER_GO#g"
sed "s#defined(SANITIZER_GO)#SANITIZER_GO#g"

llvm-svn: 285443
2016-10-28 20:14:18 +00:00
Dmitry Vyukov 693163e723 tsan: fix windows meta mapping
Currently windows fails on startup with:
CHECK failed: gotsan.cc:3077 "(((m - prev_m) / kMetaShadowSize)) == (((p - prev) / kMetaShadowCell))" (0x3ffffffeffffff7e, 0x6ffffff7e)

Make MemToMeta do the same MemToShadow does on windows: add offset instead of or'ing it.

llvm-svn: 285420
2016-10-28 17:25:27 +00:00
Dmitry Vyukov 128bd99808 tsan: fix code formatting
llvm-svn: 285418
2016-10-28 17:23:08 +00:00
Dmitry Vyukov a2a677c542 sanitizer_common: fix description of disable_coredump flag
s/disable_core/disable_coredump/
Add missing space in text.

llvm-svn: 285401
2016-10-28 14:25:51 +00:00
Dmitry Vyukov 7e6f8db7aa tsan: fix windows build
Currently fails with:

C:\workdir\compiler-rt\lib\tsan\go>gcc -c -o race_windows_amd64.syso gotsan.cc -I..\rtl -I..\.. -I..\..\sanitizer_common -I..\..\..\include -m64 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO -Wno-error=at
tributes -Wno-attributes -Wno-format -Wno-maybe-uninitialized -DSANITIZER_DEBUG=0 -O3 -fomit-frame-pointer -std=c++11 
gotsan.cc:9229:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/alternatename:__sanitizer_print_memory_profile=__sanitizer_default_print_memory_profile") // NOLINT
 ^
gotsan.cc: In function 'void __sanitizer_print_memory_profile(int)':
gotsan.cc:9226:17: error: redefinition of 'void __sanitizer_print_memory_profile(int)'
 extern "C" void __sanitizer_print_memory_profile(int top_percent) {}
                 ^
gotsan.cc:6898:6: note: 'void __sanitizer_print_memory_profile(int)' previously defined here
 void __sanitizer_print_memory_profile(int top_percent) {


Remove __sanitizer_print_memory_profile from Go build, it is not needed.

llvm-svn: 285400
2016-10-28 14:16:13 +00:00
Maxim Ostapenko 984f42eed5 [asan/lsan] Avoid possible deadlock in dynamic ASan runtime thread initialization.
There is possible deadlock in dynamic ASan runtime when we dlopen() shared lib
which creates a thread at the global initialization stage. The scenario:

1) dlopen grabs a GI_pthread_mutex_lock in main thread.
2) main thread calls pthread_create, ASan intercepts it, calls real pthread_create
   and waits for the second thread to be "fully initialized".
3) Newly created thread tries to access a thread local disable_counter in LSan
   (to complete its "full initialization") and hangs in tls_get_addr_tail, because
   it also tries to acquire GI_pthread_mutex_lock.

The issue is reproducible on relative recent Glibc versions e.g. 2.23.

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

llvm-svn: 285385
2016-10-28 06:49:53 +00:00
Richard Smith f8520559ce Atomics library: provide operations for __int128 when it is available.
llvm-svn: 285265
2016-10-27 01:46:24 +00:00
Anna Zaks be7ae6684f [sanitizers] Set Darwin specific linker and compiler flags for all tests
Looks like we are missing these flags only in tsan and sanitizer-common.

This results in linker warnings in some settings as it can cause the Unit
tests to be built with a different SDK version than that was used to build
the runtime. For example, we are not setting the minimal deployment target
on the tests but are setting the minimal deployment target for the sanitizer
library, which leads to the following warning on some bots: ld: warning:
object file (sanitizer_posix_test.cc.i386.o) was built for newer OSX version
(10.12) than being linked (10.11).

Differential Revision: https://reviews.llvm.org/D25860  https://reviews.llvm.org/D25352

llvm-svn: 285255
2016-10-26 23:23:38 +00:00
Kostya Kortchinsky 71dcc33c58 [scudo] Lay the foundation for 32-bit support
Summary:
In order to support 32-bit platforms, we have to make some adjustments in
multiple locations, one of them being the Scudo chunk header. For it to fit on
64 bits (as a reminder, on x64 it's 128 bits), I had to crunch the space taken
by some of the fields. In order to keep the offset field small, the secondary
allocator was changed to accomodate aligned allocations for larger alignments,
hence making the offset constant for chunks serviced by it.

The resulting header candidate has been added, and further modifications to
allow 32-bit support will follow.

Another notable change is the addition of MaybeStartBackgroudThread() to allow
release of the memory to the OS.

Reviewers: kcc

Subscribers: llvm-commits

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

llvm-svn: 285209
2016-10-26 16:16:58 +00:00
Renato Golin 81e8b771d7 [ARM RT] Fix broken clear_cache debug build on ARM
clear_cache is using R7 for the SVC call and that's the frame pointer in
GCC, which is only disabled on -O2/3, so Release builds finish, Debug don't.

Fixes PR30797.

llvm-svn: 285204
2016-10-26 15:20:33 +00:00