Commit Graph

10070 Commits

Author SHA1 Message Date
Kamil Rytarowski c22867f5fc Correct ctype(3) functions with NLS on NetBSD
Summary:
The setlocale(3) function reloads the ctype(3) arrays from
external files. This happens behind the scenes in the internals
of libc (citrus library, runes functions etc).

ctype(3) functions like isspace(3) can be provided with two
variations on NetBSD: inlined or via a global symbol in libc:

```
#if defined(_NETBSD_SOURCE) && !defined(_CTYPE_NOINLINE) && \
    !defined(__cplusplus)
#include <sys/ctype_inline.h>
#else
#include <sys/ctype_bits.h>
#endif
```

The in-lined versions are de-facto array lookup operations.

```
#define isspace(c)      ((int)((_ctype_tab_ + 1)[(c)] & _CTYPE_S))
```

After setting setlocale(3) the ctype(3) arrays (_ctype_tab_,
_toupper_tab_, _tolower_tab_) are reload behind the scenes
and they are required to be marked as initialized.

Set them initialized inside the common setlocale(3) interceptor.

The arrays are of size of 257 elements: 0..255 + 1 (EOF).

This corrects errors on NetBSD/amd64 in applications
prebuilt with MSan.

Sponsored by <The NetBSD Foundation>

Reviewers: vitalybuka, dvyukov, joerg

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

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

llvm-svn: 326008
2018-02-24 01:01:14 +00:00
Alex Shlyapnikov 524946232b [Sanitizers] Increase allocated chunk limit for LargeMmapAllocator
Summary:
There are applications out there which allocate more than 1 << 18 large chunks
of memory (those handled by LargeMmapAllocator, aka secondary allocator).

For 64 bits, secondary allocator stores allocated chunks in a growing on
demand region of memory, growing in blocks of 128K, up to 1 << 20 chunks total.

Sanitizer internal allocator's secondary uses fixed size array storing up
to 1 << 15 chunks (down to 256K from 2Mb of memory used for that array).

Nothing is changed for 32 bits, chunks are still stored in the fixed size
array (up to 1 << 15 chunks).

Reviewers: eugenis

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

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

llvm-svn: 326007
2018-02-24 01:00:27 +00:00
Matt Morehouse ddf352b953 [libFuzzer] Include TEMP_MAX_LEN in Fuzzer::PrintStats.
Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

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

llvm-svn: 325817
2018-02-22 19:00:17 +00:00
Kamil Rytarowski 663dbfadbf Try to fix the syntax in test
Reported on a buildbot:

Error in XFAIL list:
couldn't parse text: '| arm || aarch64 || mips'
in expression: 'freebsd | arm || aarch64 || mips'

Add || in the place of |

Fallout from D43382

llvm-svn: 325751
2018-02-22 07:17:01 +00:00
Kamil Rytarowski c419df9066 Remove empty files
Left over after D43382

llvm-svn: 325744
2018-02-22 06:11:28 +00:00
Kamil Rytarowski 80c2a79437 Xray instrumentation / enabling more tests
Summary:
The Unix subdirectory mostly allows only on Linux x86_64 but now we can target x86_64 arch in general.

Patch by David CARLIER

Reviewers: krytarowski, dberris, emaste

Reviewed By: krytarowski, dberris, emaste

Subscribers: emaste, llvm-commits, #sanitizers

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

llvm-svn: 325743
2018-02-22 06:08:26 +00:00
Vitaly Buka e075709b41 [sanitizer] Allow to set SANITIZER_CAN_USE_PREINIT_ARRAY externally
llvm-svn: 325720
2018-02-21 21:13:07 +00:00
Evgeniy Stepanov 43271b1803 [hwasan] Fix inline instrumentation.
This patch changes hwasan inline instrumentation:

Fixes address untagging for shadow address calculation (use 0xFF instead of 0x00 for the top byte).
Emits brk instruction instead of hlt for the kernel and user space.
Use 0x900 instead of 0x100 for brk immediate (0x100 - 0x800 are unavailable in the kernel).
Fixes and adds appropriate tests.

Patch by Andrey Konovalov.

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

llvm-svn: 325711
2018-02-21 19:52:23 +00:00
Maxim Kuvyrkov 6b287234ea Fix racy msan test
Summary:
Child thread may finish before pthread_setname_np() and/or
pthread_getname_np() had a chance to run, which causes these functions
to fail with ENOENT (meaning /proc/self/task/[tid]/comm doesn't exist).

Fix by stalling child thread on a mutex.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: llvm-commits, #sanitizers

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

llvm-svn: 325703
2018-02-21 18:03:50 +00:00
Kamil Rytarowski 8b5d3ebcbe Msan, fixing DTLS_on_tls_get_addr signature empty implementation
Summary: No supported oses normally compiled that code (or not for a long time) probably never caught it.

Patch by: David CARLIER

Reviewers: vitalybuka, krytarowski

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

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

llvm-svn: 325664
2018-02-21 04:16:45 +00:00
Kamil Rytarowski 59a9856e06 Add new interceptor: strmode(3)
Summary:
strmode - convert inode status information into a symbolic string

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 325588
2018-02-20 15:53:30 +00:00
Kamil Rytarowski 8317565532 Add new interceptor: fgetln(3)
Summary:
fgetln - get a line from a stream

Sponsored by <The NetBSD Foundation>

Reviewers: vitalybuka, joerg

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

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

llvm-svn: 325587
2018-02-20 15:52:08 +00:00
Kamil Rytarowski babcdb3a9a Stop intercepting forkpty(3) and openpty(3) on NetBSD
Summary:
forkpty(3) and openpty(3) are part of `-lutil` and we don't intend to reimplement
this system library in sanitizers. Everybody using these functions will need to use
a precompiled library against MSan or other desired sanitizer.

Restrict these functions to Linux-only.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 325585
2018-02-20 15:43:07 +00:00
Kamil Rytarowski 7cde46764a Recognize all NetBSD architectures in UBSan
Summary:
Use uniform accessors for Program Pointer,
Stack Pointer and Frame Pointer.

Remove CPU check in UBSan supported platforms
and rely only on the OS type.

This adds NetBSD support in GetPcSpBp() for:
 - ARM
 - ARM64
 - HPPA
 - PowerPC/PowerPC64
 - SPARC/SPARC64
 - MIPS
 - DEC Alpha AXP
 - DEC VAX
 - M68K and M68010
 - SH3
 - IA64
 - OR1K
 - RISCV

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, ro

Reviewed By: vitalybuka

Subscribers: aemerson, jyknight, sdardis, kubamracek, arichardson, llvm-commits, kristof.beyls, fedor.sergeev, #sanitizers

Tags: #sanitizers

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

llvm-svn: 325431
2018-02-17 13:35:09 +00:00
Kamil Rytarowski bab5252789 Add initial XRay support for NetBSD
Summary:
Reuse the existing FreeBSD code as it is.

Sponsored by <The NetBSD Foundation>

Reviewers: dberris, rnk, vitalybuka

Reviewed By: dberris

Subscribers: mclow.lists, emaste, mgorny, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 325345
2018-02-16 14:45:20 +00:00
Kamil Rytarowski 015125d7ff Reintroduce FreeBSD support in test/xray
Tested by Douglas Yung.

The original patch from D43278 has been reverted.

New patch by myself.

llvm-svn: 325315
2018-02-16 04:20:33 +00:00
Kamil Rytarowski 515fc27b9e Revert part of SVN r. 325240 in lit.cfg
The original change broke a llvm-clang-lld-x86_64-debian setup.

This change will be investigated and reintroduced in future.

Original commit:

  "Add Xray instrumentation support to FreeBSD"
  https://reviews.llvm.org/D43278

llvm-svn: 325309
2018-02-16 01:16:06 +00:00
Kuba Mracek 9967378eba [asan] Add "arm64" into the list of 64-bit architectures
It looks like get_bits_for_arch doesn't recognize "arm64" as a 64-bit architecture, and it actually matches the "arm" regexp, which marks it as 32-bit. Let's fix that by matching the 64-bit list first and addin "arm64" into the list.

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

llvm-svn: 325300
2018-02-15 22:14:36 +00:00
Alex Shlyapnikov 48296ebf8b [TSan] Fix static TLS boundaries calculations in __tls_get_addr interceptor.
Summary:
DTLS_on_tls_get_addr expects (tls_addr + tls_size) as the last
parameter, static_tls_end.

Reviewers: dvyukov

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

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

llvm-svn: 325276
2018-02-15 18:58:31 +00:00
Kamil Rytarowski a6affc2fab Try to unbreak Darwin after XRay/FreeBSD commit
Add a fallback definition of getTSCFrequency().

llvm-svn: 325249
2018-02-15 15:24:01 +00:00
Kamil Rytarowski 7d15ab6aef Implement a large part of NetBSD syscalls of netbsd_syscall_hooks.h
This is a follow up of:

  r325206 - Add NetBSD syscall hooks skeleton in sanitizers

Sponsored by <The NetBSD Foundation>

llvm-svn: 325248
2018-02-15 15:15:45 +00:00
Kamil Rytarowski 62b0c5bb88 Enable test/asan for NetBSD
Sponsored by <The NetBSD Foundation>

llvm-svn: 325246
2018-02-15 14:59:59 +00:00
Kamil Rytarowski e7c26e7929 Enable syscall-specific functions in TSan/NetBSD
NetBSD ships now with netbsd_syscall_hooks.h and requires support
for TSan specific features to be enabled.

This is follow up of:

  D42048: Add NetBSD syscall hooks skeleton in sanitizers

Sponsored by <The NetBSD Foundation>

llvm-svn: 325245
2018-02-15 14:58:15 +00:00
Kamil Rytarowski 4d4ed0e288 Add Xray instrumentation support to FreeBSD
Summary:
- Enabling the build.
- Using assembly for the cpuid parts.
- Using thr_self FreeBSD call to get the thread id 

Patch by: David CARLIER

Reviewers: dberris, rnk, krytarowski

Reviewed By: dberris, krytarowski

Subscribers: emaste, stevecheckoway, nglevin, srhines, kubamracek, dberris, mgorny, krytarowski, llvm-commits, #sanitizers

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

llvm-svn: 325240
2018-02-15 14:17:15 +00:00
Kamil Rytarowski 5ffda0cc1f Teach sanitizer about NetBSD specific ioctl(2) calls
Summary:
Introduce handling of 1200 NetBSD specific ioctl(2) calls.
Over 100 operations are disabled as unavailable or conflicting
with the existing ones (the same operation number).

Add a script that generates the rules to detect ioctls on NetBSD.
The generate_netbsd_ioctls.awk script has been written
in NetBSD awk(1) (patched nawk) and is compatible with gawk.

Generate lib/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc
with the awk(1) script.

Update sanitizer_platform_limits_netbsd accordingly to add the needed
definitions.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis, dvyukov

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 325212
2018-02-15 03:36:16 +00:00
Kamil Rytarowski 443434e45c Prevent recursive MSan interceptors in strftime(3) like functions
Summary:
This corrects intercepting this call on NetBSD without false positives.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 325208
2018-02-15 02:48:20 +00:00
Kamil Rytarowski a8ab3a6008 Prevent recursive MSan interceptors in fgets(3)
Summary:
This corrects intercepting this call on NetBSD without false positives.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 325207
2018-02-15 02:47:35 +00:00
Kamil Rytarowski 39628a7ab0 Add NetBSD syscall hooks skeleton in sanitizers
Summary:
Implement the skeleton of NetBSD syscall hooks for use with sanitizers.

Add a script that generates the rules to handle syscalls
on NetBSD: generate_netbsd_syscalls.awk. It has been written
in NetBSD awk(1) (patched nawk) and is compatible with gawk.

Generate lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
that is a public header for applications, and included as:
<sanitizer_common/sanitizer_platform_limits_netbsd.h>.

Generate sanitizer_syscalls_netbsd.inc that defines all the
syscall rules for NetBSD. This file is modeled after the Linux
specific file: sanitizer_common_syscalls.inc.

Start recognizing NetBSD syscalls with existing sanitizers:
ASan, ESan, HWASan, TSan, MSan.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, kcc, dvyukov, eugenis

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 325206
2018-02-15 02:43:02 +00:00
Kamil Rytarowski 1046294bd3 Add new interceptor: lstat(2)
Summary:
lstat - get file status

Use it on NetBSD.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 325199
2018-02-15 02:17:06 +00:00
Vitaly Buka 1fd9f071a2 [sanitizer] Fix flakiness in the tests
Seems tests fails if link already exists.
Also removed duplicated part of tests.

llvm-svn: 325194
2018-02-15 00:40:36 +00:00
Matt Morehouse 36c89b3c77 [libFuzzer] Set -experimental_len_control=1000 as default.
Summary:
Experiments using
https://github.com/google/fuzzer-test-suite/tree/master/engine-comparison
show a significant increase in coverage and reduction in corpus size
with this option enabled.

Addresses https://llvm.org/pr36371.

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits

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

llvm-svn: 325050
2018-02-13 20:52:15 +00:00
Kostya Kortchinsky 1ce4642ddc [sanitizer] Implement GetRSS on Windows
Summary:
Pretty straightforward, returning the `WorkingSetSize` of a
`PROCESS_MEMORY_COUNTERS` structure. AFAIU, `GetProcessMemoryInfo` is in
`kernel32.lib` for Windows 7 and above. Support for earlier Windows versions
would require `psapi.lib`, but I don't think those are supported by ASan?

Reviewers: alekseyshl, rnk, vitalybuka

Reviewed By: vitalybuka

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

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

llvm-svn: 325020
2018-02-13 17:05:54 +00:00
Kostya Kortchinsky 1022220b16 [sanitizer] Size class map & local cache improvements
Summary:
- Reland rL324263, this time allowing for a compile-time decision as to whether
  or not use the 32-bit division. A single test is using a class map covering
  a maximum size greater than 4GB, this can be checked via the template
  parameters, and allows SizeClassAllocator64PopulateFreeListOOM to pass;
- `MaxCachedHint` is always called on a class id for which we have already
  computed the size, but we still recompute `Size(class_id)`. Change the
  prototype of the function to work on sizes instead of class ids. This also
  allows us to get rid of the `kBatchClassID` special case. Update the callers
  accordingly;
- `InitCache` and `Drain` will start iterating at index 1: index 0 contents are
  unused and can safely be left to be 0. Plus we do not pay the cost of going
  through an `UNLIKELY` in `MaxCachedHint`, and touching memory that is
  otherwise not used;
- `const` some variables in the areas modified;
- Remove an spurious extra line at the end of a file.

Reviewers: alekseyshl, tl0gic, dberris

Reviewed By: alekseyshl, dberris

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

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

llvm-svn: 324906
2018-02-12 16:59:17 +00:00
Kuba Mracek 9ead7bb3d4 Revert r324847, there's bot failures.
llvm-svn: 324849
2018-02-11 20:44:04 +00:00
Kuba Mracek 3eb694d01e [sanitizer] Implement NanoTime() on Darwin
Currently NanoTime() on Darwin is unimplemented and always returns 0. Looks like there's quite a few things broken because of that (TSan periodic memory flush, ASan allocator releasing pages back to the OS). Let's fix that.

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

llvm-svn: 324847
2018-02-11 19:25:34 +00:00
Kuba Mracek 3ecf9dcaf4 [compiler-rt] Replace forkpty with posix_spawn
On Darwin, we currently use forkpty to communicate with the "atos" symbolizer. There are several problems that fork or forkpty has, e.g. that after fork, interceptors are still active and this sometimes causes crashes or hangs. This is especially problematic for TSan, which uses interceptors for OS-provided locks and mutexes, and even Libc functions use those.

This patch replaces forkpty with posix_spawn. Since posix_spawn doesn't fork (at least on Darwin), the interceptors are not a problem. Additionally, this also fixes a latent threading problem with ptsname (it's unsafe to use this function in multithreaded programs). Yet another benefit is that we'll handle post-fork failures (e.g. sandbox disallows "exec") gracefully now.

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

llvm-svn: 324846
2018-02-11 19:23:42 +00:00
Kamil Rytarowski b3ca0d127d Correct a typo in tsan_pthread_setname_np in the FreeBSD code
Noted by David CARLIER.

llvm-svn: 324811
2018-02-10 14:44:12 +00:00
Kamil Rytarowski 9ce6bdf530 Mark the textdomain.cc test as unsupported on BSDs
textdomain is a part of -lintl on BSDs. In GLIBC it's in libc.

We assume that -lintl will need to be rebuilt with sanitizers
in order to sanitize programs using its features.

This is a proper continuation of D41013.

The original patch has been reverted (adding -lintl).

llvm-svn: 324810
2018-02-10 14:36:55 +00:00
Dean Michael Berris ec81ae37bd [XRay] Rename Buffer.Buffer to Buffer.Data
Summary: some compiler (msvc) treats Buffer.Buffer as constructor and refuse to compile. NFC

Authored by comicfans44.

Reviewers: rnk, dberris

Reviewed By: dberris

Subscribers: llvm-commits

Tags: #sanitizers

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

llvm-svn: 324807
2018-02-10 09:07:34 +00:00
Kostya Kortchinsky 2833383cd4 [scudo] Allow options to be defined at compile time
Summary:
Allow for options to be defined at compile time, like is already the case for
other sanitizers, via `SCUDO_DEFAULT_OPTIONS`.

Reviewers: alekseyshl, dberris

Reviewed By: alekseyshl, dberris

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

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

llvm-svn: 324620
2018-02-08 16:29:48 +00:00
Jonas Devlieghere 1db3ca9ab1 [builtins] Workaround for infinite recursion in c?zdi2
gcc resolves `__builtin_c?z` to `__c?zdi2` which leads to infinite
recursion. This problem has been observed for sparc64, mips64 and riscv.
Presumably this happens whenever an arch without dedicated bit counting
instructions is targeted. This patch provides a workaround.

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

llvm-svn: 324593
2018-02-08 11:14:11 +00:00
Serguei Katkov d535c4d9d2 Update test counter_promo_nest.c to meet llvm change
The test expects to see the pattern "load add store" twice
in a row.

However the test contains actually several instances of this pattern.
Currently the first pattern appears in the output twice.

But after LLVM change https://reviews.llvm.org/D42691 some addtional
modification is done and one of another pattern has been hoisted in
function entry block.

As a result we have another order of meeting this pattern.
The test is updated to meet this change.

llvm-svn: 324571
2018-02-08 07:15:49 +00:00
Rafael Espindola 23581e5ee4 Add space inside the regular expression.
This should now pass on both ppc and x86. Sorry about the noise.

llvm-svn: 324556
2018-02-08 02:29:56 +00:00
Rafael Espindola 8d1f53a78d Remove extra space.
Should fix the ppc bots.

llvm-svn: 324548
2018-02-08 00:39:19 +00:00
Rafael Espindola dee75682c8 Update for llvm change.
llvm-svn: 324541
2018-02-07 23:13:57 +00:00
Yvan Roux cae4970b34 [asan] Fix filename size on linux platforms.
This is a a fix for:
https://bugs.llvm.org/show_bug.cgi?id=35996

Use filename limits from system headers to be synchronized with what
LD_PRELOAD can handle.

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

llvm-svn: 324496
2018-02-07 18:27:25 +00:00
Kamil Rytarowski ccb970ee03 Correct a bug in GetArgsAndEnv() for NetBSD
Fix setting envp.

llvm-svn: 324481
2018-02-07 14:05:57 +00:00
Petr Hosek 2f70693e08 [Fuzzer] Use Zircon's public API on Fuchsia
The original libFuzzer Fuchsia port relied on convenience libraries,
but these are not exported as part of Fuchsia sysroot. This change
eliminates the use of these libraries and relies on public API only.

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

llvm-svn: 324454
2018-02-07 08:22:58 +00:00
Vitaly Buka ca8d201070 [Sanitizers, Darwin] Disable SANITIZER_SUPPORTS_WEAK_HOOKS before Mac OS X 10.9
Summary:
Before Xcode 4.5, undefined weak symbols don't work reliably on Darwin:
https://stackoverflow.com/questions/6009321/weak-symbol-link-on-mac-os-x
Therefore this patch disables their use before Mac OS X 10.9 which is the first version
only supported by Xcode 4.5 and above.

Reviewers: glider, kcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits

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

llvm-svn: 324284
2018-02-05 23:02:09 +00:00
Kostya Kortchinsky 02f6845095 [sanitizer] Revert rL324263
Summary:
The 32-bit division  breaks SizeClassAllocator64PopulateFreeListOOM which uses
Primary that has a maximum size > 32-bit.

Reviewers: alekseyshl

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

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

llvm-svn: 324268
2018-02-05 20:17:24 +00:00
Kostya Kortchinsky d6f7a65197 [sanitizer] SizeClassMap minor improvement/correctness changes
Summary:
In `ClassID`, make sure we use an unsigned as based for the `lbits` shift.
The previous code resulted in spurious sign extensions like for x64:
```
add     esi, 0FFFFFFFFh
movsxd  rcx, esi
and     rcx, r15
```
The code with the `U` added is:
```
add     esi, 0FFFFFFFFh
and     rsi, r15
```
And for `MaxCachedHint`, use a 32-bit division instead of `64-bit`, which is
faster (https://lemire.me/blog/2017/11/16/fast-exact-integer-divisions-using-floating-point-operations/)
and already used in other parts of the code (64-bit `GetChunkIdx`, 32-bit
`GetMetaData` enforce 32-bit divisions)

Not major performance gains by any mean, but they don't hurt.

Reviewers: alekseyshl

Reviewed By: alekseyshl

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

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

llvm-svn: 324263
2018-02-05 19:22:56 +00:00
Kostya Kortchinsky 5c6e6c28c4 [sanitizer] Allocator local cache improvements
Summary:
Here are a few improvements proposed for the local cache:
- `InitCache` always read from `per_class_[1]` in the fast path. This was not
  ideal as we are working with `per_class_[class_id]`. The latter offers the
  same property we are looking for (eg: `max_count != 0` means initialized),
  so we might as well use it and keep our memory accesses local to the same
  `per_class_` element. So change `InitCache` to take the current `PerClass`
  as an argument. This also makes the fast-path assembly of `Deallocate` a lot
  more compact;
- Change the 32-bit `Refill` & `Drain` functions to mimic their 64-bit
  counterparts, by passing the current `PerClass` as an argument. This saves
  some array computations;
- As far as I can tell, `InitCache` has no place in `Drain`: it's either called
  from `Deallocate` which calls `InitCache`, or from the "upper" `Drain` which
  checks for `c->count` to be greater than 0 (strictly). So remove it there.
- Move the `stats_` updates to after we are done with the `per_class_` accesses
  in an attempt to preserve locality once more;
- Change some `CHECK` to `DCHECK`: I don't think the ones changed belonged in
  the fast path and seemed to be overly cautious failsafes;
- Mark some variables as `const`.

The overall result is cleaner more compact fast path generated code, and some
performance gains with Scudo (and likely other Sanitizers).

Reviewers: alekseyshl

Reviewed By: alekseyshl

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

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

llvm-svn: 324257
2018-02-05 18:06:45 +00:00
Kamil Rytarowski c0dc9bb93e Handle NetBSD symbol mangling devname -> __devname50
llvm-svn: 324240
2018-02-05 14:50:01 +00:00
Kuba Mracek f1ddefb55f Use NULL instead of nullptr in invalid-pointer-pairs-compare-null.cc; nullptr is not available on older Darwin systems.
llvm-svn: 324136
2018-02-02 20:42:29 +00:00
Kuba Mracek 66ce45150f [asan] Make concurrent_overflow.cc less flaky
The "sleep(5)" sometimes times out on our bots, causing the test to fail. Let's use pthread_join.

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

llvm-svn: 324126
2018-02-02 19:49:24 +00:00
Kamil Rytarowski 78c9ac4dc5 Correct FileCheck usage in two newly added tests
llvm-svn: 324121
2018-02-02 18:48:15 +00:00
Kamil Rytarowski e6bba9bc6f Add new NetBSD interceptors: devname(3), devname_r(3)
Summary:
devname, devname_r - get device name

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 324120
2018-02-02 18:45:33 +00:00
Kamil Rytarowski 42983551bd Correct the return value of strlcat(3) in the interceptor
Late fix for SVN r. 324034
Add new interceptors: strlcpy(3) and strlcat(3)

There was forgotten an addition of len to the return value.

llvm-svn: 324091
2018-02-02 13:56:52 +00:00
Kamil Rytarowski e2f8718b50 Add new interceptors: strlcpy(3) and strlcat(3)
Summary:
NetBSD ships with strlcpy(3) and strlcat(3), a safe
replacement of strcpy(3) and strcat(3).

Hide both functions under SANITIZER_INTERCEPT_STRLCPY.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

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

llvm-svn: 324034
2018-02-01 23:34:30 +00:00
Vitaly Buka b2a27efdc0 [sanitizer] Fix array sizes used for path in tests
llvm-svn: 324022
2018-02-01 22:26:18 +00:00
Kuba Mracek 11ee02fd39 Update readlink.c and readlinkat.c to use larger buffers on Darwin.
llvm-svn: 324016
2018-02-01 21:59:51 +00:00
Kostya Kortchinsky 298f224194 [sanitizer] Implement NanoTime & MonotonicNanoTime for Windows
Summary:
Implement `MonotonicNanoTime` using `QueryPerformanceCounter`.

This function is used by Scudo & the 64-bit Primary allocator. Implementing it
now means that the release-to-OS mechanism of the Primary will kick in (it
never did since the function returned 0 always), but `ReleaseMemoryPagesToOS` is
still not currently implemented for Windows.

Performance wise, this adds a syscall & a 64-bit division per call to
`MonotonicNanoTime` so the impact might not be negligible, but I don't think
there is a way around it.

Reviewers: rnk, alekseyshl, amccarth

Reviewed By: alekseyshl, amccarth

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

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

llvm-svn: 324011
2018-02-01 21:38:14 +00:00
Kostya Kortchinsky 8c4ca0bbea [scudo] Minor Secondary changes
Summary:
Few changes to the secondary:
- mark `const` variables as such;
- change some `CHECK` to `DCHECK`: I don't feel we need to be as conservative as
  we were with out checks, as they are the results of our own computation.
- mark a condition as `UNLIKELY`.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 323997
2018-02-01 20:00:42 +00:00
Alex Shlyapnikov 3c80f4d941 Make detect_invalid_pointer_pairs option to be tristate.
Summary:
With the change, one can choose not to report comparison (or subtraction)
of a pointer with nullptr pointer.

Reviewers: kcc, jakubjelinek, alekseyshl

Reviewed By: alekseyshl

Subscribers: kubamracek

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

llvm-svn: 323995
2018-02-01 19:52:56 +00:00
Jonas Hahnfeld 44ef345c50 [CMake] Remove -stdlib= which is unused when passing -nostdinc++
This avoids the warnings when building with LLVM_ENABLE_LIBCXX
which automatically adds -stdlib=libc++ to CMAKE_CXX_FLAGS.

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

llvm-svn: 323969
2018-02-01 13:57:24 +00:00
Dean Michael Berris cdca0730be [XRay][compiler-rt+llvm] Update XRay register stashing semantics
Summary:
This change expands the amount of registers stashed by the entry and
`__xray_CustomEvent` trampolines.

We've found that since the `__xray_CustomEvent` trampoline calls can show up in
situations where the scratch registers are being used, and since we don't
typically want to affect the code-gen around the disabled
`__xray_customevent(...)` intrinsic calls, that we need to save and restore the
state of even the scratch registers in the handling of these custom events.

Reviewers: pcc, pelikan, dblaikie, eizan, kpw, echristo, chandlerc

Reviewed By: echristo

Subscribers: chandlerc, echristo, hiraditya, davide, dblaikie, llvm-commits

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

llvm-svn: 323940
2018-02-01 02:21:54 +00:00
Vitaly Buka d3fad26588 [sanitizer] Move readlinkat.c test from Linux to Posix
llvm-svn: 323837
2018-01-31 00:04:10 +00:00
Vitaly Buka eca881fc7a [sanitizer] Fix tests on Android and Darwin
llvm-svn: 323834
2018-01-30 23:51:44 +00:00
Petr Hosek b1eaa56704 [fuzzer] Update and enable libFuzzer on Fuchsia
This change updates the Fuchsia-specific code to use the C++ friendly
duration expressions and flips on the building of
libclang_rt.fuzzer-x86_64.a and similar for Fuchsia. Given that
compiler-rt doesn't build on Fuchsia, test have been run by explicitly
building the library and linking it against
lib/fuzzer/tests/FuzzerUnittest.cpp.

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

llvm-svn: 323828
2018-01-30 22:59:48 +00:00
Vitaly Buka 4ec0d9c1b7 [sanitizer] Add interceptors for readlinkat, name_to_handle_at, open_by_handle_at
Summary:
Also move existing readlink msan interceptor to sanitizer_common.

Fixes google/sanitizers#908

Patch by Oliver Chang

Reviewers: vitalybuka, eugenis

Reviewed By: vitalybuka

Subscribers: llvm-commits

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

llvm-svn: 323825
2018-01-30 22:22:12 +00:00
Matt Morehouse 1d8e5ea250 [libFuzzer] Fix sizeof(ptr) bug.
sizeof(const char *) returns 4 or 8 when what we really want is the size
of the array.

llvm-svn: 323802
2018-01-30 18:25:55 +00:00
Kostya Kortchinsky 4223af42b8 [scudo] Add default implementations for weak functions
Summary:
This is in preparation for platforms where `SANITIZER_SUPPORTS_WEAK_HOOKS` is 0.
They require a default implementation.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: delcypher, llvm-commits, #sanitizers

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

llvm-svn: 323795
2018-01-30 17:59:49 +00:00
Martin Pelikan 1e0d3b43ea [XRay] [compiler-rt] stop writing garbage in naive log records
Summary:
Turns out sizeof(packed) isn't as strong as we'd hoped.  This makes sure
that when we initialize the padding, all 12 bytes will be zero.

Reviewers: dberris, kpw, eizan

Subscribers: delcypher, llvm-commits, #sanitizers

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

llvm-svn: 323755
2018-01-30 13:25:25 +00:00
Kostya Kortchinsky c15da10101 [scudo] Add support for Fuchsia OS.
Summary: Built & tested in Fuchsia's build system.

Reviewers: alekseyshl, cryptoad, aarongreen

Reviewed By: cryptoad

Subscribers: srhines, mgorny

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

llvm-svn: 323685
2018-01-29 20:17:29 +00:00
Dmitry Vyukov e64c4f418c tsan: deflake a test
There was a failure on a bot:
http://lab.llvm.org:8011/builders/clang-cmake-mipsel/builds/1283

strerror test is indeed flaky. We protect all races by a barrier in other tests
to eliminate flakiness. Do the same here.

No idea why tls_race2.cc failed. Add output at the end of the test
as we do in other tests. Sometimes test process crashes somewhere
in the middle (e.g. during race reporting) and it looks like empty output.
Output at the end of test allows to understand if the process has crashed,
or it has finished but produced no race reports.

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

llvm-svn: 323657
2018-01-29 15:10:22 +00:00
Don Hinton 23743f48fa Revert: [compiler-rt] r323626 - [cmake] [compiler-rt] Remove duplicate CMAKE_CXX_FLAGS.
Looks like it broke a bot: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-android/builds/7195
Reverting until I have a chance to investigate.

llvm-svn: 323629
2018-01-29 05:32:21 +00:00
Don Hinton 448ef74698 [cmake] [compiler-rt] Remove duplicate CMAKE_CXX_FLAGS.
`set_target_compile_flags()` ultimately sets COMPILE_FLAGS which is
added to CMAKE_CXX_FLAGS in the compile rule, so passing
CMAKE_CXX_FLAGS causes them to be duplicated.

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

llvm-svn: 323626
2018-01-29 05:07:20 +00:00
Kuba Mracek 07d85e46fc [xray] Don't try to run XRay unit tests on Darwin
This gets rid of a lit warning (input './projects/compiler-rt/test/xray/Unit' contained no tests).

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

llvm-svn: 323613
2018-01-28 03:11:25 +00:00
Petr Hosek 9945c44ea6 [sanitizer] Update from zx_time_get to zx_clock_get
This Zircon syscall was renamed.

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

llvm-svn: 323611
2018-01-27 23:58:23 +00:00
Don Hinton 78fd93e039 [cmake] [compiler-rt] Call llvm_setup_rpath() when adding shared libraries.
Clang and llvm already use llvm_setup_rpath(), so this change will
help standarize rpath usage across all projects.

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

llvm-svn: 323606
2018-01-27 21:14:17 +00:00
Hiroshi Inoue d1a6646e59 [NFC] fix trivial typos in comments and documents
"in in" -> "in", "on on" -> "on" etc.

llvm-svn: 323510
2018-01-26 08:16:08 +00:00
Kostya Kortchinsky 4b4db0057f [scudo] Overhaul malloc related interceptors
Summary:
This is a follow-up to D42506.

There are a few of things that bothered me about `scudo_interceptors.cpp`:
- the filename is a misnomer: it intercepts some functions, but the rest (C++)
  is actually in `scudo_new_delete.cpp`. I feel like `scudo_malloc.cpp` is more
  appropriate (ASan uses the same naming scheme);
- we do not need "full" interceptors, since we are never accessing the
  unsanitized version of the functions, we just need the
  `extern "C" INTERCEPTOR_ATTRIBUTE` part of it to just call our functions;
- a couple of functions where duplicated while they could just be `ALIAS`'d;
- use the `SANITIZER_INTERCEPT_*` defines to hide the unneeded interceptors;
- use `SIZE_T` instead of `uptr`: while it's the same behind the curtain,
  the former is meant for this use case.

In the end there is no functional change on the currently supported platforms
(Linux, Android).

Reviewers: alekseyshl

Reviewed By: alekseyshl

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

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

llvm-svn: 323464
2018-01-25 20:42:44 +00:00
Kostya Kortchinsky 896c1c0746 [sanitizer] Implement GetNumberOfCPUs for Windows
Summary:
Implement `GetNumberOfCPUs` using `GetNativeSystemInfo`.
The only consummer of this function is Scudo which is not functional on
Windows yet.

Reviewers: rnk, zturner

Reviewed By: zturner

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

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

llvm-svn: 323462
2018-01-25 20:14:35 +00:00
Kamil Rytarowski 3417a78781 Correct typo in TSan code
We wrongly enabled additional (unwanted) branch for NetBSD.

Noted by Vlad Tsyrklevich

llvm-svn: 323413
2018-01-25 11:07:42 +00:00
Kostya Kortchinsky fc45e4a3f1 [scudo] Remove SANITIZER_LINUX requirement for the malloc interceptors
Summary:
Currently all platforms are using the `scudo_interceptors.cpp` interceptors.

We might to come up with platform specific interceptors when/if we get Apple &
Windows, but as of now, that allows for Fuchsia to use them.

`scudo_new_delete.cpp` didn't have the `#if SANITIZER_LINUX` so it's good to go.

Reviewers: alekseyshl, flowerhack

Reviewed By: flowerhack

Subscribers: delcypher, #sanitizers, llvm-commits

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

llvm-svn: 323386
2018-01-24 22:46:34 +00:00
Martin Storsjo 09bc73d11f [builtins] Align addresses to cache lines in __clear_cache for aarch64
This makes sure that the last cache line gets invalidated properly.

This matches the example code at
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0024a/BABJDBHI.html,
and also matches what libgcc does.

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

llvm-svn: 323315
2018-01-24 10:14:52 +00:00
Kamil Rytarowski dfcbdda1e0 Break a line into <= 80 characters
llvm-svn: 323279
2018-01-23 23:14:32 +00:00
Kostya Kortchinsky 1ebebde8b7 [scudo] Allow for weak hooks, gated by a define
Summary:
Hooks in the allocation & deallocation paths can be a security risk (see for an
example https://scarybeastsecurity.blogspot.com/2016/11/0day-exploit-advancing-exploitation.html
which used the glibc's __free_hook to complete exploitation).

But some users have expressed a need for them, even if only for tests and
memory benchmarks. So allow for `__sanitizer_malloc_hook` &
`__sanitizer_free_hook` to be called if defined, and gate them behind a global
define `SCUDO_CAN_USE_HOOKS` defaulting to 0.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 323278
2018-01-23 23:07:42 +00:00
Kamil Rytarowski 70552c6f53 Add a new interceptor: paccept(2)
Summary:
paccept(2) is a NetBSD-specific variation of accept(2).

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

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

llvm-svn: 323273
2018-01-23 22:41:47 +00:00
Francis Ricci 564f845b74 [ubsan] Add preinit initializer for ubsan
Summary:
Now that ubsan does function interception (for signals), we
need to ensure that ubsan is initialized before any library
constructors are called. Otherwise, if a constructor calls
sigaction, ubsan will intercept in an unitialized state, which
will cause a crash.

This patch is a partial revert of r317757, which removed
preinit arrays for ubsan.

Reviewers: vitalybuka, eugenis, pcc

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

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

llvm-svn: 323249
2018-01-23 19:54:02 +00:00
Bill Seurer e76f2171f9 [PowerPC][asan] Fix asan tests to handle changed memory layouts
In more recent Linux kernels with 47 bit VMAs the layout of virtual memory
for powerpc64 changed causing the address sanitizer to not work properly. This
patch fixes up a test case that was found to fail on some newer Fedora
releases that use different address ranges.

ref: https://reviews.llvm.org/D40907
llvm-svn: 323217
2018-01-23 16:28:17 +00:00
Alex Shlyapnikov ac8217de83 Small fixes for detect_invalid_pointer_pairs.
Summary:
One test-case uses a wrong operation (should be subtraction).
Second test-case should declare a global variables before a tested one
in order to guarantee we will find a red-zone.

Reviewers: kcc, jakubjelinek, alekseyshl

Reviewed By: alekseyshl

Subscribers: kubamracek

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

llvm-svn: 323162
2018-01-22 23:28:52 +00:00
Evgeniy Stepanov 7c70d9d0be [ubsan] Disable signal handling on Android.
Summary: See rationale in the comments.

Reviewers: vitalybuka

Subscribers: srhines, llvm-commits, kubamracek

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

llvm-svn: 323142
2018-01-22 19:26:01 +00:00
Maxim Ostapenko b0d49a604b [lsan] Respect log_path option in standalone LSan
Differential Revision: https://reviews.llvm.org/D42303

llvm-svn: 323083
2018-01-22 09:30:27 +00:00
Hiroshi Inoue 93eaad7dac [NFC] fix trivial typos in comments
"the the" -> "the"

llvm-svn: 323080
2018-01-22 07:51:37 +00:00
Petr Hosek 4dd524ed6a [sanitizer] Pass the CMake compiler to custom libc++ build
This addresses the error introduced in r323054 on some bots.

llvm-svn: 323061
2018-01-21 03:22:22 +00:00
Petr Hosek 066e4bf888 Reland "[Fuzzer] Parametrize add_custom_libcxx"
add_custom_libcxx uses the just built compiler and installs the
built libc++, e.g. for testing, neither of which is desirable in
case of Fuzzer where the libc++ should be built using the host
compiler and it's only linked into the libFuzzer and should never
be installed. This change introduces additional arguments to
add_custom_libcxx to allow parametrizing its behavior.

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

llvm-svn: 323054
2018-01-21 01:01:53 +00:00
Kamil Rytarowski f086a5ab03 [compiler-rt] Implement __clear_cache() on OpenBSD/mips64
Summary:
Make __clear_cache() invoke the platform's cache flush function
on OpenBSD/mips64.

Reviewers: krytarowski

Reviewed By: krytarowski

Subscribers: sdardis, dberris, arichardson, krytarowski, llvm-commits, #sanitizers

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

llvm-svn: 323039
2018-01-20 14:16:16 +00:00
Petr Hosek 81ac12d1b4 Revert "[Fuzzer] Parametrize add_custom_libcxx"
This reverts commit r323032: failing on the sanitizer-x86_64-linux-autoconf bot.

llvm-svn: 323033
2018-01-20 09:21:00 +00:00
Petr Hosek 94e67be187 [Fuzzer] Parametrize add_custom_libcxx
add_custom_libcxx uses the just built compiler and installs the
built libc++, e.g. for testing, neither of which is desirable in
case of Fuzzer where the libc++ should be built using the host
compiler and it's only linked into the libFuzzer and should never
be installed. This change introduces additional arguments to
add_custom_libcxx to allow parametrizing its behavior.

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

llvm-svn: 323032
2018-01-20 09:03:16 +00:00
Petr Hosek aecae82f41 Reland "Fix syntax error introduced in r322991"
This triggers compiler error when building sanitizers for Fuchsia.

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

llvm-svn: 323029
2018-01-20 03:37:47 +00:00
Petr Hosek 2a26210187 Revert "[sanitizer] Fix syntax error introduced in r322991"
This reverts commit r323027: it breaks the SanitizerLintCheck.

llvm-svn: 323028
2018-01-20 03:23:45 +00:00
Petr Hosek 51bbea2017 [sanitizer] Fix syntax error introduced in r322991
This triggers compiler error when building sanitizers for Fuchsia.

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

llvm-svn: 323027
2018-01-20 02:34:33 +00:00
Dan Liew 3fc243aea5 Force lit to execute the ASan and TSan tests on iOS devices
sequentially.

The current implementation of commands in
`test/sanitizer_common/ios_commands/` for iOS devices cannot be executed
in parallel which results in the ASan and TSan tests failing when
executed in parallel by lit which was the default behaviour.

We now force the ASan and TSan tests to be a new parallelism group named
`darwin-ios-device-sanitizer` which allows only one test to be run at a
time.  We also emit a warning informing the user that tests are being
run sequentially.

This only applies if the target is an iOS device.

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

llvm-svn: 323026
2018-01-20 02:07:30 +00:00
Kamil Rytarowski 0699f57bc7 Support the localtime interceptor for NetBSD
Summary:
The localtime symbol is mangled to __locatime50
on NetBSD.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 323019
2018-01-20 00:40:29 +00:00
Kamil Rytarowski ada9d47cba Intercept accept4() on NetBSD
Summary:
The accept4() function first appeared in NetBSD 8.0.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 323018
2018-01-20 00:37:27 +00:00
Petar Jovanovic 6f10bd21f0 [TSan][MIPS] Expand sanitizer memory space to lower addresses
MemToShadowImpl() maps lower addresses to a memory space out of sanitizers
range. The simplest example is address 0 which is mapped to 0x2000000000

static const uptr kShadowBeg     = 0x2400000000ull;

but accessing the address during tsan execution will lead to a segmentation
fault.

This patch expands the range used by the sanitizer and ensures that 1/8 of
the maximum valid address in the virtual address spaces is used for shadow
memory.

Patch by Milos Stojanovic.

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

llvm-svn: 323013
2018-01-20 00:06:07 +00:00
Kostya Kortchinsky 0fb904325a [sanitizer] Allow Fuchsia to use getauxval
Summary:
Fuchsia has `getauxval` (https://fuchsia.googlesource.com/zircon/+/master/third_party/ulib/musl/include/sys/auxv.h,
https://fuchsia.googlesource.com/zircon/+/master/third_party/ulib/musl/src/misc/getauxval.c)
so set SANITIZER_USE_GETAUXVAL to 1 for this platform.

Reviewers: alekseyshl, flowerhack

Reviewed By: flowerhack

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

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

llvm-svn: 323002
2018-01-19 22:33:30 +00:00
Kostya Kortchinsky 5435b68a11 [scudo] Pass SANITIZER_COMMON_LINK_FLAGS to the shared library LINK_FLAGS
Summary:
We somehow never did it, and it raised no issue until now, when trying to
enable Fuchsia as a supported Scudo platform in the cmake config.

So propagate SANITIZER_COMMON_LINK_FLAGS for now.

Reviewers: alekseyshl, flowerhack

Reviewed By: flowerhack

Subscribers: mgorny, #sanitizers, llvm-commits

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

llvm-svn: 322999
2018-01-19 22:17:39 +00:00
Petr Hosek 76657a9c44 Reland "Make TracePcGuardController linker-initialized"
It was always intended to be.

Patch By: mcgrathr

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

llvm-svn: 322991
2018-01-19 21:14:53 +00:00
Kamil Rytarowski 2038405616 Correct typo after r322829
llvm-svn: 322947
2018-01-19 14:47:49 +00:00
Martin Pelikan 4834bca106 [XRay] [compiler-rt] fix heap overflow by computing record pointers correctly
Summary:
While there, unify InMemoryRawLog and InMemoryRawLogWithArg's coding style:
- swap libc's memcpy(3) for sanitizer's internal memcpy
- use basic pointer arithmetics to compute offsets from the first record
  entry in the pre-allocated buffer, which is always the appropriate type
  for the given function
- lose the local variable references as the TLD.* names fit just as well

Reviewers: eizan, kpw, dberris, dblaikie

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 322941
2018-01-19 13:18:40 +00:00
Martin Storsjo fe011a6ed9 [builtins] Use FlushInstructionCache on windows on aarch64 as well
Generalize this handling to a separate toplevel ifdef (since any
windows case should use the same function), instead of indenting
the aarch64 case one step further.

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

llvm-svn: 322928
2018-01-19 07:34:46 +00:00
Kostya Kortchinsky ab0d88746a [scudo] Use -fsanitize=scudo rather than --whole-archive in tests
Summary:
Tests were being run by whole-linking the static library with our test binaries.
But since `-fsanitize=scudo` landed with rL317337, we might as well change how
the tests are compiled to use it.

The only difference will be on Android, where the clang flag links in the
dynamic library instead, but the bots are already pushing
`libclang_rt.*-android.so` to the device there is no additional change needed.

Tested locally, including with a standalone build, and an Android one on a O
device, and it all passes.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 322882
2018-01-18 20:02:56 +00:00
Kamil Rytarowski ba91a689a1 Enable sanitizer_common tests on NetBSD
Summary:
NetBSD can handle asan, ubsan, msan, tsan tests
on 64-bit and when applicable 32-bit X86 OS.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 322842
2018-01-18 11:49:45 +00:00
Kamil Rytarowski 124d5eb96e Break a line into two lines
This should restore the rule of <=80 characters per line.

llvm-svn: 322841
2018-01-18 11:38:10 +00:00
Kamil Rytarowski 878469cd82 Add new NetBSD interceptors: getgrouplist(3) & getgroupmembership(3)
Summary:
getgrouplist, getgroupmembership -- calculate group access list

Sponsored by <The NetBSD Foundation>

Reviewers: vitalybuka, joerg

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

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

llvm-svn: 322836
2018-01-18 11:17:35 +00:00
Kamil Rytarowski 26370ddcd7 Add new interceptors: access(2), faccessat(2)
Summary:
access, faccessat - check access permissions of a file or pathname

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, kubamracek, #sanitizers

Tags: #sanitizers

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

llvm-svn: 322831
2018-01-18 11:04:25 +00:00
Kamil Rytarowski c815ed5792 Add new interceptors for pwcache(3)-style functions
Summary:
From <pwd.h>: user_from_uid, uid_from_user

From <grp.h>: group_from_gid, gid_from_group

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 322829
2018-01-18 10:53:27 +00:00
Alex Shlyapnikov dd77ed51e7 [Sanitizers] Changes in Hwasan allocator missed in D42198.
Converting a few failure handler calls missed in D42198.

llvm-svn: 322793
2018-01-18 00:23:46 +00:00
Alex Shlyapnikov fd2833992a [Sanitizers] Make common allocator agnostic to failure handling modes.
Summary:
Make common allocator agnostic to failure handling modes and move the
decision up to the particular sanitizer's allocator, where the context
is available (call stack, parameters, return nullptr/crash mode etc.)

It simplifies the common allocator and allows the particular sanitizer's
allocator to generate more specific and detailed error reports (which
will be implemented later).

The behavior is largely the same, except one case, the violation of the
common allocator's check for "size + alignment" overflow is now reportied
as OOM instead of "bad request". It feels like a worthy tradeoff and
"size + alignment" is huge in this case anyway (thus, can be interpreted
as not enough memory to satisfy the request). There's also a Report()
statement added there.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits, #sanitizers

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

llvm-svn: 322784
2018-01-17 23:20:36 +00:00
Kostya Kortchinsky 33802be579 [scudo] Fix for the Scudo interface function scope
Summary:
A forgotten include in `scudo_allocator.cpp` made the symbol only local :/

Before:
```
nm ./lib/clang/7.0.0/lib/linux/libclang_rt.scudo-i686-android.so | grep rss
00024730 t __scudo_set_rss_limit
```
After:
```
nm ./lib/clang/7.0.0/lib/linux/libclang_rt.scudo-i686-android.so | grep rs
00024760 T __scudo_set_rss_limit
```
And we want `T`!

This include also means that we can get rid of the `extern "C"` in the C++
file, the compiler does fine without it (note that this was already the case
for all the `__sanitizer_*` interface functions.

Reviewers: alekseyshl, eugenis

Reviewed By: eugenis

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 322782
2018-01-17 23:10:02 +00:00
Kostya Kortchinsky 255913b3a0 [scudo] Limit by default the TSD pool to 2 on Android
Summary:
jemalloc on Android currently uses 2 arenas
(https://android.googlesource.com/platform/external/jemalloc/+/master/Android.bp#64).
Since the Android toolchain absorbs compiler-rt and compiles it as is, we have
to enforce the same limit to somehow stay competitive in terms of memory usage.

The changes could either go in:
- `scudo_platform.h` with a default for Android of 2 (this is the solution
  implemented here);
- in `CMakeLists.txt` adding -DSCUDO_SHARED_TSD_POOL_SIZE=2 for Android.
- something else?

I don't have a strong opinion on how to do it, but it has to be done upstream
anyway.

Reviewers: alekseyshl, eugenis

Reviewed By: alekseyshl, eugenis

Subscribers: srhines, #sanitizers, llvm-commits

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

llvm-svn: 322764
2018-01-17 21:54:48 +00:00
Petr Hosek eac2b47b9f Reland "[libFuzzer] Support using libc++"
This is needed in case the users of libFuzzer use libc++ in their
code, which the fuzz target (libFuzzer) will be linked against.
When libc++ source is available, we build a private version of it
and link it against libFuzzer which allows using the same static
library against codebases which use both libc++ and libstdc++.

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

llvm-svn: 322755
2018-01-17 20:39:14 +00:00
Petr Hosek 68bc4bd6e5 Revert "[libFuzzer] Support using libc++"
This reverts commit r322604: test is failing for standalone compiler-rt.

llvm-svn: 322689
2018-01-17 17:24:56 +00:00
Kamil Rytarowski b87c8fa456 Add new interceptor: acct(2)
Summary:
acct - enable or disable process accounting

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 322646
2018-01-17 13:05:14 +00:00
Kamil Rytarowski 1628943978 Hotfix for test/asan/TestCases/alloca_constant_size.cc
Add missing endif.

llvm-svn: 322638
2018-01-17 12:32:17 +00:00
Kamil Rytarowski 3efd1c516c [Sanitizers, test] Fix sanitizer tests on Solaris (PR 33274)
Summary:
This patch (on top of the previous two (https://reviews.llvm.org/D40898 and
https://reviews.llvm.org/D40899) complete the compiler-rt side of the the Solaris
sanitizer port.

It contains the following sets of changes:

* For the time being, the port is for 32-bit x86 only, so reject the various tests on
  x86_64.

* When compiling as C++, <setjmp.h> resp. <iso/setjmp_iso.h> only declares
  _setjmp and _longjmp inside namespace std.

* MAP_FILE is a Windows feature.  While e.g. Linux <sys/mman.h> provides a
  no-op compat define, Solaris does not.

* test/asan/TestCases/Posix/coverage.cc was initially failing like this:

/vol/gcc/src/llvm/llvm/local/projects/compiler-rt/lib/sanitizer_common/scripts/sancov.py: 4 files merged; 2 PCs total
rm: cannot remove '/var/gcc/llvm/local/projects/compiler-rt/test/asan/I386SunOSConfig/TestCases/Posix/Output/coverage': Invalid argument

  Further digging revealed that the rm was trying to remove the running test's working
  directory which failed as observed.  cd'ing out of the dir before let the test pass.

* Two tests needed a declaration of alloca. I've now copied the existing code from
  test/asan/TestCases/alloca_constant_size.cc, but it may be more profitable and
  maintainable to have a common testsuite header where such code is collected.

* Similarly, Solaris' printf %p format doesn't include the leading 0x.

* In test/asan/TestCases/malloc-no-intercept.c, I had to undef __EXTENSIONS__
  (predefined by clang for no apparent reason) to avoid conflicting declarations
  for memalign.

* test/ubsan/TestCases/Float/cast-overflow.cpp has different platform dependent
  ways to define BYTE_ORDER and friends.  Why not just use __BYTE_ORDER__ and
  friends as predefined by clang and gcc?

Patch by Rainer Orth.

Reviewers: kcc, alekseyshl

Reviewed By: alekseyshl

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

Tags: #sanitizers

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

llvm-svn: 322635
2018-01-17 12:26:04 +00:00
Peter Collingbourne 7351a22b7d cfi: Add a blacklist entry for MSVC's std::get_temporary_buffer function.
Differential Revision: https://reviews.llvm.org/D42150

llvm-svn: 322607
2018-01-17 01:15:33 +00:00
Petr Hosek a1b57e694e [libFuzzer] Support using libc++
This is needed in case the users of libFuzzer use libc++ in their
code, which the fuzz target (libFuzzer) will be linked against.
When libc++ source is available, we build a private version of it
and link it against libFuzzer which allows using the same static
library against codebases which use both libc++ and libstdc++.

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

llvm-svn: 322604
2018-01-17 00:42:48 +00:00
Evgeniy Stepanov d96b06f2c2 [hwasan] Build runtime library with -fPIC, not -fPIE.
Summary: -fPIE can not be used when building a shared library.

Reviewers: alekseyshl, peter.smith

Subscribers: kubamracek, llvm-commits, mgorny

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

llvm-svn: 322588
2018-01-16 19:21:45 +00:00
Petr Hosek 77cfaca5f6 Reland "Install resource files into a share/ directory"
Currently these files are being installed into a root installation
directory, but this triggers an error when the installation directory
is set to an empty string which is often the case when DESTDIR is
used to control the installation destination.

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

llvm-svn: 322451
2018-01-14 03:43:14 +00:00
Francis Ricci 0a80f8924b [Sanitizers, LSan, Darwin] Allow for lack of VM_MEMORY_OS_ALLOC_ONCE
Summary:
Some time ago, the sanitizers as of r315899 were imported into gcc mainline.  This broke
bootstrap on Darwin 10 and 11, as reported in GCC PR sanitizer/82824
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82824) due to the unconditional use
of VM_MEMORY_OS_ALLOC_ONCE.  This was only introduced in Darwin 13/Mac OS X 10.9.

The use of the macro was introduced in r300450.

I couldn't find any statement which Darwin versions are supposed to be supported by
LLVM, but the trivial patch to use the macro only if present allowed the gcc bootstrap
to finish.

So far, I haven't tried building llvm/compiler-rt  on Darwin 11.  Maybe the patch is
simple enough to go in nonetheless.

Committing on behalf of ro.

Reviewers: glider, fjricci, kcc, kuba, kubamracek, george.karpenkov

Reviewed By: fjricci

Subscribers: #sanitizers, zaks.anna, srhines, dberris, kubamracek, llvm-commits

Tags: #sanitizers

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

llvm-svn: 322437
2018-01-13 14:43:49 +00:00
Evgeniy Stepanov 080e0d40b9 [hwasan] An LLVM flag to disable stack tag randomization.
Summary: Necessary to achieve consistent test results.

Reviewers: kcc, alekseyshl

Subscribers: kubamracek, llvm-commits, hiraditya

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

llvm-svn: 322429
2018-01-13 01:32:15 +00:00
Petr Hosek c2b340a5c6 Revert "[SanitizerCoverage][Fuchsia] Make TracePcGuardController linker-initialized"
This reverts commit r322424: this broke the tsan lint check.

llvm-svn: 322428
2018-01-13 00:56:28 +00:00
Petr Hosek 5bbba48752 [SanitizerCoverage][Fuchsia] Make TracePcGuardController linker-initialized
It was always intended to be.

Patch By: mcgrathr

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

llvm-svn: 322424
2018-01-13 00:29:49 +00:00
Kamil Rytarowski 4463ae4f6d Switch from Bourne shell to simply base shell to build libfuzzer
Summary: It is not necessary launching the build script with bash.

Reviewers: krytarowski

Reviewed By: krytarowski

Subscribers: llvm-commits, #sanitizers

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

llvm-svn: 322422
2018-01-12 23:45:24 +00:00
Matt Morehouse 59e4e400c3 [libFuzzer] Fix bug introduced in r322380 that always links -lc++.
llvm-svn: 322409
2018-01-12 22:10:47 +00:00
Kamil Rytarowski d6b30fffda Correct the setitimer interceptor on NetBSD
Summary:
itimerval can contain padding that may be legitimately uninitialized.

On NetBSD there are four integers of type "long, int, long, int", the
int argument stands for __sanitizer_suseconds_t. Compiler adds extra
padding in this layout.

Check every field of struct itimerval separately.

Define __sanitizer_suseconds_t as long on FreeBSD, Linux and SmartOS,
and int on NetBSD. Define __sanitizer_timeval and __sanitizer_itimerval.

Sponsored by <The NetBSD Foundation>

Reviewers: eugenis, joerg, vitalybuka

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 322399
2018-01-12 20:45:56 +00:00
Kostya Kortchinsky 0bf9c5eee5 [scudo] Add SANITIZER_CXX_ABI_LIBRARY to SCUDO_DYNAMIC_LIBS
Summary:
This is needed for the shared runtime since we are pulling RTUbsan in.

Otherwise some builds might fail with errors such as:
`error: undefined reference to '__dynamic_cast'`

Reviewers: alekseyshl, srhines

Reviewed By: srhines

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

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

llvm-svn: 322389
2018-01-12 18:45:30 +00:00
Kamil Rytarowski e81e944199 lib Fuzzer FreeBSD support
Summary: Patch by David CARLIER

Reviewers: vitalybuka, kcc, dim, emaste, davide, morehouse, george.karpenkov

Reviewed By: morehouse

Subscribers: george.karpenkov, kubamracek, srhines, mgorny, emaste, krytarowski

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

llvm-svn: 322380
2018-01-12 17:15:05 +00:00
Evgeniy Stepanov 99fa3e774d [hwasan] Stack instrumentation.
Summary:
Very basic stack instrumentation using tagged pointers.
Tag for N'th alloca in a function is built as XOR of:
 * base tag for the function, which is just some bits of SP (poor
   man's random)
 * small constant which is a function of N.

Allocas are aligned to 16 bytes. On every ReturnInst allocas are
re-tagged to catch use-after-return.

This implementation has a bunch of issues that will be taken care of
later:
1. lifetime intrinsics referring to tagged pointers are not
   recognized in SDAG. This effectively disables stack coloring.
2. Generated code is quite inefficient. There is one extra
   instruction at each memory access that adds the base tag to the
   untagged alloca address. It would be better to keep tagged SP in a
   callee-saved register and address allocas as an offset of that XOR
   retag, but that needs better coordination between hwasan
   instrumentation pass and prologue/epilogue insertion.
3. Lifetime instrinsics are ignored and use-after-scope is not
   implemented. This would be harder to do than in ASan, because we
   need to use a differently tagged pointer depending on which
   lifetime.start / lifetime.end the current instruction is dominated
   / post-dominated.

Reviewers: kcc, alekseyshl

Subscribers: srhines, kubamracek, javed.absar, hiraditya, llvm-commits

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

llvm-svn: 322324
2018-01-11 22:53:30 +00:00
Petr Hosek bf8751dc48 Revert "Install resource files into a share/ directory"
This reverts commit r322256: broke the dfsan build.

llvm-svn: 322261
2018-01-11 07:05:41 +00:00
Petr Hosek 17850f67ff Reland "Install resource files into a share/ directory"
Currently these files are being installed into a root installation
directory, but this triggers an error when the installation directory
is set to an empty string which is often the case when DESTDIR is
used to control the installation destination.

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

llvm-svn: 322256
2018-01-11 06:42:10 +00:00
Petr Hosek b00060137e Revert "Install resource files into a share/ directory"
This reverts commit r322234: this is breaking dfsan tests.

llvm-svn: 322243
2018-01-11 00:12:03 +00:00
Petr Hosek 5e9e86a538 Reland "Install resource files into a share/ directory"
Currently these files are being installed into a root installation
directory, but this triggers an error when the installation directory
is set to an empty string which is often the case when DESTDIR is
used to control the installation destination.

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

llvm-svn: 322234
2018-01-10 22:59:00 +00:00
Matt Morehouse f113deaa3c [MSan] Enable use-after-dtor instrumentation by default.
Summary:
Enable the compile-time flag -fsanitize-memory-use-after-dtor by
default. Note that the run-time option MSAN_OPTIONS=poison_in_dtor=1
still needs to be enabled for destructors to be poisoned.

Reviewers: eugenis, vitalybuka, kcc

Reviewed By: eugenis, vitalybuka

Subscribers: cfe-commits, llvm-commits

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

llvm-svn: 322221
2018-01-10 20:27:48 +00:00
Evgeniy Stepanov 29e3f5b722 [hwasan] An option to disable tag randomization.
Summary:
Avoid flaky test failures by by using a monotonic number sequence of
heap tags.

Does not affect stack tags: the way we generate those guarantees
uniqueness for at least 30-something first allocas in any function,
as well as the UAR tag.

Reviewers: alekseyshl, kcc

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 322214
2018-01-10 19:36:10 +00:00
Petr Hosek 772aea2b91 Revert "[CMake] Install resource files into a share/ directory"
This reverts commit r322153 because it broke the sanitizer bots.

llvm-svn: 322156
2018-01-10 02:24:12 +00:00
Petr Hosek de4ed26b28 [CMake] Install resource files into a share/ directory
Currently these files are being installed into a root installation
directory, but this triggers an error when the installation directory
is set to an empty string which is often the case when DESTDIR is
used to control the installation destination.

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

llvm-svn: 322153
2018-01-10 02:12:22 +00:00
Stephan Bergmann 188fd220a7 o -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17
As discussed in the mail thread <https://groups.google.com/a/isocpp.org/forum/
#!topic/std-discussion/T64_dW3WKUk> "Calling noexcept function throug non-
noexcept pointer is undefined behavior?", such a call should not be UB.
However, Clang currently warns about it.

This change removes exception specifications from the function types recorded
for -fsanitize=function, both in the functions themselves and at the call sites.
That means that calling a non-noexcept function through a noexcept pointer will
also not be flagged as UB.  In the review of this change, that was deemed
acceptable, at least for now.  (See the "TODO" in compiler-rt
test/ubsan/TestCases/TypeCheck/Function/function.cpp.)

This is the compiler-rt part of a patch covering both cfe and compiler-rt.

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

llvm-svn: 321860
2018-01-05 07:57:24 +00:00
Evgeniy Stepanov 8a86d017bb [asan] Fix build with Android NDK < 14.
NDK < 13 & API_LEVEL < 21 do not define struct mmsghdr.
Newer NDK use unified headers and provide this definition for all api
levels.

Since we can not check for the NDK version, check the api level. This
is more strict than absolutely necessary, but it does not really
matter: it is only a sanity check.

llvm-svn: 321817
2018-01-04 19:47:55 +00:00
Kostya Kortchinsky d30bea4559 [scudo] Attempt to re-enable the valloc test on armhf
Summary:
It used to fail on the bots, but I could not repro it locally. So turn it back
on to try and see if it still fails and maybe get to the heart of it.

Reviewers: alekseyshl, flowerhack

Reviewed By: alekseyshl

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

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

llvm-svn: 321812
2018-01-04 18:35:28 +00:00
Kostya Kortchinsky 541c5a0797 [scudo] s/unsigned long/size_t/ for __scudo_set_rss_limit
Summary:
`__scudo_set_rss_limit`'s `LimitMb` should really be a `size_t`. Update
accordingly the prototype. To avoid the `NOLINT` and conform with the other
Sanitizers, use the sanitizers types for the internal definition. This should
have no functional change.

Additionally, capitalize a variable name to follow the LLVM coding standards.

Reviewers: alekseyshl, flowerhack

Reviewed By: alekseyshl

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 321803
2018-01-04 17:05:04 +00:00
Kuba Mracek 773be7b496 [tsan] Separate the constants in libignore and bump the maximum for instrumented libraries
We're having some use cases where we have more than 128 (the current maximum) instrumented dynamic libraries loaded into a single process. Let's bump the limit to 1024, and separate the constants.

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

llvm-svn: 321782
2018-01-04 02:28:51 +00:00
Evgeniy Stepanov f2b2169ded [msan] Intercept sendmmsg, recvmmsg.
Summary: Extend the sendmsg test to cover all recv*.

Reviewers: vitalybuka

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 321774
2018-01-03 23:32:15 +00:00
Kamil Rytarowski 31abb45803 Add MSan interceptor for fstat(2)
Summary:
Add new MSan interceptor that corrects NetBSD's
specific handling of fstat(2).

NetBSD renames the call to __fstat50.

Add new test: test/msan/fstat.cc

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 321765
2018-01-03 22:28:39 +00:00
Evgeniy Stepanov 5e9d73c51a [hwasan] Add heap tag randomization.
Summary:
Generate tags for heap allocations from a pseudo-random sequence
seeded with getrandom(), where available.

Reviewers: kcc, alekseyshl

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 321761
2018-01-03 21:42:28 +00:00
Azharuddin Mohammed febd5e3e37 [cmake] Fix typo in test/asan/CMakeLists.txt
Summary:
[cmake] Fix typo in test/asan/CMakeLists.txt

Should be variable name instead of variable reference.

Reviewers: samsonov, rnk, smeenai, beanz

Reviewed By: smeenai

Subscribers: kubamracek, llvm-commits, mgorny

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

llvm-svn: 321760
2018-01-03 21:29:49 +00:00
Marco Castelluccio 8dfdfa65ed Hide some symbols to avoid a crash on shutdown when using code coverage
Summary:
gcov / gcda-based profiling crashes when shared libraries are unloaded

Patch by Benoit Belley and test by Marco Castelluccio for Firefox

See https://bugs.llvm.org/show_bug.cgi?id=27224 & https://bugzilla.mozilla.org/show_bug.cgi?id=1401230

Reviewers: davidxl, rnk, void

Subscribers: jessicah, marco-c, belleyb, cfe-commits

Tags: #clang

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

llvm-svn: 321703
2018-01-03 11:21:30 +00:00
Marco Castelluccio ba3a619139 Flush gcda files before unlocking them
Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=35464.

Reviewers: zturner, rnk, void

Subscribers: sylvestre.ledru, llvm-commits, #sanitizers

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

llvm-svn: 321702
2018-01-03 11:13:45 +00:00
Evgeniy Stepanov 2db14a5715 [asan] Restore asan_device_setup compatibility with older libraries.
Summary:
This way new asan_device_setup, which knows about the quirks of
recent releases of Android, can be used with older ASan runtime
library (say, from an NDK release). The library is version locked to
the compiler, and is often hard or impossible to update.

Reviewers: vitalybuka

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 321677
2018-01-02 21:35:23 +00:00
Jonas Hahnfeld 0f9768dcef [scudo] Touch memory to count as RSS
This should fix the test from https://reviews.llvm.org/D41128.

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

llvm-svn: 321627
2018-01-01 18:19:06 +00:00
Evgeniy Stepanov 39021fdd02 [msan] Intercept pthread_getname_np.
llvm-svn: 321544
2017-12-28 23:06:51 +00:00
Yi Kong d4e71e9ec7 Ignore the DISPATCH_NOESCAPE if not defined
This macro is only defined after XCode 8, causing build breakage for
build systems with prior versions. Ignore DISPATCH_NOESCAPE if not
defined.

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

llvm-svn: 321543
2017-12-28 23:06:24 +00:00
Stephan Bergmann 703478ae6e -fsanitize=vptr warnings on bad static types in dynamic_cast and typeid
...when such an operation is done on an object during con-/destruction.

(This adds a test case to compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp
that, unlike the existing test cases there, wants to detect multiple UBSan
warnings in one go. Therefore, that file had to be changed from globally using
-fno-sanitize-recover to individually using halt_on_error only where
appropriate.)

This is the compiler-rt part of a patch covering both cfe and compiler-rt.

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

llvm-svn: 321518
2017-12-28 12:45:23 +00:00
Jonas Hahnfeld 4452100a5a [XRay] Add missing include to unit test
FDRLoggingTest::MultiThreadedCycling uses std::array so we need to
include the right C++ header and not rely on transitive dependencies.

llvm-svn: 321485
2017-12-27 10:39:02 +00:00
Dimitry Andric 60c7f2d9ce Fix PR35739: chkstk and chkst2 should only be built for Windows
As reported in PR35739, rL252927 added the Windows specific chkstk and
chkstk2 sources unconditionally, and since these are assembly without a
NO_EXEC_STACK_DIRECTIVE at the end, automated vulnerability scanners
warned about the objects having an executable stack.

Avoid the problem by only including these files when Windows is
targeted.

Reviewers: compnerd, rnk, martell

Reviewed By: martell

Subscribers: mstorsjo, mgorny, martell, javed.absar, #sanitizers, llvm-commits

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

llvm-svn: 321431
2017-12-24 21:11:32 +00:00
Alex Shlyapnikov 50c342bf3f [Sanitizers] Export aligned new/delete from runtimes.
Summary:
Export aligned new/delete to make dynamic runtimes work again.

Remove all valid new/delete cases from ASan test, there's a test in
common for that.

Reviewers: eugenis

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

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

llvm-svn: 321394
2017-12-23 00:30:51 +00:00
Simon Dardis 92365cae1c Reland "[mips][compiler-rt] Provide 64bit atomic add and sub"
r318733 introduced a build failure for native MIPS32 systems for xray due
to the lack of __sync_fetch_and_add / __syn_fetch_and_sub support. This patch
extends the existing support providing atomics so that xray can be
successfully built.

The initial patch was reverted in r321292, as I suspected it may have caused the
buildbot failure. Another patch in the updates the bot fetched caused the test
failures which was reverted.

Reviewers: atanasyan, dberris

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

llvm-svn: 321383
2017-12-22 20:31:07 +00:00
Alex Shlyapnikov 7abef8f569 [Sanitizers] Disable new_delete_test.cc on Android until it's supported.
llvm-svn: 321374
2017-12-22 18:19:59 +00:00
Alex Shlyapnikov f547c96d9f [Sanitizers, CMake] Basic sanitizer Solaris support (PR 33274)
Summary:
This patch, on top of https://reviews.llvm.org/D40898, contains the build system
changes necessary to enable the Solaris/x86 sanitizer port.

The only issue of note is the libclang_rt.sancov_{begin, end} libraries: clang relies on the
linker automatically defining __start_SECNAME and __stop_SECNAME labels for
sections whose names are valid C identifiers.  This is a GNU ld extension not present
in the ELF gABI, also implemented by gold and lld, but not by Solaris ld.  To work around
this, I automatically link the sancov_{begin,end} libraries into every executable for now.
There seems to be now way to build individual startup objects like crtbegin.o/crtend.o,
so I've followed the lead of libclang_rt.asan-preinit which also contains just a single
object.

Reviewers: kcc, alekseyshl

Reviewed By: alekseyshl

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

Tags: #sanitizers

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

llvm-svn: 321373
2017-12-22 18:04:20 +00:00
Alex Shlyapnikov 5ca33a137a [MSan,TSan] Add aligned new/delete interceptors.
Summary:
Providing aligned new/delete implementations to match ASan.
Unlike ASan, MSan and TSan do not perform any additional checks
on overaligned memory, hence no sanitizer specific tests.

Reviewers: eugenis

Subscribers: kubamracek, #sanitizers, llvm-commits

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

llvm-svn: 321365
2017-12-22 17:02:17 +00:00
Reid Kleckner d0711dfba1 Include process.h for getpid on Windows in instr profiling
llvm-svn: 321313
2017-12-21 21:48:55 +00:00
Petr Hosek 016d18c61a [sanitizer] Make function declarations C-compatible
The public sanitizer headers are intended to be usable from either
C++ or C, but they declare no-argument functions with the syntax that
is not a proper prototype declaration in C. This goes unnoticed until
someone uses -Wsystem-headers.

Patch By: mcgrathr

Reviewers: phosek, vitalybuka

Reviewed By: vitalybuka

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

llvm-svn: 321305
2017-12-21 20:51:16 +00:00
Petr Hosek aa73ff2da5 [CMake] Allow passing extra CMake arguments to custom libc++
This can be used to customize the libc++ build.

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

llvm-svn: 321299
2017-12-21 20:04:10 +00:00
Simon Dardis 6e62834fef Revert "[mips][compiler-rt] Provide 64bit atomic add and sub"
This reverts commit r321260. It appears to have broken the sanitizer
bot sanitizer-ppc64be-linux.

http://lab.llvm.org:8011/builders/sanitizer-ppc64be-linux/builds/5029

Reverting to see if the buildbot turns green.

llvm-svn: 321292
2017-12-21 19:01:32 +00:00
Simon Dardis 70cd933ff8 [mips][compiler-rt] Provide 64bit atomic add and sub
r318733 introduced a build failure for native MIPS32 systems for xray due
to the lack of __sync_fetch_and_add / __syn_fetch_and_sub support. This patch
extends the existing support providing atomics so that xray can be
successfully built.

Reviewers: atanasyan, dberris

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

llvm-svn: 321260
2017-12-21 13:05:41 +00:00
Vedant Kumar 8f4976bb7b [ubsan] Diagnose noreturn functions which return (compiler-rt)
This is paired with the clang change: https://reviews.llvm.org/D40698

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

llvm-svn: 321232
2017-12-21 00:10:36 +00:00
Max Moroz a40ce7bc36 [libfuzzer] Fix UB when calculating Log(0) in StackDepthStepFunction().
Summary:
__builtin_clz used for Log calculation returns an undefined result
when argument is 0. I noticed that issue when was testing some fuzzers:

```
/src/libfuzzer/FuzzerTracePC.h:282:33: runtime error: shift exponent 450349 is too large for 32-bit type 'uint32_t' (aka 'unsigned int')
  #0 0x43d83f in operator() /src/libfuzzer/FuzzerTracePC.h:283:33
  #1 0x43d83f in void fuzzer::TracePC::CollectFeatures<fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*)::$_1>(fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*)::$_1) const /src/libfuzzer/FuzzerTracePC.h:290
  #2 0x43cbd4 in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/libfuzzer/FuzzerLoop.cpp:445:7
  #3 0x43e5f1 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:706:5
  #4 0x43e9e1 in fuzzer::Fuzzer::Loop(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:739:3
  #5 0x432f8c in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:754:6
  #6 0x42ee18 in main /src/libfuzzer/FuzzerMain.cpp:20:10
  #7 0x7f17ffeb182f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
  #8 0x407838 in _start (/out/rotate_fuzzer+0x407838)

Reviewers: kcc

Reviewed By: kcc

Subscribers: llvm-commits, #sanitizers

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

llvm-svn: 321211
2017-12-20 19:31:51 +00:00
Evgeniy Stepanov 3fd1b1a764 [hwasan] Implement -fsanitize-recover=hwaddress.
Summary: Very similar to AddressSanitizer, with the exception of the error type encoding.

Reviewers: kcc, alekseyshl

Subscribers: cfe-commits, kubamracek, llvm-commits, hiraditya

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

llvm-svn: 321203
2017-12-20 19:05:44 +00:00
Martin Storsjo f8e19b3799 [builtins] Implement __chkstk for arm64 windows
Differential Revision: https://reviews.llvm.org/D41134

llvm-svn: 321151
2017-12-20 06:52:52 +00:00
Evgeniy Stepanov 0d060044b5 [hwasan] Remove --check-prefix=CHECK (NFC)
llvm-svn: 321141
2017-12-20 02:03:47 +00:00
Evgeniy Stepanov b74d731fb0 [hwasan] Fix handling of store errors.
llvm-svn: 321121
2017-12-19 22:57:02 +00:00
Evgeniy Stepanov b3574b32c3 [hwasan] Remove unused -check-prefix in tests.
llvm-svn: 321119
2017-12-19 22:48:46 +00:00
Dimitry Andric e4f5d01033 Fix more inconsistent line endings. NFC.
llvm-svn: 321016
2017-12-18 19:46:56 +00:00
Xinliang David Li 9d301b3750 [PGO] Test case changes for D41059
Differential Revision: http://reviews.llvm.org/D41059

llvm-svn: 320999
2017-12-18 17:56:42 +00:00
Maxim Ostapenko de74bdb3d2 [asan] Add interceptor for printf_chk
There could be a situation when a specific DSO was built with FORTIFY_SOURCE option. In case asan-ed binary link against that DSO,
libasan can't handle the possible memory error because it does not have interceptors for spinrtf_chk, snprintf_chk, vprintf_chk,
vsnprintf_chk, __fprintf_chk functions. Let's interceptors for them.

Patch by Denis Khalikov.

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

llvm-svn: 320990
2017-12-18 15:31:26 +00:00
Stephan Bergmann 2635ea6601 Revert r320977 "No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17"
At least <http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-android/
builds/6013/steps/annotate/logs/stdio> complains about
__ubsan::__ubsan_handle_function_type_mismatch_abort (compiler-rt
lib/ubsan/ubsan_handlers.cc) returning now despite being declared 'noreturn', so
looks like a different approach is needed for the function_type_mismatch check
to be called also in cases that may ultimately succeed.

llvm-svn: 320981
2017-12-18 13:51:46 +00:00
Stephan Bergmann c7121f6d28 No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17
As discussed in the mail thread <https://groups.google.com/a/isocpp.org/forum/
#!topic/std-discussion/T64_dW3WKUk> "Calling noexcept function throug non-
noexcept pointer is undefined behavior?", such a call should not be UB.
However, Clang currently warns about it.

There is no cheap check whether two function type_infos only differ in noexcept,so pass those two type_infos as additional data to the function_type_mismatch 
handler (with the optimization of passing a null "static callee type" info when that is already noexcept, so the additional check can be avoided anyway).  For
the Itanium ABI (which appears to be the only one that happens to be used on
platforms that support -fsanitize=function, and which appears to only record
noexcept information for pointer-to-function type_infos, not for function
type_infos themselves), we then need to check the mangled names for occurrence
of "Do" representing "noexcept".

This is the compiler-rt part of a patch covering both cfe and compiler-rt.

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

llvm-svn: 320977
2017-12-18 13:05:41 +00:00
Kostya Kortchinsky 8bcbcea929 [sanitizer] Define __sanitizer_clockid_t on FreeBSD
Summary:
https://reviews.llvm.org/D41121 broke the FreeBSD build due to that type not
being defined on FreeBSD. As far as I can tell, it is an int, but I do not have
a way to test the change.

Reviewers: alekseyshl, kparzysz

Reviewed By: kparzysz

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

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

llvm-svn: 320931
2017-12-16 23:01:14 +00:00
Filipe Cabecinhas 237d4c2eab [ubsan-minimal] Add a path for non-POSIX (and bare-metal) use of the library
Summary:
Hook on -DKERNEL_USE (which is also used in lib/builtins) to not import
strlen and not rely on write() being implemented with the stderr on fd 2.

With this, the only requirements to use this library are:
  - "Good enough" std::atomic<void*> and std::atomic<int>
  - abort() being implemented
  - ubsan_message(const char*) being implemented

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 320831
2017-12-15 17:30:50 +00:00
Ilya Biryukov 186990c49b Added a separate install target for compilert-rt-headers
Summary:
This patch adds a new install target `install-compilert-rt-headers`,
that is similar to `install-clang-headers`.

It allows to install the headers without installing all of
compiler-rt.

Reviewers: alekseyshl, beanz

Reviewed By: beanz

Subscribers: smeenai, beanz, mgorny, #sanitizers, kcc, llvm-commits

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

llvm-svn: 320808
2017-12-15 13:20:13 +00:00
Kostya Serebryany b99a7102c1 [libFuzzer] make the tests depend on ubsan
llvm-svn: 320787
2017-12-15 01:39:52 +00:00
Kostya Kortchinsky efe3d3436a [scudo] Refactor ScudoChunk
Summary:
The initial implementation used an ASan like Chunk class that was deriving from
a Header class. Due to potential races, we ended up working with local copies
of the Header and never using the parent class fields. ScudoChunk was never
constructed but cast, and we were using `this` as the pointer needed for our
computations. This was meh.

So we refactored ScudoChunk to be now a series of static functions within the
namespace `__scudo::Chunk` that take a "user" pointer as first parameter (former
`this`). A compiled binary doesn't really change, but the code is more sensible.

Clang tends to inline all those small function (in -O2), but GCC left a few not
inlined, so we add the `INLINE` keyword to all.

Since we don't have `ScudoChunk` pointers anymore, a few variables were renamed
here and there to introduce a clearer distinction between a user pointer
(usually `Ptr`) and a backend pointer (`BackendPtr`).

Reviewers: alekseyshl, flowerhack

Reviewed By: alekseyshl

Subscribers: #sanitizers, llvm-commits

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

llvm-svn: 320745
2017-12-14 21:32:57 +00:00
Kamil Rytarowski 271018d216 [Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.

This part was initially developed inside libsanitizer in the GCC tree and should apply to
both.  Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.

I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.

Most of the changes are probably straightforward with a few exceptions:

* The Solaris syscall interface isn't stable, undocumented and can change within an
  OS release.  The stable interface is the libc interface, which I'm using here, if possible
  using the internal _-prefixed names.

* While the patch primarily target 32-bit x86, I've left a few sparc changes in.  They
  cannot currently be used with clang due to a backend limitation, but have worked
  fine inside the gcc tree.

* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
  Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.

The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11.  Only a few failures remain, some of them analyzed, some
still TBD:

    AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
    AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
    AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
    AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
    AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
    AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
    AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
    AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
    AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
    AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c

   SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
    SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations

Maybe this is good enough the get the ball rolling.

Reviewers: kcc, alekseyshl

Reviewed By: alekseyshl

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

Tags: #sanitizers

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

llvm-svn: 320740
2017-12-14 20:14:29 +00:00
Vedant Kumar d7c9336a84 [profile] Port the runtime to Solaris (retry)
This includes a few nice bits of refactoring (e.g splitting out the
exclusive locking code into a common utility).

Hopefully the Windows support is fixed now.

Patch by Rainer Orth!

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

llvm-svn: 320731
2017-12-14 19:01:04 +00:00
Vedant Kumar e8e8599ade Revert "(HEAD -> master, origin/master, origin/HEAD) [profile] Port the runtime to Solaris"
This reverts commit r320726. It looks like flock isn't available on
Windows:

http://lab.llvm.org:8011/builders/sanitizer-windows/builds/21317/steps/build%20compiler-rt/logs/stdio

llvm-svn: 320728
2017-12-14 18:50:13 +00:00
Vedant Kumar 5b0d5b45a2 [profile] Port the runtime to Solaris
This includes a few nice bits of refactoring (e.g splitting out the
exclusive locking code into a common utility).

Patch by Rainer Orth!

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

llvm-svn: 320726
2017-12-14 18:43:14 +00:00
Kostya Kortchinsky 123adb5073 [scudo] Disabling the interface test on armhf
Summary:
I will investigate the breakage tomorrow, disable on armhf to turn the bots
green over the night.

http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh/builds/2952/steps/ninja%20check%202/logs/FAIL%3A%20Scudo-armhf%3A%3A%20interface.cpp

This is post https://reviews.llvm.org/D41128.

Reviewers: alekseyshl

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

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

llvm-svn: 320665
2017-12-14 02:54:11 +00:00
Dean Michael Berris 504b0c28f3 [XRay][compiler-rt] Coalesce calls to mprotect to reduce patching overhead
Summary:
Before this change, XRay would conservatively patch sections of the code
one sled at a time. Upon testing/profiling, this turns out to take an
inordinate amount of time and cycles. For an instrumented clang binary,
the cycles spent both in the patching/unpatching routine constituted 4%
of the cycles -- this didn't count the time spent in the kernel while
performing the mprotect calls in quick succession.

With this change, we're coalescing the number of calls to mprotect from
being linear to the number of instrumentation points, to now being a
lower constant when patching all the sleds through `__xray_patch()` or
`__xray_unpatch()`. In the case of calling `__xray_patch_function()` or
`__xray_unpatch_function()` we're now doing an mprotect call once for
all the sleds for that function (reduction of at least 2x calls to
mprotect).

Reviewers: kpw, eizan

Subscribers: llvm-commits

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

llvm-svn: 320664
2017-12-14 02:51:20 +00:00
Kamil Rytarowski 6c18f027ff Set of corrections for MSan/NetBSD
Summary:
Changes:

 - Don't attempt to intercept GLIBC specific functions like __strtol_internal.
   This is required to stop intercepting it as we leak dlerror(3) for dlsym(3)
   that cannot manage to find a symbol.
 - Correct interception of fstatat(2).
 - Don't run a test for fgetgrent_r() that is missing on NetBSD.
 - Correct link_map location (offset) in Obj_Entry on x86_64 and i386.
 - Stop intercepting getpshared-like functions in pthread(3). This is feature
   is not enabled by default on NetBSD as it's unfinished.
 - Switch intercepting from UTMP to UTMPX functions.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis, kcc

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 320663
2017-12-14 01:20:16 +00:00
Kuba Mracek 2c1fa4feb1 [asan] Use linker initialization for the allocator
This saves ~2 MB of dirty memory footprint. Can be a big deal on mobile devices especially when running multiple processes with ASan.

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

llvm-svn: 320660
2017-12-14 00:07:15 +00:00
Kuba Mracek eb18bc5d22 [sanitizer] Use MADV_FREE on Darwin/BSD to release pages to the OS
MADV_DONTNEED on Linux actually mark the pages as free to be overwritten with zeroes, but on Darwin and BSD, it's just an advisory flag (the OS cannot discard the content). We should use MADV_FREE on Darwin and BSD.

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

llvm-svn: 320659
2017-12-14 00:04:30 +00:00
Matt Morehouse 6e294952b6 [libFuzzer] Add dummy call of LLVMFuzzerTestOneInput to afl_driver.
Summary:
Add dummy call of LLVMFuzzerTestOneInput to afl_driver before it starts
executing on actual inputs. Do this so that first time initialization
performed by LLVMFuzzerTestOneInput is not considered code covered by
a particular input.

Patch By: metzman

Reviewers: kcc, morehouse

Reviewed By: kcc

Subscribers: llvm-commits, Sanitizers

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

llvm-svn: 320643
2017-12-13 22:02:44 +00:00
Kostya Kortchinsky f22f5fe910 [scudo] Adding a public Scudo interface
Summary:
The first and only function to start with allows to set the soft or hard RSS
limit at runtime. Add associated tests.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: mgorny, #sanitizers, llvm-commits

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

llvm-svn: 320611
2017-12-13 20:41:35 +00:00
Kostya Kortchinsky f50246da65 [sanitizer] Introduce a vDSO aware timing function
Summary:
See D40657 & D40679 for previous versions of this patch & description.

A couple of things were fixed here to have it not break some bots.
Weak symbols can't be used with `SANITIZER_GO` so the previous version was
breakin TsanGo. I set up some additional local tests and those pass now.

I changed the workaround for the glibc vDSO issue: `__progname` is initialized
after the vDSO and is actually public and of known type, unlike
`__vdso_clock_gettime`. This works better, and with all compilers.

The rest is the same.

Reviewers: alekseyshl

Reviewed By: alekseyshl

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

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

llvm-svn: 320594
2017-12-13 16:23:54 +00:00
Kostya Kortchinsky 4ac0b1e6e9 [scudo] Inline getScudoChunk function.
Summary:
getScudoChunk function is implicitly inlined for optimized builds on
clang, but not on gcc. It's a small enough function that it seems
sensible enough to just inline it by default.

Reviewers: cryptoad, alekseyshl

Reviewed By: cryptoad

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

llvm-svn: 320592
2017-12-13 16:10:39 +00:00
Dean Michael Berris eec462f0e8 [XRay][compiler-rt] Reduce XRay log spam
This change makes XRay print the log file output only when the verbosity
level is higher than 0. It reduces the log spam in the default case when
we want XRay running silently, except when there are actual
fatal/serious errors.

We also update the documentation to show how to get the information
after the change to the default behaviour.

llvm-svn: 320550
2017-12-13 06:37:13 +00:00
Evgeniy Stepanov ecb48e523e [hwasan] Inline instrumentation & fixed shadow.
Summary: This brings CPU overhead on bzip2 down from 5.5x to 2x.

Reviewers: kcc, alekseyshl

Subscribers: kubamracek, hiraditya, llvm-commits

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

llvm-svn: 320538
2017-12-13 01:16:34 +00:00
Kostya Serebryany e9ed2327b6 [libFuzzer] change the strategy for -experimental_len_control to grow max_len slower
llvm-svn: 320531
2017-12-12 23:11:28 +00:00
Roman Lebedev 1b318b1016 [msan] LIT: Add lld testing config
Summary: A follow-up for D39508, with memory sanitizer changes.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis

Subscribers: mgorny, mehdi_amini, kcc, #sanitizers, llvm-commits

Tags: #sanitizers, #lld

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

llvm-svn: 320514
2017-12-12 19:17:52 +00:00
Petr Hosek 95d7a4197a [CMake] Support runtimes and monorepo layouts when looking for libcxx
This also slightly refactors the code that's checking the directory
presence which allows eliminating one unnecessary variable.

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

llvm-svn: 320446
2017-12-12 01:20:52 +00:00
Kostya Kortchinsky ab5f6aaa75 [sanitizer] Revert rL320409
Summary: D40679 broke a couple of builds, reverting while investigating.

Reviewers: alekseyshl

Reviewed By: alekseyshl

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

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

llvm-svn: 320417
2017-12-11 21:03:12 +00:00
Kostya Kortchinsky d276d72441 [sanitizer] Introduce a vDSO aware time function, and use it in the allocator [redo]
Summary:
Redo of D40657, which had the initial discussion. The initial code had to move
into a libcdep file, and things had to be shuffled accordingly.

`NanoTime` is a time sink when checking whether or not to release memory to
the OS. While reducing the amount of calls to said function is in the works,
another solution that was found to be beneficial was to use a timing function
that can leverage the vDSO.

We hit a couple of snags along the way, like the fact that the glibc crashes
when clock_gettime is called from a preinit_array, or the fact that
`__vdso_clock_gettime` is mangled (for security purposes) and can't be used
directly, and also that clock_gettime can be intercepted.

The proposed solution takes care of all this as far as I can tell, and
significantly improve performances and some Scudo load tests with memory
reclaiming enabled.

@mcgrathr: please feel free to follow up on
https://reviews.llvm.org/D40657#940857 here. I posted a reply at
https://reviews.llvm.org/D40657#940974.

Reviewers: alekseyshl, krytarowski, flowerhack, mcgrathr, kubamracek

Reviewed By: alekseyshl, krytarowski

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

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

llvm-svn: 320409
2017-12-11 19:23:12 +00:00
Ahmed Bougacha 7008c6bc03 Update another sanitizer test for C++14.
Follow-up to r320251.

llvm-svn: 320284
2017-12-10 05:50:23 +00:00
Kostya Serebryany de891a1946 [libFuzzer] even less aggressive step function for stack depth. Also don't use asan in one test to speed it up
llvm-svn: 320259
2017-12-09 19:18:10 +00:00
Tim Northover ad850f83ee Update sanitizer tests for C++14 default in Clang
llvm-svn: 320251
2017-12-09 13:35:52 +00:00
Kostya Serebryany f94d87aadf [libFuzzer] make the stack depth signal less agressive, otherwise we are sometimes exploding the corpus size. This still needs more analysis and tuning
llvm-svn: 320237
2017-12-09 02:45:23 +00:00
Kamil Rytarowski df8147e30d Revert change in test/msan/textdomain.cc for NetBSD
SVN r. 320226

This breaks Linux.

llvm-svn: 320236
2017-12-09 02:38:58 +00:00
Kamil Rytarowski f6510a01a6 Correct handling of the TLS/NetBSD block of the main program
Summary:
Include <sys/tls.h> for:

 - struct tls_tcb - thread control block structure
 - __HAVE___LWP_GETTCB_FAST - __lwp_gettcb_fast() is available
 - __HAVE___LWP_GETPRIVATE_FAST -  __lwp_getprivate_fast() is available
 - __HAVE_TLS_VARIANT_I - TLS Variant I for this architecture
 - __HAVE_TLS_VARIANT_II - TLS Variant II for this architecture

Rename ThreadSelfSegbase() to ThreadSelfTlsTcb and switch it
to retrieve in a portable way TCB.

Switch ThreadSelf() to retrieve pthread from struct tcb_tls.

Use dl_iterate_phdr() to find out the size of TLS block of
the main program.

Correct the index of the  TLS block of the main program
(dlpi_tls_modid); it's 1, not 2.

New NetBSD code is now CPU (NetBSD port) agnostic.

Stop sharing the same code with FreeBSD.

Sponsored by <The NetBSD Foundation>

Reviewers: dvyukov, joerg, vitalybuka

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 320234
2017-12-09 02:23:33 +00:00
Evgeniy Stepanov 9595d16893 Hardware-assisted AddressSanitizer (compiler-rt)
Summary:
Runtime library for HWASan, initial commit.
Does not randomize tags yet, does not handle stack or globals.

Reviewers: kcc, pcc, alekseyshl

Subscribers: srhines, kubamracek, dberris, mgorny, llvm-commits, krytarowski

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

llvm-svn: 320231
2017-12-09 01:31:51 +00:00
Kamil Rytarowski f318d95524 Fix test/msan/iconv.cc on NetBSD
Summary:
NetBSD still uses the old POSIX iconv(3) signature with the 2nd const argument.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 320228
2017-12-09 00:41:59 +00:00
Kamil Rytarowski 79a8c282e3 Fix test/msan/textdomain.cc on NetBSD
Summary:
This tests must be linked with -lintl for the gettext(3) features.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 320226
2017-12-09 00:39:04 +00:00
Kamil Rytarowski ff98462be3 Disable test/msan/tsearch.cc on NetBSD
Summary:
This test uses GNU-specific extension to libc: tdestroy() and as-is is not compatible with NetBSD.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 320225
2017-12-09 00:37:58 +00:00
Kamil Rytarowski a85d348111 Disable test/msan/pvalloc.cc on NetBSD
Summary:
The pvalloc(3) function is a non-standard extension missing on NetBSD.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 320224
2017-12-09 00:37:20 +00:00
Kamil Rytarowski 35542495db Fix test/msan/ifaddrs.cc for NetBSD
Summary:
NetBSD requires to include <sys/socket.h> for struct sockaddr.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 320223
2017-12-09 00:36:49 +00:00
Kamil Rytarowski 008f63c3c9 Disable test/msan/ftime.cc on NetBSD
Summary:
ftime(3) has been removed from libc/NetBSD.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 320222
2017-12-09 00:36:17 +00:00
Kamil Rytarowski fb22504594 NetBSD ships with POSIX strerror_r(3)
Summary:
Switch NetBSD from GNU to the POSIX strerror_r(3) interceptor.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 320221
2017-12-09 00:35:44 +00:00
Kamil Rytarowski 9ecd493129 Add NetBSD/x86_64 mapping in MSan
Summary:
Reuse the Linux new mapping as it is.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, vitalybuka, eugenis

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 320218
2017-12-09 00:27:52 +00:00
Matt Morehouse ffb1132e52 [libFuzzer] Add support for Fuchsia OS.
Summary:
This patch adds the initial support for Fuchsia.

- LIBFUZZER_FUCHSIA is added as an OS type in FuzzerDefs.h
- Fuchsia is, by design, not POSIX compliant. However, it does use ELF and
  supports common POSIX I/O functions. Thus, FuzzerExtFunctions.h and
  FuzzerIO.h are implemented by extending the header guards in
  FuzzerExtFunctionsWeak.cpp and FuzzerIOPosix.cpp to include
  LIBFUZZER_FUCHSIA.
- The platform-specific portions of FuzzerUtil.h are implemented by
  FuzzerUtilFuchsia.cpp, which makes use of exception ports, syscalls, and
  the launchpad library.
- The experimental equivalence server is not currently supported, so
  FuzzerShmem.h is implemented by stub methods in FuzzerShmemFuchsia.cpp.
  Any future implementation will likely involve VMOs.

Tested with ASAN/SanCov on Fuchsia/x86-64 with the canonical toy fuzzer.

Patch By: aarongreen

Reviewers: kcc, morehouse, flowerhack, phosek

Reviewed By: kcc, phosek, Eugene.Zelenko

Subscribers: srhines, mgorny, Eugene.Zelenko

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

llvm-svn: 320210
2017-12-08 22:54:44 +00:00
Kostya Serebryany 2659c63e2e [libFuzzer] honor -use_counters, sligntly change the meaning of -experimental_len_control, call UpdateFeatureFrequency only if instructed by the flag
llvm-svn: 320205
2017-12-08 22:21:42 +00:00
Xinliang David Li 3905953582 Update test case for r320180
llvm-svn: 320181
2017-12-08 19:38:42 +00:00
Kostya Kortchinsky 9fcb91b3eb [scudo] Minor code generation improvement
Summary:
It looks like clang was generating somewhat weird assembly with the current
code. `FromPrimary`, even though `const`,  was replaced every time with the code
generated for `size <= SizeClassMap::kMaxSize` instead of using a variable or
register, and `FromPrimary` didn't induce `ClassId != 0` for the compiler, so a
dead branch was generated for `getActuallyAllocatedSize(Ptr, ClassId)` since
it's never called for `ClassId = 0` (Secondary backed allocations) [this one
was more wishful thinking on my side than anything else].

I rearranged the code bit so that the generated assembly is less clunky.

Also changed 2 whitespace inconsistencies that were bothering me.

Reviewers: alekseyshl, flowerhack

Reviewed By: flowerhack

Subscribers: llvm-commits, #sanitizers

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

llvm-svn: 320160
2017-12-08 16:36:37 +00:00
Vedant Kumar 75850f57fd [ubsan] Test for pass_object_size bounds checks
llvm-svn: 320129
2017-12-08 01:51:51 +00:00
Bill Seurer c776a9f5a8 [PowerPC][asan] Update asan to handle changed memory layouts in newer kernels
In more recent Linux kernels with 47 bit VMAs the layout of virtual memory
for powerpc64 changed causing the address sanitizer to not work properly. This
patch adds support for 47 bit VMA kernels for powerpc64 and fixes up test
cases.

https://reviews.llvm.org/D40908

There is an associated patch for trunk.

Tested on several 4.x and 3.x kernel releases.

llvm-svn: 320110
2017-12-07 22:53:49 +00:00
Xinliang David Li b0c97e566f Test case update for D40873
llvm-svn: 320105
2017-12-07 22:23:43 +00:00
Evgeniy Stepanov be437e72ef [sanitizer] Simplify android_run.py.
A test-only change to pass all *SAN_OPTIONS to the device without
listing them individually.

llvm-svn: 319998
2017-12-07 01:28:44 +00:00
Kostya Serebryany a97bd9a7d3 [libFuzzer] Decrease stack usage in unit tests
Summary: With 3 Dictionary objects, each containing space of ~16k DictionaryEntry objects, the MutationDispatcher object is fairly memory heavy.  On platforms with a lower default stack size, this can cause panics in FuzzerUnittest as those tests stack-allocate the MutationDispatcher.  This may be especially problematic for platforms that do not (yet) have a way to programmatically change their stack size, aside from link-time flags.  In general, it seems more prudent to use the heap for an object of this size.

Reviewers: kcc, morehouse

Reviewed By: kcc

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

llvm-svn: 319988
2017-12-06 23:35:02 +00:00
Vlad Tsyrklevich 5407edd375 Update other SizeEnums to be of type uptr as well
llvm-svn: 319984
2017-12-06 23:02:02 +00:00
Kamil Rytarowski 0f5cb013d0 Revert SVN r, 319967
"Correct atexit(3) support in MSan/NetBSD"

This causes failures on Linux.

llvm-svn: 319981
2017-12-06 22:50:12 +00:00
Vlad Tsyrklevich 03ad4e7f46 Fix broken windows sanitizer buildbot
r319875 caused a sign comparison build failure. Explicitly set the
enum's type to be unsigned.

llvm-svn: 319977
2017-12-06 22:40:23 +00:00
Kostya Serebryany 7ac58ee3e1 [libFuzzer] fix a minor regression in printing
llvm-svn: 319975
2017-12-06 22:12:24 +00:00
Kamil Rytarowski 0192818ffe Correct atexit(3) support in MSan/NetBSD
Summary:
The NetBSD specific implementation of cxa_atexit() does not
preserve the 2nd argument if dso is equal to NULL.

Changes:

 - Split paths of handling intercepted __cxa_atexit() and atexit(3).
   This affects all supported Operating Systems.
 - Add a local stack-like structure to hold the __cxa_atexit() context.
   atexit(3) is documented in the C standard as calling callback from the
   earliest to the oldest entry. This path also fixes potential ABI
   problem of passing an argument to a function from the atexit(3)
   callback mechanism.
 - Allow usage of global vars with ctors in interceptors.
   This allows to use Vector without automatic cleaning up the structures.

This code has been modeled after TSan implementation for the same functions.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc

Reviewed By: vitalybuka

Subscribers: llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 319967
2017-12-06 21:57:39 +00:00
Kamil Rytarowski bf228b9200 Handle NetBSD symbol renaming in msan_interceptors.cc
Summary:
NetBSD renames symbols for historical and compat reasons.

Add required symbol renames in sanitizer_common_interceptors.inc:

 - gettimeofday -> __gettimeofday50
 - getrusage -> __getrusage50
 - shmctl -> __shmctl50

Additionally handle sigaction symbol mangling.
Rename the function symbol in the file to SIGACTION_SYMNAME and define
it as __sigaction14 for NetBSD and sigaction for !NetBSD. We cannot use
simple renaming with the proprocessor, as there are valid fields named
sigaction and they must be left intact.

Sponsored by <The NetBSD Foundation>

Reviewers: joerg, eugenis, vitalybuka, dvyukov

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits, #sanitizers

Tags: #sanitizers

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

llvm-svn: 319966
2017-12-06 21:32:57 +00:00
Ben Hamilton f20525bc87 [compiler-rt] Set up .arcconfig to point to new Diffusion CRT repository
Summary:
We want to automatically copy the appropriate mailing list
as well as #sanitizers for review requests to the compiler-rt repository.

For context, see the proposal and discussion here:

http://lists.llvm.org/pipermail/cfe-dev/2017-November/056032.html

Similar to D40179, I set up a new Diffusion repository with callsign
"CRT" for compiler-rt:

https://reviews.llvm.org/source/compiler-rt/

This explicitly updates compiler-rt's .arcconfig to point to the new
CRT repository in Diffusion, which will let us use Herald rules H270
and H271.

Reviewers: krytarowski, joerg, dvyukov, vitalybuka, sammccall

Reviewed By: sammccall

Subscribers: dlj, bkramer, dberris, llvm-commits, sammccall, klimek, #sanitizers

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

llvm-svn: 319954
2017-12-06 20:55:32 +00:00
Alex Shlyapnikov e85b4df435 [TSan] Make more TSan interceptors symbolizer-aware.
Summary:
Switching the rest of intercepted allocs to InternalAlloc (well, except
__libc_memalign) when current thread is 'in_symbolizer'. Symbolizer
might (and does) use allocation functions other than malloc/calloc/realloc.

posix_memalign is the one actually used, others switched just in case
(since the failure is obscure and not obvious to diagnose).

Reviewers: dvyukov

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 319929
2017-12-06 19:12:57 +00:00
Kamil Rytarowski 90b46353e7 [Sanitizers] Use SANITIZER_* macros in lib/interception
Summary:
Unlike the rest of the sanitizer code, lib/interception uses native macros like __linux__
to check for specific targets instead of the common ones like SANITIZER_LINUX.

When working on the Solaris port of the sanitizers, the current style was found to not
only be inconsistent, but clumsy to use because the canonical way to check for Solaris
is to check for __sun__ && __svr4__ which is a mouthful.

Therefore, this patch switches to use SANITIZER_* macros instead.

Tested on x86_64-pc-linux-gnu.

Reviewers: kcc, vitalybuka

Reviewed By: vitalybuka

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

Tags: #sanitizers

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

llvm-svn: 319906
2017-12-06 17:02:00 +00:00
Kostya Kortchinsky ddf4ef3959 [scudo] Correct performance regression in Secondary
Summary:
This wasn't noticed: `RoundUpTo` doesn't produce a constant expression, so the
sizes were not constant either. Enforce them to be static const, replace
`RoundUpTo` by its expression. The compiler can now optimize the associated
computations accordingly.

Also looking at the produced assembly, `PageSize` was fetched multiple times
during `Allocate`, so keep a local value of it. As a result it's fetched once
and kept in a register.

Reviewers: alekseyshl, flowerhack

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 319903
2017-12-06 16:53:24 +00:00
Simon Dardis b0f8e3511b [compiler-rt][xray][cmake] Fix a build issue caused by set/item mixup
r319165 introduced a change to CMakeLists.txt for xray where the set of supported
architectures for XRay was iterated over, tested if they could be targeted then
passed to add_compiler_rt_object_libraries. However all targets were passed,
rather than the architecture that was just tested. For cases such as MIPS, where
mips and mips64 are supported, cmake would then test if mips64 could be targetted
resulting in an attempt to produce multiple identical logical target names, falling
afowl of CMP0002.

Reviewers: dberris

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

llvm-svn: 319893
2017-12-06 14:03:41 +00:00