Commit Graph

10837 Commits

Author SHA1 Message Date
Kostya Serebryany 1e2ec57803 [hwasan] properly report heap-buffer-overflow
llvm-svn: 341159
2018-08-31 03:18:31 +00:00
Kostya Serebryany e775a3ee42 [hwasan] fix the build on Linux Ubuntu 14.04. We don't need __hwasan_shadow on Linux at all
llvm-svn: 341158
2018-08-31 02:38:23 +00:00
Kostya Serebryany f8be3fa5b6 [hwasan] make malloc(0) return nullptr, add basic address description for stack addresses
llvm-svn: 341156
2018-08-31 01:38:00 +00:00
Kostya Serebryany 347b989cef [hwasan] fix the linux-only pthread_create interceptor and reinstate the two threaded tests
llvm-svn: 341143
2018-08-30 23:22:26 +00:00
Kostya Serebryany e6507f02a0 [hwasan] use thread-local ring buffers to properly report heap-use-after-free
llvm-svn: 341133
2018-08-30 22:11:56 +00:00
Kostya Serebryany 8f0f36b83f [hwasan] temporarily remove two tests to silence the bots
llvm-svn: 341129
2018-08-30 22:07:09 +00:00
Kostya Serebryany c359d9b8fa [hwasan] simplify the thread hangling: instead of the ThreadRegistry (too heavy) simply maintain a linked list of Threads
llvm-svn: 341111
2018-08-30 20:15:39 +00:00
David Carlier bdab89b228 [Xray] Darwin fix variable typo
llvm-svn: 341090
2018-08-30 18:12:47 +00:00
Matt Morehouse 7e042bb1d1 [libFuzzer] Port to Windows
Summary:
Port libFuzzer to windows-msvc.
This patch allows libFuzzer targets to be built and run on Windows, using -fsanitize=fuzzer and/or fsanitize=fuzzer-no-link. It allows these forms of coverage instrumentation to work on Windows as well.
It does not fix all issues, such as those with -fsanitize-coverage=stack-depth, which is not usable on Windows as of this patch.
It also does not fix any libFuzzer integration tests. Nearly all of them fail to compile, fixing them will come in a later patch, so libFuzzer tests are disabled on Windows until them.

Patch By: metzman

Reviewers: morehouse, rnk

Reviewed By: morehouse, rnk

Subscribers: #sanitizers, delcypher, morehouse, kcc, eraman

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

llvm-svn: 341082
2018-08-30 15:54:44 +00:00
David Carlier e4c372c4a4 [Xray] Darwin improving slightly the support
using sysctl to get the tic frequency data.
still linkage issue for X-ray_init not resolved.

Reviewers: dberris, kubamracek

Reviewed By: dberris

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

llvm-svn: 341019
2018-08-30 05:55:27 +00:00
Petr Hosek 6518929569 [sanitizer] Transition to new _zx_vmar_... calls
Now that all _zx_vmar_... calls have been updated, we can undo the
change made in r337801 and switch over to the new calls.

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

llvm-svn: 341011
2018-08-30 01:27:26 +00:00
Kostya Serebryany a4132df0ee [hwasan] add a simple threaded UAF test, make it work on x86 (need to disable tagging in malloc with inside pthread_create)
llvm-svn: 341007
2018-08-30 00:44:55 +00:00
Kostya Serebryany d0cd2db23b [hwasan] add basic ThreadRegistry plumbing, also rename HwasanThread to Thread
llvm-svn: 341005
2018-08-30 00:13:20 +00:00
Kostya Serebryany a050a8da03 [hwasan] remove even more stale code
llvm-svn: 340989
2018-08-29 22:54:52 +00:00
Kostya Serebryany 87bc568eca [hwasan] remove more stale code
llvm-svn: 340985
2018-08-29 22:47:53 +00:00
Kostya Serebryany 1e4498869d [hwasan] get rid of some macros, remove the fixed shadow mapping
llvm-svn: 340983
2018-08-29 22:42:16 +00:00
Kostya Serebryany 5d26313ce0 [hwasan] formatting change, NFC
llvm-svn: 340980
2018-08-29 22:23:34 +00:00
Kostya Serebryany ab62b59a76 [hwasan] rename some variables and functions for better readability, NFC
llvm-svn: 340979
2018-08-29 22:21:22 +00:00
Max Moroz 8c95b48ba2 [libFuzzer] Remove mutation stats and weighted mutation selection.
Summary:
This was an experimental feature. After evaluating it with:

1) https://github.com/google/fuzzer-test-suite/tree/master/engine-comparison

2) enabling on real world fuzz targets running at ClusterFuzz and OSS-Fuzz

The following conclusions were made:

1) With fuzz targets that have reached a code coverage plateau, the feature does
   not improve libFuzzer's ability to discover new coverage and may actually
   negatively impact it.

2) With fuzz targets that have not yet reached a code coverage plateau, the
   feature might speed up new units discovery in some cases, but it is quite
   rare and hard to confirm with a high level on confidence.

Revert of https://reviews.llvm.org/D48054 and https://reviews.llvm.org/D49621.

Reviewers: metzman, morehouse

Reviewed By: metzman, morehouse

Subscribers: delcypher, #sanitizers, llvm-commits, kcc

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

llvm-svn: 340976
2018-08-29 21:53:15 +00:00
Kostya Serebryany fd48b7d558 [hwasan] simplify the realloc implementation: always allocate/deallocate on realloc. This may slowdown some realloc-heavy code, but at least at this point a want simpler code. Also added a test
llvm-svn: 340973
2018-08-29 21:28:14 +00:00
Kostya Serebryany 51e1a83850 Add a thread-local ring buffer of heap allocations
Summary:
We need this in order to properly report heap-use-after-free,
since we don't have a quarantine.

This is a first part of the code, more like a proof of concept.
But I'd like to commit at as is and proceed with refactoring,
adding a ThreadRegistry, and extending the functionality.

Reviewers: eugenis

Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 340971
2018-08-29 21:07:07 +00:00
Kostya Serebryany d709a36084 [sanitizer] reapply r340884 'Add a RingBuffer class to sanitizer_common', with fixes for Windows
llvm-svn: 340969
2018-08-29 21:00:01 +00:00
Kostya Kortchinsky 65e1bcf2b2 [sanitizer] Revert D50940
Summary:
The previous version of the patch makes some code unable to distinguish
failure to map address 0 and error.
Revert to turn the bots back to green while figuring out a new approach.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 340957
2018-08-29 19:41:28 +00:00
Matt Morehouse cf311cfc20 Revert "[libFuzzer] Port to Windows"
This reverts r340949 due to bot breakage again.

llvm-svn: 340954
2018-08-29 18:40:41 +00:00
Matt Morehouse 245ebd71ef [libFuzzer] Port to Windows
Summary:
Port libFuzzer to windows-msvc.
This patch allows libFuzzer targets to be built and run on Windows, using -fsanitize=fuzzer and/or fsanitize=fuzzer-no-link. It allows these forms of coverage instrumentation to work on Windows as well.
It does not fix all issues, such as those with -fsanitize-coverage=stack-depth, which is not usable on Windows as of this patch.
It also does not fix any libFuzzer integration tests. Nearly all of them fail to compile, fixing them will come in a later patch, so libFuzzer tests are disabled on Windows until them.

Reviewers: morehouse, rnk

Reviewed By: morehouse, rnk

Subscribers: #sanitizers, delcypher, morehouse, kcc, eraman

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

llvm-svn: 340949
2018-08-29 18:08:34 +00:00
Hans Wennborg 61cbae90a5 Revert r340884 "Add a RingBuffer class to sanitizer_common"
The test doesn't pass on Windows, where sizeof(long) == 4 also
on 64-bit, and so it isn't a multiple of sizeof(void*).

This also reverts the follow-up r340886.

> Summary: a constrained RingBuffer optimized for fast push
>
> Reviewers: eugenis
>
> Reviewed By: eugenis
>
> Subscribers: kubamracek, mgorny, delcypher, #sanitizers, llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D51196

llvm-svn: 340924
2018-08-29 12:40:29 +00:00
Kamil Rytarowski d1c1e036ae Introduce new type for inteceptors UINTMAX_T
Summary:
The UINTMAX_T type will be used in new interceptors.

While there, correct the type of strtoumax(3) from INTMAX_T to UINTMAX_T.

Original patch from Yang Zheng.

Reviewers: vitalybuka, kcc, joerg

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, tomsun.0.7, #sanitizers

Tags: #sanitizers

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

llvm-svn: 340907
2018-08-29 09:11:17 +00:00
Kostya Serebryany 67d0488934 [sanitizer] fix a test
llvm-svn: 340886
2018-08-28 23:50:59 +00:00
Kostya Serebryany 66eefee7ed Add a RingBuffer class to sanitizer_common
Summary: a constrained RingBuffer optimized for fast push

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: kubamracek, mgorny, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 340884
2018-08-28 23:32:56 +00:00
Matt Morehouse bab8556f01 Revert "[libFuzzer] Port to Windows"
This reverts commit r340860 due to failing tests.

llvm-svn: 340867
2018-08-28 19:07:24 +00:00
Matt Morehouse c6fff3b6f5 [libFuzzer] Port to Windows
Summary:
Port libFuzzer to windows-msvc.
This patch allows libFuzzer targets to be built and run on Windows, using -fsanitize=fuzzer and/or fsanitize=fuzzer-no-link. It allows these forms of coverage instrumentation to work on Windows as well.
It does not fix all issues, such as those with -fsanitize-coverage=stack-depth, which is not usable on Windows as of this patch.
It also does not fix any libFuzzer integration tests. Nearly all of them fail to compile, fixing them will come in a later patch, so libFuzzer tests are disabled on Windows until them.

Patch By: metzman

Reviewers: morehouse, rnk

Reviewed By: morehouse, rnk

Subscribers: morehouse, kcc, eraman

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

llvm-svn: 340860
2018-08-28 18:34:32 +00:00
Vlad Tsyrklevich 03f89d3c5e SafeStack: Fix thread liveness check on *BSD
Summary:
The Linux/BSD system call interfaces report errors differently, use the
internal_iserror() function to correctly check errors on either.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: delcypher, llvm-commits, #sanitizers, krytarowski, kcc, devnexen

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

llvm-svn: 340856
2018-08-28 18:30:03 +00:00
Dean Michael Berris 6b1e125db9 [XRay][compiler-rt] Remove uses of internal allocator in profiling mode
Summary:
This change removes further cases where the profiling mode
implementation relied on dynamic memory allocation. We're using
thread-local aligned (uninitialized) memory instead, which we initialize
appropriately with placement new.

Addresses llvm.org/PR38577.

Reviewers: eizan, kpw

Subscribers: jfb, llvm-commits

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

llvm-svn: 340814
2018-08-28 10:41:10 +00:00
Dean Michael Berris bb6aa92c31 [XRay][compiler-rt] Stash flags as well in x86_64 trampoline
Summary:
This change saves and restores the full flags register in x86_64 mode.
This makes running instrumented signal handlers safer, and avoids flags
set during the execution of the event handlers from polluting the
instrumented call's flags state.

Reviewers: kpw, eizan, jfb

Subscribers: llvm-commits

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

llvm-svn: 340812
2018-08-28 10:32:50 +00:00
Vitaly Buka dd4c14e4dd [lsan] Check that leak sanitizer works in the forked process
Regression test for PR38698

llvm-svn: 340769
2018-08-27 19:15:05 +00:00
Petr Hosek 118dc299f9 [sanitizer][fuzzer] Transition back to ZX_TIME_INFINITE
Now that all Zircon calls have been transitioned to take time as signed
value, we can transition back to ZX_TIME_INFINITE, undoing the change
made in r337802.

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

llvm-svn: 340764
2018-08-27 17:51:52 +00:00
Vitaly Buka d833acdb5f Revert "[lsan] Do not check for leaks in the forked process"
Users need leak reports in forks.

This reverts commit r334036.

llvm-svn: 340758
2018-08-27 17:26:28 +00:00
Kostya Kortchinsky 9920489a2a [scudo] Replace eraseHeader with compareExchangeHeader for Quarantined chunks
Summary:
The reason for the existence of `eraseHeader` was that it was deemed faster
to null-out a chunk header, effectively making it invalid, rather than marking
it as available, which incurred a checksum computation and a cmpxchg.

A previous use of `eraseHeader` was removed with D50655 due to a race.

Now we remove the second use of it in the Quarantine deallocation path and
replace is with a `compareExchangeHeader`.

The reason for this is that greatly helps debugging some heap bugs as the chunk
header is now valid and the chunk marked available, as opposed to the header
being invalid. Eg: we get an invalid state error, instead of an invalid header
error, which reduces the possibilities. The computational penalty is negligible.

Reviewers: alekseyshl, flowerhack, eugenis

Reviewed By: eugenis

Subscribers: delcypher, jfb, #sanitizers, llvm-commits

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

llvm-svn: 340633
2018-08-24 18:21:32 +00:00
David Carlier 60251a5eb7 [Sanitizer] implementing remaining function under OSX
- GetRandom and GetnumberOfCPUs using sys call for the former.
- enabling unit tests for the other oses.

Reviewers: kubamracek

Reviewed By: kubamracek

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

llvm-svn: 340621
2018-08-24 16:53:06 +00:00
Kostya Serebryany a7c3846a2e [hwasan] implement detection of realloc-after-free
llvm-svn: 340593
2018-08-24 01:44:17 +00:00
Kostya Serebryany c5f98d2ab2 [hwasan] implement detection of double-free (invalid-free)
llvm-svn: 340591
2018-08-24 01:12:26 +00:00
Kuba Mracek 9f690839d6 [sanitizer] Don't call task_for_pid(mach_task_self). NFC.
Calling task_for_pid with mach_task_self is just returning mach_task_self anyway, but it also triggers system warnings (task_for_pid is only supposed to be used by high-privileged executables). NFC.

rdar://problem/39198248

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

llvm-svn: 340587
2018-08-23 22:55:58 +00:00
Kostya Kortchinsky 14b838a1ca [sanitizer] Change Mmap*NoAccess to return nullptr on error
Summary:
`MmapNoAccess` & `MmapFixedNoAccess` return directly the result of
`internal_mmap`, as opposed to other Mmap functions that return nullptr.

This inconsistency leads to some confusion for the callers, as some check for
`~(uptr)0` (`MAP_FAILED`) for failure (while it can fail with `-ENOMEM` for
example).

Two potential solutions: change the callers, or make the functions return
`nullptr` on failure to follow the precedent set by the other functions.
The second option looked more appropriate to me.

Correct the callers that were wrongly checking for `~(uptr)0` or
`MAP_FAILED`.

TODO for follow up CLs:
- There are a couple of `internal_mmap` calls in XRay that check for
  MMAP_FAILED as a result as well (cc: @dberris); they should use
  `internal_iserror`;


Reviewers: eugenis, alekseyshl, dberris, kubamracek

Reviewed By: alekseyshl

Subscribers: kristina, kubamracek, delcypher, #sanitizers, dberris, llvm-commits

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

llvm-svn: 340576
2018-08-23 21:13:39 +00:00
Kostya Serebryany e2efbbe571 [hwasan] make error reporting look more like in asan, print the memory tag around the buggy access, simplify one test
llvm-svn: 340470
2018-08-22 22:55:16 +00:00
Kostya Serebryany bb4cf6e1e1 [hwasan] remove stale data field
llvm-svn: 340442
2018-08-22 19:47:19 +00:00
Kuba Mracek 986f03c2ea [tsan] Adjust setjmp/longjmp handling on Darwin for macOS Mojave
On macOS Mojave, the OS started using the XOR-by-a-secret-key scheme (same as glibc is alread doing) for storing the SP value in setjmp environment. We need to adjust for that to keep supporting setjmp/longjmp on latest Darwin. The patch is basically doing the same what we're already doing for glibc.

rdar://problem/43542596

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

llvm-svn: 340350
2018-08-21 22:35:52 +00:00
Kuba Mracek 22d1a2789a Fixup for r340342: Avoid Block_release'ing the block since we're no longer making a copy.
rdar://problem/42242579

llvm-svn: 340347
2018-08-21 22:03:28 +00:00
Kuba Mracek faef7d034a [tsan] Avoid calling Block_copy in the "sync" GCD interceptors
The synchronous dispatch functions in GCD (dispatch_sync, dispatch_barrier_sync), don't make a copy of the passed block. To maintain binary compatibility, we should avoid doing that as well in TSan, as there's no reason to do that. The synchronous dispatch functions will not return before the block is actually executed.

rdar://problem/42242579

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

llvm-svn: 340342
2018-08-21 21:24:22 +00:00
Vlad Tsyrklevich f6c701054e SafeStack: Use correct unsafe stack sizes
Summary:
When deallocating thread stacks, we use one thread's unsafe stack size
to deallocate another thread's unsafe stack; however, the two sizes may
differ. Record an unsafe stack's size in the thread stack linked list.

Reviewers: pcc, eugenis

Reviewed By: eugenis

Subscribers: delcypher, llvm-commits, #sanitizers, kcc

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

llvm-svn: 340308
2018-08-21 17:29:01 +00:00
Evgeniy Stepanov 4f0e10fff9 [hwasan] Add a (almost) no-interceptor mode.
Summary:
The idea behind this change is to allow sanitization of libc. We are prototyping on Bionic,
but the tool interface will be general enough (or at least generalizable) to support any other libc.

When libc depends on libclang_rt.hwasan, the latter can not interpose libc functions.
In fact, majority of interceptors become unnecessary when libc code is instrumented.

This change gets rid of most hwasan interceptors and provides interface for libc to notify
hwasan about thread creation and destruction events. Some interceptors (pthread_create)
are kept under #ifdef to enable testing with uninstrumented libc. They are expressed in
terms of the new libc interface.

The new cmake switch, COMPILER_RT_HWASAN_WITH_INTERCEPTORS, ON by default, builds testing
version of the library with the aforementioned pthread_create interceptor.
With the OFF setting, the library becomes more of a libc plugin.

Reviewers: vitalybuka, kcc, jfb

Subscribers: srhines, kubamracek, mgorny, jfb, llvm-commits

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

llvm-svn: 340216
2018-08-20 21:49:15 +00:00
Kostya Kortchinsky 7515e75bc2 [sanitizer] Use private futex operations for BlockingMutex
Summary:
Use `FUTEX_PRIVATE_FLAG` in conjunction with the wait & wake operations
employed by `BlockingMutex`. As far as I can tell, the mutexes are
process-private, and there is an actual performance benefit at employing the
private operations. There should be no downside to switching to it.

Reviewers: eugenis, alekseyshl, dvyukov

Reviewed By: dvyukov

Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 340178
2018-08-20 14:57:58 +00:00
Fangrui Song b2f8ba0dec [msan] Remove XFAIL: freebsd from test/msan/tls_reuse.cc
This passes now.

llvm-svn: 340132
2018-08-18 23:25:55 +00:00
Kuba Mracek 2b93dfe0ad [sanitizer] When setting up shadow memory on iOS, fix handling the return value of task_info on older OS versions
task_vm_info is a "revisioned" structure, new OS versions add fields to the end, and compatibility is based on the reported size. On older OS versions, min_address/max_address is not filled back. Let's handle that case. Unfortunately, we can't really write a test (as the failure only happens when on a specific OS version).

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

llvm-svn: 340058
2018-08-17 17:53:14 +00:00
Roman Lebedev 630fa0ee87 [NFC] Some small test updates for Implicit Conversion sanitizer.
Split off from D50251.

llvm-svn: 339996
2018-08-17 07:33:38 +00:00
Dean Michael Berris 21d4a1eec7 [XRay][compiler-rt] Avoid InternalAlloc(...) in Profiling Mode
Summary:
We avoid using dynamic memory allocated with the internal allocator in
the profile collection service used by profiling mode. We use aligned
storage for globals and in-struct storage of objects we dynamically
initialize.

We also remove the dependency on `Vector<...>` which also internally
uses the dynamic allocator in sanitizer_common (InternalAlloc) in favour
of the XRay allocator and segmented array implementation.

This change addresses llvm.org/PR38577.

Reviewers: eizan

Reviewed By: eizan

Subscribers: llvm-commits

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

llvm-svn: 339978
2018-08-17 01:57:42 +00:00
Matt Morehouse be57e8e328 Revert "[libFuzzer] Use std::discrete_distribution for input selection."
This reverts r339973 due to msan.test failing on
sanitizer-x86_64-linux-fuzzer bot.

llvm-svn: 339976
2018-08-17 01:30:27 +00:00
Matt Morehouse 0094d31f5b [libFuzzer] Use std::discrete_distribution for input selection.
Summary:
Since we're casting from double to size_t during input selection, we
really want a discrete distribution over size_t rather than a piecewise
distribution over doubles.

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

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

llvm-svn: 339973
2018-08-17 00:13:22 +00:00
Evgeniy Stepanov 37fb896572 Revert "Revert "[hwasan] Add __hwasan_handle_longjmp.""
This reapplies commit r339935 with the following changes:
* make longjmp test C, not C++, to avoid dependency on libc++/libstdc++
* untag pointer in memset interceptor

x86_64 does not have TBI, so hwasan barely works there. Tests must be carefully
written in a way that does not leak tagged pointer to system libraries.

llvm-svn: 339963
2018-08-16 23:17:14 +00:00
Evgeniy Stepanov 7f9b4af184 Revert "[hwasan] Add __hwasan_handle_longjmp."
This reverts commit 339935 which breaks hwasan tests on x86_64.

llvm-svn: 339957
2018-08-16 22:28:02 +00:00
Evgeniy Stepanov 628e766ca3 [hwasan] Enable Android logging.
Summary: Enable syslog as soon as the shadow is mapped.

Reviewers: vitalybuka, kcc

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 339950
2018-08-16 21:56:04 +00:00
Evgeniy Stepanov 8bb383f1fb [hwasan] Add __hwasan_handle_longjmp.
Summary:
A callback to annotate longjmp-like code.

Unlike __asan_handle_no_return, in hwasan we can not conservatively
"unpoison" the entire thread stack, because there is no such thing as
unpoisoned memory. Pointer and memory tags must always match.

Reviewers: vitalybuka, kcc

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 339935
2018-08-16 20:46:41 +00:00
Evgeniy Stepanov fa9f78553a [hwasan] Add malloc_fill_byte and free_fill_byte flags.
Reviewers: vitalybuka, kcc

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 339932
2018-08-16 20:13:09 +00:00
David Carlier 0a1e2f9f7e [Sanitizer] Fix build openbsd
- The alternative syscall exists only on FreeBSD.
- Adding OpenBSD's equivalent and while at it other
remaining oses ones.

Reviewers: vitalybuka, krytarowsky, hiraditya

Reviewed By: hiraditya

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

llvm-svn: 339886
2018-08-16 15:54:38 +00:00
Dean Michael Berris 560c733815 [XRay][compiler-rt] Remove MAP_NORESERVE from XRay allocations
Summary:
This reverses an earlier decision to allow seg-faulting from the
XRay-allocated memory if it turns out that the system cannot provide
physical memory backing that cannot be swapped in/out on Linux.

This addresses http://llvm.org/PR38588.

Reviewers: eizan

Reviewed By: eizan

Subscribers: llvm-commits

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

llvm-svn: 339869
2018-08-16 12:19:03 +00:00
Peter Collingbourne dfd1c96d97 cfi: Remove blacklist entries for libc++.
These functions have had no-CFI annotations in the source code for
a while now.

llvm-svn: 339800
2018-08-15 18:05:55 +00:00
Evgeniy Stepanov a265a13bbe [hwasan] Add a basic API.
Summary:
Add user tag manipulation functions:
  __hwasan_tag_memory
  __hwasan_tag_pointer
  __hwasan_print_shadow (very simple and ugly, for now)

Reviewers: vitalybuka, kcc

Subscribers: kubamracek, hiraditya, llvm-commits

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

llvm-svn: 339746
2018-08-15 00:39:35 +00:00
Matt Morehouse 0f22fac274 [SanitizerCoverage] Add associated metadata to PC guards.
Summary:
Without this metadata LLD strips unused PC table entries
but won't strip unused guards.  This metadata also seems
to influence the linker to change the ordering in the PC
guard section to match that of the PC table section.

The libFuzzer runtime library depends on the ordering
of the PC table and PC guard sections being the same.  This
is not generally guaranteed, so we may need to redesign
PC tables/guards/counters in the future.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: kcc, hiraditya, llvm-commits

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

llvm-svn: 339733
2018-08-14 22:04:34 +00:00
Vlad Tsyrklevich 05ee22e31d Reland "SafeStack: Delay thread stack clean-up""
This relands commit r339405 (reverted in commit r339408.) The original
revert was due to tests failing on a darwin buildbot; however, after
looking at the affected code more I realized that the Darwin safestack
support has always been broken and disabled it in r339719. This relands
the original commit.

llvm-svn: 339723
2018-08-14 20:28:58 +00:00
Vlad Tsyrklevich a6446223e3 SafeStack: Disable Darwin support
Summary:
Darwin support does not appear to be used as evidenced by the fact that
the pthread interceptors have never worked and there is no support for
other common threading mechanisms like GCD.

Reviewers: pcc, eugenis, kubamracek

Reviewed By: pcc, kubamracek

Subscribers: kubamracek, mgorny, delcypher, llvm-commits, #sanitizers, kcc

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

llvm-svn: 339719
2018-08-14 19:46:16 +00:00
Kostya Kortchinsky 3afc797e42 [scudo] Fix race condition in deallocation path when Quarantine is bypassed
Summary:
There is a race window in the deallocation path when the Quarantine is bypassed.
Initially we would just erase the header of a chunk if we were not to use the
Quarantine, as opposed to using a compare-exchange primitive, to make things
faster.

It turned out to be a poor decision, as 2 threads (or more) could simultaneously
deallocate the same pointer, and if the checks were to done before the header
got erased, this would result in the pointer being added twice (or more) to
distinct thread caches, and eventually be reused.

Winning the race is not trivial but can happen with enough control over the
allocation primitives. The repro added attempts to trigger the bug, with a
moderate success rate, but it should be enough to notice if the bug ever make
its way back into the code.

Since I am changing things in this file, there are 2 smaller changes tagging
along, marking a variable `const`, and improving the Quarantine bypass test at
runtime.

Reviewers: alekseyshl, eugenis, kcc, vitalybuka

Reviewed By: eugenis, vitalybuka

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 339705
2018-08-14 18:34:52 +00:00
Petr Hosek 39f0860743 [CMake] Don't parse target triple except for arch
compiler-rt CMake build currently tries to parse the triple and then
put it back together, but doing so inherently tricky, and doing so
from CMake is just crazy and currently doesn't handle triples that
have more than three components. Fortunatelly, the CMake really only
needs the architecture part, which is typically the first component,
to construct variants for other architectures. This means we can keep
the rest of the triple as is and avoid the parsing altogether.

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

llvm-svn: 339701
2018-08-14 18:01:19 +00:00
Evgeniy Stepanov d8cc7f9f07 [hwasan] Provide __sanitizer_* aliases to allocator functions.
Summary:
Export __sanitizer_malloc, etc as aliases to malloc, etc.
This way users can wrap sanitizer malloc, even in fully static binaries.

Both jemalloc and tcmalloc provide similar aliases (je_* and tc_*).

Reviewers: vitalybuka, kcc

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 339614
2018-08-13 21:07:27 +00:00
Evgeniy Stepanov 753bc5496b [hwasan] Handle missing /proc/self/maps.
Summary:
Don't crash when /proc/self/maps is inaccessible from main thread.
It's not a big deal, really.

Reviewers: vitalybuka, kcc

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 339607
2018-08-13 20:04:48 +00:00
Evgeniy Stepanov c68be8d2d5 [hwasan] Allow optional early shadow setup.
Summary:
Provide __hwasan_shadow_init that can be used to initialize shadow w/o touching libc.
It can be used to bootstrap an unusual case of fully-static executable with
hwasan-instrumented libc, which needs to run hwasan code before it is ready to serve
user calls like madvise().

Reviewers: vitalybuka, kcc

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 339606
2018-08-13 19:57:11 +00:00
Kostya Kortchinsky 15acf26c5d [sanitizer] Remove st(X) from the clobber list in 32-bit x86 atomics
Summary:
When compiling with `WERROR=ON` & a recent clang, having the `st(?)` registers
in the clobber list produces a fatal error (except `st(7)` for some reason):
```
.../sanitizer_common/sanitizer_atomic_clang_x86.h:98:9: error: inline asm clobber list contains reserved registers: ST0, ST1, ST2, ST3, ST4, ST5, ST6 [-Werror,-Winline-asm]
        "movq %1, %%mm0;"  // Use mmx reg for 64-bit atomic moves
        ^
<inline asm>:1:1: note: instantiated into assembly here
        movq 8(%esp), %mm0;movq %mm0, (%esi);emms;
^
.../sanitizer_common/sanitizer_atomic_clang_x86.h:98:9: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour.
        "movq %1, %%mm0;"  // Use mmx reg for 64-bit atomic moves
        ^
<inline asm>:1:1: note: instantiated into assembly here
        movq 8(%esp), %mm0;movq %mm0, (%esi);emms;
^
```
As far as I can tell, they were in there due to the use of the `emms`
instruction, but removing the clobber doesn't appear to have a functional
impact. I am unsure if there is a better way to address this.

Reviewers: eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, delcypher, jfb, llvm-commits, #sanitizers

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

llvm-svn: 339575
2018-08-13 15:01:24 +00:00
Dan Liew 706005486f [CMake] Fix bug in `add_weak_symbols()` function.
Previously the the `weak_symbols.txt` files could be modified and the
build system wouldn't update the link flags automatically. Instead the
developer had to know to reconfigure CMake manually.

This is now fixed by telling CMake that the file being used to
read weak symbols from is a configure-time dependency.

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

llvm-svn: 339559
2018-08-13 12:59:38 +00:00
Evgeniy Stepanov 2339dc2397 [hwasan] Remove liblog dependency.
HWASan will not run on older Android releases where we use
__android_log_write for logging.

This dependency is also harmful in the case when libc itself depends
on hwasan, because it creates a loop of
  libc -> hwasan -> liblog -> libc
which makes liblog vs libc initialization order undetermined.

Without liblog the loop is just
  libc -> hwasan -> libc
and any init order issues can be solved in hwasan.

llvm-svn: 339449
2018-08-10 16:38:57 +00:00
Vlad Tsyrklevich bd85115c6e Revert "SafeStack: Delay thread stack clean-up"
This reverts commit r339405, it's failing on Darwin buildbots because
it doesn't seem to have a tgkill/thr_kill2 interface. It has a
__pthread_kill() syscall, but that relies on having a handle to the
thread's port which is not equivalent to it's tid.

llvm-svn: 339408
2018-08-10 00:36:04 +00:00
Vlad Tsyrklevich a24ecc337f SafeStack: Delay thread stack clean-up
Summary:
glibc can call SafeStack instrumented code even after the last pthread
data destructor has run. Delay cleaning-up unsafe stacks for threads
until the thread is dead by having future threads clean-up prior threads
stacks.

Reviewers: pcc, eugenis

Reviewed By: eugenis

Subscribers: cryptoad, eugenis, kubamracek, delcypher, llvm-commits, #sanitizers, kcc

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

llvm-svn: 339405
2018-08-09 22:56:41 +00:00
Kostya Kortchinsky d2214053a2 [sanitizer] Remove rsp from the clobber list in internal_clone
Summary:
When compiling with WERROR=ON, a new fatal warning started popping up recently
(due to -Werror,-Winline-asm):
```
.../lib/sanitizer_common/sanitizer_linux.cc:1214:24: error: inline asm clobber list contains reserved registers: RSP [-Werror,-Winline-asm]
                       "syscall\n"
                       ^
<inline asm>:1:1: note: instantiated into assembly here
        syscall
^
.../lib/sanitizer_common/sanitizer_linux.cc:1214:24: note: Reserved registers on the clobber list may not be preserved across the asm statement, and clobbering them may lead to undefined behaviour.
                       "syscall\n"
                       ^
<inline asm>:1:1: note: instantiated into assembly here
        syscall
^
```

Removing `rsp` from the clobber list makes the warning go away, and does not
appear to have a functional impact. If there is another way to solve this, let
me know.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis

Subscribers: kubamracek, delcypher, llvm-commits, #sanitizers

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

llvm-svn: 339370
2018-08-09 20:01:11 +00:00
David Carlier 9d03a90f15 Enable getentropy for FreeBSD 12
As for Linux with its getrandom's syscall, giving the possibility to fill buffer with native call for good quality but falling back to /dev/urandom in worst case similarly.

Reviewers: vitalybuka, krytarowski

Reviewed By: vitalybuka

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

llvm-svn: 339318
2018-08-09 08:11:48 +00:00
Petr Hosek eb46c95c3e [CMake] Use normalized Windows target triples
Changes the default Windows target triple returned by
GetHostTriple.cmake from the old environment names (which we wanted to
move away from) to newer, normalized ones. This also requires updating
all tests to use the new systems names in constraints.

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

llvm-svn: 339307
2018-08-09 02:16:18 +00:00
George Karpenkov 67d858d5e4 [libFuzzer] Increase the iteration limit in shrink.test
After https://reviews.llvm.org/D48800, shrink.test started failing on
x86_64h architecture.
Looking into this, the optimization pass is too eager to unroll the loop
on x86_64h, possibly leading to worse coverage data.

Alternative solutions include not unrolling the loop when fuzzing, or
disabling this test on that architecture.

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

llvm-svn: 339303
2018-08-09 00:41:22 +00:00
Alex Lorenz 9693e8baa3 [macOS] stop generating the libclang_rt.10.4.a library for macOS 10.4
The support for macOS 10.4 has been dropped by Xcode 10.

rdar://42876880

llvm-svn: 339277
2018-08-08 17:29:55 +00:00
Max Moroz cd02f3147b [libFuzzer] Optimize handle unstable checks by reducing iterations
Summary:
We only run the 3rd check if 2nd check finds unstable edges. 
3rd UpdateUnstableCounters is now merged with ApplyUnstableCounters to only run 1 iteration.

Patch by Kyungtak Woo (@kevinwkt).

Reviewers: Dor1s, metzman, morehouse

Reviewed By: Dor1s, morehouse

Subscribers: delcypher, #sanitizers, llvm-commits, kcc

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

llvm-svn: 339249
2018-08-08 14:32:46 +00:00
Vedant Kumar 381e9d2386 [Coverage] Ignore 'unused' functions with non-zero execution counts
Frontends emit 'unused' coverage mapping records for functions which are
provably unused in a TU. These unused records contain a single counter
with CounterKind::Zero. However, a function may be unused in one TU and
used in another. When this happens, prefer the records with a full set
of counters instead of arbitrarily picking the first loaded record.

There is no impact on the single-TU case. In the multiple-TU case, this
resolves issues causing a function to appear unused when it's not.

Testing: check-{llvm,clang,compiler-rt}

rdar://42981322

llvm-svn: 339194
2018-08-07 22:25:36 +00:00
Max Moroz e03993e6c7 [libFuzzer] Disable print_unstable_stats.test for aarch64.
Summary:
Follow-up for https://reviews.llvm.org/D50264. Reported by testbots:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/5592

Reviewers: morehouse, kevinwkt, metzman, javed.absar, Dor1s

Reviewed By: Dor1s

Subscribers: kristof.beyls, delcypher, #sanitizers, llvm-commits, kcc

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

llvm-svn: 339143
2018-08-07 14:22:00 +00:00
Max Moroz 84a48271d4 [libFuzzer] Add unstable function printing to print_unstable_stats flag
Summary:
There may be cases in which a user wants to know which part of their code is unstable.
We use ObservedFuncs and UnstableCounters to print at exit which of the ObservedFunctions
are unstable under the -print_unstable_stats flag.

Patch by Kyungtak Woo (@kevinwkt).

Reviewers: Dor1s, metzman, morehouse

Reviewed By: Dor1s, metzman, morehouse

Subscribers: delcypher, #sanitizers, llvm-commits, kcc

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

llvm-svn: 339081
2018-08-06 23:14:13 +00:00
Martin Storsjo d07bd75cb3 [CMake] Allow building builtins standalone out of tree without any llvm-config available
This is the same as libcxxabi/libcxx do.

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

llvm-svn: 338818
2018-08-03 05:50:33 +00:00
Max Moroz 5a9baa330c [libFuzzer] Initial implementation of weighted mutation leveraging during runtime.
Summary:
Added functions that calculate stats while fuzz targets are running and give
mutations weight based on how much new coverage they provide, and choose better
performing mutations more often.

Patch by Kodé Williams (@kodewilliams).

Reviewers: Dor1s, metzman, morehouse

Reviewed By: Dor1s, morehouse

Subscribers: delcypher, kcc, llvm-commits, #sanitizers

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

llvm-svn: 338776
2018-08-02 22:30:03 +00:00
Filipe Cabecinhas 440e96f2f7 Add header guard to asan_report.h
llvm-svn: 338700
2018-08-02 11:05:07 +00:00
Kostya Serebryany cedebd5940 [libFuzzer] use absolute distance in addition to the hamming distance in value profiling; our A/B testing have (somewhat weak) indication that this provides an additional signal for corpus expansion
llvm-svn: 338661
2018-08-02 00:24:49 +00:00
Kostya Serebryany a8d7bcdd71 Fix sizeof(struct pthread) in glibc 2.14.
Summary: Fixes: https://github.com/google/sanitizers/issues/966

Reviewers: kcc

Reviewed By: kcc

Subscribers: kubamracek

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

llvm-svn: 338606
2018-08-01 18:29:51 +00:00
Filipe Cabecinhas e0fcc68a32 Add missing condition
llvm-svn: 338577
2018-08-01 15:30:14 +00:00
Filipe Cabecinhas a0d8359079 Test: Enable exceptions for test that needs it
llvm-svn: 338535
2018-08-01 13:20:38 +00:00
Marco Castelluccio 85ae51ed22 [gcov] Add test which uses fork
Test for https://bugs.llvm.org/show_bug.cgi?id=38180.

llvm-svn: 338500
2018-08-01 09:11:36 +00:00
Matt Davis 89e8af6d96 [compiler-rt] Add a routine to specify the mode used when creating profile dirs.
Summary:
This patch introduces `llvm_profile_set_dir_mode` and `llvm_profile_get_dir_mode` to
the compiler-rt profile API. 

Originally, profile data was placed into a directory that was created with a hard-coded
mode value of 0755 (for non-win32 builds).  In certain cases, it can be helpful to create
directories with a different mode other than 0755.  This patch introduces set/get
routines to allow users to specify a desired mode.  The default remains at 0755.

Reviewers: void, probinson

Reviewed By: probinson

Subscribers: probinson, dberris, cfe-commits

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

llvm-svn: 338456
2018-07-31 23:37:24 +00:00
Marco Castelluccio ae43a27f9c [gcov] Add tests using switch, one with break clauses and one with fallthrough
llvm-svn: 338453
2018-07-31 23:26:50 +00:00
Dean Michael Berris f8d5969943 [XRay][compiler-rt] Update test to use similar structure
This is a follow-up to D50037.

llvm-svn: 338349
2018-07-31 04:47:37 +00:00
Dean Michael Berris 3bd20d4605 [XRay][compiler-rt] Profiling Mode: Include file header in buffers
Summary:
This change provides access to the file header even in the in-memory
buffer processing. This allows in-memory processing of the buffers to
also check the version, and the format, of the profile data.

Reviewers: eizan, kpw

Reviewed By: eizan

Subscribers: llvm-commits

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

llvm-svn: 338347
2018-07-31 04:16:54 +00:00
Reid Kleckner cae1b9fef2 Pacify sanitizer lint script that still does not run on Windows
llvm-svn: 338334
2018-07-31 00:08:26 +00:00
Reid Kleckner a5ed43c1c9 [asan/win] Use SRW locks to fix a race in BlockingMutex
Summary:
Before my change, BlockingMutex used Windows critial sections. Critical
sections can only be initialized by calling InitializeCriticalSection,
dynamically.

The primary sanitizer allocator expects to be able to reinterpret zero
initialized memory as a BlockingMutex and immediately lock it.
RegionInfo contains a mutex, and it placement new is never called for
it. These objects are accessed via:
  RegionInfo *GetRegionInfo(uptr class_id) const {
    DCHECK_LT(class_id, kNumClasses);
    RegionInfo *regions = reinterpret_cast<RegionInfo *>(SpaceEnd());
    return &regions[class_id];
  }
The memory comes from the OS without any other initialization.

For various reasons described in the comments, BlockingMutex::Lock would
check if the object appeared to be zero-initialized, and it would lazily
call the LinkerInitialized constructor to initialize the critical
section. This pattern is obviously racy, and the code had a bunch of
FIXMEs about it.

The best fix here is to use slim reader writer locks, which can start
out zero-initialized. They are available starting in Windows Vista. I
think it's safe to go ahead and use them today.

Reviewers: kcc, vitalybuka

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 338331
2018-07-30 23:32:33 +00:00
Roman Lebedev f07c5a0e9c [NFC] Rename test/ubsan/TestCases/{ImplicitCast => ImplicitConversion}
Just to be consistent with the rest.
I should have done that in the commit itself, but the filepaths
is one thing i forgot to verify :S

llvm-svn: 338307
2018-07-30 21:11:34 +00:00
Roman Lebedev 0c234517fd [compiler-rt] integer-truncation-blacklist.c: XFAIL on android/ios
The Builder sanitizer-x86_64-linux-android is failing
starting with rL338287 / D48959.

It runs the tests via android_compile.py, so i'm not sure this
is actually *this* issue:
  https://code.google.com/p/address-sanitizer/issues/detail?id=316
but this seems oddly similar to the other XFAIL'ed cases...

Right now that seems to be the only failing builder,
so i *think* it makes sense to try to just blacklist it for now.

llvm-svn: 338296
2018-07-30 20:05:24 +00:00
Roman Lebedev eb4a9bc343 [compiler-rt][ubsan] Implicit Conversion Sanitizer - integer truncation - compiler-rt part
Summary:
This is a compiler-rt part.
The clang part is D48958.

See [[ https://bugs.llvm.org/show_bug.cgi?id=21530 | PR21530 ]], https://github.com/google/sanitizers/issues/940.

Reviewers: #sanitizers, samsonov, vsk, rsmith, pcc, eugenis, kcc, filcab

Reviewed By: #sanitizers, vsk, filcab

Subscribers: llvm-commits, eugenis, filcab, kubamracek, dberris, #sanitizers, regehr

Tags: #sanitizers

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

llvm-svn: 338287
2018-07-30 18:58:30 +00:00
Azharuddin Mohammed ec6bdf8d4f [cmake] [ARM] Exclude any VFP builtins if VFP is not supported
Summary:
rL325492 disables FPU features when using soft floating point
(-mfloat-abi=soft), which is used internally when building for arm. This causes
errors with builtins that utililize VFP instructions.

With this change we check if VFP is enabled (by checking if the preprocessor
macro __VFP_FP__ is defined), and exclude such builtins if it is not enabled.

Reviewers: rengolin, samsonov, compnerd, smeenai, javed.absar, peter.smith

Reviewed By: peter.smith

Subscribers: delcypher, peter.smith, mgorny, kristof.beyls, chrib, llvm-commits

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

llvm-svn: 338284
2018-07-30 18:18:59 +00:00
Dean Michael Berris f1ceb0b376 [XRay][compiler-rt] FDR Mode: Use mmap instead of internal allocator
Summary:
This change moves FDR mode to use `internal_mmap(...)` from
sanitizer_common instead of the internal allocator interface. We're
doing this to sidestep the alignment issues we encounter with the
`InternalAlloc(...)` functions returning pointers that have some magic
bytes at the beginning.

XRay copies bytes into the buffer memory, and does not require the magic
bytes tracking the other sanitizers use when allocating/deallocating
buffers.

Reviewers: kpw, eizan

Subscribers: llvm-commits

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

llvm-svn: 338228
2018-07-30 05:56:42 +00:00
Fangrui Song 8c40e40a85 [asan] Fix typo
llvm-svn: 338225
2018-07-30 00:25:16 +00:00
Fangrui Song c0ca8089a2 Fix Asan-i386-calls-Test AddressSanitizer.ShadowGapTest on FreeBSD
0x22000000 happens to be on the left of a heap allocation and the error
message is different (heap-buffer-overflow).
FreeBSD NetBSD have larger SHADOW_OFFSET (0x40000000) but let's try not
using #ifdef here.

llvm-svn: 338208
2018-07-28 23:41:50 +00:00
Jonas Hahnfeld a7c9fe3762 [test] Use printf instead of C++ iostream, NFC.
This test fails with libc++ when built with MemorySanitizer. This
is because we link to an uninstrumented version of the library
so msan detects a nested error when calling std::cout << "...".
This can be easily avoided by using good old printf.

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

llvm-svn: 338053
2018-07-26 18:23:40 +00:00
Dmitry Vyukov 04f97cf2f0 [tsan] Fix gcc pedantic warning
Fix gcc (7.2.0) pedantic warning
warning: extra ‘;’ [-Wpedantic]

Author: jasonl220 (Jason Lovett)
Review: https://reviews.llvm.org/D49817
llvm-svn: 338023
2018-07-26 13:02:54 +00:00
Fangrui Song cb1107ed14 [sanitizer] Include signal.h instead of sys/signal.h
llvm-svn: 338004
2018-07-26 04:50:33 +00:00
Max Moroz f55b8c6e91 [libFuzzer] Disable handle-unstable.test for ARM and delete duplicated test file.
Summary:
This change should fix the failures mentioned in
https://reviews.llvm.org/D49684#1175245

Reviewers: kevinwkt, morehouse, metzman

Reviewed By: kevinwkt, morehouse

Subscribers: kristof.beyls, delcypher, chrib, #sanitizers, llvm-commits, kcc

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

llvm-svn: 337949
2018-07-25 18:34:20 +00:00
Jeremy Morse 63c153edb2 [XRay tests] Don't filter test-critical calls
By default, xray filters events that takes less than 5uS from its log.
In this existing test, should printf complete very quickly this will
lead to test-critical function calls being filtered (i.e. print_parent_tid).
Given that we're not testing the filtering feature, disable it for this
test.

llvm-svn: 337929
2018-07-25 14:48:53 +00:00
David Carlier 62e06ff583 [Asan][Msan] Unit tests Disable some tests for FreeBSD
Reviewers: krytarowski

Reviewed By: krytarowski

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

llvm-svn: 337913
2018-07-25 12:38:23 +00:00
Petr Hosek 47e5fcba57 [profile] Support profiling runtime on Fuchsia
This ports the profiling runtime on Fuchsia and enables the
instrumentation. Unlike on other platforms, Fuchsia doesn't use
files to dump the instrumentation data since on Fuchsia, filesystem
may not be accessible to the instrumented process. We instead use
the data sink to pass the profiling data to the system the same
sanitizer runtimes do.

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

llvm-svn: 337881
2018-07-25 03:01:35 +00:00
Matt Morehouse 5377b5b275 [sanitizer] Update symbolizer test.
llvm-svn: 337872
2018-07-24 23:50:42 +00:00
Max Moroz 8db0befc6d [libFuzzer] Handle unstable edges by disregarding unstable edges
Summary:
Added a new mode within flag -handle_unstable for new unstable handling algorithm that does the following:
    When an edge is shown as unstable, copy to UnstableCounters the value 0.
    During ApplyUnstableCounters we copy back the value 0 to ModuleInline8bitCounters if the edge was unstable.

This way we would be ignoring completely features that were collected through non-determinism.
Unstable hits would be counted as if it never hit.

Reviewers: metzman, Dor1s, kcc, morehouse

Reviewed By: metzman, morehouse

Subscribers: delcypher, llvm-commits, #sanitizers

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

llvm-svn: 337853
2018-07-24 21:02:44 +00:00
Kuba Mracek dc36389ea8 [tsan] Fix crash in objc_sync_enter/objc_sync_exit when using an Obj-C tagged pointer
Objective-C tagged pointers (either bottom-most or top-most bit is 1) are valid Obj-C objects but are not valid pointers. Make sure we don't crash on them when used in objc_sync_enter/objc_sync_exit. Instead, let's synchronize on a global object.

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

llvm-svn: 337837
2018-07-24 16:19:06 +00:00
Igor Kudrin 356c2aeffe [profile] Fix finding the first and last directory separators on Windows.
Until now, our code preferred backslashes to slashes, whereas Windows
allows using both types of directory separators in one path string.

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

llvm-svn: 337826
2018-07-24 13:06:19 +00:00
Igor Kudrin 63600c7487 [profile] Fix a possible memory leak in parseFilenamePattern().
Differential Revision: https://reviews.llvm.org/D49666

llvm-svn: 337823
2018-07-24 12:28:53 +00:00
Petr Hosek b8ab7e811b [sanitizer][fuzzer] Temporarily transition to ZX_TIME_INFINITE_OLD
This is a preparation for breaking change when all Zircon calls that
take time as an argument will start using signed valued. We will
transition back to ZX_TIME_INFITINE after all the changes to these
symbols are done and become part of the Fuchsia SDK.

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

llvm-svn: 337802
2018-07-24 02:34:24 +00:00
Petr Hosek e2da642697 [sanitizer] Transition from _zx_vmar_... to _zx_vmar_..._old calls
This is a preparation for breaking changes to _zx_vmar_... calls.
We will transition back to _zx_vmar_... after all the changes to
these symbols are done and become part of the Fuchsia SDK.

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

llvm-svn: 337801
2018-07-24 02:28:54 +00:00
Petr Hosek c14d513e0d Revert "[Fuzzer] Update path to libc++ headers"
This reverts commit r337775 since r337727 has been reverted in r337782.

llvm-svn: 337784
2018-07-24 00:34:55 +00:00
Petr Hosek 2cf5d81f04 [Fuzzer] Update path to libc++ headers
The path to headers which are installed into libc++ build directory
has changed in r337727 which broke the libFuzzer build.

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

llvm-svn: 337775
2018-07-23 23:38:28 +00:00
Matthew Voss 1486d5c6e2 Reapply "[XRay] Remove scheduling dependency in fork_basic_logging.cc"
Summary:
Continuation of https://reviews.llvm.org/D49501

Second part of the test has an scheduling order when there shouldn't be.



Reviewers: dberris, ormris

Reviewed By: dberris, ormris

Subscribers: TWeaver

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

llvm-svn: 337745
2018-07-23 21:22:02 +00:00
Max Moroz 1e954f78d1 [libFuzzer] Handle unstable edges by using minimum hit counts
Summary:
Created unstable_handle flag that takes 1 or 2, depending on the handling type.
Modified RunOne to accommodate the following heuristic:
    Use the first CollectFeatures to count how many features there are.
    If no new features, CollectFeatures like before.
    If there is new feature, we run CB 2 more times,
        Check which edges are unstable per input and we store the least amount of hit counts for each edge.
        Apply these hit counts back to inline8bitcounters so that CollectFeatures can work as intended.
Modified UnstableCounters to 8int_t and created a bitset UnstableSet to tell which edges are unstable.

Patch by Kyungtak Woo (@kevinwkt).

Reviewers: Dor1s, metzman, morehouse

Reviewed By: Dor1s, morehouse

Subscribers: delcypher, #sanitizers, llvm-commits, kcc

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

llvm-svn: 337696
2018-07-23 14:20:52 +00:00
Peter Collingbourne acf005676e Change the cap on the amount of padding for each vtable to 32-byte (previously it was 128-byte)
We tested different cap values with a recent commit of Chromium. Our results show that the 32-byte cap yields the smallest binary and all the caps yield similar performance.
Based on the results, we propose to change the cap value to 32-byte.

Patch by Zhaomo Yang!

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

llvm-svn: 337622
2018-07-20 21:43:20 +00:00
H.J. Lu 0cb55919ec Mark REAL(swapcontext) with indirect_return attribute on x86
When shadow stack from Intel CET is enabled, the first instruction of all
indirect branch targets must be a special instruction, ENDBR.

lib/asan/asan_interceptors.cc has

...
  int res = REAL(swapcontext)(oucp, ucp);
...

REAL(swapcontext) is a function pointer to swapcontext in libc.  Since
swapcontext may return via indirect branch on x86 when shadow stack is
enabled, as in this case,

int res = REAL(swapcontext)(oucp, ucp);
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^  This function may be
returned via an indirect branch.

Here compiler must insert ENDBR after call, like

call *bar(%rip)
endbr64

I opened an LLVM bug:

https://bugs.llvm.org/show_bug.cgi?id=38207

to add the indirect_return attribute so that it can be used to inform
compiler to insert ENDBR after REAL(swapcontext) call.  We mark
REAL(swapcontext) with the indirect_return attribute if it is available.

This fixed:

https://bugs.llvm.org/show_bug.cgi?id=38249

Reviewed By: eugenis

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

llvm-svn: 337603
2018-07-20 19:24:11 +00:00
Dan Liew c358e51e9b On Darwin switch from the `VM_MEMORY_ANALYSIS_TOOL` VM tag to
`VM_MEMORY_SANITIZER`.

It turns out that `VM_MEMORY_ANALYSIS_TOOL` is already reserved for
use by other tools so switch to a tag reserved for use by the Sanitizers.

rdar://problem/41969783

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

llvm-svn: 337579
2018-07-20 17:07:35 +00:00
Kostya Kortchinsky cccd21d42c [scudo] Simplify internal names (NFC)
Summary:
There is currently too much redundancy in the class/variable/* names in Scudo:
- we are in the namespace `__scudo`, so there is no point in having something
  named `ScudoX` to end up with a final name of `__scudo::ScudoX`;
- there are a lot of types/* that have `Allocator` in the name, given that
  Scudo is an allocator I figure this doubles up as well.

So change a bunch of the Scudo names to make them shorter, less redundant, and
overall simpler. They should still be pretty self explaining (or at least it
looks so to me).

The TSD part will be done in another CL (eg `__scudo::ScudoTSD`).

Reviewers: alekseyshl, eugenis

Reviewed By: alekseyshl

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 337557
2018-07-20 15:07:17 +00:00
Dmitry Vyukov 97cf5f7f40 esan: fix shadow setup
r337531 changed return type of MmapFixedNoReserve, but esan wasn't updated.
As the result esan shadow setup always fails.
We probably need to make MmapFixedNoAccess signature consistent
with MmapFixedNoReserve. But this is just to unbreak tests.
 

llvm-svn: 337550
2018-07-20 13:40:08 +00:00
David Carlier 12be7b7bf7 [Xray] fix c99 warning build about flexible array semantics
Reviewers: dberris

Reviewed By: dberris

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

llvm-svn: 337536
2018-07-20 09:22:22 +00:00
Dmitry Vyukov f52726aae9 sanitizers: consistently check result of MmapFixedNoReserve
MmapFixedNoReserve does not terminate process on failure.
Failure to check its result and die will always lead to harder
to debug crashes later in execution. This was observed in Go
processes due to some address space conflicts.

Consistently check result of MmapFixedNoReserve.
While we are here also add warn_unused_result attribute
to prevent such bugs in future and change return type to bool
as that's what all callers want.

Reviewed in https://reviews.llvm.org/D49367

llvm-svn: 337531
2018-07-20 08:33:41 +00:00
Joel E. Denny a47cb644c7 [libFuzzer] Use separate test directory for each config
Previously, check-all failed many tests for me.  It was running the
X86_64DefaultLinuxConfig, X86_64LibcxxLinuxConfig, and
X86_64StaticLibcxxLinuxConfig configs out of
llvm-build/projects/compiler-rt/test/fuzzer.  Now, it runs them out of
separate subdirectories there, and most tests pass.

Reviewed By: morehouse, george.karpenkov

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

llvm-svn: 337521
2018-07-20 02:39:01 +00:00
Kostya Serebryany 44edc281d9 [libFuzzer] when -print_coverage=1 is given, print more stats (the number of seeds that hit every given function)
llvm-svn: 337501
2018-07-19 22:00:48 +00:00
Teresa Johnson 408f50dbb4 [profile] Fix typo in test
Noticed that this was causing a compiler warning in the test.

llvm-svn: 337493
2018-07-19 20:18:37 +00:00
Teresa Johnson 73053b221f [profile] Add interface to get profile filename
Summary:
Add __llvm_profile_get_filename interface to get the profile filename,
which can be used for identifying which profile file belongs to an app
when multiple binaries are instrumented and dumping profiles into the
same directory. The filename includes the path.

Reviewers: davidxl

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 337482
2018-07-19 19:03:50 +00:00
Teresa Johnson d4143bc772 [compiler-rt] Only set lto_flags if lto_supported
Fix bot failure from r37465. Move the new lto_flags append under the
check for whether lto_supported. Otherwise TestingConfig may not have
that member.

llvm-svn: 337467
2018-07-19 16:12:15 +00:00
Teresa Johnson 293b0f43ac [compiler-rt] Add NewPM testing to CFI tests
Summary:
Executes both LTO and ThinLTO CFI tests an additional time using the new
pass manager. I only bothered to add with gold and not lld as testing
with one linker should be sufficient. I didn't add for APPLE or WIN32
since I don't have a way to test those.

Depends on D49429.

Reviewers: pcc

Subscribers: dberris, mgorny, mehdi_amini, delcypher, dexonsmith, #sanitizers, llvm-commits

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

llvm-svn: 337465
2018-07-19 15:32:48 +00:00
Dean Michael Berris 41cea19b4f [XRay][compiler-rt] Profiling: No files when empty
This change makes it so that the profiling mode implementation will only
write files when there are buffers to write. Before this change, we'd
always open a file even if there were no profiles collected when
flushing.

llvm-svn: 337443
2018-07-19 09:20:19 +00:00
Dean Michael Berris e0099f1c6d [XRay][compiler-rt] FDR Mode: Add extents metadata to buffer
When providing raw access to the FDR mode buffers, we used to not
include the extents metadata record. This oversight means that
processing the buffers in-memory will lose important information that
would have been written in files.

This change exposes the metadata record by serializing the data
similarly to how we would do it when flushing to files.

llvm-svn: 337441
2018-07-19 05:17:32 +00:00
David Carlier cfc1d1d46e [Xray] Fix allocator build, MAP_NORESERVE flag is not always supported
MAP_NORESERVE is not supported or a no-op on BSD.

Reviewers: dberris

Reviewed By: dberris

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

llvm-svn: 337440
2018-07-19 05:08:59 +00:00
Kostya Serebryany 7a6295f2e1 [libFuzzer] fix the bot (the no-assert build)
llvm-svn: 337437
2018-07-19 03:16:12 +00:00
Kostya Serebryany 79bd14772f [libFuzzer] quick hack to fix the bot
llvm-svn: 337436
2018-07-19 01:54:28 +00:00
Kostya Serebryany 6b87e0c18f [libFuzzer] first experimental attempt at DFT-based mutations (DFT=data-flow-trace)
llvm-svn: 337434
2018-07-19 01:23:32 +00:00
Matthew Voss ac1f9263d1 Remove scheduling dependency from XRay :: Posix/fork_basic_logging.cc
Summary:
We've been seeing intermittent failures on our internal bots and we suspect
this may be due to the OS scheduling the child process to run before the parent
process.

This version ensures that the parent and child can be run in either order.

Reviewers: Maknee, dberris

Reviewed By: dberris

Subscribers: delcypher, #sanitizers, Maknee, llvm-commits

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

llvm-svn: 337432
2018-07-19 00:25:00 +00:00
Peter Collingbourne 4a653fa7f1 Rename __asan_gen_* symbols to ___asan_gen_*.
This prevents gold from printing a warning when trying to export
these symbols via the asan dynamic list after ThinLTO promotes them
from private symbols to external symbols with hidden visibility.

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

llvm-svn: 337428
2018-07-18 22:23:14 +00:00
Petr Hosek 4915d3a1ec [Fuzzer] Improve crash unwinding on Fuchsia
Fuchsia doesn't have signals; instead it expects processes to have a
dedicated exception thread that binds to the process' exception port and
waits for exception packets to be delivered. On the other hand,
libFuzzer and sanitizer_common use expect to collect crash information
via libunwind from the same thread that caused the exception.

The long term fix is to improve support for remote unwinding in
libunbwind, plumb this through sanitizer_common and libFuzzer, and
handle the exception exclusively on the exception thread. In the
meantime, this revision has the exception thread "resurrect" the
crashing thread by:

* saving its general purpose register state onto the crashing thread's
  stack,
* setting the crashing thread's program counter to an assembly trampoline
  with the CFI information needed by libunwind, and
* resuming the crashed thread.

Patch By: aarongreen

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

llvm-svn: 337418
2018-07-18 19:20:47 +00:00
Max Moroz 42b54e8117 [libFuzzer] Create single template for visiting Inline8bitCounters
Summary:
Created IterateInline8bitCounters, a single template for visiting  Inline8bitCounters (nested for loop)
Made InitializeUnstableCounters and UpdateUnstableCounters both send a lambda to IterateInline8bitCounters.

Patch by Kyungtak Woo (@kevinwkt).

Reviewers: Dor1s, metzman, kcc, morehouse

Reviewed By: metzman, morehouse

Subscribers: delcypher, llvm-commits, #sanitizers

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

llvm-svn: 337403
2018-07-18 17:03:27 +00:00
Dean Michael Berris 4719c52455 [XRay][compiler-rt] Segmented Array: Simplify and Optimise
Summary:
This is a follow-on to D49217 which simplifies and optimises the
implementation of the segmented array. In this patch we co-locate the
book-keeping for segments in the `__xray::Array<T>` with the data it's
managing. We take the chance in this patch to actually rename `Chunk` to
`Segment` to better align with the high-level description of the
segmented array.

With measurements using benchmarks landed in D48879, we've identified
that calls to `pthread_getspecific` started dominating the cycles, which
led us to revert the change made in D49217 to use C++ thread_local
initialisation instead (it reduces the cost by a huge margin, since we
save one PLT-based call to pthread functions in the hot path). In
particular, this is in `__xray::getThreadLocalData()`.

We also took the opportunity to remove the least-common-multiple based
calculation and instead pack as much data into segments of the array.
This greatly simplifies the API of the container which hides as much of
the implementation details as possible. For instance, we calculate the
number of elements we need for the each segment internally in the Array
instead of making it part of the type.

With the changes here, we're able to get a measurable improvement on the
performance of profiling mode on top of what D48879 already provides.

Depends on D48879.

Reviewers: kpw, eizan

Subscribers: llvm-commits

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

llvm-svn: 337343
2018-07-18 02:08:39 +00:00
Dean Michael Berris 9d6b7a5f2b [XRay][compiler-rt] Simplify Allocator Implementation
Summary:
This change simplifies the XRay Allocator implementation to self-manage
an mmap'ed memory segment instead of using the internal allocator
implementation in sanitizer_common.

We've found through benchmarks and profiling these benchmarks in D48879
that using the internal allocator in sanitizer_common introduces a
bottleneck on allocating memory through a central spinlock. This change
allows thread-local allocators to eliminate contention on the
centralized allocator.

To get the most benefit from this approach, we also use a managed
allocator for the chunk elements used by the segmented array
implementation. This gives us the chance to amortize the cost of
allocating memory when creating these internal segmented array data
structures.

We also took the opportunity to remove the preallocation argument from
the allocator API, simplifying the usage of the allocator throughout the
profiling implementation.

In this change we also tweak some of the flag values to reduce the
amount of maximum memory we use/need for each thread, when requesting
memory through mmap.

Depends on D48956.

Reviewers: kpw, eizan

Subscribers: llvm-commits

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

llvm-svn: 337342
2018-07-18 01:53:39 +00:00
Dean Michael Berris 1e3feb49e3 [XRay][compiler-rt] FDR Mode: Allow multiple runs
Summary:
Fix a bug in FDR mode which didn't allow for re-initialising the logging
in the same process. This change ensures that:

- When we flush the FDR mode logging, that the state of the logging
  implementation is `XRAY_LOG_UNINITIALIZED`.

- Fix up the thread-local initialisation to use aligned storage and
  `pthread_getspecific` as well as `pthread_setspecific` for the
  thread-specific data.

- Actually use the pointer provided to the thread-exit cleanup handling,
  instead of assuming that the thread has thread-local data associated
  with it, and reaching at thread-exit time.

In this change we also have an explicit test for two consecutive
sessions for FDR mode tracing, and ensuring both sessions succeed.

Reviewers: kpw, eizan

Subscribers: llvm-commits

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

llvm-svn: 337341
2018-07-18 01:31:30 +00:00
Max Moroz 061b4af998 [libFuzzer] Mutation tracking and logging implemented.
Summary:
Code now exists to track number of mutations that are used in fuzzing in total
and ones that produce new coverage. The stats are currently being dumped to the
command line.

Patch by Kodé Williams (@kodewilliams).

Reviewers: metzman, Dor1s, morehouse, kcc

Reviewed By: Dor1s, morehouse, kcc

Subscribers: delcypher, kubamracek, kcc, morehouse, llvm-commits, #sanitizers, mgorny

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

llvm-svn: 337324
2018-07-17 20:37:40 +00:00
Martin Storsjo 946a81f5b0 [builtins] Implement the __chkstk function for ARM for MinGW
This function is available for linking in from kernel32.dll, but
it's not allowed to link that function from there in Windows Store
apps.

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

llvm-svn: 337313
2018-07-17 19:14:47 +00:00
Matt Morehouse 43a2296976 libFuzzer: prevent irrelevant strings from leaking into auto-dictionary
This is a fix for bug 37047.

https://bugs.llvm.org/show_bug.cgi?id=37047

Implemented by basically reversing the logic. Previously all strings
were considered, with some operations excluded. Now strings are excluded
by default, and only strings during the CB considered.

Patch By: pdknsk

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

llvm-svn: 337296
2018-07-17 16:12:00 +00:00
Matt Morehouse ef521ffe24 [libFuzzer] Avoid STL in MSan test.
Summary:
STL can cause MSan false positives if lib[std]c++ isn't instrumented
with MSan.

Reviewers: kcc

Reviewed By: kcc

Subscribers: Dor1s, llvm-commits

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

llvm-svn: 337224
2018-07-16 23:22:54 +00:00
Max Moroz 5697c59c7f Revert r337194 (https://reviews.llvm.org/D48891) due to compilation errors.
llvm-svn: 337206
2018-07-16 20:05:18 +00:00
Alex Lorenz 88feedd7c7 [cmake][libFuzzer] fixup r337193 to ensure msan/dfsan are not added
to test deps for libfuzzer when they're not supported by the platform

llvm-svn: 337203
2018-07-16 19:41:49 +00:00
Petr Hosek b05be5f4b4 [CMake] Use cxx-headers as a depedency for C++ headers
We no longer pass CLANG_DEFAULT_CXX_STDLIB to the runtimes build
as it was causing issues so we can no longer use this variable. We
instead use cxx-headers as a dependency whenever this is available
since both XRay and libFuzzer are built as static libraries so this
is sufficient.

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

llvm-svn: 337199
2018-07-16 18:48:20 +00:00
Max Moroz 8a5083df53 [libFuzzer] Mutation tracking and logging implemented.
Summary:
Code now exists to track number of mutations that are used in fuzzing in total
and ones that produce new coverage. The stats are currently being dumped to the
command line.

Patch by Kodé Williams (@kodewilliams).

Reviewers: metzman, Dor1s, morehouse, kcc

Reviewed By: Dor1s, morehouse, kcc

Subscribers: delcypher, kubamracek, kcc, morehouse, llvm-commits, #sanitizers, mgorny

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

llvm-svn: 337194
2018-07-16 17:50:46 +00:00
Matt Morehouse 0876a889f7 [libFuzzer] Add msan and dfsan to test deps.
Required now that we have tests using MSan and DFSan.

llvm-svn: 337193
2018-07-16 17:37:15 +00:00
Max Moroz 08dad54924 [libFuzzer] Implement stat::stability_rate based on the percentage of unstable edges.
Summary:
Created a -print_unstable_stats flag.
When -print_unstable_stats=1, we run it 2 more times on interesting inputs poisoning unstable edges in an array.
On program termination, we run PrintUnstableStats() which will print a line with a stability percentage like AFL does.

Patch by Kyungtak Woo (@kevinwkt).

Reviewers: metzman, Dor1s, kcc, morehouse

Reviewed By: metzman, Dor1s, morehouse

Subscribers: delcypher, llvm-commits, #sanitizers, kcc, morehouse, Dor1s

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

llvm-svn: 337187
2018-07-16 16:01:31 +00:00
Max Moroz 1d369a5d01 Revert r337175 (https://reviews.llvm.org/D49212) due to unintentional format changes.
llvm-svn: 337180
2018-07-16 15:15:34 +00:00
Chandler Carruth 4abbd13ab2 Fix warnings in a static assert added to CFI.
llvm-svn: 337178
2018-07-16 15:01:26 +00:00
Henry Zhu ebc68ff65f Test commit
llvm-svn: 337176
2018-07-16 14:54:29 +00:00
Max Moroz 2156d885e0 [libFuzzer] Implement stat::stability_rate based on the percentage of unstable edges.
Summary:
Created a -print_unstable_stats flag.
When -print_unstable_stats=1, we run it 2 more times on interesting inputs poisoning unstable edges in an array.
On program termination, we run PrintUnstableStats() which will print a line with a stability percentage like AFL does.

Patch by Kyungtak Woo (@kevinwkt).

Reviewers: metzman, Dor1s, kcc, morehouse

Reviewed By: metzman, Dor1s, morehouse

Subscribers: delcypher, llvm-commits, #sanitizers, kcc, morehouse, Dor1s

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

llvm-svn: 337175
2018-07-16 14:54:23 +00:00
Marco Castelluccio 1f0b194b4a [gcov] Add a test showing differences in line counts when building with or without exceptions enabled.
Test for https://bugs.llvm.org/show_bug.cgi?id=38066.

llvm-svn: 337174
2018-07-16 14:40:33 +00:00
Filipe Cabecinhas 3bc3fb477a [cfi] Don't pass a uint16_t to memset. Make sure the 16-bit constant is appropriate for us.
Reviewers: eugenis, pcc, kcc

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 337170
2018-07-16 13:41:54 +00:00
Marco Castelluccio 0a75de4bfe Add a test with __gcov_flush called before terminating the program.
Test for https://bugs.llvm.org/show_bug.cgi?id=38067.

llvm-svn: 337150
2018-07-16 09:13:46 +00:00
Dean Michael Berris 734e3928b3 [XRay][compiler-rt] Use `SANITIZER_CXX_ABI_LIBRARY` for XRay unit tests
Summary:
Fix a TODO in CMake config for XRay tests to use the detected C++ ABI
library in the tests.

Also make the tests depend on the llvm-xray target when built in-tree.

Reviewers: kpw, eizan

Reviewed By: eizan

Subscribers: mgorny, llvm-commits

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

llvm-svn: 337142
2018-07-16 01:08:56 +00:00
Petr Hosek d533fae6ef [CMake] Change the flag to use compiler-rt builtins to boolean
This changes the name and the type to what it was prior to r333037
which matches the name of the flag used in other runtimes: libc++,
libc++abi and libunwind. We don't need the type to be a string since
there's only binary choice between libgcc and compiler-rt unlike in
the case of C++ library where there're multiple options.

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

llvm-svn: 337116
2018-07-15 03:05:20 +00:00
Max Moroz 038771a25a [UBSan] Followup for silence_unsigned_overflow flag to handle negate overflows.
Summary:
That flag has been introduced in https://reviews.llvm.org/D48660 for
suppressing UIO error messages in an efficient way. The main motivation is to
be able to use UIO checks in builds used for fuzzing as it might provide an
interesting signal to a fuzzing engine such as libFuzzer.

See https://github.com/google/oss-fuzz/issues/910 for more information.

Reviewers: morehouse, kcc

Reviewed By: morehouse

Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 337068
2018-07-13 22:49:06 +00:00
Vlad Tsyrklevich ddf998b608 Fix for Darwin buildbot failure due to r337037
Duplicate __get_unsafe_stack_bottom instead of using an alias for
platforms that don't suppport it like Darwin.

llvm-svn: 337044
2018-07-13 20:56:48 +00:00
Vlad Tsyrklevich be9a9fd3dd SafeStack: Add builtins to read unsafe stack top/bottom
Summary:
Introduce built-ins to read the unsafe stack top and bottom. The unsafe
stack top is required to implement garbage collection scanning for
Oilpan. Currently there is already a built-in 'get_unsafe_stack_start'
to read the bottom of the unsafe stack, but I chose to duplicate this
API because 'start' is ambiguous (e.g. Oilpan uses WTF::GetStackStart to
read the safe stack top.)

Reviewers: pcc

Reviewed By: pcc

Subscribers: llvm-commits, kcc

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

llvm-svn: 337037
2018-07-13 19:48:35 +00:00
Petr Hosek 2d46cfedf2 [CMake] Don't use CLANG_DEFAULT_* values
These are not necessarily correct, just because Clang is configured
to use libc++ or compiler-rt as defaults doesn't mean that the host
compiler uses these as defaults as well. A more correct solution
would be to test the host compiler to check what the default actually
is as attempted in D46857.

Part of PR-38025.

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

llvm-svn: 337033
2018-07-13 19:16:30 +00:00
Kostya Kortchinsky 4a547fb62d [sanitizer] Use -Wl,-z,global on Android
Summary:
Use `-Wl,-z,global` for all Sanitizer shared libraries on
Android. We want them to be in the global group
(https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#changes-to-library-search-order)
to avoid any alloc/dealloc mismatch between the libc allocator & said library.

`audioserver` was one of the binary that exhibited the problem with Scudo,
this seems to fix it.

[edited for accuracy]

Reviewers: eugenis, alekseyshl

Reviewed By: eugenis

Subscribers: kubamracek, srhines, mgorny, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 337010
2018-07-13 15:31:05 +00:00
Marco Castelluccio d47bde0d7a Add a test with multiple BBs on the same line
Test for https://bugs.llvm.org/show_bug.cgi?id=38065.

llvm-svn: 336996
2018-07-13 13:01:43 +00:00
Dan Liew 95d9d22e00 Remove `tsan/Darwin/gcd-after-null.mm` test.
Summary:
This test invokes undocumented behaviour that could change in
the future. Given this, it's probably best to just remove the
test.

rdar://problem/42022283

Reviewers: kubamracek

Subscribers: llvm-commits, #sanitizers

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

llvm-svn: 336977
2018-07-13 07:37:01 +00:00
Dean Michael Berris 10141261e1 [XRay][compiler-rt] Add PID field to llvm-xray tool and add PID metadata record entry in FDR mode
Summary:
llvm-xray changes:
- account-mode - process-id  {...} shows after thread-id
- convert-mode - process {...} shows after thread
- parses FDR and basic mode pid entries
- Checks version number for FDR log parsing.

Basic logging changes:
- Update header version from 2 -> 3

FDR logging changes:
- Update header version from 2 -> 3
- in writeBufferPreamble, there is an additional PID Metadata record (after thread id record and tsc record)

Test cases changes:
- fdr-mode.cc, fdr-single-thread.cc, fdr-thread-order.cc modified to catch process id output in the log.

Reviewers: dberris

Reviewed By: dberris

Subscribers: hiraditya, llvm-commits, #sanitizers

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

llvm-svn: 336974
2018-07-13 05:38:22 +00:00
Dean Michael Berris 5d92d3e5be [XRay][compiler-rt] Profiling Mode: Flush logs on exit
Summary:
This change adds support for writing out profiles at program exit.

Depends on D48653.

Reviewers: kpw, eizan

Reviewed By: kpw

Subscribers: llvm-commits

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

llvm-svn: 336969
2018-07-13 04:04:18 +00:00
George Karpenkov 01c762b9fd [fuzzer] [tests] Increase the number of iterations for three-bytes.test
The test is flaky otherwise on some of our macOS machines in the test fleet.

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

llvm-svn: 336966
2018-07-13 01:21:50 +00:00
Dan Liew 0de57a676c [CMake] Fix a typo in the variable used to retrieve source file names
for the `RTHwasan_dynamic` target.

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

llvm-svn: 336944
2018-07-12 20:55:02 +00:00
Marco Castelluccio 2bb551c6bf Simplify instrprof-dlopen-dlclose-gcov.test to avoid failures on Aarch64.
The test for a function with an if block in a single line (https://bugs.llvm.org/show_bug.cgi?id=38065) will be moved to a separate test.

llvm-svn: 336942
2018-07-12 20:28:09 +00:00
Matt Morehouse 4543816150 [SanitizerCoverage] Add associated metadata to 8-bit counters.
Summary:
This allows counters associated with unused functions to be
dead-stripped along with their functions.  This approach is the same one
we used for PC tables.

Fixes an issue where LLD removes an unused PC table but leaves the 8-bit
counter.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: llvm-commits, hiraditya, kcc

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

llvm-svn: 336941
2018-07-12 20:24:58 +00:00
Matt Morehouse 24d617cbee [libFuzzer] If LLD available, require it to build first.
Since we now have a test that requires LLD, make sure it is built before
that test runs.

llvm-svn: 336932
2018-07-12 18:52:10 +00:00
Matt Morehouse d507c96ff1 [libFuzzer] Use lld-available for gc-sections.test.
The lld feature is never available for libFuzzer tests, so
gc-sections.test never actually runs.

llvm-svn: 336926
2018-07-12 18:09:03 +00:00
Dan Liew 4625480acb [CMake] Remove unnecesary list of source files for Xray unit tests.
The list duplicates information already available in the parent
directory so use that instead. It is unclear to me why we need
to spell out the dependencies explicitly but fixing that should
be done in a separate patch.

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

llvm-svn: 336905
2018-07-12 13:48:18 +00:00
Dan Liew c5d759a926 [CMake] Rename `SANITIZER_HEADERS` to `SANITIZER_IMPL_HEADERS` under `lib/sanitizer_common`.
The variable name `SANITIZER_HEADERS` is already used for the list of
public headers in `include/CMakeLists.txt`.  Although the previous
implementation worked it's probably best to avoid shadowing global
variables to avoid confusion.

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

llvm-svn: 336904
2018-07-12 13:36:44 +00:00
Dean Michael Berris 4366b0122a [XRay][compiler-rt] Fixup: require x86_64 for profiling mode tests
This constrains the build environments we are testing/supporting for the runtime
tests until we can be sure xray works in more platforms.

llvm-svn: 336878
2018-07-12 01:54:29 +00:00
Joel E. Denny a09b9317f5 [FileCheck] Add -allow-deprecated-dag-overlap to another compiler-rt test
See https://reviews.llvm.org/D47106 for details.

llvm-svn: 336859
2018-07-11 22:07:31 +00:00
Joel E. Denny da660d6a70 [FileCheck] Add -allow-deprecated-dag-overlap to failing compiler-rt tests
See https://reviews.llvm.org/D47106 for details.

Reviewed By: probinson

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

llvm-svn: 336845
2018-07-11 20:26:44 +00:00
Zaara Syeda f3fd38effd Remove ppc64 BE XFAILs now that gcov profiling works, after starting a clean
build this time.

llvm-svn: 336839
2018-07-11 19:17:43 +00:00
Marco Castelluccio e125955890 Link to the correct bug number about the Mac failure for instrprof-shared-gcov-flush.test.
llvm-svn: 336820
2018-07-11 15:44:15 +00:00
Zaara Syeda 47c2ddf6b3 Revert 336811, there are still some problems with the tests.
llvm-svn: 336819
2018-07-11 15:37:19 +00:00
Zaara Syeda 495adf52db Remove ppc64 BE XFAILs now that gcov profiling works.
llvm-svn: 336811
2018-07-11 14:55:19 +00:00
Marco Castelluccio e21cfa7e7f Fix reading 32 bit gcov tag values on little-endian machines
Summary:
The write buffer contains signed chars, which means the shift operations caused values such as the arc tag value (0x01a10000) to be read incorrectly (0xffa10000).

This fixes a regression from https://reviews.llvm.org/D49132.

Reviewers: uweigand, davidxl

Reviewed By: uweigand

Subscribers: llvm-commits, #sanitizers

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

llvm-svn: 336775
2018-07-11 09:30:25 +00:00
Dean Michael Berris 8299e4b8db [XRay] basic mode PID and TID always fetch
Summary: XRayRecords now includes a PID field. Basic handlers fetch pid and tid each time they are called instead of caching the value. Added a testcase that calls fork and checks if the child TID is different from the parent TID to verify that the processes' TID are different in the trace.

Reviewers: dberris, Maknee

Reviewed By: dberris, Maknee

Subscribers: kpw, llvm-commits, #sanitizers

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

llvm-svn: 336769
2018-07-11 07:14:27 +00:00
Stephen Hines 6812c28ef3 Add libcxxabi option back for sanitizer use.
Summary:
A prior refactoring accidentally dropped the case for using libc++abi as
the out-of-tree C++ runtime library for sanitizers. This patch restores
that functionality, which is used by Android, which can't depend on the
full libc++ for these libraries.

Reviewers: phosek, EricWF

Reviewed By: phosek

Subscribers: meikeb, kongyi, chh, mgorny, delcypher, llvm-commits, #sanitizers, pirama

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

llvm-svn: 336749
2018-07-11 00:50:03 +00:00
Matt Morehouse 79d55d30c3 [libFuzzer] Disable dataflow.test on AArch64.
Summary:
After my recent change to allow MSan + libFuzzer, the
ExplodeDFSanLabelsTest.cpp test started to overflow the stack with
recursive function SetBytesForLabel() on an AArch64 bot.  Perhaps that
bot has a smaller stack size, or maybe AArch64 has larger stack frames
for this particular function.

Reviewers: kcc, javed.absar

Reviewed By: kcc

Subscribers: kristof.beyls, llvm-commits

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

llvm-svn: 336725
2018-07-10 20:45:36 +00:00
Matt Morehouse 0e904e8806 Revert "[Fuzzer] Afl driver changing iterations handling"
This reverts rL334510 due to breakage of afl_driver's command line
interface.

Patch By: Jonathan Metzman

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

llvm-svn: 336719
2018-07-10 19:58:42 +00:00
Vlad Tsyrklevich f90ad5b327 Limit ASan non-executable-pc test case to x86 bots
The test case fails on the big-endian PPC bot, probably because PowerPC
uses function descriptors. More over other architectures don't support
NX mappings. (This test case was not being exercised prior to r336633.)

llvm-svn: 336714
2018-07-10 19:34:46 +00:00
Ulrich Weigand dd4d2ac607 [gcov] Fix fallout from r336693
Fix building GCDAProfiling.c with pre-C99 compilers.
This caused a build bot failure.

llvm-svn: 336706
2018-07-10 17:08:05 +00:00
Ulrich Weigand f4556f634f [asan] Disable non-execute test on s390
Processors before z14 don't support non-execute protection,
so they will start execution random memory contents, causing
the test to randomly fail or succeed.

llvm-svn: 336705
2018-07-10 16:55:27 +00:00
Dan Liew 9f6302e950 Try to fix broken build due to r336663.
It turns out that the `${XRAY_HEADERS}` CMake variable was already
in use and was used for public headers. It seems that
`lib/xray/tests/CMakeLists.txt` was depending on this.

To fix rename the new `${XRAY_HEADERS}` to `${XRAY_IMPL_HEADERS}`.

llvm-svn: 336699
2018-07-10 16:22:05 +00:00
Ulrich Weigand f0642bfe44 Remove s390x XFAILs now that gcov profiling works.
llvm-svn: 336695
2018-07-10 16:09:24 +00:00
Ulrich Weigand e508cd2a04 [gcov] Fix gcov profiling on big-endian machines
Two fixes required to handle big-endian systems:

- 64-bit counter values are stored in a mixed-endian format in the
gcov files: a 32-bit low-part followed by a 32-bit high part. Note that
this is already implemented correctly on the LLVM side, see
GCOVBuffer::readInt64.

- The tag values (e.g. arcs tag, object summary tag, ...) are aways
written as the same sequence of bytes independent of byte order. But
when *reading* them back in, the code reads them as 32-bit values in
host byte order. For the comparisons to work correctly, this should
instead always read them as little-endian values.

Fixes PR 38121.

Reviewed By: marco-c

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

llvm-svn: 336693
2018-07-10 16:08:27 +00:00
Marco Castelluccio 2827420aab Reapply "Make __gcov_flush flush counters for all shared libraries"
This reapplies r336365, after marking tests as failing on various
configurations.

llvm-svn: 336678
2018-07-10 14:12:03 +00:00
Filipe Cabecinhas f6cf891b4d [scudo] Use mkdir -p when creating directories for a test
llvm-svn: 336673
2018-07-10 13:59:59 +00:00
Dan Liew 9af77974e2 [LibFuzzer] Disable MSan test on Darwin which was added by r336619. The MemorySanitizer is
not supported on Darwin currently and so Clang refuses to compile with
`-fsanitize=memory`.

llvm-svn: 336669
2018-07-10 13:35:35 +00:00
Dan Liew b1f95697c1 [CMake] Add compiler-rt header files to the list of sources for targets
when building with an IDE so that header files show up in the UI.
This massively improves the development workflow in IDEs.

To implement this a new function `compiler_rt_process_sources(...)` has
been added that adds header files to the list of sources when the
generator is an IDE. For non-IDE generators (e.g. Ninja/Makefile) no
changes are made to the list of source files.

The function can be passed a list of headers via the
`ADDITIONAL_HEADERS` argument. For each runtime library a list of
explicit header files has been added and passed via
`ADDITIONAL_HEADERS`. For `tsan` and `sanitizer_common` a list of
headers was already present but it was stale and has been updated
to reflect the current state of the source tree.

The original version of this patch used file globbing (`*.{h,inc,def}`)
to find the headers but the approach was changed due to this being a
CMake anti-pattern (if the list of headers changes CMake won't
automatically re-generate if globbing is used).

The LLVM repo contains a similar function named `llvm_process_sources()`
but we don't use it here for several reasons:

* It depends on the `LLVM_ENABLE_OPTION` cache variable which is
  not set in standalone compiler-rt builds.
* We would have to `include(LLVMProcessSources)` which I'd like to
  avoid because it would include a bunch of stuff we don't need.

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

llvm-svn: 336663
2018-07-10 13:00:17 +00:00
Filipe Cabecinhas 6a9c719ee1 [compiler-rt] Get rid of "%T" expansions
Summary:
Original patch by Kuba Mracek

The %T lit expansion expands to a common directory shared between all
the tests in the same directory, which is unexpected and unintuitive,
and more importantly, it's been a source of subtle race conditions and
flaky tests. In https://reviews.llvm.org/D35396, it was agreed that it
would be best to simply ban %T and only keep %t, which is unique to each
test. When a test needs a temporary directory, it can just create one
using mkdir %t.

This patch removes %T in compiler-rt.

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

llvm-svn: 336661
2018-07-10 12:53:46 +00:00
Dean Michael Berris b251f62428 [XRay][compiler-rt] Fixup build breakage
Changes:

- Remove static assertion on size of a structure, fails on systems where
  pointers aren't 8 bytes.

- Use size_t instead of deducing type of arguments to
  `nearest_boundary`.

Follow-up to D48653.

llvm-svn: 336648
2018-07-10 08:58:12 +00:00
Dean Michael Berris 0dd4f9f22f [XRay][compiler-rt] xray::Array Freelist and Iterator Updates
Summary:
We found a bug while working on a benchmark for the profiling mode which
manifests as a segmentation fault in the profiling handler's
implementation. This change adds unit tests which replicate the
issues in isolation.

We've tracked this down as a bug in the implementation of the Freelist
in the `xray::Array` type. This happens when we trim the array by a
number of elements, where we've been incorrectly assigning pointers for
the links in the freelist of chunk nodes. We've taken the chance to add
more debug-only assertions to the code path and allow us to verify these
assumptions in debug builds.

In the process, we also took the opportunity to use iterators to
implement both `front()` and `back()` which exposes a bug in the
iterator decrement operation.  In particular, when we decrement past a
chunk size boundary, we end up moving too far back and reaching the
`SentinelChunk` prematurely.

This change unblocks us to allow for contributing the non-crashing
version of the benchmarks in the test-suite as well.

Reviewers: kpw

Subscribers: mgorny, llvm-commits

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

llvm-svn: 336644
2018-07-10 08:25:44 +00:00
Vlad Tsyrklevich 25291f15e7 Add lowercase OS name feature
Summary:
Some tests already make use of OS feature names, e.g. 'linux' and 'freebsd',
but they are not actually currently set by lit.

Reviewers: pcc, eugenis

Reviewed By: eugenis

Subscribers: emaste, krytarowski, delcypher, llvm-commits, #sanitizers

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

llvm-svn: 336633
2018-07-10 02:02:21 +00:00
Matt Morehouse a34c65e845 [libFuzzer] Make -fsanitize=memory,fuzzer work.
This patch allows libFuzzer to fuzz applications instrumented with MSan
without recompiling libFuzzer with MSan instrumentation.

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

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

llvm-svn: 336619
2018-07-09 23:51:08 +00:00
Matt Morehouse a5bb6d53f2 Revert "[libFuzzer] Mutation tracking and logging implemented"
This reverts r336597 due to bot breakage.

llvm-svn: 336616
2018-07-09 22:31:26 +00:00
Matt Morehouse d153d46884 [libFuzzer] Mutation tracking and logging implemented
Code now exists to track number of mutations that are used in fuzzing in
total and ones that produce new coverage. The stats are currently being
dumped to the command line.

Patch By: Kode Williams

Differntial Revision: https://reviews.llvm.org/D48054

llvm-svn: 336597
2018-07-09 20:17:52 +00:00
Alex Shlyapnikov 63af91574f [ASan] Minor ASan error reporting cleanup
Summary:
- use proper Error() decorator for error messages
- refactor ASan thread id and name reporting

Reviewers: eugenis

Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 336573
2018-07-09 17:54:55 +00:00
Michael Zolotukhin 9664ca9dce Revert "Make __gcov_flush flush counters for all shared libraries"
This reverts r336365: the added tests are failing on various
configurations (e.g. on green-dragon).

llvm-svn: 336474
2018-07-07 00:07:00 +00:00
Kostya Serebryany 2bd02db943 libFuzzer: always print line-break for NEW_FUNC/PC output
Summary: This is a minor cosmetic change. When function/path exceed ~1000 characters, the output is truncated before the line-break. I noticed this for NEW_FUNC.

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits, #sanitizers

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

llvm-svn: 336461
2018-07-06 19:47:00 +00:00
Yvan Roux 19d28309af Recommit "[CMake] Run libFuzzer tests with check-all."
Since problematic tests on AArch64 were disabled at r336446.

llvm-svn: 336449
2018-07-06 17:22:02 +00:00
Matt Morehouse 373d6ed7cf [MSan] Add functions to enable/disable interceptor checks.
Summary:
The motivation for this change is to make libFuzzer+MSan possible
without instrumenting libFuzzer.

See https://github.com/google/sanitizers/issues/958.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: llvm-commits, kcc

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

llvm-svn: 336447
2018-07-06 17:10:51 +00:00
Yvan Roux becbb87553 [libFuzzer] Disable hanging tests on AArch64
Disable problematic tests which broke AArch64 bots.
Details available in Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=38034

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

llvm-svn: 336446
2018-07-06 17:06:01 +00:00
Kostya Kortchinsky 2efb847b6f [scudo] Add some logs for Android
Summary:
Namely, set the abort message, and allow to write the message to syslog if the
option is enabled.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 336445
2018-07-06 16:50:12 +00:00
Marco Castelluccio 32d18beb8c Make __gcov_flush flush counters for all shared libraries
Summary:
This will make the behavior of __gcov_flush match the GCC behavior.

I would like to rename __gcov_flush to __llvm_gcov_flush (in case of programs linking to libraries built with different compilers), but I guess we can't for compatibility reasons.

Reviewers: davidxl

Reviewed By: davidxl

Subscribers: samsonov, vitalybuka, pcc, kcc, junbuml, glider, fhahn, eugenis, dvyukov, davidxl, srhines, chh, llvm-commits, #sanitizers

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

llvm-svn: 336365
2018-07-05 15:52:59 +00:00
Yvan Roux 01c0d860f3 Revert "[CMake] Run libFuzzer tests with check-all."
Revert due to AArch64 bots breakage, upstream PR raised to track the
issue: https://bugs.llvm.org/show_bug.cgi?id=38034

llvm-svn: 336341
2018-07-05 12:19:03 +00:00
George Karpenkov aeeac6d41c [libFuzzer] [NFC] Inline static variable to avoid the linker warning.
Differential Revision: https://reviews.llvm.org/D48650

llvm-svn: 336238
2018-07-04 00:37:45 +00:00
Kostya Serebryany 51ddb88300 [libFuzzer] add one more value profile metric, under a flag (experimental)
llvm-svn: 336234
2018-07-03 22:33:09 +00:00
Kostya Serebryany dcac0a3b5e [libFuzzer] remove stale code, as suggested in https://reviews.llvm.org/D48800
llvm-svn: 336230
2018-07-03 21:22:44 +00:00
Kostya Serebryany 0bc9143de8 [libFuzzer] add a tiny and surprisingly hard puzzle
llvm-svn: 336229
2018-07-03 21:17:55 +00:00
Kostya Kortchinsky e64a81475c [scudo] Get rid of builtin-declaration-mismatch warnings
Summary:
The C interceptors were using `SIZE_T` defined in the interception library as
a `__sanitizer::uptr`. On some 32-bit platforms, this lead to the following
warning:
```
warning: declaration of ‘void* malloc(SIZE_T)’ conflicts with built-in declaration ‘void* malloc(unsigned int)’ [-Wbuiltin-declaration-mismatch]
INTERCEPTOR_ATTRIBUTE void *malloc(SIZE_T size) {
```
`__sanitizer::uptr` is indeed defined as an `unsigned long` on those.

So just include `stddef.h` and use `size_t` instead.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: delcypher, llvm-commits, #sanitizers

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

llvm-svn: 336221
2018-07-03 19:03:46 +00:00
Kostya Kortchinsky 02827792b5 [scudo] Enable Scudo on PPC64
Summary:
In conjunction with the clang side change D48833, this will enable Scudo on
PPC64. I tested `check-scudo` on a powerpc64le box and everything passes.

Reviewers: eugenis, alekseyshl

Reviewed By: alekseyshl

Subscribers: mgorny, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 336213
2018-07-03 16:09:18 +00:00
Kostya Kortchinsky 4bc7f3d4d6 [scudo] Enable Scudo memory hooks for Fuchsia.
Summary:
    It would be useful for Flutter apps, especially, to be able to use
    malloc hooks to debug memory leaks on Fuchsia. They're not able to do
    this right now, so it'd be a nice bonus to throw in with the Scudo
    switchover.


Reviewers: cryptoad, alekseyshl

Reviewed By: cryptoad

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

llvm-svn: 336139
2018-07-02 19:48:01 +00:00
Fangrui Song 5f27e0c021 [asan] Fix deadlock issue on FreeBSD, caused by use of .preinit_array in rL325240
Summary:
Without this patch,
clang -fsanitize=address -xc =(printf 'int main(){}') -o a; ./a => deadlock in __asan_init>AsanInitInternal>AsanTSDInit>...>__getcontextx_size>_rtld_bind>rlock_acquire(rtld_bind_lock, &lockstate)

libexec/rtld-elf/rtld.c
  wlock_acquire(rtld_bind_lock, &lockstate);
  if (obj_main->crt_no_init)
    preinit_main(); // unresolved PLT functions cannot be called here

lib/libthr/thread/thr_rtld.c
  uc_len = __getcontextx_size(); // unresolved PLT function in libthr.so.3

check-xray tests currently rely on .preinit_array so we special case in
xray_init.cc

Subscribers: srhines, kubamracek, krytarowski, delcypher, llvm-commits, #sanitizers

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

llvm-svn: 336067
2018-07-01 17:52:41 +00:00
David Carlier c33f35ff0f [UBsan] Enable subset of unit tests for OpenBSD
Reviewers: kubamracek, krytarowski

Reviewed By: krytarowski

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

llvm-svn: 336053
2018-06-30 21:35:05 +00:00
Fangrui Song da891dc6b4 [asan] Use MADV_NOCORE for use_madv_dontdump on FreeBSD.
Currently in FreeBSD 12.0-CURRENT with trunk clang+compiler-rt, faulty -fsanitize=address executable hangs at 'urdlck' state.

Ka Ho Ng has verified that by backporting this to llvm 6.0.1, with use_madv_dontdump=1, shadow memory is not dumped.

ASAN_OPTIONS=abort_on_error=1:disable_coredump=0:use_madv_dontdump=1 ./a

Reviewers: dimitry, kcc, dvyukov, emaste, khng300

Subscribers: kubamracek, delcypher, llvm-commits, #sanitizers

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

llvm-svn: 336046
2018-06-30 08:27:48 +00:00
Chih-Hung Hsieh 7222e8e30b [profile] Add llvm_gcov_flush to be called outside a shared library
__gcov_flush is hidden.
For applications to dump profiling data of selected .so files,
they can use dlsym to find and call llvm_gcov_flush in each .so file.

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

llvm-svn: 336019
2018-06-29 21:45:55 +00:00
Evgeniy Stepanov d77e7ba74e [cfi] Use __builtin version of __clear_cache.
__builtin___clear_cache is also present on X86 and does the right thing (i.e. nop) there.

llvm-svn: 335997
2018-06-29 17:22:58 +00:00
Evgeniy Stepanov ac9b6adf77 [scs] Disable negative test in shadowcallstack.
The test checks that scs does NOT work correctly w/o runtime support.
That's a strange thing to test, and it is also flaky, because things
may just work if x18 happens to point to a writable page.

llvm-svn: 335982
2018-06-29 15:16:45 +00:00
Kostya Kortchinsky e92d7878e5 [scudo] Add some runtime tests for the minimal runtime
Summary:
As well as some tests to ensure that various combinations of the clang command
line flags work (shared/static/minimal).

Reviewers: eugenis, alekseyshl, vitalybuka

Reviewed By: vitalybuka

Subscribers: srhines, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 335981
2018-06-29 14:56:25 +00:00
Evgeniy Stepanov 6d310651a2 [cfi] Reset i-cache after copying code in test.
Fixes intermittent crashes on Android.
Also add PROT_READ to the code mapping for no real reason.

llvm-svn: 335943
2018-06-29 00:38:26 +00:00
Evgeniy Stepanov 3702f91287 [asan] Change 3 tests from XFAIL to UNSUPPORTED.
The failure in https://github.com/google/sanitizers/issues/981 is flaky.

llvm-svn: 335941
2018-06-28 23:27:55 +00:00
Evgeniy Stepanov 730c985d56 [asan] Disable 3 tests on Android O+.
https://github.com/google/sanitizers/issues/981

llvm-svn: 335937
2018-06-28 22:54:55 +00:00
Evgeniy Stepanov e40ae2e3a2 [asan] Fix one more test on Android.
This change makes it pass both on libstdc++ and libc++-based toolchains.

The error was:
error: function-like macro '__GLIBC_PREREQ' is not defined
                               ^

llvm-svn: 335936
2018-06-28 22:54:42 +00:00
Evgeniy Stepanov 59ef3dbbc6 [asan] un-XFAIL one test
NDK r16 provides glob.h, which makes this test pass.
Supporting different test outcomes depending on the version of NDK
add unnecessary complexity to the test harness. IMHO, it's OK to require
the latest stable release.

llvm-svn: 335935
2018-06-28 22:54:30 +00:00
Evgeniy Stepanov 71dc39823c [fuzzer] Don't run tests on Android.
Need better build system support.

llvm-svn: 335933
2018-06-28 22:16:59 +00:00
Alex Shlyapnikov fb1644835b [TSan] More detailed error message on failed sahdow memory madvise
Summary:
Report errno value on failed shadow memory madvise attempt and add a
hint message with the possible workaround.

Reviewers: eugenis

Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits

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

llvm-svn: 335928
2018-06-28 21:38:34 +00:00
David Carlier a8c5041bdf [UBsan] minimal unit tests removing OpenBSD spacial case
The OpenBSD driver now handles sanitisers with ld.lld automatically.

Reviewers: vitalybuka

Reviewed By: vitalybuka

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

llvm-svn: 335923
2018-06-28 21:10:52 +00:00
Vedant Kumar c8735fbb4c [Darwin] Add an integration test for PGO + symbol exports
rdar://41470205

llvm-svn: 335891
2018-06-28 17:53:43 +00:00