Commit Graph

12994 Commits

Author SHA1 Message Date
Vedant Kumar 8c4a65b9b2 [ubsan] Check implicit casts in ObjC for-in statements
Check that the implicit cast from `id` used to construct the element
variable in an ObjC for-in statement is valid.

This check is included as part of a new `objc-cast` sanitizer, outside
of the main 'undefined' group, as (IIUC) the behavior it's checking for
is not technically UB.

The check can be extended to cover other kinds of invalid casts in ObjC.

Partially addresses: rdar://12903059, rdar://9542496

Differential Revision: https://reviews.llvm.org/D71491
2020-07-13 15:11:18 -07:00
Craig Topper b92c2bb6a2 [X86] Add CPU name strings to getIntelProcessorTypeAndSubtype and getAMDProcessorTypeAndSubtype in compiler-rt.
These aren't used in compiler-rt, but I plan to make a similar
change to the equivalent code in Host.cpp where the mapping from
type/subtype is an unnecessary complication. Having the CPU strings
here will help keep the code somewhat synchronized.
2020-07-12 12:59:25 -07:00
Gui Andrade e54b228408 [Sanitizers] Change protoent test to check for IPv6 instead of RDP
Looks like RDP isn't present on some of LLVM's buildbot machines
2020-07-10 23:50:39 +00:00
Sergej Jaskiewicz 979c5023d3 Revert "[compiler-rt] [test] Use the parent process env as base env in tests"
This reverts commit 5ab446cfe5.

That commit caused memory sanitizer test failures on PowerPC buildbots
2020-07-10 20:01:50 +03:00
Vitaly Buka c06417b24d Fix check-all with -DLLVM_USE_SANITIZER=Address 2020-07-10 01:47:51 -07:00
Danila Kutenin 68c011aa08 [builtins] Optimize udivmodti4 for many platforms.
Summary:
While benchmarking uint128 division we found out that it has huge latency for small divisors

https://reviews.llvm.org/D83027

```
Benchmark                                                   Time(ns)        CPU(ns)     Iterations
--------------------------------------------------------------------------------------------------
BM_DivideIntrinsic128UniformDivisor<unsigned __int128>            13.0           13.0     55000000
BM_DivideIntrinsic128UniformDivisor<__int128>                     14.3           14.3     50000000
BM_RemainderIntrinsic128UniformDivisor<unsigned __int128>         13.5           13.5     52000000
BM_RemainderIntrinsic128UniformDivisor<__int128>                  14.1           14.1     50000000
BM_DivideIntrinsic128SmallDivisor<unsigned __int128>             153            153        5000000
BM_DivideIntrinsic128SmallDivisor<__int128>                      170            170        3000000
BM_RemainderIntrinsic128SmallDivisor<unsigned __int128>          153            153        5000000
BM_RemainderIntrinsic128SmallDivisor<__int128>                   155            155        5000000
```

This patch suggests a more optimized version of the division:

If the divisor is 64 bit, we can proceed with the divq instruction on x86 or constant multiplication mechanisms for other platforms. Once both divisor and dividend are not less than 2**64, we use branch free subtract algorithm, it has at most 64 cycles. After that our benchmarks improved significantly

```
Benchmark                                                   Time(ns)        CPU(ns)     Iterations
--------------------------------------------------------------------------------------------------
BM_DivideIntrinsic128UniformDivisor<unsigned __int128>            11.0           11.0     64000000
BM_DivideIntrinsic128UniformDivisor<__int128>                     13.8           13.8     51000000
BM_RemainderIntrinsic128UniformDivisor<unsigned __int128>         11.6           11.6     61000000
BM_RemainderIntrinsic128UniformDivisor<__int128>                  13.7           13.7     52000000
BM_DivideIntrinsic128SmallDivisor<unsigned __int128>              27.1           27.1     26000000
BM_DivideIntrinsic128SmallDivisor<__int128>                       29.4           29.4     24000000
BM_RemainderIntrinsic128SmallDivisor<unsigned __int128>           27.9           27.8     26000000
BM_RemainderIntrinsic128SmallDivisor<__int128>                    29.1           29.1     25000000
```

If not using divq instrinsics, it is still much better

```
Benchmark                                                   Time(ns)        CPU(ns)     Iterations
--------------------------------------------------------------------------------------------------
BM_DivideIntrinsic128UniformDivisor<unsigned __int128>            12.2           12.2     58000000
BM_DivideIntrinsic128UniformDivisor<__int128>                     13.5           13.5     52000000
BM_RemainderIntrinsic128UniformDivisor<unsigned __int128>         12.7           12.7     56000000
BM_RemainderIntrinsic128UniformDivisor<__int128>                  13.7           13.7     51000000
BM_DivideIntrinsic128SmallDivisor<unsigned __int128>              30.2           30.2     24000000
BM_DivideIntrinsic128SmallDivisor<__int128>                       33.2           33.2     22000000
BM_RemainderIntrinsic128SmallDivisor<unsigned __int128>           31.4           31.4     23000000
BM_RemainderIntrinsic128SmallDivisor<__int128>                    33.8           33.8     21000000
```

PowerPC benchmarks:

Was
```
BM_DivideIntrinsic128UniformDivisor<unsigned __int128>            22.3           22.3     32000000
BM_DivideIntrinsic128UniformDivisor<__int128>                     23.8           23.8     30000000
BM_RemainderIntrinsic128UniformDivisor<unsigned __int128>         22.5           22.5     32000000
BM_RemainderIntrinsic128UniformDivisor<__int128>                  24.9           24.9     29000000
BM_DivideIntrinsic128SmallDivisor<unsigned __int128>             394            394        2000000
BM_DivideIntrinsic128SmallDivisor<__int128>                      397            397        2000000
BM_RemainderIntrinsic128SmallDivisor<unsigned __int128>          399            399        2000000
BM_RemainderIntrinsic128SmallDivisor<__int128>                   397            397        2000000
```

With this patch
```
BM_DivideIntrinsic128UniformDivisor<unsigned __int128>            21.7           21.7     33000000
BM_DivideIntrinsic128UniformDivisor<__int128>                     23.0           23.0     31000000
BM_RemainderIntrinsic128UniformDivisor<unsigned __int128>         21.9           21.9     33000000
BM_RemainderIntrinsic128UniformDivisor<__int128>                  23.9           23.9     30000000
BM_DivideIntrinsic128SmallDivisor<unsigned __int128>              32.7           32.6     23000000
BM_DivideIntrinsic128SmallDivisor<__int128>                       33.4           33.4     21000000
BM_RemainderIntrinsic128SmallDivisor<unsigned __int128>           31.1           31.1     22000000
BM_RemainderIntrinsic128SmallDivisor<__int128>                    33.2           33.2     22000000
```

My email: danilak@google.com, I don't have commit rights

Reviewers: howard.hinnant, courbet, MaskRay

Reviewed By: courbet

Subscribers: steven.zhang, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D81809
2020-07-10 09:59:16 +02:00
Julian Lettner bed3e1a99b [Sanitizer] Update macOS version checking
Support macOS 11 in our runtime version checking code and update
`GetMacosAlignedVersionInternal()` accordingly.  This follows the
implementation of `Triple::getMacOSXVersion()` in the Clang driver.

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D82918
2020-07-09 17:28:01 -07:00
Sergej Jaskiewicz 8372d50508 [compiler-rt] [test] Allow expanding lit substitutions recursively
Summary:
This allows using lit substitutions in the `COMPILER_RT_EMULATOR` variable.

(For reference, the ability to expand substitutions recursively has been introduced in https://reviews.llvm.org/D76178.)

Reviewers: phosek, compnerd

Reviewed By: compnerd

Subscribers: dberris, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D83489
2020-07-09 19:49:18 +03:00
Sergej Jaskiewicz 5ab446cfe5 [compiler-rt] [test] Use the parent process env as base env in tests
Summary:
Right now the lit config builds up an environment that the tests will be run in. However, it does it from scratch instead of adding new variables to the parent process environment. This may (and does) result in strange behavior when running tests with an executor (i. e. with the `COMPILER_RT_EMULATOR` CMake variable set to something), since the executor may need some of the parent process's environment variables.

Here this is fixed.

Reviewers: compnerd, phosek

Reviewed By: compnerd

Subscribers: dberris, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D83486
2020-07-09 19:44:35 +03:00
Sergej Jaskiewicz a89d54fd61 [compiler-rt] Better Windows support for running tests in external shell
Summary:
These changes are necessary to support remote running compiler-rt tests
that were compiled on Windows.

Most of the code here has been copy-pasted from other lit configs.

Why do we remove the conversions to ASCII in the crt config?

We set the `universal_newlines` argument to `True` in `Popen` instead.
This is supported in both Python 2.7 and 3, is easier
(no need to do the `str(dir.decode('ascii'))` dance) and less
error prone.

Also, this is necessary because if the config is executed on Windows,
and `execute_external` is `True`, we take the branch
`if sys.platform in ['win32'] and execute_external`,
and if we use Python 3, then the `dir` variable is a byte-like object,
not str, but the ``replace method on byte-like objects requires its
arguments to also be byte-like objects, which is incompatible with
Python 2 etc etc.

It is a lot simpler to just work with strings in the first place, which
is achieved by setting `universal_newlines` to `True`. As far as
I understand, this way wasn't taken because of the need to support
Python <2.7, but this is not the case now.

Reviewers: compnerd, phosek, weimingz

Reviewed By: compnerd

Subscribers: dberris, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D83485
2020-07-09 19:40:22 +03:00
Eric Christopher 371c94fca0 Fix a typo in an error message. 2020-07-08 20:43:05 -07:00
Gui Andrade 158feabde4 [Sanitizer]: Require !android for protoent test 2020-07-08 23:07:59 +00:00
Gui Andrade 339f1b4903 sanitizers: Add interceptors for getproto{ent,byname,bynumber}_r
This also allows intercepting these getprotoent functions on Linux as
well, since Linux exposes them.

Differential Revision: https://reviews.llvm.org/D82424
2020-07-08 21:41:18 +00:00
Sid Manning baca8f977e [compiler-rt][Hexagon] Remove fma/fmin/max code
This code should reside in the c-library.

Differential Revision: https://reviews.llvm.org/D82263
2020-07-07 19:50:04 -05:00
Dan Liew 8a8d6e2b72 Revert "Temporarily disable the following failing tests on Darwin:"
This reverts commit f3a089506f.

888951aaca introduced a fix that
should make the disabled tests work again.

rdar://problem/62141412
2020-07-07 10:15:46 -07:00
Dan Liew 888951aaca Disable interception of sigaltstack on i386 macOS.
Summary:
28c91219c7 introduced an interceptor for `sigaltstack`. It turns out this
broke `setjmp` on i386 macOS. This is because the implementation of `setjmp` on
i386 macOS is written in assembly and makes the assumption that the call to
`sigaltstack` does not clobber any registers.  Presumably that assumption was
made because it's a system call.  In particular `setjmp`  assumes that before
and after the call that `%ecx` will contain a pointer the `jmp_buf`. The
current interceptor breaks this assumption because it's written in C++ and
`%ecx` is not a callee-saved register. This could be fixed by writing a
trampoline interceptor to the existing interceptor in assembly that
ensures all the registers are preserved. However, this is a lot of work
for very little gain. Instead this patch just disables the interceptor
on i386 macOS.

For other Darwin architectures it currently appears to be safe to intercept
`sigaltstack` using the current implementation because:

* `setjmp` for x86_64 saves the pointer `jmp_buf` to the stack before calling `sigaltstack`.
* `setjmp` for armv7/arm64/arm64_32/arm64e appears to not call `sigaltstack` at all.

This patch should unbreak (once they are re-enabled) the following
tests:

```
AddressSanitizer-Unit :: ./Asan-i386-calls-Test/AddressSanitizer.LongJmpTest
AddressSanitizer-Unit :: ./Asan-i386-calls-Test/AddressSanitizer.SigLongJmpTest
AddressSanitizer-Unit :: ./Asan-i386-inline-Test/AddressSanitizer.LongJmpTest
AddressSanitizer-Unit :: ./Asan-i386-inline-Test/AddressSanitizer.SigLongJmpTest
AddressSanitizer-i386-darwin :: TestCases/longjmp.cpp
```

This patch introduces a `SANITIZER_I386` macro for convenience.

rdar://problem/62141412

Reviewers: kubamracek, yln, eugenis

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

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D82691
2020-07-07 10:15:37 -07:00
Julian Lettner 71a6a41f1c [Sanitizer] Fix demangling for Swift symbol names
The Swift symbol name prefix has changed from `_T0` to `_$s` as
documented here [1].  This prevents Swift names from properly being
symbolicated when using the in-process LLVM symbolizer.  The best way to
fix this seems to be to avoid the duplication of "Is this a Swift symbol
name?" here.  We can simply remove this check as `swift_demangle`
already returns null for non-Swift names [2,3].

The check was included in the initial support for Swift name demangling
to avoid superfluous calls to `dlsym()` [4].  A subsequent commit
changed this logic to retrieve the `swift_demangle` function pointer
eagerly during sanitizer initialization, but did not remove the check
[5].

[1] https://github.com/apple/swift/blob/master/docs/ABI/Mangling.rst
[2] b5a8b518ea/include/swift/Demangling/Demangle.h (L643)
[3] b5a8b518ea/stdlib/public/runtime/Demangle.cpp (L656)
[4] https://reviews.llvm.org/D19135
[5] https://reviews.llvm.org/D20015

rdar://62753845

Reviewers: kubamracek, delcypher, dcoughlin, samsonov, thakis

Reviewed By: kubamracek

Differential Revision: https://reviews.llvm.org/D81705
2020-07-06 12:12:22 -07:00
Amara Emerson 85e144329c [profile] Mark gcov test as unsupported on Darwin. 2020-07-04 10:41:27 -07:00
Fangrui Song 1c6e2eceeb [gcov][test] Add `UNSUPPORTED: host-byteorder-big-endian` to gcov-fork.c
This test strangely failed on ppc64be
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/50913
2020-07-03 17:06:54 -07:00
Fangrui Song fba8523fb5 [gcov][test] Reorganize some compiler-rt/test/profile tests 2020-07-03 16:17:16 -07:00
Vedant Kumar 47481cbffb [test] Deflake test/profile/ContinuousSyncMode/online-merging.c
This test spawns 32 child processes which race to update counters on
shared memory pages. On some Apple-internal machines, two processes race
to perform an update in approximately 0.5% of the test runs, leading to
dropped counter updates. Deflake the test by using atomic increments.

Tested with:

```
$ for I in $(seq 1 1000); do echo ":: Test run $I..."; ./bin/llvm-lit projects/compiler-rt/test/profile/Profile-x86_64h/ContinuousSyncMode/online-merging.c -av || break; done
```

rdar://64956774
2020-07-02 13:31:56 -07:00
Fangrui Song 48c196f5c8 [gcov] Move llvm_writeout_files from atexit to a static destructor
atexit registered functions run earlier so `__attribute__((destructor))`
annotated functions cannot be tracked.

Set a priority of 100 (compatible with GCC 7 onwards) to track
destructors and destructors whose priorities are greater than 100.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7970

Reviewed By: calixte, marco-c

Differential Revision: https://reviews.llvm.org/D82253
2020-07-01 16:41:55 -07:00
Ryan Prichard 3fb48b7088 [compiler-rt][Android] Use correct builtins library name for tests
The builtins library name is special on Android:

 * There is an "-android" suffix.

 * For the compiler-rt i386 architecture, Android targets i686 (in the
   triple and in the builtins library filename)

With this change, check-builtins works with Android.

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D82149
2020-07-01 14:30:25 -07:00
Gui Andrade 05d79295df [Sanitizers] Disable sysmsg interceptors on Android 2020-07-01 18:32:28 +00:00
Gui Andrade cc4d523bb6 sanitizer_common_interceptors: Fix lint errors 2020-07-01 17:33:35 +00:00
Gui Andrade 144e57fc95 [Sanitizers] Implement interceptors for msgsnd, msgrcv
Differential Revision: https://reviews.llvm.org/D82897
2020-06-30 23:48:10 +00:00
Julian Lettner 32791937d7 [Sanitizer] Remove obsolete assert for OS version checking on Darwin
macOS versions do not necessarily start with 10 anymore.  Remove an
obsolete assert.
2020-06-30 13:36:10 -07:00
Anatoly Trosinenko 0ee439b705 [builtins] Change si_int to int in some helper declarations
This patch changes types of some integer function arguments or return values from `si_int` to the default `int` type to make it more compatible with `libgcc`.

The compiler-rt/lib/builtins/README.txt has a link to the [libgcc specification](http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc). This specification has an explicit note on `int`, `float` and other such types being just illustrations in some cases while the actual types are expressed with machine modes.

Such usage of always-32-bit-wide integer type may lead to issues on 16-bit platforms such as MSP430. Provided [libgcc2.h](https://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=libgcc/libgcc2.h;hb=HEAD) can be used as a reference for all targets supported by the libgcc, this patch fixes some existing differences in helper declarations.

This patch is expected to not change behavior at all for targets with 32-bit `int` type.

Differential Revision: https://reviews.llvm.org/D81285
2020-06-30 11:07:02 +03:00
Petr Hosek cf1d044843 [CMake][compiler-rt] Only set lld as available when it was built
The `-fuse-ld=lld` check might succeed because there's a system lld,
but that lld may be out-of-date which would cause any tests that
attempt to use for LTO fail. This was observed on some of the bots.

Differential Revision: https://reviews.llvm.org/D81629
2020-06-29 15:09:05 -07:00
Steven Wu 898b01602b [compiler-rt] Fix mismatched #if/#endif comments
Fix a mismatched #if/#endif comments from my previous commit.
2020-06-26 14:54:35 -07:00
Anatoly Trosinenko a4e8f7fe3f [builtins] Improve compatibility with 16 bit targets
Some parts of existing codebase assume the default `int` type to be (at least) 32 bit wide. On 16 bit targets such as MSP430 this may cause Undefined Behavior or results being defined but incorrect.

Differential Revision: https://reviews.llvm.org/D81408
2020-06-26 15:31:11 +03:00
Steven Wu b2303debfa [compiler-rt] Add support for arm64 macOS
Summary: Allow compiler-rt to build for arm64 support on macOS.

Reviewers: arphaman, doug.gregor, dexonsmith

Reviewed By: arphaman, dexonsmith

Subscribers: dberris, mgorny, kristof.beyls, jkorous, ributzka, danielkiss, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D82610
2020-06-25 16:44:36 -07:00
Anatoly Trosinenko a931ec7ca0 [builtins] Move more float128-related helpers to GENERIC_TF_SOURCES list
There are two different _generic_ lists of source files in the compiler-rt/lib/builtins/CMakeLists.txt. Now there is no simple way to not use the tf-variants of helpers at all.

Since there exists a separate `GENERIC_TF_SOURCES` list, it seems quite natural to move all float128-related helpers there. If it is not possible for some reason, it would be useful to have an explanation of that reason somewhere near the `GENERIC_TF_SOURCES` definition.

Differential Revision: https://reviews.llvm.org/D81282
2020-06-25 22:32:49 +03:00
Hiroshi Yamauchi 9878996c70 Revert "[PGO] Extend the value profile buckets for mem op sizes."
This reverts commit 63a89693f0.

Due to a build failure like http://lab.llvm.org:8011/builders/sanitizer-windows/builds/65386/steps/annotate/logs/stdio
2020-06-25 11:13:49 -07:00
Hiroshi Yamauchi 63a89693f0 [PGO] Extend the value profile buckets for mem op sizes.
Extend the memop value profile buckets to be more flexible (could accommodate a
mix of individual values and ranges) and to cover more value ranges (from 11 to
22 buckets).

Disabled behind a flag (to be enabled separately) and the existing code to be
removed later.

Differential Revision: https://reviews.llvm.org/D81682
2020-06-25 10:22:56 -07:00
Vitaly Buka 8df3e1fd86 Add option to symbolize inline frames for InternalSymbolizer
Summary:
Currently, there is no way to let the `InternalSymbolizer` implemented
functions know if inline frames should be symbolized. This patch updates
the function `__sanitizer_symbolize_code` to include a parameter for
this ASAN option and toggle between LLVM symbolization functions when
appropriate.

Fixes the following two failing tests when internal symbolization is
enabled:
```
SanitizerCommon-*-x86_64-Linux :: print-stack-trace.cpp
SanitizerCommon-*-x86_64-Linux :: symbolize_pc_inline.cpp
```

Reviewers: vitalybuka, kcc, filcab

Reviewed By: vitalybuka

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79280
2020-06-23 19:56:53 -07:00
Gui Andrade 16784c0558 test/msan/sigwait: Don't silently ignore assertion failures
Summary: As the parent process would return 0 independent of whether the child succeeded, assertions in the child would be ignored.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D82400
2020-06-23 14:10:51 -07:00
Craig Topper 23654d9e7a Recommit "[X86] Calculate the needed size of the feature arrays in _cpu_indicator_init and getHostCPUName using the size of the feature enum."
Hopefully this version will fix the previously buildbot failure
2020-06-22 13:32:03 -07:00
Craig Topper bebea4221d Revert "[X86] Calculate the needed size of the feature arrays in _cpu_indicator_init and getHostCPUName using the size of the feature enum."
Seems to breaking build.

This reverts commit 5ac144fe64.
2020-06-22 12:20:40 -07:00
Craig Topper 5ac144fe64 [X86] Calculate the needed size of the feature arrays in _cpu_indicator_init and getHostCPUName using the size of the feature enum.
Move 0 initialization up to the caller so we don't need to know
the size.
2020-06-22 11:46:20 -07:00
Craig Topper 90406d62e5 [X86] Add cooperlake and tigerlake to the enum in cpu_model.c
I forgot to do this when I added then to _cpu_indicator_init.
2020-06-21 16:20:26 -07:00
Craig Topper 0e6c9316d4 [X86] Add cooperlake detection to _cpu_indicator_init.
libgcc has this enum encoding defined for a while, but their
detection code is missing. I've raised a bug with them so that
should get fixed soon.
2020-06-21 13:02:33 -07:00
Craig Topper 35f7d58328 [X86] Set the cpu_vendor in __cpu_indicator_init to VENDOR_OTHER if cpuid isn't supported on the CPU.
We need to set the cpu_vendor to a non-zero value to indicate
that we already called __cpu_indicator_init once.

This should only happen on a 386 or 486 CPU.
2020-06-20 15:36:04 -07:00
Eric Christopher 8116d01905 Typos around a -> an. 2020-06-20 14:04:48 -07:00
Eric Christopher f305176bc6 [cpplint] As part of using inclusive language within the llvm project,
migrate away from the use of blacklist and whitelist.
2020-06-20 00:58:04 -07:00
Fangrui Song 2a4317bfb3 [SanitizeCoverage] Rename -fsanitize-coverage-{white,black}list to -fsanitize-coverage-{allow,block}list
Keep deprecated -fsanitize-coverage-{white,black}list as aliases for compatibility for now.

Reviewed By: echristo

Differential Revision: https://reviews.llvm.org/D82244
2020-06-19 22:22:47 -07:00
Ryan Prichard ac716c0cc4 [builtins][Android] Fix 386->686 adjustment
At this point in this code:
 - COMPILER_RT_DEFAULT_TARGET_TRIPLE is "i686-linux-android"
 - arch is "i386"

The get_compiler_rt_target function currently turns that into:

   i686-android-linux-android

The ${COMPILER_RT_OS_SUFFIX} is "-android" and redundant, so stop
adding it.

The get_compiler_rt_target() function is used for the
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR mode that isn't normally used with
Android.

Differential Revision: https://reviews.llvm.org/D82150
2020-06-19 16:08:20 -07:00
Ryan Prichard 8627190f31 [builtins] Fix typos in comments
Differential Revision: https://reviews.llvm.org/D82146
2020-06-19 16:08:04 -07:00
Vitaly Buka 92f22259e0 [sanitizer] Update global_symbols.txt 2020-06-18 16:55:12 -07:00
Christopher Ferris e7ac984dc0 [scudo][standalone] Allow Primary allocations to fail up multiple times.
Summary:
When enabling some malloc debug features on Android, multiple 32 bit
regions become exhausted, and the allocations fail. Allow allocations
to keep trying each bigger class in the Primary until it finds a fit.
In addition, some Android tests running on 32 bit fail sometimes due
to a running out of space in two regions, and then fail the allocation.

Reviewers: cryptoad

Reviewed By: cryptoad

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D82070
2020-06-18 11:46:39 -07:00
Ian Levesque 7c7c8e0da4 [xray] Option to omit the function index
Summary:
Add a flag to omit the xray_fn_idx to cut size overhead and relocations
roughly in half at the cost of reduced performance for single function
patching.  Minor additions to compiler-rt support per-function patching
without the index.

Reviewers: dberris, MaskRay, johnislarry

Subscribers: hiraditya, arphaman, cfe-commits, #sanitizers, llvm-commits

Tags: #clang, #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D81995
2020-06-17 13:49:01 -04:00
Fangrui Song 70f9cfc857 [builtins][test] Delete unneeded file headers
We don't add file headers to tests. The comments are useless as well -
their purpose can be easily inferred from the filenames.
2020-06-16 17:46:22 -07:00
David Tenty 8aef01eed4 [AIX][compiler-rt] Pick the right form of COMPILER_RT_ALIAS for AIX
Summary: we use the alias attribute, similar to what is done for ELF.

Reviewers: ZarkoCA, jasonliu, hubert.reinterpretcast, sfertile

Reviewed By: jasonliu

Subscribers: dberris, aheejin, mstorsjo, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D81120
2020-06-16 14:10:40 -04:00
Ilya Leoshkevich ccd8b7b103 [LSan] Enable for SystemZ
Summary: Add runtime support, adjust the tests and enable LSan.

Reviewers: vitalybuka, eugenis, uweigand, jonpa

Reviewed By: uweigand

Subscribers: mgorny, cfe-commits, #sanitizers

Tags: #clang, #sanitizers

Differential Revision: https://reviews.llvm.org/D78644
2020-06-16 13:45:29 +02:00
Vitaly Buka 6b4aeec94a [asan] Unpoison signal alternate stack.
Summary:
Before unwinding the stack, `__asan_handle_no_return` is supposed to
unpoison the entire stack - that is, remove the entries in the shadow
memory corresponding to stack (e.g. redzone markers around variables).
This does not work correctly if `__asan_handle_no_return` is called from
the alternate stack used in signal handlers, because the stack top is
read from a cache, which yields the default stack top instead of the
signal alternate stack top.

It is also possible to jump between the default stack and the signal
alternate stack. Therefore, __asan_handle_no_return needs to unpoison
both.

Reviewers: vitalybuka, kubamracek, kcc, eugenis

Reviewed By: vitalybuka

Subscribers: phosek, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76986
2020-06-16 02:28:38 -07:00
Robert Schneider 387e94ca92 [asan] Refactor stack unpoisoning.
Summary: This adds a customization point to support unpoisoning of signal alternate stacks on POSIX.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D81577
2020-06-16 01:52:44 -07:00
Gui Andrade b0ffa8befe [MSAN] Pass Origin by parameter to __msan_warning functions
Summary:
Normally, the Origin is passed over TLS, which seems like it introduces unnecessary overhead. It's in the (extremely) cold path though, so the only overhead is in code size.

But with eager-checks, calls to __msan_warning functions are extremely common, so this becomes a useful optimization.

This can save ~5% code size.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis, vitalybuka

Subscribers: hiraditya, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D81700
2020-06-15 17:49:18 -07:00
Fangrui Song 6c7aebbc01 [msan] Fix comment of __msan::Origin::isHeapOrigin 2020-06-14 23:58:49 -07:00
Craig Topper 033bf61cc5 [X86] Remove brand_id check from cpu_indicator_init.
Brand index was a feature some Pentium III and Pentium 4 CPUs.
It provided an index into a software lookup table to provide a
brand name for the CPU. This is separate from the family/model.

It's unclear to me why this index being non-zero was used to
block checking family/model. None of the CPUs that had a non-zero
brand index are supported by __builtin_cpu_is or target
multi-versioning so this should have no real effect.
2020-06-12 20:35:48 -07:00
Craig Topper 94ccb2acbf [X86] Combine to two feature variables in __cpu_indicator_init into an array and pass them around as pointer we can treat as an array.
This simplifies the indexing code to set and test bits.
2020-06-12 18:30:41 -07:00
Craig Topper e424a3526a [X86] Explicitly initialize __cpu_features2 global in compiler-rt to 0.
Seems like this may be needed in order for the linker to find the
symbol. At least on my Mac.
2020-06-12 18:30:34 -07:00
Vitaly Buka 55ed35ecb9 [sanitizer] Avoid unneeded deferefence 2020-06-11 00:17:32 -07:00
Arthur Eubanks bf124017a2 [NFC] Rename variable to workaround old gcc bug
Summary:
gcc 5.1 is still supported according to
https://releases.llvm.org/10.0.0/docs/GettingStarted.html

We're hitting the following bug due to a variable created in the loop header being the same as a variable used in the loop header:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54430

Reviewers: hctim, pcc

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D81594
2020-06-10 12:14:53 -07:00
Sergej Jaskiewicz c148e15c25 [compiler-rt] [test] Fix NameError when loading lit.cfg.py for crt
Summary:
The `execute_external` global variable is defined in [`lit.common.cfg.py`](fcfb3170a7/compiler-rt/test/lit.common.cfg.py (L18-L27)) and used here (on lines 23 and 39). However, this variable is not visible in configs that are loaded independently.

Explicitly assign it to the correct value to avoid `NameError`.

Reviewers: compnerd, phosek

Reviewed By: compnerd, phosek

Subscribers: dberris, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79892
2020-06-10 13:47:24 +03:00
Vitaly Buka b040e226ed [asan] Suppress lint warning in tests 2020-06-10 03:28:27 -07:00
Vitaly Buka 5a3b380f49 Revert "[InstrProfiling] Use !associated metadata for counters, data and values"
This reverts commit 69c5ff4668.
This reverts commit 603d58b5e4.
This reverts commit ba10bedf56.
This reverts commit 39b3c41b65.
2020-06-10 02:32:50 -07:00
Mitch Phillips e26b25f8b1 [HWASan] Add sizeof(global) in report even if symbols missing.
Summary: Refactor the current global header iteration to be callback-based, and add a feature that reports the size of the global variable during reporting. This allows binaries without symbols to still report the size of the global variable, which is always available in the HWASan globals PT_NOTE metadata.

Reviewers: eugenis, pcc

Reviewed By: pcc

Subscribers: mgorny, llvm-commits, #sanitizers

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D80599
2020-06-09 13:02:13 -07:00
Mehdi Amini d31c9e5a46 Change filecheck default to dump input on failure
Having the input dumped on failure seems like a better
default: I debugged FileCheck tests for a while without knowing
about this option, which really helps to understand failures.

Remove `-dump-input-on-failure` and the environment variable
FILECHECK_DUMP_INPUT_ON_FAILURE which are now obsolete.

Differential Revision: https://reviews.llvm.org/D81422
2020-06-09 18:57:46 +00:00
Petr Hosek 69c5ff4668 [InstrProfiling] Use -fuse-ld=lld in instrprof-gc-sections test
This was accidentally omitted in 603d58b leading to a test failure
on some of the bots that don't use lld as the default linker.
2020-06-08 16:36:14 -07:00
Petr Hosek 603d58b5e4 [InstrProfiling] Use !associated metadata for counters, data and values
The !associated metadata may be attached to a global object declaration
with a single argument that references another global object. This
metadata prevents discarding of the global object in linker GC unless
the referenced object is also discarded.

Furthermore, when a function symbol is discarded by the linker, setting
up !associated metadata allows linker to discard counters, data and
values associated with that function symbol. This is not possible today
because there's metadata to guide the linker. This approach is also used
by other instrumentations like sanitizers.

Note that !associated metadata is only supported by ELF, it does not have
any effect on non-ELF targets.

Differential Revision: https://reviews.llvm.org/D76802
2020-06-08 15:07:43 -07:00
Petr Hosek ba10bedf56 Revert "[InstrProfiling] Use !associated metadata for counters, data and values"
This reverts commit 39b3c41b65 due to
a failing associated.ll test.
2020-06-08 14:38:15 -07:00
Petr Hosek 39b3c41b65 [InstrProfiling] Use !associated metadata for counters, data and values
The !associated metadata may be attached to a global object declaration
with a single argument that references another global object. This
metadata prevents discarding of the global object in linker GC unless
the referenced object is also discarded.

Furthermore, when a function symbol is discarded by the linker, setting
up !associated metadata allows linker to discard counters, data and
values associated with that function symbol. This is not possible today
because there's metadata to guide the linker. This approach is also used
by other instrumentations like sanitizers.

Note that !associated metadata is only supported by ELF, it does not have
any effect on non-ELF targets.

Differential Revision: https://reviews.llvm.org/D76802
2020-06-08 13:35:56 -07:00
Julian Lettner e47c0ef09f [TSan] Revert removal of ignore_interceptors_accesses flag
This flag suppresses TSan FPs on Darwin.  I removed this flag
prematurely and have been dealing with the fallout ever since.

This commit puts back the flag, reverting 7d1085cb [1].

[1] https://reviews.llvm.org/D55075
2020-06-08 12:35:43 -07:00
Dmitry Vyukov fcf6ae2f07 tsan: add OpenBSD support for Go
With the race_debug_openbsd_amd64.syso file created via this diff,
Go's race detector is able to detect a race in the example code
from this link: https://golang.org/doc/articles/race_detector.html

Reviewed-in: https://reviews.llvm.org/D80469
Author: qbit (Aaron Bieber)
2020-06-08 16:47:13 +02:00
Fangrui Song e3200dab60 [gcov] Support .gcno/.gcda in gcov 8, 9 or 10 compatible formats 2020-06-07 11:27:49 -07:00
Fangrui Song b2ffe940b0 [gcov] Fix instrprof-gcov-__gcov_flush-terminate.test 2020-06-07 09:31:52 -07:00
Fangrui Song bfce849d83 [gcov][test] Delete UNSUPPORTED: host-byteorder-big-endian from test/profile tests
It seems that after dc52ce424b, all big-endian problems have been fixed.

01899bb4e4 seems to have fixed XFAIL: * of
profile/instrprof-gcov-__gcov_flush-terminate.test

This essentially reverts commit 5a9b792d72 and
93d5ae3af1.
2020-06-07 08:42:57 -07:00
Fangrui Song e664d0543f [gcov] Improve tests and lower the minimum supported version to gcov 3.4
global-ctor.ll no longer checks what it intended to check
(@_GLOBAL__sub_I_global-ctor.ll needs a !dbg to work).
Rewrite it.

gcov 3.4 and gcov 4.2 use the same format, thus we can lower the version
requirement to 3.4
2020-06-06 23:11:32 -07:00
Fangrui Song cdd683b516 [gcov] Support big-endian .gcno and simplify version handling in .gcda 2020-06-06 11:01:47 -07:00
Evgenii Stepanov d1a6e4d2db [hwasan] Disable malloc-fill by default.
Summary: Non-zero malloc fill is causing way too many hard to debug issues.

Reviewers: kcc, pcc, hctim

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D81284
2020-06-05 11:27:16 -07:00
Arthur Eubanks f59311e31d Mark lambda in use-after-scope-capture.cpp as noinline
Summary:
As explained in https://bugs.llvm.org/show_bug.cgi?id=46208,
symbolization on Windows after inlining and around
lambdas/std::functions doesn't work very well. Under the new pass
manager, there is inlining at -O1.
use-after-scope-capture.cpp checks that the symbolization points to the
line containing "return x;", but the combination of
Windows/inlining/lambdas makes the symbolization point to the line
"f = [&x]() {".

Mark the lambda as noinline since this test is not a test for
symbolization.

Reviewers: hans, dblaikie, vitalybuka

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D81193
2020-06-05 09:03:38 -07:00
Julian Lettner 284934fbc1 Make linter happy 2020-06-04 15:14:48 -07:00
Julian Lettner e9f556526e [Darwin] Add tests for OS version checking
Extract ParseVersion helper function for testing.

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D80761
2020-06-03 17:51:23 -07:00
Julian Lettner eb9ca9da3e Make linter happy
Fixup for ba6b1b4353.
2020-06-03 17:00:33 -07:00
Julian Lettner cab4b3b8e3 Fix bug in newly added VersionBase::operator>=
Fixup for ba6b1b4353.
2020-06-03 15:26:36 -07:00
Julian Lettner ba6b1b4353 [Darwin] Improve runtime OS version checks
Use a struct to represent numerical versions instead of encoding release
names in an enumeration. This avoids the need to extend the enumeration
every time there is a new release.

Rename `GetMacosVersion() -> GetMacosAlignedVersion()` to better reflect
how this is used on non-MacOS platforms.

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D79970
2020-06-03 13:44:11 -07:00
Hiroshi Yamauchi 14bb6770f2 [profile] Sync InstrProfData.inc with llvm.
Reviewers: davidxl

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D81038
2020-06-03 10:00:11 -07:00
kamlesh kumar e31ccee1b0 [RISCV-V] Provide muldi3 builtin assembly implementation
Provides an assembly implementation of muldi3 for RISC-V, to solve bug 43388.
Since the implementation is the same as for mulsi3, that code was moved to
`riscv/int_mul_impl.inc` and is now reused by both `mulsi3.S` and `muldi3.S`.

Differential Revision: https://reviews.llvm.org/D80465
2020-06-02 21:04:55 +01:00
Kostya Serebryany 801d823bde [asan] fix a comment typo 2020-06-01 19:14:56 -07:00
Kostya Serebryany 2e6c3e3e7b add debug code to chase down a rare crash in asan/lsan https://github.com/google/sanitizers/issues/1193
Summary: add debug code to chase down a rare crash in asan/lsan https://github.com/google/sanitizers/issues/1193

Reviewers: vitalybuka

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D80967
2020-06-01 19:14:56 -07:00
Martin Liska b638b63b99
Move internal_uname to #if SANITIZER_LINUX scope.
Remove it from target-specific scope which corresponds
to sanitizer_linux.cpp where it lives in the same macro
scope.

Differential Revision: https://reviews.llvm.org/D80864
2020-06-01 21:04:51 +02:00
Julian Lettner f97a609b17 [Darwin] Add and adopt a way to query the Darwin kernel version
This applies the learnings from [1].  What I intended as a simple
cleanup made me realize that the compiler-rt version checks have two
separate issues:

1) In some places (e.g., mmap flag setting) what matters is the kernel
   version, not the OS version.
2) OS version checks are implemented by querying the kernel version.
   This is not necessarily correct inside the simulators if the
   simulator runtime isn't aligned with the host macOS.

This commit tackles 1) by adopting a separate query function for the
Darwin kernel version.  2) (and cleanups) will be dealt with in
follow-ups.

[1] https://reviews.llvm.org/D78942

rdar://63031937

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D79965
2020-06-01 10:37:03 -07:00
serge-sans-paille af38074874 Fix strict aliasing warning in msan.cpp
Use internal_memcpy instead.

Differential Revision: https://reviews.llvm.org/D80732
2020-06-01 07:42:10 +02:00
Hubert Tong 403d5a5e35 [test][compiler-rt] Avoid LD_PRELOAD for "outer" dynamic linkers
Summary:
This patch moves the setting of `LD_PRELOAD` "inwards" to avoid issues
where the built library needs to be loaded with the dynamic linker that
was configured with the build (and cannot, for example, be loaded by the
dynamic linker associated with the `env` utility).

Reviewed By: vitalybuka, nemanjai, jsji

Differential Revision: https://reviews.llvm.org/D79695
2020-05-31 16:33:42 -04:00
Dan Liew fc532c1a0d Remove some non-determinism from the `Darwin/duplicate_os_log_reports.cpp` test.
The test read from an uninitialized buffer which could cause the output
to be unpredictable.

The test is currently disabled so this won't actually change anything
until the test is re-enabled.
2020-05-30 15:19:32 -07:00
Adrian Herrera 4034d0ce20 [libFuzzer] Fixed description of fuzzer merge control file.
Summary:
The description of the fuzzer merge control file appears to be incorrect/out of date.
No "DONE" line appears in the control file. Rather, FT and COV are the markers that appear
following the STARTED line.

Reviewers: metzman, kcc

Reviewed By: kcc

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D80788
2020-05-29 16:00:26 -07:00
Vitaly Buka 058f5f6fd8 Avoid O_CLOEXEC to allow building on older Linux (RHEL5)
Summary:
See https://github.com/google/sanitizers/issues/1253.

Small patch to enable compilation on (ancient) Red Hat Enterprise Linux 5.

Reviewers: kcc, vitalybuka

Reviewed By: vitalybuka

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D80648
2020-05-29 02:06:53 -07:00
Dan Liew e47e22642f Disable `duplicate_os_log_reports.cpp` test.
It's not passing on macOS green dragon bots. To get them green just
disable for now.

rdar://problem/62141527
2020-05-28 15:57:44 -07:00
Evgenii Stepanov 519959ad82 [scudo] Fix deadlock in ScudoWrappersCTest.DisableForkEnable test.
pthread_cond_wait needs a loop around it to handle spurious wake ups,
as well as the case when signal runs before wait.
2020-05-28 14:31:33 -07:00
Dmitry Vyukov 0969541ffc tsan: disable java_finalizer2 test on darwin
pthread_barrier_t is not supported on darwin.
Do what other tests that use pthread_barrier_t do.
2020-05-28 11:03:02 +02:00
Dan Liew f3a089506f Temporarily disable the following failing tests on Darwin:
AddressSanitizer-Unit :: ./Asan-i386-calls-Test/AddressSanitizer.LongJmpTest
  AddressSanitizer-Unit :: ./Asan-i386-calls-Test/AddressSanitizer.SigLongJmpTest
  AddressSanitizer-Unit :: ./Asan-i386-inline-Test/AddressSanitizer.LongJmpTest
  AddressSanitizer-Unit :: ./Asan-i386-inline-Test/AddressSanitizer.SigLongJmpTest

These failures will be examined properly when time permits.

rdar://problem/62141412
2020-05-27 19:32:06 -07:00
Dmitry Vyukov d24dd2b279 tsan: fix test in debug mode
sanitizer-x86_64-linux-autoconf has failed after the previous tsan commit:

FAIL: ThreadSanitizer-x86_64 :: java_finalizer2.cpp (245 of 403)
******************** TEST 'ThreadSanitizer-x86_64 :: java_finalizer2.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';      /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/./bin/clang  --driver-mode=g++ -fsanitize=thread -Wall  -m64   -gline-tables-only -I/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/test/tsan/../ -std=c++11 -I/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/test/tsan/../ -nostdinc++ -I/b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/tools/clang/runtime/compiler-rt-bins/lib/tsan/libcxx_tsan_x86_64/include/c++/v1 -O1 /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/test/tsan/java_finalizer2.cpp -o /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/tools/clang/runtime/compiler-rt-bins/test/tsan/X86_64Config/Output/java_finalizer2.cpp.tmp &&  /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/tools/clang/runtime/compiler-rt-bins/test/tsan/X86_64Config/Output/java_finalizer2.cpp.tmp 2>&1 | FileCheck /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/test/tsan/java_finalizer2.cpp
--
Exit Code: 1

Command Output (stderr):
--
/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/test/tsan/java_finalizer2.cpp:82:11: error: CHECK: expected string not found in input
// CHECK: DONE
          ^
<stdin>:1:1: note: scanning from here
FATAL: ThreadSanitizer CHECK failed: /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/tsan/rtl/tsan_sync.cpp:69 "((*meta)) == ((0))" (0x4000003e, 0x0)
^
<stdin>:5:12: note: possible intended match here
 #3 __tsan::OnUserAlloc(__tsan::ThreadState*, unsigned long, unsigned long, unsigned long, bool) /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/tsan/rtl/tsan_mman.cpp:225:16 (java_finalizer2.cpp.tmp+0x4af407)
           ^

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-autoconf/builds/51143/steps/test%20tsan%20in%20debug%20compiler-rt%20build/logs/stdio

Fix heap object overlap by offsetting java heap as other tests are doing.
2020-05-27 21:48:39 +02:00
Dmitry Vyukov 4408eeed0f tsan: fix false positives in AcquireGlobal
Add ThreadClock:: global_acquire_ which is the last time another thread
has done a global acquire of this thread's clock.

It helps to avoid problem described in:
https://github.com/golang/go/issues/39186
See test/tsan/java_finalizer2.cpp for a regression test.
Note the failuire is _extremely_ hard to hit, so if you are trying
to reproduce it, you may want to run something like:
$ go get golang.org/x/tools/cmd/stress
$ stress -p=64 ./a.out

The crux of the problem is roughly as follows.
A number of O(1) optimizations in the clocks algorithm assume proper
transitive cumulative propagation of clock values. The AcquireGlobal
operation may produce an inconsistent non-linearazable view of
thread clocks. Namely, it may acquire a later value from a thread
with a higher ID, but fail to acquire an earlier value from a thread
with a lower ID. If a thread that executed AcquireGlobal then releases
to a sync clock, it will spoil the sync clock with the inconsistent
values. If another thread later releases to the sync clock, the optimized
algorithm may break.

The exact sequence of events that leads to the failure.
- thread 1 executes AcquireGlobal
- thread 1 acquires value 1 for thread 2
- thread 2 increments clock to 2
- thread 2 releases to sync object 1
- thread 3 at time 1
- thread 3 acquires from sync object 1
- thread 1 acquires value 1 for thread 3
- thread 1 releases to sync object 2
- sync object 2 clock has 1 for thread 2 and 1 for thread 3
- thread 3 releases to sync object 2
- thread 3 sees value 1 in the clock for itself
  and decides that it has already released to the clock
  and did not acquire anything from other threads after that
  (the last_acquire_ check in release operation)
- thread 3 does not update the value for thread 2 in the clock from 1 to 2
- thread 4 acquires from sync object 2
- thread 4 detects a false race with thread 2
  as it should have been synchronized with thread 2 up to time 2,
  but because of the broken clock it is now synchronized only up to time 1

The global_acquire_ value helps to prevent this scenario.
Namely, thread 3 will not trust any own clock values up to global_acquire_
for the purposes of the last_acquire_ optimization.

Reviewed-in: https://reviews.llvm.org/D80474
Reported-by: nvanbenschoten (Nathan VanBenschoten)
2020-05-27 16:27:47 +02:00
Jinsong Ji 5ee902bb5f [compiler-rt][asan] Add noinline to use-after-scope testcases
Some testcases are unexpectedly passing with NPM.
This is because the target functions are inlined in NPM.

I think we should add noinline attribute to keep these test points.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D79648
2020-05-27 14:05:02 +00:00
Kazushi (Jam) Marukawa dedaf3a2ac [VE] Dynamic stack allocation
Summary:
This patch implements dynamic stack allocation for the VE target. Changes:
* compiler-rt: `__ve_grow_stack` to request stack allocation on the VE.
* VE: base pointer support, dynamic stack allocation.

Differential Revision: https://reviews.llvm.org/D79084
2020-05-27 10:11:06 +02:00
Jinsong Ji a7141480fb [compiler-rt][NFC]Fix Wdeprecated warnings for fsanitize-coverage
A few testcases are still using deprecated options.

warning: argument '-fsanitize-coverage=[func|bb|edge]' is deprecated,
use '-fsanitize-coverage=[func|bb|edge],[trace-pc-guard|trace-pc]'
instead [-Wdeprecated]

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D79741
2020-05-27 02:37:30 +00:00
Marco Elver 14de6e29b1 [Clang][Driver] Add Bounds and Thread to SupportsCoverage list
Summary:
This permits combining -fsanitize-coverage with -fsanitize=bounds or
-fsanitize=thread. Note that, GCC already supports combining these.

Tested:
- Add Clang end-to-end test checking IR is generated for both combinations
of sanitizers.
- Several previously failing TSAN tests now pass.

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

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: #sanitizers, dvyukov, nickdesaulniers, cfe-commits

Tags: #clang, #sanitizers

Differential Revision: https://reviews.llvm.org/D79628
2020-05-26 13:36:21 -07:00
Kostya Serebryany 2e82492540 [fuzzer][afl] Fix build with GCC
Summary:
Fixes this build error with GCC 9.3.0:

```
../lib/fuzzer/afl/afl_driver.cpp:114:30: error: expected unqualified-id before string constant
  114 | __attribute__((weak)) extern "C" void __sanitizer_set_report_fd(void *);
      |                              ^~~
```

Reviewers: metzman, kcc

Reviewed By: kcc

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D80479
2020-05-26 11:35:50 -07:00
Craig Topper 2bb822bc90 [X86] Add family/model for Intel Comet Lake CPUs for -march=native and function multiversioning
This adds the family/model returned by CPUID for some Intel
Comet Lake CPUs. Instruction set and tuning wise these are
the same as "skylake".

These are not in the Intel SDM yet, but these should be correct.
2020-05-24 00:29:25 -07:00
Craig Topper 95bc21f32f [X86] Add avx512vp2intersect feature to compiler-rt's feature detection to match libgcc. 2020-05-21 21:54:54 -07:00
Matt Morehouse 353e5aa42d [libFuzzer] Fix leak in unit test. 2020-05-21 09:02:22 -07:00
Julian Lettner b3ca4f3431 [Darwin] Remove obsolete OS version checks
The oldest supported deployment target currently is 10.7 [1].  We can
remove a few outdated checks.

[1] 3db893b371/compiler-rt/cmake/config-ix.cmake (L397)

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D79958
2020-05-20 19:46:41 -07:00
Matt Morehouse 8817e6ab31 [sanitizer_symbolizer] Add __isinf to symbols list. 2020-05-20 12:39:40 -07:00
Amy Huang b11c2e2feb Add some dependencies to the compiler-rt symbolizer build 2020-05-20 10:01:42 -07:00
Jinsong Ji 8d0fdd44ee [compiler-rt][scudo][LIT] Use target_suffix instead of target-arch
Per target runtime dir may change the suffix of shared libs.
We can not assume we are always building with per_target_runtime_dir on.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D80243
2020-05-20 03:34:50 +00:00
Dan Liew 5811f3a9f8 [asan_symbolize] Fix bug handling C++ symbols when using Atos.
Summary:
The previous code tries to strip out parentheses and anything in between
them. I'm guessing the idea here was to try to drop any listed arguments
for the function being symbolized. Unfortunately this approach is broken
in several ways.

* Templated functions may contain parentheses. The existing approach
messes up these names.
* In C++ argument types are part of a function's signature for the
purposes of overloading so removing them could be confusing.

Fix this simply by not trying to adjust the function name that comes
from `atos`.

A test case is included.

Without the change the test case produced output like:

```
WRITE of size 4 at 0x6060000001a0 thread T0
    #0 0x10b96614d in IntWrapper<void >::operator=> const&) asan-symbolize-templated-cxx.cpp:10
    #1 0x10b960b0e in void writeToA<IntWrapper<void > >>) asan-symbolize-templated-cxx.cpp:30
    #2 0x10b96bf27 in decltype>)>> >)) std::__1::__invoke<void >), IntWrapper<void > >>), IntWrapper<void >&&) type_traits:4425
    #3 0x10b96bdc1 in void std::__1::__invoke_void_return_wrapper<void>::__call<void >), IntWrapper<void > >>), IntWrapper<void >&&) __functional_base:348
    #4 0x10b96bd71 in std::__1::__function::__alloc_func<void >), std::__1::allocator<void >)>, void >)>::operator>&&) functional:1533
    #5 0x10b9684e2 in std::__1::__function::__func<void >), std::__1::allocator<void >)>, void >)>::operator>&&) functional:1707
    #6 0x10b96cd7b in std::__1::__function::__value_func<void >)>::operator>&&) const functional:1860
    #7 0x10b96cc17 in std::__1::function<void >)>::operator>) const functional:2419
    #8 0x10b960ca6 in Foo<void >), IntWrapper<void > >::doCall>) asan-symbolize-templated-cxx.cpp:44
    #9 0x10b96088b in main asan-symbolize-templated-cxx.cpp:54
    #10 0x7fff6ffdfcc8 in start (in libdyld.dylib) + 0
```

Note how the symbol names for the frames are messed up (e.g. #8, #1).

With the patch the output looks like:

```
WRITE of size 4 at 0x6060000001a0 thread T0
    #0 0x10005214d in IntWrapper<void (int)>::operator=(IntWrapper<void (int)> const&) asan-symbolize-templated-cxx.cpp:10
    #1 0x10004cb0e in void writeToA<IntWrapper<void (int)> >(IntWrapper<void (int)>) asan-symbolize-templated-cxx.cpp:30
    #2 0x100057f27 in decltype(std::__1::forward<void (*&)(IntWrapper<void (int)>)>(fp)(std::__1::forward<IntWrapper<void (int)> >(fp0))) std::__1::__invoke<void (*&)(IntWrapper<void (int)>), IntWrapper<void (int)> >(void (*&)(IntWrapper<void (int)>), IntWrapper<void (int)>&&) type_traits:4425
    #3 0x100057dc1 in void std::__1::__invoke_void_return_wrapper<void>::__call<void (*&)(IntWrapper<void (int)>), IntWrapper<void (int)> >(void (*&)(IntWrapper<void (int)>), IntWrapper<void (int)>&&) __functional_base:348
    #4 0x100057d71 in std::__1::__function::__alloc_func<void (*)(IntWrapper<void (int)>), std::__1::allocator<void (*)(IntWrapper<void (int)>)>, void (IntWrapper<void (int)>)>::operator()(IntWrapper<void (int)>&&) functional:1533
    #5 0x1000544e2 in std::__1::__function::__func<void (*)(IntWrapper<void (int)>), std::__1::allocator<void (*)(IntWrapper<void (int)>)>, void (IntWrapper<void (int)>)>::operator()(IntWrapper<void (int)>&&) functional:1707
    #6 0x100058d7b in std::__1::__function::__value_func<void (IntWrapper<void (int)>)>::operator()(IntWrapper<void (int)>&&) const functional:1860
    #7 0x100058c17 in std::__1::function<void (IntWrapper<void (int)>)>::operator()(IntWrapper<void (int)>) const functional:2419
    #8 0x10004cca6 in Foo<void (IntWrapper<void (int)>), IntWrapper<void (int)> >::doCall(IntWrapper<void (int)>) asan-symbolize-templated-cxx.cpp:44
    #9 0x10004c88b in main asan-symbolize-templated-cxx.cpp:54
    #10 0x7fff6ffdfcc8 in start (in libdyld.dylib) + 0
```

rdar://problem/58887175

Reviewers: kubamracek, yln

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79597
2020-05-19 16:08:09 -07:00
Matt Morehouse e2e38fca64 Entropic: Boosting LibFuzzer Performance
Summary:
This is collaboration between Marcel Boehme @ Monash, Australia and Valentin Manès plus Sang Kil Cha @ KAIST, South Korea.

We have made a few modifications to boost LibFuzzer performance by changing how weights are assigned to the seeds in the corpus. Essentially, seeds that reveal more "information" about globally rare features are assigned a higher weight. Our results on the Fuzzer Test Suite seem quite promising. In terms of bug finding, our Entropic patch usually finds the same errors much faster and in more runs. In terms of coverage, our version Entropic achieves the same coverage in less than half the time for the majority of subjects. For the lack of space, we shared more detailed performance results directly with @kcc. We'll publish the preprint with all the technical details as soon as it is accepted. Happy to share if you drop us an email.

There should be plenty of opportunities to optimise further. For instance, while Entropic achieves the same coverage in less than half the time, Entropic has a much lower #execs per second. We ran the perf-tool and found a few performance bottlenecks.

Thanks for open-sourcing LibFuzzer (and the entire LLVM Compiler Infrastructure)! This has been such a tremendous help to my research.

Patch By: Marcel Boehme

Reviewers: kcc, metzman, morehouse, Dor1s, vitalybuka

Reviewed By: kcc

Subscribers: dgg5503, Valentin, llvm-commits, kcc

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73776
2020-05-19 10:28:57 -07:00
Jinsong Ji 3f5f8f3973 [compiler-rt][CMake] Fix PowerPC runtime build
When build in runtime bulid mode with LLVM_ENABLE_RUNTIMES,
the base-config-ix.cmake will complain about two errors.

One is empty string in replace, the other one is unknown `TEST_BIG_ENDIAN ` command.

This patch fix it so that we can test runtime build.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D80040
2020-05-18 19:46:43 +00:00
Martin Storsjö 54a8524070 [compiler-rt] Don't error out on missing builtins when builting builtins themselves
This fixes bootstrapping the builtins when no previous version of
them exists after 2fe66bdb2e.

Also fix a whitespace issue in that commit.
2020-05-18 11:28:44 +03:00
Fangrui Song 02cdbc349f [XRay] Migrate xray_naive_log=true tests to xray_mode=xray-basic 2020-05-17 09:32:52 -07:00
Yi Kong 2fe66bdb2e [Compiler-rt] Emit error if builtins library cannot be found
Since setting COMPILER_RT_USE_BUILTINS_LIBRARY would remove -z,defs
flag, missing builtins library would continue to build unnoticed.
Explicitly emit an error in such case.

Differential Revision: https://reviews.llvm.org/D79470
2020-05-17 10:54:53 +08:00
Jinsong Ji 853b5cbadc [compiler-rt][CMAKE] Only add cmake link flags in standalone build
Only add CMAKE_EXE_LINKER_FLAGS when in a standalone bulid.
Or else CMAKE_EXE_LINKER_FLAGS contains flags for build compiler of Clang/llvm.
This might not be the same as what the COMPILER_RT_TEST_COMPILER supports.
eg: the build compiler use lld linker and we use it to build clang with
default ld linker then to be tested clang will complain about lld
options like --color-diagnostics.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D78373
2020-05-15 18:25:39 +00:00
Alex Lorenz 10b49315fa [test] NFC, add missing declarations and include to test files to avoid 'implicit-function-declaration' diagnostics in the tests 2020-05-14 10:01:50 -07:00
Peter Collingbourne d2a26ad0dc hwasan: Collect ring buffer statistics and include in dev note.
These statistics are intended to help us tune the scudo MTE
implementation.

Differential Revision: https://reviews.llvm.org/D79913
2020-05-14 09:47:42 -07:00
Douglas Yung 79af7314fb Fix PS4 build of compiler-rt runtime.
In a previous change I added a shim for fork(), but when compiled from InstrProfiling.c, the
required header file was not included, so pid_t was undefined. This change adds that include.
2020-05-14 02:11:16 +00:00
Douglas Yung 5435c5def2 Add shim for fork() on PS4 as it is not supported there.
Reviewers: probinson

Subscribers: #sanitizers llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79839
2020-05-13 18:47:01 +00:00
Kamil Rytarowski f61f6ffe11 [compiler-rt] [builtin] Switch the return type of __atomic_compare_exchange_##n to bool
Summary:
Synchronize the function definition with the LLVM documentation.

https://llvm.org/docs/Atomics.html#libcalls-atomic

GCC also returns bool for the same atomic builtin.

Reviewers: theraven

Reviewed By: theraven

Subscribers: theraven, dberris, jfb, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79845
2020-05-13 14:09:02 +02:00
KAWASHIMA Takahiro 7d4167430c [gcov] Fix simultaneous .gcda creation/lock
Fixes PR45673

The commit 9180c14fe4 (D76206) resolved only a part of the problem
of concurrent .gcda file creation. It ensured that only one process
creates the file but did not ensure that the process locks the
file first. If not, the process which created the file may clobber
the contents written by a process which locked the file first.
This is the cause of PR45673.

This commit prevents the clobbering by revising the assumption
that a process which creates the file locks the file first.
Regardless of file creation, a process which locked the file first
uses fwrite (new_file==1) and other processes use mmap (new_file==0).

I also tried to keep the creation/first-lock process same by using
mkstemp/link/unlink but the code gets long. This commit is more
simple.

Note: You may be confused with other changes which try to resolve
concurrent file access. My understanding is (may not be correct):

D76206:   Resolve race of .gcda file creation (but not lock)
This one: Resolve race of .gcda file creation and lock
D54599:   Same as D76206 but abandoned?
D70910:   Resolve race of multi-threaded counter flushing
D74953:   Resolve counter sharing between parent/children processes
D78477:   Revision of D74953

Differential Revision: https://reviews.llvm.org/D79556
2020-05-13 13:03:03 +09:00
Fangrui Song f98709a982 [gcov] Fix big-endian problems
In a big-endian .gcda file, the first four bytes are "gcda" instead of "adcg".
All 32-bit values are in big-endian.

With this change, libclang_rt.profile can hopefully produce gcov
compatible output.
2020-05-11 22:36:46 -07:00
Fangrui Song 4c684b91d5 Revert part of D49132 "[gcov] Fix gcov profiling on big-endian machines"
D49132 is partially correct. For 64-bit values, the lower 32-bit part comes
before the higher 32-bit part (in a little-endian manner).

For 32-bit values, libgcov reads/writes 32-bit values in native endianness.
2020-05-11 22:27:01 -07:00
Fangrui Song 013f06703e [gcov] Emit GCOV_TAG_OBJECT_SUMMARY/GCOV_TAG_PROGRAM_SUMMARY correctly and fix llvm-cov's decoding of runcount
gcov 9 (r264462) started to use GCOV_TAG_OBJECT_SUMMARY. Before,
GCOV_TAG_PROGRAM_SUMMARY was used.
libclang_rt.profile should emit just one tag according to the version.

Another bug introduced by rL194499 is that the wrong runcount field was
selected.

Fix the two bugs so that gcov can correctly decode "Runs:" from
libclang_rt.profile produced .gcda files, and llvm-cov gcov can
correctly decode "Runs:" from libgcov produced .gcda files.
2020-05-11 21:53:53 -07:00
Evgenii Stepanov 67b950be6d [hwasan] Fix allocator alignment.
Summary:
Fix hwasan allocator not respecting the requested alignment when it is
higher than a page, but still within primary (i.e. [2048, 65536]).

Reviewers: pcc, hctim, cryptoad

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79656
2020-05-11 15:45:42 -07:00
Julian Lettner bba38de50c [compile-rt] Reduce #ifdef noise for ptrauth
Create a sanitizer_ptrauth.h header that #includes <ptrauth> when
available and defines just the required macros as "no ops" otherwise.
This should avoid the need for excessive #ifdef'ing.

Follow-up to and discussed in: https://reviews.llvm.org/D79132

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D79540
2020-05-11 09:47:21 -07:00
Kostya Kortchinsky 9959eb918a Add vendor identity check for Hygon Dhyana processor in Scudo
Summary:
The Hygon Dhyana processor supports hardware CRC32.

Related link:
https://reviews.llvm.org/D78874

Result of "make check":
Testing Time: 1364.04s
  Unsupported Tests:   317
  Expected Passes  : 36802
  Expected Failures:   161
[100%] Built target check-llvm
[100%] Built target check

Reviewers: cryptoad

Reviewed By: cryptoad

Subscribers: craig.topper, cryptoad, cfe-commits, #sanitizers, llvm-commits

Tags: #clang, #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D62368
2020-05-11 09:17:57 -07:00
Fangrui Song 25544ce2df [gcov] Default coverage version to '407*' and delete CC1 option -coverage-cfg-checksum
Defaulting to -Xclang -coverage-version='407*' makes .gcno/.gcda
compatible with gcov [4.7,8)

In addition, delete clang::CodeGenOptionsBase::CoverageExtraChecksum and GCOVOptions::UseCfgChecksum.
We can infer the information from the version.

With this change, .gcda files produced by `clang --coverage a.o` linked executable can be read by gcov 4.7~7.
We don't need other -Xclang -coverage* options.
There may be a mismatching version warning, though.

(Note, GCC r173147 "split checksum into cfg checksum and line checksum"
 made gcov 4.7 incompatible with previous versions.)
2020-05-10 16:14:07 -07:00
Fangrui Song 13a633b438 [gcov] Delete CC1 option -coverage-no-function-names-in-data
rL144865 incorrectly wrote function names for GCOV_TAG_FUNCTION
(this might be part of the reasons the header says
"We emit files in a corrupt version of GCOV's "gcda" file format").

rL176173 and rL177475 realized the problem and introduced -coverage-no-function-names-in-data
to work around the issue. (However, the description is wrong.
libgcov never writes function names, even before GCC 4.2).

In reality, the linker command line has to look like:

clang --coverage -Xclang -coverage-version='407*' -Xclang -coverage-cfg-checksum -Xclang -coverage-no-function-names-in-data

Failing to pass -coverage-no-function-names-in-data can make gcov 4.7~7
either produce wrong results (for one gcov-4.9 program, I see "No executable lines")
or segfault (gcov-7).
(gcov-8 uses an incompatible format.)

This patch deletes -coverage-no-function-names-in-data and the related
function names support from libclang_rt.profile
2020-05-10 12:37:44 -07:00
Fangrui Song 93d5ae3af1 [gcov] Temporarily unsupport host-byteorder-big-endian 2020-05-10 11:17:17 -07:00
Fangrui Song 415c689dd2 [compiler-rt][test] Add feature host-byteorder-big-endian
This is needed to make 5a9b792d72 "[gcov] Temporarily unsupport host-byteorder-big-endian"
work.
2020-05-10 11:02:25 -07:00
Fangrui Song 5a9b792d72 [gcov] Temporarily unsupport host-byteorder-big-endian
llvm-cov gcov does not support host-byteorder-big-endian yet.
2020-05-10 10:29:09 -07:00
Jinsong Ji a72b9dfd45 [sanitizer] Enable whitelist/blacklist in new PM
https://reviews.llvm.org/D63616 added `-fsanitize-coverage-whitelist`
and `-fsanitize-coverage-blacklist` for clang.

However, it was done only for legacy pass manager.
This patch enable it for new pass manager as well.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D79653
2020-05-10 02:34:29 +00:00
Evgenii Stepanov 9fcd2b68e7 [hwasan] Untag destination address in hwasan_posix_memalign.
Required on X86 because no TBI.
2020-05-08 16:35:48 -07:00
Evgenii Stepanov eaea9ed835 [hwasan] Reset current thread pointer on thread exit.
Summary:
This is necessary to handle calls to free() after __hwasan_thread_exit,
which is possible in glibc.

Also, add a null check to GetCurrentThread, otherwise the logic in
GetThreadByBufferAddress turns it into a non-null value. This means that
all of the checks for GetCurrentThread() != nullptr do not have any
effect at all right now!

Reviewers: pcc, hctim

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79608
2020-05-08 10:31:25 -07:00
Arthur Eubanks 355633860e Fix MSan test use-after-dtor.cpp under new pass manager
Summary: The new pass manager symbolizes the location as ~Simple instead of Simple::~Simple.

Reviewers: rnk, leonardchan, vitalybuka

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79594
2020-05-08 09:12:41 -07:00
Calixte Denizet 0da37bedc2 [compiler-rt] Reduce the number of threads in gcov test to avoid failure
Summary:
Patch in D78477 introduced a new test for gcov and this test is failing on arm:
 - http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-full-sh/builds/4752/steps/ninja%20check%202/logs/stdio
  - http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/10501/steps/ninja%20check%202/logs/stdio
So try to fix it in reducing the number of threads.

Reviewers: marco-c

Reviewed By: marco-c

Subscribers: dberris, kristof.beyls, #sanitizers, serge-sans-paille, sylvestre.ledru

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79621
2020-05-08 12:48:07 +02:00
Calixte Denizet bec223a9bc [profile] Don't crash when forking in several threads
Summary:
When forking in several threads, the counters were written out in using the same global static variables (see GCDAProfiling.c): that leads to crashes.
So when there is a fork, the counters are resetted in the child process and they will be dumped at exit using the interprocess file locking.
When there is an exec, the counters are written out and in case of failures they're resetted.

Reviewers: jfb, vsk, marco-c, serge-sans-paille

Reviewed By: marco-c, serge-sans-paille

Subscribers: llvm-commits, serge-sans-paille, dmajor, cfe-commits, hiraditya, dexonsmith, #sanitizers, marco-c, sylvestre.ledru

Tags: #sanitizers, #clang, #llvm

Differential Revision: https://reviews.llvm.org/D78477
2020-05-07 14:13:11 +02:00
Julian Lettner 5e4740c212 [Darwin] Improve ASan diagnostics on arm64e with pointer auth
When reporting diagnostics from ASan's (and other sanitizer's) signal
handlers we should strip the "invalid signature" bit before printing
addresses.  This makes the report less confusing and let's the user
focus on the real issue.

rdar://62615826

Reviewed By: kubamracek, delcypher

Differential Revision: https://reviews.llvm.org/D79132
2020-05-06 18:32:31 -07:00
Vitaly Buka d9c529c2a8 [lsan] Fix warnings lit config 2020-05-05 22:42:14 -07:00
Vitaly Buka d059d01c23 [dfsan] Remove realloc from done_abilist.txt
Summary:
Currently, realloc is marked as "discard" in done_abilist.txt. As discussed in PR#45583, this is probably not the expected behavior; a custom wrapper seems to be required. Since this wrapper has not been implemented yet, realloc should not be in the done_abilist.txt file so that a warning is displayed when it is called.

Reviewers: kcc, pcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78379
2020-05-05 22:32:45 -07:00
Dan Liew 4155784cdf Try to make `duplicate_os_log_reports.cpp` more reliable.
It looks like some bots are failing with os log not giving any
output. This might be due to the system under test being heavy
load so the 2 minute window might not be large enough. This
patch makes the window larger in the hope that this test will
be more reliable.

rdar://problem/62141527
2020-05-04 13:49:55 -07:00
Peter Collingbourne 8fac07a12a scudo: Exclude previous tag when retagging freed memory.
This means that immediate use after free will be detected 100% of
the time.

Differential Revision: https://reviews.llvm.org/D79216
2020-05-01 09:35:38 -07:00
Evgenii Stepanov 45b7d44ecb [scudo] Zero- and pattern-initialization of memory.
Summary:
Implement pattern initialization of memory (excluding the secondary
allocator because it already has predictable memory contents).
Expose both zero and pattern initialization through the C API.

Reviewers: pcc, cryptoad

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79133
2020-04-30 15:00:55 -07:00
Evgenii Stepanov 7a555958f1 [scudo] Initialize the allocator in setTrackAllocationStacks.
Summary:
If this is called before the malloc call in a thread (or in the whole
program), the lazy initialization of the allocation can overwrite
Options.

Reviewers: pcc, cryptoad

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D79130
2020-04-29 17:01:58 -07:00
Julian Lettner d56f62e0df [compiler-rt] Fix issue related to switch to Python3 in lit config 2020-04-29 14:34:32 -07:00
Julian Lettner 82ed13cd28 [Darwin] Fix compilation issues on arm64
Newer iOS SDK introduce accessors to retrieve the register values
(arm_thread_state64_get_*) and disallows direct access to fields. If
arm_thread_state64_get_sp is defined, the accessors are available.
2020-04-29 13:46:59 -07:00
Nico Weber e071ea48e9 Unbreak check-builtins on macOS after Python3 switch.
See https://crbug.com/1076480 for details.
2020-04-29 16:42:14 -04:00
Vitaly Buka efba642171 Revert "[tsan] Relax stack trace check"
Edited hwasan by mistake.

This reverts commit a3b942edc8.
2020-04-28 23:57:03 -07:00
Vitaly Buka d1fafa40b8 [tsan] Relax stack trace check
With GCC 8 stack is different.
2020-04-28 23:57:03 -07:00
Vitaly Buka a3b942edc8 [tsan] Relax stack trace check
With GCC 8 stack is different.
2020-04-28 14:06:00 -07:00
Saleem Abdulrasool a5d79e5fa1 build: use Python3 for compiler-rt
compiler-rt is built in a unified configuration on some of the builders
which requires that this is updated to follow the same pattern as LLVM.
2020-04-28 17:29:04 +00:00
KAWASHIMA Takahiro 89f6a2376e [gcov][test] Work around PR45673 - NFC
Work around PR45673 until the test code is fixed.
2020-04-28 20:19:19 +09:00
Ian Levesque 4b9bef7e6c [xray] Preserve x8 in trampoline on AArch64
Summary: Fixes an ABI violation in the trampoline code for AArch64 that causes the indirect result register to get overwritten if the XRay handler function is complex enough to use it.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: kristof.beyls, danielkiss, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78596
2020-04-27 14:57:26 -04:00
Ayke van Laethem 4d41df6482
[builtins] Support architectures with 16-bit int
This is the first patch in a series to add support for the AVR target.
This patch includes changes to make compiler-rt more target independent
by not relying on the width of an int or long.

Differential Revision: https://reviews.llvm.org/D78662
2020-04-26 01:22:10 +02:00
Pratyai Mazumder 73812f3d0b [SanitizerCoverage] Add `__sanitizer_cov_bool_flag_init` as the weak interface functions.
Summary:
Following up the discussion on D77638 (and following rGd6cfed6060c283dc4a6bf9ca294dcd732e8b9f72
as example), defining `__sanitizer_cov_bool_flag_init` as the weak interface
functions in various compiler-rt/ files.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: dberris, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77857
2020-04-24 19:54:54 -07:00
Fangrui Song 10bc12588d [XRay] Change Sled.Function to PC-relative for sled version 2 and make llvm-xray support sled version 2 addresses
Follow-up of D78082 and D78590.

Otherwise, because xray_instr_map is now read-only, the absolute
relocation used for Sled.Function will cause a text relocation.
2020-04-24 14:41:56 -07:00
Fangrui Song 25e22613df [XRay] Change ARM/AArch64/powerpc64le to use version 2 sled (PC-relative address)
Follow-up of D78082 (x86-64).

This change avoids dynamic relocations in `xray_instr_map` for ARM/AArch64/powerpc64le.

MIPS64 cannot use 64-bit PC-relative addresses because R_MIPS_PC64 is not defined.
Because MIPS32 shares the same code, for simplicity, we don't use PC-relative addresses for MIPS32 as well.

Tested on AArch64 Linux and ppc64le Linux.

Reviewed By: ianlevesque

Differential Revision: https://reviews.llvm.org/D78590
2020-04-24 08:35:43 -07:00
Ayke van Laethem 1109dcba20
[builtins] Add void prototype to unprototyped functions
This patch replaces () prototypes with (void) prototypes.

Differential Revision: https://reviews.llvm.org/D78641
2020-04-22 21:43:44 +02:00
Peter Collingbourne 3616e851f6 scudo: Change the macro used to check whether we're targeting the platform.
Differential Revision: https://reviews.llvm.org/D78594
2020-04-22 10:32:51 -07:00
Ian Levesque 5081468a66 [xray] Avoid text relocations in trampolines for ARM/AArch64
Summary: Switch to pc-relative lookup of the xray handler function to avoid text relocations.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: kristof.beyls, danielkiss, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78595
2020-04-21 23:21:02 -04:00
Ian Levesque eeaabe64e3 [xray] Use hidden symbol visibility for xray trampolines
Summary: We load multiple copies of the trampolines into memory when instrumenting DSOs.  Hidden visibility prevents conflicts in this scenario.

Reviewers: MaskRay, dberris, johnislarry

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78593
2020-04-21 23:19:52 -04:00
Dan Liew da820f4f57 Add missing call to `__sanitizer::InitializePlatformEarly()` in UBSan's standalone init.
Summary:
While working on rdar://problem/62083617 I noticed this call was
missing.

This is a no-op for all platforms except Darwin. For Darwin this
means the `use_xnu_fast_mmap` flag is initialized as it was intended
when using UBSan in standalone mode.

Reviewers: vitalybuka, vsk, kubamracek, yln, samsonov

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78532
2020-04-21 18:43:43 -07:00
Dan Liew 564530e50a Add missing call to `Symbolizer::LateInitialize()` in UBSan's standalone init.
Summary:
This fixes symbolization in Standalone UBSan mode for the Darwin simulators.

861b69faee (rdar://problem/58789439) tried to fix
symbolization for all sanitizers on Darwin simulators but unfortunately it only
fixed the problem for TSan.

For UBSan in standalone mode the fix wasn't sufficient because UBSan's
standalone init doesn't call `Symbolizer::LateInitialize()` like ASan
and TSan do. This meant that `AtosSymbolizerProcess::LateInitialize()`
was never being called before
`AtosSymbolizerProcess::StartSymbolizerSubprocess()` which breaks an
invariant we expect to hold.

The missing call to `Symbolizer::LateInitialize()` during UBSan's
standalone init seems like an accidently omission so this patch simply
adds it.

rdar://problem/62083617

Reviewers: vitalybuka, kubamracek, yln, samsonov

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78530
2020-04-21 18:43:33 -07:00
Dan Liew c860262bd2 Disable a Darwin test under LSan.
* Changing source lines seems to cause us to hit rdar://problem/62132428.
* Even if I workaround the above issue sometimes the source line in the dylib reported by atos is off by one.

It's simpler to just disable the test for now.

rdar://problem/61793759
2020-04-21 15:17:21 -07:00
Evgenii Stepanov 2e1cfd02d0 Fix Solaris build of ubsan.
Summary: Broken in D78325.

Reviewers: ro

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

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78510
2020-04-21 12:06:30 -07:00
Fangrui Song 5771c98562 [XRay] Change xray_instr_map sled addresses from absolute to PC relative for x86-64
xray_instr_map contains absolute addresses of sleds, which are relocated
by `R_*_RELATIVE` when linked in -pie or -shared mode.

By making these addresses relative to PC, we can avoid the dynamic
relocations and remove the SHF_WRITE flag from xray_instr_map.  We can
thus save VM pages containg xray_instr_map (because they are not
modified).

This patch changes x86-64 and bumps the sled version to 2. Subsequent
changes will change powerpc64le and AArch64.

Reviewed By: dberris, ianlevesque

Differential Revision: https://reviews.llvm.org/D78082
2020-04-21 09:36:09 -07:00
Dan Liew 7039773b24 Unbreak ASan runtime in the simulators.
Summary:
861b69faee (rdar://problem/58789439) while
fixing symbolization for TSan completely broke ASan's runtime for the
simulators.

The problem with the previous patch is that the memory passed to
`putenv()` was poisoned and when passed to `putenv()` it tripped
an interceptor for `strchr()` which saw the memory was poisoned and
raised an ASan issue.

The memory was poisoned because `AtosSymbolizerProcess` objects
are created using ASan's internal allocator. Memory from this
allocator gets poisoned with `kAsanInternalHeapMagic`.

To workaround this, this patch makes the memory for the environment
variable entry a global variable that isn't poisoned.

This pass also adds a `DCHECK(getenv(K_ATOS_ENV_VAR))` because the
following DCHECK would crash because `internal_strcmp()` doesn't
work on nullptr.

rdar://problem/62067724

Reviewers: kubamracek, yln

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78525
2020-04-20 19:08:08 -07:00
Sam Kerner e5ce95c660 [dfsan] Fix a bug in strcasecmp() and strncasecmp(): Compare the lowercase versions of the characters when choosing a return value.
Summary:
Resolves this bug:

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

Reviewers: morehouse, pcc

Reviewed By: morehouse

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78490
2020-04-20 17:13:40 -07:00
Oliver Stannard 78fe93030f [LSan] Disable a failing test on ARM
This started failing after an OS upgrade on a buildbot machine, and I
don't see anything obvious to fix or revert, so disable it for now to
get the bot green.

Covered by https://bugs.llvm.org/show_bug.cgi?id=44158

Differential revision: https://reviews.llvm.org/D78496
2020-04-20 17:48:19 +01:00
Julian Lettner a54e18df0a [compiler-rt] Use --standalone when running tests on the iOS simulator
We can use `simctl spawn --standalone` to enable running tests without
the need for an already-booted simulator instance.  This also side-steps
the problem of not having a good place to shutdown the instance after
we are finished with testing.

rdar://58118442

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D78409
2020-04-20 08:42:57 -07:00
kpdev 1b0436cd4b [scudo] Silent warning for u64 -> u32 convertion
Error is raised because of using -Werror=convertion
2020-04-17 09:29:55 +03:00
Petr Hosek 6919b708a1 [CMake] Set UBSAN_LINK_FLAGS for ubsan
This variable is being used, but it's not being set (it's only set
for ubsan_minimal, but not ubsan). This addresses a regression that
was introduced in D78325.

Differential Revision: https://reviews.llvm.org/D78410
2020-04-17 23:21:59 -07:00
Peter Collingbourne 21d50019ca scudo: Add support for diagnosing memory errors when memory tagging is enabled.
Introduce a function __scudo_get_error_info() that may be called to interpret
a crash resulting from a memory error, potentially in another process,
given information extracted from the crashing process. The crash may be
interpreted as a use-after-free, buffer overflow or buffer underflow.

Also introduce a feature to optionally record a stack trace for each
allocation and deallocation. If this feature is enabled, a stack trace for
the allocation and (if applicable) the deallocation will also be available
via __scudo_get_error_info().

Differential Revision: https://reviews.llvm.org/D77283
2020-04-17 17:26:30 -07:00
Dan Liew 861b69faee [Darwin] Fix symbolization for recent simulator runtimes.
Summary:
Due to sandbox restrictions in the recent versions of the simulator runtime the
atos program is no longer able to access the task port of a parent process
without additional help.

This patch fixes this by registering a task port for the parent process
before spawning atos and also tells atos to look for this by setting
a special environment variable.

This patch is based on an Apple internal fix (rdar://problem/43693565) that
unfortunately contained a bug (rdar://problem/58789439) because it used
setenv() to set the special environment variable. This is not safe because in
certain circumstances this can trigger a call to realloc() which can fail
during symbolization leading to deadlock. A test case is included that captures
this problem.

The approach used to set the necessary environment variable is as
follows:

1. Calling `putenv()` early during process init (but late enough that
malloc/realloc works) to set a dummy value for the environment variable.

2. Just before `atos` is spawned the storage for the environment
variable is modified to contain the correct PID.

A flaw with this approach is that if the application messes with the
atos environment variable (i.e. unsets it or changes it) between the
time its set and the time we need it then symbolization will fail. We
will ignore this issue for now but a `DCHECK()` is included in the patch
that documents this assumption but doesn't check it at runtime to avoid
calling `getenv()`.

The issue reported in rdar://problem/58789439 manifested as a deadlock
during symbolization in the following situation:

1. Before TSan detects an issue something outside of the runtime calls
setenv() that sets a new environment variable that wasn't previously
set. This triggers a call to malloc() to allocate a new environment
array. This uses TSan's normal user-facing allocator. LibC stores this
pointer for future use later.

2. TSan detects an issue and tries to launch the symbolizer. When we are in the
symbolizer we switch to a different (internal allocator) and then we call
setenv() to set a new environment variable. When this happen setenv() sees
that it needs to make the environment array larger and calls realloc() on the
existing enviroment array because it remembers that it previously allocated
memory for it. Calling realloc() fails here because it is being called on a
pointer its never seen before.

The included test case closely reproduces the originally reported
problem but it doesn't replicate the `((kBlockMagic)) ==
((((u64*)addr)[0])` assertion failure exactly. This is due to the way
TSan's normal allocator allocates the environment array the first time
it is allocated. In the test program addr[0] accesses an inaccessible
page and raises SIGBUS. If TSan's SIGBUS signal handler is active, the
signal is caught and symbolication is attempted again which results in
deadlock.

In the originally reported problem the pointer is successfully derefenced but
then the assert fails due to the provided pointer not coming from the active
allocator. When the assert fails TSan tries to symbolicate the stacktrace while
already being in the middle of symbolication which results in deadlock.

rdar://problem/58789439

Reviewers: kubamracek, yln

Subscribers: jfb, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78179
2020-04-17 15:08:14 -07:00
Fangrui Song 17772995d4 [builtins] Add missing header in D77912 and make __builtin_clzll more robust 2020-04-17 08:29:58 -07:00
Petr Hosek 485862ecda [profile] Avoid duplicating or leaking VMO
Now that write data continously into the memory mapping, we don't need
to keep the VMO handle around after it has been mapped. This change also
ensures that the VMO is always closed on error.

Differential Revision: https://reviews.llvm.org/D76963
2020-04-17 00:54:12 -07:00
Evgenii Stepanov 77e3a2e0fe [ubsan] Link shared runtime library with a version script.
Summary:
Do not reexport libgcc.a symbols and random sanitizer internal symbols
by applying a version script to the shared library build.

This fixes unwinder conflicts on Android that are created by reexporting
the unwinder interface from libgcc_real.a. The same is already done in
asan and hwasan.

Reviewers: vitalybuka, srhines

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78325
2020-04-16 17:33:54 -07:00
Dan Liew fccea7f372 [NFC] Introduce a `LateInitialize()` method to `SymbolizerTool` that is called during the LateInitialize stage of the sanitizer runtimes.
Summary:
This is implemented by adding a `Symbolizer::LateInitializeTools()`
method that iterates over the registered tools and calls the
`LateInitialize()` method on them.

`Symbolizer::LateInitializeTools()` is now called from the various
`Symbolizer::LateInitialize()` implementations.

The default implementation of `SymbolizerTool::LateInitialize()`
does nothing so this change should be NFC.

This change allows `SymbolizerTool` implementations to perform
any initialization that they need to perform at the
LateInitialize stage of a sanitizer runtime init.

rdar://problem/58789439

Reviewers: kubamracek, yln, vitalybuka, cryptoad, phosek, rnk

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78178
2020-04-16 17:25:58 -07:00
Pratyai Mazumder a1526cd62b [NFC, tsan] Update tsan tests expectation
Summary:
These tests pass with clang, but fail if gcc was used.
gcc build creates similar but not the same stacks.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: dvyukov, llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78114
2020-04-16 17:19:52 -07:00
Julian Lettner 80022ae2b5 [UBSan] Fix vptr checks on arm64e
Fix UBSan's vptr checks in the presence of arm64e pointer signing.

Radar-Id: rdar://61786404

Reviewed By: vsk

Differential Revision: https://reviews.llvm.org/D78230
2020-04-16 16:09:05 -07:00
Daniel S Fava 3b222ef246 tsan: fixes to ThreadClock::releaseStoreAcquire and tests
Fixes:
1. Setting the number of entries in a thread's clock to max between
   the thread and the SyncClock the thread is acquiring from
2. Setting last_acquire_

Unit- and stress-test for releaseStoreAcquire added to
tests/unit/tsan_clock_test.cpp
2020-04-16 22:53:26 +02:00
Ilya Leoshkevich 921009e667 [MSan] Enable for SystemZ
Summary:
This patch adds runtime support, adjusts tests and enables MSan.

Like for ASan and UBSan, compile the tests with -mbackchain.

Reviewers: eugenis, uweigand, jonpa, vitalybuka

Reviewed By: eugenis, vitalybuka

Subscribers: vitalybuka, mgorny, hiraditya, #sanitizers, stefansf, Andreas-Krebbel

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76358
2020-04-16 12:15:01 +02:00
Vitaly Buka 61f594e45a [NFC, msan] Increase stack in small stack tests
Test fails in our setup if used with libunwind.
It needs just few bytest to pass.
2020-04-15 19:41:57 -07:00
Ayke van Laethem d9e5691843
[builtins] Fix unprototypes function declaration
The following declarations were missing a prototype:

    FE_ROUND_MODE __fe_getround();
    int __fe_raise_inexact();

Discovered while fixing a bug in Clang related to unprototyped function
calls (see the previous commit).

Differential Revision: https://reviews.llvm.org/D78205
2020-04-15 23:44:51 +02:00
Sam Kerner 10070e31a5 Fix DataFlowSanitizer implementation of strchr() so that strchr(..., '\0') returns a pointer to '\0'.
Summary:

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

Reviewers: pcc, morehouse

Reviewed By: morehouse

Subscribers: morehouse, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77996
2020-04-15 13:08:47 -07:00
Kostya Kortchinsky 15754acc59 [scudo][standalone] Split logs on Android
Summary:
The function used to log on Android will cut the message past
a certain amount of characters, which mostly materializes when
dumping the size class map on OOM.

This change splits the log message at newline boundaries.

Reviewers: pcc, cferris, hctim, eugenis

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78018
2020-04-14 11:29:57 -07:00
Fangrui Song b541196eb4 [builtins] Make __umodsi3/__udivdi3/__umoddi3 standalone (shift and subtract)
@kamleshbhalui reported that when the Standard Extension M
(Multiplication and Division) is disabled for RISC-V,
`__udivdi3` will call __udivmodti4 which will in turn calls `__udivdi3`.

This patch moves __udivsi3 (shift and subtract) to int_div_impl.inc
`__udivXi3`, optimize a bit, add a `__umodXi3`, and use `__udivXi3` and
`__umodXi3` to define `__udivsi3` `__umodsi3` `__udivdi3` `__umoddi3`.

Reviewed By: kamleshbhalui

Differential Revision: https://reviews.llvm.org/D77912
2020-04-14 10:38:37 -07:00
Fangrui Song 4113e388c8 [XRay] Define uint64_t Address = Sled.Address; NFC
This makes it easy to change the address stored in a sled from an
absolute address to a PC-relative address.
2020-04-13 22:44:12 -07:00
Dan Liew 8efc3ccaf8 [Darwin] Fix a bug where the symbolizer would examine the wrong process.
Summary:
Previously `AtosSymbolizer` would set the PID to examine in the
constructor which is called early on during sanitizer init. This can
lead to incorrect behaviour in the case of a fork() because if the
symbolizer is launched in the child it will be told examine the parent
process rather than the child.

To fix this the PID is determined just before the symbolizer is
launched.

A test case is included that triggers the buggy behaviour that existed
prior to this patch. The test observes the PID that `atos` was called
on. It also examines the symbolized stacktrace. Prior to this patch
`atos` failed to symbolize the stacktrace giving output that looked
like...

```
  #0 0x100fc3bb5 in __sanitizer_print_stack_trace asan_stack.cpp:86
  #1 0x10490dd36 in PrintStack+0x56 (/path/to/print-stack-trace-in-code-loaded-after-fork.cpp.tmp_shared_lib.dylib:x86_64+0xd36)
  #2 0x100f6f986 in main+0x4a6 (/path/to/print-stack-trace-in-code-loaded-after-fork.cpp.tmp_loader:x86_64+0x100001986)
  #3 0x7fff714f1cc8 in start+0x0 (/usr/lib/system/libdyld.dylib:x86_64+0x1acc8)
```

After this patch stackframes `#1` and `#2` are fully symbolized.

This patch is also a pre-requisite refactor for rdar://problem/58789439.

Reviewers: kubamracek, yln

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77623
2020-04-13 13:36:29 -07:00
Dan Liew 2169568d9f [Sanitizer Common] Show command used to launch symbolizer process at high verbosity level.
Summary:
In preparation for writing a test for a bug fix we need to be able to
see the command used to launch the symbolizer process. This feature
will likely be useful for debugging how the Sanitizers use the
symbolizer in general.

This patch causes the command line used to launch the process to be
shown at verbosity level 3 and higher.

A small test case is included.

Reviewers: kubamracek, yln, vitalybuka, eugenis, kcc

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77622
2020-04-13 13:36:29 -07:00
Matt Morehouse 6cdcb9b402 [SanCov] Disable whitelist/blacklist test on Darwin. 2020-04-13 10:59:05 -07:00
Kostya Kortchinsky 612f23857f [scudo][standalone] Work with -Werror=class-memaccess
Summary:
Fuchsia's gcc uses this, which in turn prevents us to compile successfully
due to a few `memset`'ing some non-trivial classes in some `init`.

Change those `memset` to members initialization.

Reviewers: pcc, hctim

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77902
2020-04-11 07:29:12 -07:00
Nemanja Ivanovic 7cc6d0cc90 [TSAN] Fix infinite loop on targets where char is unsigned
For targets where char is unsigned (like PowerPC), something like
char c = fgetc(...) will never produce a char that will compare
equal to EOF so this loop does not terminate.
Change the type to int (which appears to be the POSIX return type
for fgetc).
This allows the test case to terminate normally on PPC.
2020-04-11 07:12:47 -05:00
Dmitry Vyukov c65e6079fc tsan: add newline in test file
Buildbots say:

[126/127] Running lint check for sanitizer sources...
FAILED: projects/compiler-rt/lib/CMakeFiles/SanitizerLintCheck
cd /home/buildbots/ppc64be-clang-multistage-test/clang-ppc64be-multistage/stage1/projects/compiler-rt/lib && env LLVM_CHECKOUT=/home/buildbots/ppc64be-clang-multistage-test/clang-ppc64be-multistage/llvm/llvm SILENT=1 TMPDIR= PYTHON_EXECUTABLE=/usr/bin/python COMPILER_RT=/home/buildbots/ppc64be-clang-multistage-test/clang-ppc64be-multistage/llvm/compiler-rt /home/buildbots/ppc64be-clang-multistage-test/clang-ppc64be-multistage/llvm/compiler-rt/lib/sanitizer_common/scripts/check_lint.sh
/home/buildbots/ppc64be-clang-multistage-test/clang-ppc64be-multistage/llvm/compiler-rt/test/tsan/fiber_cleanup.cpp:71:  Could not find a newline character at the end of the file.  [whitespace/ending_newline] [5]
ninja: build stopped: subcommand failed.

Somehow this check is not part of 'ninja check-tsan'.
2020-04-11 11:13:39 +02:00
Dmitry Vyukov 1624be938d tsan: fix leak of ThreadSignalContext memory mapping when destroying fibers
When creating and destroying fibers in tsan a thread state is created and destroyed. Currently, a memory mapping is leaked with each fiber (in __tsan_destroy_fiber). This causes applications with many short running fibers to crash or hang because of linux vm.max_map_count.

The root of this is that ThreadState holds a pointer to ThreadSignalContext for handling signals. The initialization and destruction of it is tied to platform specific events in tsan_interceptors_posix and missed when destroying a fiber (specifically, SigCtx is used to lazily create the ThreadSignalContext in tsan_interceptors_posix). This patch cleans up the memory by makinh the ThreadState create and destroy the ThreadSignalContext.

The relevant code causing the leak with fibers is the fiber destruction:

void FiberDestroy(ThreadState *thr, uptr pc, ThreadState *fiber) {
  FiberSwitchImpl(thr, fiber);
  ThreadFinish(fiber);
  FiberSwitchImpl(fiber, thr);
  internal_free(fiber);
}

Author: Florian
Reviewed-in: https://reviews.llvm.org/D76073
2020-04-11 10:30:31 +02:00
Dmitry Vyukov efeb35e195 tsan: disable ASLR in Go test on NetBSD
Tsan does not support ASLR on NetBSD.
Disable ASLR in the Go test and extend
the error message to be more actionable.

Reported-by: Keith Randall (khr)
2020-04-11 09:46:45 +02:00
Matt Morehouse bef187c750 Implement `-fsanitize-coverage-whitelist` and `-fsanitize-coverage-blacklist` for clang
Summary:
This commit adds two command-line options to clang.
These options let the user decide which functions will receive SanitizerCoverage instrumentation.
This is most useful in the libFuzzer use case, where it enables targeted coverage-guided fuzzing.

Patch by Yannis Juglaret of DGA-MI, Rennes, France

libFuzzer tests its target against an evolving corpus, and relies on SanitizerCoverage instrumentation to collect the code coverage information that drives corpus evolution. Currently, libFuzzer collects such information for all functions of the target under test, and adds to the corpus every mutated sample that finds a new code coverage path in any function of the target. We propose instead to let the user specify which functions' code coverage information is relevant for building the upcoming fuzzing campaign's corpus. To this end, we add two new command line options for clang, enabling targeted coverage-guided fuzzing with libFuzzer. We see targeted coverage guided fuzzing as a simple way to leverage libFuzzer for big targets with thousands of functions or multiple dependencies. We publish this patch as work from DGA-MI of Rennes, France, with proper authorization from the hierarchy.

Targeted coverage-guided fuzzing can accelerate bug finding for two reasons. First, the compiler will avoid costly instrumentation for non-relevant functions, accelerating fuzzer execution for each call to any of these functions. Second, the built fuzzer will produce and use a more accurate corpus, because it will not keep the samples that find new coverage paths in non-relevant functions.

The two new command line options are `-fsanitize-coverage-whitelist` and `-fsanitize-coverage-blacklist`. They accept files in the same format as the existing `-fsanitize-blacklist` option <https://clang.llvm.org/docs/SanitizerSpecialCaseList.html#format>. The new options influence SanitizerCoverage so that it will only instrument a subset of the functions in the target. We explain these options in detail in `clang/docs/SanitizerCoverage.rst`.

Consider now the woff2 fuzzing example from the libFuzzer tutorial <https://github.com/google/fuzzer-test-suite/blob/master/tutorial/libFuzzerTutorial.md>. We are aware that we cannot conclude much from this example because mutating compressed data is generally a bad idea, but let us use it anyway as an illustration for its simplicity. Let us use an empty blacklist together with one of the three following whitelists:

```
  # (a)
  src:*
  fun:*

  # (b)
  src:SRC/*
  fun:*

  # (c)
  src:SRC/src/woff2_dec.cc
  fun:*
```

Running the built fuzzers shows how many instrumentation points the compiler adds, the fuzzer will output //XXX PCs//. Whitelist (a) is the instrument-everything whitelist, it produces 11912 instrumentation points. Whitelist (b) focuses coverage to instrument woff2 source code only, ignoring the dependency code for brotli (de)compression; it produces 3984 instrumented instrumentation points. Whitelist (c) focuses coverage to only instrument functions in the main file that deals with WOFF2 to TTF conversion, resulting in 1056 instrumentation points.

For experimentation purposes, we ran each fuzzer approximately 100 times, single process, with the initial corpus provided in the tutorial. We let the fuzzer run until it either found the heap buffer overflow or went out of memory. On this simple example, whitelists (b) and (c) found the heap buffer overflow more reliably and 5x faster than whitelist (a). The average execution times when finding the heap buffer overflow were as follows: (a) 904 s, (b) 156 s, and (c) 176 s.

We explain these results by the fact that WOFF2 to TTF conversion calls the brotli decompression algorithm's functions, which are mostly irrelevant for finding bugs in WOFF2 font reconstruction but nevertheless instrumented and used by whitelist (a) to guide fuzzing. This results in longer execution time for these functions and a partially irrelevant corpus. Contrary to whitelist (a), whitelists (b) and (c) will execute brotli-related functions without instrumentation overhead, and ignore new code paths found in them. This results in faster bug finding for WOFF2 font reconstruction.

The results for whitelist (b) are similar to the ones for whitelist (c). Indeed, WOFF2 to TTF conversion calls functions that are mostly located in SRC/src/woff2_dec.cc. The 2892 extra instrumentation points allowed by whitelist (b) do not tamper with bug finding, even though they are mostly irrelevant, simply because most of these functions do not get called. We get a slightly faster average time for bug finding with whitelist (b), which might indicate that some of the extra instrumentation points are actually relevant, or might just be random noise.

Reviewers: kcc, morehouse, vitalybuka

Reviewed By: morehouse, vitalybuka

Subscribers: pratyai, vitalybuka, eternalsakura, xwlin222, dende, srhines, kubamracek, #sanitizers, lebedev.ri, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D63616
2020-04-10 10:44:03 -07:00
Florian Hahn d6525eff5e [compiler-rt] Try to disable failing test on Darwin.
Looks like this test fails on Darwin x86_64 as well:

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

Command Output (stderr):
--
fatal error: error in backend: Global variable '__sancov_gen_' has an invalid section specifier '__DATA,__sancov_bool_flag': mach-o section specifier requires a section whose length is between 1 and 16 characters.
2020-04-10 11:08:49 +01:00
Dmitry Vyukov 87735b5b1d tsan: don't check libc dependency on NetBSD
This new check fails on NetBSD as well.
It is meant to prevent regressions, so disable it on NetBSD.

Reported-by: Keith Randall (khr)
2020-04-10 11:12:55 +02:00
Peter Collingbourne 9c86b83ffc scudo: Replace ALIGNED macro with standard alignas specifier.
alignas was introduced in C++11 and is already being used throughout LLVM.

Differential Revision: https://reviews.llvm.org/D77823
2020-04-09 14:36:03 -07:00
Pratyai Mazumder 2d39559d68 [SanitizerCoverage] Add compiler-rt test for -fsanitize-coverage=inline-bool-flag
Reviewers: kcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: dberris, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77638
2020-04-09 13:49:13 -07:00
Marek Kurdej 8b3d3921b0 [libFuzzer] Fix typo in seed_inputs flag description. NFC. 2020-04-09 13:54:07 +02:00
Raul Tambre 3e9d074dea [compiler-rt] Don't print warning about missing testingsupport if not including tests
Reviewers: samsonov, vitalybuka

Reviewed By: vitalybuka

Subscribers: dberris, mgorny, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77375
2020-04-09 02:31:12 -07:00
Ilya Leoshkevich aaba9a7761 [compiler-rt] Don't use __libc_stack_end on ARM
Summary:
Commit b684c1a50f ("Add a `Symbolizer::GetEnvP()` method that allows
symbolizer implementations to customise the environment of the
symbolizer binary.") exposed a latent ARM issue, and that broke

http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-full-sh

This coincided with breakage caused by my commit 5f5fb56c68
("[compiler-rt] Intercept the uname() function"), so I had to
investigate.

The issue is that GetArgsAndEnv does not work on ARM: there glibc's
_start overwrites argc value stored at __libc_start_end, breaking the
existing argv/envp parsing logic.

Fix by inferring argc from argv.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis

Subscribers: dberris, kristof.beyls, danielkiss, #sanitizers, delcypher

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77400
2020-04-08 14:25:59 +02:00
Dmitry Vyukov 2db63723a8 tsan: fix Go/ppc build
PPC now requires ReExec due to ASLR.
Pull in more functions for Go build.

Suggested-by: Keith Randall (khr)
2020-04-07 16:40:59 +02:00
Nico Weber e613f0ee8d Reland "Make llvm_source_root in llvm-lit relative too."
This reverts commit 3185881d69
and adds a missing "include(AddLLVM)" (similar lines already
exist elsewhere in compiler-rt).
2020-04-06 20:49:10 -04:00
Matt Morehouse ec69bac144 [sanitizer_common] Update global_symbols.txt. 2020-04-06 09:58:04 -07:00
Matt Morehouse d0498faeae Revert "[sanitizer_common] Show new unexpected symbols."
This reverts commit 68d73dfa1a.
2020-04-06 09:58:03 -07:00
Matt Morehouse 7bea22d36f Revert "[sanitizer_common] Update global_symbols.txt."
This reverts commit 98bb7fdbe5.
2020-04-06 09:58:03 -07:00
Matt Morehouse 98bb7fdbe5 [sanitizer_common] Update global_symbols.txt. 2020-04-06 09:43:34 -07:00
Matt Morehouse 68d73dfa1a [sanitizer_common] Show new unexpected symbols. 2020-04-06 09:43:33 -07:00
Kamil Rytarowski 695ca346eb [compiler-rt] Fix build on NetBSD 9.99.52+
Add a fallback definition of the netsmb device driver that
was removed.
2020-04-05 01:08:17 +02:00
Riyaz V Puthiyapurayil 9657446313 [compiler-rt] Build with correct ABI (PR38025)
Summary:
This patch fixes [[ https://bugs.llvm.org/show_bug.cgi?id=38025 | PR38025 ]]:
Wrong ABI used when building compiler-rt

Differential Revision: https://reviews.llvm.org/D74133
2020-04-03 11:53:40 -07:00
Ilya Leoshkevich 6897111231 [MSan] Add COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED
Summary:
MSan not implementing COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED looks
like an omission - this macro makes it possible for those intercepted
functions, which libc needs very early, to work before interceptors are
initialized (i.e. before REAL() is usable).

While currently there are no observable practical problems in this
area, changes in libc or in MSan runtime may provoke them. Therefore,
change MSan to work like ASan and TSan already do - use internal
functions in certain interceptors when initialization is not complete.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis

Subscribers: #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76969
2020-04-03 17:18:53 +02:00
Julian Lettner b94afc19eb iOS simulator testing: replace `simctl bootstatus` with boot+shutdown
rdar://59643443
2020-04-02 14:45:54 -07:00
Dmitry Vyukov 0fb8a53562 tsan: don't check libc dependency on FreeBSD
This check fails on FreeBSD:
https://github.com/golang/go/issues/14481#issuecomment-607471193
It is meant to prevent regressions, so disable it on FreeBSD.
2020-04-02 12:46:28 +02:00
Dmitry Vyukov e2d6023250 tsan: fix Go build on Windows
Fix similar to https://reviews.llvm.org/D77111 but fow Windows.

gotsan.cpp:14071:16: error: missing terminating ' character [-Werror]
case 0b10'010:  // c.lwsp (rd != x0)
         ^

Reported-by: Keith Randall
2020-04-01 10:36:29 +02:00
KAWASHIMA Takahiro 9180c14fe4 Fix simultaneous .gcda creation
The intent of the `llvm_gcda_start_file` function is that only
one process create the .gcda file and initialize it to be updated
by other processes later.

Before this change, if multiple processes are started simultaneously,
some of them may initialize the file because both the first and
second `open` calls may succeed in a race condition and `new_file`
becomes 1 in those processes. This leads incorrect coverage counter
values. This often happens in MPI (Message Passing Interface) programs.
The test program added in this change is a simple reproducer.

This change ensures only one process creates/initializes the file by
using the `O_EXCL` flag.

Differential Revision: https://reviews.llvm.org/D76206
2020-04-01 10:29:50 +09:00
Valentin Churavy cba15d1b5c
Add manually overriding of the darwin SDK version
Summary:
When doing cross-compilation from Linux to MacOS we don't have
access to have access to `xcodebuild` and therefore need a way
to set the SDK version from the outside.

Fixes https://reviews.llvm.org/D68292#1853594 for me.

Reviewers: delcypher, yln

Reviewed By: delcypher

Subscribers: #julialang, mgorny, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D77026
2020-03-31 12:54:56 -04:00
Douglas Yung 41c135d6d2 Fix buildgo.sh script to fix linux build failure due to changes in ad1466f8cb.
The above change used a binary literal that is not supported in c++11 mode when
using gcc. It was formalized into the c++14 standard and works when using that
mode to compile, so change the script to use c++14 instead.

Reviewed by: dvyukov

Differential Revision: https://reviews.llvm.org/D77111
2020-03-31 09:32:00 -07:00
Dmitry Vyukov 65b4695375 tsan: fix build bugs
1. Fix expression inside of DCHECK_LE.
2. Add a debug build test to buildgo.sh.
3. Fix race binary path in buildgo.sh.
2020-03-28 09:09:39 +01:00
Ilya Leoshkevich fad47d2225 [compiler-rt] Fall back to internal_uname() when called early
Summary:
Commit 5f5fb56c68 ("[compiler-rt] Intercept the uname() function")
broke sanitizer-x86_64-linux and clang-cmake-thumbv7-full-sh (again)
builds:

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/26313
http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-full-sh/builds/4324

The reason is that uname() can be called as early as
__pthread_initialize_minimal_internal(). When intercepted, this
triggers ASan initialization, which eventually calls dlerror(), which
in turn uses pthreads, causing all sorts of issues.

Fix by falling back to internal_uname() when interceptor runs before
ASan is initialized. This is only for Linux at the moment.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis

Subscribers: dberris, #sanitizers, pcc

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76919
2020-03-28 03:14:19 +01:00
Dan Liew 853a1e6942 Only add `darwin_log_cmd` lit shell test feature when the log can be queried.
Summary:
Follow up fix to 445b810fbd. The `log show` command only works for
privileged users so run a quick test of the command during lit config to
see if the command works and only add the `darwin_log_cmd` feature if
this is the case.

Unfortunately this means the `asan/TestCases/Darwin/duplicate_os_log_reports.cpp`
test and any other tests in the future that use this feature won't run
for unprivileged users which is likely the case in CI.

rdar://problem/55986279

Reviewers: kubamracek, yln, dcoughlin

Subscribers: Charusso, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76899
2020-03-27 11:24:50 -07:00
Luís Marques ad1466f8cb [sanitizer][RISCV] Implement SignalContext::GetWriteFlag for RISC-V
This patch follows the approach also used for MIPS, where we decode the
offending instruction to determine if the fault was caused by a read or
write operation, as that seems to be the only relevant information we have
in the signal context structure to determine that.

Differential Revision: https://reviews.llvm.org/D75168
2020-03-26 19:55:35 +00:00
Dan Liew 445b810fbd [ASan] Fix issue where system log buffer was not cleared after reporting an issue.
Summary:
When ASan reports an issue the contents of the system log buffer
(`error_message_buffer`) get flushed to the system log (via
`LogFullErrorReport()`). After this happens the buffer is not cleared
but this is usually fine because the process usually exits soon after
reporting the issue.

However, when ASan runs in `halt_on_error=0` mode execution continues
without clearing the buffer. This leads to problems if more ASan
issues are found and reported.

1. Duplicate ASan reports in the system log. The Nth (start counting from 1)
ASan report  will be duplicated (M - N) times in the system log if M is the
number of ASan issues reported.

2. Lost ASan reports. Given a sufficient
number of reports the buffer will fill up and consequently cannot be appended
to. This means reports can be lost.

The fix here is to reset `error_message_buffer_pos` to 0 which
effectively clears the system log buffer.

A test case is included but unfortunately it is Darwin specific because
querying the system log is an OS specific activity.

rdar://problem/55986279

Reviewers: kubamracek, yln, vitalybuka, kcc, filcab

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76749
2020-03-26 10:56:17 -07:00
Mitch Phillips 1216f4c0ea [GWP-ASan] Use functions in backtrace test, not line numbers.
Summary:
There's no unwinding functionality on Android that allows for line
numbers to be retrieved in-process. As a result, we can't have
this backtrace test run on Android.

Cleanup the test to use optnone functions instead, which is more stable
than line numbers anyway.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: #sanitizers, morehouse, cferris

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76807
2020-03-26 10:10:24 -07:00
Ilya Leoshkevich 2ca7fe3796 [compiler-rt] Use uname syscall in GetKernelAreaSize()
Commit 5f5fb56c68 ("[compiler-rt] Intercept the uname() function")
broke clang-cmake-thumbv7-full-sh build:

http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-full-sh/builds/4296

This also affects i386.

The reason is that intercepted uname() is called by GetKernelAreaSize()
during ASAN initialization on 32-bit platforms, but the respective
interceptor is not initialized yet at this point, leading to null
pointer dereference.

Introduce internal_uname() wrapper around uname syscall, and use it in
GetKernelAreaSize() and in FixedCVE_2016_2143().

Author: Ilya Leoshkevich
Reviewed By: Evgenii Stepanov

Differential Revision: https://reviews.llvm.org/D76776
2020-03-26 13:35:09 +01:00
Ilya Leoshkevich dc37287320 [asan] Fix read_binary_name_regtest.c test dying with SIGPIPE
Disable symbolization of results, since llvm-symbolizer cannot start
due to restricted readlink(), causing the test to die with SIGPIPE.

Author: Ilya Leoshkevich
Reviewed By: Evgenii Stepanov

Differential Revision: https://reviews.llvm.org/D76576
2020-03-26 13:34:18 +01:00
Jonas Devlieghere 6430707196 Revert "tsan: fix leak of ThreadSignalContext for fibers"
Temporarily revert "tsan: fix leak of ThreadSignalContext for fibers"
because it breaks the LLDB bot on GreenDragon.

This reverts commit 93f7743851.
This reverts commit d8a0f76de7.
2020-03-25 19:18:38 -07:00
Wolfgang 93f7743851 Fixing a sanitizer lint problem that was breaking some builds. 2020-03-25 18:26:28 -07:00
Max Moroz 6d0488f75b [compiler-rt] Mark FDP non-template methods inline to avoid ODR violations. 2020-03-25 13:43:54 -07:00
Dmitry Vyukov d8a0f76de7 tsan: fix leak of ThreadSignalContext for fibers
When creating and destroying fibers in tsan a thread state
is created and destroyed. Currently, a memory mapping is
leaked with each fiber (in __tsan_destroy_fiber).
This causes applications with many short running fibers
to crash or hang because of linux vm.max_map_count.

The root of this is that ThreadState holds a pointer to
ThreadSignalContext for handling signals. The initialization
and destruction of it is tied to platform specific events
in tsan_interceptors_posix and missed when destroying a fiber
(specifically, SigCtx is used to lazily create the
ThreadSignalContext in tsan_interceptors_posix). This patch
cleans up the memory by inverting the control from the
platform specific code calling the generic ThreadFinish to
ThreadFinish calling a platform specific clean-up routine
after finishing a thread.

The relevant code causing the leak with fibers is the fiber destruction:

void FiberDestroy(ThreadState *thr, uptr pc, ThreadState *fiber) {
  FiberSwitchImpl(thr, fiber);
  ThreadFinish(fiber);
  FiberSwitchImpl(fiber, thr);
  internal_free(fiber);
}

I would appreciate feedback if this way of fixing the leak is ok.
Also, I think it would be worthwhile to more closely look at the
lifecycle of ThreadState (i.e. it uses no constructor/destructor,
thus requiring manual callbacks for cleanup) and how OS-Threads/user
level fibers are differentiated in the codebase. I would be happy to
contribute more if someone could point me at the right place to
discuss this issue.

Reviewed-in: https://reviews.llvm.org/D76073
Author: Florian (Florian)
2020-03-25 17:05:46 +01:00
Dmitry Vyukov 5f149ef51f compiler-rt: allow golang race detector to run on musl-c
tsan while used by golang's race detector was not working on alpine
linux, since it is using musl-c instead of glibc. Since alpine is very
popular distribution for container deployments, having working race
detector would be nice. This commits adds some ifdefs to get it working.

It fixes https://github.com/golang/go/issues/14481 on golang's issue tracker.

Reviewed-in: https://reviews.llvm.org/D75849
Author: graywolf-at-work (Tomas Volf)
2020-03-25 17:05:45 +01:00
Max Moroz 1e65209e04 [compiler-rt] FuzzedDataProvider: make linter happy. 2020-03-25 00:39:17 -07:00
Max Moroz 1262db1b6a [compiler-rt] Refactor FuzzedDataProvider for better readability.
Summary: Separate class definition and actual methods implementation. The main
goal is to keep the list of available methods in a concise readable form inside
the class definition.

Reviewers: hctim, metzman

Subscribers: dberris, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76651
2020-03-24 23:51:49 -07:00
Petr Hosek ba1f4405c6 [profile] Move RuntimeCounterRelocation and ProfileDumped into a separate file
This avoids the test failure that was introduced in rG32bddad where
this function pulls in the rest of InstrProfilingFile.c which is
undesirable in use cases when profile runtime is being used without
the rest of libc.

This also allows additional cleanup by eliminating another variable
from platforms that don't need it.

Differential Revision: https://reviews.llvm.org/D76750
2020-03-24 20:27:14 -07:00
Petr Hosek 32bddad37b [profile] Make atexit hook a no-op on Fuchsia
On Fuchsia, we always use the continuous mode with runtime counter
relocation, so there's no need for atexit hook or support for dumping
the profile manually.

Differential Revision: https://reviews.llvm.org/D76556
2020-03-24 18:47:38 -07:00
Dan Liew b684c1a50f Add a `Symbolizer::GetEnvP()` method that allows symbolizer implementations to customise the environment of the symbolizer binary.
Summary:
This change introduces the `Symbolizer::GetEnvP()` method that returns a
pointer to environment array used for spawning the symbolizer process.
The motivation is to allow implementations to customise the environment
if required.  The default implementation just returns
`__sanitizer::GetEnviron()` which (provided it's implemented) should
preserve the existing behaviours of the various implementations.

This change has been plumbed through the `internal_spawn(...)` and
`StartSubprocess(...)` process spawning implementations.

For the `StartSubprocess()` implementation we need to call `execve()`
rather than `execv()` to pass the environment. However, it appears that
`internal_execve(...)` exists in sanitizer_common so this patch use that
which seems like a nice clean up.

Support in the Windows implementation of
`SymbolizerProcess:StartSymbolizerSubprocess()` has not been added
because the Windows sanitizer runtime doesn't implement `GetEnviron()`.

rdar://problem/58789439

Reviewers: kubamracek, yln, dvyukov, vitalybuka, eugenis, phosek, aizatsky, rnk

Subscribers: #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76666
2020-03-24 15:41:46 -07:00
Mitch Phillips a4e8d89704 [GWP-ASan] Only pack frames that are stored.
Summary:
Backtrace() returns the number of frames that are *available*, rather
than the number of frames stored. When we pack, we supply the number of
frames we have stored. The number of available frames can exceed the
number of stored frames, leading to stack OOB read.

Fix up this problem.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: #sanitizers, morehouse, cferris, pcc

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76722
2020-03-24 14:37:09 -07:00
Dmitry Vyukov 180d211770 tsan: Adding releaseAcquire() to ThreadClock
realeaseAcquire() is a new function added to TSan in support of the Go data-race detector.
It's semantics is:

void ThreadClock::releaseAcquire(SyncClock *sc) const {
  for (int i = 0; i < kMaxThreads; i++) {
    tmp = clock[i];
    clock[i] = max(clock[i], sc->clock[i]);
    sc->clock[i] = tmp;
  }
}

For context see: https://go-review.googlesource.com/c/go/+/220419

Reviewed-in: https://reviews.llvm.org/D76322
Author: dfava (Daniel Fava)
2020-03-24 11:27:46 +01:00
Peter Collingbourne 8140f6bcde scudo: Create a public include directory. NFCI.
For MTE error reporting we will need to expose interfaces for crash handlers
to use to interpret scudo headers and metadata. The intent is that these
interfaces will live in scudo/interface.h.

Move the existing interface.h into an include/scudo directory and make it
independent of the internal headers, so that we will be able to add the
interfaces there.

Differential Revision: https://reviews.llvm.org/D76648
2020-03-23 18:23:29 -07:00
Max Moroz 2136d17d8d [compiler-rt] Add ConsumeRandomLengthString() version without arguments.
Reviewers: hctim, metzman

Subscribers: dberris, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76448
2020-03-23 16:32:37 -07:00