Commit Graph

11276 Commits

Author SHA1 Message Date
Kostya Kortchinsky f0fbeaf44a [scudo] Tuning changes based on feedback from current use
Summary:
This tunes several of the default parameters used within the allocator:
- disable the deallocation type mismatch on Android by default; this
  was causing too many issues with third party libraries;
- change the default `SizeClassMap` to `Dense`, it caches less entries
  and is way more memory efficient overall;
- relax the timing of the RSS checks, 10 times per second was too much,
  lower it to 4 times (every 250ms), and update the test so that it
  passes with the new default.

Reviewers: eugenis

Reviewed By: eugenis

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

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

llvm-svn: 352057
2019-01-24 15:56:54 +00:00
Martin Liska acc348aad0 Revert https://reviews.llvm.org/D56485.
llvm-svn: 352033
2019-01-24 08:46:06 +00:00
Martin Liska dc5c81330b Always compare C++ typeinfo (based on libstdc++ implementation).
Differential Revision: https://reviews.llvm.org/D56485.

llvm-svn: 352032
2019-01-24 08:25:36 +00:00
Julian Lettner 0bd6017228 Temporarily deactivate tests; it fails on certain bots
llvm-svn: 352020
2019-01-24 03:51:01 +00:00
Fangrui Song 4d91cf71cc [ubsan] Fix test when isPICDefault() returns false after rCTE352003
llvm-svn: 352013
2019-01-24 02:56:34 +00:00
Julian Lettner cea84ab93a [Sanitizers] UBSan unreachable incompatible with ASan in the presence of `noreturn` calls
Summary:
UBSan wants to detect when unreachable code is actually reached, so it
adds instrumentation before every `unreachable` instruction. However,
the optimizer will remove code after calls to functions marked with
`noreturn`. To avoid this UBSan removes `noreturn` from both the call
instruction as well as from the function itself. Unfortunately, ASan
relies on this annotation to unpoison the stack by inserting calls to
`_asan_handle_no_return` before `noreturn` functions. This is important
for functions that do not return but access the the stack memory, e.g.,
unwinder functions *like* `longjmp` (`longjmp` itself is actually
"double-proofed" via its interceptor). The result is that when ASan and
UBSan are combined, the `noreturn` attributes are missing and ASan
cannot unpoison the stack, so it has false positives when stack
unwinding is used.

Changes:
  # UBSan now adds the `expect_noreturn` attribute whenever it removes
    the `noreturn` attribute from a function
  # ASan additionally checks for the presence of this attribute

Generated code:
```
call void @__asan_handle_no_return    // Additionally inserted to avoid false positives
call void @longjmp
call void @__asan_handle_no_return
call void @__ubsan_handle_builtin_unreachable
unreachable
```

The second call to `__asan_handle_no_return` is redundant. This will be
cleaned up in a follow-up patch.

rdar://problem/40723397

Reviewers: delcypher, eugenis

Tags: #sanitizers

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

llvm-svn: 352003
2019-01-24 01:06:19 +00:00
Peter Collingbourne 020ce3f026 hwasan: Read shadow address from ifunc if we don't need a frame record.
This saves a cbz+cold call in the interceptor ABI, as well as a realign
in both ABIs, trading off a dcache entry against some branch predictor
entries and some code size.

Unfortunately the functionality is hidden behind a flag because ifunc is
known to be broken on static binaries on Android.

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

llvm-svn: 351989
2019-01-23 22:39:11 +00:00
Martin Storsjo b5a5055704 Fix building sanitizers for MinGW
The /EHsc flag is MSVC specific, not generic to the windows target.

llvm-svn: 351927
2019-01-23 07:23:16 +00:00
Peter Collingbourne 73078ecd38 hwasan: Move memory access checks into small outlined functions on aarch64.
Each hwasan check requires emitting a small piece of code like this:
https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html#memory-accesses

The problem with this is that these code blocks typically bloat code
size significantly.

An obvious solution is to outline these blocks of code. In fact, this
has already been implemented under the -hwasan-instrument-with-calls
flag. However, as currently implemented this has a number of problems:
- The functions use the same calling convention as regular C functions.
  This means that the backend must spill all temporary registers as
  required by the platform's C calling convention, even though the
  check only needs two registers on the hot path.
- The functions take the address to be checked in a fixed register,
  which increases register pressure.
Both of these factors can diminish the code size effect and increase
the performance hit of -hwasan-instrument-with-calls.

The solution that this patch implements is to involve the aarch64
backend in outlining the checks. An intrinsic and pseudo-instruction
are created to represent a hwasan check. The pseudo-instruction
is register allocated like any other instruction, and we allow the
register allocator to select almost any register for the address to
check. A particular combination of (register selection, type of check)
triggers the creation in the backend of a function to handle the check
for specifically that pair. The resulting functions are deduplicated by
the linker. The pseudo-instruction (really the function) is specified
to preserve all registers except for the registers that the AAPCS
specifies may be clobbered by a call.

To measure the code size and performance effect of this change, I
took a number of measurements using Chromium for Android on aarch64,
comparing a browser with inlined checks (the baseline) against a
browser with outlined checks.

Code size: Size of .text decreases from 243897420 to 171619972 bytes,
or a 30% decrease.

Performance: Using Chromium's blink_perf.layout microbenchmarks I
measured a median performance regression of 6.24%.

The fact that a perf/size tradeoff is evident here suggests that
we might want to make the new behaviour conditional on -Os/-Oz.
But for now I've enabled it unconditionally, my reasoning being that
hwasan users typically expect a relatively large perf hit, and ~6%
isn't really adding much. We may want to revisit this decision in
the future, though.

I also tried experimenting with varying the number of registers
selectable by the hwasan check pseudo-instruction (which would result
in fewer variants being created), on the hypothesis that creating
fewer variants of the function would expose another perf/size tradeoff
by reducing icache pressure from the check functions at the cost of
register pressure. Although I did observe a code size increase with
fewer registers, I did not observe a strong correlation between the
number of registers and the performance of the resulting browser on the
microbenchmarks, so I conclude that we might as well use ~all registers
to get the maximum code size improvement. My results are below:

Regs | .text size | Perf hit
-----+------------+---------
~all | 171619972  | 6.24%
  16 | 171765192  | 7.03%
   8 | 172917788  | 5.82%
   4 | 177054016  | 6.89%

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

llvm-svn: 351920
2019-01-23 02:20:10 +00:00
Yi Kong 02d85149a0 [builtins] Do not set hidden attribute on Android
Bionic libc relies on an old libgcc behaviour which does not set hidden
visibility attribute. Keep exporting these symbols on Android for 
compatibility.

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

llvm-svn: 351915
2019-01-23 01:59:35 +00:00
Jonathan Metzman 3c535a60dd [libFuzzer][MSVC] Enable building libFuzzer with MSVC
Summary:
Enable building libFuzzer with MSVC.

* Don't try to include <endian.h> in FuzzerSHA1.cpp. MSVC
  doesn't have this header, and WINDOWS is always little
  endian (even on ARM)

Subscribers: srhines, mgorny, javed.absar, kristof.beyls

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

llvm-svn: 351855
2019-01-22 18:59:25 +00:00
Vitaly Buka 096ee9159f [safestack] Return syscalls for mmap, munmap and mprotect
This function can be already intercepted by instrumented code.

llvm-svn: 351783
2019-01-22 05:23:48 +00:00
Vitaly Buka b793d25443 [safestack] Fix NetBSD build
llvm-svn: 351771
2019-01-22 00:39:59 +00:00
Chandler Carruth 4a1b95bda0 Fix typos throughout the license files that somehow I and my reviewers
all missed!

Thanks to Alex Bradbury for pointing this out, and the fact that I never
added the intended `legacy` anchor to the developer policy. Add that
anchor too. With hope, this will cause the links to all resolve
successfully.

llvm-svn: 351731
2019-01-21 09:52:34 +00:00
Eugene Leviant 0d7952ce78 [HWASAN] Improve tag mismatch diagnostics
Reports correct size and tags when either size is not power of two
or offset to bad granule is not zero.

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

llvm-svn: 351730
2019-01-21 09:51:10 +00:00
Vitaly Buka d733430c19 [fuzzer] Fix test checks broken after license header update
llvm-svn: 351717
2019-01-21 02:22:06 +00:00
Vitaly Buka 2b3d8b3286 [safestack] Remove unsupported platforms
llvm-svn: 351716
2019-01-21 02:21:59 +00:00
Vitaly Buka 7ef159dda5 [safestack] Fix FreeBSD runtime build
llvm-svn: 351715
2019-01-21 02:21:51 +00:00
Jonathan Metzman dd467f4f43 [libFuzzer][MSVC] Make Sanitizer Coverage MSVC-compatible
Summary:
Make Sanitizer Coverage work when compiled work when compiler-rt
is compiled with MSVC.

The previous solution did not work for MSVC because MSVC tried to
align the .SCOV$CZ section even though we used
__declspec(align(1)) on its only symbol:
__stop___sancov_cntrs.
Because the counter array is composed
of 1 byte elements, it does not always end on an 8 or 4 byte
boundary. This means that padding was sometimes added to
added to align the next section, .SCOV$CZ.
Use a different strategy now: instead of only instructing
the compiler not to align the symbol, make the section
one byte long by making its only symbol a uint8_t, so that
the linker won't try to align it.

Reviewers: morehouse, rnk

Reviewed By: rnk

Subscribers: kubamracek

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

llvm-svn: 351714
2019-01-21 02:15:29 +00:00
Dan Liew a35df433bf [ASan] On Darwin record global allocator pointer and size in introspection struct.
This implements `mi_extra_init(...)` for the ASan allocator on
Darwin and uses the `__lsan::GetAllocatorGlobalRange(...)` function
to retrieve the allocator pointer and size.

rdar://problem/45284065

llvm-svn: 351713
2019-01-21 01:41:12 +00:00
Dan Liew 5a3857c9b2 On Darwin add allocator address and size fields to
`sanitizer_malloc_introspection_t` and initialize them to zero.

We allow sanitizer implementations to perform different initialization
by defining `COMMON_MALLOC_HAS_EXTRA_INTROSPECTION_INIT` to be `1`
and providing an implementation of `mi_extra_init(...)`.

We use these changes in future patches to implement malloc zone enumeration.

rdar://problem/45284065

llvm-svn: 351712
2019-01-21 01:41:08 +00:00
Dan Liew 4dd0bf9487 On Darwin allow for sanitizer malloc implementations to provide a zone
enumerator.

This is done by defining `COMMON_MALLOC_HAS_ZONE_ENUMERATOR` to `1` and
then by providing an implementation of the `mi_enumerator(...)` function.
If a custom implementation isn't desired the macro is set to `0` which
causes a stub version (that fails) to be used.

Currently all Darwin sanitizers that have malloc implementations define
this to be `0` so there is no functionality change.

rdar://problem/45284065

llvm-svn: 351711
2019-01-21 01:41:01 +00:00
Vitaly Buka 9e23482d4b [safestack] Remove Darwin from supported platforms
r339720 already disabled it in the driver

llvm-svn: 351704
2019-01-20 23:03:10 +00:00
Dan Liew 0e83f5dff1 Fix bug in `AsanAllocatorASVT` (ASan) and `AllocatorASVT` (LSan) templated alias.
We forgot to pass `AddressSpaceView` to the `CombinedAllocator`
which meant we would always use `LocalAddressSpaceView` for the
`CombinedAllocator` leading to a static_assert failing when we
tried to do `AsanAllocatorASVT<RemoteAddressSpaceView>` or
`AllocatorASVT<RemoteAddressSpaceView>`.

rdar://problem/45284065

llvm-svn: 351689
2019-01-20 16:57:24 +00:00
Chandler Carruth 57b08b0944 Update more file headers across all of the LLVM projects in the monorepo
to reflect the new license. These used slightly different spellings that
defeated my regular expressions.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351648
2019-01-19 10:56:40 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Chandler Carruth 469bdefd44 Install new LLVM license structure and new developer policy.
This installs the new developer policy and moves all of the license
files across all LLVM projects in the monorepo to the new license
structure. The remaining projects will be moved independently.

Note that I've left odd formatting and other idiosyncracies of the
legacy license structure text alone to make the diff easier to read.
Critically, note that we do not in any case *remove* the old license
notice or terms, as that remains necessary until we finish the
relicensing process.

I've updated a few license files that refer to the LLVM license to
instead simply refer generically to whatever license the LLVM project is
under, basically trying to minimize confusion.

This is really the culmination of so many people. Chris led the
community discussions, drafted the policy update and organized the
multi-year string of meeting between lawyers across the community to
figure out the strategy. Numerous lawyers at companies in the community
spent their time figuring out initial answers, and then the Foundation's
lawyer Heather Meeker has done *so* much to help refine and get us ready
here. I could keep going on, but I just want to make sure everyone
realizes what a huge community effort this has been from the begining.

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

llvm-svn: 351631
2019-01-19 06:14:24 +00:00
Evgeniy Stepanov c089fbbaf2 [hwasan] Madvise away unused shadow.
Summary:
Whenever a large shadow region is tagged to zero, madvise(DONT_NEED)
as much of it as possible.

This reduces shadow RSS on Android by 45% or so, and total memory use
by 2-4%, probably even more on long running multithreaded programs.
CPU time seems to be in the noise.

Reviewers: kcc, pcc

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 351620
2019-01-19 01:54:09 +00:00
Vitaly Buka 22039df5d1 [safestack] Add ThreadId type as uint64_t
Reviewers: krytarowski, eugenis

Subscribers: llvm-commits

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

llvm-svn: 351607
2019-01-18 22:32:29 +00:00
Vitaly Buka f5ce42c040 [safestack] Remove dependency of SafeStack on sanitizer_common
Summary:
SafeStack needs just few functions from there, but sanitizer_common
introduces conflicts with other runtimes, e.g. SCUDO.

Reviewers: eugenis, kcc, cryptoad

Subscribers: mgorny, krytarowski, fedor.sergeev, jfb, llvm-commits

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

llvm-svn: 351506
2019-01-18 01:53:37 +00:00
Vitaly Buka dbe4b02eeb [safestack] Replace statics with unnamed namespace
Reviewers: eugenis

Subscribers: jfb, llvm-commits

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

llvm-svn: 351503
2019-01-18 01:36:09 +00:00
Peter Collingbourne 48807d0d35 xray: Add missing header to list of installed headers.
Spotted by gn's llvm/utils/gn/build/sync_source_lists_from_cmake.py script.

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

llvm-svn: 351479
2019-01-17 21:11:49 +00:00
Jonathan Metzman b795c31dff [libFuzzer][MSVC] Make attribute-use compatible with MSVC
Summary:
Replace attributes with macros that use equivalent declspecs
for MSVC.

Reviewers: vitalybuka

Reviewed By: vitalybuka

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

llvm-svn: 351456
2019-01-17 16:36:05 +00:00
Dan Liew c7700127ae Fix sanitizer tool list used to generate sanitizer_common tests to be up-to-date.
Summary:
This replaces the sanitizer tool list (used for generating
sanitizer_common configurations) with a tool list derived from
existing build system information.

Previously sanitizer_common had its own list of supported sanitizer
tools. This was bad because it was out of sync with the rest of the
build system. Notably it meant that the sanitizer_common runtime was
only being tested on Darwin the ASan dylib and not the other sanitizer
dylibs that are built for Darwin (LSan, TSan, and UBSan).

Unfortunately enabling the tests against other sanitizer dylibs has lead
to some test failures on Darwin. For now they've been marked as
XFAIL until the failures can investigated properly.

For Windows and Android we use the old sanitizer tool list to try avoid
bot breakages.

rdar://problem/47143078

Reviewers: kubamracek, george.karpenkov, yln, samsonov, vitalybuka, krytarowski

Subscribers: srhines, mgorny, fedor.sergeev, #sanitizers, llvm-commits

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

llvm-svn: 351398
2019-01-16 23:37:31 +00:00
Nico Weber e5653be62a compiler-rt tests: Unbreak cmake with LLVM_ENABLE_PIC=OFF on mac
The LTO target doesn't exist with LLVM_ENABLE_PIC turned off.

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

llvm-svn: 351373
2019-01-16 20:36:27 +00:00
Nico Weber 07d8b321b3 Make compiler-rt CMakeLists.txt formatting a bit more like LLVM's usual formatting
llvm-svn: 351363
2019-01-16 18:12:45 +00:00
Julian Lettner ac855d3ea9 [TSan] Use switches when dealing with enums
Summary:
Small refactoring: replace some if-else cascades with switches so that the compiler warns us about missing cases.
Maybe found a small bug?

Reviewers: dcoughlin, kubamracek, dvyukov, delcypher, jfb

Reviewed By: dvyukov

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 351288
2019-01-16 01:45:12 +00:00
Peter Collingbourne f12c754b02 compiler-rt/test: Bring back -pie on Android.
Looks like the sanitizer-x86_64-linux-android bot started failing
because -pie is still needed when targeting API levels < 16 (which
is the case by default for arm and i686).

llvm-svn: 351270
2019-01-15 22:53:24 +00:00
Jonathan Metzman 9e14cccf6f [libFuzzer] Remove unstable edge handling
Summary:
Remove code for handling unstable edges from libFuzzer since
it has not been found useful.

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

llvm-svn: 351262
2019-01-15 22:12:51 +00:00
Peter Collingbourne 6498fbb22b compiler-rt/test: Add a couple of convenience features for Android.
Add a ANDROID_SERIAL_FOR_TESTING CMake variable. This lets you
run the tests with multiple devices attached without having to set
ANDROID_SERIAL.

Add a mechanism for pushing files to the device. Currently most
sanitizers require llvm-symbolizer and the sanitizer runtime to
be pushed to the device. This lets the sanitizer make this happen
automatically before running the tests by specifying the paths in
the lit.site.cfg file.

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

llvm-svn: 351260
2019-01-15 22:06:48 +00:00
Rong Xu 3e9e7fb961 [profile] Sync up InstrProfData.inc with llvm copy /NFC
llvm-svn: 351257
2019-01-15 21:59:17 +00:00
Peter Collingbourne f6627ce834 compiler-rt/test: Clean up Android specific workarounds in lit.common.cfg.
-pie -Wl,--enable-new-dtags are no longer needed because
the driver passes them by default as of r316606.

Prepend -fuse-ld=gold instead of appending it so that the linker can
be overridden using COMPILER_RT_TEST_COMPILER_CFLAGS.

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

llvm-svn: 351252
2019-01-15 21:27:44 +00:00
Hans Wennborg eb60fbfdb4 Update year in license files
In last year's update (D48219) it was suggested that the release manager
might want to do this, so here we go.

llvm-svn: 351194
2019-01-15 15:10:32 +00:00
David Carlier c5b8eb2714 Revert little bad rebasing.
llvm-svn: 351191
2019-01-15 13:08:20 +00:00
David Carlier bd27e4c156 [Sanitizer] Intercept sl_add api on FreeBSD/NetBSD
Reviewers: krytarowski, vitalybuka

Reviewed By: krytarowski

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

llvm-svn: 351189
2019-01-15 11:21:33 +00:00
Roman Lebedev 0aa9153d48 [compiler-rt] alignment-assumption-blacklist.cpp test apparently passes on android, un-XFAIL it.
llvm-svn: 351184
2019-01-15 10:48:51 +00:00
Roman Lebedev d8bc31a849 [compiler-rt] fuzzer-alignment-assumption.test: fixup the expected column number
llvm-svn: 351181
2019-01-15 10:25:14 +00:00
Roman Lebedev a06ad18669 [compiler-rt][UBSan] Sanitization for alignment assumptions.
Summary:
This is the compiler-rt part.
The clang part is D54589.

This is a second commit, the original one was r351106,
which was mass-reverted in r351159 because 2 compiler-rt tests were failing.

Now, i have fundamentally changed the testing approach:
i malloc a few bytes, intentionally mis-align the pointer
(increment it by one), and check that. Also, i have decreased
the expected alignment. This hopefully should be enough to pacify
all the bots. If not, i guess i might just drop the two 'bad' tests.

Reviewers: filcab, vsk, #sanitizers, vitalybuka, rsmith, morehouse

Reviewed By: morehouse

Subscribers: rjmccall, krytarowski, rsmith, kcc, srhines, kubamracek, dberris, llvm-commits

Tags: #sanitizers

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

llvm-svn: 351178
2019-01-15 09:44:27 +00:00
Dan Liew cf34faa3e5 Explicitly set C++ standard for `Posix/no-fd.cc` ASan test.
Summary:
The test uses `nullptr` which can break running the test if the
compiler happens to be using something older than C++11 as the default
language standard. Avoid this by explicitly setting the standard.

rdar://problem/47253542

Reviewers: eugenis, yln, vitalybuka

Subscribers: kubamracek, #sanitizers, llvm-commits

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

llvm-svn: 351169
2019-01-15 08:54:10 +00:00
Vlad Tsyrklevich 86e68fda3b Revert alignment assumptions changes
Revert r351104-6, r351109, r351110, r351119, r351134, and r351153. These
changes fail on the sanitizer bots.

llvm-svn: 351159
2019-01-15 03:38:02 +00:00
Vlad Tsyrklevich 07d5b7f47e Silence failing tests
r351134 tried to disable these tests by using 'UNSUPPORTED: *' but '*'
is not supported for UNSUPPORTED like it is for XFAIL. Update these
tests to use XFAIL for now in order to silence x86_64-linux and
x86_64-linux-android.

llvm-svn: 351153
2019-01-15 02:22:14 +00:00
Jonathan Metzman a4d569bc19 [libFuzzer][MSVC] Use alternatename for ext functions
Summary:
Use alternatename for external functions only when using
MSVC since Clang doesn't support it and MSVC doesn't support
Clang's method (weak aliases).

Reviewers: morehouse

Reviewed By: morehouse

Subscribers: rnk, thakis, mgorny

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

llvm-svn: 351152
2019-01-15 02:20:53 +00:00
Roman Lebedev deb8089a71 [compiler-rt] UBSan: just completely disable two alignment-assumption tests for now.
And they are faling on clang-cmake-armv7-full too.
*ONLY* these two.
I'm not sure what to make of it.

Perhaps doing a malloc and checking that pointer will
make them fail as expected?

llvm-svn: 351134
2019-01-14 22:44:19 +00:00
Roman Lebedev add3080cb9 [compiler-rt] UBSan: Disable 3 of the new alignment assumption tests on android.
Once again, just like with r338296, these tests seem to only have
failed sanitizer-x86_64-linux-android, so let's just disable them,
since that seems like the pre-established practice here..

To be noted, they failed on some configs there, but not all,
so it is not XFAIL.

llvm-svn: 351119
2019-01-14 21:02:25 +00:00
Shoaib Meenai 6e39af016f [compiler-rt] Add option to disable libc++ build
Having libc++ checked out doesn't necessarily mean it should be built;
for example, the same source tree might be used for multiple build
configurations, and libc++ might not build in some of those
configurations. Add an option to compiler-rt's build to disable building
libc++. This defaults to ON, so it shouldn't change any existing build
configurations.

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

llvm-svn: 351117
2019-01-14 20:33:30 +00:00
Roman Lebedev fd10ac3584 [compiler-rt] Update ubsan_interface.inc with alignment assumption handlers
Somehow this escaped my local testing.
A follow-up for r351106.

llvm-svn: 351110
2019-01-14 19:35:12 +00:00
Michal Gorny 965517fdad [test] Disable sunrpc tests when rpc/xdr.h is missing
Disable tests requiring sunrpc when the relevant headers are missing.
In order to accommodate that, move the header check
from sanitizer_common to base-config-ix, and define the check result
as a global variable there.  Use it afterwards both for definition
needed by sanitizer_common, and to control 'sunrpc' test feature.

While at it, remove the append_have_file_definition macro that was used
only once, and no longer fits the split check-definition.

Bug report: https://github.com/google/sanitizers/issues/974

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

llvm-svn: 351109
2019-01-14 19:18:34 +00:00
Roman Lebedev cc10d54432 [compiler-rt][UBSan] Sanitization for alignment assumptions.
Summary:
This is the compiler-rt part.
The clang part is D54589.

Reviewers: filcab, vsk, #sanitizers, vitalybuka, rsmith, morehouse

Reviewed By: morehouse

Subscribers: rjmccall, krytarowski, rsmith, kcc, srhines, kubamracek, dberris, llvm-commits

Tags: #sanitizers

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

llvm-svn: 351106
2019-01-14 19:09:29 +00:00
Diana Picus 2e3aaed7e7 [asan] Add fallback for Thumb after r350139
This reverts r350806 which marked some tests as UNSUPPORTED on ARM and
instead reintroduces the old code path only for Thumb, since that seems
to be the only target that broke.

It would still be nice to find the root cause of the breakage, but with
the branch point for LLVM 8.0 scheduled for next week it's better to put
things in a stable state while we investigate.

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

llvm-svn: 351040
2019-01-14 09:45:49 +00:00
Evgeniy Stepanov 0df20e893f [sanitizer] Move android's GetPageSize to a header (NFC)
No need to pay function call overhead for a function that returns a
constant.

llvm-svn: 350983
2019-01-12 00:09:24 +00:00
Peter Collingbourne c1fde4fa94 sanitizer_common: Change gen_dynamic_list.py to take a -o argument instead of writing to stdout.
This makes the script a little more gn friendly; gn does not support
redirecting the output of a script.

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

llvm-svn: 350980
2019-01-11 23:30:24 +00:00
Stefan Granitz 8c026e44cf [CMake] Fix standalone build after LLVM exports utility targets
LLVM started exporting targets for utilites with https://reviews.llvm.org/rL350959, which broke compiler-rt standalone builds because it was used to define FileCheck manually.
Changed this, so FileCheck gets imported now.

llvm-svn: 350973
2019-01-11 21:59:58 +00:00
David Carlier d0de9890d3 [Sanitizer] Disable getusershell interception for Android
Reviewers: vitalybuka, pcc, eugenis

Reviewed By: eugenis

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

llvm-svn: 350965
2019-01-11 20:09:24 +00:00
Dan Liew cb09a6f20c Provide storage for `true_type::value` and `false_type::value`.
Summary:
This fixes linker errors that occurs when the
`sanitizer_type_traits_test.cc` is built without optimizations.

The error occurs because the test tries to take a reference.
A possible workaround is to give the GTest macros take boolean rvalues
by doing something like:

```
ASSERT_TRUE(bool(is_same<uptr, uptr>::value));
```

However this only hides the problem. Unfortunately Using `constexpr`
won't fix the problem unless we are using C++17.

Reviewers: vitalybuka, kubamracek, george.karpenkov, yln

Subscribers: mgorny, #sanitizers, llvm-commits

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

llvm-svn: 350940
2019-01-11 17:59:52 +00:00
Matt Morehouse 1d36253fd8 XFAIL getusershell.cc on Android.
Android does not implement [set|get|end]usershell().

llvm-svn: 350935
2019-01-11 17:26:11 +00:00
David Carlier 8a81b29215 [Sanitizer] Intercept getusershell
- If entries are properly copied (there were a bug in FreeBSD implementation in earlier version), or list properly reset.

Reviewers: vitalybuka, krytarowski

Reviewed By: krytarowski

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

llvm-svn: 350919
2019-01-11 05:53:09 +00:00
Julian Lettner 7d1085cbb0 [TSan] Remove ignore_interceptors_accesses flag
Summary:
It has been superseded by the `ignore_noninstrumented_modules` flag and is no longer needed.

Also simplify a test that checks that `mmap_interceptor` respects ignore annotations (`thr->ignore_reads_and_writes `).
Relevant: https://reviews.llvm.org/rL269855

<rdar://problem/46263073> Remove obsolete Apple-specific suppression option

Reviewers: dcoughlin, kubamracek, dvyukov, delcypher

Reviewed By: dvyukov

Subscribers: jfb, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 350883
2019-01-10 20:04:33 +00:00
Michal Gorny 1765839052 [sanitizer_common] Define __sanitizer_FILE on NetBSD
Differential Revision: https://reviews.llvm.org/D56109

llvm-svn: 350882
2019-01-10 19:56:57 +00:00
Michal Gorny 5b2b63e524 [sanitizer_common] Remove support for tirpc/rpc/xdr.h
Remove the partial support for rpc/xdr.h from libtirpc.  Since it is
an entirely external library, we ought to build it sanitized separately
and not attempt to intercept like the libc implementation.  Besides,
the existing code for tirpc support was neither complete nor working.

Noted by @krytarowski.

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

llvm-svn: 350881
2019-01-10 19:56:50 +00:00
Amy Kwan 0b7c9e535b [compiler-rt][builtins][PowerPC] Implemented __floattitf builtin on PowerPC
This patch implements the long double __floattitf (int128_t) method for
PowerPC -- specifically to convert a 128 bit integer into a long double
(IBM double-double).

To invoke this method, one can do so by linking against compiler-rt, via the
--rtlib=compiler-rt command line option supplied to clang.

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

llvm-svn: 350818
2019-01-10 13:23:33 +00:00
Amy Kwan 941dacc360 [compiler-rt][builtins][PowerPC] Implemented __fixunstfti builtin on PowerPC
This patch implements the __uint128_t __fixunstfti (long double) method for
PowerPC -- specifically to convert a long double (IBM double-double) to an
unsigned 128 bit integer.

The general approach of this algorithm is to convert the high and low doubles
of the long double and add them together if the doubles fit within 64 bits.
However, additional adjustments and scaling is performed when the high or low
double does not fit within a 64 bit integer.

To invoke this method, one can do so by linking against compiler-rt, via the
--rtlib=compiler-rt command line option supplied to clang.

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

llvm-svn: 350815
2019-01-10 12:30:12 +00:00
Diana Picus decce55758 [asan] Mark tests as UNSUPPORTED on arm
Temporarily mark a couple of tests as UNSUPPORTED until we figure out
why they fail on the thumb bots.

The failure was introduced in
r350139 - Add support for background thread on NetBSD in ASan.

llvm-svn: 350806
2019-01-10 09:40:56 +00:00
David Carlier c1ba1eec69 i[Sanitizer] Enable pututxline interception
Reviewers: krytarowski

Reviewed By: krytarowski

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

llvm-svn: 350796
2019-01-10 04:19:30 +00:00
Jonathan Metzman 55ddb2c790 [libfuzzer][MSVC] Make calls to builtin functions work with MSVC
Summary:
Replace calls to builtin functions with macros or functions that call the
Windows-equivalents when targeting windows and call the original
builtin functions everywhere else.
This change makes more parts of libFuzzer buildable with MSVC.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: mgorny, rnk, thakis

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

llvm-svn: 350766
2019-01-09 21:46:09 +00:00
David Carlier 5e53818be5 [asan] Disable TSD dtor leak unit tests on FreeBSD x86 64
- Assertion fails in the third iteration.

Reviewers: krytarowski

Reviewed By: krytarowski

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

llvm-svn: 350744
2019-01-09 17:14:57 +00:00
Michal Gorny 2c2d65efab [test] Detect glibc-2.27+ and XFAIL appropriate tests
XFAIL the tests known to fail with glibc-2.27+.  This takes away
the burden of handling known failures from users, and ensures that
we will be verbosely informed when they actually start working again.

Bug report: https://bugs.llvm.org/show_bug.cgi?id=37804

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

llvm-svn: 350717
2019-01-09 13:27:29 +00:00
Peter Collingbourne fdef020d80 hwasan: Ignore loads and stores of size 0.
Now that memory intrinsics are instrumented, it's more likely that
CheckAddressSized will be called with size 0. (It was possible before
with IR like:

  %val = load [0 x i8], [0 x i8]* %ptr

but I don't think clang will generate IR like that and the optimizer
would normally remove it by the time it got anywhere near our pass
anyway). The right thing to do in both cases is to disable the
addressing checks (since the underlying memory intrinsic is a no-op),
so that's what we do.

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

llvm-svn: 350683
2019-01-09 00:44:13 +00:00
David Carlier bfce66fbc1 [Sanitizer] Intercept fdevname on FreeBSD
- Is a file descriptor flavor FreeBSD's specific.
- reentrant version included.

Reviewers: vitalybuka, krytarowski, emaste

Reviewed By: emaste

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

llvm-svn: 350658
2019-01-08 21:49:37 +00:00
Evgeniy Stepanov 43cba99775 Fix Mac compilation.
Provide an implementation of MemoryMappingLayout::Error() for Mac.

llvm-svn: 350601
2019-01-08 02:02:27 +00:00
Evgeniy Stepanov e1caa4ac72 [asan] Support running without /proc
Summary:
This patch lets ASan run when /proc is not accessible (ex. not mounted
yet). It includes a special test-only flag that emulates this condition
in an unpriviledged process.

This only matters on Linux, where /proc is necessary to enumerate
virtual memory mappings.

Reviewers: vitalybuka, pcc, krytarowski

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 350590
2019-01-08 01:07:34 +00:00
Julian Lettner a6d29024ed [TSan] Support Objective-C @synchronized with tagged pointers
Summary:
Objective-C employs tagged pointers, that is, small objects/values may be encoded directly in the pointer bits. The resulting pointer is not backed by an allocation/does not point to a valid memory. TSan infrastructure requires a valid address for `Acquire/Release` and `Mutex{Lock/Unlock}`.
This patch establishes such a mapping via a "dummy allocation" for each encountered tagged pointer value.


Reviewers: dcoughlin, kubamracek, dvyukov, delcypher

Reviewed By: dvyukov

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 350556
2019-01-07 19:19:23 +00:00
Petr Hosek 5c43496fa3 [compiler-rt][Fuchsia] Replace _zx_vmar_allocate_old call
This is the deprecated legacy interface, replace it with the current
_zx_vmar_allocate one.

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

llvm-svn: 350488
2019-01-06 05:19:05 +00:00
Evgeniy Stepanov 045a83231d Revert "Revert "Switch Android from TLS_SLOT_TSAN(8) to TLS_SLOT_SANITIZER(6)""
This reapplies commit r348984.

llvm-svn: 350449
2019-01-05 00:45:14 +00:00
Peter Collingbourne 1c650debd7 Bring back the pthread_create interceptor, but only on non-aarch64.
We still need the interceptor on non-aarch64 to untag the pthread_t
and pthread_attr_t pointers and disable tagging on allocations done
internally by glibc.

llvm-svn: 350445
2019-01-04 23:24:02 +00:00
Peter Collingbourne 714e170648 Disable system-allocator-fallback.cc test on Android O and earlier.
The dynamic loader on Android O appears to have a bug where it crashes
when dlopening DF_1_GLOBAL libraries.

llvm-svn: 350444
2019-01-04 23:10:47 +00:00
Evgeniy Stepanov 9fbc364e16 [sanitizer] Reduce stack depot size on Android.
Summary:
The default setting kTabSizeLog=20 results in an 8Mb global hash table,
almost all of it in private pages. That is not a sane setting in a
mobile, system-wide use case: with ~150 concurrent processes stack
depot will account for more than 1Gb of RAM.

Reviewers: kcc, pcc

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 350443
2019-01-04 22:55:04 +00:00
Peter Collingbourne 87f477b5e4 hwasan: Implement lazy thread initialization for the interceptor ABI.
The problem is similar to D55986 but for threads: a process with the
interceptor hwasan library loaded might have some threads started by
instrumented libraries and some by uninstrumented libraries, and we
need to be able to run instrumented code on the latter.

The solution is to perform per-thread initialization lazily. If a
function needs to access shadow memory or add itself to the per-thread
ring buffer its prologue checks to see whether the value in the
sanitizer TLS slot is null, and if so it calls __hwasan_thread_enter
and reloads from the TLS slot. The runtime does the same thing if it
needs to access this data structure.

This change means that the code generator needs to know whether we
are targeting the interceptor runtime, since we don't want to pay
the cost of lazy initialization when targeting a platform with native
hwasan support. A flag -fsanitize-hwaddress-abi={interceptor,platform}
has been introduced for selecting the runtime ABI to target. The
default ABI is set to interceptor since it's assumed that it will
be more common that users will be compiling application code than
platform code.

Because we can no longer assume that the TLS slot is initialized,
the pthread_create interceptor is no longer necessary, so it has
been removed.

Ideally, lazy initialization should only cost one instruction in the
hot path, but at present the call may cause us to spill arguments
to the stack, which means more instructions in the hot path (or
theoretically in the cold path if the spills are moved with shrink
wrapping). With an appropriately chosen calling convention for
the per-thread initialization function (TODO) the hot path should
always need just one instruction and the cold path should need two
instructions with no spilling required.

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

llvm-svn: 350429
2019-01-04 19:27:04 +00:00
Peter Collingbourne fcbcc6114f hwasan: Use system allocator to realloc and free untagged pointers in interceptor mode.
The Android dynamic loader has a non-standard feature that allows
libraries such as the hwasan runtime to interpose symbols even after
the symbol already has a value. The new value of the symbol is used to
relocate libraries loaded after the interposing library, but existing
libraries keep the old value. This behaviour is activated by the
DF_1_GLOBAL flag in DT_FLAGS_1, which is set by passing -z global to
the linker, which is what we already do to link the hwasan runtime.

What this means in practice is that if we have .so files that depend
on interceptor-mode hwasan without the main executable depending on
it, some of the libraries in the process will be using the hwasan
allocator and some will be using the system allocator, and these
allocators need to interact somehow. For example, if an instrumented
library calls a function such as strdup that allocates memory on
behalf of the caller, the instrumented library can reasonably expect
to be able to call free to deallocate the memory.

We can handle that relatively easily with hwasan by using tag 0 to
represent allocations from the system allocator. If hwasan's realloc
or free functions are passed a pointer with tag 0, the system allocator
is called.

One limitation is that this scheme doesn't work in reverse: if an
instrumented library allocates memory, it must free the memory itself
and cannot pass ownership to a system library. In a future change,
we may want to expose an API for calling the system allocator so
that instrumented libraries can safely transfer ownership of memory
to system libraries.

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

llvm-svn: 350427
2019-01-04 19:21:51 +00:00
Evgeniy Stepanov d398471a63 [hwasan] Switch to 64 allocator with a dense size class map.
Summary:
Replace the 32-bit allocator with a 64-bit one with a non-constant
base address, and reduce both the number of size classes and the maximum
size of per-thread caches.

As measured on [1], this reduces average weighted memory overhead
(MaxRSS) from 26% to 12% over stock android allocator. These numbers
include overhead from code instrumentation and hwasan shadow (i.e. not a
pure allocator benchmark).

This switch also enables release-to-OS functionality, which is not
implemented in the 32-bit allocator. I have not seen any effect from
that on the benchmark.

[1] https://android.googlesource.com/platform/system/extras/+/master/memory_replay/

Reviewers: vitalybuka, kcc

Subscribers: kubamracek, cryptoad, llvm-commits

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

llvm-svn: 350370
2019-01-03 23:19:02 +00:00
Kuba Mracek 66d5d4a3d6 Re-disable the sanitizer_common/TestCases/Posix/getfsent.cc test. Recent macOS versions don't have the /etc/fstab file any more so we cannot test getfsent/setfsent APIs on Darwin.
llvm-svn: 350331
2019-01-03 17:26:29 +00:00
David Carlier 28dab60859 [Sanitizer] Fix typo in funopen unit test.
llvm-svn: 350259
2019-01-02 20:23:47 +00:00
Julian Lettner ff43aa7e43 [TSan] Enable detection of lock-order-inversions for Objective-C @synchronized
Summary:
@synchronized semantics can be synthesized by using existing mutex_[un]lock operations.

```
@synchronized(obj) {
  // ...
}

=> 
{
  mutex_lock(obj);
  // ...
  mutex_unlock(obj);
}
```
Let me know whether you think this a good idea.

Reviewers: dcoughlin, dvyukov, kubamracek, delcypher

Reviewed By: dvyukov

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 350258
2019-01-02 20:10:30 +00:00
David Carlier 5e164b53db [Sanitizer] Disable arc4random seeding apis on for Non NetBSD platforms.
- arc4random_stir / arc4random_addrandom had been made obsolete (and removed) from FreeBSD 12.

Reviewers: krytarowski

Reviewed By: krytarowski

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

llvm-svn: 350249
2019-01-02 19:11:44 +00:00
David Carlier 205b709366 [Sanitizer] Enable funopen on FreeBSD
Reviewers: krytarowski

Reviewed By: krytarowski

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

llvm-svn: 350248
2019-01-02 19:07:27 +00:00
Evgeniy Stepanov f5f1fb594b [sanitizer] Android does not provide <fstab.h>
llvm-svn: 350246
2019-01-02 19:05:26 +00:00
Michal Gorny 3d25e8d9f8 [sanitizer_common] Implement funopen*() interceptors for NetBSD
Differential Revision: https://reviews.llvm.org/D56158

llvm-svn: 350233
2019-01-02 17:37:14 +00:00
Michal Gorny 71a75307ae [sanitizer_common] Implement popen, popenve, pclose interceptors
Implement the interceptors for popen(), pclose() and popenve()
functions.  The first two are POSIX, the third one is specific
to NetBSD.  popen() spawns a process and creates a FILE object piping
data from/to that process.  pclose() closes the pipe and waits for
the process to terminate appropriately.

For the purpose of popen(), the COMMON_INTERCEPTOR_FILE_OPEN macro is
modified to allow null path parameter.

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

llvm-svn: 350232
2019-01-02 17:37:09 +00:00
Michal Gorny 7cab4722d3 [sanitizer_common] Add tests for NetBSD funopen*() functions
Differential Revision: https://reviews.llvm.org/D56154

llvm-svn: 350231
2019-01-02 17:37:04 +00:00
Michal Gorny f2208068dc [sanitizer_common] Add test for popen()
Differential Revision: https://reviews.llvm.org/D56153

llvm-svn: 350230
2019-01-02 17:37:00 +00:00
Michal Gorny eebec78b05 [sanitizer_common] Add tests for more *putc and *getc variants
Add tests for the more character-oriented functions, that is:
- fputc(), putc() and putchar()
- getc_unlocked()
- putc_unlocked() and putchar_unlocked()

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

llvm-svn: 350229
2019-01-02 17:36:55 +00:00