Commit Graph

8792 Commits

Author SHA1 Message Date
Catherine Moore 61efa174d7 [cmake] Disable building enable_execute_stack.c for baremetal targets.
Disable building enable_execute_stack.c for targets that do not have
support for mprotect().

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

llvm-svn: 302680
2017-05-10 15:34:25 +00:00
Francis Ricci 1cdcbcdb92 Add dyld to sanitizer procmaps on darwin
Summary:
Sanitizer procmaps uses dyld apis to iterate over the list of images
in the process. This is much more performan than manually recursing
over all of the memory regions in the process, however, dyld does
not report itself in the list of images. In order to prevent reporting
leaks from dyld globals and to symbolize dyld functions in stack traces,
this patch special-cases dyld and ensures that it is added to the
list of modules.

This is accomplished by recursing through the memory map of the process
until a dyld Mach header is found. While this recursion is expensive,
it is run before the full set of images has been loaded in the process,
so only a few calls are required. The result is cached so that it never
needs to be searched for when the full process memory map exists, as this
would be incredibly slow, on the order of minutes for leak sanitizer with
only 25 or so libraries loaded.

Reviewers: alekseyshl, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 302673
2017-05-10 14:38:04 +00:00
Adhemerval Zanella 6b989288ab [msan] Fix getmntent{_r} for empty /etc/fstab
Some configuration (for instance default docker ubuntu images) uses
a default empty and invalid /etc/fstab configuration file.  It makes
any call to getmntent return NULL and it leads to failures on
Msan-aarch64{-with-call}-Test/MemorySanitizer.getmntent{_r}.

This patch fixes it by creating a temporary file with some valid
entries (although not valid for the system) to use along with
setmntent/getmntent.

llvm-svn: 302639
2017-05-10 12:18:25 +00:00
Simon Dardis be1d6315e1 [mips] XFAIL getpwnam_r_invalid_user.cc test
XFAIL this test while we investigate the root cause.

llvm-svn: 302635
2017-05-10 10:58:11 +00:00
Ivan A. Kosarev e73af512a6 [Safestack] Fix the canary test to catch the libc's message regarding stack smashing
By default glibc writes its diagnostics directly to tty so the `2>&1 |`
redirection in the test doesn't catch the *** stack smashing detected ***
message, which in turn breaks printing the lit's progress bar. By defining
the LIBC_FATAL_STDERR_ environment variable we force glibc to direct
diagnostic messages to stderr.

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

llvm-svn: 302628
2017-05-10 08:06:42 +00:00
Simon Dardis f570c76c5c [mips] XFAIL dfsan's custom.cc test on mips64.
Test was already marked as failing for mips64el. Now that it's being
tested on mips64, it has to be XFAILed there as well.

llvm-svn: 302570
2017-05-09 19:17:16 +00:00
Simon Dardis 35392b8e37 [mips] Remove XFAIL from sanitizer_coverage_no_prune.cc
Test is XPASSing, so remove the XFAIL marker.

llvm-svn: 302567
2017-05-09 18:29:44 +00:00
Ulrich Weigand 41ffc70484 [SystemZ] Remove XFAIL on sanitizer_coverage_no_prune.cc
This test case works fine on SystemZ as well.

llvm-svn: 302563
2017-05-09 18:17:26 +00:00
Ulrich Weigand 9d190c22b5 [SystemZ] Fix failures after D32542
This commit made ubsan use the fast unwinder.  On SystemZ this requires
test cases to be compiled with -mbackchain.  That was already done for
asan, but not ubsan.  Add the flag for ubsan as well.

llvm-svn: 302562
2017-05-09 18:07:50 +00:00
Simon Dardis ad11bf54bf [compiler-rt][mips] Fix a test for mips.
GCC 4.9.2 likes the specialize one of the memcpys in msan_interceptors.cc,
leading to test failure.

llvm-svn: 302561
2017-05-09 17:58:33 +00:00
Reid Kleckner e2328ebae2 Allow compiler-rt to find lld and libc++ parallel to LLVM, as in the monorepo
llvm-svn: 302541
2017-05-09 15:54:57 +00:00
Kostya Kortchinsky b0e96eb28e [scudo] CRC32 optimizations
Summary:
This change optimizes several aspects of the checksum used for chunk headers.

First, there is no point in checking the weak symbol `computeHardwareCRC32`
everytime, it will either be there or not when we start, so check it once
during initialization and set the checksum type accordingly.

Then, the loading of `HashAlgorithm` for SSE versions (and ARM equivalent) was
not optimized out, while not necessary. So I reshuffled that part of the code,
which duplicates a tiny bit of code, but ends up in a much cleaner assembly
(and faster as we avoid an extraneous load and some calls).

The following code is the checksum at the end of `scudoMalloc` for x86_64 with
full SSE 4.2, before:
```
mov     rax, 0FFFFFFFFFFFFFFh
shl     r10, 38h
mov     edi, dword ptr cs:_ZN7__scudoL6CookieE ; __scudo::Cookie
and     r14, rax
lea     rsi, [r13-10h]
movzx   eax, cs:_ZN7__scudoL13HashAlgorithmE ; __scudo::HashAlgorithm
or      r14, r10
mov     rbx, r14
xor     bx, bx
call    _ZN7__scudo20computeHardwareCRC32Ejm ; __scudo::computeHardwareCRC32(uint,ulong)
mov     rsi, rbx
mov     edi, eax
call    _ZN7__scudo20computeHardwareCRC32Ejm ; __scudo::computeHardwareCRC32(uint,ulong)
mov     r14w, ax
mov     rax, r13
mov     [r13-10h], r14
```
After:
```
mov     rax, cs:_ZN7__scudoL6CookieE ; __scudo::Cookie
lea     rcx, [rbx-10h]
mov     rdx, 0FFFFFFFFFFFFFFh
and     r14, rdx
shl     r9, 38h
or      r14, r9
crc32   eax, rcx
mov     rdx, r14
xor     dx, dx
mov     eax, eax
crc32   eax, rdx
mov     r14w, ax
mov     rax, rbx
mov     [rbx-10h], r14
```

Reviewers: dvyukov, alekseyshl, kcc

Reviewed By: alekseyshl

Subscribers: aemerson, rengolin, llvm-commits

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

llvm-svn: 302538
2017-05-09 15:12:38 +00:00
Francis Ricci 0f3d30960e Avoid unnecessary calls to vm_region_recurse
Summary: This should significantly improve darwin lsan performance in cases where root regions are not used.

Reviewers: alekseyshl, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 302530
2017-05-09 14:10:30 +00:00
Bill Seurer 360f4783cf [powerpc] Remove XFAIL for sanitizer_coverage_no_prune.cc on powerpc64
This test case works fine on powerpc64 (both BE and LE).

llvm-svn: 302430
2017-05-08 15:17:43 +00:00
Dean Michael Berris 90a8fc8cb8 [XRay][compiler-rt] XFAIL on ppc
Follow-up on D32846.

llvm-svn: 302392
2017-05-08 00:38:13 +00:00
Martell Malone c348a8c747 [builtins] Fixup emulated TLS for mingw.
Enabled emulated TLS on WOA for mingw
Fix <windows.h> include for mingw

Reviewed By: chapuni, mstorsjo

Subscribers: compnerd, llvm-commits

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

llvm-svn: 302340
2017-05-06 15:13:17 +00:00
Kostya Serebryany ddf8111331 [sanitizer-coverage] implement -fsanitize-coverage=no-prune,... instead of a hidden -mllvm flag. compiler-rt part (test only).
llvm-svn: 302321
2017-05-05 23:28:47 +00:00
Kostya Kortchinsky ee0695766c [scudo] Add Android support
Summary:
This change adds Android support to the allocator (but doesn't yet enable it in
the cmake config), and should be the last fragment of the rewritten change
D31947.

Android has more memory constraints than other platforms, so the idea of a
unique context per thread would not have worked. The alternative chosen is to
allocate a set of contexts based on the number of cores on the machine, and
share those contexts within the threads. Contexts can be dynamically reassigned
to threads to prevent contention, based on a scheme suggested by @dvyuokv in
the initial review.

Additionally, given that Android doesn't support ELF TLS (only emutls for now),
we use the TSan TLS slot to make things faster: Scudo is mutually exclusive
with other sanitizers so this shouldn't cause any problem.

An additional change made here, is replacing `thread_local` by `THREADLOCAL`
and using the initial-exec thread model in the non-Android version to prevent
extraneous weak definition and checks on the relevant variables.

Reviewers: kcc, dvyukov, alekseyshl

Reviewed By: alekseyshl

Subscribers: srhines, mgorny, llvm-commits

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

llvm-svn: 302300
2017-05-05 21:38:22 +00:00
Peter Collingbourne 44781f1b0c CFI: Add a blacklist entry for std::_Sp_counted_ptr_inplace::_Sp_counted_ptr_inplace().
This ctor is used by std::make_shared and needs to cast to uninitialized T*
in order to call std::allocator_traits<T>::construct.

llvm-svn: 302272
2017-05-05 18:46:14 +00:00
Alexander Potapenko 27b09270c4 [ubsan]: temporarily disable print_stack_trace.cc test
Some problems with ARM stack unwinding led to inaccurate stack traces being
printed, which caused this test to fail on
http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh

llvm-svn: 302239
2017-05-05 14:51:16 +00:00
Bill Seurer e608f6a632 [powerpc] Mark coverage-sample.cc as XFAIL on powerpc64le
When run this test case causes a segementation fault on powerpc64le.
The xfail should be removed when the problem is fixed.

llvm-svn: 302237
2017-05-05 14:20:11 +00:00
Alexander Potapenko 416c14d409 [ubsan] Implement __sanitizer_print_stack_trace for standalone UBSan runtime.
Patch by Max Moroz, reviewed at https://reviews.llvm.org/D32542

llvm-svn: 302218
2017-05-05 09:02:28 +00:00
Dean Michael Berris 6016158215 [XRay][compiler-rt] Remove dependency on FileCheck from function id utilities tests
Follow-up on D32846 to simplify testing and not rely on FileCheck to
test boundary conditions, and instead do all the testing in code
instead.

llvm-svn: 302212
2017-05-05 01:55:13 +00:00
Vedant Kumar 6a877cfec4 [ubsan] Fix error summary message for ObjC BOOL invalid loads
llvm-svn: 302211
2017-05-05 01:35:42 +00:00
Dean Michael Berris d45003ca19 [XRay][compiler-rt] Add function id utilities for XRay
Summary:
This change allows us to provide users and implementers of XRay handlers
a means of converting XRay function id's to addresses. This, in
combination with the facilities provided in D32695, allows users to find
out:

  - How many function id's there are defined in the current binary.
  - Get the address of the function associated with this function id.
  - Patch only specific functions according to their requirements.

While we don't directly provide symbolization support in XRay, having
the function's address lets users determine this information easily
either during runtime, or offline with tools like 'addr2line'.

Reviewers: dblaikie, echristo, pelikan

Subscribers: kpw, llvm-commits

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

llvm-svn: 302210
2017-05-05 01:27:11 +00:00
Peter Wu dbc4f7413c [ASAN] Add interceptor for __longjmp_chk
Summary:
glibc on Linux calls __longjmp_chk instead of longjmp (or _longjmp) when
_FORTIFY_SOURCE is defined. Ensure that an ASAN-instrumented program
intercepts this function when a system library calls it, otherwise the
stack might remain poisoned and result in CHECK failures and false
positives.

Fixes https://github.com/google/sanitizers/issues/721

Reviewed By: eugenis

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

llvm-svn: 302152
2017-05-04 14:03:57 +00:00
Simon Dardis 19a4d97127 [compiler-rt][mips] Add support for quad precision builtins for mips64
Match the builtins that GCC provides for IEEE754 quad precision
on MIPS64. Also, enable building them with clang as PR20098 is resolved.

Disable tests for xf and xc modes as MIPS doesn't support that mode in
hardware or software.

Reviewers: slthakur

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

llvm-svn: 302147
2017-05-04 13:34:17 +00:00
Dean Michael Berris 768c5cc9c5 [XRay][compiler-rt][NFC] Update comments to doxygen format; group functions better.
llvm-svn: 302121
2017-05-04 06:27:51 +00:00
Dean Michael Berris 5cc4632b5b [XRay][compiler-rt] Support patching/unpatching specific functions
Summary:
This change allows us to patch/unpatch specific functions using the
function ID. This is useful in cases where implementations might want to
do coverage-style, or more fine-grained control of which functions to
patch or un-patch at runtime.

Depends on D32693.

Reviewers: dblaikie, echristo, kpw

Subscribers: llvm-commits

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

llvm-svn: 302112
2017-05-04 04:59:20 +00:00
Kostya Serebryany 8c34243a13 [asan] print the 'unexpected format specifier in printf interceptor' warning just once (came up in https://github.com/google/oss-fuzz/pull/562). Not touching a similar scanf warning -- for some reason it does not fire for me.
llvm-svn: 302064
2017-05-03 18:38:34 +00:00
Kuba Mracek a7cad4fcb7 [tsan] Detect races on modifying accesses in Swift code
This patch allows the Swift compiler to emit calls to `__tsan_external_write` before starting any modifying access, which will cause TSan to detect races on arrays, dictionaries and other classes defined in non-instrumented modules. Races on collections from the Swift standard library and user-defined structs and a frequent cause of subtle bugs and it's important that TSan detects those on top of existing LLVM IR instrumentation, which already detects races in direct memory accesses.

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

llvm-svn: 302050
2017-05-03 16:51:01 +00:00
Reid Kleckner eceba0d2e3 Revert my bad winasan coverage test fix and apply one that actually works
trace-pc doesn't work, but trace-pc-guard does. *shrug*

llvm-svn: 302045
2017-05-03 16:11:01 +00:00
Reid Kleckner d7e681ca10 Speculative fix for WinASan after r301994
llvm-svn: 302043
2017-05-03 15:59:07 +00:00
Maxim Ostapenko 726701b0ed [sanitizer] Intercept mcheck and mprobe on Linux
This patch addresses https://github.com/google/sanitizers/issues/804.
Users can use mcheck and mprobe functions to verify heap state so we should intercept them to avoid breakage of valid code.

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

llvm-svn: 302001
2017-05-03 07:09:10 +00:00
Kuba Mracek 9537912961 [asan] Mark some more testcases as unsupported on iOS.
llvm-svn: 301976
2017-05-02 21:22:29 +00:00
Kuba Mracek 24d7542715 [asan] Mark atos-symbolizer-dyld-root-path.cc testcase as unsupported on iOS.
llvm-svn: 301967
2017-05-02 20:09:33 +00:00
Kuba Mracek 1a8e0b0b0e [asan] Mark a bunch of tests as unsupported on iOS
This patch marks a few ASan tests as unsupported on iOS. These are mostly tests that use files or paths that are invalid/inaccessible on iOS or the simulator. We currently don't have a good way of propagating/copying secondary files that individual tests need. The same problem exists on Android, so I'm just marking the tests as UNSUPPORTED now.

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

llvm-svn: 301966
2017-05-02 19:37:28 +00:00
Kuba Mracek f3b6db40b6 [asan] Disable some Darwin tests that don't work on iOS simulator
Differential Revision: https://reviews.llvm.org/D32633

llvm-svn: 301965
2017-05-02 19:35:29 +00:00
Sterling Augustine bb34f278a2 Roll back r301831 to fix broken powerpc64le tests.
http://lab.llvm.org:8011/builders/clang-ppc64le-linux/builds/5941

llvm-svn: 301935
2017-05-02 16:43:39 +00:00
Dmitry Vyukov 2b66b5a3b7 tsan: allow fast large MemoryRangeSet on non-Windows Go
The fast reset for large memory regions is not working
only on windows. So enable it for Go/linux/darwin/freebsd.

See https://github.com/golang/go/issues/20139
for background and motivation.

Based on idea by Josh Bleecher Snyder.

llvm-svn: 301927
2017-05-02 15:15:45 +00:00
Kostya Kortchinsky 7fc481e561 [compiler-rt] move tsan's Android __get_tls() to sanitizer_common
Summary:
TSan's Android `__get_tls()` and `TLS_SLOT_TSAN` can be used by other sanitizers as well (see D32649), this change moves them to sanitizer_common.
I picked sanitizer_linux.h as their new home.
In the process, add the 32-bit versions for ARM, i386 & MIPS.

Can the address of `__get_tls()[TLS_SLOT_TSAN]` change in between the calls?
I am not sure if there is a need to repeat the construct as opposed to using a variable. So I left things as they were.

Testing on my side was restricted to a successful cross-compilation.

Reviewers: dvyukov, kubamracek

Reviewed By: dvyukov

Subscribers: aemerson, rengolin, srhines, dberris, arichardson, llvm-commits

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

llvm-svn: 301926
2017-05-02 15:13:36 +00:00
Pierre Gousseau 1c5550671d Revert r301904 causing tsan test failure in x86_64-linux-autoconf
llvm-svn: 301909
2017-05-02 10:22:05 +00:00
Pierre Gousseau b7101479a8 [asan] Add strndup/__strndup interceptors if targeting linux.
Differential Revision: https://reviews.llvm.org/D31457

llvm-svn: 301904
2017-05-02 09:01:02 +00:00
Kostya Serebryany 5508ffaef2 [sanitizer-coverage] add a deprecation note for the old sanitizer-coverage; remove a TODO printf
llvm-svn: 301889
2017-05-02 00:44:24 +00:00
Kostya Serebryany 60cff50b27 [sanitizer-coverage] remove more stale code
llvm-svn: 301845
2017-05-01 22:07:12 +00:00
Vedant Kumar b33cc94142 [ubsan] Fall back to the fast unwinder when print_stacktrace=1
This makes it possible to get stacktrace info when print_stacktrace=1 on
Darwin (where the slow unwinder is not currently supported [1]). This
should not regress any other platforms.

[1] The thread about r300295 has a relatively recent discusion about
this. We should be able to enable the existing slow unwind functionality
for Darwin, but this needs more testing.

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

llvm-svn: 301839
2017-05-01 21:41:01 +00:00
Kostya Serebryany e5ca68cfcd [asan] speed up small memcpy (> 32 but <= 64 bytes)
llvm-svn: 301837
2017-05-01 21:05:29 +00:00
Sterling Augustine ba6c9cb5e8 Add powerpc64 and powerpc64le to build infrastructure.
From Phab D32031.

llvm-svn: 301831
2017-05-01 20:35:02 +00:00
Kostya Serebryany f151b848c0 [sanitizer-coverage] disable coverage_direct=1, will remove the code in a few weeks
llvm-svn: 301826
2017-05-01 20:01:50 +00:00
Sterling Augustine 98a89e6d60 Cleanup previous test commit.
llvm-svn: 301820
2017-05-01 18:04:06 +00:00
Sterling Augustine cdcc5b61f4 Add a blank line as a test-commit.
Per http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

llvm-svn: 301818
2017-05-01 17:43:29 +00:00
Bill Seurer 6a47ba2ee0 [powerpc] deactivate flakey tests on powerpc64le
These test cases occassionally fail when run on powerpc64le:

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

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

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

llvm-svn: 301798
2017-05-01 13:56:04 +00:00
Dmitry Vyukov 5fa9175e24 tsan: support linker init flag in __tsan_mutex_destroy
For a linker init mutex with lazy flag setup
(no __tsan_mutex_create call), it is possible that
no lock/unlock happened before the destroy call.
Then when destroy runs we still don't know that
it is a linker init mutex and will emulate a memory write.
This in turn can lead to false positives as the mutex
is in fact linker initialized.

Support linker init flag in destroy annotation to resolve this.

llvm-svn: 301795
2017-05-01 10:01:13 +00:00
Dean Michael Berris fea2d0b8bf [XRay][compiler-rt] Document and update the XRay Logging API
Summary:
In this patch we document the requirements for implementations that want
to install handlers for the dynamically-controlled XRay "framework".
This clarifies what the expectations are for implementations that
want to install their handlers using this API (similar to how the FDR
logging implementation does so). It also gives users some guarantees on
semantics for the APIs.

If all goes well, users can decide to use the XRay APIs to control the
tracing/logging at the application level, without having to depend on
implementation details of the installed logging implementation. This
lets users choose the implementation that comes with compiler-rt, or
potentially multiple other implementations that use the same APIs.

We also add one convenience function (__xray_remove_log_impl()) for
explicitly removing the currently installed log implementation.

Reviewers: kpw, pelikan

Subscribers: llvm-commits

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

llvm-svn: 301784
2017-05-01 00:52:57 +00:00
Kuba Mracek 5a195f4fc5 [tsan] Track external tags in thread traces
To make the TSan external API work with Swift and other use cases, we need to track "tags" for individual memory accesses. Since there is no space to store this information in shadow cells, let's use the thread traces for that. This patch stores the tag as an extra frame in the stack traces (by calling FuncEntry and FuncExit with the address of a registered tag), this extra frame is then stripped before printing the backtrace to stderr.

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

llvm-svn: 301777
2017-04-30 20:35:18 +00:00
Kuba Mracek 10c6ba06d4 Fix unset-insert-libraries-on-exec.cc to use "%env" to make it work in iOS simulator.
llvm-svn: 301622
2017-04-28 05:50:46 +00:00
Kuba Mracek b08c567201 Fix the reexec-insert-libraries-env.cc testcase to use %env to make it work on iOS simulator.
llvm-svn: 301621
2017-04-28 05:48:27 +00:00
Kuba Mracek 0d91d6a4ed [asan] Add a compilation wrapper that codesigns shared libraries to support iOS simulator testing
Tests that run on the iOS simulator require the dlopen'd dylibs are codesigned. This patch adds the "iossim_compile.py" wrapper that codesigns any produces dylib.

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

llvm-svn: 301617
2017-04-28 04:55:35 +00:00
Vedant Kumar f2e6206fa0 [ubsan] Make the cast overflow message less redundant
llvm-svn: 301589
2017-04-27 20:48:17 +00:00
Evgeniy Stepanov 4094d9a127 [asan] Fix dead stripping of globals on Linux (compiler-rt).
Third attempt. See the description of the corresponding commit in
LLVM for more details.

llvm-svn: 301588
2017-04-27 20:27:33 +00:00
Kostya Kortchinsky 36b3434161 [scudo] Move thread local variables into their own files
Summary:
This change introduces scudo_tls.h & scudo_tls_linux.cpp, where we move the
thread local variables used by the allocator, namely the cache, quarantine
cache & prng. `ScudoThreadContext` will hold those. This patch doesn't
introduce any new platform support yet, this will be the object of a later
patch. This also changes the PRNG so that the structure can be POD.

Reviewers: kcc, dvyukov, alekseyshl

Reviewed By: dvyukov, alekseyshl

Subscribers: llvm-commits, mgorny

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

llvm-svn: 301584
2017-04-27 20:21:16 +00:00
Tim Northover 8488991bb8 TSan: update line number after XFAIL on iOS.
llvm-svn: 301560
2017-04-27 16:21:50 +00:00
Rafael Espindola dc18f517cd Also match the output on 32 bit systems.
llvm-svn: 301543
2017-04-27 14:21:09 +00:00
Rafael Espindola fbdaac4841 Add missing FileCheck, update CHECK lines and avoid subshell.
llvm-svn: 301541
2017-04-27 13:32:09 +00:00
Kuba Mracek c080598ed3 Mark two tests (dead-strip.c, initialization-bug.cc) as unsupported on iOS.
llvm-svn: 301478
2017-04-26 21:34:18 +00:00
Kuba Mracek 74233bed59 [asan] Allow propagating env variables when testing on iOS Simulator
This patch adds "%env" as a way to express that the environment variable should be set on the target device/simulator. This fixes some test failures when testing on iOS/Simulator.

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

llvm-svn: 301462
2017-04-26 20:38:24 +00:00
Kuba Mracek 3cb973f791 XFAIL the TSan XPC tests on iOS. XPC isn't available on iOS.
llvm-svn: 301459
2017-04-26 20:29:30 +00:00
Kuba Mracek b74b99d189 Fix the dump_registers.cc ASan testcase on iOS to allow both SIGSEGV and SIGBUS.
llvm-svn: 301458
2017-04-26 20:27:06 +00:00
Kuba Mracek 2a906e1b34 Mark the asan-sigbus.cpp ASan testcase as unsupported on iOS. We don't handle propagating crashes from/to iOS well.
llvm-svn: 301456
2017-04-26 20:23:23 +00:00
Kuba Mracek 0826e6c01a Add a missing "%run" expansion to fread_fwrite.cc test case to support testing on iOS simulator.
llvm-svn: 301455
2017-04-26 20:20:35 +00:00
Kuba Mracek d07620663d Fix the typo in strtok.c testcase: There was a missing space in %run expansion.
llvm-svn: 301451
2017-04-26 20:02:14 +00:00
Kuba Mracek 2074b67ec2 Follow-up for r301443: The python scrips need to be executable.
llvm-svn: 301448
2017-04-26 19:43:56 +00:00
Kuba Mracek 132c829ecc [asan] Add support for running lit tests in the iOS Simulator
This patch adds a basic support for running the ASan lit test suite against an iOS Simulator. This is done by generating more lit.site.cfg configurations into subdirectories such as IOSSimI386Config and IOSSimX86_64Config. These test suites are not added into "check-all" or into "check-asan", they have to be run manually.

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

llvm-svn: 301443
2017-04-26 18:59:22 +00:00
Alex Shlyapnikov 67f83373e9 [lsan] When necessary, define LSan suppression for tls_get_addr.
Summary:
Generalize already defined LSan suppression for the leak on
tls_get_addr, some envs do not have the entire call stack symbolized,
so we have to be less specific.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 301434
2017-04-26 17:13:31 +00:00
Michal Gorny 2bcd94f8d8 [test] Build sanitizer/xray tests only if COMPILER_RT_BUILD_* is on
Cover the sanitizer tests with COMPILER_RT_BUILD_SANITIZERS
conditional, and add COMPILER_RT_BUILD_XRAY conditional to the xray
tests. This makes it possible to do a pure-builtins build with tests
enabled.

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

llvm-svn: 301387
2017-04-26 07:35:36 +00:00
Frederich Munch 922b602683 [builtins] Implement emulated TLS on Windows.
Summary:
LLVM JIT needs to be able to use emulated TLS on all platforms, and this provides a reference one can compile to enable emutls for Linux/Mac/Windows.

Reviewers: chh, howard.hinnant

Reviewed By: chh

Subscribers: mgorny, llvm-commits

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

llvm-svn: 301350
2017-04-25 19:04:19 +00:00
Alex Shlyapnikov 7ca80051b9 [lsan] When necessary, define LSan suppression for pthread_exit.
Summary:
Generalize already defined LSan suppression for the leak on
pthread_exit, some envs do not have the entire call stack symbolized,
so we have to be less specific.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 301335
2017-04-25 17:24:27 +00:00
Nitesh Jain 4b386467e9 [Compiler-rt][MIPS] Fix assert introduce with commit rl301171.
llvm-svn: 301307
2017-04-25 13:25:40 +00:00
Hans Wennborg ac4799b3fc Revert r301089 "[builtins] Implement emulated TLS on Windows."
This broke the self-host build on Windows (PR32777).

Original commit message:

> [builtins] Implement emulated TLS on Windows.
>
> Summary:
> LLVM JIT needs to be able to use emulated TLS on all platforms, and this provides a reference one can compile to enable emutls for Linux/Mac/Windows.
>
> Reviewers: chh, howard.hinnant
>
> Reviewed By: chh
>
> Subscribers: mgorny, llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D30787

llvm-svn: 301274
2017-04-24 23:16:49 +00:00
Reid Kleckner 453f745569 [asan] Fix Windows global dead stripping tests
Pass /Gw to clang-cl which is equivalent to -fdata-sections. This is now
necessary.

llvm-svn: 301272
2017-04-24 23:13:47 +00:00
Rafael Espindola 8fb1efa4d0 Mark a test as requiring a shell.
llvm-svn: 301265
2017-04-24 22:20:22 +00:00
Evgeniy Stepanov 0b11403d55 [cfi] Fix wrong CMake condition for WIN32.
llvm-svn: 301257
2017-04-24 21:27:47 +00:00
Evgeniy Stepanov 2c201068dd [asan] Remove asanwrapper from Android test harness.
It is only necessary for pre-L and creates problems on newer builds.

llvm-svn: 301256
2017-04-24 21:27:45 +00:00
Evgeniy Stepanov ed8c47477f [asan] Use posix strerror_r interceptor on android.
This fixes a regression in r297315.

llvm-svn: 301243
2017-04-24 20:25:39 +00:00
Evgeniy Stepanov 5d7633f75d [cfi] Disable ThinLTO + CFI tests on Windows.
PR32770.

llvm-svn: 301235
2017-04-24 19:52:51 +00:00
Kuba Mracek dd13e4e0b0 [tsan] Include __tsan_external_* API from a header file instead of declaring them manually. NFC.
Differential Revision: https://reviews.llvm.org/D32384

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

llvm-svn: 301189
2017-04-24 16:42:29 +00:00
Kostya Kortchinsky 38199b2a30 [sanitizer] Cache SizeClassForTransferBatch in the 32-bit local cache
Summary:
`SizeClassForTransferBatch` is expensive and is called for every `CreateBatch`
and `DestroyBatch`. Caching it means `kNumClasses` calls in `InitCache`
instead. This should be a performance gain if more than `kNumClasses / 2`
batches are created and destroyed during the lifetime of the local cache.

I have chosen to fully remove the function and putting the code in `InitCache`,
which is a debatable choice.

In single threaded benchmarks leveraging primary backed allocations, this turns
out to be a sizeable gain in performances (greater than 5%). In multithreaded
benchmarks leveraging everything, it is less significant but still an
improvement (about 1%).

Reviewers: kcc, dvyukov, alekseyshl

Reviewed By: dvyukov

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 301184
2017-04-24 14:53:38 +00:00
Sagar Thakur a37c0d99c9 Revert [scudo] Enabling MIPS support for Scudo
This patch broke the buildbot clang-cmake-mips. Investigating the issue.

llvm-svn: 301173
2017-04-24 11:02:36 +00:00
Sagar Thakur 4bac44c805 [scudo] Enabling MIPS support for Scudo
Adding MIPS 32-bit and 64-bit support for Scudo.

Reviewed by cryptoad
Differential: D31803

llvm-svn: 301158
2017-04-24 04:29:44 +00:00
Frederich Munch 5de7f2d7b8 [builtins] Implement emulated TLS on Windows.
Summary:
LLVM JIT needs to be able to use emulated TLS on all platforms, and this provides a reference one can compile to enable emutls for Linux/Mac/Windows.

Reviewers: chh, howard.hinnant

Reviewed By: chh

Subscribers: mgorny, llvm-commits

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

llvm-svn: 301089
2017-04-22 18:45:17 +00:00
Ahmed Bougacha ea84c1687c [cfi] Disable thinlto tests on Darwin.
These were added in r301016, but they're failing, because
-fsanitize=cfi seemingly causes -flto=thin to emit raw bitcode objects,
rather than the mach-o-wrapped bitcode we emit with -flto=thin alone.

That causes all tests to fail with ld64 errors.

Filed PR32741.

llvm-svn: 301065
2017-04-22 00:07:47 +00:00
Alex Shlyapnikov 342586d728 [lsan] Enable LSan on PowerPC64.
Summary: Re-landing reverted D31995 with suppressions defined in D32303 and D32377.

Reviewers: eugenis

Subscribers: nemanjai, llvm-commits

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

llvm-svn: 301048
2017-04-21 21:59:53 +00:00
Alex Shlyapnikov a3417bc4dd Suppress DTLS leak happening in some glibc versions.
Summary: Refer to https://sourceware.org/bugzilla/show_bug.cgi?id=12650 for the context.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 301043
2017-04-21 21:34:37 +00:00
Vitaly Buka 9703df2b36 [asan] Optimize strchr for strict_string_checks=false
Summary:
strchr interceptor does not need to call strlen if strict_string_checks is not
enabled. Unnecessary strlen calls affect python parser performance.

Reviewers: eugenis, kcc

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 301027
2017-04-21 19:39:46 +00:00
Evgeniy Stepanov f608a0a778 [cfi] Replace elif with elseif in cmake.
Apparently, elif() is deprecated.

llvm-svn: 301022
2017-04-21 19:22:15 +00:00
Evgeniy Stepanov ca32b682f6 [cfi] Run tests with and without lld and thinlto.
Run tests in all configurations:
(standalone, with devirtualization) * (gold, lld) * (lto, thinlto)

llvm-svn: 301016
2017-04-21 18:11:23 +00:00
Kostya Kortchinsky f1a54fdfd6 [scudo] Bypass Quarantine if its size is set to 0
Summary:
In the current state of things, the deallocation path puts a chunk in the
Quarantine whether it's enabled or not (size of 0). When the Quarantine is
disabled, this results in the header being loaded (and checked) twice, and
stored (and checksummed) once, in `deallocate` and `Recycle`.

This change introduces a `quarantineOrDeallocateChunk` function that has a
fast path to deallocation if the Quarantine is disabled. Even though this is
not the preferred configuration security-wise, this change saves a sizeable
amount of processing for that particular situation (which could be adopted by
low memory devices). Additionally this simplifies a bit `deallocate` and
`reallocate`.

Reviewers: dvyukov, kcc, alekseyshl

Reviewed By: dvyukov

Subscribers: llvm-commits

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

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

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

llvm-svn: 301011
2017-04-21 17:49:19 +00:00
Kuba Mracek 428b36671c [tsan] Refactor __tsan_external_read/__tsan_external_write to avoid code duplication
Let's introduce a ExternalAccess function that has the shared code only once.

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

llvm-svn: 301008
2017-04-21 17:41:01 +00:00
Kuba Mracek d1be869744 [tsan] Publish the TSan external API in tsan_interface.h
Let's make the TSan external API available and commented in the public header:

    void *__tsan_external_register_tag(const char *object_type);
    void __tsan_external_assign_tag(void *addr, void *tag);
    void __tsan_external_read(void *addr, void *caller_pc, void *tag);
    void __tsan_external_write(void *addr, void *caller_pc, void *tag);

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

llvm-svn: 301003
2017-04-21 17:25:47 +00:00
Kuba Mracek 676d008198 [tsan] Track external API accesses as 1-byte accesses (instead of 8-byte)
It doesn't really make sense to track them as 8-byte accesses.

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

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

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

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

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

llvm-svn: 300998
2017-04-21 16:44:27 +00:00
Diana Picus 1f043e1c55 Revert r300889, r300906, r300935, r300939
At least one of the ARM bots is still broken:
Command Output (stderr):
--
/home/buildslave/buildslave/clang-cmake-armv7-a15-full/llvm/projects/compiler-rt/test/asan/TestCases/Posix/strchr.c:31:12: error: expected string not found in input
 // CHECK: strchr.c:[[@LINE-2]]
           ^
<stdin>:3:59: note: scanning from here
==16297==ERROR: AddressSanitizer: SEGV on unknown address 0xb5add000 (pc 0xb6dccaa4 bp 0xbe8c19c8 sp 0xbe8c1570 T0)
                                                          ^
<stdin>:3:59: note: with expression "@LINE-2" equal to "29"
==16297==ERROR: AddressSanitizer: SEGV on unknown address 0xb5add000 (pc 0xb6dccaa4 bp 0xbe8c19c8 sp 0xbe8c1570 T0)
                                                          ^
<stdin>:5:57: note: possible intended match here
 #0 0xb6dccaa3 in strlen /build/glibc-f8FFOS/glibc-2.23/string/../sysdeps/arm/armv6t2/strlen.S:82

Try to fix by reverting r300889 and subsequent fixes:
Revert "[asan] Fix test by removing "The signal is caused" check."
Revert "[asan] Fix test on ppc64le-linux by checking "UNKNOWN memory access""
Revert "[asan] Match BUS and SIGV to fix test on Darwin"
Revert "[asan] Optimize strchr for strict_string_checks=false"

llvm-svn: 300955
2017-04-21 08:21:56 +00:00
Vitaly Buka a232323ff7 [asan] Fix test by removing "The signal is caused" check.
llvm-svn: 300939
2017-04-21 01:16:58 +00:00
Vitaly Buka e03dc7d754 [asan] Fix test on ppc64le-linux by checking "UNKNOWN memory access"
llvm-svn: 300935
2017-04-21 00:48:43 +00:00
Alex Shlyapnikov c426666b4d Disable LSan on ppc64, some tests are failing.
llvm-svn: 300933
2017-04-21 00:36:29 +00:00
Ahmed Bougacha c6422fed85 Revert "Enable lsan test suite on Darwin x86_64 builds"
This reverts commit r300897.

Most LSan/ASan tests are failing on darwin bots.

llvm-svn: 300929
2017-04-21 00:00:59 +00:00
Kostya Serebryany 2500d1e35d [asan] move textdomain.c to Linux dir, as the test is Linux-specific
llvm-svn: 300926
2017-04-20 23:57:44 +00:00
Kostya Serebryany b2d291eb9b sanitizer: fix crash with textdomain(NULL) interceptor
Summary:
The textdomain function accepts a NULL parameter (and should then return the
current message domain). Add a check for this and include ASAN tests.

Link: https://github.com/google/sanitizers/issues/787

Reviewers: m.guseva, kcc

Reviewed By: kcc

Subscribers: kubamracek

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

llvm-svn: 300924
2017-04-20 23:38:10 +00:00
Vitaly Buka 70197c55b0 [asan] Match BUS and SIGV to fix test on Darwin
llvm-svn: 300906
2017-04-20 21:58:18 +00:00
Alex Shlyapnikov 906ffb7b8f Enable LSan on PowerPC64.
Summary: Re-landing reverted D31995 with suppressions defined in D32303.

Reviewers: eugenis

Subscribers: nemanjai, llvm-commits

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

llvm-svn: 300903
2017-04-20 21:56:36 +00:00
Evgeniy Stepanov b9cb969d9c [cfi] Add explicit -flto in create-derivers test.
This is necessary to run the test suite in ThinLTO mode - otherwise
opt complains about an input file containing several modules.

llvm-svn: 300901
2017-04-20 21:44:37 +00:00
Evgeniy Stepanov a32c3e5b18 [cfi] Move one test under cross-dso/icall.
The test is using indirect calls.

llvm-svn: 300900
2017-04-20 21:44:35 +00:00
Francis Ricci dcaf4e2139 Enable lsan test suite on Darwin x86_64 builds
Reviewers: kubamracek, alekseyshl

Subscribers: mgorny, llvm-commits

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

llvm-svn: 300897
2017-04-20 21:27:25 +00:00
Francis Ricci 6b494d9edc make detect_leaks=1 the default for the lsan test suite
Summary:
This already appears to be the case in all .cc test files,
it was probably left out of the .c test files accidentally. Make it a global
default, instead of manually adding it to each individual test.

This is needed to force leak detection for Darwin tests, where leak detection
is disabled by default.

Reviewers: m.ostapenko, kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300890
2017-04-20 21:00:02 +00:00
Vitaly Buka f50f97c9dd [asan] Optimize strchr for strict_string_checks=false
Summary:
strchr interceptor does not need to call strlen if strict_string_checks is not
enabled. Unnecessary strlen calls affect python parser performance.

Reviewers: eugenis, kcc

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 300889
2017-04-20 20:59:37 +00:00
Alex Shlyapnikov 3106fc476c Define standard suppressions for LSan, start with this one.
llvm-svn: 300887
2017-04-20 20:54:22 +00:00
Alex Shlyapnikov bdbb894a52 Define a suppression for known leaks on pthread_exit call.
Summary: Refer to D32194 for the context.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 300886
2017-04-20 20:54:19 +00:00
Kostya Kortchinsky fff8e0620b [scudo] Remove GetActuallyAllocatedSize calls from the fast path
Summary:
GetActuallyAllocatedSize is actually expensive. In order to avoid calling this
function in the malloc/free fast path, we change the Scudo chunk header to
store the size of the chunk, if from the Primary, or the amount of unused
bytes if from the Secondary. This way, we only have to call the culprit
function for Secondary backed allocations (and still in realloc).

The performance gain on a singly threaded pure malloc/free benchmark exercising
the Primary allocator is above 5%.

Reviewers: alekseyshl, kcc, dvyukov

Reviewed By: dvyukov

Subscribers: llvm-commits

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

llvm-svn: 300861
2017-04-20 18:07:17 +00:00
Kostya Kortchinsky 006805d146 [scudo] Minor changes and refactoring
Summary:
This is part of D31947 that is being split into several smaller changes.

This one deals with all the minor changes, more specifically:
- Rename some variables and functions to make their purpose clearer;
- Reorder some code;
- Mark the hot termination incurring checks as `UNLIKELY`; if they happen, the
  program will die anyway;
- Add a `getScudoChunk` method;
- Add an `eraseHeader` method to ScudoChunk that will clear a header with 0s;
- Add a parameter to `allocate` to know if the allocated chunk should be filled
  with zeros. This allows `calloc` to not have to call
  `GetActuallyAllocatedSize`; more changes to get rid of this function on the
  hot paths will follow;
- reallocate was missing a check to verify that the pointer is properly
  aligned on `MinAlignment`;
- The `Stats` in the secondary have to be protected by a mutex as the `Add`
  and `Sub` methods are actually not atomic;
- The software CRC32 function was moved to the header to allow for inlining.

Reviewers: dvyukov, alekseyshl, kcc

Reviewed By: dvyukov

Subscribers: llvm-commits

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

llvm-svn: 300846
2017-04-20 15:11:00 +00:00
Keith Wyss dd11cf9022 [XRay] [compiler-rt] - Fix standalone and non-deterministic test issue
Summary:
The thread order test fails sometimes my machine independently of standalone
build.

From testing both standalone and in-tree build, I see I configured it wrong.

The other hypothesis for an issue is that cold starts can interfere with whether
record unwriting happens. Once this happens more than once, we can naively
FileCheck on the wrong test output, which compounds the issue.

While "rm blah.* || true" will print to stderr if the glob can't expand, this is
mostly harmless and makes sure earlier failing tests don't sabotage us.

Example failure:

---
header:
  version:         1
  type:            1
  constant-tsc:    true
  nonstop-tsc:     true
  cycle-frequency: 3800000000
records:
  - { type: 0, func-id: 1, function: 'f1()', cpu: 9, thread: 21377, kind: function-enter, tsc: 2413745203147228 }
  - { type: 0, func-id: 1, function: 'f1()', cpu: 9, thread: 21377, kind: function-exit, tsc: 2413745203304238 }
...

The CMAKE related change fixes the expectation that COMPILER_RT_STANDALONE_BUILD will be explicitly FALSE instead
of empty string when it is not "TRUE".

Reviewers: dberris

Subscribers: llvm-commits

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

llvm-svn: 300822
2017-04-20 05:59:26 +00:00
Dean Michael Berris 9df8ef5538 [XRay][compiler-rt] Cleanup CFI/CFA annotations on trampolines
Summary:
This is a follow-up to D32202.

While the previous change (D32202) did fix the stack alignment issue, we
were still at a weird state in terms of the CFI/CFA directives (as the
offsets were wrong). This change cleans up the SAVE/RESTORE macros for
the trampoline, accounting the stack pointer adjustments with less
instructions and with some clearer math. We note that the offsets will
be different on the exit trampolines, because we don't typically 'call'
into this trampoline and we only ever jump into them (i.e. treated as a
tail call that's patched in at runtime).

Reviewers: eugenis, kpw, pelikan

Subscribers: llvm-commits

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

llvm-svn: 300815
2017-04-20 03:26:04 +00:00
Kostya Serebryany 1838561dfe [sanitizer-coverage] remove more unused code
llvm-svn: 300780
2017-04-19 23:05:53 +00:00
Kostya Serebryany d32bc3ee38 [sanitizer-coverage] remove run-time support for -fsanitize-coverage=indirect-calls
llvm-svn: 300775
2017-04-19 22:24:03 +00:00
Kostya Serebryany a2a0d2d3fc [sanitizer-coverage] remove run-time support for -fsanitize-coverage=trace-bb
llvm-svn: 300766
2017-04-19 21:30:46 +00:00
Francis Ricci 6e2b22f929 Fixup style from r300760
llvm-svn: 300765
2017-04-19 21:25:06 +00:00
Francis Ricci 9be010f0d0 Make sure to scan mmap'd memory regions for root pointers on OS X
Summary:
In the general case, we only need to check for root regions inside
the memory map returned by procmaps. However, on Darwin,
we also need to check inside mmap'd regions, which aren't returned
in the list of modules we get from procmaps.

This patch refactors memory region scanning on darwin to reduce
code duplication with the kernel alloc once page scan.

Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300760
2017-04-19 21:11:08 +00:00
Francis Ricci eb930609e8 Implement StopTheWorld for Darwin
Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300759
2017-04-19 21:11:07 +00:00
Alex Shlyapnikov 87276d68cd Turn symbolization on for ASan unit test.
Summary:
On PowerPC and ARM (possibly, need to verify), couple tests involving
pthread_exit fail due to leaks detected by LSan. pthread_exit tries
to perform unwinding that leads to dlopen'ing libgcc_s.so. dlopen
mallocs "libgcc_s.so" string which confuses LSan, it fails to
realize that this allocation happens in dynamic linker and should
be ignored.
Symbolized leak report is required to define a suppression for this
known problem.

Reviewers: eugenis

Subscribers: aemerson, rengolin, kubamracek, llvm-commits

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

Turn symbolization on for PPC and Thumb only to do not slow down other platforms.

llvm-svn: 300748
2017-04-19 20:39:09 +00:00
Kostya Serebryany b45905c5a9 [sanitizer-coverage] remove run-time support for the deprecated -fsanitize-coverage=8bit-counters
llvm-svn: 300745
2017-04-19 20:17:41 +00:00
Keith Wyss b2566da849 Skip tests that use 'llvm_xray' for standalone builds.
Summary:
Tests that generate output with compiler-rt and verify it with the llvm_xray
command (built from the llvm tree) are extremely convenient, but compiler-rt
can be built out of tree and llvm_xray is not built for every target.

This change intends to disable tests for out of tree builds, but does nothing
to detect whether llvm_xray can be found elsewhere on the path, is fresh enough,
or is part of a build target for the in tree build.

Tested:
  Tested that this didn't break check-xray. Haven't reproduced bots or standalone
  builds.

Reviewers: dberris, kcc

Subscribers: llvm-commits

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

llvm-svn: 300716
2017-04-19 17:20:47 +00:00
Nico Weber bb7e8d2ec4 Let ubsan search UBSAN_SYMBOLIZER_PATH for llvm-symbolizer
https://reviews.llvm.org/D27375

llvm-svn: 300692
2017-04-19 14:03:40 +00:00
Francis Ricci 14777f6977 Implement function to get registers from suspended thread on darwin
Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300691
2017-04-19 14:00:42 +00:00
Francis Ricci 2096fa4bf9 Move valid caller-pc checks out of platform-specific checks
Summary:
ProcessPlatformSpecificAllocations for linux leak sanitizer iterated over
memory chunks and ran two checks concurrently:
1) Ensured the pc was valid
2) Checked whether it was a linker allocation

All platforms will need the valid pc check, so it is moved out of the platform-
specific file. To prevent code and logic duplication, the linker allocation
check is moved as well, with the name of the linker supplied by the platform-specific
module. In cases where we don't need to check for linker allocations (ie Darwin),
this name will be a nullptr, and we'll only run the caller pc checks.

Reviewers: kubamracek, alekseyshl, kcc

Subscribers: llvm-commits

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

llvm-svn: 300690
2017-04-19 14:00:35 +00:00
Dean Michael Berris 9404497acd [XRay][compiler-rt] Fix up CFI annotations and stack alignment
Summary:
Previously, we had been very undisciplined about CFI annotations with
the XRay trampolines. This leads to runtime crashes due to mis-alined
stack pointers that some function implementations may run into (i.e.
those using instructions that require properly aligned addresses coming
from the stack). This patch attempts to clean that up, as well as more
accurately use the correct amounts of space on the stack for stashing
and un-stashing registers.

Reviewers: eugenis, kcc

Subscribers: kpw, llvm-commits

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

llvm-svn: 300660
2017-04-19 05:37:14 +00:00
Evgeniy Stepanov 63f6c02638 [sanitizer] Define lsan-x86 in tests for both i386 and i686.
llvm-svn: 300601
2017-04-18 21:10:50 +00:00
Francis Ricci 6759006a4b Implement suspended thread register count for darwin
Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300599
2017-04-18 21:05:11 +00:00
Francis Ricci 55735a75f1 Remove mips64 defines from darwin-specific file
Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits, arichardson

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

llvm-svn: 300598
2017-04-18 21:05:09 +00:00
Francis Ricci fdf7779795 Don't use abort_on_error for lsan darwin test suite
Summary:
This option is disabled by our other test suites, and will cause
failures when unit tests abort instead of failing with an error code.
Will also prevent the test suite from being too slow.

Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300593
2017-04-18 20:56:59 +00:00
Francis Ricci cae98fc8f0 Allow for setting of global platform-specific lsan options in the test suite
Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300592
2017-04-18 20:56:56 +00:00
Maxim Ostapenko 3546060190 [sanitizer] Don't include <linux/user.h> in sanitizer_stoptheworld_linux_libcdep.cc on ARM Android
Turned out that adding defined(_arm_) in sanitizer_stoptheworld_linux_libcdep.cc breaks android arm with some toolchains.

.../llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc:36:11: fatal error:
      'linux/user.h' file not found
# include <linux/user.h>  // for pt_regs
          ^
1 error generated.

Context:
#if SANITIZER_ANDROID && defined(__arm__)
# include <linux/user.h>  // for pt_regs
#else

This patch removes corresponding #if SANITIZER_ANDROID && defined(__arm__) and a bit rearranges adjacent сode.

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

llvm-svn: 300531
2017-04-18 07:22:26 +00:00
Douglas Yung 8439c8ed13 [XRay][compiler-rt] Use emulated TSC when CPU supports rdtscp, but cannot determine the CPU frequency
A problem arises if a machine supports the rdtscp instruction, but the processor
frequency cannot be determined by the function getTSCFrequency(). In this case,
we want to use the emulated TSC instead. This patch implements that by adding a
call to getTSCFrequency() from probeRequiredCPUFeatures(), and the function only
returns true if both the processor supports rdtscp and the CPU frequency can be
determined.

This should fix PR32620.

Reviewers: dberris

Subscribers: llvm-commits

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

llvm-svn: 300525
2017-04-18 03:25:11 +00:00
Evgeniy Stepanov 9fd4e9eb4e [asan] Fixup for r300483 (which is a fixup for r300473).
Sanitizer Printf() does not know about %lu.

llvm-svn: 300521
2017-04-18 01:08:00 +00:00
Francis Ricci 5989dd241e Update suspended threads info to be compatible with darwin
Summary:
On Darwin, we need to track thread and tid as separate values.
This patch splits out the implementation of the suspended threads list
to be OS-specific.

Reviewers: glider, kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 300491
2017-04-17 20:29:38 +00:00
Benjamin Kramer 25bdb98a98 [tsan] Add missing include for uint64_t in test.
llvm-svn: 300484
2017-04-17 19:55:12 +00:00
Kuba Mracek 7fdd4f88d9 Fixup for r300473: Use %lu on Linux for tid_t in format strings.
llvm-svn: 300483
2017-04-17 19:51:58 +00:00
Kuba Mracek ceb30b0717 [sanitizer] Introduce tid_t as a typedef for OS-provided thread IDs
We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD).

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

llvm-svn: 300473
2017-04-17 18:17:38 +00:00
Francis Ricci 7c6bf1cc9f Don't read non-readable address ranges during lsan pointer scanning
Summary: This specifically addresses the Mach-O zero page, which we cannot read from.

Reviewers: kubamracek, samsonov, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300456
2017-04-17 16:34:38 +00:00
Francis Ricci 7de60c501c Scan Kernel Alloc Once page for global pointers
Summary: libxpc stashes some pointers here.

Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300450
2017-04-17 14:07:06 +00:00
Vedant Kumar 4afdcb0975 [profile] Sync up InstrProfData.inc (NFC)
llvm-svn: 300383
2017-04-15 00:10:33 +00:00
Vedant Kumar 2b1eae0aa5 [ubsan] Use the correct tool name in diagnostics
When using ASan and UBSan together, the common sanitizer tool name is
set to "AddressSanitizer". That means that when a UBSan diagnostic is
printed out, it looks like this:

  SUMMARY: AddressSanitizer: ...

This can confuse users. Fix it so that we always use the correct tool
name when printing out UBSan diagnostics.

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

llvm-svn: 300358
2017-04-14 18:24:35 +00:00
Xinliang David Li 3bb31c8c49 [Profile] PE binary coverage bug fix
PR/32584

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

llvm-svn: 300278
2017-04-13 23:37:15 +00:00
Vitaly Buka 74b6a82c0c [msan] Fix msan_test.cc by checking bind results before assuming IPv6 supported.
llvm-svn: 300250
2017-04-13 20:25:24 +00:00
Vitaly Buka 958cd8f993 Revert "[msan] Fix msan_test broken after r299884."
This does not fix the test, it still fails to bind.

This reverts commit r300150.

llvm-svn: 300249
2017-04-13 20:25:20 +00:00
Francis Ricci 54ce07d093 Disable use of tls scanning on darwin leak sanitizer
Summary:
These checks appear linux-specific, disable them on darwin, at
least for now.

Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300248
2017-04-13 20:14:15 +00:00
Francis Ricci 5bfddfefe1 Move Linux-specific lsan tests into a new directory
Summary:
These tests aren't supported on other platforms, move them
to their own directory.

Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300247
2017-04-13 20:13:53 +00:00
Alex Shlyapnikov 4765f17738 Revert "Enable LSan on PowerPC64."
This reverts commit r300204. Breaks ASAN tests on PPC.

llvm-svn: 300237
2017-04-13 18:49:29 +00:00
Francis Ricci 9e2152a4b8 Implement global pointer scanning for darwin leak sanitizer
Reviewers: kubamracek, kcc, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300234
2017-04-13 18:40:19 +00:00
Francis Ricci bdb8b58d16 Don't assume PTHREAD_CREATE_JOINABLE is 0 on all systems
Summary:
Lsan was using PTHREAD_CREATE_JOINABLE/PTHREAD_CREATE_DETACHED
as truthy values, which works on Linux, where the values are 0 and 1,
but this fails on OS X, where the values are 1 and 2.

Set PTHREAD_CREATE_DETACHED to the correct value for a given system.

Reviewers: kcc, glider, kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300221
2017-04-13 17:28:52 +00:00
Alex Shlyapnikov 8b2caae996 Cache size per class size in SizeClassAllocatorXLocalCache.
Summary:
Allocator::ClassIdToSize() is not free and calling it in every
Allocate/Deallocate has noticeable impact on perf.
Reapplying D31991 with the appropriate fixes.

Reviewers: cryptoad

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 300216
2017-04-13 16:49:16 +00:00
Alex Shlyapnikov d77394c5f2 Enable LSan on PowerPC64.
Summary:
With D31555 commited, looks like basic LSan functionality
works on PPC64. Time to enable LSan there.

Reviewers: eugenis

Subscribers: nemanjai, llvm-commits

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

llvm-svn: 300204
2017-04-13 16:17:32 +00:00
Francis Ricci e32a66b2de Free zone name when destroying malloc zone
Summary:
The darwin interceptor for malloc_destroy_zone manually frees the
zone struct, but does not free the name component. Make sure to
free the name if it has been set.

Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300195
2017-04-13 14:00:24 +00:00
Maxim Ostapenko 661033d575 [lsan] Reenable lsan tests on ARM bots
This patch addresses pr32636. Enable lsan tests on ARM bots filtering out Thumb targets.
Tested locally on ARM Arndale board in two configurations:

1) CFLAGS="-march=armv7-a"
	Testing Time: 37.57s
	Expected Passes    : 69
	Unsupported Tests  : 7

2) CFLAGS="-march=armv7-a -mthumb"
	Testing Time: 0.16s
	Unsupported Tests  : 76

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

llvm-svn: 300194
2017-04-13 12:00:56 +00:00
Diana Picus 7e5db62ad5 Revert "Cache size per class size in SizeClassAllocatorXLocalCache."
This reverts commit r300107 because it broke the ARM and AArch64
buildbots.

llvm-svn: 300180
2017-04-13 07:39:04 +00:00
Vitaly Buka 0d2b80d499 [msan] Fix msan_test broken after r299884.
Bind to ANY as some machines may have IPv6 support but without IPv6 on loopback
interface.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 300150
2017-04-13 00:36:03 +00:00
Vitaly Buka b3cc24c289 [msan] Fix invalid use of vector constructor introduced by r299884.
llvm-svn: 300149
2017-04-13 00:36:02 +00:00
Alex Shlyapnikov daa342d9c3 Cache size per class size in SizeClassAllocatorXLocalCache.
Summary:
Allocator::ClassIdToSize() is not free and calling it in every
Allocate/Deallocate has noticeable impact on perf.

Reviewers: eugenis, kcc

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 300107
2017-04-12 21:44:56 +00:00
Alex Shlyapnikov 05bf27ac3f Avoid calling SizeClassMap::MaxCachedHint on hot path, it's not free.
Summary: Remove unecessary SizeClassMap::MaxCachedHint call.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 300103
2017-04-12 20:51:42 +00:00
Francis Ricci e9438b35aa Fix memory leaks in address sanitizer darwin tests
Summary: These leaks are detected by leak sanitizer for darwin.

Reviewers: glider, kubamracek, kcc, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300080
2017-04-12 17:31:41 +00:00
Francis Ricci f518c75641 Use 0-padding for i386 and arm print format specifiers
Summary:
This is used for the other architectures in print_address, but is
missing from i386 and arm.

Reviewers: m.ostapenko, spetrovic

Subscribers: aemerson, rengolin, llvm-commits, kubamracek

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

llvm-svn: 300065
2017-04-12 14:25:28 +00:00
Renato Golin baf04f92bc [LSAN] Disable on ARM/Thumb for good
I didn't pay enough attention to the patch I reverted, now I'm going to
hit it with a bigger hammer until we can understand what the problems
are.

llvm-svn: 300044
2017-04-12 10:12:49 +00:00
Renato Golin c6c8f09e49 Revert "[lsan] Fix typo in test/lsan/lit.common.cfg"
This reverts commit r299957. It broke the Thumb bots. We need to make
sure why and maybe stop it from being tested on Thumb environments. But
for now, let's get the bots green.

llvm-svn: 300042
2017-04-12 09:45:08 +00:00
Ismail Donmez d063db71e3 Fix compile error
llvm-svn: 300041
2017-04-12 09:42:46 +00:00
Martin Pelikan 75ed0acf97 [XRay] [compiler-rt] Refactor rewinding FDR logging.
Summary:
While there, make the threshold in ticks for the rewind computed only
once and not per function, unify the two versions we had and slightly
reformat bits according to coding standards.

Reviewers: dberris

Subscribers: llvm-commits

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

llvm-svn: 300028
2017-04-12 05:30:35 +00:00
Martin Pelikan bb1147317a [XRay] [compiler-rt] Simplify FDR logging handler. [NFC]
Summary:
Not repeating screamy failure paths makes the 300+ line function a bit shorter.
There's no need to overload the variable name "Buffer" if it only works on the
thread local buffer.  Fix some comments while there.

I plan to move the rewinding logic into a separate function too, but in this
diff it would be too much of a mess to comprehend.  This is trivially NFC.

Reviewers: kpw, dberris

Subscribers: llvm-commits

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

llvm-svn: 300018
2017-04-12 01:31:17 +00:00
Douglas Yung bcfc9d9b38 [XRay][compiler-rt] Add another work-around to XRay FDR tests when TSC emulation is needed
This patch applies a work-around to the XRay FDR tests when TSC emulation is 
needed because the processor frequency cannot be determined.

This fixes PR32620 using the suggestion given by Dean in comment 1.

Reviewers: dberris

Subscribers: llvm-commits

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

llvm-svn: 300017
2017-04-12 01:24:48 +00:00
Kostya Serebryany 13c8daf57a [msan] fix iconv interceptor. before the fix the interceptor failed to mark memory as initialized if iconv returned -1. Found in a hard way while fuzzing libxml2 :(
llvm-svn: 300010
2017-04-12 00:12:34 +00:00
Francis Ricci 03b2a8e47e Implement standalone lsan interceptors for OS X
Summary:
Mimicks the existing tsan and asan implementations of
Darwin interception.

Reviewers: kubamracek, kcc, glider

Subscribers: llvm-commits, mgorny

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

llvm-svn: 299979
2017-04-11 20:05:02 +00:00
Francis Ricci 84f17f32ad Don't delete lsan thread-local data until it's no longer required
Summary:
The routines for thread destruction in the thread registry require
the lsan thread index, which is stored in pthread tls on OS X.
This means that we need to make sure that the lsan tls isn't destroyed
until after the thread registry tls. This change ensures that we
don't delete the lsan tls until we've finished destroying the thread
in the registry, ensuring that the destructor for the lsan tls runs
after the destructor for the thread registry tls.

This patch also adds a check to ensure that the thread ID is valid before
returning it in GetThreadID(), to ensure that the above behavior
is working correctly.

Reviewers: dvyukov, kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 299978
2017-04-11 19:57:12 +00:00
Xinliang David Li 577b9d41d6 Revert 299954 : test failure needs to be fixed
llvm-svn: 299960
2017-04-11 16:27:26 +00:00
Maxim Ostapenko 83d37dc066 [lsan] Fix typo in test/lsan/lit.common.cfg
llvm-svn: 299957
2017-04-11 16:22:19 +00:00
Xinliang David Li a53e6702d2 [Profile] PE binary coverage bug fix
PR/32584

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

llvm-svn: 299954
2017-04-11 15:51:39 +00:00
Maxim Ostapenko de3b9a2ecc Reapply "Enable LSan for arm Linux"
This patch reapplies r299923 with typo fixed in BLX macros.

llvm-svn: 299948
2017-04-11 14:58:26 +00:00
Nico Weber 7124b5f6f9 Revert r299923, it doesn't build in bootstrap builds.
FAILED: lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.arm.dir/sanitizer_linux.cc.o 
lib/sanitizer_common/sanitizer_linux.cc:1340:24: error: invalid instruction
                       BLX(ip)
                       ^
lib/sanitizer_common/sanitizer_linux.cc:1313:19: note: expanded from macro 'BLX'
#  define BLX(R) "mov lr, pc; bx" #R "\n"
                  ^
<inline asm>:6:13: note: instantiated into assembly here
mov lr, pc; bxip
            ^~~~

llvm-svn: 299943
2017-04-11 14:28:49 +00:00
Catherine Moore 82525903a4 This patch causes the installation of headers for the sanitizer and/or xray to be disabled when COMPILER_RT_BUILD_SANITIZERS=OFF and/or COMPILER_RT_BUILD_XRAY=OFF.
Reviewer: dberris

Subscribers: dberris, mgorny, llvm-commits, clm

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

llvm-svn: 299940
2017-04-11 13:45:05 +00:00
Maxim Ostapenko 950d2809d5 [lsan] Enable LSan for arm Linux
This patch enables LSan for arm Linux.

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

llvm-svn: 299923
2017-04-11 08:13:38 +00:00
Douglas Yung c79031b2e9 [XRay][compiler-rt] Add support for TSC emulation for x86_64 to xray_fdr_logging.cc
Previously in r297800, a work-around was created to use TSC emulation on x86_64 when RDTSCP was not available on the host. A similar change was needed in the file xray_fdr_logging.cc which this patch ports over to that file.

Eventually the code should be refactored as there will be 3 locations with the same code, but that can be done as a separate step. This patch is just to keep the test from failing on my machine due to an illegal instruction since RDTSCP is not available on my x86_64 linux VM.

Reviewers: dberris

Subscribers: llvm-commits

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

llvm-svn: 299922
2017-04-11 07:45:16 +00:00
Dean Michael Berris 7b0ad61eaa [XRay][compiler-rt] Remove the xray_fdr_log_printer_tool
Summary:
We can move this functionality into LLVM's tools instead, as it no
longer is strictly required for the compiler-rt testing infrastructure.
It also is blocking the successful bootstrapping of the clang compiler
due to a missing virtual destructor in one of the flag parsing library.

Since this binary isn't critical for the XRay runtime testing effort
anymore (yet), we remove it in the meantime with the hope of moving the
functionality in LLVM proper instead.

Reviewers: kpw, pelikan, rnk, seurer, eugenis

Subscribers: llvm-commits, mgorny

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

llvm-svn: 299916
2017-04-11 06:04:08 +00:00
Alex Shlyapnikov 4d240da94b [PPC64, Sanitizers] Proper stack frame for the thread spawned in internal_clone
Summary:
Set up the proper stack frame for the thread spawned in internal_clone,
the current code does not follow ABI (and causes SEGV trying to use this
malformed frame).

Reviewers: wschmidt

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 299896
2017-04-10 23:24:50 +00:00
Vitaly Buka 2bca1a9f40 [tsan] Fall-back to IPv6 if IPv4 is not available.
Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 299885
2017-04-10 21:03:21 +00:00
Vitaly Buka c5e73d6e24 [msan] Choose in runtime if IPv4 or IPv6 are supported.
Summary: This reverts commit cab5051c691ce27a7ffac41e8e76ceb222ad9549.

Reviewers: eugenis

Subscribers: mgorny, llvm-commits

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

llvm-svn: 299884
2017-04-10 21:03:18 +00:00
Evgeniy Stepanov 2384165155 Revert "[asan] Fix dead stripping of globals on Linux (compiler-rt)."
This reverts r299698, which caused a big increase in object file size.

llvm-svn: 299881
2017-04-10 20:36:43 +00:00
Ivan A. Kosarev ec4880905d [Asan] Eliminate SHADOW_TO_MEM() macro
Differential Revision: https://reviews.llvm.org/D31592

llvm-svn: 299867
2017-04-10 19:13:47 +00:00
Vitaly Buka 59d309c7b5 [msan] Make test to fall-back to IPv6 if IPv4 is not available.
Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 299862
2017-04-10 17:59:07 +00:00
Vitaly Buka 08582c8e50 [msan] Replace AF_INET with AF_UNIX to avoid IPv4 vs IPv6 issues.
Summary: This reverts commit 79cf16bf224d6ac9fb9e0356c5947ebc4fd6ff92.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 299860
2017-04-10 17:58:03 +00:00
Vitaly Buka 30b4cfab1b [msan] Wrap sockaddr_in and socket for future IPv6 support.
Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 299859
2017-04-10 17:56:37 +00:00
Vitaly Buka 9804c81c55 [msan] Reorder unittests for future parametrization.
Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 299858
2017-04-10 17:22:06 +00:00
Evgeniy Stepanov bacee5c04f [cfi] Accept weak definition of __cfi_check.
https://reviews.llvm.org/D31796 results in LLD emitting __cfi_check
as a weak symbol, while Gold keeps it strong. Accept both.

llvm-svn: 299804
2017-04-07 22:52:08 +00:00
Rafael Espindola fc20b2b4ad Use a temp file to avoid Process Substitution.
Thanks to Reid Kleckner for the suggestion.

llvm-svn: 299794
2017-04-07 18:55:03 +00:00
Reid Kleckner 8cdfed7c9d [builtins] Remove stray quotes to fix check-builtins on non-Windows :(
llvm-svn: 299790
2017-04-07 17:40:25 +00:00
Reid Kleckner bfad55fbc0 [builtins] Make some ISA macro checks work with MSVC
llvm-svn: 299786
2017-04-07 17:18:43 +00:00
Reid Kleckner 3ae87c4650 [builtins] Fix MSVC build
Avoid __attribute__((constructor)) in cpu_model.c.

Use more C99 _Complex emulation in divtc3.c. Joerg Sonnenberger added
this builtin just after the last round of C99 _Complex emulation landed
in r249514 (Oct 2015).

llvm-svn: 299784
2017-04-07 16:54:32 +00:00
Reid Kleckner 8c78ca2e8f [builtins] Get the builtins tests passing on Windows
Many things were broken:

- We stopped building most builtins on Windows in r261432 for reasons
  that are not at all clear to me. This essentially reverts that patch.

- Fix %librt to expand to clang_rt.builtins-$arch.lib on Windows instead
  of libclang_rt.builtins-$arch.a.

- Fix memory protection tests (trampoline, enable executable, clear
  cache) on Windows. One issue was that the MSVC incremental linker
  generates ILT thunks for functions with external linkage, so memcpying
  the functions into the executable stack buffer wasn't working. You
  can't memcpy an RIP-relative jump without fixing up the offset.

- Disable tests that rely on C99 complex library functions when using
  the MSVC CRT, which isn't compatible with clang's C99 _Complex.

In theory, these could all be separate patches, but it would not green
the tests, so let's try for it all at once. Hopefully this fixes the
clang-x64-ninja-win7 bot.

llvm-svn: 299780
2017-04-07 16:35:09 +00:00
Reid Kleckner 78495ea7c0 Add missing import
llvm-svn: 299739
2017-04-07 01:24:48 +00:00
Reid Kleckner f6e857c402 [lit] Fix Darwin pickling errors with process pools
For a function to be pickle-able, it has to be in the top-level of a
real Python module. So, I made one for this code snippet.

llvm-svn: 299738
2017-04-07 01:23:15 +00:00
Evgeniy Stepanov 0680968ff3 [asan] Fix dead stripping of globals on Linux (compiler-rt).
This is a re-land of r298173, r298169, r298159.

llvm-svn: 299698
2017-04-06 19:55:52 +00:00
Rafael Espindola 8024cac19a Replace a few uses of basename.
This replaces a few uses of basename with the recently introduced lit
replacements.

llvm-svn: 299693
2017-04-06 19:38:24 +00:00
Ivan Krasin e63dccd98d Revert r299672: Add a virtual destructor to a class with virtual methods.
Reason: breaks sanitizers builds.

Original Differential Revision: https://reviews.llvm.org/D317

llvm-svn: 299679
2017-04-06 18:22:25 +00:00
Dimitry Andric 01220bf9d2 Add __ffssi2 implementation to compiler-rt builtins
Summary:
During MIPS implementation work for FreeBSD, John Baldwin (jhb@FreeBSD.org)
found that gcc 6.x emits calls to __ffssi2() when compiling libc and some
userland programs in the base system.

Add it to compiler-rt's builtins, based off of the existing __ffsdi2()
implementation.  Also update the CMake files and add a test case.

Reviewers: howard.hinnant, weimingz, rengolin, compnerd

Reviewed By: weimingz

Subscribers: dberris, mgorny, llvm-commits, emaste

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

llvm-svn: 299675
2017-04-06 18:12:02 +00:00
Ivan Krasin 547aadcba8 Add a virtual destructor to a class with virtual methods.
Summary:
Recently, Clang enabled the check for virtual destructors
in the presence of virtual methods. That broke the bootstrap
build. Fixing it.

Reviewers: pcc

Reviewed By: pcc

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 299672
2017-04-06 17:58:45 +00:00
Francis Ricci 4cce35f0ce Enable builds of darwin lsan by default
Summary: Testing and asan leak detection are disabled by default.

Reviewers: kubamracek, kcc

Subscribers: srhines, llvm-commits, mgorny

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

llvm-svn: 299669
2017-04-06 17:41:26 +00:00
Craig Topper d3115972bf [TSan] Adjust expectation for check_analyze.sh
r299658 fixed a case where InstCombine was replicating instructions instead of combining. Fixing this reduced the number of pushes and pops in the __tsan_read and __tsan_write functions.

Adjust the expectations to account for this after talking to Dmitry Vyukov.

llvm-svn: 299661
2017-04-06 17:09:08 +00:00
Dean Michael Berris d41c5ffc3e [XRay][compiler-rt] Remove unused local variable
The local was only referenced in assertions.

Follow-up to D31345.

llvm-svn: 299644
2017-04-06 11:27:53 +00:00
Maxim Ostapenko e6b81315f7 Try to fix MAC buildbot after r299630
llvm-svn: 299632
2017-04-06 08:17:09 +00:00
Maxim Ostapenko 18afec1ba6 Try to fix windows buildbot after r299630
llvm-svn: 299631
2017-04-06 07:53:26 +00:00
Maxim Ostapenko fe863a6510 [lsan] Avoid segfaults during threads destruction under high load
This patch addresses two issues:

	* It turned out that suspended thread may have dtls->dtv_size == kDestroyedThread (-1)
	and LSan wrongly assumes that DTV is available. This leads to SEGV when LSan tries to
	iterate through DTV that is invalid.
	* In some rare cases GetRegistersAndSP can fail with errno 3 (ESRCH). In this case LSan
	assumes that the whole stack of a given thread is available. This is wrong because ESRCH
	can indicate that suspended thread was destroyed and its stack was unmapped. This patch
	properly handles ESRCH from GetRegistersAndSP in order to avoid invalid accesses to already
	unpapped threads stack.

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

llvm-svn: 299630
2017-04-06 07:42:27 +00:00
Dean Michael Berris 895171e6ee [XRay] [compiler-rt] Unwriting FDR mode buffers when functions are short.
Summary:
"short" is defined as an xray flag, and buffer rewinding happens for both exits
 and tail exits.

 I've made the choice to seek backwards finding pairs of FunctionEntry, TailExit
 record pairs and erasing them if the FunctionEntry occurred before exit from the
 currently exiting function. This is a compromise so that we don't skip logging
 tail calls if the function that they call into takes longer our duration.

 This works by counting the consecutive function and function entry, tail exit
 pairs that proceed the current point in the buffer. The buffer is rewound to
 check whether these entry points happened recently enough to be erased.

 It is still possible we will omit them if they call into a child function that
 is not instrumented which calls a fast grandchild that is instrumented before
 doing other processing.

Reviewers: pelikan, dberris

Reviewed By: dberris

Subscribers: llvm-commits

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

llvm-svn: 299629
2017-04-06 07:14:43 +00:00
Weiming Zhao fbe67da29b [Builtins] Fix div0 error in udivsi3
Summary: Need to save `lr` before bl to aeabi_div0

Reviewers: rengolin, compnerd

Reviewed By: compnerd

Subscribers: llvm-commits

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

llvm-svn: 299628
2017-04-06 06:13:39 +00:00
Evgeniy Stepanov 7e94d38374 [cfi] Fix symbol lookup hack in cross-dso cfi to handle LLD binaries.
llvm-svn: 299604
2017-04-06 00:34:45 +00:00
Rafael Espindola 03994b814d Simplify test a bit.
There are two cases to consider:

We are using the internal shell. This will still fail because of
ulimit.
We are using an external shell. In this case the difference is that we
now also constrain FileCheck to use less than 4 MB of of stack, which
it should :-)

llvm-svn: 299586
2017-04-05 20:26:33 +00:00
Rafael Espindola 69a9e931ce Avoid calling basename to compute xdynamiclib_namespec.
This also exposes a xdynamiclib_filename that can be used to simplify
a few tests.

llvm-svn: 299478
2017-04-04 22:33:02 +00:00
Rafael Espindola f58991b7a4 Don't remove the cwd.
This works with a regular shell since the kernel can keep track of a
deleted cwd. Since we just keep a path string, the following
subprocess invocations fail.

I think this would also fail on windows.

llvm-svn: 299471
2017-04-04 21:42:59 +00:00
Rafael Espindola 01a8db64b1 Avoid sub shell.
Another step in getting these tests to run with the integrated one.

llvm-svn: 299452
2017-04-04 17:49:45 +00:00
Rafael Espindola 5b32f8e6bc Replace wc -l with count.
This is a far more common way in llvm of counting lines in tests.

llvm-svn: 299231
2017-03-31 16:49:37 +00:00
Rafael Espindola ebb4a918b5 Simplify test.
We don't need && since that is how various run lines are combined.
The redirects were not being used.

llvm-svn: 299215
2017-03-31 13:35:37 +00:00
Sam McCall 61dc7c0790 Remove unused variable.
llvm-svn: 299206
2017-03-31 12:07:58 +00:00
Maxim Ostapenko f73b73d04d [asan] Move AsanCheckDynamicRTPrereqs check under flag
The patch addresses https://github.com/google/sanitizers/issues/786. Currently AsanCheckDynamicRTPrereqs prevents
dynamic ASan runtime from running in some important environments e.g. cowbuilder and fakeroot that may also work with interposition.
Let's allow users to switch off the check given that they know what they do.

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

llvm-svn: 299188
2017-03-31 06:36:37 +00:00
Kuba Mracek b2e2634510 [asan] Turn -fsanitize-address-use-after-scope on by default [compiler-rt part]
AddressSanitizer has an optional compile-time flag, -fsanitize-address-use-after-scope, which enables detection of use-after-scope bugs. We'd like to have this feature on by default, because it is already very well tested, it's used in several projects already (LLVM automatically enables it when using -DLLVM_USE_SANITIZER=Address), it's low overhead and there are no known issues or incompatibilities.

This patch enables use-after-scope by default via the Clang driver, where we set true as the default value for AsanUseAfterScope. This also causes the lifetime markers to be generated whenever fsanitize=address is used. This has some nice consequences, e.g. we now have line numbers for all local variables.

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

llvm-svn: 299175
2017-03-31 03:00:29 +00:00
Kuba Mracek f1980a6305 Fixup for r299085: Keep the scribble.cc test on Darwin only, while I investigate why this test sometimes fails on Linux.
llvm-svn: 299130
2017-03-30 23:34:44 +00:00
Kuba Mracek 21e8ce398d Fixup for r299085: Disable the scribble.cc test on AArch64.
llvm-svn: 299099
2017-03-30 19:36:49 +00:00
Kuba Mracek 48c74b35d1 Fixup for r299085: On Windows %p doesn't print 0x prefix.
llvm-svn: 299092
2017-03-30 17:48:41 +00:00
Kuba Mracek c45f1e3134 Fixup for r299085: Print all output to stderr.
llvm-svn: 299090
2017-03-30 17:21:51 +00:00
Kuba Mracek 152dbcac82 Fixup for r299085: Include stdint.h in scribble.cc to make uintptr_t available.
llvm-svn: 299089
2017-03-30 17:01:35 +00:00
Kuba Mracek 0bf5ec2812 [tsan] Add interceptor for xpc_connection_cancel to avoid false positives
TSan reports a false positive when using xpc_connection_cancel. We're missing a happens-before edge from xpc_connection_cancel to the event handler on the same connection.

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

llvm-svn: 299086
2017-03-30 15:48:25 +00:00
Kuba Mracek fe7e91b003 [asan] Implement "scribble" flags, which overwrite free'd memory with 0x55
This patch implements "Malloc Scribble" in ASan via "max_free_fill_size" and "free_fill_byte" flags, which can be used to overwrite free()'d memory. We also match the behavior of MallocScribble and MallocPreScribble env vars on macOS (see https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html), which is a helpful tool to detect use-after-free bugs that happen in non-instrumented code.

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

llvm-svn: 299085
2017-03-30 15:44:57 +00:00
Rafael Espindola 281979b12d avoid a subshell.
Instead of using grep -v we can just expand the globs a bit.

llvm-svn: 299084
2017-03-30 15:02:24 +00:00
Francis Ricci 2aa23e892c Enable leak detection on linux-i686 by default
Summary:
This is already assumed by the test suite, and by
asan_flags.cc.

Reviewers: m.ostapenko, vitalybuka, kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 299082
2017-03-30 14:05:46 +00:00
Rafael Espindola bc16aa9551 Use FileCheck instead of [.
llvm-svn: 299081
2017-03-30 14:02:08 +00:00
Rafael Espindola 41ca83f811 Add LIT_USE_INTERNAL_SHELL to compiler-rt tests.
I am working on improving our internal bot infrastructure. One thing
that is unique to the ps4 is that we want to run the posix tests, but
have to execute them on windows.

We currently have a local hack to use a shell on windows, but it is
pretty much impossible to get all all the tools to play nice with all
the heuristics for what is a path and what is a command line option.

This adds support LIT_USE_INTERNAL_SHELL and I will then try to fix
the tests that fail with it but adding the missing features.

llvm-svn: 299077
2017-03-30 13:33:22 +00:00
Rafael Espindola be927f586d Use count instead of grep -c.
Using count is more common in llvm and avoids a subshell.

llvm-svn: 299076
2017-03-30 13:22:30 +00:00
Maxim Ostapenko f29aec76dd [sanitizer] Move fread and fwrite interceptors to sanitizer_common
{M, T, E}San have fread and fwrite interceptors, let's move them to sanitizer_common to enable ASan checks as well.

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

llvm-svn: 299061
2017-03-30 07:25:33 +00:00
Dean Michael Berris d7b2aafcfc [XRay][compiler-rt] Spell REQUIRES properly for x86_64-linux
Until llvm-xray starts running/supporting binaries that are not ELF64 we
only run the FDR tests on x86_64-linux. Previous changes caused the
tests to not actually run on x86_64.

Follow-up on D31454.

llvm-svn: 299050
2017-03-30 03:50:56 +00:00
Dean Michael Berris c8381a8ad4 [XRay][compiler-rt] Only run tests using llvm-xray in x86_64 for now
Followup on D31454.

llvm-svn: 299049
2017-03-30 03:18:48 +00:00
Dean Michael Berris fecffaf87a [XRay][compiler-rt] XFAIL the FDR mode tests on aarch64-42vma
Followup on D31454.

llvm-svn: 299048
2017-03-30 02:48:50 +00:00
Kuba Mracek 8ed2928d2c [asan] Support line numbers in StackVarDescr
When -fsanitize-address-use-after-scope is used, the instrumentation produces line numbers in stack frame descriptions. This patch make sure the ASan runtime supports this format (ParseFrameDescription needs to be able to parse "varname:line") and prepares lit tests to allow line numbers in ASan report output.

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

llvm-svn: 299043
2017-03-30 00:41:09 +00:00
Dean Michael Berris 51c1365501 [XRay][compiler-rt] Use llvm-xray in FDR mode tests
Summary:
This change allows us to do an end-to-end test of the FDR mode
implementation that uses the llvm-xray tooling to verify that what we
are both writing and reading the data in a consistent manner.

Reviewers: kpw, pelikan

Subscribers: llvm-commits

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

llvm-svn: 299042
2017-03-30 00:35:58 +00:00
Kostya Serebryany 2203ee08dd [sanitizers] Fix get_groups interceptor in sanitizer (https://reviews.llvm.org/D31332, patch by Martin Liška)
llvm-svn: 299036
2017-03-29 22:59:28 +00:00
Francis Ricci a79b8a22b4 Move current thread data out of lsan_common on linux
Summary:
Now that we have a platform-specific non-common lsan file, use
it to store non-common lsan data.

Reviewers: kubamracek

Subscribers: llvm-commits

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

llvm-svn: 299032
2017-03-29 21:49:47 +00:00