Commit Graph

11997 Commits

Author SHA1 Message Date
Dmitry Vyukov 7505cc301f tsan: remove tracking of racy addresses
We used to deduplicate based on the race address to prevent lots
of repeated reports about the same race.

But now we clear the shadow for the racy address in DoReportRace:

  // This prevents trapping on this address in future.
  for (uptr i = 0; i < kShadowCnt; i++)
    StoreShadow(&shadow_mem[i], i == 0 ? Shadow::kRodata : Shadow::kEmpty);

It should have the same effect of not reporting duplicates
(and actually better because it's automatically reset when the memory is reallocated).

So drop the address deduplication code. Both simpler and faster.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D130240
2022-07-25 10:33:26 +02:00
Khem Raj 8f24a56a3a [compiler-rt][CMake] Enable TF intrinsics on powerpc32 Linux
clang generates calls to these intrinsics when used for ppc32/linux, when using libgcc this works ok but when using compiler-rt for rtlib it fails with missing intrinsic symbols. also see [1]

[1] https://lists.llvm.org/pipermail/llvm-dev/2014-May/072784.html

Reviewed By: MaskRay, glaubitz

Differential Revision: https://reviews.llvm.org/D121379
2022-07-24 10:17:22 -07:00
Dimitrije Milosevic 2bfb0fcb51 [MIPS][compiler-rt] Fix stat struct's size for O32 ABI
Add the MIPS O32 ABI value for the stat struct's size.

Differential Revision: https://reviews.llvm.org/D129749.
2022-07-23 11:53:00 +02:00
Ivan Trofimov 15e9b1d0c0 [libasan] Remove 4Mb stack limit for swapcontext unpoisoning
Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D129219
2022-07-22 17:37:44 -07:00
Vitaly Buka c93e4b6b2c [asan] Reset stack bounds of context
ClearShadowMemoryForContextStack assumes that context contains the stack
bounds. This is not true for a context from getcontext or oucp of
swapcontext.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D130218
2022-07-22 13:40:16 -07:00
Julian Lettner 2f46983981 [Sanitizer][Darwin] Factor out code for GCD worker registration
This is a NFC change to factor out GCD worker thread registration via
the pthread introspection hook.

In a follow-up change we also want to register GCD workers for ASan to
make sure threads are registered before we attempt to print reports on
them.

rdar://93276353

Differential Revision: https://reviews.llvm.org/D126351
2022-07-22 13:29:28 -07:00
Dmitry Vyukov b988d8ddc2 tsan: remove unnecessary brackets
Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D130236
2022-07-21 12:11:44 +02:00
Rainer Orth 3776db9a4f [sanitizer_common] Support Solaris < 11.4 in GetStaticTlsBoundary
This patch, on top of D120048 <https://reviews.llvm.org/D120048>, supports
GetTls on Solaris 11.3 and Illumos that lack `dlpi_tls_modid`.  It's the
same method originally used in D91605 <https://reviews.llvm.org/D91605>,
but integrated into `GetStaticTlsBoundary`.

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

Differential Revision: https://reviews.llvm.org/D120059
2022-07-21 09:18:10 +02:00
Ian Anderson 28800c2e18 [sanitizer] Use consistent checks for XDR
sanitizer_platform_limits_posix.h defines `__sanitizer_XDR ` if `SANITIZER_LINUX && !SANITIZER_ANDROID`, but sanitizer_platform_limits_posix.cpp tries to check it if `HAVE_RPC_XDR_H`. This coincidentally works because macOS has a broken <rpc/xdr.h> which causes `HAVE_RPC_XDR_H` to be 0, but if <rpc/xdr.h> is fixed then clang fails to compile on macOS. Restore the platform checks so that <rpc/xdr.h> can be fixed on macOS.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D130060
2022-07-20 22:28:07 -07:00
Xi Ruoyao bba1f26f2e Port address sanitizer to LoongArch
Depends on D129371.

It survived all GCC ASan tests.

Changes are trivial and mostly "borrowed" RISC-V logics, except that a different SHADOW_OFFSET is used.

Reviewed By: SixWeining, MaskRay, XiaodongLoong

Differential Revision: https://reviews.llvm.org/D129418
2022-07-21 11:32:21 +08:00
Vitaly Buka 82995e0e82 [NFC][asan] Clang-format a code 2022-07-20 18:57:37 -07:00
Vitaly Buka e8554402b3 [NFC][memprof] Remove unused code 2022-07-20 18:50:45 -07:00
Vitaly Buka 26a7ee3d54 [NFC][asan] Use RoundDownTo 2022-07-20 18:50:44 -07:00
Xi Ruoyao dbec35ccf8 [sanitizer] Port sanitizer_common to LoongArch
Initial libsanitizer support for LoongArch. It survived all GCC UBSan tests.

Major changes:

1. LoongArch port of Linux kernel only supports `statx` for `stat` and its families.  So we need to add `statx_to_stat` and use it for `stat`-like libcalls.  The logic is "borrowed" from Glibc.
2. `sanitizer_syscall_linux_loongarch64.inc` is mostly duplicated from RISC-V port, as the syscall interface is almost same.

Reviewed By: SixWeining, MaskRay, XiaodongLoong, vitalybuka

Differential Revision: https://reviews.llvm.org/D129371
2022-07-20 00:58:40 -07:00
Vitaly Buka 868e1ee1d0 Revert "[libasan] Remove 4Mb stack limit for swapcontext unpoisoning"
This patches exposed existing incorectness of swapcontext imlementation.
swapcontext does not set oucp->uc_stack. Unpoisoning works if ucp is
from makecontext, but may try to use garbage pointers if it's from
previos swapcontext or from getcontext. Existing limit reduces
probability of garbage pointers are used.

I restore behavour which we had for years, and will look to improve
swapcontext support.

This reverts commit d0751c9725.
2022-07-19 21:40:19 -07:00
Andrew Turner 1b2fa907d7 Add the FreeBSD AArch64 memory layout
Use the FreeBSD AArch64 memory layout values when building for it.
These are based on the x86_64 values, scaled to take into account the
larger address space on AArch64.

Reviewed by: vitalybuka

Differential Revision: https://reviews.llvm.org/D125758
2022-07-19 09:58:04 -04:00
Dmitry Vyukov 6d1f86095d tsan: optimize DenseSlabAlloc
If lots of threads do lots of malloc/free and they overflow
per-pthread DenseSlabAlloc cache, it causes lots of contention:

  31.97%  race.old  race.old            [.] __sanitizer::StaticSpinMutex::LockSlow
  17.61%  race.old  race.old            [.] __tsan_read4
  10.77%  race.old  race.old            [.] __tsan::SlotLock

Optimize DenseSlabAlloc to use a lock-free stack of batches of nodes.
This way we don't take any locks in steady state at all and do only
1 push/pop per Refill/Drain.

Effect on the added benchmark:

$ TIME="%e %U %S %M" time ./test.old 36 5 2000000
34.51 978.22 175.67 5833592
32.53 891.73 167.03 5790036
36.17 1005.54 201.24 5802828
36.94 1004.76 226.58 5803188

$ TIME="%e %U %S %M" time ./test.new 36 5 2000000
26.44 720.99 13.45 5750704
25.92 721.98 13.58 5767764
26.33 725.15 13.41 5777936
25.93 713.49 13.41 5791796

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D130002
2022-07-19 15:42:57 +02:00
serge-sans-paille eb0e3319bf [sanitizer] Don't call dlerror() after swift_demangle lookup through dlsym
Because the call to `dlerror()` may actually want to print something, which turns into a deadlock
as showcased in #49223.

Instead rely on further call to dlsym to clear `dlerror` internal state if they
need to check the return status.

Differential Revision: https://reviews.llvm.org/D128992
2022-07-19 09:07:30 +02:00
Xi Ruoyao 36b52c38aa [sanitizer] Compare against the alignment of the latter range trying to find consecutive TLS blocks in GetStaticTlsBoundary
On a mips64el-linux-gnu system, the dynamic linker arranges TLS blocks
like:

    [0] 0xfff7fe9680..0xfff7fe9684, align = 0x4
    [1] 0xfff7fe9688..0xfff7fe96a8, align = 0x8
    [2] 0xfff7fe96c0..0xfff7fe9e60, align = 0x40
    [3] 0xfff7fe9e60..0xfff7fe9ef8, align = 0x8

Note that the dynamic linker can only put [1] at 0xfff7fe9688, not
0xfff7fe9684 or it will be misaligned.  But we were comparing the
distance between two blocks with the alignment of the previous range,
causing GetStaticTlsBoundary fail to merge the consecutive blocks.

Compare against the alignment of the latter range to fix the issue.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D129112
2022-07-17 00:45:15 -07:00
Rainer Orth 74f6672e59 [sanitizer_common] Several Solaris procmaps fixes
Since the introduction of GoogleTest sharding in D122251
<https://reviews.llvm.org/D122251>, some of the Solaris sanitizer tests
have been running extremly long (up to an hour) while they took mere
seconds before.  Initial investigation suggests that massive lock
contention in Solaris procfs is involved here.

However, there's an easy way to somewhat reduce the impact: while the
current `ReadProcMaps` uses `ReadFileToBuffer` to read `/proc/self/xmap`,
that function primarily caters to Linux procfs reporting file sizes of 0
while the size on Solaris is accurate.  This patch makes use of that,
reducing the number of syscalls involved and reducing the runtime of
affected tests by a factor of 4.

Besides, it handles shared mappings and doesn't call `readlink` for unnamed
map entries.

Tested on `sparcv9-sun-solaris2.11` and `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D129837
2022-07-16 06:59:00 +02:00
Julian Lettner 32a425ec0c [Sanitizer][Darwin][NFC] Small SANITIZER_APPLE cleanup
We introduced `SANITIZER_APPLE` here: https://reviews.llvm.org/D126263
2022-07-15 16:31:35 -07:00
Leonard Grey 1231a2cec0 [lsan][Darwin][nfc] Fix thread vector size
The reserve constructor was removed in 44f55509d7
but this one was missed. As a result, we attempt to iterate through 1024 threads
each time, most of which are 0.

Differential Revision: https://reviews.llvm.org/D129897
2022-07-15 17:34:29 -04:00
Leonard Grey b15cf06fb3 [lsan][nfc] Add missing newline to VReport 2022-07-15 15:44:23 -04:00
Petr Hosek cae5462a2c [compiler-rt][CMake] Set unwinder for MSan unittests
This addresses an issue introduced by 6699f55488.
2022-07-15 08:11:59 +00:00
Petr Hosek 6699f55488 [compiler-rt][CMake] Set --unwindlib=none when using LLVM libunwind
We already link libunwind explicitly so avoid trying to link toolchain's
default libunwind which may be missing. This matches what we already do
for libcxx and libcxxabi.

Differential Revision: https://reviews.llvm.org/D129472
2022-07-15 07:25:38 +00:00
Kostya Serebryany ef0081d608 [SanitizerCoverage] add weak definitions for the load/store callbacks.
Add weak definitions for the load/store callbacks.

This matches the weak definitions for all other SanitizerCoverage
callbacks.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D129801
2022-07-14 20:26:41 -07:00
Vitaly Buka bb4d974135 [NFC] Clang-format D129645 2022-07-14 10:27:04 -07:00
Dmitry Vyukov ab02680b5a tsan: fix a bug in trace part switching
Callers of TraceSwitchPart expect that TraceAcquire will always succeed
after the call. It's possible that TryTraceFunc/TraceMutexLock in TraceSwitchPart
that restore the current stack/mutexset filled the trace part exactly up
to the TracePart::kAlignment gap and the next TraceAcquire won't succeed.
Skip the alignment gap after writing initial stack/mutexset to avoid that.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D129777
2022-07-14 17:49:00 +02:00
Alexander Potapenko b191056f44 [compiler-rt][hwasan] Support for new Intel LAM API
New version of Intel LAM patches
(https://lore.kernel.org/linux-mm/20220712231328.5294-1-kirill.shutemov@linux.intel.com/)
uses a different interface based on arch_prctl():
 - arch_prctl(ARCH_GET_UNTAG_MASK, &mask) returns the current mask for
   untagging the pointers. We use it to detect kernel LAM support.
 - arch_prctl(ARCH_ENABLE_TAGGED_ADDR, nr_bits) enables pointer tagging
   for the current process.

Because __NR_arch_prctl is defined in different headers, and no other
platforms need it at the moment, we only declare internal_arch_prctl()
on x86_64.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D129645
2022-07-13 19:11:13 -07:00
Leonard Chan 21f72c05c4 [hwasan] Add __hwasan_add_frame_record to the hwasan interface
Hwasan includes instructions in the prologue that mix the PC and SP and store
it into the stack ring buffer stored at __hwasan_tls. This is a thread_local
global exposed from the hwasan runtime. However, if TLS-mechanisms or the
hwasan runtime haven't been setup yet, it will be invalid to access __hwasan_tls.
This is the case for Fuchsia where we instrument libc, so some functions that
are instrumented but can run before hwasan initialization will incorrectly
access this global. Additionally, libc cannot have any TLS variables, so we
cannot weakly define __hwasan_tls until the runtime is loaded.

A way we can work around this is by moving the instructions into a hwasan
function that does the store into the ring buffer and creating a weak definition
of that function locally in libc. This way __hwasan_tls will not actually be
referenced. This is not our long-term solution, but this will allow us to roll
out hwasan in the meantime.

This patch includes:

- A new llvm flag for choosing to emit a libcall rather than instructions in the
  prologue (off by default)
- The libcall for storing into the ringbuffer (__hwasan_add_frame_record)

Differential Revision: https://reviews.llvm.org/D128387
2022-07-13 15:15:15 -07:00
Leonard Chan d843d5c8e6 Revert "[hwasan] Add __hwasan_record_frame_record to the hwasan interface"
This reverts commit 4956620387.

This broke a sanitizer builder: https://lab.llvm.org/buildbot/#/builders/77/builds/19597
2022-07-13 15:06:07 -07:00
leonardchan 4956620387 [hwasan] Add __hwasan_record_frame_record to the hwasan interface
Hwasan includes instructions in the prologue that mix the PC and SP and store
it into the stack ring buffer stored at __hwasan_tls. This is a thread_local
global exposed from the hwasan runtime. However, if TLS-mechanisms or the
hwasan runtime haven't been setup yet, it will be invalid to access __hwasan_tls.
This is the case for Fuchsia where we instrument libc, so some functions that
are instrumented but can run before hwasan initialization will incorrectly
access this global. Additionally, libc cannot have any TLS variables, so we
cannot weakly define __hwasan_tls until the runtime is loaded.

A way we can work around this is by moving the instructions into a hwasan
function that does the store into the ring buffer and creating a weak definition
of that function locally in libc. This way __hwasan_tls will not actually be
referenced. This is not our long-term solution, but this will allow us to roll
out hwasan in the meantime.

This patch includes:

- A new llvm flag for choosing to emit a libcall rather than instructions in the
  prologue (off by default)
- The libcall for storing into the ringbuffer (__hwasan_record_frame_record)

Differential Revision: https://reviews.llvm.org/D128387
2022-07-14 05:07:11 +08:00
Mitch Phillips 81c48436bb [~NFC] Fix printf() type punning warning in asan_globals.cpp 2022-07-12 10:48:43 -07:00
Mariusz Borsa af0a26b476 [Sanitizers][Darwin] Remove SANITIZER_MAC
This is to finish the change started by D125816 , D126263 and D126577 (replace SANITIZER_MAC by SANITIZER_APPLE).
Dropping definition of SANITIZER_MAC completely, to remove any possible confusion.

Differential Revision: https://reviews.llvm.org/D129502
2022-07-12 09:11:17 -07:00
Fangrui Song 9cf13067cb [sanitizer] Remove #include <linux/fs.h> to resolve fsconfig_command/mount_attr conflict with glibc 2.36
It is generally not a good idea to mix usage of glibc headers and Linux UAPI
headers (https://sourceware.org/glibc/wiki/Synchronizing_Headers). In glibc
since 7eae6a91e9b1670330c9f15730082c91c0b1d570 (milestone: 2.36), sys/mount.h
defines `fsconfig_command` which conflicts with linux/mount.h:

    .../usr/include/linux/mount.h:95:6: error: redeclaration of ‘enum fsconfig_command’

Remove #include <linux/fs.h> which pulls in linux/mount.h. Expand its 4 macros manually.
Android sys/mount.h doesn't define BLKBSZGET and it still needs linux/fs.h.
In the long term we should move Linux specific definitions to sanitizer_platform_limits_linux.cpp
but this commit is easy to cherry pick into older compiler-rt releases.

Fix https://github.com/llvm/llvm-project/issues/56421

Reviewed By: #sanitizers, vitalybuka, zatrazz

Differential Revision: https://reviews.llvm.org/D129471
2022-07-11 12:53:35 -07:00
Fangrui Song d2ce7e824d Revert "[sanitizer] Remove #include <linux/fs.h> to resolve fsconfig_command/mount_attr conflict with glibc 2.36"
This reverts commit b379129c4b.

Breaks Android build. Android sys/mount.h doesn't define macros like BLKBSZGET.
2022-07-11 12:53:34 -07:00
Fangrui Song b379129c4b [sanitizer] Remove #include <linux/fs.h> to resolve fsconfig_command/mount_attr conflict with glibc 2.36
It is generally not a good idea to mix usage of glibc headers and Linux UAPI
headers (https://sourceware.org/glibc/wiki/Synchronizing_Headers). In glibc
since 7eae6a91e9b1670330c9f15730082c91c0b1d570 (milestone: 2.36), sys/mount.h
defines `fsconfig_command` which conflicts with linux/mount.h:

    .../usr/include/linux/mount.h:95:6: error: redeclaration of ‘enum fsconfig_command’

Remove #include <linux/fs.h> which pulls in linux/mount.h. Expand its 4 macros manually.

Fix https://github.com/llvm/llvm-project/issues/56421

Reviewed By: #sanitizers, vitalybuka, zatrazz

Differential Revision: https://reviews.llvm.org/D129471
2022-07-11 11:38:28 -07:00
Alex Brachet 1039165b96 [scudo][NFC] Clang-format c823cbf699
Ran `git clang-format` but didn't add the changed file...
2022-07-11 17:41:37 +00:00
Alex Brachet c823cbf699 [scudo][Fuchsia] Don't assume MapPlatformData::Vmar is valid
After https://reviews.llvm.org/D129237, the assumption
that any non-null data contains a valid vmar handle is no
longer true. Generally this code here needs cleanup, but
in the meantime this fixes errors on Fuchsia.

Differential Revision: https://reviews.llvm.org/D129331
2022-07-11 17:39:44 +00:00
Ivan Trofimov d0751c9725 [libasan] Remove 4Mb stack limit for swapcontext unpoisoning
Reviewed By: vitalybuka, eugenis

Differential Revision: https://reviews.llvm.org/D129219
2022-07-11 10:32:43 -07:00
Dominic Chen ec9907fbf6 [scudo] Satisfy -Wstrict-prototypes
Differential Revision: https://reviews.llvm.org/D129391
2022-07-11 10:28:38 -07:00
Ivan Trofimov f20a3cbefd [NFC][asan] Clang-format a test
Part of D129219.
2022-07-11 10:12:05 -07:00
Than McIntosh 127e59048c tsan: update Go x86 build rules to back off to sse3
This is a partial revert of https://reviews.llvm.org/D106948, changing
just the Go build rules to remove -msse4.2 and revert back to -msse3,
so as to preserve support for older x86 machines. More details at
https://github.com/golang/go/issues/53743.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D129482
2022-07-11 12:41:24 -04:00
Petr Hosek fb89c41269 [CMake] Set the common link flags for memprof tests
This was missed in ba007f20bb by mistake.
2022-07-09 09:03:33 +00:00
Petr Hosek ba007f20bb [CMake] Use explicit header path when using in-tree libc++ for tests
This is a follow up to D118200 which applies a similar cleanup to
headers when using in-tree libc++ to avoid accidentally picking up
the system headers.

Differential Revision: https://reviews.llvm.org/D128035
2022-07-09 06:14:29 +00:00
Petr Hosek 99cc28b705 Revert "[CMake] Use explicit header path when using in-tree libc++ for tests"
This reverts commit 61b410cb8b as this
appears to have broken some sanitizer tests.
2022-07-09 04:27:16 +00:00
Petr Hosek 61b410cb8b [CMake] Use explicit header path when using in-tree libc++ for tests
This is a follow up to D118200 which applies a similar cleanup to
headers when using in-tree libc++ to avoid accidentally picking up
the system headers.

Differential Revision: https://reviews.llvm.org/D128035
2022-07-09 03:18:46 +00:00
Petr Hosek df90d22704 [CMake] Option to select C++ library for runtimes that use it
We currently have an option to select C++ ABI and C++ library for tests
but there are runtimes that use C++ library, specifically ORC and XRay,
which aren't covered by existing options. This change introduces a new
option to control the use of C++ libray for these runtimes.

Ideally, this option should become the default way to select C++ library
for all of compiler-rt replacing the existing options (the C++ ABI
option could remain as a hidden internal option).

Differential Revision: https://reviews.llvm.org/D128036
2022-07-08 22:10:24 +00:00
Julian Lettner ca50840b5b [Sanitizer][Darwin] Cleanup MaybeReexec() function and usage
While investigating another issue, I noticed that `MaybeReexec()` never
actually "re-executes via `execv()`" anymore.  `DyldNeedsEnvVariable()`
only returned true on macOS 10.10 and below.

Usually, I try to avoid "unnecessary" cleanups (it's hard to be certain
that there truly is no fallout), but I decided to do this one because:

* I initially tricked myself into thinking that `MaybeReexec()` was
  relevant to my original investigation (instead of being dead code).
* The deleted code itself is quite complicated.
* Over time a few other things were mushed into `MaybeReexec()`:
  initializing `MonotonicNanoTime()`, verifying interceptors are
  working, and stripping the `DYLD_INSERT_LIBRARIES` env var to avoid
  problems when forking.
* This platform-specific thing leaked into `sanitizer_common.h`.
* The `ReexecDisabled()` config nob relies on the "strong overrides weak
  pattern", which is now problematic and can be completely removed.
* `ReexecDisabled()` actually hid another issue with interceptors not
  working in unit tests.  I added an explicit `verify_interceptors`
  (defaults to `true`) option instead.

Differential Revision: https://reviews.llvm.org/D129157
2022-07-08 14:31:42 -07:00
Leonard Chan 474c873148 Revert "[llvm] cmake config groundwork to have ZSTD in LLVM"
This reverts commit f07caf20b9 which seems to break upstream https://lab.llvm.org/buildbot/#/builders/109/builds/42253.
2022-07-08 13:48:05 -07:00
Cole Kissane f07caf20b9 [llvm] cmake config groundwork to have ZSTD in LLVM
- added `FindZSTD.cmake`
- added a CMake option `LLVM_ENABLE_ZSTD` with behavior mirroring that of `LLVM_ENABLE_ZLIB`
- likewise added have_zstd to compiler-rt/test/lit.common.cfg.py, clang-tools-extra/clangd/test/lit.cfg.py, and several lit.site.cfg.py.in files mirroring have_zlib behavior

Reviewed By: leonardchan, MaskRay

Differential Revision: https://reviews.llvm.org/D128465
2022-07-08 11:46:52 -07:00
Julian Lettner 7789c9afc1 Revert "[Sanitizer][Darwin] Cleanup MaybeReexec() function and usage"
Many tests for the `UBSan-Standalone-iossim-x86_64` fail with this.
Reverting so I can investigate.

This reverts commit 0a9667b0f5.
2022-07-07 17:27:10 -07:00
Julian Lettner 0a9667b0f5 [Sanitizer][Darwin] Cleanup MaybeReexec() function and usage
While investigating another issue, I noticed that `MaybeReexec()` never
actually "re-executes via `execv()`" anymore.  `DyldNeedsEnvVariable()`
only returned true on macOS 10.10 and below.

Usually, I try to avoid "unnecessary" cleanups (it's hard to be certain
that there truly is no fallout), but I decided to do this one because:

* I initially tricked myself into thinking that `MaybeReexec()` was
  relevant to my original investigation (instead of being dead code).
* The deleted code itself is quite complicated.
* Over time a few other things were mushed into `MaybeReexec()`:
  initializing `MonotonicNanoTime()`, verifying interceptors are
  working, and stripping the `DYLD_INSERT_LIBRARIES` env var to avoid
  problems when forking.
* This platform-specific thing leaked into `sanitizer_common.h`.
* The `ReexecDisabled()` config nob relies on the "strong overrides weak
  pattern", which is now problematic and can be completely removed.
* `ReexecDisabled()` actually hid another issue with interceptors not
  working in unit tests.  I added an explicit `verify_interceptors`
  (defaults to `true`) option instead.

Differential Revision: https://reviews.llvm.org/D129157
2022-07-07 16:39:27 -07:00
Leonard Chan c211041802 [hwasan][fuchsia] Fix features bitmask checking
Update the address tagging bitmask check to just see if
ZX_ARM64_FEATURE_ADDRESS_TAGGING_TBI is enabled rather than checking
if it's the only thing that's enabled.

Differential Revision: https://reviews.llvm.org/D129318
2022-07-07 14:43:00 -07:00
Dominic Chen 5f3818c7df [scudo] Add [[no_unique_address]] attribute to new MapPlatformData variables
Differential Revision: https://reviews.llvm.org/D129237
2022-07-07 13:12:55 -07:00
Dominic Chen ff8c0e6eb5 [scudo] Pass MapPlatformData in more calls
Allow platforms to avoid looking up private data by providing private context

Differential Revision: https://reviews.llvm.org/D129237
2022-07-07 10:43:07 -07:00
theidexisted 85236e6f3b [NFC][sanitizer] Minor change: eliminate loop
Reviewed By: #sanitizers, fmayer, vitalybuka

Differential Revision: https://reviews.llvm.org/D128873
2022-07-07 10:33:08 -07:00
Vitaly Buka ba4435eb62 [msan] Fix dn_comp interceptor after D126851
Unpoison by strlen(dest), as dn_expand
returns the size if the compressed name (src).

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D129244
2022-07-07 09:27:44 -07:00
Vitaly Buka 9a04710b57 [NFC][sanitizer] Format dn_expand interceptor 2022-07-06 21:21:17 -07:00
Sunho Kim 30b6c51f51 [ORC][ORC_RT][AArch64] Implement TLS descriptor in ELFNixPlatform.
Implements TLS descriptor relocations in JITLink ELF/AARCH64 backend and support the relevant runtime functions in ELFNixPlatform.

Unlike traditional TLS model, TLS descriptor model requires linker to return the "offset" from thread pointer via relocaiton not the actual pointer to thread local variable. There is no public libc api for adding new allocations to TLS block dynamically which thread pointer points to. So, we support this by taking delta from thread base pointer to the actual thread local variable in our allocated section.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D128601
2022-07-06 20:12:22 +09:00
Dimitrije Milosevic 5d8077565e [MIPS] Resolve issues in building ASAN for N32 ABI
Building the compiler-rt's AddressSanitizer for
the n32 MIPS ABI currently fails, due to a few reasons:

    - defined(__mips64), which is set solely based on
    the architecture type (32-bit/64-bit), was still used
    in some places. Therefore, defined(__mips64) is swapped
    with SANITIZER_MIPS64, which takes the ABI into account
    as well - defined(__mips64) && _MIPS_SIM == ABI64.
    - The n32 ABI still uses 64-bit *Linux* system calls,
    even though the word size is 32 bits.
    - After the transition to canonical system calls (D124212),
    the n32 ABI still didn't use them, even though they
    are supported.

Differential Revision: https://reviews.llvm.org/D127098
2022-07-06 12:44:29 +02:00
Julian Lettner 18e4674ea6 [Sanitizer][Darwin] Fix log-path_test.cpp
In my previous change [1], I added log output that made a test that
expected "no output" fail.  The easiest solution is to only print the
new hint/warning when we at least ask for `verbosity=1`.

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

Radar-Id: rdar://96437354
2022-07-05 16:34:55 -07:00
Andi-Bogdan Postelnicu 6e2058e588 [Compiler-RT] Remove FlushViewOfFile call when unmapping gcda files on win32.
This patch was pushed for calixte@mozilla.com

- this function (Windows only) is called when gcda are dumped on disk;
- according to its documentation, it's only useful in case of hard failures, this is highly improbable;
- it drastically decreases the time in the tests and consequently it avoids timeouts when we use slow disks.

Differential Revision: https://reviews.llvm.org/D129128
2022-07-05 13:24:28 +00:00
Vitaly Buka 7788b0c097 [lsan] malloc_usable_size returns 0 for nullptr 2022-07-02 20:16:30 -07:00
Vitaly Buka f2fa4f9759 [sanitizer] Update dn_expand interceptor for glibc 2.34
Symbol changed with 640bbdf71c6f10ac26252ac67a22902e26657bd8
2022-07-01 16:26:58 -07:00
Petr Hosek 291e3a8565 [compiler-rt] Update Fuchsia sanitizer sched_yield
Fuchsia has split overloaded nanosleep(0) for yielding to its own
dedicated syscall, so valid zero deadlines would just return.

Patch By: gevalentino

Differential Revision: https://reviews.llvm.org/D128748
2022-07-01 17:25:57 +00:00
Julian Lettner 3abf3df08a [Sanitizer][Darwin] Lookup dyld image header via shared cache
On macOS 13+, dyld itself has moved into the shared cache.  Looking it
up via vm_region_recurse_64() now causes spins/hangs/crashes.  We use a
different set of dyld APIs to find the image header in the shared cache.

rdar://92131949

Differential Revision: https://reviews.llvm.org/D128936
2022-06-30 15:45:25 -07:00
Kostya Serebryany 92fb310151 [libFuzzer] Extend the fuzz target intarface to allow -1 return value.
With this change, fuzz targets may choose to return -1
to indicate that the input should not be added to the corpus
regardless of the coverage it generated.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D128749
2022-06-30 13:21:27 -07:00
Mariusz Borsa 67ced6af3b [Sanitizers] Cleanup handling of stat64/statfs64
This is a follow up to <LLVM reviews>/D127343, which was reverted due to test failures.

There are differences in handling of stat64/statfs64 calls by sanitizers between Linux and macOS. Versions of macOS starting with 10.6 drop the stat64/statfs64 APIs completely, relying on the linker to redirect stat/statfs to the appropriate 64 bit versions. Emitting variables needed by sanitizers is thus controlled by convoluted sets of conditions, involving Linux, IOS, macOS and Android, sprinkled around files.

This change clarifies it a bit, allowing to specify presence/absence of stat64/statfs64 for each platform, in a single location.

Please note that I wasn't able to test this change on platforms other than macOS and Linux Fedora 34. The previous attempt has caused test failures but couldn't figure out the context. I have a vague suspicion that they were Android and perhaps Fuchsia builds - and some build involving ppc64le, I don't have hardware handy to attempt a test there. Tried to tighten the conditions this time to clearly separate macOS from Linux, so Linux builds should behave same (sanitizerwise) as before the change. Will add people who reported the tests failing before as reviewers, so they can provide context should the change cause the test failures again.

Differential Revision: https://reviews.llvm.org/D128476
2022-06-28 15:01:38 -07:00
Matthias Braun a145a32544 build_symbolizer: Set LLVM_DEFAULT_TARGET_TRIPLE in llvm builds
Pass on the default target triple of the host clang to the LLVM builds
within the `build_symbolizer.sh` script.

Differential Revision: https://reviews.llvm.org/D128731
2022-06-28 14:49:35 -07:00
Matthias Braun 2030e6496a Avoid ar_to_bc.sh script in symbolizer build; add -ignore-non-bitcode flag to llvm-link
Remove the `ar_to_bc.sh` helper script in the compiler-rt symbolizer
build. Instead use `llvm-link` directly as D81109 introduced the
capability to read archives. I just needed to add a new flag
`-ignore-non-bitcode` to avoid `llvm-link` aborting when it found a
non-bitcode file in the archive.

Differential Revision: https://reviews.llvm.org/D128729
2022-06-28 14:49:35 -07:00
Than McIntosh 13fb97d688 tsan: add missing guard for DumpProcessMap call
Add a missing "#if !SANITIZER_GO" guard for a call to DumpProcessMap
in the Finalize hook (needed to build an updated Go race detector syso
image).

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D128641
2022-06-27 10:10:45 -04:00
Petr Hosek f3caa98e49 Revert "[CMake][compiler-rt] Clean up the use of libcxx and libcxxabi"
This reverts commit 4164cfa537 since
it broke the clang-x86_64-debian-fast builder:

  https://lab.llvm.org/buildbot/#/builders/109/builds/41339
2022-06-25 03:10:55 +00:00
Petr Hosek 4164cfa537 [CMake][compiler-rt] Clean up the use of libcxx and libcxxabi
We no longer support the use of LLVM_ENABLE_PROJECTS for libcxx and
libcxxabi. We don't use paths to libcxx and libcxxabi in compiler-rt.

Differential Revision: https://reviews.llvm.org/D126905
2022-06-25 02:53:43 +00:00
Petr Hosek 72ec31afad [CMake] Use set rather than list PREPEND
list PREPEND is only supported since CMake 3.15.

Differential Revision: https://reviews.llvm.org/D128548
2022-06-25 02:19:55 +00:00
Petr Hosek 048e6bb46b [CMake][compiler-rt] Treat target cflags as list rather than string
This is need after 30dfe016d4.

Differential Revision: https://reviews.llvm.org/D128548
2022-06-24 22:37:00 +00:00
Petr Hosek 8bee6e52f8 Revert "[CMake][compiler-rt] Clean up the use of libcxx and libcxxabi"
This reverts commit c0d4f2282d which
broke clang-x86_64-debian-fast:

  https://lab.llvm.org/buildbot/#/builders/109/builds/41268
2022-06-24 08:24:45 +00:00
Petr Hosek c0d4f2282d [CMake][compiler-rt] Clean up the use of libcxx and libcxxabi
We no longer support the use of LLVM_ENABLE_PROJECTS for libcxx and
libcxxabi. We don't use paths to libcxx and libcxxabi in compiler-rt.

Differential Revision: https://reviews.llvm.org/D126905
2022-06-24 08:11:37 +00:00
Lang Hames 232bd331cb [ORC-RT] Make the ORC runtime C API public.
This is a first step towards allowing programs to pre-link against the ORC
runtime, which would allow us to move some code that is currently in the LLVM
OrcTarget library into the ORC runtime instead.

The C API header has limited utility as-is, but serves as a minimal first step
and provides clients with tools for interacting with wrapper functions.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D127324
2022-06-16 19:02:23 -07:00
Fangrui Song 0e182469ee [sanitizer] Delete empty sanitizer_openbsd.cpp after D89759 2022-06-16 16:38:01 -07:00
Mitch Phillips 13e9c1d18e Reland "[ASan] Use debuginfo for symbolization."
This reverts commit 99796d06db.

Hint: Looking here because your manual invocation of something in
'check-asan' broke? You need a new symbolizer (after D123538).

An upcoming patch will remove the internal metadata for global
variables. With D123534 and D123538, clang now emits DWARF debug info
for constant strings (the only global variable type it was missing), and
llvm-symbolizer is now able to symbolize all global variable addresses
(where previously it wouldn't give you the file:line information).

Move ASan's runtime over from the internal metadata to DWARF.

Differential Revision: https://reviews.llvm.org/D127552
2022-06-16 13:58:55 -07:00
Kristina Bessonova 5cfbfa035f [sanitizer_common] Fix SanitizerCommon.ChainedOriginDepotStats test
This test was failing with the following error message if to run the test binary
directly, w/o using lit:

  $ Sanitizer-x86_64-Test --gtest_filter=SanitizerCommon.ChainedOriginDepot*
  ...
  [ RUN      ] SanitizerCommon.ChainedOriginDepotStats
  compiler-rt/lib/sanitizer_common/tests/sanitizer_chained_origin_depot_test.cpp:77: Failure
  Expected: (stats1.allocated) > (stats0.allocated), actual: 196608 vs 196608
  [  FAILED  ] SanitizerCommon.ChainedOriginDepotStats (867 ms)

Since the ChainedOriginDepot* tests are not doing any cleanup, by the time
SanitizerCommon.ChainedOriginDepotStats test starts executing the depot
may not be empty, so there will be no allocation for the test.

This patch introduces ChainedOriginDepot::TestOnlyUnmap() API that deallocates
memory when requested. This makes sure underlying TwoLevelMap initiates
the expected allocation during the test.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D127621
2022-06-16 11:59:58 +02:00
Kirill Stoimenov 99796d06db Revert "[ASan] Use debuginfo for symbolization."
This reverts commit f0ab8d90d4.
2022-06-15 23:42:46 +00:00
Mitch Phillips f0ab8d90d4 [ASan] Use debuginfo for symbolization.
Hint: Looking here because your manual invocation of something in
'check-asan' broke? You need a new symbolizer (after D123538).

An upcoming patch will remove the internal metadata for global
variables. With D123534 and D123538, clang now emits DWARF debug info
for constant strings (the only global variable type it was missing), and
llvm-symbolizer is now able to symbolize all global variable addresses
(where previously it wouldn't give you the file:line information).

Move ASan's runtime over from the internal metadata to DWARF.

Differential Revision: https://reviews.llvm.org/D127552
2022-06-15 15:36:36 -07:00
Benjamin Kramer 8bc0bb9564 Add a conversion from double to bf16
This introduces a new compiler-rt function `__truncdfbf2`.
2022-06-15 12:56:31 +02:00
Benjamin Kramer fb34d531af Promote bf16 to f32 when the target doesn't support it
This is modeled after the half-precision fp support. Two new nodes are
introduced for casting from and to bf16. Since casting from bf16 is a
simple operation I opted to always directly lower it to integer
arithmetic. The other way round is more complicated if you want to
preserve IEEE semantics, so it's handled by a new __truncsfbf2
compiler-rt builtin.

This is of course very bare bones, but sufficient to get a semi-softened
fadd on x86.

Possible future improvements:
 - Targets with bf16 conversion instructions can now make fp_to_bf16 legal
 - The software conversion to bf16 can be replaced by a trivial
   implementation under fast math.

Differential Revision: https://reviews.llvm.org/D126953
2022-06-15 12:56:31 +02:00
Petr Hosek 7524fe962e [libFuzzer] Use the compiler to link the relocatable object
Rather than invoking the linker directly, let the compiler driver
handle it. This ensures that we use the correct linker in the case
of cross-compiling.

Differential Revision: https://reviews.llvm.org/D127828
2022-06-15 07:16:40 +00:00
Petr Hosek 18a1fc8459 [CMake][compiler-rt] Provide a dedicated option for LLVM unwinder
This allows configuring LLVM unwinder separately from the C++ library
matching how we configure it in libcxx.

This also applies changes made to libunwind+libcxxabi+libcxx in D113253
to compiler-rt.

Differential Revision: https://reviews.llvm.org/D115674
2022-06-14 17:26:25 +00:00
Mariusz Borsa a4bf361454 Revert "[Sanitizers] Cleanup handling of stat64/statfs64"
This reverts commit 6d890a0fb8.
2022-06-10 10:56:26 -07:00
Peter S. Housel 2be5abb7e9 [ORC][ORC_RT] Handle ELF .init_array with non-default priority
ELF-based platforms currently support defining multiple static
initializer table sections with differing priorities, for example
.init_array.0 or .init_array.100; the default .init_array corresponds
to a priority of 65535. When building a shared library or executable,
the system linker normally sorts these sections and combines them into
a single .init_array section. This change adds the capability to
recognize ELF static initializers with priorities other than the
default, and to properly sort them by priority, to Orc and the Orc
runtime.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D127056
2022-06-09 22:47:58 -07:00
Peter S. Housel 1aa71f8679 [ORC][ORC_RT] Integrate ORC platforms with LLJIT and lli
This change enables integrating orc::LLJIT with the ORCv2
platforms (MachOPlatform and ELFNixPlatform) and the compiler-rt orc
runtime. Changes include:

- Adding SPS wrapper functions for the orc runtime's dlfcn emulation
  functions, allowing initialization and deinitialization to be invoked
  by LLJIT.

- Changing the LLJIT code generation default to add UseInitArray so
  that .init_array constructors are generated for ELF platforms.

- Integrating the ORCv2 Platforms into lli, and adding a
  PlatformSupport implementation to the LLJIT instance used by lli which
  implements initialization and deinitialization by calling the new
  wrapper functions in the runtime.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D126492
2022-06-09 22:47:58 -07:00
Mariusz Borsa 6d890a0fb8 [Sanitizers] Cleanup handling of stat64/statfs64
There are differences in handling of stat64/statfs64 calls by sanitizers between Linux and macOS. Versions of macOS starting with 10.6 drop the stat64/statfs64 APIs completely, relying on the linker to redirect stat/statfs to the appropriate 64 bit versions. Emitting variables needed by sanitizers is thus controlled by convoluted sets of conditions, involving Linux, IOS, macOS and Android, sprinkled around files.

This change adresses it, allowing to specify presence/absence of stat64/statfs64 for each platform, in a single location. Also, it adresses the Android case which handles stat64, but not statfs64.

Adding Vitaly as a reviewer since he seems to be actively working on sanitizers, perhaps can comment on the Android bit

Differential Revision: https://reviews.llvm.org/D127343
2022-06-09 12:51:34 -07:00
David Carlier a4c97e1937 [Sanitizers] prctl interception update for the PR_SET_VMA option case.
Supports on Android but also from Linux 5.17

Reviewers: vitalybuka, eugenis

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D127326
2022-06-09 06:07:26 +01:00
Andrew Turner ccae01cbce [compiler-rt] Fix Mmap on FreeBSD AArch64
On FreeBSD AArch64 safestack needs to use __syscall to handle 64 bit arguments

Reviewed by: MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D125901
2022-06-08 17:22:33 -04:00
Andrew Turner ad3faddaa6 [compiler-rt] Fix the longjmp sp slot on FreeBSD AArch64
The stack pointer is stored in the second slot in the jump buffer on
AArch64. Use the correct slot value to read this rather than the
following register.

Reviewed by: melver

Differential Revision: https://reviews.llvm.org/D125762
2022-06-08 17:22:27 -04:00
Andrew Turner b3c1442c6c [compiler-rt] Add the FreeBSD AArch64 shadow offset
As with 64 bit x86 use an offset in middle of the address space scaled up
to work with the full 48 bit space.

Reviewed by: MaskRay

Differential Revision: https://reviews.llvm.org/D125757
2022-06-08 17:22:16 -04:00
Andrew Turner 9496e39b4a [compiler-rt] Add the common FreeBSD AArch64 support
Reviewed by: vitalybuka

Differential Revision: https://reviews.llvm.org/D125756
2022-06-08 17:22:01 -04:00
Leonard Chan 060907dd00 Revert "Reland "[NFC][compiler-rt][asan] Unify asan and lsan allocator settings""
This reverts commit b37d84aa8d.

This broke aarch64 asan builders for fuchsia. I accidentally changed the allocator
settings for fuchsia on aarch64 because the new asan allocator settings use:

```
// AArch64/SANITIZER_CAN_USE_ALLOCATOR64 is only for 42-bit VMA
// so no need to different values for different VMA.
const uptr kAllocatorSpace =  0x10000000000ULL;
const uptr kAllocatorSize  =  0x10000000000ULL;  // 3T.
typedef DefaultSizeClassMap SizeClassMap;
```

rather than reaching the final `#else` which would use fuchsia's lsan config.
2022-06-08 11:56:33 -07:00
Leonard Chan 033af5a537 [compiler-rt][hwasan] Check address tagging mode in InitializeOsSupport on Fuchsia
Differential Revision: https://reviews.llvm.org/D127262
2022-06-08 11:34:50 -07:00
Nikita Popov 38ad963cc9 [sanitizer] Fix shift UB in LEB128 test
If u64 and uptr have the same size, then this will perform a shift
by the bitwidth, which is UB. We only need this code if uptr is
smaller than u64.
2022-06-08 14:21:25 +02:00