Commit Graph

12066 Commits

Author SHA1 Message Date
Mitch Phillips 2fb4e754c6 Guard fuzzer build behind Clang-only flags.
Should fix sanitizer buildbots and any one else who's building
compiler-rt using gcc.

llvm-svn: 369055
2019-08-15 22:15:46 +00:00
Mitch Phillips fdee340bea Remove CMake >= v3.13 target_link_options.
Instead, use set_target_properties.

llvm-svn: 369051
2019-08-15 21:34:13 +00:00
Mitch Phillips be8a2f7565 [GWP-ASan] Implement stack frame compression.
Summary:
This patch introduces stack frame compression to GWP-ASan. Each stack frame is
variable-length integer encoded as the difference between frame[i] and
frame[i - 1]. Furthermore, we use zig-zag encoding on the difference to ensure
that negative differences are also encoded into a relatively small number of
bytes.

Examples of what the compression looks like can be seen in
`gwp_asan/tests/compression.cpp`.

This compression can reduce the memory consumption cost of stack traces by
~50%.

Reviewers: vlad.tsyrklevich

Reviewed By: vlad.tsyrklevich

Subscribers: mgorny, #sanitizers, llvm-commits, eugenis, morehouse

Tags: #sanitizers, #llvm

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

llvm-svn: 369048
2019-08-15 21:09:09 +00:00
Julian Lettner bb99437f6d [sanitizer_common] Always use posix_spawn on Darwin
On Darwin we have two external symbolizers: atos and llvm-symbolizer.
atos was changed to use posix_spawn (instead of fork+execv) in a
previous commit [1]. Let's use posix_spawn for llvm-symbolizer as well.

Our hope is that eventually we can transition to posix_spawn on other
platforms too.

[1] 399408a92f

llvm-svn: 369021
2019-08-15 17:25:10 +00:00
Jonas Devlieghere 8903433bb2 Re-land "[compiler-rt] Migrate llvm::make_unique to std::make_unique"
With the compiler-rt check for C++14 updated in r368960, this should now
be fine to land.

llvm-svn: 369009
2019-08-15 14:57:44 +00:00
Jonas Devlieghere 4d474e078a [CMake] Check for C++14 instead of C++11
Now that LLVM moved to C++14, `COMPILER_RT_HAS_STD_CXX11_FLAG` should
become `COMPILER_RT_HAS_STD_CXX14_FLAG`.

I ran into this issue when replacing llvm::make_unique with
std::make_unique in an X-ray unit test. We are correctly passing
`-std=c++14`, but this got overwritten further down the invocation by
the compiler-rt flags. Given that this unit test is using LLVM headers,
this is bound to break sooner than later, regardless of my change.

Differential revision: https://reviews.llvm.org/D66271

llvm-svn: 368960
2019-08-15 04:42:15 +00:00
Jonas Devlieghere d65f37dbcc Revert "[compiler-rt] Migrate llvm::make_unique to std::make_unique"
The X-ray unit tests in compiler-rt are overriding the C++ version by
explicitly passing -std=c++11 in the compiler invocation. This poses a
problem as these tests are including LLVM headers that can now use C++14
features. I'm temporarily reverting this as I investigate the correct
solution.

llvm-svn: 368952
2019-08-15 03:02:57 +00:00
Julian Lettner 399408a92f [sanitizer_common] Replace forkpty with posix_spawn on Darwin
On Darwin, we currently use forkpty to communicate with the "atos"
symbolizer. There are several problems that fork[pty] has, e.g. that
after fork, interceptors are still active and this sometimes causes
crashes or hangs. This is especially problematic for TSan, which uses
interceptors for OS-provided locks and mutexes, and even Libc functions
use those.

This patch replaces forkpty with posix_spawn on Darwin. Since
posix_spawn doesn't fork (at least on Darwin), the interceptors are not
a problem. Another benefit is that we'll handle post-fork failures (e.g.
sandbox disallows "exec") gracefully now.

Related revisions and previous attempts that were blocked by or had to
be revered due to test failures:
https://reviews.llvm.org/D48451
https://reviews.llvm.org/D40032

Reviewed By: kubamracek

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

llvm-svn: 368947
2019-08-15 00:18:55 +00:00
Jonas Devlieghere 5edd6843fa [compiler-rt] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

Differential revision: https://reviews.llvm.org/D66259

llvm-svn: 368946
2019-08-15 00:06:49 +00:00
Kostya Kortchinsky 2be59170d4 [scudo][standalone] Add more stats to mallinfo
Summary:
Android requires additional stats in mallinfo. While we can provide
right away the number of bytes mapped (Primary+Secondary), there was
no way to get the number of free bytes (only makes sense for the
Primary since the Secondary unmaps everything on deallocation).

An approximation could be `StatMapped - StatAllocated`, but since we
are mapping in `1<<17` increments for the 64-bit Primary, it's fairly
inaccurate.

So we introduce `StatFree` (note it's `Free`, not `Freed`!), which
keeps track of the amount of Primary blocks currently unallocated.

Reviewers: cferris, eugenis, vitalybuka, hctim, morehouse

Reviewed By: morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 368866
2019-08-14 16:04:01 +00:00
Julian Lettner d8c47d52da [TSan] Fix test failing on Linux
llvm-svn: 368641
2019-08-13 00:37:48 +00:00
Mitch Phillips 352d1b59c0 [GWP-ASan] Update backtrace function signature.
Summary:
Updates the function signature and comments for backtracing (and printing
backtraces). This update brings GWP-ASan in line with future requirements for
stack frame compression, wherein the length of the trace is provided
explicitly, rather than relying on nullptr-termination.

Reviewers: vlad.tsyrklevich

Reviewed By: vlad.tsyrklevich

Subscribers: #sanitizers, llvm-commits, morehouse

Tags: #sanitizers, #llvm

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

llvm-svn: 368619
2019-08-12 21:36:44 +00:00
Max Moroz 74cec618f3 [libFuzzer] Merge: print feature coverage number as well.
Summary:
feature coverage is a useful signal that is available during the merge
process, but was not printed previously.

Output example:

```
$ ./fuzzer -use_value_profile=1 -merge=1 new_corpus/ seed_corpus/
INFO: Seed: 1676551929
INFO: Loaded 1 modules   (2380 inline 8-bit counters): 2380 [0x90d180, 0x90dacc), 
INFO: Loaded 1 PC tables (2380 PCs): 2380 [0x684018,0x68d4d8), 
MERGE-OUTER: 180 files, 78 in the initial corpus
MERGE-OUTER: attempt 1
INFO: Seed: 1676574577
INFO: Loaded 1 modules   (2380 inline 8-bit counters): 2380 [0x90d180, 0x90dacc), 
INFO: Loaded 1 PC tables (2380 PCs): 2380 [0x684018,0x68d4d8), 
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 1048576 bytes
MERGE-INNER: using the control file '/tmp/libFuzzerTemp.111754.txt'
MERGE-INNER: 180 total files; 0 processed earlier; will process 180 files now
#1	pulse  cov: 134 ft: 330 exec/s: 0 rss: 37Mb
#2	pulse  cov: 142 ft: 462 exec/s: 0 rss: 38Mb
#4	pulse  cov: 152 ft: 651 exec/s: 0 rss: 38Mb
#8	pulse  cov: 152 ft: 943 exec/s: 0 rss: 38Mb
#16	pulse  cov: 520 ft: 2783 exec/s: 0 rss: 39Mb
#32	pulse  cov: 552 ft: 3280 exec/s: 0 rss: 41Mb
#64	pulse  cov: 576 ft: 3641 exec/s: 0 rss: 50Mb
#78	LOADED cov: 602 ft: 3936 exec/s: 0 rss: 88Mb
#128	pulse  cov: 611 ft: 3996 exec/s: 0 rss: 93Mb
#180	DONE   cov: 611 ft: 4016 exec/s: 0 rss: 155Mb
MERGE-OUTER: succesfull in 1 attempt(s)
MERGE-OUTER: the control file has 39741 bytes
MERGE-OUTER: consumed 0Mb (37Mb rss) to parse the control file
MERGE-OUTER: 9 new files with 80 new features added; 9 new coverage edges
```

Reviewers: hctim, morehouse

Reviewed By: morehouse

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

Tags: #llvm, #sanitizers

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

llvm-svn: 368617
2019-08-12 20:21:27 +00:00
Nico Weber d2e493c337 Fix Wnewline-eof after r368598
llvm-svn: 368613
2019-08-12 19:57:17 +00:00
Dan Liew c3b93bed29 [asan_symbolize] Fix bug where the frame counter was not incremented.
Summary:
This bug occurred when a plug-in requested that a binary not be
symbolized while the script is trying to symbolize a stack frame. In
this case `self.frame_no` would not be incremented. This would cause
subsequent stack frames that are symbolized to be incorrectly numbered.

To fix this `get_symbolized_lines()` has been modified to take an
argument that indicates whether the stack frame counter should
incremented. In `process_line_posix()` `get_symbolized_lines(None, ...)`
is now used in in the case where we don't want to symbolize a line so
that we can keep the frame counter increment in a single function.

A test case is included. The test uses a dummy plugin that always asks
`asan_symbolize.py` script to not symbolize the first binary that the
script asks about. Prior to the patch this would cause the output to
script to look something like

```
  #0 0x0
  #0 0x0 in do_access
  #1 0x0 in main
```

This is the second attempt at landing this patch. The first (r368373)
failed due to failing some android bots and so was reverted in r368472.
The new test is now disabled for Android. It turns out that the patch
also fails for iOS too so it is also disabled for that family of
platforms too.

rdar://problem/49476995

Reviewers: kubamracek, yln, samsonov, dvyukov, vitalybuka

Subscribers: #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 368603
2019-08-12 18:51:25 +00:00
Matthew G McGovern 38a1aa117f [builtins] MSVC warning disable for clean build
- https://reviews.llvm.org/D66023
    - amended for ifdef/if gcc errors in previous verison

llvm-svn: 368598
2019-08-12 18:08:44 +00:00
Kostya Kortchinsky 8095449e68 [scudo][standalone] Minor corrections
Summary:
Few corrections with no functional change:
- replacing `%zd` with `%zu` all around: the values are unsigned
- prefer `MAP_ANONYMOUS` to `MAP_ANON` (it's deprecated)
- remove the unused `enum LinkerInitialized`
- mark a parameter as `UNUSED` in Fuchsia's `getRandom`
- correct the casing of a variable and use `nullptr` instead of 0 for
  pointers in `list.h`
- reorder some `typedef` to be consistent between `signed` and
  `unsigned`

Reviewers: eugenis, vitalybuka, morehouse, hctim

Reviewed By: vitalybuka, morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 368585
2019-08-12 15:35:09 +00:00
Dimitry Andric c09d888632 Add support for FreeBSD's LD_32_LIBRARY_PATH
Summary:
Because the dynamic linker for 32-bit executables on 64-bit FreeBSD uses
the environment variable `LD_32_LIBRARY_PATH` instead of
`LD_LIBRARY_PATH` to find needed dynamic libraries, running the 32-bit
parts of the dynamic ASan tests will fail with errors similar to:

```
ld-elf32.so.1: Shared object "libclang_rt.asan-i386.so" not found, required by "Asan-i386-inline-Dynamic-Test"
```

This adds support for setting up `LD_32_LIBRARY_PATH` for the unit and
regression tests.  It will likely also require a minor change to the
`TestingConfig` class in `llvm/utils/lit/lit`.

Reviewers: emaste, kcc, rnk, arichardson

Reviewed By: arichardson

Subscribers: kubamracek, krytarowski, fedor.sergeev, delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 368516
2019-08-10 19:07:38 +00:00
David Carlier 8d1646bf66 [Sanitizer] Reenable getusershell interception
and disabling it forAndroid.

Reviewers: krytarowski, vitalybuka

Reviewed By: krytarowski

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

llvm-svn: 368504
2019-08-10 03:35:54 +00:00
Julian Lettner 5ef4b190d9 [Sanitizer][Darwin] Add interceptor for malloc_zone_from_ptr
Ensure that malloc_default_zone and malloc_zone_from_ptr return the
sanitizer-installed malloc zone even when MallocStackLogging (MSL) is
requested. This prevents crashes in certain situations. Note that the
sanitizers and MSL cannot be used together. If both are enabled, MSL
functionality is essentially deactivated since it only hooks the default
allocator which is replaced by a custom sanitizer allocator.

rdar://53686175

Reviewed By: kubamracek

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

llvm-svn: 368492
2019-08-09 21:46:32 +00:00
Eric Christopher 11c1847237 Revert "[sanitizers] MSVC warning disable for clean build" and follow-up that tried to fix the build as it's still broken.
This reverts commit 368476 and 368480.

llvm-svn: 368481
2019-08-09 20:43:36 +00:00
Martin Storsjo 96a2b25bcb Fix compilation after SVN r368476
That revision broke compilation with this error:

lib/builtins/fixunsxfdi.c:13:2: error: unterminated conditional directive
 #if !_ARCH_PPC

llvm-svn: 368480
2019-08-09 20:36:00 +00:00
Matthew G McGovern 8e2842cc85 [sanitizers] MSVC warning disable for clean build
- https://reviews.llvm.org/D66023

llvm-svn: 368476
2019-08-09 20:09:46 +00:00
Mitch Phillips cace571c91 Revert "[asan_symbolize] Fix bug where the frame counter was not incremented."
This reverts commit 52a36fae2a.

This commit broke the sanitizer_android buildbot. See comments at
https://reviews.llvm.org/rL368373 for more details.

llvm-svn: 368472
2019-08-09 19:36:41 +00:00
Max Moroz 3653aeeffa [libFuzzer] Merge: print stats after reading the output corpus dir.
Summary:
The purpose is to be able to extract the number of new edges added to
the original (i.e. output) corpus directory after doing the merge. Use case
example: in ClusterFuzz, we do merge after every fuzzing session, to avoid
uploading too many corpus files, and we also record coverage stats at that
point. Having a separate line indicating stats after reading the initial output
corpus directory would make the stats extraction easier for both humans and
parsing scripts.

Context: https://github.com/google/clusterfuzz/issues/802.

Reviewers: morehouse, hctim

Reviewed By: hctim

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

Tags: #llvm, #sanitizers

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

llvm-svn: 368461
2019-08-09 18:20:53 +00:00
Max Moroz f8744ab57a [compiler-rt] FuzzedDataProvider: use C++ headers only instead of a C/C++ mix.
Reviewers: Dor1s

Reviewed By: Dor1s

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

Tags: #llvm, #sanitizers

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

llvm-svn: 368448
2019-08-09 16:00:53 +00:00
Benjamin Kramer 8819a734ae [sanitizer] Update symbolizer/scripts/global_symbols.txt
llvm-svn: 368440
2019-08-09 14:03:30 +00:00
Dan Liew 52a36fae2a [asan_symbolize] Fix bug where the frame counter was not incremented.
Summary:
This bug occurred when a plug-in requested that a binary not be
symbolized while the script is trying to symbolize a stack frame. In
this case `self.frame_no` would not be incremented. This would cause
subsequent stack frames that are symbolized to be incorrectly numbered.

To fix this `get_symbolized_lines()` has been modified to take an
argument that indicates whether the stack frame counter should
incremented. In `process_line_posix()` `get_symbolized_lines(None, ...)`
is now used in in the case where we don't want to symbolize a line so
that we can keep the frame counter increment in a single function.

A test case is included. The test uses a dummy plugin that always asks
`asan_symbolize.py` script to not symbolize the first binary that the
script asks about. Prior to the patch this would cause the output to
script to look something like

```
  #0 0x0
  #0 0x0 in do_access
  #1 0x0 in main
```

rdar://problem/49476995

Reviewers: kubamracek, yln, samsonov, dvyukov, vitalybuka

Subscribers: #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 368373
2019-08-09 00:52:07 +00:00
Peter Collingbourne 3a9059effb hwasan: Add a code model check for tagged globals.
See D65364 for the code model requirements for tagged globals. Because
of the relocations used these requirements cannot be checked at link
time so they must be checked at runtime.

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

llvm-svn: 368351
2019-08-08 21:40:00 +00:00
Max Moroz df3b465c9c [compiler-rt] Add ConsumeProbability and ConsumeFloatingPoint methods to FDP.
Summary:
Also slightly cleaned up the comments and changed the header's extension
back to `.h` as per comments on https://reviews.llvm.org/D65812.

New methods added:

* `ConsumeProbability` returns [0.0, 1.0] by consuming an unsigned integer value
   from the input data and dividing that value by the integer's max value.
* `ConsumeFloatingPointInRange` returns a floating point value in the given
   range. Relies on `ConsumeProbability` method. This method does not have the
   limitation of `std::uniform_real_distribution` that requires the given range
   to be <= the floating point type's max. If the range is too large, this
   implementation will additionally call `ConsumeBool` to decide whether the
   result will be in the first or the second half of the range.
* `ConsumeFloatingPoint` returns a floating point value in the range
  `[std::numeric_limits<T>::lowest(), std::numeric_limits<T>::min()]`.

Tested on Linux, Mac, Windows.


Reviewers: morehouse

Reviewed By: morehouse

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

Tags: #llvm, #sanitizers

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

llvm-svn: 368331
2019-08-08 19:49:37 +00:00
Kamil Rytarowski 42ae6fecd4 Sync ioctl(2) list with NetBSD 9.99.3
Register 36 new ioctl(2) calls.

Enable NVMM for amd64 as the API has been stabilized.

llvm-svn: 368247
2019-08-08 02:21:44 +00:00
Kamil Rytarowski 9d161896a1 Update generate_netbsd_ioctls.awk for NetBSD 9.99.3
Register new ioctl argument types passed in ioctl(2) calls.

llvm-svn: 368246
2019-08-08 02:08:23 +00:00
Douglas Yung 11538f0afa Add LLD as a requirement for hwasan tests because of change in r368111.
llvm-svn: 368242
2019-08-08 01:08:22 +00:00
Kamil Rytarowski 72c940417a Restrict the NetBSD ASan TSD fallback to !ASAN_DYNAMIC
The fallback to the alternative implementation of TSD with TLS
is only needed for the static version of ASan for NetBSD.

The same code cannot be reused for the dynamic version of ASan as
TLS breaks and TSD code works.

llvm-svn: 368219
2019-08-07 21:56:43 +00:00
Mitch Phillips c96387fce3 [HWASan] Use LLD for check-hwasan.
HWASan+globals build fix in rL368111 unfortunately didn't fix the
problem when clang_cflags specified -fuse-ld=ld.gold. Change the order
to force lld in an attempt to fix the Android sanitizer bot.

llvm-svn: 368218
2019-08-07 21:56:21 +00:00
Peter Collingbourne feef101ac2 Require lld for hwasan tests.
We're using relocations that are unsupported by the version of gold on the
bot, so force the use of lld. One of the tests is already using lld,
so this should be safe.

llvm-svn: 368111
2019-08-06 23:43:20 +00:00
Alexander Richardson 0b168ffdc3 [TSAN] Fix tsan on FreeBSD after D54889
Summary:
It appears that since https://reviews.llvm.org/D54889, BackgroundThread()
crashes immediately because cur_thread()-> will return a null pointer
which is then dereferenced. I'm not sure why I only see this issue on
FreeBSD and not Linux since it should also be unintialized on other platforms.

Reviewers: yuri, dvyukov, dim, emaste

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

Tags: #sanitizers, #llvm

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

llvm-svn: 368103
2019-08-06 22:30:48 +00:00
Peter Collingbourne 0930643ff6 hwasan: Instrument globals.
Globals are instrumented by adding a pointer tag to their symbol values
and emitting metadata into a special section that allows the runtime to tag
their memory when the library is loaded.

Due to order of initialization issues explained in more detail in the comments,
shadow initialization cannot happen during regular global initialization.
Instead, the location of the global section is marked using an ELF note,
and we require libc support for calling a function provided by the HWASAN
runtime when libraries are loaded and unloaded.

Based on ideas discussed with @evgeny777 in D56672.

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

llvm-svn: 368102
2019-08-06 22:07:29 +00:00
David Carlier 074a4c6274 [Sanitizer] little typo
llvm-svn: 368093
2019-08-06 21:46:01 +00:00
David Carlier 906e727972 [Sanitizer] Linux explicitally migrate shadow mapping to Transparent Huge Page
in madvise mode, the shadow pages will be migrated only via madvise explicit calls.

Reviewers: vitalybuka

Reviewed By: vitalybuka

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

llvm-svn: 368090
2019-08-06 21:30:03 +00:00
Max Moroz 6c619aadc4 [compiler-rt] Rename FuzzedDataProvider.h to .hpp and other minor changes.
Summary:
.hpp makes more sense for this header as it's C++ only, plus it
contains the actual implementation.

Reviewers: Dor1s

Reviewed By: Dor1s

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

Tags: #llvm, #sanitizers

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

llvm-svn: 368054
2019-08-06 16:02:39 +00:00
Vitaly Buka ac9ee01fcb [compiler-rt] Implement getrandom interception
Summary:
Straightforward implementation of `getrandom` syscall and libc
hooks.

Test Plan: Local MSAN failures caused by uninstrumented `getrandom`
calls stop failing.

Patch by Andrew Krieger.

Reviewers: eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: srhines, kubamracek, dberris, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 367999
2019-08-06 08:41:53 +00:00
Puyan Lotfi 1b3718e609 [compiler-rt] Reverting r367962 due to Fuchsia bot build-breakage.
llvm-svn: 367990
2019-08-06 08:08:07 +00:00
Puyan Lotfi c9d90d5002 [compiler-rt] Appending COMPILER_RT_LIBCXX_PATH -isystem include for xray (3)
Third landing attempt: Added "if (HAVE_LIBCXX)" to keep Green Dragon green.

Haven't found a better way to pass the libcxx include path for building
compiler-rt with libcxx; this seems to be missing only for xray.

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

llvm-svn: 367962
2019-08-06 00:34:34 +00:00
Yi Kong 295d4b7727 Build libfuzzer libcxx-static with PIC
r356153 changed default build option of static libcxx to no PIC. We now
need to explicitly specify CMAKE_POSITION_INDEPENDENT_CODE to get PIC
libcxx.

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

llvm-svn: 367943
2019-08-05 22:55:17 +00:00
Peter Collingbourne e757cadb07 hwasan: Untag global variable addresses in tests.
Once we start instrumenting globals, all addresses including those of string literals
that we pass to the operating system will start being tagged. Since we can't rely
on the operating system to be able to cope with these addresses, we need to untag
them before passing them to the operating system. This change introduces a macro
that does so and uses it everywhere it is needed.

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

llvm-svn: 367938
2019-08-05 21:46:10 +00:00
Eric Christopher 1d73e228db BMI2 support is indicated in bit eight of EBX, not nine.
See Intel SDM, Vol 2A, Table 3-8:
https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-2a-manual.pdf#page=296

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

llvm-svn: 367929
2019-08-05 21:25:59 +00:00
David Carlier 1d92925a5a [Sanitizer] Linux refactor shadow huge page mode handling
Disabling Transparent huge page mode refactored in one function.

Reviewers: vitalybuka

Reviewed By: vitalybuka

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

llvm-svn: 367925
2019-08-05 20:54:36 +00:00
Max Moroz f1b0a93e3a [compiler-rt] Move FDP to include/fuzzer/FuzzedDataProvider.h for easier use.
Summary:
FuzzedDataProvider is a helper class for writing fuzz targets that fuzz
multple inputs simultaneously. The header is supposed to be used for fuzzing
engine agnostic fuzz targets (i.e. the same target can be used with libFuzzer,
AFL, honggfuzz, and other engines). The common thing though is that fuzz targets
are typically compiled with clang, as it provides all sanitizers as well as
different coverage instrumentation modes. Therefore, making this FDP class a
part of the compiler-rt installation package would make it easier to develop
and distribute fuzz targets across different projects, build systems, etc.
Some context also available in https://github.com/google/oss-fuzz/pull/2547.

This CL does not delete the header from `lib/fuzzer/utils` directory in order to
provide the downstream users some time for a smooth migration to the new
header location.

Reviewers: kcc, morehouse

Reviewed By: morehouse

Subscribers: lebedev.ri, kubamracek, dberris, mgorny, delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 367917
2019-08-05 19:55:52 +00:00
Nico Weber 307beb13af compiler-rt: Remove .cc from all lit config files
All cc files have been renamed to cpp now.

llvm-svn: 367911
2019-08-05 19:25:35 +00:00
Nico Weber bb7ad98a47 Follow-up for r367863 and r367656
llvm-svn: 367888
2019-08-05 16:50:56 +00:00
Nico Weber 673dc3d4a0 compiler-rt: Rename cc files below test/asan to cpp
See r367803 and similar other changes.

llvm-svn: 367887
2019-08-05 16:48:12 +00:00
Nico Weber f3750a4420 Try to fix OOB tests more on Windows after r367642
See PR42868 for more details.

The affected list of tests is:

Failing Tests (8):
    AddressSanitizer-Unit :: ./Asan-x86_64-calls-Test.exe/AddressSanitizer.LargeOOBRightTest
    AddressSanitizer-Unit :: ./Asan-x86_64-calls-Test.exe/AddressSanitizer.OOBRightTest
    AddressSanitizer-Unit :: ./Asan-x86_64-calls-Test.exe/AddressSanitizer.OOB_char
    AddressSanitizer-Unit :: ./Asan-x86_64-calls-Test.exe/AddressSanitizer.OOB_int
    AddressSanitizer-Unit :: ./Asan-x86_64-inline-Test.exe/AddressSanitizer.LargeOOBRightTest
    AddressSanitizer-Unit :: ./Asan-x86_64-inline-Test.exe/AddressSanitizer.OOBRightTest
    AddressSanitizer-Unit :: ./Asan-x86_64-inline-Test.exe/AddressSanitizer.OOB_char
    AddressSanitizer-Unit :: ./Asan-x86_64-inline-Test.exe/AddressSanitizer.OOB_int

llvm-svn: 367874
2019-08-05 15:10:15 +00:00
Nico Weber 997d626de6 Try to fix OOB tests on at least Windows after r367642
gtest's built-in regex engine doesn't support (). Looks like it's not
needed, just remove it.

See PR42868 for more details.

llvm-svn: 367873
2019-08-05 15:04:20 +00:00
Nico Weber 74989aff53 compiler-rt: Rename cc files below test/sanitizer_common to cpp
See r367803 and similar other changes.

llvm-svn: 367863
2019-08-05 13:57:03 +00:00
Nico Weber 8b8f66d993 compiler-rt: Rename remaining cc files in test/profile to cpp
See r367803 and similar other changes.

llvm-svn: 367858
2019-08-05 13:42:31 +00:00
Nico Weber 2f7d11be6f More follow-up to r367851
llvm-svn: 367856
2019-08-05 13:27:37 +00:00
Nico Weber 6eed7e7e94 compiler-rt: Rename last few cc files below test/ubsan to cpp
See r367803 and similar other changes.

llvm-svn: 367855
2019-08-05 13:23:38 +00:00
Nico Weber c4310f921d compiler-rt: Rename .cc file in test/dfsan to cpp
See r367849 et al.

llvm-svn: 367854
2019-08-05 13:19:28 +00:00
Nico Weber 53770e78ae compiler-rt: Rename cc files in test/hwasan/TestCases subdirectories as well
Should've been part of r367849.

llvm-svn: 367851
2019-08-05 13:12:23 +00:00
Nico Weber f9e0df071e compiler-rt: Rename .cc file in test/hwasan to .cpp
Like r367463, but for test/hwasan.

llvm-svn: 367849
2019-08-05 13:10:50 +00:00
Fangrui Song 97ccf6b8c1 compiler-rt: Rename .cc file in test/lsan to .cpp
Like r367463, but for test/lsan.

llvm-svn: 367803
2019-08-05 07:04:42 +00:00
Rainer Orth f98a153c8d [sanitizer_common][tests] Fix SanitizerCommon-Unit :: ./Sanitizer-*-Test/SanitizerCommon.PthreadDestructorIterations on Solaris
SanitizerCommon.PthreadDestructorIterations currently FAILs on Solaris:

  [ RUN      ] SanitizerCommon.PthreadDestructorIterations
  /vol/llvm/src/compiler-rt/local/lib/sanitizer_common/tests/sanitizer_posix_test.cc:58: Failure
  Value of: destructor_executed
    Actual: true
  Expected: false
  [  FAILED  ] SanitizerCommon.PthreadDestructorIterations (1 ms)

It turns out that destructor is called 4 times after the first call to SpawnThread, but
5 times after the second.  While PTHREAD_DESTRUCTOR_ITERATIONS is 4 in
<limits.h>, the Solaris pthread_key_create(3C) man page documents

  If, after all the destructors have been called for all keys  with  non-
  null  values,  there  are  still  some  keys  with non-null values, the
  process will be repeated. POSIX requires that this process be  executed
  at   least   PTHREAD_DESTRUCTOR_ITERATIONS  times.  Solaris  calls  the
  destructors repeatedly until all values with associated destructors are
  NULL. Destructors that set new values can cause an infinite loop.

The patch adjusts the test case to allow for this.

Tested on x86_64-pc-solaris2.11.

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

llvm-svn: 367705
2019-08-02 18:55:22 +00:00
Fangrui Song bcaeed49cb compiler-rt: Rename .cc file in test/tsan to .cpp
Like r367463, but for test/tsan.

llvm-svn: 367656
2019-08-02 07:18:07 +00:00
Fangrui Song d21b3d346a compiler-rt: Rename .cc file in test/msan to .cpp
Like r367463, but for test/msan.

llvm-svn: 367653
2019-08-02 06:07:05 +00:00
Fangrui Song 6db8c59f21 compiler-rt: Rename .cc file in test/xray to .cpp
Like r367463, but for test/xray.

Update test/xray/lit.cfg.py config.suffixes to remove .cc (we actually
don't have .c tests now)

llvm-svn: 367652
2019-08-02 05:49:58 +00:00
Vitaly Buka 74296c99b3 Fix flaky test caused by PR42868
llvm-svn: 367642
2019-08-02 02:27:04 +00:00
Nico Weber 4a1a113a99 Remove a few straggler ".cc"s in compiler-rt/lib
llvm-svn: 367589
2019-08-01 17:53:25 +00:00
Nico Weber 4ef767dfe9 try to fix bots more after r367562
llvm-svn: 367587
2019-08-01 17:31:49 +00:00
Nico Weber 558ee6544e try to fix bots after r367562
llvm-svn: 367586
2019-08-01 17:30:41 +00:00
Nico Weber 267d63f80a compiler-rt: Call a generated c++ file in hwasan .cpp instead of .cc
llvm-svn: 367572
2019-08-01 14:48:16 +00:00
Nico Weber 3fa3831830 compiler-rt: Rename .cc file in lib/scudo/standalone/tests to .cpp
Like r367463, but for scudo/standalone/tests.

With this, all files in compiler-rt/lib have extension cpp.

llvm-svn: 367569
2019-08-01 14:38:49 +00:00
Nico Weber 6d46ebefb7 compiler-rt: Rename .cc file in lib/scudo/standalone to .cpp
Like r367463, but for scudo/standalone.

llvm-svn: 367568
2019-08-01 14:36:38 +00:00
Nico Weber d11b16e1fe compiler-rt: Rename .cc file in lib/tsan/{benchmarks,dd,go} to .cpp
Like r367463, but for tsan/{benchmarks,dd,go}.

The files benchmarks aren't referenced in the build anywhere and where added
in 2012 with the comment "no Makefiles yet".

llvm-svn: 367567
2019-08-01 14:30:49 +00:00
Nico Weber 5de29a4b0e compiler-rt: Rename .cc file in lib/tsan/tests/{rtl,unit} to .cpp
Like r367463, but for tsan/tests/{rtl,unit}.

llvm-svn: 367566
2019-08-01 14:26:37 +00:00
Nico Weber 5a3bb1a4d6 compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp
Like r367463, but for tsan/rtl.

llvm-svn: 367564
2019-08-01 14:22:42 +00:00
Nico Weber 1265d0f44c compiler-rt: Rename .cc file in lib/msan/tests to .cpp
Like r367463, but for msan/tests.

llvm-svn: 367563
2019-08-01 14:09:37 +00:00
Nico Weber 60c66db476 compiler-rt: Rename .cc file in lib/msan to .cpp
Like r367463, but for msan.

llvm-svn: 367562
2019-08-01 14:08:18 +00:00
Nico Weber ae1fc9baae compiler-rt: Rename .cc file in lib/lsan to .cpp
Like r367463, but for lsan.

llvm-svn: 367561
2019-08-01 14:01:30 +00:00
Nico Weber 9642e337eb compiler-rt: Rename .cc file in lib/{interception/tests,safestack} to .cpp
Like r367463, but for interception/tests and safestack.

llvm-svn: 367560
2019-08-01 13:56:52 +00:00
Nico Weber b47455b573 compiler-rt: Rename .cc file in lib/asan/tests to .cpp
Like r367463, but for asan/tests

llvm-svn: 367559
2019-08-01 13:48:31 +00:00
Nico Weber 217222abea compiler-rt: Rename .cc file in lib/asan to .cpp
Like r367463, but for asan.

llvm-svn: 367558
2019-08-01 13:43:28 +00:00
Nico Weber c58c1c5350 Try to heal bots more after r367551
llvm-svn: 367555
2019-08-01 13:10:43 +00:00
Nico Weber 208ebc9e8b Try to heal bots after r367551
llvm-svn: 367552
2019-08-01 12:42:28 +00:00
Nico Weber a9aa813792 compiler-rt: Rename .cc file in lib/{dfsan,stats,ubsan_minimal} to .cpp
Like r367463, but for dfsan, stats, ubsan_minimal.

llvm-svn: 367551
2019-08-01 12:41:23 +00:00
Nico Weber bc0d697db9 compiler-rt: Rename .cc file in lib/xray/tests/unit to .cpp
Like r367463, but for xray/texts/unit.

llvm-svn: 367550
2019-08-01 12:35:27 +00:00
Nico Weber b301860321 compiler-rt: Rename .cc file in lib/xray to .cpp
Like r367463, but for xray.

llvm-svn: 367546
2019-08-01 12:30:58 +00:00
Nico Weber 45ff4868c4 compiler-rt: Try to appease lint script.
A bot complains:

/b/sanitizer-x86_64-linux-autoconf/build/llvm/projects/compiler-rt/lib/sanitizer_common/tests/malloc_stress_transfer_test.cpp:2:  Streams are highly discouraged.  [readability/streams] [3]
/b/sanitizer-x86_64-linux-autoconf/build/llvm/projects/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cpp:11:  Streams are highly discouraged.  [readability/streams] [3]
lib/CMakeFiles/SanitizerLintCheck.dir/build.make:57: recipe for target 'lib/CMakeFiles/SanitizerLintCheck' failed

I do not know why this apparently wasn't a problem when the files
had extension .cc.

llvm-svn: 367493
2019-07-31 23:34:07 +00:00
Nico Weber 0e86e7fda3 Attempt to heal bots after r367467
llvm-svn: 367473
2019-07-31 20:12:19 +00:00
Nico Weber c940adeddb compiler-rt: Rename .cc file in lib/sanitizer_common/symbolizer to .cpp
llvm-svn: 367471
2019-07-31 19:41:02 +00:00
Nico Weber f724b460bd Attempt to heal tsan bot after r367463
llvm-svn: 367469
2019-07-31 19:31:36 +00:00
Nico Weber d6d569fc06 compiler-rt: Rename .cc file in lib/sanitizer_common/tests to .cpp
See https://reviews.llvm.org/D58620 for discussion, and for the commands
I ran. In addition I also ran

  for f in $(svn diff | diffstat | grep .cc | cut -f 2 -d ' '); do rg $(basename $f) . ; done

and manually updated references to renamed files found by that.

llvm-svn: 367467
2019-07-31 19:11:14 +00:00
Nico Weber 65492d959b compiler-rt: Rename .cc file in lib/sanitizer_common to .cpp
See https://reviews.llvm.org/D58620 for discussion, and for the commands
I ran. In addition I also ran

  for f in $(svn diff | diffstat | grep .cc | cut -f 2 -d ' '); do rg $f . ; done

and manually updated (many) references to renamed files found by that.

llvm-svn: 367463
2019-07-31 18:51:27 +00:00
Nico Weber b42a1c6967 Attempt to heal bots after r367456
llvm-svn: 367462
2019-07-31 18:43:27 +00:00
Nico Weber 62a0585530 compiler-rt: Rename .cc file in lib/profile to .cpp
See https://reviews.llvm.org/D58620 for discussion.

Note how the comment in the file already said ".cpp" :)

llvm-svn: 367460
2019-07-31 18:21:08 +00:00
Nico Weber ebbce04c14 compiler-rt: Rename .cc files in lib/interception to .cpp.
See https://reviews.llvm.org/D58620 for discussion, and for the commands
I ran. In addition I also ran

  for f in $(svn diff | diffstat | grep .cc | cut -f 2 -d ' '); do rg $f . ; done

and manually updated references to renamed files found by that.

llvm-svn: 367456
2019-07-31 18:01:55 +00:00
Nico Weber 46ba969752 compiler-rt: Rename .cc files in lib/ubsan to .cpp.
See https://reviews.llvm.org/D58620 for discussion, and for the commands
I ran. In addition I also ran

  for f in $(svn diff | diffstat | grep .cc | cut -f 2 -d ' '); do rg $f . ; done

and manually updated references to renamed files found by that.

llvm-svn: 367452
2019-07-31 17:51:05 +00:00
Nico Weber b206c3e3e4 gn build: Add build files for compiler-rt/lib/profile
Differential Revision: https://reviews.llvm.org/D65518

llvm-svn: 367450
2019-07-31 17:15:32 +00:00
Nico Weber e4001bacc2 gn build: Fix redundant object files in builtin lib.
compiler-rt's builtin library has generic implementations of many
functions, and then per-arch optimized implementations of some.

In the CMake build, both filter_builtin_sources() and an explicit loop
at the end of the build file (see D37166) filter out the generic
versions if a per-arch file is present.

The GN build wasn't doing this filtering. Just do the filtering manually
and explicitly, instead of being clever.

While here, also remove files from the mingw/arm build that are
redundantly listed after D39938 / r318139 (both from the CMake and the
GN build).

While here, also fix a target_os -> target_cpu typo.

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

llvm-svn: 367448
2019-07-31 17:08:34 +00:00
Alexander Richardson a4ea27de92 [Sanitizer][ASAN][MSAN] Fix infinite recursion on FreeBSD
Summary:
MSAN was broken on FreeBSD by https://reviews.llvm.org/D55703: after this
change accesses to the key variable call __tls_get_addr, which is
intercepted. The interceptor then calls GetCurrentThread which calls
MsanTSDGet which again calls __tls_get_addr, etc...
Using the default implementation in the SANITIZER_FREEBSD case fixes MSAN
for me.

I then applied the same change to ASAN (introduced in https://reviews.llvm.org/D55596)
but that did not work yet. In the ASAN case, we get infinite recursion
again during initialization, this time because calling pthread_key_create() early on
results in infinite recursion. pthread_key_create() calls sysctlbyname()
which is intercepted but COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED returns
true, so the interceptor calls internal_sysctlbyname() which then ends up
calling the interceptor again. I fixed this issue by using dlsym() to get
the libc version of sysctlbyname() instead.

This fixes https://llvm.org/PR40761

Reviewers: vitalybuka, krytarowski, devnexen, dim, bsdjhb, #sanitizers, MaskRay

Reviewed By: MaskRay

Subscribers: MaskRay, emaste, kubamracek, jfb, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 367442
2019-07-31 16:31:55 +00:00