Commit Graph

8964 Commits

Author SHA1 Message Date
Kuba Mracek ce65982ea1 Revert r306504: Re-enable wait.cc, wait4.cc, waitid.cc tests on Darwin.
llvm-svn: 306551
2017-06-28 15:13:09 +00:00
Dean Michael Berris 66e08e7781 [XRay][compiler-rt][NFC] Move test case into correct directory.
Followup to D34669.

llvm-svn: 306506
2017-06-28 05:21:15 +00:00
Dean Michael Berris c3881436cf [XRay][compiler-rt] Only run test in x86_64 linux.
Followup to D34669.

llvm-svn: 306505
2017-06-28 05:19:59 +00:00
Kuba Mracek 70e8e9d8f6 Re-enable wait.cc, wait4.cc, waitid.cc tests on Darwin. They used to be flaky, something to do with LeakSanitizer now being enabled on Darwin. Let's re-enable them and see if they are still flaky or not.
llvm-svn: 306504
2017-06-28 05:03:28 +00:00
Dean Michael Berris 261d97332d [XRay][compiler-rt][NFC] Add example always/never instrument files.
Summary:
This change introduces two files that show exaples of the
always/never instrument files that can be provided to clang. We don't
add these as defaults yet in clang, which we can do later on (in a
separate change).

We also add a test that makes sure that these apply in the compiler-rt
project tests, and that changes in clang don't break the expectations in
compiler-rt.

Reviewers: pelikan, kpw

Subscribers: llvm-commits

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

llvm-svn: 306502
2017-06-28 04:44:36 +00:00
Evgeniy Stepanov 9e4519db1e [asan] Fix windows build.
llvm-svn: 306493
2017-06-28 00:37:29 +00:00
Evgeniy Stepanov 6f75e2dd48 [msan] Intercept wcscat, wcsncat.
Also move wcslen, wscnlen to common interceptors.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 306482
2017-06-27 22:52:38 +00:00
Xinliang David Li 1f0d0b2a4c [Profile] Remove redundant call
llvm-svn: 306480
2017-06-27 22:42:24 +00:00
Francis Ricci fa0e536521 Don't build tsan/dd when COMPILER_RT_HAS_TSAN is false
llvm-svn: 306463
2017-06-27 21:10:46 +00:00
Francis Ricci 23aae3b554 Don't double-include cfi tests on linux
llvm-svn: 306455
2017-06-27 19:52:35 +00:00
Francis Ricci d379d1c2ee Loop directly over sanitizers to build in cmake
Summary: Cleaner than computing the intersection for each possible sanitizer

Reviewers: compnerd, beanz

Subscribers: llvm-commits, mgorny

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

llvm-svn: 306453
2017-06-27 19:32:39 +00:00
Francis Ricci 57a3f4584d Only test sanitizers that are built when COMPILER_RT_SANITIZERS_TO_BUILD is used
Summary: This allows check-all to be used when only a subset of the sanitizers are built.

Reviewers: beanz, compnerd, rnk, pcc

Subscribers: llvm-commits, mgorny

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

llvm-svn: 306450
2017-06-27 19:18:01 +00:00
Xinliang David Li 967669f6c1 [PGO] Refactor file/buffer writer callback interfaces /NFC
Introduces a 'owner' struct to include the overridable write
method and the write context in C.

This allows easy introdution of new member API to help reduce
profile merge time in the follow up patch.

llvm-svn: 306432
2017-06-27 17:28:01 +00:00
Francis Ricci 07fa7942fd Revert "Only test sanitizers that are built when COMPILER_RT_SANITIZERS_TO_BUILD is used"
This breaks cfi testing in cases when the cfi runtime isn't built.

This reverts commit 1c6a7b07545f0c9ce68e8b226f5397694ce48af7.

llvm-svn: 306431
2017-06-27 17:24:26 +00:00
Francis Ricci 80296ee7f3 Only test sanitizers that are built when COMPILER_RT_SANITIZERS_TO_BUILD is used
Summary: This allows check-all to be used when only a subset of the sanitizers are built.

Reviewers: beanz, compnerd

Subscribers: llvm-commits, mgorny

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

llvm-svn: 306415
2017-06-27 15:22:56 +00:00
Francis Ricci 2189fe1870 [tsan] Add missing include directory for test unittests
Summary: Required to fix standalone builds in some configurations

Reviewers: kubamracek, zaks.anna

Subscribers: mgorny, llvm-commits

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

llvm-svn: 306411
2017-06-27 14:56:59 +00:00
Alex Shlyapnikov 01676883cd [Sanitizers] 64 bit allocator respects allocator_may_return_null flag
Summary:
Make SizeClassAllocator64 return nullptr when it encounters OOM, which
allows the entire sanitizer's allocator to follow
allocator_may_return_null=1 policy
(LargeMmapAllocator: D34243, SizeClassAllocator64: D34433).

Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 306342
2017-06-26 22:54:10 +00:00
Kuba Mracek 495371d6df [asan] Flag 'asan_gen_prefixes.cc' as unsupported on iOS. The ARM and ARM64 assemblers can use different label prefixes than the expected.
llvm-svn: 306335
2017-06-26 21:37:40 +00:00
Derek Bruening 92e4443c32 [esan] Disable flaky tests for PR33590
Disables 3 esan workingset tests until their underlying failures are
determined and resolved.

llvm-svn: 306259
2017-06-26 01:02:54 +00:00
Xinliang David Li 95ce779185 [PGO] Implementate profile counter regiser promotion (test case)
Differential Revision: http://reviews.llvm.org/D34085

llvm-svn: 306232
2017-06-25 00:27:09 +00:00
Vitaly Buka b768d5b863 [asan] Regression test for PR33372
Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 306195
2017-06-24 01:40:41 +00:00
Evgeniy Stepanov 90e5c30836 [asan] Add support for Android debug message.
Add ASan report to the "debug message" field in Android tombstones.

llvm-svn: 306184
2017-06-23 23:38:20 +00:00
Vedant Kumar d1c3780cf6 [ubsan] Improve diagnostics for return value checks (compiler-rt)
Differential Revision: https://reviews.llvm.org/D34298

llvm-svn: 306164
2017-06-23 21:32:48 +00:00
Alex Shlyapnikov f3cc7cc3d8 [Sanitizers] 32 bit allocator respects allocator_may_return_null flag
Summary:
Make SizeClassAllocator32 return nullptr when it encounters OOM, which
allows the entire sanitizer's allocator to follow allocator_may_return_null=1
policy, even for small allocations (LargeMmapAllocator is already fixed
by D34243).

Will add a test for OOM in primary allocator later, when
SizeClassAllocator64 can gracefully handle OOM too.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 305972
2017-06-22 00:02:37 +00:00
Justin Bogner dd862f9106 [sanitizer-coverage] Stop marking this test as unsupported on Darwin
The bug that was causing this to fail was fixed in r305429.

llvm-svn: 305942
2017-06-21 19:04:59 +00:00
Kostya Kortchinsky 2b053b1c28 [sanitizer] Add a function to gather random bytes
Summary:
AFAICT compiler-rt doesn't have a function that would return 'good' random
bytes to seed a PRNG. Currently, the `SizeClassAllocator64` uses addresses
returned by `mmap` to seed its PRNG, which is not ideal, and  
`SizeClassAllocator32` doesn't benefit from the entropy offered by its 64-bit
counterpart address space, so right now it has nothing. This function aims at
solving this, allowing to implement good 32-bit chunk randomization. Scudo also
has a function that does this for Cookie purposes, which would go away in a
later CL once this lands.

This function will try the `getrandom` syscall if available, and fallback to
`/dev/urandom` if not.

Unfortunately, I do not have a way to implement and test a Mac and Windows
version, so those are unimplemented as of now. Note that `kRandomShuffleChunks`
is only used on Linux for now.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: zturner, rnk, llvm-commits, kubamracek

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

llvm-svn: 305922
2017-06-21 15:56:03 +00:00
Simon Dardis f62399945c [mips][compiler-rt] Fix build breakage.
Change some reinterpret_casts to c-style casts due to template instantiation
restrictions and build breakage due to missing paranthesises.

llvm-svn: 305899
2017-06-21 11:29:15 +00:00
Vitaly Buka ff7b8ea2a0 Revert "[compiler-rt] Don't reset non-default user handler if allow_user_segv_handler is true."
Summary:
On Android we still need to reset preinstalled handlers and allow use handlers later.

This reverts commit r304039.

Reviewers: eugenis

Subscribers: kubamracek, dberris, llvm-commits

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

llvm-svn: 305871
2017-06-21 01:10:23 +00:00
Evgeniy Stepanov 827cd74618 [asan] Fix android compiler wrapper lost in r301617.
llvm-svn: 305870
2017-06-21 00:56:31 +00:00
Alex Shlyapnikov ccab11b0e8 [Sanitizers] Move cached allocator_may_return_null flag to sanitizer_allocator
Summary:
Move cached allocator_may_return_null flag to sanitizer_allocator.cc and
provide API to consolidate and unify the behavior of all specific allocators.

Make all sanitizers using CombinedAllocator to follow
AllocatorReturnNullOrDieOnOOM() rules to behave the same way when OOM
happens.

When OOM happens, turn allocator_out_of_memory flag on regardless of
allocator_may_return_null flag value (it used to not to be set when
allocator_may_return_null == true).

release_to_os_interval_ms and rss_limit_exceeded will likely be moved to
sanitizer_allocator.cc too (later).

Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 305858
2017-06-20 21:23:02 +00:00
Alex Shlyapnikov a26d10802b [ASan] Disable allocator_oom_test.cc on s390
Summary:
ASan shadow memory on s390 is larger than other configurations, let's
disable this test for now (will revisit it later).

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 305822
2017-06-20 19:16:41 +00:00
Evgeniy Stepanov a2049b5210 [asan] Fix android setup script to overwrite the symlink.
This fixes asan_device_setup failing to update an existing asan
installation.

llvm-svn: 305746
2017-06-19 21:42:44 +00:00
Francis Ricci 42175cb0d7 Add lsan interceptors for libdispatch functions on darwin
Summary:
This is required for standalone LSan to work with libdispatch worker threads,
and is a slimmed down version of the functionality provided for ASan
in asan_mac.cc.

Re-commit of r305695 with use_stacks=0 to get around a racy lingering pointer.

Reviewers: alekseyshl, kubamracek, glider, kcc

Subscribers: mgorny, llvm-commits

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

llvm-svn: 305732
2017-06-19 19:21:31 +00:00
Francis Ricci 214b354f2e Revert "Add lsan interceptors for libdispatch functions on darwin"
This reverts r305695

llvm-svn: 305712
2017-06-19 17:08:55 +00:00
Francis Ricci 4f1e047a6d Add lsan interceptors for libdispatch functions on darwin
Summary:
This is required for standalone LSan to work with libdispatch worker threads,
and is a slimmed down version of the functionality provided for ASan
in asan_mac.cc.

Reviewers: alekseyshl, kubamracek, glider, kcc

Subscribers: mgorny, llvm-commits

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

llvm-svn: 305695
2017-06-19 14:09:10 +00:00
Sagar Thakur 6478d14a0d [scudo] Enabling MIPS support for Scudo
Adding MIPS 32-bit and 64-bit support for Scudo.

Reviewed by cryptoad, sdardis.
Differential: D31803

llvm-svn: 305682
2017-06-19 11:28:59 +00:00
Dean Michael Berris 8d6f9c24d3 [XRay][compiler-rt][NFC] Add a test for both arg1 and arg0 handling in the same binary
This test makes sure we can handle both arg0 and arg1 handling in the
same binary, and making sure that the XRay runtime calls the correct
trampoline when handlers for both of these cases are installed.

llvm-svn: 305660
2017-06-19 03:52:25 +00:00
Dean Michael Berris 043d3f8682 [XRay][compiler-rt][NFC] Add a name for argument to __xray_set_handler_arg1(...)
Just makes the interface consistent with the other functions in
include/xray/xray_interface.h.

llvm-svn: 305658
2017-06-19 01:30:04 +00:00
Pirama Arumuga Nainar 31b825d834 Call cmake_minimum_required at the top of CMakeLists.txt
Summary:
Since r298413, the NEW behavior of the CMake policy CMP0056 is followed.
However, it is only effective after the call to cmake_minimum_required.
This causes CMAKE_EXE_LINKER_FLAGS etc. to be unused when CMake tries to
check compilers for languages specified in the 'project' declaration.

Set cmake_minimum_required(VERSION) at the top of the file and ahead of
the project declaration.

Reviewers: beanz

Subscribers: mgorny, srhines, llvm-commits

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

llvm-svn: 305593
2017-06-16 21:14:45 +00:00
Alex Shlyapnikov 5a308f24c3 [Sanitizer] Remove CombinedAllocator::Allocate's 'cleared' parameter
Summary:
CombinedAllocator::Allocate cleared parameter is not used anywhere and
seem to be obsolete.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305590
2017-06-16 21:00:03 +00:00
Reid Kleckner f1b9f3a23f [WinASan] Fix hotpatching new Win 10 build 1703 x64 strnlen prologue
The first instruction of the new ucrtbase!strnlen implementation loads a
global, presumably to dispatch between SSE and non-SSE optimized strnlen
implementations.

Fixes PR32895 and probably
https://github.com/google/sanitizers/issues/818

llvm-svn: 305581
2017-06-16 20:44:00 +00:00
Alex Shlyapnikov d340605a37 [Sanitizers] Fix allocator OOM test on Windows.
Summary:
Point of failure is different after D34243, hence the change of the
message.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305580
2017-06-16 20:36:39 +00:00
Alex Shlyapnikov 9092fe6f4b [Sanitizers] Secondary allocator respects allocator_may_return_null=1.
Summary:
Context: https://github.com/google/sanitizers/issues/740.

Making secondary allocator to respect allocator_may_return_null=1 flag
and return nullptr when "out of memory" happens.

More changes in primary allocator and operator new will follow.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 305569
2017-06-16 18:48:08 +00:00
Dean Michael Berris 10bbc4f99e Add test for logging the implicit "this" argument for C++ member functions.
Summary:
This allows us to do more interesting things with the data available to
C++ methods, to log the `this` pointer.

Depends on D34050.

Reviewers: pelikan

Subscribers: llvm-commits

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

llvm-svn: 305545
2017-06-16 03:24:07 +00:00
Evgeniy Stepanov 2aed0fb07e [cfi] Enable icall tests with thinlto.
llvm-svn: 305534
2017-06-16 00:18:35 +00:00
Vedant Kumar f7e804157e [ubsan] Fix a faulty memory accessibility check
The dynamic type check needs to inspect vtables, but could crash if it
encounters a vtable pointer to inaccessible memory. In the first attempt
to fix the issue (r304437), we performed a memory accessibility check on
the wrong range of memory. This should *really* fix the problem.

Patch by Max Moroz!

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

llvm-svn: 305489
2017-06-15 18:23:16 +00:00
Vitaly Buka 4a2cc96f1f [asan] Fix typo in doc string.
llvm-svn: 305436
2017-06-15 00:31:59 +00:00
Vitaly Buka 7901b47094 [asan] Return allow_user_segv_handler=0 to fix compatibility issues.
Summary:
After r303941 it was not possible to setup ASAN_OPTIONS to have the same
behavior for pre r303941 and post r303941 builds.
Pre r303941 Asan does not accept handle_sigbus=2.
Post r303941 Asan does not accept allow_user_segv_handler.

This fix ignores allow_user_segv_handler=1, but for allow_user_segv_handler=0
it will upgrade flags like handle_sigbus=1 to handle_sigbus=2. So user can set
ASAN_OPTIONS=allow_user_segv_handler=0 and have same behavior on old and new
clang builds (except range from r303941 to this revision).

In future users which need to prevent third party handlers should switch to
handle_sigbus=2 and remove allow_user_segv_handler as soon as suport of older
builds is not needed.

Related bugs:
  https://github.com/google/oss-fuzz/issues/675
  https://bugs.chromium.org/p/chromium/issues/detail?id=731130

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305433
2017-06-15 00:19:13 +00:00
Kostya Kortchinsky 77f30c9c31 [sanitizer] Reverting D34152
Summary:
This broke thread_local_quarantine_pthread_join.cc on some architectures, due
to the overhead of the stashed regions. Reverting while figuring out the best
way to deal with it.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305404
2017-06-14 17:32:26 +00:00
Kostya Kortchinsky eca926ab3a [sanitizer] MmapAlignedOrDie changes to reduce fragmentation
Summary:
The reasoning behind this change is explained in D33454, which unfortunately
broke the Windows version (due to the platform not supporting partial unmapping
of a memory region).

This new approach changes `MmapAlignedOrDie` to allow for the specification of
a `padding_chunk`. If non-null, and the initial allocation is aligned, this
padding chunk will hold the address of the extra memory (of `alignment` bytes).
This allows `AllocateRegion` to get 2 regions if the memory is aligned
properly, and thus help reduce fragmentation (and saves on unmapping
operations). As with the initial D33454, we use a stash in the 32-bit Primary
to hold those extra regions and return them on the fast-path.

The Windows version of `MmapAlignedOrDie` will always return a 0
`padding_chunk` if one was requested.

Reviewers: alekseyshl, dvyukov, kcc

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305391
2017-06-14 15:32:17 +00:00
Alex Shlyapnikov 8531fa3028 [ASan] Move rss_limit_is_exceeded_ flag to ASan.
Summary:
Move the OOM decision based on RSS limits out of generic allocator to
ASan allocator, where it makes more sense at the moment.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 305342
2017-06-13 23:57:24 +00:00
Evgeniy Stepanov cde90a66b5 [sanitize] Remove stack size limits from secondary threads.
If pthread_attr_getstack tell us the stack is 2G, why would we doubt that?

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

llvm-svn: 305330
2017-06-13 22:29:15 +00:00
Dmitry Vyukov dc2a38cdf2 tsan: fix reading of mutex flags
SyncVar::IsFlagSet returns true if any flag is set.
This is wrong. Check the actual requested flag.

llvm-svn: 305281
2017-06-13 09:37:51 +00:00
Dmitry Vyukov f5b3b84826 tsan: fix pedantic warnings
ISO C++ does not allow ?: with omitted middle operand

llvm-svn: 305273
2017-06-13 07:09:56 +00:00
Vedant Kumar 8c31c2a546 [ubsan] Detect invalid unsigned pointer index expression (compiler-rt)
Compiler-rt part of: https://reviews.llvm.org/D33910

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

llvm-svn: 305217
2017-06-12 18:42:51 +00:00
Vedant Kumar c7672d66ba Mark a sancov test as unsupported on x86_64h-darwin
Failing bot: http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-expensive/6891

llvm-svn: 305133
2017-06-10 00:12:11 +00:00
Xinliang David Li 384f704834 Minor clean up of profile rt tests
llvm-svn: 305113
2017-06-09 21:14:19 +00:00
Maxim Ostapenko d8c47ca836 [asan] Fix ASan internal failure in AllocateFromLocalPool
This patch addresses PR 33206. There might be a situation when dynamic ASan runtime initializes later
than shared library which has malloc in static constructor (rtld doesn't provide an order of shared libs initialization).
In this case ASan hasn't yet initialized interceptors, but already intercepts malloc.
If malloc is too big to be handled by static local pool, ASan will die with error: 
Sanitizer CHECK failed: lib/asan/asan_malloc_linux.cc:40 ((allocated_for_dlsym)) < ((kDlsymAllocPoolSize)) (1036, 1024)

Patch by Denis Khalikov.

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

llvm-svn: 305058
2017-06-09 07:47:38 +00:00
Kostya Serebryany 2c2fb8896b [sanitizer-coverage] one more flavor of coverage: -fsanitize-coverage=inline-8bit-counters. Experimental so far, not documenting yet. Reapplying revisions 304630, 304631, 304632, 304673, see PR33308
llvm-svn: 305026
2017-06-08 22:58:19 +00:00
Vedant Kumar cecb1121bb Mark the tsan strerror_r test as unsupported on Darwin
llvm-svn: 304944
2017-06-07 21:10:35 +00:00
Vedant Kumar 3e95c498aa Revert "Fix tsan test for Darwin. NFCI."
This reverts commit r304941. Vitaly Buka writes:
"Actually it depends on return value.
Test is for char* version of function. It will probably fail for int
version."

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

llvm-svn: 304941
2017-06-07 20:43:15 +00:00
Evgeniy Stepanov 7922ac23f1 [sanitizer] Fix symbolizer build after r304864.
r304864 moved code into a new BinaryFormat library. Update the
symbolizer build script.

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

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

llvm-svn: 304858
2017-06-07 01:53:38 +00:00
Alex Shlyapnikov effb794346 [ASan] A speculative attempt to fix a flaky test on ppc64be.
Summary:
As mentioned in test/msan/fork.cc, if test output is redirected to a file
(as opposed to being piped directly to FileCheck), we may lose some "done"s due to
a kernel bug: https://lkml.org/lkml/2014/2/17/324, so let's pipe the
output of the test.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 304744
2017-06-05 22:23:15 +00:00
Evgeniy Stepanov 790838110f Revert r304285, r304297.
r304285 - [sanitizer] Avoid possible deadlock in child process after fork
r304297 - [sanitizer] Trying to fix MAC buildbots after r304285

These changes create deadlock when Tcl calls pthread_create from a
pthread_atfork child handler. More info in the original review at
https://reviews.llvm.org/D33325

llvm-svn: 304735
2017-06-05 21:20:55 +00:00
Alex Shlyapnikov abe8af9fac [asan] Use asan exitcode=0 option to always succeed a test run.
Summary:
halt_on_error-torture.cc intermittently fails on ppc64be, let's try to
collect more info on failures.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 304731
2017-06-05 20:36:57 +00:00
Tim Northover ada043541d CMake: don't try to use lld if we're not building it.
Monorepo version!

llvm-svn: 304716
2017-06-05 15:10:04 +00:00
Renato Golin 77a12b3972 Revert "[sanitizer-coverage] test for -fsanitize-coverage=inline-8bit-counters"
Revert "Mark sancov test as unsupported on Darwin"
Revert "[LSan] Detect dynamic loader by its base address."

This reverts commit r304633.
This reverts commit r304673.
This reverts commit r304632.

Those commit have broken LOTS of ARM/AArch64 bots for two days.

llvm-svn: 304699
2017-06-05 07:36:02 +00:00
Vedant Kumar 921e4ddbad Mark the atos-symbolizer test as unsupported on i386-darwin
atos is apparently not able to resolve symbol addresses properly on
i386-darwin reliably any more. This is causing bot flakiness:
http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-expensive/6841

There have not been any SDK changes on the bot as of late.

/Users/buildslave/jenkins/sharedspace/clang-stage1-cmake-RA_workspace/llvm/projects/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer.cc:20:12: error: expected string not found in input
 // CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer.cc:[[@LINE-4]]
           ^
<stdin>:35:27: note: scanning from here
 #0 0x112f56 in wrap_free (/Users/buildslave/jenkins/sharedspace/clang-stage1-cmake-RA_workspace/clang-build/lib/clang/5.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:i386+0x56f56)
                          ^
<stdin>:35:27: note: with expression "@LINE-4" equal to "16"
 #0 0x112f56 in wrap_free (/Users/buildslave/jenkins/sharedspace/clang-stage1-cmake-RA_workspace/clang-build/lib/clang/5.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:i386+0x56f56)
                          ^
<stdin>:36:168: note: possible intended match here
 #1 0xb6f20 in main (/Users/buildslave/jenkins/sharedspace/clang-stage1-cmake-RA_workspace/clang-build/tools/clang/runtime/compiler-rt-bins/test/asan/I386DarwinConfig/TestCases/Darwin/Output/atos-symbolizer.cc.tmp:i386+0x1f20)

llvm-svn: 304674
2017-06-04 02:18:45 +00:00
Vedant Kumar d3322c1ed7 Mark sancov test as unsupported on Darwin
This test has been failing on all Darwin bots since it was introduced:
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/32111

fatal error: error in backend: Global variable '__sancov_gen_' has an invalid section specifier '__DATA,__sancov_counters': mach-o section specifier requires a section whose length is between 1 and 16 characters.
Target: x86_64-apple-darwin15.6.0

llvm-svn: 304673
2017-06-04 01:56:44 +00:00
Dimitry Andric 6c00c9950c Adjust sanitizers for FreeBSD 64-bit inode update
Summary:
Very recently, FreeBSD 12 has been updated to use 64-bit inode numbers:
<https://svnweb.freebsd.org/changeset/base/318737>.  This entails many
user-visible changes, but for the sanitizers the modifications are
limited in scope:
* The `stat` and `lstat` syscalls were removed, and should be replaced
  with calls to `fstatat`.
* The `getdents` syscall was removed, and should be replaced with calls
  to `getdirentries`.
* The layout of `struct dirent` was changed to accomodate 64-bit inode
  numbers, and a new `d_off` field was added.
* The system header <sys/_types.h> now contains a macro `__INO64` to
  determine whether the system uses 64-bit inode numbers.

I tested these changes on both FreeBSD 12.0-CURRENT (after r318959,
which adds the `__INO64` macro), and FreeBSD 11.0-STABLE (which still
uses 32-bit inode numbers).

Reviewers: emaste, kcc, vitalybuka, kubamracek

Reviewed By: vitalybuka

Subscribers: llvm-commits

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

llvm-svn: 304658
2017-06-03 11:11:36 +00:00
Alex Shlyapnikov 2090504453 [LSan] Detect dynamic loader by its base address.
Summary:
Whenever possible (Linux + glibc 2.16+), detect dynamic loader module by
its base address, not by the module name matching. The current name
matching approach fails on some configurations.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 304633
2017-06-03 01:43:44 +00:00
Kostya Serebryany edc20a10c1 [sanitizer-coverage] test for -fsanitize-coverage=inline-8bit-counters
llvm-svn: 304632
2017-06-03 01:36:53 +00:00
Kostya Serebryany ad272b0861 [asan] fix one more case where stack-use-after-return is not async-signal-safe (during thread startup). beef-up the test to give it a chance to catch regressions. Also relax the lint to make C++11 more usable.
llvm-svn: 304598
2017-06-02 21:32:04 +00:00
Kostya Serebryany 124c2ae4fa [sanitizer-coverage] nuke more stale code
llvm-svn: 304508
2017-06-02 01:17:04 +00:00
Kostya Serebryany 1800814b41 [sanitizer-coverage] nuke more stale code
llvm-svn: 304504
2017-06-02 00:52:35 +00:00
Kostya Serebryany c1a56baa3e [sanitizer-coverage] nuke more stale code
llvm-svn: 304503
2017-06-02 00:17:54 +00:00
Kostya Serebryany 70c64869b5 [sanitizer-coverage] nuke more stale code
llvm-svn: 304500
2017-06-01 23:56:49 +00:00
Vedant Kumar 41dfc4f1fa [ubsan] Runtime support for pointer overflow checking
Patch by John Regehr and Will Dietz!

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

llvm-svn: 304461
2017-06-01 19:40:59 +00:00
Vedant Kumar 8f5073446f Tighten up test to address bot failure. NFC.
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/32035

llvm-svn: 304440
2017-06-01 17:56:12 +00:00
Vedant Kumar 9af30e3541 Bug 33221 [UBSAN] segfault with -fsanitize=undefined
There is can be a situation when vptr is not initializing
by constructor of the object, and has a junk data which should
be properly checked, because c++ standard says:

"if default constructor is not specified
16 (7.3) no initialization is performed."

Patch by Denis Khalikov!

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

llvm-svn: 304437
2017-06-01 16:44:11 +00:00
Pierre Gousseau 183d1368f3 [asan] Add strndup/__strndup interceptors.
Recommit of r302781 with Vitaly Buka's fix for non zero terminated strings.

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

llvm-svn: 304399
2017-06-01 09:37:22 +00:00
Kostya Serebryany 9c50876120 [sanitizer-coverage] remove stale code (old coverage); compiler-rt part
llvm-svn: 304318
2017-05-31 18:26:32 +00:00
Maxim Ostapenko b1f0a346d6 [sanitizer] Trying to fix MAC buildbots after r304285
It seems that on MAC allocator already locks on fork thus adding another ForceLock
in fork interceptor will cause a deadlock.

llvm-svn: 304297
2017-05-31 11:40:57 +00:00
Maxim Ostapenko 62a0f55930 [sanitizer] Avoid possible deadlock in child process after fork
This patch addresses https://github.com/google/sanitizers/issues/774. When we
fork a multi-threaded process it's possible to deadlock if some thread acquired
StackDepot or allocator internal lock just before fork. In this case the lock
will never be released in child process causing deadlock on following memory alloc/dealloc
routine. While calling alloc/dealloc routines after multi-threaded fork is not allowed,
most of modern allocators (Glibc, tcmalloc, jemalloc) are actually fork safe. Let's do the same
for sanitizers except TSan that has complex locking rules.

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

llvm-svn: 304285
2017-05-31 07:28:09 +00:00
Alex Shlyapnikov 0145dee366 [sanitizer] Add "isapla" to symbolizer's global symbols whitelist.
Summary: D33637 introduced isalpha, whitelist need to reflect that.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 304234
2017-05-30 19:52:34 +00:00
Alex Shlyapnikov f8f8f49a24 [asan] Enable back halt_on_error-torture.cc disabled on PowerPC.
Summary:
D33521 addressed a memory ordering issue in BlockingMutex, which seems
to be the cause of a flakiness of a few ASan tests on PowerPC.

Reviewers: eugenis

Subscribers: kubamracek, nemanjai, llvm-commits

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

llvm-svn: 304045
2017-05-26 23:14:06 +00:00
Vitaly Buka e8b09195fa [compiler-rt] Don't reset non-default user handler if allow_user_segv_handler is true.
Reviewers: eugenis, kcc

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 304039
2017-05-26 21:51:26 +00:00
Renato Golin 5ade1f1c86 [LSAN-ARM] Marking new test unsupported on ARMHF due to bot failures
The test was meant for Darwin anyway, so I'm not even sure it's supposed
to run on Linux. If it was, then we need time to investigate, but since
the test is new, there's no point in reverting the whole patch because
of it.

llvm-svn: 304010
2017-05-26 17:31:33 +00:00
Kostya Kortchinsky db18e4d993 [scudo] Check the return values of the pthread_* functions
Summary:
Currently we are not enforcing the success of `pthread_once`, and
`pthread_setspecific`. Errors could lead to harder to debug issues later in
the thread's life. This adds checks for a 0 return value for both.
If `pthread_setspecific` fails in the teardown path, opt for an immediate
teardown as opposed to a fatal failure.

Reviewers: alekseyshl, kcc

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 303998
2017-05-26 15:39:22 +00:00
Alex Shlyapnikov 23ff882e45 [asan] Enable back some ASan tests disabled on PowerPC.
Summary:
D33521 addressed a memory ordering issue in BlockingMutex, which seems
to be the cause of a flakiness of a few ASan tests on PowerPC.

Reviewers: eugenis

Subscribers: kubamracek, nemanjai, llvm-commits

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

llvm-svn: 303995
2017-05-26 14:49:42 +00:00
Vitaly Buka a05da1fca9 [compiler-rt] Replace allow_user_segv_handler=0 with kHandleSignalExclusive
Summary:
allow_user_segv_handler had confusing name did not allow to control behavior for
signals separately.

Reviewers: eugenis, alekseyshl, kcc

Subscribers: llvm-commits, dberris, kubamracek

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

llvm-svn: 303941
2017-05-25 23:42:33 +00:00
Kostya Serebryany f3509b6d9b [asan] relax sanbox_read_proc_self_maps_test to pass even if unshare() fails.
llvm-svn: 303911
2017-05-25 20:50:36 +00:00
Francis Ricci 3bfbd70840 Fix typo in tls patch
llvm-svn: 303906
2017-05-25 19:55:44 +00:00
Vitaly Buka 40d54d408b [compiler-rt] Make print_module_map description consistent with the rest.
Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303892
2017-05-25 18:07:48 +00:00
Francis Ricci 86e070f7e9 Implement tls scanning for darwin LSan
Summary:
This required for any users who call exit() after creating
thread-specific data, as tls destructors are only called when
pthread_exit() or pthread_cancel() are used. This should also
match tls behavior on linux.

Getting the base address of the tls section is straightforward,
as it's stored as a section offset in %gs. The size is a bit trickier
to work out, as there doesn't appear to be any official documentation
or source code referring to it. The size used in this patch was determined
by taking the difference between the base address and the address of the
subsequent memory region returned by vm_region_recurse_64, which was
1024 * sizeof(uptr) on all threads except the main thread, where it was
larger. Since the section must be the same size on all of the threads,
1024 * sizeof(uptr) seemed to be a reasonable size to use, barring
a more programtic way to get the size.

1024 seems like a reasonable number, given that PTHREAD_KEYS_MAX
is 512 on darwin, so pthread keys will fit inside the region while
leaving space for other tls data. A larger size would overflow the
memory region returned by vm_region_recurse_64, and a smaller size
wouldn't leave room for all the pthread keys. In addition, the
stress test added here passes, which means that we are scanning at
least the full set of possible pthread keys, and probably
the full tls section.

Reviewers: alekseyshl, kubamracek

Subscribers: krytarowski, llvm-commits

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

llvm-svn: 303887
2017-05-25 17:41:13 +00:00
Francis Ricci 75ca300f2b Don't require ThreadState to be contained within tls on all platforms
The existing implementation ran CHECKs to assert that the thread state
was stored inside the tls. However, the mac implementation of tsan doesn't
store the thread state in tls, so these checks fail once darwin tls support
is added to the sanitizers. Only run these checks on platforms where
the thread state is expected to be contained in the tls.

llvm-svn: 303886
2017-05-25 17:41:10 +00:00
Adam Nemet 14205b4a76 Disable two more flaky ASan wait* tests temporarily on Darwin
llvm-svn: 303885
2017-05-25 17:24:54 +00:00
Kostya Kortchinsky 5d0ecbc8d9 [sanitizer] Revert rL303879 as it breaks Windows
Summary:
Apparently Windows's `UnmapOrDie` doesn't support partial unmapping. Which
makes the new region allocation technique not Windows compliant.

Reviewers: alekseyshl, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303883
2017-05-25 16:54:44 +00:00
Kostya Kortchinsky 0dd40cf28d [sanitizer] Change the 32-bit Primary AllocateRegion to reduce fragmentation
Summary:
Currently, AllocateRegion has a tendency to fragment memory: it allocates
`2*kRegionSize`, and if the memory is aligned, will unmap `kRegionSize` bytes,
thus creating a hole, which can't itself be reused for another region. This
is exacerbated by the fact that if 2 regions get allocated one after another
without any `mmap` in between, the second will be aligned due to mappings 
generally being contiguous.

An idea, suggested by @alekseyshl, to prevent such a behavior is to have a
stash of regions: if the `2*kRegionSize` allocation is properly aligned, split
it in two, and stash the second part to be returned next time a region is
requested.

At this point, I thought about a couple of ways to implement this:
 - either an `IntrusiveList` of regions candidates, storing `next` at the
   begining of the region;
 - a small array of regions candidates existing in the Primary.

While the second option is more constrained in terms of size, it offers several
advantages:
 - security wise, a pointer in a region candidate could be overflowed into, and
   abused when popping an element;
 - we do not dirty the first page of the region by storing something in it;
 - unless several threads request regions simultaneously from different size
   classes, the stash rarely goes above 1 entry.

I am not certain about the Windows impact of this change, as `sanitizer_win.cc`
has its own version of MmapAlignedOrDie, maybe someone could chime in on this.

MmapAlignedOrDie is effectively unused after this change and could be removed
at a later point. I didn't notice any sizeable performance gain, even though we
are saving a few `mmap`/`munmap` syscalls.

Reviewers: alekseyshl, kcc, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303879
2017-05-25 16:19:57 +00:00
Alex Shlyapnikov 3ea9499e75 [sanitizer] Pair atomic acquire with release in BlockingMutex::Unlock
Summary:
Dmitry, seeking your expertise. I believe, the proper way to implement
Lock/Unlock here would be to use acquire/release semantics. Am I missing
something?

Reviewers: dvyukov

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303869
2017-05-25 15:07:07 +00:00
Dimitry Andric 8779ea7aed Add generic __bswap[ds]i2 implementations
Summary:
In FreeBSD we needed to add generic implementations for `__bswapdi2` and
`__bswapsi2`, since gcc 6.x for mips is emitting calls to these.  See:

https://reviews.freebsd.org/D10838 and https://reviews.freebsd.org/rS318601

The actual mips code generated for these generic C versions is pretty
OK, as can be seen in the (FreeBSD) review.

I checked over gcc sources, and it seems that it can emit these calls on
more architectures, so maybe it's best to simply always add them to the
compiler-rt builtins library.

Reviewers: howard.hinnant, compnerd, petarj, emaste

Reviewed By: compnerd, emaste

Subscribers: mgorny, llvm-commits, arichardson

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

llvm-svn: 303866
2017-05-25 14:52:14 +00:00
Catherine Moore b9f969d9e0 [cmake] Disable building emutls.c for baremetal targets.
Differential Revision: https://reviews.llvm.org/D33199

llvm-svn: 303865
2017-05-25 14:45:54 +00:00
Bill Seurer ec372bd8ed [powerpc] deactivate flakey test halt_on_error-torture.cc on powerpc64 be
This test case occassionally fails when run on powerpc64 be.

asan/TestCases/Posix/halt_on_error-torture.cc

The failure causes false problem reports to be sent to developers whose
code had nothing to do with the failures.  Reactivate it when the real
problem is 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: 303864
2017-05-25 14:41:58 +00:00
Bill Seurer 37c9be9393 [PowerPC] Fix test case sem_init_glibc.cc for powerpc64be
This test case fails on powerpc64be with older glibcs because of the glibc
version test.

llvm-svn: 303863
2017-05-25 14:32:22 +00:00
Vitaly Buka 4974f108ac [compiler-rt] Change default of allow_user_segv_handler to true
Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 303842
2017-05-25 06:29:30 +00:00
Jonathan Roelofs 3c8f953f61 Allow builds to set COMPILER_RT_OS_DIR differently from CMAKE_SYSTEM_NAME
llvm-svn: 303817
2017-05-24 22:41:49 +00:00
Hans Wennborg 0eec1f0b96 Fix negate-overflow.cpp test on Windows after r303440
lit would interpret the exit code as failuire.

llvm-svn: 303809
2017-05-24 21:52:40 +00:00
Vitaly Buka 62882c93c8 Revert "[compiler-rt] Change default of allow_user_segv_handler to true"
Breaks sanitizer-x86_64-linux-fuzzer bot.

This reverts commit r303729.

llvm-svn: 303795
2017-05-24 19:09:24 +00:00
Jonathan Roelofs dc62b80c82 Allow armv{7,7s,7k,7m,7em} builds
llvm-svn: 303765
2017-05-24 15:53:24 +00:00
Ulrich Weigand 66f2260837 [sanitizer] [SystemZ] Update CVE-2016-2143 check for Ubuntu 16.04
The Ubuntu 16.04 kernel contains a backport of the CVE check
starting with version 4.4.0-13.  Update FixedCVE_2016_2143.

llvm-svn: 303757
2017-05-24 15:06:33 +00:00
Vitaly Buka 354439a5a1 [compiler-rt] Change default of allow_user_segv_handler to true
Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 303729
2017-05-24 07:21:39 +00:00
Vitaly Buka 9808ff5d6a [asan] Remove allow_user_segv_handler on Windows.
Summary:
This flags is not covered by tests on Windows and looks like it's implemented
incorrectly. Switching its default breaks some tests.

Taking into account that related handle_segv flag is not supported on Windows
it's safer to remove it until we commit to support it.

Reviewers: eugenis, zturner, rnk

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 303728
2017-05-24 07:17:27 +00:00
Adam Nemet 4f4748557e Disable flaky ASan tests temporarily on darwin
llvm-svn: 303662
2017-05-23 17:50:48 +00:00
Dean Michael Berris 36778a54fe [XRay][compiler-rt] Add __xray_remove_customevent_handler(...)
This change adds __xray_remove_customevent_handler(...) to be consistent
with other APIs that add/remove handlers.

llvm-svn: 303526
2017-05-22 03:23:54 +00:00
Vitaly Buka 4eff87c36d Revert "[compiler-rt] Change default of allow_user_segv_handler to true"
Failed libFuzzer tests on Windows.

This reverts commit r303476.

llvm-svn: 303481
2017-05-20 02:09:25 +00:00
Vitaly Buka 99534e8040 [compiler-rt] Change default of allow_user_segv_handler to true
Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 303476
2017-05-20 01:04:59 +00:00
Vitaly Buka 8018780d39 [compiler-rt] Switch handle_<signal> flags from bool to enum.
Summary: We are going to make it tri-state and remove allow_user_segv_handler.

Reviewers: eugenis, alekseys, kcc

Subscribers: kubamracek, dberris, llvm-commits

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

llvm-svn: 303464
2017-05-19 22:37:16 +00:00
Vitaly Buka 5934882576 [compiler-rt] Add negative test for boolean flags.
Reviewers: eugenis, alekseyshl

Subscribers: kubamracek, dberris, llvm-commits

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

llvm-svn: 303462
2017-05-19 22:37:13 +00:00
Francis Ricci dd592ff467 Use write instead of read permissions to check for global sections on mac
Summary:
The LINKEDIT section is very large and is read-only. Scanning this
section caused LSan on darwin to be very slow. When only writable sections
are scanned for global pointers, performance improved by a factor of about 25x.

Reviewers: alekseyshl, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 303422
2017-05-19 13:34:02 +00:00
Vitaly Buka 1cfc81f1de [compiler-rt] Replace ifs with switch statement in IsHandledDeadlySignal
Reviewers: eugenis

Subscribers: kubamracek, llvm-commits, dberris

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

llvm-svn: 303392
2017-05-18 23:13:22 +00:00
Kostya Kortchinsky 432b8dd8ad [scudo] lower quarantine default sizes
Summary:
After discussing the current defaults with a couple of parties, the consensus
is that they are too high. 1Mb of quarantine has about a 4Mb impact on PSS, so
memory usage goes up quickly.
This is obviously configurable, but the default value should be more
"approachable", so both the global size and the thread local size are 1/4 of
what they used to be.

Reviewers: alekseyshl, kcc

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 303380
2017-05-18 20:47:35 +00:00
Simon Dardis 657899bad1 [compiler-rt][cmake] Build unit tests conditionally with _FILE_OFFSET_BITS=64 and _LARGEFILE_SOURCE
The sanitizer library unit tests for libc can get a different definition
of 'struct stat' to what the sanitizer library is built with for certain
targets.

For MIPS the size element of 'struct stat' is after a macro guarded
explicit padding element.

This patch resolves any possible inconsistency by adding the same
_FILE_OFFSET_BITS=64 and _LARGE_SOURCE with the same
conditions as the sanitizer library to the build flags for the unit tests.

This resolves a recurring build failure on the MIPS buildbots due to
'struct stat' defintion differences.

Reviewers: slthakur

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

llvm-svn: 303350
2017-05-18 13:19:35 +00:00
Daniel Jasper f97310fb7a Revert r302781 and subsequent attempts to disable part of it.
The Msan unit tests are still broken and by this point, I think we
should start over.

llvm-svn: 303339
2017-05-18 09:31:37 +00:00
Diana Picus 44514860f4 Fixup r303324 - temporary disable stndup interceptor, due to r302781 being buggy
r303324 missed one of the tests added by r302781. This commit applies
the same fix as r303324 to the missed test (strndup.cc).

llvm-svn: 303338
2017-05-18 09:12:27 +00:00
Kostya Serebryany 9aa8ef8504 temporary disable stndup interceptor, due to r302781 being buggy
llvm-svn: 303324
2017-05-18 03:00:07 +00:00
Tim Shen af3ffcc1f8 [XRay] Fix __xray_function_address on PPC reguarding local entry points.
Reviewers: echristo, dberris

Subscribers: llvm-commits

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

llvm-svn: 303302
2017-05-17 21:20:00 +00:00
Leo Li f084f6d7d1 [Ubsan]Remove unused link libraries.
Summary: Remove unused link libraries metioned in D33216.

Reviewers: llvm-commits, vsk

Reviewed By: vsk

Subscribers: vsk, kubamracek, mgorny, filcab

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

llvm-svn: 303286
2017-05-17 19:37:27 +00:00
Leo Li 3f55f7e02d Generate ubsan shared libraries.
Summary: Those libraries are required by aosp (https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/master/Android.mk). Currenly the shared libraries are generated by aosp Makefile system. We are looking forward to using cmake to generate them.

Reviewers: llvm-commits, vsk

Reviewed By: vsk

Subscribers: filcab, vsk, srhines, kubamracek, mgorny, krytarowski

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

llvm-svn: 303276
2017-05-17 17:17:41 +00:00
Hans Wennborg 4035ec59bf Include setjmp.h unconditionally in asan_test_utils.h
It's used in asan_test.cc also on Windows, and my build was failing
with:

C:/src/llvm/projects/compiler-rt/lib/asan/tests/asan_test.cc:549:28: error: unknown type name 'jmp_buf'
NOINLINE void LongJmpFunc1(jmp_buf buf) {
                           ^
C:/src/llvm/projects/compiler-rt/lib/asan/tests/asan_test.cc:569:10: error: unknown type name 'jmp_buf'
  static jmp_buf buf;
         ^

I couldn't find what changed to make this not work anymore, but this should fix
it.

llvm-svn: 303273
2017-05-17 16:44:08 +00:00
Francis Ricci 3b57da0c73 Revert "Implement tls scanning for darwin LSan"
This reverts r303262, due to TSan buildbot breakages.

llvm-svn: 303266
2017-05-17 15:25:41 +00:00
Francis Ricci eab89eb850 Implement tls scanning for darwin LSan
Summary:
This required for any users who call exit() after creating
thread-specific data, as tls destructors are only called when
pthread_exit() or pthread_cancel() are used. This should also
match tls behavior on linux.

Getting the base address of the tls section is straightforward,
as it's stored as a section offset in %gs. The size is a bit trickier
to work out, as there doesn't appear to be any official documentation
or source code referring to it. The size used in this patch was determined
by taking the difference between the base address and the address of the
subsequent memory region returned by vm_region_recurse_64, which was
1024 * sizeof(uptr) on all threads except the main thread, where it was
larger. Since the section must be the same size on all of the threads,
1024 * sizeof(uptr) seemed to be a reasonable size to use, barring
a more programtic way to get the size.

1024 seems like a reasonable number, given that PTHREAD_KEYS_MAX
is 512 on darwin, so pthread keys will fit inside the region while
leaving space for other tls data. A larger size would overflow the
memory region returned by vm_region_recurse_64, and a smaller size
wouldn't leave room for all the pthread keys. In addition, the
stress test added here passes, which means that we are scanning at
least the full set of possible pthread keys, and probably
the full tls section.

Reviewers: alekseyshl, kubamracek

Subscribers: krytarowski, llvm-commits

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

llvm-svn: 303262
2017-05-17 14:35:17 +00:00
Saleem Abdulrasool 4a45838d10 builtins: fix guard __AEABI__ -> __ARM_EABI__
llvm-svn: 303207
2017-05-16 20:25:07 +00:00
Saleem Abdulrasool 92a239b225 builtins: one more case of a missing header
llvm-svn: 303195
2017-05-16 18:19:44 +00:00
Saleem Abdulrasool 369f74c16b builtins: add missing includes
This inclusion is needed to fix the ARM build.  The int_lib.h include is
slightly ugly, but allows us to use the `AEABI_RTABI` macro to decorate
the CC for the functions.

llvm-svn: 303190
2017-05-16 17:06:48 +00:00
Saleem Abdulrasool 36ac5ddff7 builtins: expand out the AEABI function stubs
These actually may change calling conventions.  We cannot simply provide
function aliases as the aliased function may have a different calling
convention.  Provide a forwarding function instead to permit the
compiler to synthesize the calling convention adjustment thunk.

Remove the `ARM_EABI_FNALIAS` macro as that is not safe to use.

Resolves PR33030!

llvm-svn: 303188
2017-05-16 16:41:37 +00:00
Saleem Abdulrasool 44c45717b9 builtins: use reserved spelling (NFC)
llvm-svn: 303138
2017-05-16 04:17:12 +00:00
Vitaly Buka a0a6d59da8 [tsan] Update tsan test for r303084
Tail duplication changed number of pop instruction, but TSAN performance was not
affected.

llvm-svn: 303136
2017-05-16 02:06:15 +00:00
Kostya Serebryany 130fca1882 [asan] make asan under sandboxes more robust
llvm-svn: 303132
2017-05-15 23:37:54 +00:00
Manoj Gupta 2361a394b6 Fix executable stack directive on Linux.
Summary: Use __linux__  to check for Linux and bring back the check for __GNU__.

Reviewers: echristo, krytarowski, compnerd, rengolin

Reviewed By: krytarowski

Subscribers: phosek, llvm-commits, srhines

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

llvm-svn: 303131
2017-05-15 23:13:54 +00:00
Alex Shlyapnikov cbb1fdf350 [lsan] Report the missing linker only when the linker is actually missing.
Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 303129
2017-05-15 23:11:01 +00:00
Manoj Gupta cf0675bb74 [builtins] Fix a check from __GNU__ to __GNUC__ for disabling executable stack.
Summary:
Neither GCC nor Clang define __GNU__. Instead use __GNUC__ for the check.

Reviewers: echristo, rengolin, compnerd

Subscribers: srhines, krytarowski, llvm-commits

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

llvm-svn: 303112
2017-05-15 20:41:17 +00:00
Saleem Abdulrasool 12588d76db builtins: fix filtering aliased targets
Some build targets (e.g. i686) have aliased names (e.g. i386).  We would
get multiple definitions previously and have the linker arbitrarily
select a definition on those aliased targets.  Make this more
deterministic by checking those aliases.

llvm-svn: 303103
2017-05-15 19:09:13 +00:00
Reid Kleckner 886d2e6ef0 [ubsan] Don't enable debug info in all tests
Add a lit substitution (I chose %gmlt) so that only stack trace tests
get debug info.

We need a lit substition so that this expands to -gline-tables-only
-gcodeview on Windows. I think in the future we should reconsider the
need for -gcodeview from the GCC driver, but for now, this is necessary.

llvm-svn: 303083
2017-05-15 17:25:10 +00:00
Kostya Kortchinsky dc646a0889 [sanitizer] Change SizeClassAllocator32 to accept just one template
Summary:
With rL279771, SizeClassAllocator64 was changed to accept only one template
instead of 5, for the following reasons: "First, this will make the mangled
names shorter. Second, this will make adding more parameters simpler". This
patch mirrors that work for SizeClassAllocator32.

This is in preparation for introducing the randomization of chunks in the
32-bit SizeClassAllocator in a later patch.

Reviewers: kcc, alekseyshl, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303071
2017-05-15 14:47:19 +00:00
Eugene Zelenko 12aa9554a6 [XRay] Fix build with libc++ (NFC).
llvm-svn: 302962
2017-05-12 22:26:42 +00:00
Reid Kleckner 999f74ad59 [ubsan] Enable debug info in test binaries
This fixes tests that use debug info to check ubsan stack traces.  One
was XFAILd on Windows and the other was actively failing for weeks.

llvm-svn: 302924
2017-05-12 17:06:16 +00:00
Francis Ricci fb3d1ea063 Disable two failing darwin lsan tests
These tests don't fail consistently in all cases, but they
fail most of the time on the buildbots. Mark as UNSUPPORTED for now to
avoid buildbots failing due to XPASS.

llvm-svn: 302920
2017-05-12 16:52:19 +00:00
Reid Kleckner 07c0dd7654 [asan/win] Re-enable Win64 asan tests on Win8+
Our theory is that reserving large amounts of shadow memory isn't
reliable on Win7 and earlier NT kernels. This affects the
clang-x64-ninja-win7 buildbot, which uses Windows 7.

llvm-svn: 302917
2017-05-12 16:30:56 +00:00
Francis Ricci b680e9742a Disable two failing darwin lsan tests
These are causing buildbot failures, disable for now.

llvm-svn: 302912
2017-05-12 16:01:15 +00:00
Francis Ricci fdcab2cbf2 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: 302904
2017-05-12 15:10:05 +00:00
Francis Ricci 61ed9345c9 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: 302899
2017-05-12 14:10:53 +00:00
Francis Ricci 5d4ad5c7d2 Account for stack redzone when computing sp on darwin
thread_get_register_pointer_values handles the redzone computation
automatically, but is marked as an unavailable API function. This
patch replicates its logic accounting for the stack redzone on
x86_64.

Should fix flakiness in the use_stack_threaded test for lsan on darwin.

llvm-svn: 302898
2017-05-12 14:10:51 +00:00
Alexander Potapenko f06fbd4794 [msan] Remove a failing test from MemorySanitizer.ICmpRelational
This is a follow-up to r302787, which broke MemorySanitizer.ICmpRelational.

MSan is now reporting a false positive on the following test case:
  TestForNotPoisoned((poisoned(-1, 0x80000000U) >= poisoned(-1, 0U)))
, which is sort of anticipated, because we're approximating the comparison
with an OR of the arguments' shadow values.

llvm-svn: 302887
2017-05-12 09:39:32 +00:00
Dean Michael Berris 1cc7504774 [XRay][compiler-rt] Only run custom event logging in x86_64-linux
We only have an implementation in x86_64 that works for the
patching/unpatching and runtime support (trampolines).

Follow-up to D30630.

llvm-svn: 302873
2017-05-12 05:13:11 +00:00
Dean Michael Berris 71086a87b1 [XRay][compiler-rt] Remove unused variable after refactoring
Follow-up to D30630.

llvm-svn: 302861
2017-05-12 01:43:20 +00:00
Dean Michael Berris 724de21662 [XRay][compiler-rt] Fix misspeling of XRaySledEntry
Follow-up to D30630.

llvm-svn: 302860
2017-05-12 01:33:55 +00:00
Dean Michael Berris 29e16deb17 [XRay][compiler-rt] Runtime changes to support custom event logging
Summary:
This change implements support for the custom event logging sleds and
intrinsics at runtime. For now it only supports handling the sleds in
x86_64, with the implementations for other architectures stubbed out to
do nothing.

NOTE: Work in progress, uploaded for exposition/exploration purposes.

Depends on D27503, D30018, and D33032.

Reviewers: echristo, javed.absar, timshen

Subscribers: mehdi_amini, nemanjai, llvm-commits

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

llvm-svn: 302857
2017-05-12 01:07:41 +00:00
Kostya Kortchinsky 01a66fc928 [scudo] Use our own combined allocator
Summary:
The reasoning behind this change is twofold:
- the current combined allocator (sanitizer_allocator_combined.h) implements
  features that are not relevant for Scudo, making some code redundant, and
  some restrictions not pertinent (alignments for example). This forced us to
  do some weird things between the frontend and our secondary to make things
  work;
- we have enough information to be able to know if a chunk will be serviced by
  the Primary or Secondary, allowing us to avoid extraneous calls to functions
  such as `PointerIsMine` or `CanAllocate`.

As a result, the new scudo-specific combined allocator is very straightforward,
and allows us to remove some now unnecessary code both in the frontend and the
secondary. Unused functions have been left in as unimplemented for now.

It turns out to also be a sizeable performance gain (3% faster in some Android
memory_replay benchmarks, doing some more on other platforms).

Reviewers: alekseyshl, kcc, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 302830
2017-05-11 21:40:45 +00:00
Pierre Gousseau 9ce59db426 [asan] Test 'strndup_oob_test.cc' added in r302781 fails on the clang-cmake-thumbv7-a15-full-sh bot.
Marking as unsupported on armv7l-unknown-linux-gnueabihf, same as strdup_oob_test.cc

llvm-svn: 302807
2017-05-11 16:26:50 +00:00
Benjamin Kramer 71ed2e6457 Renumber test line number expectations after r302783.
Also remove a confused stable-runtimes requirement.

llvm-svn: 302801
2017-05-11 14:04:23 +00:00
Pierre Gousseau 24090e59ea [asan] Test 'strndup_oob_test.cc' added in r302781 fails on clang-s390x-linux.
Marking it as unsupported for now to hopefully make the bot green.

llvm-svn: 302789
2017-05-11 11:22:04 +00:00
Alexander Potapenko 65de57150e [msan] add a regression test for PR32842
Make sure MSan doesn't miss a bug comparing two integers with defined low bits.

llvm-svn: 302788
2017-05-11 11:12:26 +00:00
Renato Golin 29006dc724 [MSAN] test failed randomly on ARM when XFAILED for MIPS
llvm-svn: 302786
2017-05-11 11:05:52 +00:00
Simon Dardis 456218438a mips] XFAIL wcsncpy.cc test.
The stack unwinder fails to unwind the stack past the interceptor stack
frame, resulting in a test failure. XFAIL this for now.

llvm-svn: 302783
2017-05-11 09:56:01 +00:00
Pierre Gousseau 0550581070 [asan] Recommit of r301904: Add strndup/__strndup interceptors
Fix undeclared __interceptor_malloc in esan_interceptors.cc
Fix undeclared strnlen on OSX

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

llvm-svn: 302781
2017-05-11 08:53:24 +00:00
Francis Ricci 4cd7a15cea Revert "Add dyld to sanitizer procmaps on darwin"
This breaks several tests because we don't always have
access to __cxa_guard functions

This reverts commit 45eb470c3e9e8f6993a204e247c33d4092237efe.

llvm-svn: 302693
2017-05-10 16:33:46 +00:00
Francis Ricci 48eab42101 Revert "Disable static caching of dyld header on Go sanitizers"
This is a problem on more than just the go sanitizers, so it's
not a good enough fix for the issue.

llvm-svn: 302692
2017-05-10 16:33:43 +00:00
Tim Shen bb6fdd66fc [XRay] Fix XRay PPC return value bug.
Summary:
This bug is caused by the incorrect handling of return-value registers.

According to OpenPOWER 64-Bit ELF V2 ABI 2.2.5, up to 2 general-purpose
registers are going to be used for return values, and up to 8 floating
point registers or vector registers are going to be used for return
values.

Reviewers: dberris, echristo

Subscribers: nemanjai, llvm-commits

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

llvm-svn: 302691
2017-05-10 16:28:21 +00:00
Tim Shen 40c012654e [XRay] Fix the test func-id-utils.cc on PPC.
Summary:
The test fails on PPC, because the address of a function may vary
depending on whether the "taker" shares the same ToC (roughly, in the
same "module") as the function.

Therefore the addresses of the functions taken in func-id-utils.cc may be
different from the addresses taken in xray runtime.

Change the test to be permissive on address comparison.

Reviewers: dberris, echristo

Subscribers: llvm-commits

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

llvm-svn: 302686
2017-05-10 16:07:03 +00:00
Francis Ricci 15dc8c93bc Disable static caching of dyld header on Go sanitizers
This causes buildbot failures due to undefined __cxa_guard_acquire

llvm-svn: 302681
2017-05-10 15:40:29 +00:00
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