Commit Graph

14100 Commits

Author SHA1 Message Date
Vitaly Buka f7164c7714 [NFC][scudo] Add reference to a QEMU bug
D101031 added workaround for the bug.
2021-04-28 14:57:53 -07:00
Tres Popp d1e08b124c Revert "tsan: refactor fork handling"
This reverts commit e1021dd1fd.
2021-04-28 14:08:33 +02:00
Alex Richardson 777ca513c8 [builtins] Fix ABI-incompatibility with GCC for floating-point compare
While implementing support for the float128 routines on x86_64, I noticed
that __builtin_isinf() was returning true for 128-bit floating point
values that are not infinite when compiling with GCC and using the
compiler-rt implementation of the soft-float comparison functions.
After stepping through the assembly, I discovered that this was caused by
GCC assuming a sign-extended 64-bit -1 result, but our implementation
returns an enum (which then has zeroes in the upper bits) and therefore
causes the comparison with -1 to fail.

Fix this by using a CMP_RESULT typedef and add a static_assert that it
matches the GCC soft-float comparison return type when compiling with GCC
(GCC has a __libgcc_cmp_return__ mode that can be used for this purpose).

Also move the 3 copies of the same code to a shared .inc file.

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D98205
2021-04-28 12:19:19 +01:00
Vitaly Buka b1a77e465e [scudo] Enable arm32 arch 2021-04-27 18:35:45 -07:00
Dmitry Vyukov f69853ac40 tsan: fix build with COMPILER_RT_TSAN_DEBUG_OUTPUT
COMPILER_RT_TSAN_DEBUG_OUTPUT enables TSAN_COLLECT_STATS,
which changes layout of runtime structs (some structs contain
stats when the option is enabled).
It's not OK to build runtime with the define, but tests without it.
The error is detected by build_consistency_stats/nostats.
Fix this by defining TSAN_COLLECT_STATS for tests to match the runtime.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101386
2021-04-27 22:38:56 +02:00
Dmitry Vyukov e1021dd1fd tsan: refactor fork handling
Commit efd254b636 ("tsan: fix deadlock in pthread_atfork callbacks")
fixed another deadlock related to atfork handling.
But builders with DCHECKs enabled reported failures of
pthread_atfork_deadlock2.c and pthread_atfork_deadlock3.c tests
related to the fact that we hold runtime locks on interceptor exit:
https://lab.llvm.org/buildbot/#/builders/70/builds/6727
This issue is somewhat inherent to the current approach,
we indeed execute user code (atfork callbacks) with runtime lock held.

Refactor fork handling to not run user code (atfork callbacks)
with runtime locks held. This change does this by installing
own atfork callbacks during runtime initialization.
Atfork callbacks run in LIFO order, so the expectation is that
our callbacks run last, right before the actual fork.
This way we lock runtime mutexes around fork, but not around
user callbacks.

Extend tests to also install after fork callbacks just to cover
more scenarios. Some tests also started reporting real races
that we previously suppressed.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101385
2021-04-27 22:37:27 +02:00
Evgenii Stepanov 5275d772da Revert "tsan: fix deadlock in pthread_atfork callbacks"
Tests fail on debug builders. See the forward fix in
https://reviews.llvm.org/D101385.

This reverts commit efd254b636.
2021-04-27 12:36:31 -07:00
Evgenii Stepanov 561f4b9087 Fix -Wunused-but-set-variable warning in msan_test.cpp 2021-04-27 12:07:13 -07:00
Vitaly Buka 0e6f934cc3 [NFC][lsan] Another attempt to fix arm bot 2021-04-27 10:46:36 -07:00
Dmitry Vyukov efd254b636 tsan: fix deadlock in pthread_atfork callbacks
We take report/thread_registry locks around fork.
This means we cannot report any bugs in atfork handlers.
We resolved this by enabling per-thread ignores around fork.
This resolved some of the cases, but not all.
The added test triggers a race report from a signal handler
called from atfork callback, we reset per-thread ignores
around signal handlers, so we tried to report it and deadlocked.
But there are more cases: a signal handler can be called
synchronously if it's sent to itself. Or any other report
types would cause deadlocks as well: mutex misuse,
signal handler spoiling errno, etc.
Disable all reports for the duration of fork with
thr->suppress_reports and don't re-enable them around
signal handlers.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D101154
2021-04-27 13:25:26 +02:00
Vitaly Buka 3c47f5f46e [asan][NFC] Fix "not used" warning in test 2021-04-26 20:07:20 -07:00
Leonard Chan a786f2badc [compiler-rt][hwasan] Add definition for Symbolizer::SymbolizeFrame
This is undefined if SANITIZER_SYMBOLIZER_MARKUP is 1, which is the case for
Fuchsia, and will result in a undefined symbol error. This function is needed
by hwasan for online symbolization, but is not needed for us since we do
offline symbolization.

Differential Revision: https://reviews.llvm.org/D99386
2021-04-26 13:25:10 -07:00
Vitaly Buka 337a024bba [scudo][NFC] Fix cast warning 2021-04-25 15:47:28 -07:00
Vitaly Buka 98a7563261 [scudo] Mark ARM64 as supported platform 2021-04-25 15:47:28 -07:00
Vitaly Buka 51b4a7ef52 [sanitizer] Use COMPILER_RT_EMULATOR with gtests
Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D100998
2021-04-25 15:41:13 -07:00
Lang Hames 5e537ea1d7 [ORC-RT] Re-apply "Initial ORC Runtime directories and build..." with fixes.
This reapplies 1e1d75b190, which was reverted in ce1a4d5323 due to build
failures.

The unconditional dependencies on clang and llvm-jitlink in
compiler-rt/test/orc/CMakeLists.txt have been removed -- they don't appear to
be necessary, and I suspect they're the cause of the build failures seen
earlier.
2021-04-24 16:00:20 -07:00
Lang Hames ce1a4d5323 Revert "[ORC-RT] Initial ORC Runtime directories and build system files."
Some builders failed with a missing clang dependency. E.g.

CMake Error at /Users/buildslave/jenkins/workspace/clang-stage1-RA/clang-build \
  /lib/cmake/llvm/AddLLVM.cmake:1786 (add_dependencies):
The dependency target "clang" of target "check-compiler-rt" does not exist.

Reverting while I investigate.

This reverts commit 1e1d75b190.
2021-04-23 20:36:59 -07:00
Lang Hames 1e1d75b190 [ORC-RT] Initial ORC Runtime directories and build system files.
This patch contains initial directories and build files for the ORC runtime.

Differential Revision: https://reviews.llvm.org/D100711
2021-04-23 20:21:22 -07:00
Mitch Phillips 643ccf6e4b Revert "[Scudo] Use GWP-ASan's aligned allocations and fixup postalloc hooks."
This reverts commit a683abe5c0.

Broke the upstream buildbots:
https://lab.llvm.org/buildbot/#/builders/37/builds/3731/steps/16/logs/stdio
2021-04-23 15:40:38 -07:00
Peter Collingbourne f2819ee6cc scudo: Work around gcc 8 conversion warning.
Should fix:
https://lab.llvm.org/buildbot#builders/99/builds/2953
2021-04-23 11:26:12 -07:00
Mitch Phillips f1a47181f5 [hwasan] Remove untagging of kernel-consumed memory
Now that page aliasing for x64 has landed, we don't need to worry about
passing tagged pointers to libc, and thus D98875 removed it.
Unfortunately, we still test on aarch64 devices that don't have the
kernel tagged address ABI (https://reviews.llvm.org/D98875#2649269).

All the memory that we pass to the kernel in these tests is from global
variables. Instead of having architecture-specific untagging mechanisms
for this memory, let's just not tag the globals.

Reviewed By: eugenis, morehouse

Differential Revision: https://reviews.llvm.org/D101121
2021-04-23 11:04:36 -07:00
Mitch Phillips a683abe5c0 [Scudo] Use GWP-ASan's aligned allocations and fixup postalloc hooks.
This patch does a few cleanup things:
 1. The non-standalone scudo has a problem where GWP-ASan allocations
 may not meet alignment requirements where Scudo was requested to have
 alignment >= 16. Use the new GWP-ASan API to fix this.
 2. The standalone variant loses some debugging information inside of
 GWP-ASan because we ask GWP-ASan to allocate an aligned size in the
 frontend. This means reports end up with 'UaF on a 16-byte allocation'
 for a 1-byte allocation with 16-byte alignment. Also use the new API to
 fix this.
 3. Add post-alloc hooks for GWP-ASan intercepted allocations, and add
 stats tracking for GWP-ASan allocations.
 4. Add a small test that checks the alignment of the frontend
 allocator, so that it can be used under GWP-ASan torture mode.
 5. Add GWP-ASan torture mode as a testing configuration to catch these
 regressions.

Depends on D94830, D95889.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D95884
2021-04-23 10:07:36 -07:00
Peter Collingbourne 0a5576ecf0 scudo: Store header on deallocation before retagging memory.
From a cache perspective it's better to store the header immediately
after loading it. If we delay this operation until after we've
retagged it's more likely that our header will have been evicted from
the cache and we'll need to fetch it again in order to perform the
compare-exchange operation.

For similar reasons, store the deallocation stack before retagging
instead of afterwards.

Differential Revision: https://reviews.llvm.org/D101137
2021-04-23 09:32:16 -07:00
Vitaly Buka a062140a9e [NFC] Suppress cpplint warning in test 2021-04-22 20:20:52 -07:00
Vitaly Buka 619ecba5bc [NFC] Fix cpplint warning 2021-04-22 19:05:20 -07:00
Peter Collingbourne 484b6648fd scudo: Only static_assert for compressed LSB format with clang.
It looks like there's some old version of gcc that doesn't like this
static_assert (I couldn't reproduce the issue with gcc 8, 9 or 10).
Work around the issue by only checking the static_assert under clang,
which should provide sufficient coverage.

Should hopefully fix this buildbot:
https://lab.llvm.org/buildbot/#/builders/112/builds/5356
2021-04-22 16:11:52 -07:00
Peter Collingbourne a6500b013a scudo: Optimize getSizeLSBByClassId() by compressing the table into an integer if possible. NFCI.
With AndroidSizeClassMap all of the LSBs are in the range 4-6 so we
only need 2 bits of information per size class. Furthermore we have
32 size classes, which conveniently lets us fit all of the information
into a 64-bit integer. Do so if possible so that we can avoid a table
lookup entirely.

Differential Revision: https://reviews.llvm.org/D101105
2021-04-22 15:33:29 -07:00
Peter Collingbourne 4e88e5877c scudo: Use a table to look up the LSB for computing the odd/even mask. NFCI.
In the most common case we call computeOddEvenMaskForPointerMaybe()
from quarantineOrDeallocateChunk(), in which case we need to look up
the class size from the SizeClassMap in order to compute the LSB. Since
we need to do a lookup anyway, we may as well look up the LSB itself
and avoid computing it every time.

While here, switch to a slightly more efficient way of computing the
odd/even mask.

Differential Revision: https://reviews.llvm.org/D101018
2021-04-22 11:19:55 -07:00
Vitaly Buka 686328263e Revert "[sanitizer] Use COMPILER_RT_EMULATOR with gtests"
Missed review comments.

This reverts commit e25082961c.
2021-04-22 11:15:55 -07:00
Vitaly Buka d423509b80 [scudo] Check if MADV_DONTNEED zeroes memory
QEMU just ignores MADV_DONTNEED
b1cffefa1b/linux-user/syscall.c (L11941)

Depends on D100998.

Differential Revision: https://reviews.llvm.org/D101031
2021-04-22 10:40:18 -07:00
Vitaly Buka e25082961c [sanitizer] Use COMPILER_RT_EMULATOR with gtests
Differential Revision: https://reviews.llvm.org/D100998
2021-04-22 10:33:50 -07:00
Vitaly Buka 149d5a8c47 [lsan] Temporarily disable new check broken on arm7 2021-04-22 10:05:02 -07:00
Jianzhou Zhao 7fdf270965 [dfsan] Track origin at loads
The first version of origin tracking tracks only memory stores. Although
    this is sufficient for understanding correct flows, it is hard to figure
    out where an undefined value is read from. To find reading undefined values,
    we still have to do a reverse binary search from the last store in the chain
    with printing and logging at possible code paths. This is
    quite inefficient.

    Tracking memory load instructions can help this case. The main issues of
    tracking loads are performance and code size overheads.

    With tracking only stores, the code size overhead is 38%,
    memory overhead is 1x, and cpu overhead is 3x. In practice #load is much
    larger than #store, so both code size and cpu overhead increases. The
    first blocker is code size overhead: link fails if we inline tracking
    loads. The workaround is using external function calls to propagate
    metadata. This is also the workaround ASan uses. The cpu overhead
    is ~10x. This is a trade off between debuggability and performance,
    and will be used only when debugging cases that tracking only stores
    is not enough.

Reviewed By: gbalats

Differential Revision: https://reviews.llvm.org/D100967
2021-04-22 16:25:24 +00:00
Peter Collingbourne e4fa0b307f scudo: Obtain tag from pointer instead of loading it from memory. NFCI.
Since we already have a tagged pointer available to us, we can just
extract the tag from it and avoid an LDG instruction.

Differential Revision: https://reviews.llvm.org/D101014
2021-04-21 21:47:49 -07:00
Matt Morehouse 3511022f5f [HWASan] Untag argument to __hwasan_tag_memory.
__hwasan_tag_memory expects untagged pointers, so make sure our pointer
is untagged.
2021-04-21 17:08:43 -07:00
Peter Collingbourne 3d47e003e9 scudo: Make prepareTaggedChunk() and resizeTaggedChunk() generic.
Now that we have a more efficient implementation of storeTags(),
we should start using it from resizeTaggedChunk(). With that, plus
a new storeTag() function, resizeTaggedChunk() can be made generic,
and so can prepareTaggedChunk(). Make it so.

Now that the functions are generic, move them to combined.h so that
memtag.h no longer needs to know about chunks.

Differential Revision: https://reviews.llvm.org/D100911
2021-04-21 13:53:39 -07:00
Peter Collingbourne 46c59d91dc scudo: Use DC GZVA instruction in storeTags().
DC GZVA can operate on multiple granules at a time (corresponding to
the CPU's cache line size) so we can generally expect it to be faster
than STZG in a loop.

Differential Revision: https://reviews.llvm.org/D100910
2021-04-21 13:53:26 -07:00
Roland McGrath d9b2641aa5 [scudo] Avoid empty statement warnings
An empty macro that expands to just `... else ;` can get
warnings from some compilers (e.g. GCC's -Wempty-body).

Reviewed By: cryptoad, vitalybuka

Differential Revision: https://reviews.llvm.org/D100693
2021-04-21 12:39:09 -07:00
Emily Shi 6ae7fc0a29 [compiler-rt] check max address from kernel is <= mmap range size
If these sizes do not match, asan will not work as expected. Previously, we added compile-time checks for non-iOS platforms. We check at run time for iOS because we get the max VM size from the kernel at run time.

rdar://76477969

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D100784
2021-04-21 12:02:48 -07:00
Vitaly Buka 5e9e463e1f [lsan] Test to show lsan dependency on globals
This test from @MaskRay comment on D69428. The patch is looking to
break this behavior. If we go with D69428 I hope we will have some
workaround for this test or include explicit test update into the patch.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D100906
2021-04-20 22:00:26 -07:00
Fangrui Song 031c40dc3c [sanitizer] Fix glibc sparc build and add GetTls support
sanitizer_linux_libcdep.cpp doesn't build for Linux sparc (with minimum support
but can build) after D98926. I wasn't aware because the file didn't mention
`__sparc__`.

While here, add the relevant support since it does not add complexity
(the D99566 approach).  Adds an explicit `#error` for unsupported
non-Android Linux and FreeBSD architectures.

ThreadDescriptorSize is only used by lsan to scan thread-specific data keys in
the thread control block.

On TLS Variant II architectures (i386/x86_64/s390/sparc), our dl_iterate_phdr
based approach can cover the region from the first byte of the static TLS block
(static TLS surplus) to the thread pointer.
We just need to extend the range to include the first few members of struct
pthread. offsetof(struct pthread, specific_used) satisfies the requirement and
has not changed since 2007-05-10. We don't need to update ThreadDescriptorSize
for each glibc version.

Technically we could use the 524/1552 for x86_64 as well but there is potential
risk that large applications with thousands of shared object dependency may
dislike the time complexity increase if there are many threads, so I don't make
the simplification for now.

Differential Revision: https://reviews.llvm.org/D100892
2021-04-20 17:42:41 -07:00
Dan Liew 6f4f0afaa8 [Compiler-rt] Fix bug when considering CMake path returned by llvm-config.
The previous check was wrong because it only checks that the LLVM CMake
directory exists. However, it's possible that the directory exists but
the `LLVMConfig.cmake` file does not. When this happens we would
incorectly try to include the non-existant file.

To fix this we make the check stricter by checking that the file
we want to include actually exists.

This is a follow up to fd28517d87.

rdar://76870467
2021-04-20 11:57:20 -07:00
Evgenii Stepanov fbb9132e71 Fix android-x86 library name in asan_device_setup.
https://reviews.llvm.org/D26764 removed i686 variants of compiler-rt
libraries and canonicalized the i386 name.

https://reviews.llvm.org/D37278 partially reverted the previous change
to keep i686 name on Android, but did not update asan_device_setup
script.

This changes fixes asan_device_setup.

Differential Revision: https://reviews.llvm.org/D100505
2021-04-19 17:39:58 -07:00
Emily Shi cc2b62a06e [compiler-rt] assert max virtual address is <= mmap range size
If these sizes do not match, asan will not work as expected.

If possible, assert at compile time that the vm size is less than or equal to mmap range.
If a compile time assert is not possible, check at run time (for iOS)

rdar://76477969

Reviewed By: delcypher, yln

Differential Revision: https://reviews.llvm.org/D100239
2021-04-19 14:01:07 -07:00
Emily Shi 94ba3b6e3b [compiler-rt][asan] use full vm range on apple silicon macs
We previously shrunk the mmap range size on ios, but those settings got inherited by apple silicon macs.
Don't shrink the vm range on apple silicon Mac since we have access to the full range.

Also don't shrink vm range for iOS simulators because they have the same range as the host OS, not the simulated OS.

rdar://75302812

Reviewed By: delcypher, kubamracek, yln

Differential Revision: https://reviews.llvm.org/D100234
2021-04-19 12:12:26 -07:00
Sylvestre Ledru 485e561f8d Try to unbreak the compiler-rt build on s390x
Introduced by:
3d1d7156e9
2021-04-19 13:17:47 +02:00
Fangrui Song 3d1d7156e9 [sanitizer] Don't call __tls_get_addr on s390x after D98926
glibc s390x doesn't define __tls_get_addr.

Fix PR50017
2021-04-18 10:42:44 -07:00
David CARLIER 61fc02dc03 [Sanitizers] Fix build 2021-04-17 11:15:31 +01:00
David Carlier 0df0d6acea [Sanitizers] DragonFlyBSD adding support for builtins
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D89653
2021-04-17 11:10:35 +01:00
David Carlier 4583759414 [Sanitizers] Undefined Behavior Sanitizer support for DragonFlyBSD
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D89631
2021-04-17 11:08:00 +01:00
Fangrui Song 08843a0c3f [sanitizer] GetTls: work around ppc64 with glibc<2.25(?) or GNU ld 2.30
GNU ld 2.26 and GNU ld 2.31 seem fine but GNU ld 2.30 has mysterious
segfaults linking msan tests.
2021-04-16 14:03:28 -07:00
Vitaly Buka b93629dd33 Address D100645 comment 2021-04-16 11:28:41 -07:00
Vitaly Buka 82150606fb Sanitizer built against glibc 2.34 doesn't work
As mentioned in https://gcc.gnu.org/PR100114 , glibc starting with the
https://sourceware.org/git/?p=glibc.git;a=commit;h=6c57d320484988e87e446e2e60ce42816bf51d53
change doesn't define SIGSTKSZ and MINSIGSTKSZ macros to constants, but to sysconf function call.
sanitizer_posix_libcdep.cpp has
static const uptr kAltStackSize = SIGSTKSZ * 4;  // SIGSTKSZ is not enough.
which is generally fine, just means that when SIGSTKSZ is not a compile time constant will be initialized later.
The problem is that kAltStackSize is used in SetAlternateSignalStack which is called very early, from .preinit_array
initialization, i.e. far before file scope variables are constructed, which means it is not initialized and
mmapping 0 will fail:
==145==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)

Here is one possible fix, another one could be to make kAltStackSize a preprocessor macro if _SG_SIGSTKSZ is defined
(but perhaps with having an automatic const variable initialized to it so that sysconf isn't at least called twice
during SetAlternateSignalStack.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D100645
2021-04-16 11:21:03 -07:00
Alexey Vishnyakov 827ccc93b8 [fuzzer] Print reloaded file paths
In order to integrate libFuzzer with a dynamic symbolic execution tool
Sydr we need to print loaded file paths.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D100303
2021-04-16 10:00:24 -07:00
Fangrui Song 376db8eaef [sanitizer] Mark g_use_dlpi_tls_data as unused
There is a -Wunused-variable warning on Android
2021-04-16 09:28:51 -07:00
George Balatsouras 98b114d480 [dfsan] Remove hard-coded constant in release_shadow_space.c
Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D100608
2021-04-15 17:24:35 -07:00
George Balatsouras b2b59f622e [dfsan] Add test for origin tracking stack traces
Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D100518
2021-04-15 16:22:47 -07:00
Fangrui Song afec953857 [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux and use it on musl/FreeBSD
... so that FreeBSD specific GetTls/glibc specific pthread_self code can be
removed. This also helps FreeBSD arm64/powerpc64 which don't have GetTls
implementation yet.

GetTls is the range of

* thread control block and optional TLS_PRE_TCB_SIZE
* static TLS blocks plus static TLS surplus

On glibc, lsan requires the range to include
`pthread::{specific_1stblock,specific}` so that allocations only referenced by
`pthread_setspecific` can be scanned.

This patch uses `dl_iterate_phdr` to collect TLS blocks. Find the one
with `dlpi_tls_modid==1` as one of the initially loaded module, then find
consecutive ranges. The boundaries give us addr and size.

This allows us to drop the glibc internal `_dl_get_tls_static_info` and
`InitTlsSize`. However, huge glibc x86-64 binaries with numerous shared objects
may observe time complexity penalty, so exclude them for now. Use the simplified
method with non-Android Linux for now, but in theory this can be used with *BSD
and potentially other ELF OSes.

This removal of RISC-V `__builtin_thread_pointer` makes the code compilable with
more compiler versions (added in Clang in 2020-03, added in GCC in 2020-07).

This simplification enables D99566 for TLS Variant I architectures.

Note: as of musl 1.2.2 and FreeBSD 12.2, dlpi_tls_data returned by
dl_iterate_phdr is not desired: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=254774
This can be worked around by using `__tls_get_addr({modid,0})` instead
of `dlpi_tls_data`. The workaround can be shared with the workaround for glibc<2.25.

This fixes some tests on Alpine Linux x86-64 (musl)

```
test/lsan/Linux/cleanup_in_tsd_destructor.c
test/lsan/Linux/fork.cpp
test/lsan/Linux/fork_threaded.cpp
test/lsan/Linux/use_tls_static.cpp
test/lsan/many_tls_keys_thread.cpp

test/msan/tls_reuse.cpp
```

and `test/lsan/TestCases/many_tls_keys_pthread.cpp` on glibc aarch64.

The number of sanitizer test failures does not change on FreeBSD/amd64 12.2.

Differential Revision: https://reviews.llvm.org/D98926
2021-04-15 15:34:43 -07:00
Kostya Kortchinsky 3f97c66b00 [scudo][standalone] Fuchsia related fixes
While attempting to roll the latest Scudo in Fuchsia, some issues
arose. While trying to debug them, it appeared that `DCHECK`s were
also never exercised in Fuchsia. This CL fixes the following
problems:
- the size of a block in the TransferBatch class must be a multiple
  of the compact pointer scale. In some cases, it wasn't true, which
  lead to obscure crashes. Now, we round up `sizeof(TransferBatch)`.
  This only materialized in Fuchsia due to the specific parameters
  of the `DefaultConfig`;
- 2 `DCHECK` statements in Fuchsia were incorrect;
- `map()` & co. require a size multiple of a page (as enforced in
  Fuchsia `DCHECK`s), which wasn't the case for `PackedCounters`.
- In the Secondary, a parameter was marked as `UNUSED` while it is
  actually used.

Differential Revision: https://reviews.llvm.org/D100524
2021-04-15 13:26:23 -07:00
Martijn Vels 3c23807569 Add convenient composed tsan constants
This change adds convenient composed constants to be used for tsan_read_try_lock annotations, reducing the boilerplate at the instrumentation site.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D99595
2021-04-15 10:25:41 +02:00
Vitaly Buka 2a894b698c [scudo] Restore zxtest compatibility
Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D100426
2021-04-14 22:21:06 -07:00
Evgenii Stepanov 51aa61e74b [hwasan] Fix lock contention on thread creation.
Do not hold the free/live thread list lock longer than necessary.
This change speeds up the following benchmark 10x.

constexpr int kTopThreads = 50;
constexpr int kChildThreads = 20;
constexpr int kChildIterations = 8;

void Thread() {
  for (int i = 0; i < kChildIterations; ++i) {
    std::vector<std::thread> threads;
    for (int i = 0; i < kChildThreads; ++i)
      threads.emplace_back([](){});
    for (auto& t : threads)
      t.join();
  }
}

int main() {
  std::vector<std::thread> threads;
  for (int i = 0; i < kTopThreads; ++i)
    threads.emplace_back(Thread);
  for (auto& t : threads)
    t.join();
}

Differential Revision: https://reviews.llvm.org/D100348
2021-04-14 17:13:15 -07:00
Ties Stuij 3b9dc59dbf [arm][compiler-rt] add armv8m.main and arv8.1m.main targets
These changes were enough to compile compiler-rt builtins for armv8m.main and
armv8.1m.main.

Differential Revision: https://reviews.llvm.org/D99600
2021-04-14 16:41:03 +01:00
Roland McGrath 5c500c9f01 [scudo] Make MTE inline asm compatible with GNU assembler
The GNU assembler can't parse `.arch_extension ...` before a `;`.
So instead uniformly use raw string syntax with separate lines
instead of `;` separators in the assembly code.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D100413
2021-04-13 18:11:42 -07:00
Matt Morehouse b351590bae [libFuzzer] Fix fuzzer-oom.test.
SinkPtr was not correctly marked as volatile, causing the malloc to get
optimized out.  This was causing 20-minute timeouts for the test and no
OOM.
2021-04-13 11:33:41 -07:00
Matt Morehouse 4230249048 [libFuzzer] Fix MSan false positives with custom mutators.
We need to unpoison parameters before calling into MSan-instrumented
user-defined mutators.

Addresses https://github.com/google/oss-fuzz/issues/4605.

Reviewed By: metzman

Differential Revision: https://reviews.llvm.org/D100355
2021-04-13 10:49:42 -07:00
Freddy Ye b28ec3fd18 [compiler-rt][X86] fix build fail after "[X86] Support -march=rocketlake"
This copy error will cause a failed builder on sanitizer-x86_64-linux
2021-04-13 14:33:12 +08:00
Freddy Ye 3fc1fe8db8 [X86] Support -march=rocketlake
Reviewed By: skan, craig.topper, MaskRay

Differential Revision: https://reviews.llvm.org/D100085
2021-04-13 09:48:13 +08:00
Pirama Arumuga Nainar 5d214238a1 [compiler-rt][aarch64] Add PAC-RET/BTI property to hwasan_interceptors_vfork.S
D100143 added similar annotations but missed this file.

Differential Revision: https://reviews.llvm.org/D100354
2021-04-12 17:17:33 -07:00
Julian Lettner 05df5c54e8 [TSan] Allow test contents to be copied before execution
Allow test contents to be copied before execution by using
`%ld_flags_rpath_so`, `%ld_flags_rpath_exe`, and `%dynamiclib`
substitutions.

rdar://76302416

Differential Revision: https://reviews.llvm.org/D100240
2021-04-12 13:30:06 -07:00
Emily Shi 20f38d0142 [compiler-rt] add SANITIZER_OSX
This will allow us to make osx specific changes easier. Because apple silicon macs also run on aarch64, it was easy to confuse it with iOS.

rdar://75302812

Reviewed By: yln

Differential Revision: https://reviews.llvm.org/D100157
2021-04-12 11:45:45 -07:00
Mitch Phillips 15689f3af0 [asan] Replaceable new/delete is unsupported in Windows.
Mark the test as unsupported to bring the bot online. Could probably be
permanently fixed by using one of the workarounds already present in
compiler-rt.
2021-04-12 09:50:34 -07:00
Daniel Kiss a46effbd2a [compiler-rt][aarch64] Add PAC-RET/BTI support to HWASAN.
Support for -mbranch-protection.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D100143
2021-04-12 17:02:45 +02:00
Jim Lin dd4c999c23 fix typo in a CMake SANITIZER_CAN_USE_CXXABI variable initial definition
The current variable name isn't used anywhere else, which indicates it's
a typo.  Let's fix it before someone copy+pastes it somewhere else.

Reviewed By: Jim

Differential Revision: https://reviews.llvm.org/D39157
2021-04-12 14:05:37 +08:00
Mitch Phillips 7df30e77d4 [ASan] Allow new/delete replacement by making interceptors weak
ASan declares these functions as strongly-defined, which results in
'duplicate symbol' errors when trying to replace them in user code when
linking the runtimes statically.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D100220
2021-04-09 14:19:39 -07:00
Kostya Kortchinsky 50979defc9 [scudo][standalone] Use BatchClassId in drain rather than 0
D99763 fixed `SizeClassAllocatorLocalCache::drain` but with the
assumption that `BatchClassId` is 0 - which is currently true. I would
rather not make the assumption so that if we ever change the ID of
the batch class, the loop would still work. Since `BatchClassId` is
used more often in `local_cache.h`, introduce a constant so that we
don't have to specify `SizeClassMap::` every time.

Differential Revision: https://reviews.llvm.org/D100062
2021-04-09 13:42:05 -07:00
Alex Richardson ed0bf875a9 [builtins] Avoid enum name conflicts with fenv.h
After a follow-up change (D98332) this header can be included the same time
as fenv.h when running the tests. To avoid enum members conflicting with
the macros/enums defined in the host fenv.h, prefix them with CRT_.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D98333
2021-04-09 18:48:49 +01:00
Leonard Chan a7b51d8a4f [compiler-rt][hwasan] Add C++17 new/delete operators with alignment
Differential Revision: https://reviews.llvm.org/D99368
2021-04-08 15:44:39 -07:00
David Spickett 466fab5c94 [lsan] Mark 2 new lsan tests unsupported on arm-linux
These tests were added in:
1daa48f005
59e422c90b

malloc_zero.c and realloc_too_big.c fail when only
leak sanitizer is enabled.
http://lab.llvm.org:8011/#/builders/59/builds/1635
(also in an armv8 32 bit build)

(I would XFAIL them but the same test is run with
address and leak sanitizer enabled and that one does
pass)
2021-04-08 15:57:46 +01:00
Luís Marques 0c3bc1f3a4 [ASan][RISCV] Fix RISC-V memory mapping
Fixes the ASan RISC-V memory mapping (originally introduced by D87580 and
D87581). This should be an improvement both in terms of first principles
soundness and observed test failures --- test failures would occur
non-deterministically depending on the ASLR random offset.

On RISC-V Linux (64-bit), `TASK_UNMAPPED_BASE` is currently defined as
`PAGE_ALIGN(TASK_SIZE / 3)`. The non-power-of-two divisor makes the result
be the not very round number 0x1555556000. That address had to be further
rounded to ensure page alignment after the shadow scale shifting is applied.
Still, that value explains why the mapping table may look less regular than
expected.

Further cleanups:
- Moved the mapping table comment, to ensure that the two Linux/AArch64
tables stayed together;
- Removed mention of Sv48. Neither the original mapping nor this one are
compatible with an actual Linux Sv48 address space (mainline Linux still
operates Sv48 in Sv39 mode). A future patch can improve this;
- Removed the additional comments, for consistency.

Differential Revision: https://reviews.llvm.org/D97646
2021-04-06 20:46:17 +01:00
James Y Knight 3b1b1d7530 Fix f6ee97d8271e1dfd9b6572222fefe8f40433952e:
PrintAddress needs to be false (as it was before), or this breaks sanitizer backtraces.
2021-04-06 14:10:26 -04:00
Julian Lettner a3e1b11123 [Sanitizer] Adopt Python 3 for iOS simulator test scripts
Differential Revision: https://reviews.llvm.org/D99911
2021-04-06 09:14:14 -07:00
Dan Liew fd28517d87 [CMake][Compiler-rt] Make it possible to configure standalone compiler-rt without `LLVMConfig.cmake`.
Previously it wasn't possible to configure a standalone compiler-rt
build if the `LLVMConfig.cmake` file isn't present in a shipped
toolchain.

This patch adds a fallback behaviour for when `LLVMConfig.cmake` is not
available in the toolchain being used for configure. The fallback
behaviour mocks out the bare minimum required to make a configure
succeed when the host is Darwin. Support for other platforms could
be added in future patches.

The new code path is taken either in one of the following cases:

* `llvm-config` is not available.
* `llvm-config` is available but it provides an invalid path for the CMake files.

The motivation here is to be able to generate the compiler-rt lit test
suites for an arbitrary LLVM toolchain and then run the tests against
it.

The invocation to do this looks something like.

```
CC=/path/to/cc \
CXX=/path/to/c++ \
cmake \
  -G Ninja \
  -DLLVM_CONFIG_PATH=/path/to/llvm-config \
  -DCOMPILER_RT_INCLUDE_TESTS=ON \
  /path/to/llvm-project/compiler-rt

 # Note we don't compile compiler-rt in this workflow.
bin/llvm-lit -v test/path/to/generated/test_suite
```

A possible alternative approach is to configure the
`cmake/modules/LLVMConfig.cmake.in` file in the LLVM source tree
and then include it. This approach was not taken because it is more
complicated.

An interesting side benefit of this patch is that it is now
possible to configure on Darwin without `llvm-config` being available
by configuring with `-DLLVM_CONFIG_PATH=""`. This moves us a step
closer to a world where no LLVM build artefacts are required to
build compiler-rt.

rdar://76016632

Differential Revision: https://reviews.llvm.org/D99621
2021-04-06 08:31:18 -07:00
Dan Liew fa818bb035 [CMake][Compiler-rt] Compute `LLVM_MAIN_SRC_DIR` assuming the monorepo
layout.

When doing a standalone compiler-rt build we currently rely on
getting information from the `llvm-config` binary. Previously
we would rely on calling `llvm-config --src-root` to find the
LLVM sources. Unfortunately the returned path could easily be wrong
if the sources were built on another machine.

Now that compiler-rt is part of a monorepo we can easily fix this
problem by finding the LLVM source tree next to `compiler-rt` in
the monorepo. We do this regardless of whether or not the `llvm-config`
binary is available which moves us one step closer to not requiring
`llvm-config` to be available.

To try avoid anyone breaking anyone who relies on the current behavior,
if the path assuming the monorepo layout doesn't exist we invoke
`llvm-config --src-root` to get the path. A deprecation warning is
emitted if this path is taken because we should remove this path
in the future given that other runtimes already assume the monorepo
layout.

We also now emit a warning if `LLVM_MAIN_SRC_DIR` does not exist.
The intention is that this should be a hard error in future but
to avoid breaking existing users we'll keep this as a warning
for now.

rdar://76016632

Differential Revision: https://reviews.llvm.org/D99620
2021-04-06 08:31:18 -07:00
Alexander Belyaev f6ee97d827 [rt] Update DIPrinter usage in 'sanitizer_symbolize.cpp`.
These changes were required after
5f57793c4f

Differential Revision: https://reviews.llvm.org/D99937
2021-04-06 12:31:47 +02:00
David Spickett 34f8a7f93c [lsan][test] Disable many_tls_keys_pthread.cpp on AArch64
Partially reverts 04dbb63400.

This test requires 9be8f8b34d
which is/has been reverted a few times but this test was
left enabled.

Currently that change is reverted and this test is failing:
http://lab.llvm.org:8011/#/builders/7/builds/2327
2021-04-06 11:28:02 +01:00
Nico Weber 0e92cbd6a6 Revert "[sanitizer] Simplify GetTls with dl_iterate_phdr on Linux"
This reverts commit ec575e3b0a.
Still doesn't work, see https://crbug.com/1196037
2021-04-05 19:00:18 -04:00
Fangrui Song ec575e3b0a [sanitizer] Simplify GetTls with dl_iterate_phdr on Linux
This was reverted by f176803ef1 due to
Ubuntu 16.04 x86-64 glibc 2.23 problems.
This commit additionally calls `__tls_get_addr({modid,0})` to work around the
dlpi_tls_data==NULL issues for glibc<2.25
(https://sourceware.org/bugzilla/show_bug.cgi?id=19826)

GetTls is the range of

* thread control block and optional TLS_PRE_TCB_SIZE
* static TLS blocks plus static TLS surplus

On glibc, lsan requires the range to include
`pthread::{specific_1stblock,specific}` so that allocations only referenced by
`pthread_setspecific` can be scanned.

This patch uses `dl_iterate_phdr` to collect TLS blocks. Find the one
with `dlpi_tls_modid==1` as one of the initially loaded module, then find
consecutive ranges. The boundaries give us addr and size.

This allows us to drop the glibc internal `_dl_get_tls_static_info` and
`InitTlsSize` entirely. Use the simplified method with non-Android Linux for
now, but in theory this can be used with *BSD and potentially other ELF OSes.

This simplification enables D99566 for TLS Variant I architectures.

See https://reviews.llvm.org/D93972#2480556 for analysis on GetTls usage
across various sanitizers.

Differential Revision: https://reviews.llvm.org/D98926
2021-04-04 15:35:53 -07:00
Vitaly Buka c4c5113372 [NFC][scudo] Restore !UseQuarantine check in tests
The check was removed in D99786 as it seems that quarantine is
irrelevant for the just created allocator. However there is internal
issues with tagged memory access.

We should be able to fix iterateOverChunks for taggin later.
2021-04-03 23:52:06 -07:00
Nico Weber f176803ef1 Revert "[sanitizer] Simplify GetTls with dl_iterate_phdr"
This reverts commit 9be8f8b34d.
This breaks tsan on Ubuntu 16.04:

    $ cat tiny_race.c
    #include <pthread.h>
    int Global;
    void *Thread1(void *x) {
      Global = 42;
      return x;
    }
    int main() {
      pthread_t t;
      pthread_create(&t, NULL, Thread1, NULL);
      Global = 43;
      pthread_join(t, NULL);
      return Global;
    }
    $ out/gn/bin/clang -fsanitize=thread -g -O1 tiny_race.c --sysroot ~/src/chrome/src/build/linux/debian_sid_amd64-sysroot/
    $ docker run -v $PWD:/foo ubuntu:xenial /foo/a.out
    FATAL: ThreadSanitizer CHECK failed: ../../compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp:447 "((thr_beg)) >= ((tls_addr))" (0x7fddd76beb80, 0xfffffffffffff980)
        #0 <null> <null> (a.out+0x4960b6)
        #1 <null> <null> (a.out+0x4b677f)
        #2 <null> <null> (a.out+0x49cf94)
        #3 <null> <null> (a.out+0x499bd2)
        #4 <null> <null> (a.out+0x42aaf1)
        #5 <null> <null> (libpthread.so.0+0x76b9)
        #6 <null> <null> (libc.so.6+0x1074dc)

(Get the sysroot from here: https://commondatastorage.googleapis.com/chrome-linux-sysroot/toolchain/500976182686961e34974ea7bdc0a21fca32be06/debian_sid_amd64_sysroot.tar.xz)

Also reverts follow-on commits:
This reverts commit 58c62fd976.
This reverts commit 31e541e375.
2021-04-02 18:19:17 -04:00
Vitaly Buka 46f2fdb840 [NFC][scudo] Move macro into a shared header 2021-04-02 14:38:02 -07:00
Vitaly Buka 4c58f333f1 [NFC][scudo] Add test header int CMake file 2021-04-02 14:38:02 -07:00
Vitaly Buka f02c6984d7 [NFC][scudo] Split ScudoCombinedTest.BasicCombined
Existing implementations took up to 30 minutues to execute on my setup.
Now it's more convenient to debug a single test.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D99786
2021-04-02 13:31:28 -07:00
Nico Weber 55978f914e [gn build] add build file for tsan runtime
Linux-only for now. Some mac bits stubbed out, but not tested.

Good enough for the tiny_race.c example at
https://clang.llvm.org/docs/ThreadSanitizer.html :

   $ out/gn/bin/clang -fsanitize=address -g -O1 tiny_race.c
   $ while true; do ./a.out || echo $? ; done

While here, also make `-fsanitize=address` work for .c files.

Differential Revision: https://reviews.llvm.org/D99795
2021-04-02 12:59:14 -04:00
Vitaly Buka bb1e5399e4 [NFC][scudo] Inline some functions into ScudoPrimaryTest 2021-04-02 01:04:51 -07:00
Vitaly Buka f343a73059 [NFC][scudo] Convert ScudoPrimaryTest into TYPED_TEST 2021-04-02 01:04:50 -07:00
Aaron Green 0889181625 Tweak SimpleFastHash
This change adds a SimpleFastHash64 variant of SimpleFastHash which allows call sites to specify a starting value and get a 64 bit hash in return. This allows a hash to be "resumed" with more data.

A later patch needs this to be able to hash a sequence of module-relative values one at a time, rather than just a region a memory.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D94510
2021-04-01 23:26:03 -07:00
Petr Hosek b0d286b03c [CMake] Use append instead of set with the list
This addresses an issue introduced by D99706.
2021-04-01 20:30:49 -07:00
Vitaly Buka 83dc218c77 [NFC][scudo] Move some shared stuff into ScudoCombinedTest 2021-04-01 20:20:03 -07:00
Vitaly Buka 88a1529e15 [NFC][scudo] Move globals into related test 2021-04-01 18:35:09 -07:00
Vitaly Buka 7af9b03c9d [NFC][scudo] Use TYPED_TEST to split large test 2021-04-01 17:34:13 -07:00
Daniel Rodríguez Troitiño 813e7249b8 [builtins] Build for arm64_32 for watchOS (Darwin)
Trying to build the builtins code fails because `arm64_32_SOURCES` is
missing. Setting it to the same list used for `aarch64_SOURCES` solves
that problem and allow the builtins to compile for that architecture.

Additionally, arm64_32 is added as a possible architecture for watchos
platforms.

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D99690
2021-04-01 17:16:18 -07:00
Vitaly Buka 622500479b [scudo][NFC] Make tests runs with --gtest_repeat=2
Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D99766
2021-04-01 13:37:42 -07:00
Vitaly Buka ce9e1a3632 [Scudo] Fix SizeClassAllocatorLocalCache::drain
It leaved few blocks in PerClassArray[0].

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D99763
2021-04-01 13:27:03 -07:00
Vitaly Buka 0f7e3a5546 [NFC][scudo] Simplify UseQuarantine initialization 2021-04-01 12:57:07 -07:00
Petr Hosek 775e55462a [CMake] Include dependency on cxx-headers in compiler-rt tests
The missing dependency was revealed by D97572.

Differential Revision: https://reviews.llvm.org/D99706
2021-04-01 10:42:06 -07:00
Jianzhou Zhao e4701471d6 [dfsan] Set sigemptyset's return label to be 0
This was not set from when the wrapper was introduced.

Reviewed By: gbalats

Differential Revision: https://reviews.llvm.org/D99678
2021-03-31 21:07:44 +00:00
Alex Richardson ce193ea9e8 [asan] Remove FreeBSD XFAIL from asan-sigbus.cpp test
This test passes for me on FreeBSD 12.2 and was probably fixed by
https://svnweb.freebsd.org/base?view=revision&revision=352807.

Reviewed By: emaste

Differential Revision: https://reviews.llvm.org/D98281
2021-03-31 09:17:48 +01:00
Luís Marques eb4967c8bd [Sanitizer][RISCV][AArch64][Android] Adjust allocator tests
On 64-bit systems with small VMAs (e.g. 39-bit) we can't use
SizeClassAllocator64 parameterized with size class maps containing a large
number of classes, as that will make the allocator region size too small
(< 2^32). Several tests were already disabled for Android because of this.

This patch provides the correct allocator configuration for RISC-V
(riscv64), generalizes the gating condition for tests that can't be enabled
for small VMA systems, and tweaks the tests that can be made compatible with
those systems to enable them.

I think the previous gating on Android should instead be AArch64+Android, so
the patch reflects that.

Differential Revision: https://reviews.llvm.org/D97234
2021-03-30 21:20:37 +01:00
Vitaly Buka 7c2e58f250 [NFC][scudo] Produce debug info 2021-03-30 00:22:00 -07:00
Fangrui Song 58c62fd976 [sanitizer] Improve accuracy of GetTls on x86/s390
The previous code may underestimate the static TLS surplus part, which may cause
false positives to LeakSanitizer if a dynamically loaded module uses the surplus
and there is an allocation only referenced by a thread's TLS.
2021-03-29 22:14:29 -07:00
Vitaly Buka 749e609ec9 [NFC][scudo] Sort sources in CMake file 2021-03-29 22:12:20 -07:00
Vitaly Buka 51fa9e0fd9 [NFC][scudo] Add memtag.h into CMake file 2021-03-29 22:12:20 -07:00
Fangrui Song 1daa48f005 [lsan] realloc: don't deallocate if requested size is too large
This is the behavior required by the standards.

Differential Revision: https://reviews.llvm.org/D99480
2021-03-29 13:35:10 -07:00
Fangrui Song 59e422c90b [lsan][test] Add malloc(0) and realloc(p, 0) tests 2021-03-29 11:41:07 -07:00
Jianzhou Zhao aaab444179 [dfsan] Ignore dfsan origin wrappers when instrumenting code 2021-03-29 00:15:26 +00:00
Fangrui Song d3e7ee36f6 [sanitizer] Define MAP_NORESERVE to 0 and hide mremap for FreeBSD 2021-03-27 12:18:58 -07:00
Fangrui Song 31e541e375 [sanitizer] Temporarily switch ppc64 to the _dl_get_tls_static_info implementation
sanitizer-ppc64le-linux is good while clang-ppc64le-linux has test
failures due to GetStaticTlsRange(addr, size) set *addr is 0.
2021-03-26 23:21:47 -07:00
Fangrui Song 04dbb63400 [lsan][test] Enable many_tls_keys_pthread.cpp and disable swapcontext.cpp/fork_and_leak.cpp
With D98926, many_tls_keys_pthread.cpp appears to be working.

On glibc 2.30-0ubuntu2, swapcontext.cpp and Linux/fork_and_leak.cpp work fine
but they strangely fail on clang-cmake-aarch64-full
(https://lab.llvm.org/buildbot/#/builders/7/builds/2240).
Disable them for now.

Note: check-lsan was recently enabled on AArch64 in D98985. A test takes
10+ seconds. We should figure out the bottleneck.
2021-03-26 11:26:08 -07:00
Fangrui Song dc46783f7f [memprof][test] Make test_terse.cpp robust (sched_getcpu may happens to change)
```
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/memprof/TestCases/test_terse.cpp:11:11: error: CHECK: expected string not found in input
// CHECK: MIB:[[STACKID:[0-9]+]]/1/40.00/40/40/20.00/20/20/[[AVELIFETIME:[0-9]+]].00/[[AVELIFETIME]]/[[AVELIFETIME]]/0/0/0/0
          ^
<stdin>:1:1: note: scanning from here
MIB:StackID/AllocCount/AveSize/MinSize/MaxSize/AveAccessCount/MinAccessCount/MaxAccessCount/AveLifetime/MinLifetime/MaxLifetime/NumMigratedCpu/NumLifetimeOverlaps/NumSameAllocCpu/NumSameDeallocCpu
^
<stdin>:4:1: note: possible intended match here
MIB:134217729/1/40.00/40/40/20.00/20/20/7.00/7/7/1/0/0/0
```
2021-03-26 00:45:58 -07:00
Fangrui Song 9be8f8b34d [sanitizer] Simplify GetTls with dl_iterate_phdr
GetTls is the range of

* thread control block and optional TLS_PRE_TCB_SIZE
* static TLS blocks plus static TLS surplus

On glibc, lsan requires the range to include
`pthread::{specific_1stblock,specific}` so that allocations only referenced by
`pthread_setspecific` can be scanned.

This patch uses `dl_iterate_phdr` to collect TLS ranges. Find the one
with `dlpi_tls_modid==1` as one of the initially loaded module, then find
consecutive ranges. The boundaries give us addr and size.

This allows us to drop the glibc internal `_dl_get_tls_static_info` and
`InitTlsSize` entirely. Use the simplified method with non-Android Linux for
now, but in theory this can be used with *BSD and potentially other ELF OSes.

In the future, we can move `ThreadDescriptorSize` code to lsan (and consider
intercepting `pthread_setspecific`) to avoid hacks in generic code.

See https://reviews.llvm.org/D93972#2480556 for analysis on GetTls usage
across various sanitizers.

Differential Revision: https://reviews.llvm.org/D98926
2021-03-25 21:55:27 -07:00
Matt Morehouse 96a4167b4c [HWASan] Use page aliasing on x86_64.
Userspace page aliasing allows us to use middle pointer bits for tags
without untagging them before syscalls or accesses.  This should enable
easier experimentation with HWASan on x86_64 platforms.

Currently stack, global, and secondary heap tagging are unsupported.
Only primary heap allocations get tagged.

Note that aliasing mode will not work properly in the presence of
fork(), since heap memory will be shared between the parent and child
processes.  This mode is non-ideal; we expect Intel LAM to enable full
HWASan support on x86_64 in the future.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98875
2021-03-25 07:04:14 -07:00
Jianzhou Zhao af9f461298 [dfsan] test flush on only x86 2021-03-25 02:45:43 +00:00
Jianzhou Zhao f9a135b652 [dfsan] Test dfsan_flush with origins
This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D99295
2021-03-25 00:12:53 +00:00
Matt Morehouse c8ef98e5de Revert "[HWASan] Use page aliasing on x86_64."
This reverts commit 63f73c3eb9 due to
breakage on aarch64 without TBI.
2021-03-24 16:18:29 -07:00
Julian Lettner 26e0fb88a3 [TSan] Support initialize/finalize hooks in dynamic libraries
Make TSan runtime initialization and finalization hooks work
even if these hooks are not built in the main executable.  When these
hooks are defined in another library that is not directly linked against
the TSan runtime (e.g., Swift runtime) we cannot rely on the "strong-def
overriding weak-def" mechanics and have to look them up via `dlsym()`.

Let's also define hooks that are easier to use from C-only code:
```
extern "C" void __tsan_on_initialize();
extern "C" int __tsan_on_finalize(int failed);
```
For now, these will call through to the old hooks.  Eventually, we want
to adopt the new hooks downstream and remove the old ones.

This is part of the effort to support Swift Tasks (async/await and
actors) in TSan.

rdar://74256720

Reviewed By: vitalybuka, delcypher

Differential Revision: https://reviews.llvm.org/D98810
2021-03-24 12:38:39 -07:00
Matt Morehouse 63f73c3eb9 [HWASan] Use page aliasing on x86_64.
Userspace page aliasing allows us to use middle pointer bits for tags
without untagging them before syscalls or accesses.  This should enable
easier experimentation with HWASan on x86_64 platforms.

Currently stack, global, and secondary heap tagging are unsupported.
Only primary heap allocations get tagged.

Note that aliasing mode will not work properly in the presence of
fork(), since heap memory will be shared between the parent and child
processes.  This mode is non-ideal; we expect Intel LAM to enable full
HWASan support on x86_64 in the future.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98875
2021-03-24 11:43:41 -07:00
Jianzhou Zhao 4950695eba [dfsan] Add Origin ABI Wrappers
Supported ctime_r, fgets, getcwd, get_current_dir_name, gethostname,
getrlimit, getrusage, strcpy, time, inet_pton, localtime_r,
getpwuid_r, epoll_wait, poll, select, sched_getaffinity

Most of them work as calling their non-origin verision directly.

This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98966
2021-03-24 18:22:03 +00:00
Jianzhou Zhao 91516925dd [dfsan] Add Origin ABI Wrappers
Supported strrchr, strrstr, strto*, recvmmsg, recrmsg, nanosleep,
    memchr, snprintf, socketpair, sprintf, getocketname, getsocketopt,
    gettimeofday, getpeername.

    strcpy was added because the test of sprintf need it. It will be
    committed by D98966. Please ignore it when reviewing.

    This is a part of https://reviews.llvm.org/D95835.

    Reviewed By: gbalats

    Differential Revision: https://reviews.llvm.org/D99109
2021-03-24 16:13:09 +00:00
Matt Morehouse 391b85bb03 [sanitizer] Fix Solaris build.
Use `#if SANITIZER_LINUX` instead of `#if defined(...)`.
2021-03-24 09:10:31 -07:00
Matt Morehouse 643d87ebab [sanitizer] Fix Solaris build.
mremap is only available on Linux.
2021-03-24 08:44:17 -07:00
Yvan Roux 608ee3593c [AArch64][ASAN] Re-enable fgets_fputs.cpp test.
Now that AArch64 mapping symbols are correctly handled by
llvm-symbolizer this test can be re-enabled on that target.
2021-03-24 10:06:04 +01:00
Vitaly Buka 54a40606e8 [NFC] Clang-format includes 2021-03-23 19:11:36 -07:00
Julian Lettner 39a8743603 [Sanitizer] Remove refactoring leftover [NFC] 2021-03-23 15:10:49 -07:00
Matt Morehouse 3e4faf08de [HWASan] Refactor in preparation for x86 aliasing mode. NFC
Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98373
2021-03-23 13:25:10 -07:00
Matt Morehouse f85002d22c [sanitizer] Implement MapDynamicShadowAndAliases.
The function works like MapDynamicShadow, except that it creates aliased
memory to the right of the shadow.  The main use case is for HWASan
aliasing mode, which gets fast IsAlias() checks by exploiting the fact
that the upper bits of the shadow base and aliased memory match.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98369
2021-03-23 11:52:18 -07:00
Peter Collingbourne e702fd4f1b scudo: Preserve no-memtag attribute on cached secondary allocations.
Differential Revision: https://reviews.llvm.org/D99103
2021-03-23 11:15:22 -07:00
Fangrui Song fdf97bc738 [test] Enable check-lsan on aarch64-*-linux
`check-lsan` passed on an aarch64-*-linux machine.

Unsupport `many_tls_keys_pthread.cpp` for now: it requires GetTls to include
`specific_1stblock` and `specific` in `struct pthread`.

Differential Revision: https://reviews.llvm.org/D98985
2021-03-23 11:11:26 -07:00
Matt Morehouse 642b80013c [sanitizer] Support dynamic premapped R/W range in primary allocator.
The main use case for this change is HWASan aliasing mode, which premaps
the alias space adjacent to the dynamic shadow.  With this change, the
primary allocator can allocate from the alias space instead of a
separate region.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98293
2021-03-23 10:00:14 -07:00
Vitaly Buka 091706269c [lsan][lsan] Use --std=c++14 to fix Windows test 2021-03-22 21:43:07 -07:00
Vitaly Buka 1e9c90921f Revert "[sanitizer] Support dynamic premapped R/W range in primary allocator."
Fails on Windows https://lab.llvm.org/buildbot/#/builders/127/builds/7999
and Android https://lab.llvm.org/buildbot/#/builders/77/builds/4839

This reverts commit bca0cf768b.
2021-03-22 18:52:56 -07:00
Matt Morehouse bca0cf768b [sanitizer] Support dynamic premapped R/W range in primary allocator.
The main use case for this change is HWASan aliasing mode, which premaps
the alias space adjacent to the dynamic shadow.  With this change, the
primary allocator can allocate from the alias space instead of a
separate region.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98293
2021-03-22 14:44:52 -07:00
Matt Morehouse fe5f66d925 [HWASan][NFC] Introduce constants for tag bits and masks.
x86_64 aliasing mode will use fewer than 8 bits for tags, so refactor
existing code to remove hard-coded 0xff and 8 values.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98072
2021-03-22 12:32:29 -07:00
Matt Morehouse c21f72e65a [HWASan] Fix brittle stack-oob.c test. 2021-03-22 11:08:22 -07:00
Matt Morehouse 772851ca4e [HWASan] Disable stack, globals and force callbacks for x86_64.
Subsequent patches will implement page-aliasing mode for x86_64, which
will initially only work for the primary heap allocator.  We force
callback instrumentation to simplify the initial aliasing
implementation.

Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D98069
2021-03-22 08:02:27 -07:00
Emily Shi 6ca178cd78 [asan] specify c++ version in tests to fix compile error
If we don't specify the c++ version in these tests, it could cause compile errors because the compiler could default to an older c++

rdar://75247244

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D98913
2021-03-19 10:08:18 -07:00
Jianzhou Zhao 1fe042041c [dfsan] Add origin ABI wrappers
supported: dl_get_tls_static_info, calloc, clock_gettime,
dfsan_set_write_callback, dl_iterato_phdr, dlopen, memcpy,
memmove, memset, pread, read, strcat, strdup, strncpy

This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98790
2021-03-19 16:23:25 +00:00
Daniel Kiss 4220531cef [AArch64][compiler-rt] Strip PAC from the link register.
-mbranch-protection protects the LR on the stack with PAC.
When the frames are walked the LR need to be cleared.
This inline assembly later will be replaced with a new builtin.

Test: build with  -DCMAKE_C_FLAGS="-mbranch-protection=standard".

Reviewed By: kubamracek

Differential Revision: https://reviews.llvm.org/D98008
2021-03-18 22:01:50 +01:00
Daniel Kiss c1940aac99 Revert "[AArch64][compiler-rt] Strip PAC from the link register."
This reverts commit ad40453fc4.
2021-03-18 22:01:50 +01:00
Jorg Brown 858ca7c174
Fix typo: `char` should be `TS` 2021-03-18 11:00:07 -07:00
Martin Storsjö 8e11bede3a [compiler-rt] Produce the right arch suffix for arm libraries
If producing libraries with an arch suffix (i.e. if
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR isn't set), we append the
architecture name. However, for arm, clang doesn't look for libraries
with the full architecture name, but only looks for "arm" and "armhf".

Try to deduce what the full target triple might have been, and use
that for deciding between "arm" and "armhf".

This tries to reapply this bit from D98173, that had to be reverted
in 7b153b43d3 due to affecting how
the builtins themselves are compiled, not only affecting the output
file name.

Differential Revision: https://reviews.llvm.org/D98452
2021-03-18 14:58:58 +02:00
Vitaly Buka 674d276d1b [sanitizer] Grow buffer in SharedPrintfCodeNoBuffer 2021-03-17 20:17:35 -07:00
Vitaly Buka 872ec3802c [NFC][sanitizer] Remove unneeded "explicit" 2021-03-17 19:41:15 -07:00
Vitaly Buka e0dadf3de2 [sanitizer] Remove max_len parameter from InternalScopedString
InternalScopedString uses InternalMmapVector internally
so it can be resized dynamically as needed.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D98751
2021-03-17 16:57:09 -07:00
Jon Roelofs a14263e8f8 [compiler-rt] -fsanitize=cfi is not supported on Darwin
This was responsible for:

Failed Tests (2):
  cfi-devirt-x86_64 :: mfcall.cpp
  cfi-standalone-x86_64 :: mfcall.cpp
2021-03-17 13:28:42 -07:00
Luís Marques 6b025da443 [Sanitizer] Fix debug builds of sanitizer_stacktrace_test.cpp
An implementation of `__sanitizer::BufferedStackTrace::UnwindImpl` is
provided per sanitizer, but there isn't one for sanitizer-common. In
non-optimized builds of the sanitizer-common tests that becomes a problem:
the test `sanitizer_stacktrace_test.cpp` won't have a reference to that
method optimized away, causing linking errors. This patch provides a dummy
implementation, which fixes those builds.

Differential Revision: https://reviews.llvm.org/D96956
2021-03-17 15:57:54 +00:00
Rainer Orth 3b8b5d1f22 [sanitizer_common][test] Handle missing REG_STARTEND in Posix/regex_startend.cpp
As reported in D96348 <https://reviews.llvm.org/D96348>, the
`Posix/regex_startend.cpp` test `FAIL`s on Solaris because
`REG_STARTEND` isn't defined.  It's a BSD extension not present everywhere.
E.g. AIX doesn't have it, too.

Fixed by wrapping the test in `#ifdef REG_STARTEND`.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D98425
2021-03-17 09:56:19 +01:00
Jianzhou Zhao ec5ed66cee [dfsan] Add origin ABI wrappers
supported: bcmp, fstat, memcmp, stat, strcasecmp, strchr, strcmp,
strncasecmp, strncp, strpbrk

This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98636
2021-03-17 02:22:35 +00:00
Emily Shi c2f3b2f90e [asan] disable MallocNanoZone for no fd test on darwin
On Darwin, MallocNanoZone may log after execv, which messes up this test.
Disable MallocNanoZone for this test since we don't use it anyway with asan.

This environment variable should only affect Darwin and not change behavior on other platforms.

rdar://74992832

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D98735
2021-03-16 15:17:50 -07:00
Vitaly Buka 9adc907363 [sanitizer][NFC] Fix compilation error on Windows
And remove unnecessary const_cast in ubsan.
2021-03-16 15:04:30 -07:00
Vitaly Buka f5e6182ce6 [sanitizer][NFC] Remove InternalScopedString::size()
size() is inconsistent with length().
In most size() use cases we can replace InternalScopedString with
InternalMmapVector.

Remove non-constant data() to avoid direct manipulations of internal
buffer. append() should be enought to modify InternalScopedString.
2021-03-16 14:11:59 -07:00
Martin Storsjö cfb978d85f [compiler-rt] Use try_compile_only to check for __ARM_FP
This fixes detection when linking isn't supported (i.e. while building
builtins the first time).

Since 8368e4d54c, after setting
CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY, this isn't strictly
needed, but is good for correctness anyway (and in case that commit
ends up reverted).

Differential Revision: https://reviews.llvm.org/D98737
2021-03-16 22:21:18 +02:00
Martin Storsjö 1bc8f5fbb4 [sanitizers] [windows] Use InternalMmapVector instead of silencing -Wframe-larger-than
Also use this in ReadBinaryName which currently is producing
warnings.

Keep pragmas for silencing warnings in sanitizer_unwind_win.cpp,
as that can be called more frequently.

Differential Revision: https://reviews.llvm.org/D97726
2021-03-16 22:17:25 +02:00
Peter Collingbourne db36d882ed scudo: Allow TBI to be disabled on Linux with a macro.
Android's native bridge (i.e. AArch64 emulator) doesn't support TBI so
we need a way to disable TBI on Linux when targeting the native bridge.

This can also be used to test the no-TBI code path on Linux (currently
only used on Fuchsia), or make Scudo compatible with very old
(pre-commit d50240a5f6ceaf690a77b0fccb17be51cfa151c2 from June 2013)
Linux kernels that do not enable TBI.

Differential Revision: https://reviews.llvm.org/D98732
2021-03-16 12:56:19 -07:00
Vitaly Buka 1310c686c2 [sanitizer][NFC] Don't inherit InternalMmapVector 2021-03-16 03:57:46 -07:00
Yvan Roux c0f224e630 [AArch64][ASAN] Disable fgets_fputs.cpp test.
This test is failing for long a time on AArch64 bots, disable it for now
to keep the bots green while investigating it.
2021-03-16 07:00:19 +01:00
Jianzhou Zhao 9cf5220c5c [dfsan] Updated check_custom_wrappers.sh to dedup function names
The origin wrappers added by https://reviews.llvm.org/D98359 reuse
those __dfsw_ functions.
2021-03-15 19:12:08 +00:00
Jianzhou Zhao 57a532b3ac [dfsan] Do not check dfsan_get_origin by check_custom_wrappers.sh
It is implemented like dfsan_get_label, and does not any code
in dfsan_custome.cpp.
2021-03-15 18:55:34 +00:00
Jianzhou Zhao 4e67ae7b6b [dfsan] Add origin ABI wrappers for thread/signal/fork
This is a part of https://reviews.llvm.org/D95835.

See bb91e02efd about the similar issue of fork in MSan's origin tracking.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98359
2021-03-15 16:18:00 +00:00
Edward Jones b136a74efc [RISCV][compiler-rt] Add support for save-restore
This adds the compiler-rt entry points required by the
-msave-restore option.

Differential Revision: https://reviews.llvm.org/D91717
2021-03-15 15:51:47 +00:00
Kostya Kortchinsky 752f477d67 [scudo][standalone] Add shared library to makefile
Since we are looking to remove the old Scudo, we have to have a .so for
parity purposes as some platforms use it.

I tested this on Fuchsia & Linux, not on Android though.

Differential Revision: https://reviews.llvm.org/D98456
2021-03-15 08:12:37 -07:00
Vy Nguyen 6f37d18d8c [asan] Fixed test failing on windows due to different printf behaviour.
%p reported prints upper case hex chars on Windows.
The fix  is to switch to using %#lx

Differential Revision: https://reviews.llvm.org/D98570
2021-03-15 10:58:40 -04:00
Luís Marques a149812d0e Revert "[Sanitizer][RISCV][AArch64][Android] Adjust allocator tests"
This reverts commit a00347b56e due to a
test failure on the `sanitizer-x86_64-linux-android` buildbot.
2021-03-15 13:01:26 +00:00
Luís Marques a00347b56e [Sanitizer][RISCV][AArch64][Android] Adjust allocator tests
On 64-bit systems with small VMAs (e.g. 39-bit) we can't use
`SizeClassAllocator64` parameterized with size class maps containing a
large number of classes, as that will make the allocator region size too
small (< 2^32). Several tests were already disabled for Android because
of this.

This patch provides the correct allocator configuration for RISC-V
(riscv64), generalizes the gating condition for tests that can't be
enabled for small VMA systems, and tweaks the tests that can be made
compatible with those systems to enable them.

Differential Revision: https://reviews.llvm.org/D97234
2021-03-15 11:02:42 +00:00
Daniel Kiss ad40453fc4 [AArch64][compiler-rt] Strip PAC from the link register.
-mbranch-protection protects the LR on the stack with PAC.
When the frames are walked the LR need to be cleared.
This inline assembly later will be replaced with a new builtin.

Test: build with  -DCMAKE_C_FLAGS="-mbranch-protection=standard".

Reviewed By: kubamracek

Differential Revision: https://reviews.llvm.org/D98008
2021-03-15 10:25:59 +01:00
Martin Storsjö d374667257 [compiler-rt] Use arm-specific builtins sources for arm/mingw builds
Previously, that configuration only used the generic sources, in
addition to the couple specifically chosen arm/mingw files.

Differential Revision: https://reviews.llvm.org/D98547
2021-03-13 22:22:01 +02:00
Fangrui Song b978a93635 [gcov] Delete ancient MSVC workaround 2021-03-12 15:10:12 -08:00
Fangrui Song 10b1d30ec0 [gcov] Delete FreeBSD<10 (reached end of life for years) workaround 2021-03-12 15:07:58 -08:00
Matt Morehouse 4b82f61474 [libFuzzer] Use macro instead of __attribute__.
This should fix the Windows buildbot errors.
2021-03-12 14:36:57 -08:00
Vy Nguyen ab08c3865b Revert "Revert "[compiler-rt][asan] Make wild-pointer crash error more useful""
This reverts commit c578508b5b.

Reland now that unrelated crash has been resolved.
2021-03-12 11:35:50 -05:00
Alex Richardson e2cd2f7d08 [builtins] Fix value of ARM_INEXACT
The existing value of 0x1000 sets the IXE bit (Inexact floating-point exception
trap enable), but we really want to be setting IXC, bit 4:
Inexact cumulative floating-point exception bit. This bit is set to 1 to
indicate that the Inexact floating-point exception has occurred since 0 was
last written to this bit.

Reviewed By: kongyi, peter.smith
Differential Revision: https://reviews.llvm.org/D98353
2021-03-12 11:15:24 +00:00
Vy Nguyen c578508b5b Revert "[compiler-rt][asan] Make wild-pointer crash error more useful"
This reverts commit f65e1aee40.
2021-03-11 22:13:40 -05:00
Jonas Paulsson 5908c7ca41 [libFuzzer] Add attribute noinline on Fuzzer::ExecuteCallback().
The inlining of this function needs to be disabled as it is part of the
inpsected stack traces. It's string representation will look different
depending on if it was inlined or not which will cause it's string comparison
to fail.

When it was inlined in only one of the two execution stacks,
minimize_two_crashes.test failed on SystemZ. For details see
https://bugs.llvm.org/show_bug.cgi?id=49152.

Reviewers: Ulrich Weigand, Matt Morehouse, Arthur Eubanks

Differential Revision: https://reviews.llvm.org/D97975
2021-03-11 21:05:22 -06:00
Vy Nguyen f65e1aee40 [compiler-rt][asan] Make wild-pointer crash error more useful
Right now, when you have an invalid memory address, asan would just crash and does not offer much useful info.
This patch attempted to give a bit more detail on the access.

Differential Revision: https://reviews.llvm.org/D98280
2021-03-11 21:48:39 -05:00
Andrzej Hunt 3d039f6501 [compiler-rt] PR#39514 Support versioned llvm-symbolizer binaries
Some linux distributions produce versioned llvm-symbolizer binaries,
e.g. my llvm-11 installation puts the symbolizer binary at
/usr/bin/llvm-symbolizer-11.0.0 . However if you then try to run
a binary containing ASAN with
ASAN_SYMBOLIZER_PATH=..../llvm-symbolizer-FOO , it will fail on startup
with "isn't a known symbolizer".

Although it is possible to work around this by setting up symlinks,
that's kindof ugly - supporting versioned binaries is a nicer solution.
(There are now multiple stack overflow and blog posts talking about
 this exact issue :) .)

Originally added in:
https://reviews.llvm.org/D8285

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D97682
2021-03-11 18:29:06 -08:00
Emily Shi 03afd5cea4 [asan] disable no-fd test on darwin
If a log message is triggered between execv and child, this test fails.
In the meantime, disable the test to unblock CI

rdar://74992832

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D98453
2021-03-11 16:49:18 -08:00
Aaron Green 6708186c91 [crt][fuzzer] Fix up various numeric conversions
Attempting to build a standalone libFuzzer in Fuchsia's default toolchain for the purpose of cross-compiling the unit tests  revealed a number of not-quite-proper type conversions. Fuchsia's toolchain include `-std=c++17` and `-Werror`, among others, leading to many errors like `-Wshorten-64-to-32`, `-Wimplicit-float-conversion`, etc.

Most of these have been addressed by simply making the conversion explicit with a `static_cast`. These typically fell into one of two categories: 1) conversions between types where high precision isn't critical, e.g. the "energy" calculations for `InputInfo`, and 2) conversions where the values will never reach the bits being truncated, e.g. `DftTimeInSeconds` is not going to exceed 136 years.

The major exception to this is the number of features: there are several places that treat features as `size_t`, and others as `uint32_t`. This change makes the decision to cap the features at 32 bits. The maximum value of a feature as produced by `TracePC::CollectFeatures` is roughly:
  (NumPCsInPCTables + ValueBitMap::kMapSizeInBits + ExtraCountersBegin() - ExtraCountersEnd() + log2(SIZE_MAX)) * 8

It's conceivable for extremely large targets and/or extra counters that this limit could be reached. This shouldn't break fuzzing, but it will cause certain features to collide and lower the fuzzers overall precision. To address this, this change adds a warning to TracePC::PrintModuleInfo about excessive feature size if it is detected, and recommends refactoring the fuzzer into several smaller ones.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D97992
2021-03-11 16:01:28 -08:00
Jianzhou Zhao 37520a0b2b [dfsan] Disable testing origin tracking on non x86_64 arch
Fix test cases related to https://reviews.llvm.org/D95835.
2021-03-11 21:22:43 +00:00
Martin Storsjö 7b153b43d3 [compiler-rt] Partially revert 8bd2722f65
Don't normalize arm architecture names; doing that loses the ability
to pick the right implementation of builtins for each architecture
variant. When building compiler-rt builtins as part of a
runtimes build, builtins for multiple armv* variants could be built
in the same directory, and with the simplified architecture name,
they'd all be built in the same directory, overlapping each other.
2021-03-11 22:41:10 +02:00
Hiroshi Yamauchi 365b225d46 [PGO] Fix two issues in PGOMemOPSizeOpt.
1. PGOMemOPSizeOpt grabs only the first, up to five (by default) entries from
the value profile metadata and preserves the remaining entries for the fallback
memop call site. If there are more than five entries, the rest of the entries
would get dropped. This is fine for PGOMemOPSizeOpt itself as it only promotes
up to 3 (by default) values, but potentially not for other downstream passes
that may use the value profile metadata.

2. PGOMemOPSizeOpt originally assumed that only values 0 through 8 are kept
track of. When the range buckets were introduced, it was changed to skip the
range buckets, but since it does not grab all entries (only five), if some range
buckets exist in the first five entries, it could potentially cause fewer
promotion opportunities (eg. if 4 out of 5 were range buckets, it may be able to
promote up to one non-range bucket, as opposed to 3.) Also, combined with 1, it
means that wrong entries may be preserved, as it didn't correctly keep track of
which were entries were skipped.

To fix this, PGOMemOPSizeOpt now grabs all the entries (up to the maximum number
of value profile buckets), keeps track of which entries were skipped, and
preserves all the remaining entries.

Differential Revision: https://reviews.llvm.org/D97592
2021-03-11 09:53:05 -08:00
Martin Storsjö 8368e4d54c [compiler-rt] Set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY when building builtins standalone
When building builtins, the toolchain might not yet be at a stage
when linking a test application works yet, as builtins aren't
available. Therefore set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY,
to avoid failing the compiler sanity check.

Setting CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY has the risk
of making checks for library availability succeed falsely (e.g.
indicating that libs would be available that really aren't, as the
tests don't do any linking), but the builtins library doesn't try to
link against any external libraries (and only produces static libraries
anyway), so it should be safe here.

This avoids having to set CMAKE_C_COMPILER_WORKS when bootstrapping a
cross toolchain, when building the builtins.

Differential Revision: https://reviews.llvm.org/D91334
2021-03-11 15:21:48 +02:00
Oliver Stannard 0070c9ee2d [AArch64][compiler-rt] Fix PAC instructions for older compilers
The paciasp and autiasp instructions are only accepted by recent
compilers, but have the same encoding as hint instructions, so we can
use the hint menmonic to support older compilers.
2021-03-11 09:21:05 +00:00
Fangrui Song aeaf705d5e [sanitizer] Change NanoTime to use clock_gettime on non-glibc
This avoids the `__NR_gettimeofday` syscall number, which does not exist on 32-bit musl (it has `__NR_gettimeofday_time32`).

This switched Android to `clock_gettime` as well, which should work according to the old code before D96925.

Tested on Alpine Linux x86-64 (musl) and FreeBSD x86-64.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D98121
2021-03-10 23:02:51 -08:00
Fangrui Song 5af991d464 [tsan] Fix aarch64-*-linux after D86377
All check-tsan tests fail on aarch64-*-linux because HeapMemEnd() > ShadowBeg()
for the following code path:
```
 #if defined(__aarch64__) && !HAS_48_BIT_ADDRESS_SPACE
   ProtectRange(HeapMemEnd(), ShadowBeg());
```

Restore the behavior before D86377 for aarch64-*-linux.
2021-03-10 22:16:04 -08:00
Jianzhou Zhao 6a9a686ce7 [dfsan] Tracking origins at phi nodes
This is a part of https://reviews.llvm.org/D95835.

Reviewed-by: morehouse

Differential Revision: https://reviews.llvm.org/D98268
2021-03-10 17:02:58 +00:00
Daniel Kiss 201550852b [AArch64][compiler-rt] Add Pointer Authentication support for VFORK.
The LR is stored to off-stack spill area where it is vulnerable.
"paciasp" add an auth code to the LR while the "autiasp" verifies that so
LR can't be modiifed on the spill area.

Test: build with -DCMAKE_C_FLAGS="-mbranch-protection=standard",
run on Armv8.3 capable hardware with PAuth.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D98009
2021-03-10 16:39:39 +01:00
Alex Richardson cbcab14b19 [compiler-rt] Silence a deprecation warning on FreeBSD
On FreeBSD the sys/timeb.h header has a #warning that it's deprecated.
However, we need to include this header here, so silence this warning that
is printed multiple times otherwise.

Reviewed By: dim

Differential Revision: https://reviews.llvm.org/D94963
2021-03-10 11:17:33 +00:00
Alex Richardson 6840fc4e7f [asan][tests] Handle FreeBSD in large_func_test and use-after-delete
This is the same fix as ab8a460241 for
Solaris and 23cd8d51ad (Windows+Darwin).
2021-03-10 11:17:33 +00:00
Alex Richardson 5853e1ca7f [sanitizers] Fix typo in ca9815fc24
I accidentally committed the wrong version of this patch which didn't
actually enable the hooks for FreeBSD. Fixing the typo allows the tests
to actually pass.
2021-03-10 11:17:33 +00:00
Martin Storsjö 8bd2722f65 [compiler-rt] Normalize i?86 to i386 and armv* to arm for COMPILER_RT_DEFAULT_TARGET_ARCH
This corresponds to getArchNameForCompilerRTLib in clang; any
32 bit x86 architecture triple (except on android, but those
exceptions are already handled in compiler-rt on a different level)
get the compiler rt library names with i386; arm targets get either
"arm" or "armhf". (Mapping to "armhf" is handled in the toplevel
CMakeLists.txt.)

Differential Revision: https://reviews.llvm.org/D98173
2021-03-10 08:43:54 +02:00
Jianzhou Zhao 8506fe5b41 [dfsan] Tracking origins at memory transfer
This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D98192
2021-03-09 22:15:07 +00:00
Fangrui Song 27ddcd51d3 [profile] Fix InstrProfGetRangeRepValue to use UINT64_C
This is a minor issue because the TargetValue parameter of `__llvm_profile_instrument_memop`
is usually small and cannot exceed 2**31 at all.

Differential Revision: https://reviews.llvm.org/D97640
2021-03-09 12:46:13 -08:00
Peter Collingbourne 1f55fa0b99 scudo: Add support for tracking stack traces of secondary allocations.
There is no centralized store of information related to secondary
allocations. Moreover the allocations themselves become inaccessible
when the allocation is freed in order to implement UAF detection,
so we can't store information there to be used in case of UAF
anyway.

Therefore our storage location for tracking stack traces of secondary
allocations is a ring buffer. The ring buffer is copied to the process
creating the crash dump when a fault occurs.

The ring buffer is also used to store stack traces for primary
deallocations. Stack traces for primary allocations continue to be
stored inline.

In order to support the scenario where an access to the ring buffer
is interrupted by a concurrently occurring crash, the ring buffer is
accessed in a lock-free manner.

Differential Revision: https://reviews.llvm.org/D94212
2021-03-09 11:43:03 -08:00
MarcoFalke 0cccccf0d2
[compiler-rt] FuzzedDataProvider: Add missing include
Differential Revision: https://reviews.llvm.org/D98057
2021-03-09 12:26:34 +01:00
Dmitry Vyukov 373e1681c9 [sanitizers] Enable runtime vma for mips64 in buildgo.sh
Go requires 47 bits VA for tsan.
Go will run race_detector testcases unless tsan warns about "unsupported VMA range"

Author: mzh (Meng Zhuo)
Reviewed-in: https://reviews.llvm.org/D98238
2021-03-09 11:45:55 +01:00
Dmitry Vyukov 85801b4c68 [sanitizers] fix wrong enum of memory_order for mips
Author: mzh (Meng Zhuo)
Reviewed-in: https://reviews.llvm.org/D98231
2021-03-09 11:28:45 +01:00
Peter Collingbourne 3f71ce8589 scudo: Support memory tagging in the secondary allocator.
This patch enhances the secondary allocator to be able to detect buffer
overflow, and (on hardware supporting memory tagging) use-after-free
and buffer underflow.

Use-after-free detection is implemented by setting memory page
protection to PROT_NONE on free. Because this must be done immediately
rather than after the memory has been quarantined, we no longer use the
combined allocator quarantine for secondary allocations. Instead, a
quarantine has been added to the secondary allocator cache.

Buffer overflow detection is implemented by aligning the allocation
to the right of the writable pages, so that any overflows will
spill into the guard page to the right of the allocation, which
will have PROT_NONE page protection. Because this would require the
secondary allocator to produce a header at the correct position,
the responsibility for ensuring chunk alignment has been moved to
the secondary allocator.

Buffer underflow detection has been implemented on hardware supporting
memory tagging by tagging the memory region between the start of the
mapping and the start of the allocation with a non-zero tag. Due to
the cost of pre-tagging secondary allocations and the memory bandwidth
cost of tagged accesses, the allocation itself uses a tag of 0 and
only the first four pages have memory tagging enabled.

This is a reland of commit 7a0da88943 which was reverted in commit
9678b07e42. This reland includes the following changes:

- Fix the calculation of BlockSize which led to incorrect statistics
  returned by mallinfo().
- Add -Wno-pedantic to silence GCC warning.
- Optionally add some slack at the end of secondary allocations to help
  work around buggy applications that read off the end of their
  allocation.

Differential Revision: https://reviews.llvm.org/D93731
2021-03-08 14:39:33 -08:00
Luís Marques c5a6ad86b0 [Sanitizer][RISCV] Fix internal_clone
A RISC-V implementation of `internal_clone` was introduced in D87573, as
part of the RISC-V ASan patch set by @EccoTheDolphin. That function was
never used/tested until I ported LSan for RISC-V, as part of D92403. That
port revealed problems in the original implementation, so I provided a fix
in D92403. Unfortunately, my choice of replacing the assembly with regular
C++ code wasn't correct. The clone syscall arguments specify a separate
stack, so non-inlined calls, spills, etc. aren't going to work. This wasn't
a problem in practice for optimized builds of Compiler-RT, but it breaks
for debug builds. This patch fixes the original problem while keeping the
assembly.

Differential Revision: https://reviews.llvm.org/D96954
2021-03-08 22:29:59 +00:00
Kuba Mracek 8a8fa09cb7 [tsan] Use large address space mapping on Apple Silicon Macs
Differential Revision: https://reviews.llvm.org/D86377
2021-03-08 14:09:42 -08:00
Alex Richardson ad294e572b [sanitizers] Fix interception of GLibc regexec
Previously, on GLibc systems, the interceptor was calling __compat_regexec
(regexec@GLIBC_2.2.5) insead of the newer __regexec (regexec@GLIBC_2.3.4).
The __compat_regexec strips the REG_STARTEND flag but does not report an
error if other flags are present. This can result in infinite loops for
programs that use REG_STARTEND to find all matches inside a buffer (since
ignoring REG_STARTEND means that the search always starts from the first
character).

The underlying issue is that GLibc's dlsym(RTLD_NEXT, ...) appears to
always return the oldest versioned symbol instead of the default. This
means it does not match the behaviour of dlsym(RTLD_DEFAULT, ...) or the
behaviour documented in the manpage.

It appears a similar issue was encountered with realpath and worked around
in 77ef78a0a5.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=14932 and
https://sourceware.org/bugzilla/show_bug.cgi?id=1319.

Fixes https://github.com/google/sanitizers/issues/1371

Reviewed By: #sanitizers, vitalybuka, marxin

Differential Revision: https://reviews.llvm.org/D96348
2021-03-08 10:53:55 +00:00
Jeremy Morse 66e3a4abe9 Revert "[tsan] Use large address space mapping on Apple Silicon Macs"
This reverts commit bde2e56071.

This patch produces a compile failure on linux amd64 environments, when
running:

  ninja GotsanRuntimeCheck

I get various build errors:

  ../rtl/tsan_platform.h:608: error: use of undeclared identifier 'Mapping'
    return MappingImpl<Mapping, Type>();

Here's a buildbot with the same failure during stage "check-tsan in gcc
build", there are other unrelated failures in there.

  http://lab.llvm.org:8011/#/builders/37/builds/2831
2021-03-08 09:51:51 +00:00
Raul Tambre ba860963b1 [CMake][compiler-rt] Use copying instead of symlinking for LSE builtins on non-Unix-likes
As reported in D93278 post-review symlinking requires privilege escalation on Windows.
Copying is functionally same, so fallback to it for systems that aren't Unix-like.
This is similar to the solution in AddLLVM.cmake.

Reviewed By: ikudrin

Differential Revision: https://reviews.llvm.org/D98111
2021-03-08 09:10:36 +02:00
Kuba Mracek bde2e56071 [tsan] Use large address space mapping on Apple Silicon Macs
Differential Revision: https://reviews.llvm.org/D86377
2021-03-07 12:47:08 -08:00
Elia Geretto b46c89892f [XRay][compiler-rt][x86_64] Fix CFI directives in assembly trampolines
This patch modifies the x86_64 XRay trampolines to fix the CFI information
generated by the assembler. One of the main issues in correcting the CFI
directives is the `ALIGNED_CALL_RAX` macro, which makes the CFA dependent on
the alignment of the stack. However, this macro is not really necessary because
some additional assumptions can be made on the alignment of the stack when the
trampolines are called. The code has been written as if the stack is guaranteed
to be 8-bytes aligned; however, it is instead guaranteed to be misaligned by 8
bytes with respect to a 16-bytes alignment. For this reason, always moving the
stack pointer by 8 bytes is sufficient to restore the appropriate alignment.

Trampolines that are called from within a function as a result of the builtins
`__xray_typedevent` and `__xray_customevent` are necessarely called with the
stack properly aligned so, in this case too, `ALIGNED_CALL_RAX` can be
eliminated.

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

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D96785
2021-03-06 10:38:27 -08:00
Fangrui Song ca747e48af [sanitizer] Restrict clock_gettime workaround to glibc
The hackery is due to glibc clock_gettime crashing from preinit_array (D40679).
32-bit musl architectures do not define `__NR_clock_gettime` so the code causes a compile error.

Tested on Alpine Linux x86-64 (musl) and FreeBSD x86-64.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D96925
2021-03-06 10:32:27 -08:00
Vitaly Buka 56ed64dfa9 [sanitizer] Don't expect ABORTING in print-module-map
ABORTING message is inconsistent across sanitizers.

Another followup for D98089
2021-03-05 19:22:34 -08:00
Jianzhou Zhao 469d5462fa [dfsan] Re-enable origin tracking test cases 2021-03-06 02:41:56 +00:00
Vitaly Buka 2fcd872d8a [dfsan] Remove dfsan_get_origin from done_abilist.txt
Followup for D95835
2021-03-05 17:59:39 -08:00
Vitaly Buka 1c5f083128 [NFC] Fix module map test
Followup for D98089
2021-03-05 17:23:19 -08:00
Jianzhou Zhao d02e0ba070 [dfsan] Disable origin test cases temporarily 2021-03-06 01:12:54 +00:00
Emily Shi c0503df15d [sanitizers] fix print-module-map test on linux
Looks like the default options for halt_on_error are different between linux and mac. set it to 0 in the test so the behavior is the same on both platforms.

rdar://75110847

Reviewed By: delcypher

Differential Revision: https://reviews.llvm.org/D98089
2021-03-05 16:41:37 -08:00
Rainer Orth ab8a460241 [asan][test] Handle Solaris in large_func_test.cpp etc.
Two ASan tests currently `FAIL' on Solaris

  AddressSanitizer-i386-sunos :: TestCases/large_func_test.cpp
  AddressSanitizer-i386-sunos :: TestCases/use-after-delete.cpp

both for the same reason:

  error: no check strings found with prefix 'CHECK-SunOS:'

Fixed by adding the appropriate check strings.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D97931
2021-03-06 01:28:17 +01:00
Jianzhou Zhao c20db7ea6a [dfsan] Add utils to get and print origin paths and some test cases
This is a part of https://reviews.llvm.org/D95835.

Reviewed By: morehouse, gbalats

Differential Revision: https://reviews.llvm.org/D97962
2021-03-06 00:11:35 +00:00
Emily Shi 51d8f598ad [sanitizers] run print module map test run on posix
Previously, this test only ran for mac because platforms have different messaging. This diff enables the test for all posix

rdar://75110847

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D98079
2021-03-05 15:41:14 -08:00
Petr Hosek b654b22197 Partially revert "[runtimes] Use add_lit_testsuite to register lit testsuites"
This partially reverts commit e1173c8794
until we find out why compiler-rt tests are failing under runtimes build.
2021-03-05 15:24:38 -08:00
Emily Shi 9059903f2d [ubsan] support print_module_map flag in standalone mode
Currently, `print_module_map` is only respected for ubsan if it is ran in tandem with asan. This patch adds support for this flag in standalone mode. I copied the pattern used to implement this for asan.

Also added a common `print_module_map` lit test for Darwin only. Since the print messages are different per platform, we need to write a regex test to cover them. This test is coming in a separate patch

rdar://56135732

Reviewed By: vitalybuka, vsk, delcypher

Differential Revision: https://reviews.llvm.org/D97746
2021-03-05 13:59:56 -08:00
Petr Hosek e1173c8794 [runtimes] Use add_lit_testsuite to register lit testsuites
The runtimes build uses variables set by add_lit_testsuite to collect
testsuites from all the runtimes.

Differential Revision: https://reviews.llvm.org/D97913
2021-03-05 10:37:21 -08:00
Fangrui Song 0c5bfe6bb8 [profile][test] Pin Linux/instrprof-value-prof-warn.test to -fuse-ld=bfd
To work around https://sourceware.org/bugzilla/show_bug.cgi?id=27490
2021-03-05 00:52:25 -08:00
Rainer Orth 579fd02597 [asan][test] Don't XFAIL Posix/unpoison-alternate-stack.cpp on Solaris
One ASan test currently `XPASS`es on Solaris:

  AddressSanitizer-i386-sunos :: TestCases/Posix/unpoison-alternate-stack.cpp

It was originally `XFAIL`ed in D88501 <https://reviews.llvm.org/D88501>
because `longjmp` from a signal handled is highly unportable, warned
against in XPG7, and was not supported by Solaris `libc` at the time.

However, since then support has been added for some cases including the
current one, so the `XFAIL` can go.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D97933
2021-03-05 09:43:47 +01:00
Rainer Orth 1d0dee51da [asan][test] Don't XFAIL Posix/no_asan_gen_globals.c on Solaris
One ASan test currently `XPASS`es on Solaris:

  AddressSanitizer-i386-sunos :: TestCases/Posix/no_asan_gen_globals.c

It was originally `XFAIL`ed in D88218 <https://reviews.llvm.org/D88218>
because Solaris `ld`, unlike GNU `ld`, doesn't strip local labels.  Since
then, the integrated assembler has stopped emitting those local labels, so
the difference becomes moot and the `XFAIL` can go.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D97932
2021-03-05 09:42:29 +01:00
Vitaly Buka 8a07c4a10b [sanitizer,NFC] Fix long comment formating 2021-03-04 20:58:42 -08:00
Vitaly Buka 657a58a571 [dfsan,NFC] Suppress cpplint warning 2021-03-04 20:42:18 -08:00
Mitch Phillips 1be97975cc Change instrprof LLVM_VP_MAX_NUM_VALS_PER_SITE threshold.
We're having flaky failures on this test on the sanitizer slow
buildbot. Not per-run flaky, but it'll be green for a while, then red
for a while. I suspect that changes in codegen are causing the
LLVM_VP_MAX_NUM_VALS_PER_SITE=150 to be above and below the limit
sporadically. The limit on my machine using lld and a non-bootstrapped
compiler is 175, but the bot uses GNU ld and ld.gold at different
points, which could be affecting behaviour.

Change this threshold to LLVM_VP_MAX_NUM_VALS_PER_SITE=130 in order to
try and get it below the failure point, at least for the foreseeable
future.

http://lab.llvm.org:8011/#/builders/37/builds/2744
2021-03-04 12:13:47 -08:00
Zequan Wu 9783e20988 Revert "Revert "[Coverage] Emit gap region between statements if first statements contains terminate statements.""
Reland with update on test case ContinuousSyncmode/basic.c.

This reverts commit fe5c2c3ca6.
2021-03-04 11:52:43 -08:00
Nico Weber fe5c2c3ca6 Revert "[Coverage] Emit gap region between statements if first statements contains terminate statements."
This reverts commit 2d7374a0c6.
Breaks ContinuousSyncMode/basic.c in check-profile on macOS.
2021-03-04 08:53:30 -05:00
Hans Wennborg 840a16d3c4 Revert "[darwin] switch blocking mutex from osspinlock to os_unfair_lock"
> OSSpinLock is deprecated, so we are switching to `os_unfair_lock`. However, `os_unfair_lock` isn't available on older OSs, so we keep `OSSpinLock` as fallback.
>
> Also change runtime assumption check to static since they only ever check constant values.
>
> rdar://69588111
>
> Reviewed By: delcypher, yln
>
> Differential Revision: https://reviews.llvm.org/D97509

This reverts commit 71ef54337d.
2021-03-04 12:22:39 +01:00
Petr Hosek 46a3f4ae27 Revert "[XRay][x86_64] Fix CFI directives in assembly trampolines"
This reverts commit 9ee61cf3f6 since
it's failing to compile on Darwin.
2021-03-04 01:03:04 -08:00
Siva Chandra Reddy 0106370bee [compiler-rt | interceptors] Provide an intercept override knob.
This knob is useful for downstream users who want that some of their
libc functions to not be intercepted.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D97740
2021-03-03 21:03:46 -08:00
Fangrui Song a84f4fc0df [InstrProfiling] Place __llvm_prf_vnodes and __llvm_prf_names in llvm.used on ELF
`__llvm_prf_vnodes` and `__llvm_prf_names` are used by runtime but not
referenced via relocation in the translation unit.

With `-z start-stop-gc` (LLD 13 (D96914); GNU ld 2.37 https://sourceware.org/bugzilla/show_bug.cgi?id=27451),
the linker does not let `__start_/__stop_` references retain their sections.

Place `__llvm_prf_vnodes` and `__llvm_prf_names` in `llvm.used` to make
them retained by the linker.

This patch changes most existing `UsedVars` cases to `CompilerUsedVars`
to reflect the ideal state - if the binary format properly supports
section based GC (dead stripping), `llvm.compiler.used` should be sufficient.

`__llvm_prf_vnodes` and `__llvm_prf_names` are switched to `UsedVars`
since we want them to be unconditionally retained by both compiler and linker.

Behaviors on COFF/Mach-O are not affected.

Reviewed By: davidxl

Differential Revision: https://reviews.llvm.org/D97649
2021-03-03 11:32:24 -08:00
Fangrui Song 75df61e93d [test] Improve PGO tests 2021-03-03 11:32:24 -08:00
Zequan Wu 2d7374a0c6 [Coverage] Emit gap region between statements if first statements contains terminate statements.
Differential Revision: https://reviews.llvm.org/D97101
2021-03-03 11:25:49 -08:00
Petr Hosek 61a792b39b [CMake] Rename RUNTIMES_BUILD to LLVM_RUNTIMES_BUILD
This avoid potential conflict with other internal variables.

Differential Revision: https://reviews.llvm.org/D97838
2021-03-03 10:58:51 -08:00
Elia Geretto 9ee61cf3f6 [XRay][x86_64] Fix CFI directives in assembly trampolines
This patch modifies the x86_64 XRay trampolines to fix the CFI information
generated by the assembler. One of the main issues in correcting the CFI
directives is the `ALIGNED_CALL_RAX` macro, which makes the CFA dependent on
the alignment of the stack. However, this macro is not really necessary because
some additional assumptions can be made on the alignment of the stack when the
trampolines are called. The code has been written as if the stack is guaranteed
to be 8-bytes aligned; however, it is instead guaranteed to be misaligned by 8
bytes with respect to a 16-bytes alignment. For this reason, always moving the
stack pointer by 8 bytes is sufficient to restore the appropriate alignment.

Trampolines that are called from within a function as a result of the builtins
`__xray_typedevent` and `__xray_customevent` are necessarely called with the
stack properly aligned so, in this case too, `ALIGNED_CALL_RAX` can be
eliminated.

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

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D96785
2021-03-03 10:01:28 -08:00
Nico Weber 64f5d7e972 Revert "[InstrProfiling] Place __llvm_prf_vnodes and __llvm_prf_names in llvm.used on ELF"
This reverts commit 04c3040f41.
Breaks instrprof-value-merge.c in bootstrap builds.
2021-03-03 10:21:17 -05:00
Petr Hosek 6e3946c9f5 [runtimes] Use standalone build only for compiler-rt
compiler-rt needs to use standalone build because of the assumptions
made by its build, but other runtimes can use non-standalone build.

Differential Revision: https://reviews.llvm.org/D97575
2021-03-03 00:06:20 -08:00
Petr Hosek b3ac90da1d Revert "[runtimes] Use standalone build only for compiler-rt"
This reverts commit 4e421b2323 as this
seemed to have broke Python 3 executable detection on some builders.
2021-03-02 16:59:32 -08:00
Petr Hosek 4e421b2323 [runtimes] Use standalone build only for compiler-rt
compiler-rt needs to use standalone build because of the assumptions
made by its build, but other runtimes can use non-standalone build.

Differential Revision: https://reviews.llvm.org/D97575
2021-03-02 16:21:35 -08:00
Luís Marques 2b5f3f446f [Sanitizer][NFC] Fix typo 2021-03-01 23:47:03 +00:00
Fangrui Song 04c3040f41 [InstrProfiling] Place __llvm_prf_vnodes and __llvm_prf_names in llvm.used on ELF
`__llvm_prf_vnodes` and `__llvm_prf_names` are used by runtime but not
referenced via relocation in the translation unit.

With `-z start-stop-gc` (D96914 https://sourceware.org/bugzilla/show_bug.cgi?id=27451),
the linker no longer lets `__start_/__stop_` references retain them.

Place `__llvm_prf_vnodes` and `__llvm_prf_names` in `llvm.used` to make
them retained by the linker.

This patch changes most existing `UsedVars` cases to `CompilerUsedVars`
to reflect the ideal state - if the binary format properly supports
section based GC (dead stripping), `llvm.compiler.used` should be sufficient.

`__llvm_prf_vnodes` and `__llvm_prf_names` are switched to `UsedVars`
since we want them to be unconditionally retained by both compiler and linker.

Behaviors on other COFF/Mach-O are not affected.

Differential Revision: https://reviews.llvm.org/D97649
2021-03-01 13:43:23 -08:00
Vedant Kumar 2fcc3f4b18 [test/profile] Disable instrprof-write-buffer-internal.c on Windows
This is failing due to:

"instrprof-write-buffer-internal.c.tmp.buf.profraw: Invalid
instrumentation profile data (file header is corrupt)"

https://lab.llvm.org/buildbot/#/builders/127/builds/6830
2021-03-01 11:06:38 -08:00