Commit Graph

12198 Commits

Author SHA1 Message Date
Dan Liew 5be7eb3ab4 [Builtins] Provide a mechanism to selectively disable tests based on whether an implementation is provided by a builtin library.
Summary:
If a platform removes some builtin implementations (e.g. via the
Darwin-excludes mechanism) then this can lead to test failures because
the test expects an implementation to be available.

To solve this lit features are added for each configuration based
on which sources are included in the builtin library. The features
are of the form `librt_has_<name>` where `<name>` is the name of the
source file with the file extension removed. This handles C and
assembly sources.

With the lit features in place it is possible to make certain tests
require them.

Example:

```
REQUIRES: librt_has_comparedf2
```

All top-level tests in `test/builtins/Unit` (i.e. not under
`arm`, `ppc`, and `riscv`) have been annotated with the appropriate
`REQUIRES: librt_has_*` statement.

rdar://problem/55520987

Reviewers: beanz, steven_wu, arphaman, dexonsmith, phosek, thakis

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 375150
2019-10-17 18:12:49 +00:00
Reid Kleckner 0aaa193127 [asan] Update Windows test expectations for LLVM's MS demangler
After r375041 llvm-symbolizer uses it for demangling instead of
UnDecorateSymbolName. LLVM puts spaces after commas while Microsoft does
not.

llvm-svn: 375147
2019-10-17 17:59:11 +00:00
Sam Elliott d4b7a60b92 Revert [Sanitizers] Add support for RISC-V 64-bit
This reverts r375132 (git commit 00bbe990c5)

llvm-svn: 375136
2019-10-17 17:24:28 +00:00
Sam Elliott 00bbe990c5 [Sanitizers] Add support for RISC-V 64-bit
Summary:
This has been tested with gcc trunk on openSUSE Tumbleweed on the HiFive Unleashed.

Patch by Andreas Schwab (schwab)

Reviewers: luismarques

Reviewed By: luismarques

Subscribers: mhorne, emaste, luismarques, asb, mgorny, fedor.sergeev, simoncook, kito-cheng, shiva0217, rogfer01, rkruppe, lenary, s.egerton, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 375132
2019-10-17 16:36:27 +00:00
Zoran Jovanovic 78c78cb5a1 [mips] [builtins] Remove clear_mips_cache
Differential Revision: https://reviews.llvm.org/D69021

llvm-svn: 375110
2019-10-17 12:21:14 +00:00
Dan Liew 8a5bfbe6db [CMake] Disable building all Darwin libraries (except builtins) for macOS i386 when the SDK is >= 10.15.
Summary:
In the macOS 10.15 SDK the ability to link i386 binaries was removed and
in the corresponding OS it is not possible to run macOS i386 binaries.

The consequence of these changes meant that targets like `check-asan`
would fail because:

* Unit tests could not be linked for i386
* Lit tests for i386 would fail due to not being able to execute
  compiled binaries.

The simplest fix to this is to simply disable building for i386 for
macOS when using the 10.15 SDK (or newer). This disables building the
i386 slice for most compiler-rt libraries and consequently disables the
unit and lit tests for macOS i386.

Note that because the `DARWIN_osx_ARCHS` CMake variable is a cache
variable this patch will have no affect on existing builds unless
the existing cache variable is deleted. The simplest way to deal with
this is delete existing builds and just do a fresh configure.

Note this should not affect the builtins which are managed with
the `DARWIN_osx_BUILTIN_ARCHS` CMake cache variable.

For those who wish to force using a particular set of architectures when
using newer SDKs passing `-DDARWIN_osx_ARCHS=i386;x86_64;x86_64h` to
CMake should provide a usable (but completely unsupported) workaround.

rdar://problem/55668535
rdar://problem/47939978

Reviewers: kubamracek, yln, azhar, kcc, dvyukov, vitalybuka, cryptoad, eugenis, thakis, phosek

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 374977
2019-10-16 05:48:39 +00:00
Julian Lettner ecc4680c06 Revert "[ASan] Refine diagnoses messages"
This reverts commit 4d1ecadda5.

llvm-svn: 374965
2019-10-16 02:13:16 +00:00
Julian Lettner 4d1ecadda5 [ASan] Refine diagnoses messages
The provided PC is not reliable in every case, so don't suggest
something that does not make sense.

llvm-svn: 374959
2019-10-16 00:39:09 +00:00
Dmitry Mikulin 034badb312 CFI: wrong type passed to llvm.type.test with multiple inheritance devirtualization.
Differential Revision: https://reviews.llvm.org/D67985

llvm-svn: 374909
2019-10-15 16:32:50 +00:00
Dmitry Vyukov cc2f68ea2d tsan: fix Go ppc64le build
This #define is in the non-Go ppc64le build but not in the Go build.

Reviewed-in: https://reviews.llvm.org/D68046
Author: randall77 (Keith Randall)
llvm-svn: 374868
2019-10-15 08:38:58 +00:00
Jake Ehrlich cde860a1c9 [libFuzzer] Don't prefix absolute paths in fuchsia.
The ExecuteCommand function in fuchsia used to prefix the
getOutputFile for each command run with the artifact_prefix flag if
it was available, because fuchsia components don't have a writable working
directory. However, if a file with a global path is provided, fuchsia
should honor that.

An example of this is using the global /tmp directory to store stuff.
In fuchsia it ended up being translated to data///tmp, whereas we want
to make sure it is using /tmp (which is available to components using the
isolated-temp feature).

To test this I made the change, compiled fuchsia with this toolchain and
ran a fuzzer with the -fork=1 flag (that mode makes use of the /tmp
directory). I also tested that normal fuzzing workflow was not affected
by this.

Author: charco (Marco Vanotti)
Differential Revision: https://reviews.llvm.org/D68774

llvm-svn: 374612
2019-10-11 23:35:13 +00:00
Reid Kleckner 9280d6c178 Fix check-interception link error in compiler-rt debug mode
llvm-svn: 374472
2019-10-10 23:30:54 +00:00
Evgeniy Stepanov 53a53e63c8 Add a missing include in test.
A fix for r373993.

llvm-svn: 374448
2019-10-10 20:47:22 +00:00
Julian Lettner 99c9d7bd63 Reland "[ASan] Do not misrepresent high value address dereferences as null dereferences"
Updated: Removed offending TODO comment.

Dereferences with addresses above the 48-bit hardware addressable range
produce "invalid instruction" (instead of "invalid access") hardware
exceptions (there is no hardware address decoding logic for those bits),
and the address provided by this exception is the address of the
instruction (not the faulting address).  The kernel maps the "invalid
instruction" to SEGV, but fails to provide the real fault address.

Because of this ASan lies and says that those cases are null
dereferences.  This downgrades the severity of a found bug in terms of
security.  In the ASan signal handler, we can not provide the real
faulting address, but at least we can try not to lie.

rdar://50366151

Reviewed By: vitalybuka

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

> llvm-svn: 374265

llvm-svn: 374384
2019-10-10 17:19:58 +00:00
David Carlier 69c9c223a0 [Sanitizers] Fix getrandom test
llvm-svn: 374333
2019-10-10 12:48:18 +00:00
Russell Gallop 38ac46b4bc Fix sanitizer lint check after r374315
llvm-svn: 374321
2019-10-10 12:02:31 +00:00
Roman Lebedev 6430adbe64 [UBSan] Appease linter
llvm-svn: 374316
2019-10-10 11:32:06 +00:00
David Carlier 90c8b59cfc [Sanitizers] Porting getrandom/getentropy interceptors to FreeBSD
- Available from 12.x branch, by the time it lands next year in FreeBSD tree, the 11.x's might be EOL.
- Intentionally changed the getrandom test to C code as with 12.0 (might be fixed in CURRENT since), there is a linkage issue in C++ context.

Reviewers: emaste, dim, vitalybuka

Reviewed-By: vitalybuka

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

llvm-svn: 374315
2019-10-10 11:31:37 +00:00
Roman Lebedev eb8b6fe745 [UBSan] Split nullptr-and-nonzero-offset-variable.c in another direction
llvm-svn: 374309
2019-10-10 11:03:41 +00:00
Russell Gallop c48e0873af Revert "[ASan] Do not misrepresent high value address dereferences as null dereferences"
As it was breaking bots running sanitizer lint check

This reverts r374265 (git b577efe456)

llvm-svn: 374308
2019-10-10 10:56:52 +00:00
Roman Lebedev 5d59f20cc0 [UBSan] Split nullptr-and-nonzero-offset-variable.cpp into C and C++ variants
I do not understand the BB failire, it fully passes locally.

llvm-svn: 374306
2019-10-10 10:41:42 +00:00
Roman Lebedev 3de28b83c2 [UBSan] Revisit nullptr-and-nonzero-offset-variable.cpp test to hopefully make it pass on sanitizer-windows BB
llvm-svn: 374298
2019-10-10 09:51:13 +00:00
Roman Lebedev 536b0ee40a [UBSan][clang][compiler-rt] Applying non-zero offset to nullptr is undefined behaviour
Summary:
Quote from http://eel.is/c++draft/expr.add#4:
```
4     When an expression J that has integral type is added to or subtracted
      from an expression P of pointer type, the result has the type of P.
(4.1) If P evaluates to a null pointer value and J evaluates to 0,
      the result is a null pointer value.
(4.2) Otherwise, if P points to an array element i of an array object x with n
      elements ([dcl.array]), the expressions P + J and J + P
      (where J has the value j) point to the (possibly-hypothetical) array
      element i+j of x if 0≤i+j≤n and the expression P - J points to the
      (possibly-hypothetical) array element i−j of x if 0≤i−j≤n.
(4.3) Otherwise, the behavior is undefined.
```

Therefore, as per the standard, applying non-zero offset to `nullptr`
(or making non-`nullptr` a `nullptr`, by subtracting pointer's integral value
from the pointer itself) is undefined behavior. (*if* `nullptr` is not defined,
i.e. e.g. `-fno-delete-null-pointer-checks` was *not* specified.)

To make things more fun, in C (6.5.6p8), applying *any* offset to null pointer
is undefined, although Clang front-end pessimizes the code by not lowering
that info, so this UB is "harmless".

Since rL369789 (D66608 `[InstCombine] icmp eq/ne (gep inbounds P, Idx..), null -> icmp eq/ne P, null`)
LLVM middle-end uses those guarantees for transformations.
If the source contains such UB's, said code may now be miscompiled.
Such miscompilations were already observed:
* https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20190826/687838.html
* https://github.com/google/filament/pull/1566

Surprisingly, UBSan does not catch those issues
... until now. This diff teaches UBSan about these UB's.

`getelementpointer inbounds` is a pretty frequent instruction,
so this does have a measurable impact on performance;
I've addressed most of the obvious missing folds (and thus decreased the performance impact by ~5%),
and then re-performed some performance measurements using my [[ https://github.com/darktable-org/rawspeed | RawSpeed ]] benchmark:
(all measurements done with LLVM ToT, the sanitizer never fired.)
* no sanitization vs. existing check: average `+21.62%` slowdown
* existing check vs. check after this patch: average `22.04%` slowdown
* no sanitization vs. this patch: average `48.42%` slowdown

Reviewers: vsk, filcab, rsmith, aaron.ballman, vitalybuka, rjmccall, #sanitizers

Reviewed By: rsmith

Subscribers: kristof.beyls, nickdesaulniers, nikic, ychen, dtzWill, xbolva00, dberris, arphaman, rupprecht, reames, regehr, llvm-commits, cfe-commits

Tags: #clang, #sanitizers, #llvm

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

llvm-svn: 374293
2019-10-10 09:25:02 +00:00
Julian Lettner b577efe456 [ASan] Do not misrepresent high value address dereferences as null dereferences
Dereferences with addresses above the 48-bit hardware addressable range
produce "invalid instruction" (instead of "invalid access") hardware
exceptions (there is no hardware address decoding logic for those bits),
and the address provided by this exception is the address of the
instruction (not the faulting address).  The kernel maps the "invalid
instruction" to SEGV, but fails to provide the real fault address.

Because of this ASan lies and says that those cases are null
dereferences.  This downgrades the severity of a found bug in terms of
security.  In the ASan signal handler, we can not provide the real
faulting address, but at least we can try not to lie.

rdar://50366151

Reviewed By: vitalybuka

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

llvm-svn: 374265
2019-10-10 00:33:04 +00:00
Matt Morehouse da6cb7ba4c [sanitizer_common] Remove OnPrint from Go build.
Summary: Go now uses __sanitizer_on_print instead.

Reviewers: vitalybuka, dvyukov

Reviewed By: vitalybuka

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 374258
2019-10-09 22:57:07 +00:00
Jake Ehrlich e7bfce7863 [libFuzzer] Fix Alarm callback in fuchsia.
This patch adds an #if macro to skip the InFuzzingThread() comparison
for fuchsia, similar to what it is done for Windows and NetBSD.

In fuchsia, the alarm callback runs in a separate thread[0], making it fail
the comparison InFuzzingThread(), breaking the -timeout flag.

[0]:
https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp#L323

Author: charco (aka Marco  Vanotti)
Differential Revision: https://reviews.llvm.org/D68166

llvm-svn: 374228
2019-10-09 21:01:50 +00:00
Vitaly Buka ff5a7c4ca6 [sanitizer, NFC] Fix grammar in comment
llvm-svn: 374223
2019-10-09 20:52:39 +00:00
Vitaly Buka 3afc77dbbc [sanitizer] Disable signal_trap_handler on s390
llvm-svn: 374220
2019-10-09 20:48:50 +00:00
Vitaly Buka 39f759189d [sanitizer] Make signal_name a C test
llvm-svn: 374213
2019-10-09 20:22:14 +00:00
Vitaly Buka c3317658cf [sanitizer] Use raise() in test and cover more signals
llvm-svn: 374211
2019-10-09 20:18:27 +00:00
Kostya Kortchinsky f7b1489ffc [scudo][standalone] Get statistics in a char buffer
Summary:
Following up on D68471, this CL introduces some `getStats` APIs to
gather statistics in char buffers (`ScopedString` really) instead of
printing them out right away. Ultimately `printStats` will just
output the buffer, but that allows us to potentially do some work
on the intermediate buffer, and can be used for a `mallocz` type
of functionality. This allows us to pretty much get rid of all the
`Printf` calls around, but I am keeping the function in for
debugging purposes.

This changes the existing tests to use the new APIs when required.

I will add new tests as suggested in D68471 in another CL.

Reviewers: morehouse, hctim, vitalybuka, eugenis, cferris

Reviewed By: morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 374173
2019-10-09 15:09:28 +00:00
Vitaly Buka d5f92e345c [sanitizer] Fix crypt.cpp on Android again
llvm-svn: 374125
2019-10-08 22:09:51 +00:00
Vitaly Buka f3ae951c09 [sanitizer] Fix crypt.cpp test on Darwin
llvm-svn: 374115
2019-10-08 20:50:46 +00:00
Dan Liew 196eae533b Fix `compiler_rt_logbf_test.c` test failure for Builtins-i386-darwin test suite.
Summary:
It seems that compiler-rt's implementation and Darwin
libm's implementation of `logbf()` differ when given a NaN
with raised sign bit. Strangely this behaviour only happens with
i386 Darwin libm. For x86_64 and x86_64h the existing compiler-rt
implementation matched Darwin libm.

To workaround this the `compiler_rt_logbf_test.c` has been modified
to do a comparison on the `fp_t` type and if that fails check if both
values are NaN. If both values are NaN they are equivalent and no
error needs to be raised.

rdar://problem/55565503

Reviewers: rupprecht, scanon, compnerd, echristo
Subscribers: #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D67999

llvm-svn: 374109
2019-10-08 20:06:01 +00:00
Vitaly Buka d8245e7a36 [sanitizer] Disable crypt*.cpp tests on Android
llvm-svn: 374088
2019-10-08 17:06:27 +00:00
David Carlier d80c2520d9 [builtins] Unbreak build on FreeBSD armv7 after D60351
headers include reordering.

Reviewers: phosek, echristo

Reviewed-By: phosek

Differential Revsion: https://reviews.llvm.org/D68045

llvm-svn: 374070
2019-10-08 15:45:35 +00:00
Vitaly Buka 54d767f508 [sanitizer] Fix signal_trap_handler.cpp on android
llvm-svn: 374010
2019-10-08 02:00:53 +00:00
Evgeniy Stepanov 2e2c934762 [msan] Add interceptors: crypt, crypt_r.
Reviewers: vitalybuka

Subscribers: srhines, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373993
2019-10-08 00:00:30 +00:00
Vitaly Buka 2fdec42a16 [tsan, go] fix Go windows build
Summary:
Don't use weak exports when building tsan into a shared library for Go. gcc can't handle the pragmas used to make the weak references.

Include files that have been added since the last update to build.bat. (We should really find a better way to list all the files needed.)

Add windows version defines (WINVER and _WIN32_WINNT) to get AcquireSRWLockExclusive and ReleaseSRWLockExclusive defined.

Define GetProcessMemoryInfo to use the kernel32 version. This is kind of a hack, the windows header files should do this translation for us. I think we're not in the right family partition (we're using Desktop, but that translation only happens for App and System partitions???), but hacking the family partition seems equally gross and I have no idea what the consequences of that might be.

Patch by Keith Randall.

Reviewers: dvyukov, vitalybuka

Reviewed By: vitalybuka

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

Tags: #llvm, #sanitizers

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

llvm-svn: 373984
2019-10-07 23:11:07 +00:00
Vitaly Buka 2059105637 [tsan, go] break commands into multiple lines
Summary: Patch by Keith Randall.

Reviewers: dvyukov, vitalybuka

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

Tags: #llvm, #sanitizers

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

llvm-svn: 373983
2019-10-07 23:04:16 +00:00
Vitaly Buka 9917c76107 [sanitizer] Print SIGTRAP for corresponding signal
Reviewers: eugenis, jfb

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373979
2019-10-07 22:43:19 +00:00
Vitaly Buka 87dd968849 [tsan] Don't delay SIGTRAP handler
Reviewers: eugenis, jfb

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373978
2019-10-07 22:43:17 +00:00
Kostya Kortchinsky bebdab63e8 [scudo][standalone] Correct releaseToOS behavior
Summary:
There was an issue in `releaseToOSMaybe`: one of the criteria to
decide if we should proceed with the release was wrong. Namely:

```
const uptr N = Sci->Stats.PoppedBlocks - Sci->Stats.PushedBlocks;
if (N * BlockSize < PageSize)
  return; // No chance to release anything.
```

I meant to check if the amount of bytes in the free list was lower
than a page, but this actually checks if the amount of **in use** bytes
was lower than a page.

The correct code is:

```
const uptr BytesInFreeList =
  Region->AllocatedUser -
  (Region->Stats.PoppedBlocks - Region->Stats.PushedBlocks) * BlockSize;
if (BytesInFreeList < PageSize)
  return 0; // No chance to release anything.
```

Consequences of the bug:
- if a class size has less than a page worth of in-use bytes (allocated
  or in a cache), reclaiming would not occur, whatever the amount of
  blocks in the free list; in real world scenarios this is unlikely to
  happen and be impactful;
- if a class size had less than a page worth of free bytes (and enough
  in-use bytes, etc), then reclaiming would be attempted, with likely
  no result. This means the reclaiming was overzealous at times.

I didn't have a good way to test for this, so I changed the prototype
of the function to return the number of bytes released, allowing to
get the information needed. The test added fails with the initial
criteria.

Another issue is that `ReleaseToOsInterval` can actually be 0, meaning
we always try to release (side note: it's terrible for performances).
so change a `> 0` check to `>= 0`.

Additionally, decrease the `CanRelease` threshold to `PageSize / 32`.
I still have to make that configurable but I will do it at another time.

Finally, rename some variables in `printStats`: I feel like "available"
was too ambiguous, so change it to "total".

Reviewers: morehouse, hctim, eugenis, vitalybuka, cferris

Reviewed By: morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 373930
2019-10-07 17:37:39 +00:00
Kostya Kortchinsky dc802dbef2 [scudo][standalone] Make malloc_info return a minimal XML
Summary:
Initially, our malloc_info was returning ENOTSUP, but Android would
rather have it return successfully and write a barebone XML to the
stream, so we will oblige.

Add an associated test.

Reviewers: cferris, morehouse, hctim, eugenis, vitalybuka

Reviewed By: morehouse

Subscribers: delcypher, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

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

llvm-svn: 373754
2019-10-04 15:46:34 +00:00
Vitaly Buka bb91a833c6 [compiler-rt] Remove O1 tests from signal_line.cpp
It does not work on arm

llvm-svn: 373702
2019-10-04 07:25:53 +00:00
Vitaly Buka 053391fa86 [compiler-rt] Fix signal_line.cpp test
r373682 committed wrong experimental version

llvm-svn: 373684
2019-10-04 00:43:05 +00:00
Vitaly Buka 57b6536ba1 [compiler-rt] Remove O2, O3 from signal_line test for fix android tests
llvm-svn: 373682
2019-10-04 00:38:08 +00:00
Vitaly Buka 161229eb1b compiler-rt: use __GLIBC_PREREQ for SANITIZER_INTERCEPT_GETRANDOM
Summary: Fixes https://github.com/google/oss-fuzz/issues/2836

Reviewers: eugenis

Subscribers: dberris, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373681
2019-10-04 00:38:07 +00:00
Vitaly Buka 6fb03a290b [compiler-rt] More optimization levels in signal_line.cpp test
llvm-svn: 373642
2019-10-03 18:18:35 +00:00
Vitaly Buka 1fff2881a8 compiler-rt: move all __GLIBC_PREREQ into own header file
Reviewers: eugenis

Subscribers: dberris, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

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

llvm-svn: 373632
2019-10-03 17:46:07 +00:00