Commit Graph

7257 Commits

Author SHA1 Message Date
Kostya Kortchinsky 8d4ba5fd23 [scudo] Allow for non-Android Shared TSD platforms, part 1
Summary:
This first part just prepares the grounds for part 2 and doesn't add any new
functionality. It mostly consists of small refactors:
- move the `pthread.h` include higher as it will be used in the headers;
- use `errno.h` in `scudo_allocator.cpp` instead of the sanitizer one, update
  the `errno` assignments accordingly (otherwise it creates conflicts on some
  platforms due to `pthread.h` including `errno.h`);
- introduce and use `getCurrentTSD` and `setCurrentTSD` for the shared TSD
  model code;

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits, srhines

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

llvm-svn: 315583
2017-10-12 15:01:09 +00:00
Hans Wennborg eb2218ceae Revert r315533 "Reland "[sanitizer] Introduce ReservedAddressRange to sanitizer_common""
The SanitizerCommon.ReservedAddressRangeUnmap test fails on Windows:

FAIL: SanitizerCommon-Unit :: ./Sanitizer-x86_64-Test.exe/SanitizerCommon.ReservedAddressRangeUnmap (34003 of 35554)
******************** TEST 'SanitizerCommon-Unit :: ./Sanitizer-x86_64-Test.exe/SanitizerCommon.ReservedAddressRangeUnmap' FAILED ********************
Note: Google Test filter = SanitizerCommon.ReservedAddressRangeUnmap
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from SanitizerCommon
[ RUN      ] SanitizerCommon.ReservedAddressRangeUnmap
==3780==ERROR: SanitizerTool failed to deallocate 0x1000 (4096) bytes at address 0x0000000c3000 (error code: 487)
==3780==Sanitizer CHECK failed: E:\b\build\slave\win_upload_clang\build\src\third_party\llvm\projects\compiler-rt\lib\sanitizer_common\sanitizer_win.cc:129 (("unable to unmap" && 0)) != (0) (0, 0)
********************
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
Testing Time: 299.76s
********************
Failing Tests (1):
    SanitizerCommon-Unit :: ./Sanitizer-x86_64-Test.exe/SanitizerCommon.ReservedAddressRangeUnmap

> In Fuchsia, MmapNoAccess/MmapFixedOrDie are implemented using a global
> VMAR, which means that MmapNoAccess can only be called once. This works
> for the sanitizer allocator but *not* for the Scudo allocator.
>
> Hence, this changeset introduces a new ReservedAddressRange object to
> serve as the new API for these calls. In this changeset, the object
> still calls into the old Mmap implementations.
>
> The next changeset two changesets will convert the sanitizer and scudo
> allocators to use the new APIs, respectively. (ReservedAddressRange will
> replace the SecondaryHeader in Scudo.)
>
> Finally, a last changeset will update the Fuchsia implementation.
>
> Patch by Julia Hansbrough
>
> Differential Revision: https://reviews.llvm.org/D38437

llvm-svn: 315553
2017-10-12 03:23:31 +00:00
Petr Hosek 4f213ae3a7 Reland "[sanitizer] Introduce ReservedAddressRange to sanitizer_common"
In Fuchsia, MmapNoAccess/MmapFixedOrDie are implemented using a global
VMAR, which means that MmapNoAccess can only be called once. This works
for the sanitizer allocator but *not* for the Scudo allocator.

Hence, this changeset introduces a new ReservedAddressRange object to
serve as the new API for these calls. In this changeset, the object
still calls into the old Mmap implementations.

The next changeset two changesets will convert the sanitizer and scudo
allocators to use the new APIs, respectively. (ReservedAddressRange will
replace the SecondaryHeader in Scudo.)

Finally, a last changeset will update the Fuchsia implementation.

Patch by Julia Hansbrough

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

llvm-svn: 315533
2017-10-11 23:41:32 +00:00
Evgeniy Stepanov 1961c6cb2c Disable TSan tests on Android.
They never passed. This change excludes them from 'check-all'.

llvm-svn: 315512
2017-10-11 21:22:45 +00:00
Kostya Kortchinsky 6a45f9ce82 [sanitizer] Move the errno/ENOMEM allocator checks logic to separate .cc
Summary:
This is a new attempt at D38706, which had 2 issues.

The first one was that it broke TSan, because `sanitizer_errno.h` was not
directly included in `tsan_mman.cc`. This fixes the include.

The second one was that it broke the nolibc build, because `__errno_location`
couldn't be found. This adds the new .cc to the libcdep list instead of the
base one.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: kubamracek, mgorny, llvm-commits

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

llvm-svn: 315509
2017-10-11 21:20:04 +00:00
Craig Topper 705b969f80 [X86] Add Knights Mill CPU to cpu_indicator support to match libgcc.
llvm-svn: 315505
2017-10-11 20:35:43 +00:00
Kostya Serebryany 75480e3871 [libFuzzer] disable use_feature_frequency as it degrades some of the benchmarks too much :(
llvm-svn: 315503
2017-10-11 20:31:01 +00:00
Petr Hosek c530f497b8 Revert "[sanitizer] Introduce ReservedAddressRange to sanitizer_common"
This reverts commit r315493 which is failing to build on sanitizer-windows.

llvm-svn: 315494
2017-10-11 19:29:14 +00:00
Petr Hosek 2bd0123afc [sanitizer] Introduce ReservedAddressRange to sanitizer_common
In Fuchsia, MmapNoAccess/MmapFixedOrDie are implemented using a global
VMAR, which means that MmapNoAccess can only be called once. This works
for the sanitizer allocator but *not* for the Scudo allocator.

Hence, this changeset introduces a new ReservedAddressRange object to
serve as the new API for these calls. In this changeset, the object
still calls into the old Mmap implementations.

The next changeset two changesets will convert the sanitizer and scudo
allocators to use the new APIs, respectively. (ReservedAddressRange will
replace the SecondaryHeader in Scudo.)

Finally, a last changeset will update the Fuchsia implementation.

Patch by Julia Hansbrough

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

llvm-svn: 315493
2017-10-11 19:17:35 +00:00
Kostya Serebryany 198d385a77 [libFuzzer] make -use_feature_frequency less aggressive and enable by default
llvm-svn: 315490
2017-10-11 19:01:35 +00:00
Kostya Serebryany 4083d54675 [libFuzzer] experimental flag to tweak the corpus distribution. Seems to improve the situation dramatically on the png benchmark and make things worse on a number of micro-puzzles. Needs more A/B testing
llvm-svn: 315407
2017-10-11 01:44:26 +00:00
Kostya Kortchinsky ea2f800bbc [sanitizer] Revert D38706
Summary:
D38706 breaks tsan and the nolibc build.
Reverting while working on a fix.

Reviewers: alekseyshl

Subscribers: kubamracek, mgorny, llvm-commits

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

llvm-svn: 315320
2017-10-10 15:35:11 +00:00
Kostya Kortchinsky 03f9e76790 [sanitizer] Move the errno/ENOMEM allocator checks logic to separate .cc
Summary:
The fact that `sanitizer_allocator_checks.h` is including `sanitizer_errno.h`
creates complications for future changes, where it would conflict with `errno.h`
definitions on Android and Fuchsia (macro redefinition).

By moving the portion that sets errno in the checks to a separate compilation
unit, we avoid the inclusion of the header there, which solves the issue.

Not that it is not vital to have that function in a header as it is called as a
result of an unlikely event, and doesn't need to be inlined.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: kubamracek, llvm-commits, mgorny

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

llvm-svn: 315319
2017-10-10 14:58:09 +00:00
Dean Michael Berris 9ba7401a7b [XRay][compiler-rt] Fix rdtscp support check for x86_64
Follow-up to D29438.

llvm-svn: 315306
2017-10-10 12:44:20 +00:00
Petr Hosek 1c0c35d034 [sanitizer] Don't intercept signal and sigaction on Fuchsia
Fuchsia doesn't support signals, so don't use interceptors for signal or
sigaction.

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

llvm-svn: 315227
2017-10-09 18:29:52 +00:00
Vlad Tsyrklevich a0b02833bc Limit CFI blacklist entries to specific CFI mode
Summary:
Since D37924 and D37925 were merged, it's now possible to specify
individual sanitizers or CFI modes in sanitizer blacklists. Update the
CFI blacklist entries to only apply to cfi-unrelated-cast checks.

Reviewers: eugenis, pcc

Reviewed By: eugenis

Subscribers: kcc

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

llvm-svn: 315216
2017-10-09 17:11:44 +00:00
Peter Collingbourne 107a9f624d Make the cfi target available on more platforms.
On non-Linux targets it just installs the blacklist.

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

llvm-svn: 315215
2017-10-09 17:07:47 +00:00
Vedant Kumar 16d41609ab Use list(APPEND) instead of append()
append() seems to be available with the version of cmake I'm using, but
not on the bots:

http://green.lab.llvm.org/green//job/clang-stage1-configure-RA/39354

llvm-svn: 315144
2017-10-07 03:44:46 +00:00
Vedant Kumar 074a997b13 [ubsan] Add a static runtime on Darwin
As a follow-up to r315142, this makes it possible to use ubsan with a
static runtime on Darwin. I've also added a new StandaloneStatic testing
configuration so the new setup can be tested.

llvm-svn: 315143
2017-10-07 01:46:36 +00:00
Evgeniy Stepanov 729bcd1f6e [asan] Disable wcslen test on 32-bit Android.
llvm-svn: 315132
2017-10-07 00:04:24 +00:00
Alex Shlyapnikov 84d16165d4 Revert "[LSan] Detect dynamic loader by its base address."
This reverts commit r315024.

Breaks sysconf_interceptor_bypass_test.cc

llvm-svn: 315031
2017-10-05 22:53:17 +00:00
Max Moroz 330496c3fc [libFuzzer] Disable experimental clang coverage support by default.
Summary:
It can be enabled via "-use_clang_coverage=1" flag. Reason for disabling:
libFuzzer resets Clang Counters and makes it impossible to generate coverage
report for a regular fuzz target (i.e. not standalone build).

Reviewers: kcc

Reviewed By: kcc

Subscribers: kcc

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

llvm-svn: 315029
2017-10-05 22:41:03 +00:00
Alex Shlyapnikov 44f9376347 [LSan] Detect dynamic loader by its base address.
Summary:
Relanding D33859, which was reverted because it has "broken LOTS of
ARM/AArch64 bots for two days".

If it breaks something again, please provide some pointers to broken
bots, not just revert it, otherwise it's very hard to reason what's
wrong with this commit.

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: aemerson, kubamracek, kristof.beyls, llvm-commits

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

llvm-svn: 315024
2017-10-05 21:38:33 +00:00
Dean Michael Berris 8dcba551d9 [XRay][compiler-rt] Write out arg1 payload in naive mode logging
Summary:
This change allows the XRay basic (naive) mode logging implementation to
start writing the payload entries through the arg1 logging handler. This
implementation writes out the records that the llvm-xray tool and the
trace reader library will start processing in D38550.

This introduces a new payload record type which logs the data through
the in-memory buffer. It uses the same size/alignment that the normal
XRay record entries use. We use a new record type to indicate these new
entries, so that the trace reader library in LLVM can start reading
these entries.

Depends on D38550.

Reviewers: pelikan

Subscribers: llvm-commits

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

llvm-svn: 314968
2017-10-05 05:45:51 +00:00
Evgeniy Stepanov 928bc08247 [sanitizer] Move cxx-abi library earlier in link flags.
Summary:
This change moves cxx-abi library in asan/ubsan/dd link command line
ahead of other libraries, such as pthread/rt/dl/c/gcc. Given that
cxx-abi may be the full libstdc++/libc++, it makes sense for it to be
ahead of libc and libgcc, at least.

The real motivation is Android, where in the arm32 NDK toolchain
libstdc++.a is actually a linker script that tries to sneak LLVM's
libunwind ahead of libgcc's. Wrong library order breaks unwinding.

Reviewers: srhines, danalbert

Subscribers: aemerson, kubamracek, mgorny, kristof.beyls, llvm-commits

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

llvm-svn: 314948
2017-10-04 23:35:14 +00:00
Dean Michael Berris f279d9b409 [XRay][compiler-rt] Fix logical failure in BufferQueue::getBuffer()
Follow-up to D38119.

llvm-svn: 314878
2017-10-04 06:02:12 +00:00
Dean Michael Berris d06e917b9e [XRay][compiler-rt] Use a hand-written circular buffer in BufferQueue
Summary:
This change removes the dependency on using a std::deque<...> for the
storage of the buffers in the buffer queue. We instead implement a
fixed-size circular buffer that's resilient to exhaustion, and preserves
the semantics of the BufferQueue.

We're moving away from using std::deque<...> for two reasons:

  - We want to remove dependencies on the STL for data structures.

  - We want the data structure we use to not require re-allocation in
    the normal course of operation.

The internal implementation of the buffer queue uses heap-allocated
arrays that are initialized once when the BufferQueue is created, and
re-uses slots in the buffer array as buffers are returned in order.

We also change the lock used in the implementation to a spinlock
instead of a blocking mutex. We reason that since the release operations
now take very little time in the critical section, that a spinlock would
be appropriate.

This change is related to D38073.

This change is a re-submit with the following changes:

  - Keeping track of the live buffers with a counter independent of the
    pointers keeping track of the extents of the circular buffer.

  - Additional documentation of what the data members are meant to
    represent.

Reviewers: dblaikie, kpw, pelikan

Subscribers: llvm-commits

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

llvm-svn: 314877
2017-10-04 05:20:13 +00:00
Martin Pelikan 68ea360ed1 [XRay] [compiler-rt] make sure single threaded programs get traced too
Summary:
When the XRay user calls the API to finish writing the log, the thread
which is calling the API still hasn't finished and therefore won't get
its trace written.  Add a test for only the main thread to check this.

Reviewers: dberris

Subscribers: llvm-commits

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

llvm-svn: 314875
2017-10-04 05:12:00 +00:00
Eli Friedman 0d586d06a7 [compiler-rt] Add back ARM EABI aliases where legal.
r303188 removed all the uses of aliases for EABI functions from
compiler-rt, because some of them had mismatched calling conventions.
Obviously, we can't use aliases for functions which don't have the same
calling convention, but that's only an issue for floating-point
functions with the hardfloat ABI.  In other cases, the stubs increase
size and reduce performance for no benefit.

This patch adds back the aliases, with appropriate checks to make sure
they're only used in cases where the calling convention matches.

llvm-svn: 314851
2017-10-03 21:25:07 +00:00
Dean Michael Berris 11415ac44e Revert "[XRay][compiler-rt] Use a hand-written circular buffer in BufferQueue"
This reverts r314766 (rL314766). Unit tests fail in multiple bots.

llvm-svn: 314786
2017-10-03 11:40:54 +00:00
Dean Michael Berris a1b8e0352f [XRay][compiler-rt] Use a hand-written circular buffer in BufferQueue
Summary:
This change removes the dependency on using a std::deque<...> for the
storage of the buffers in the buffer queue. We instead implement a
fixed-size circular buffer that's resilient to exhaustion, and preserves
the semantics of the BufferQueue.

We're moving away from using std::deque<...> for two reasons:

  - We want to remove dependencies on the STL for data structures.

  - We want the data structure we use to not require re-allocation in
    the normal course of operation.

The internal implementation of the buffer queue uses heap-allocated
arrays that are initialized once when the BufferQueue is created, and
re-uses slots in the buffer array as buffers are returned in order.

We also change the lock used in the implementation to a spinlock
instead of a blocking mutex. We reason that since the release operations
now take very little time in the critical section, that a spinlock would
be appropriate.

This change is related to D38073.

Reviewers: dblaikie, kpw, pelikan

Subscribers: llvm-commits

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

llvm-svn: 314766
2017-10-03 06:15:34 +00:00
Dean Michael Berris 4204464c76 fixup: use UNUSED, restore alignment for cache-line friendliness, and report on errors found when pthread_create_key fails
llvm-svn: 314765
2017-10-03 06:11:20 +00:00
Dean Michael Berris 1dbf45dc27 [XRay][compiler-rt] Use pthread for initializing thread-local data
Summary:
We avoid using C++11's thread_local keyword on non-trivially
destructible objects because it may introduce deadlocks when the C++
runtime registers destructors calling std::malloc(...). The deadlock may
happen when the allocator implementation is itself XRay instrumented.

To avoid having to call malloc(...) and free(...) in particular, we use
pthread_once, pthread_create_key, and pthread_setspecific to instead
manually register the cleanup implementation we want.

The code this replaces used an RAII type that implements the cleanup
functionality in the destructor, that was then initialized as a
function-local thread_local object. While it works in usual situations,
unfortunately it breaks when using a malloc implementation that itself
is XRay-instrumented.

Reviewers: dblaikie, kpw, pelikan

Subscribers: llvm-commits

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

llvm-svn: 314764
2017-10-03 06:11:13 +00:00
Manoj Gupta e2ff2ba57d [builtins] ARM: Reland fix for assembling builtins in thumb state.
Summary:
clang does not assemble files in thumb mode unless .thumb declaration
is present. Add .thumb/.arm decl to _FUNCTION macros to ensure 	that
files are assembled correctly.

Also add a fix to ensure that armv7k-watchos can assemble the
aeabi_c{f|d}cmp.S files.

Fixes PR 34715.

Reviewers: compnerd, peter.smith, srhines, weimingz, rengolin, efriedma, t.p.northover, fjricci

Reviewed By: compnerd

Subscribers: aemerson, javed.absar, llvm-commits, kristof.beyls

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

llvm-svn: 314718
2017-10-02 20:56:49 +00:00
Francis Ricci daf210f7b6 Add support for custom loaders to the sanitizer symbolizer
Summary:
Adds a fallback mode to procmaps when the symbolizer
fails to locate a module for a given address by using
dl_iterate_phdr.

Reviewers: kubamracek, rnk, vitalybuka, eugenis

Reviewed By: eugenis

Subscribers: srhines, llvm-commits

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

llvm-svn: 314713
2017-10-02 20:22:16 +00:00
Francis Ricci b7055bb813 Revert "Add support for custom loaders to the sanitizer symbolizer"
This reverts commit r314671, which hangs on the gcc sanitizer buildbot.

llvm-svn: 314684
2017-10-02 15:55:11 +00:00
Francis Ricci e2aa5b2ace Add support for custom loaders to the sanitizer symbolizer
Summary:
Adds a fallback mode to procmaps when the symbolizer
fails to locate a module for a given address by using
dl_iterate_phdr.

Reviewers: kubamracek, rnk, vitalybuka, eugenis

Reviewed By: eugenis

Subscribers: srhines, llvm-commits

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

llvm-svn: 314671
2017-10-02 14:30:58 +00:00
Michal Gorny 806b8d56a2 [cmake] Add a separate CMake var to control profile runtime
Make it possible to control building profile runtime separately from
other options. Before r313549, the profile runtime building was
controlled along with sanitizers. However, since that commit it is built
unconditionally which results in multiple builds for people building
different runtimes separately.

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

llvm-svn: 314646
2017-10-02 05:03:55 +00:00
Francis Ricci 345187338e Move LoadedModule list to a NoCtor vector and initialize on demand.
Unreverting this patch because llvm-clang-lld-x86_64-debian-fast started
passing again before the revert hit. Must've been just a flake.

llvm-svn: 314556
2017-09-29 20:55:06 +00:00
Francis Ricci 74c93de659 Revert "Move LoadedModule list to a NoCtor vector and initialize on demand."
I think this may have introduced a failure on
llvm-clang-lld-x86_64-debian-fast

This reverts commit r314533

llvm-svn: 314552
2017-09-29 20:04:29 +00:00
Francis Ricci 113708b7cb Move LoadedModule list to a NoCtor vector and initialize on demand.
llvm-svn: 314533
2017-09-29 16:47:02 +00:00
Francis Ricci 8fb270c691 Add missing header definition
llvm-svn: 314521
2017-09-29 15:17:23 +00:00
Francis Ricci c48e9487a5 Remove recursion from FindModuleForAddress. NFC.
llvm-svn: 314520
2017-09-29 15:14:31 +00:00
Francis Ricci 5207630d7e Refactor android fallback procmaps init. NFC.
llvm-svn: 314518
2017-09-29 15:06:47 +00:00
Dean Michael Berris fc064af181 [XRay][compiler-rt][NFC] Remove loggingInitialized() convenience function
The function was introduced as a convenience that used to be called in
multiple places. Recent refactorings have removed the need to call this
function in multiple places, so inlined the implementation in the single
place it's defined.

Broken out from D38119.

llvm-svn: 314489
2017-09-29 04:28:11 +00:00
Francis Ricci 052ec5f92a Revert "Add support for custom loaders to the sanitizer symbolizer"
This causes the gcc sanitizer buildbot to timeout.

This reverts commit 81f388fe570e5b6460dd5bc9b9a36b72714eeb68.

llvm-svn: 314453
2017-09-28 19:37:17 +00:00
Evgeniy Stepanov a41b578635 [asan] Fix the bug number in the error message.
The link in the "Shadow memory range interleaves with an existing
memory mapping" error message was pointing to the wrong bug.

llvm-svn: 314441
2017-09-28 18:19:44 +00:00
Francis Ricci b9a32d470a Add support for custom loaders to the sanitizer symbolizer
Summary:
Adds a fallback mode to procmaps when the symbolizer
fails to locate a module for a given address by using
dl_iterate_phdr.

Reviewers: kubamracek, rnk, vitalybuka, eugenis

Reviewed By: eugenis

Subscribers: srhines, llvm-commits

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

llvm-svn: 314431
2017-09-28 16:58:35 +00:00
Benjamin Kramer c4e652f3aa [asan] Unpoison global metadata on dlclose.
dlclose itself might touch it, so better return it to the state it was
before. I don't know how to create a test for this as it would require
chaning dlclose itself.

llvm-svn: 314415
2017-09-28 13:38:58 +00:00
Dmitry Vyukov 47ad1ef2db tsan: handle signals in pause call
llvm-svn: 314384
2017-09-28 07:32:00 +00:00