Commit Graph

12066 Commits

Author SHA1 Message Date
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
David CARLIER c06ef17359 [Sanitizers] intercept FreeBSD procctl
Reviewers: vitalybuka, emaster

Reviewed-By: viatelybuka

Differential Revision: https://reviews.llvm.org/D127069
2022-06-08 08:55:10 +01:00
Leonard Chan b37d84aa8d Reland "[NFC][compiler-rt][asan] Unify asan and lsan allocator settings"
I believe this should've been fixed with 4b15e665f8
which landed after this initial patch, but I reverted too early before I
saw the builder turn green again.
2022-06-07 18:09:48 -07:00
Kevin Athey 67069e1980 [MSAN] exclude android from pthread_getaffinity_np interceptor
Depends on https://reviews.llvm.org/D127185.

Differential Revision: https://reviews.llvm.org/D127264
2022-06-07 17:53:32 -07:00
Leonard Chan 13eb4fc3ce Revert "[NFC][compiler-rt][asan] Unify asan and lsan allocator settings"
This reverts commit dd045ddffc.

This broke the sanitizer-windows builder at https://lab.llvm.org/buildbot/#/builders/127/builds/30751.
2022-06-07 17:34:29 -07:00
Leonard Chan 4b15e665f8 [compiler-rt][lsan] Choose lsan allocator via SANITIZER_CAN_USE_ALLOCATOR64
Rather than checking a bunch of individual platforms.

Differential Revision: https://reviews.llvm.org/D126825
2022-06-07 17:23:38 -07:00
Leonard Chan dd045ddffc [NFC][compiler-rt][asan] Unify asan and lsan allocator settings
This updates existing asan allocator settings to use the same allocator settings as what lsan uses for platforms where they already match.

Differential Revision: https://reviews.llvm.org/D126927
2022-06-07 17:21:19 -07:00
Leonard Chan e1d84c421d [compiler-rt][sanitizer] Have all OOM-related error messages start with the same format
This way downstream tools that read sanitizer output can differentiate between OOM errors
reported by sanitizers from other sanitizer errors.

Changes:

- Introduce ErrorIsOOM for checking if a platform-specific error code from an "mmap" is an OOM err.
- Add ReportOOMError which just prepends this error message to the start of a Report call.
- Replace some Reports for OOMs with calls to ReportOOMError.
- Update necessary tests.

Differential Revision: https://reviews.llvm.org/D127161
2022-06-07 16:46:01 -07:00
Lang Hames 5368c685d9 [ORC-RT] Remove a stale comment. 2022-06-07 16:42:37 -07:00
Kevin Athey 828c94c0f6 [MSAN] Add interceptor for pthread_getaffinity_np.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D127185
2022-06-07 16:27:44 -07:00
Paul Kirth acfeb1a6c2 [compiler-rt] Avoid truncating Symbolizer output
Repalce the fixed buffer in SymbolizerProcess with InternalScopedString,
and simply append to it when reading data.

Fixes #55460

Reviewed By: vitalybuka, leonardchan

Differential Revision: https://reviews.llvm.org/D126580
2022-06-07 21:50:39 +00:00
Arthur Eubanks f9ac557567 [NFC] Properly suppress unused argument warning in __isOSVersionAtLeast()
Casting to non-void causes
  expression result unused [-Wunused-value]
2022-06-06 19:41:26 -07:00
Martin Storsjö 03c19f41a2 [builtins] Check __SEH__, when checking if ARM EHABI is implied
ARM EHABI isn't signalled by any specific compiler builtin define,
but is implied by the lack of defines specifying any other
exception handling mechanism, `__USING_SJLJ_EXCEPTIONS__` or
`__ARM_DWARF_EH__`.

As Windows SEH also can be used for unwinding, check for the
`__SEH__` define too, in the same way.

This is the same change as 4a3722a2c3 /
D126866, applied on the compiler-rt builtins gcc_personality_v0
function.

Differential Revision: https://reviews.llvm.org/D126863
2022-06-06 23:23:08 +03:00
Kevin Athey 1a729bce86 [MSAN] add dn_expand intercept.
This interceptor only addresses writes to inputs.  Reads of inputs are not checked.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D126851
2022-06-03 09:49:42 -07:00
Andrew Browne 31d12df3b9 [DFSan] Remove deprecated flag from build-libc-list.py
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D126429
2022-06-01 11:00:13 -07:00
Fangrui Song 241e645036 ar_to_bc.sh: Ignore non-bitcode files in archives
The script uses llvm-link to link LLVM bitcode files.
5426da8ffa used -DLLVM_DISABLE_ASSEMBLY_FILES=ON
to ignore object files compiled from lib/Support/BLAKE3/*.S.

A better approach (which fits Bazel better) is to ignore non-bitcode files.

Reviewed By: akyrtzi

Differential Revision: https://reviews.llvm.org/D126728
2022-06-01 10:28:14 -07:00
Nico Weber be223eb541 sanitizers: Do not include crypt.h if SANITIZER_INTERCEPT_CRYPT_R is undef
sanitizer_intercept_overriders.h might override SANITIZER_INTERCEPT_CRYPT_R to
be undefined. There's no need to require crypt.h in that case.

(The motivation is that crypt() moved from glibc into its own package at some
point, which makes intercepting it and building with a single sysroot that
supports both pre-bullseye and post-bullseye a bit hairy.)

Differential Revision: https://reviews.llvm.org/D126696
2022-06-01 13:27:06 -04:00
Brooks Davis 18efa420da compiler-rt: Allow build without __c11_atomic_fetch_nand
Don't build atomic fetch nand libcall functions when the required
compiler builtin isn't available. Without this compiler-rt can't be
built with LLVM 13 or earlier.

Not building the libcall functions isn't optimal, but aligns with the
usecase in FreeBSD where compiler-rt from LLVM 14 is built with an LLVM
13 clang and no LLVM 14 clang is built.

Reviewed By:	efriedma

Differential Revision:	https://reviews.llvm.org/D126710
2022-06-01 12:58:30 -04:00
Andrew Ng e06a81d810 [LSAN] Fix up LSAN weak symbols for Windows
Differential Revision: https://reviews.llvm.org/D126703
2022-06-01 10:18:51 +01:00
Mariusz Borsa e2adffc39c [Sanitizers][Darwin] Deprecate SANITIZER_MAC - fail compilation if encountered
Previous couple commits replaced SANITIZER_MAC with SANITIZER_APPLE in bulk.
This change will prompt anyone still trying to use SANITIZER_MAC to rename.

Differential Revision: https://reviews.llvm.org/D126577
2022-05-31 18:08:59 -07:00
Andrew Browne 15d5db276c [DFSan] build-libc-list.py no longer provides a list of default files.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D126430
2022-05-31 11:25:56 -07:00
Alex Brachet 7df55e5ed7 [scudo] Ensure pointer is not null
Differential revision: https://reviews.llvm.org/D126499
2022-05-31 17:16:49 +00:00
Alex Brachet 35a032eaf4 [InstrProf] Stop exporting lprofDirMode
This symbol should not be exposed and doesn't need to be.

Differential revision: https://reviews.llvm.org/D126548
2022-05-31 17:13:00 +00:00
Keno Fischer 167fb106d2 compiler-rt/cpu_model: Ensure constructor priority is set and align with GCC
GCC recently started setting constructor priority on init_have_lse_atomics [1]
to avoid undefined initialization order with respect to other initializers,
causing accidental use of ll/sc intrinsics on targets where this was not
intended (which presents a minor performance problem as well as a
compatibility problem for users wanting to use the rr debugger). I initially
thought compiler-rt does not have the same issue as libgcc, since it looks
like we're already setting init priority on the constructor.

Unfortuantely, it does not appear that the HAVE_INIT_PRIORITY check is ever
performed anyway, so despite appearances the init priority was not actually
applied. Fix that by applying the init priority unconditionally. It has been
supported in clang ever since it was first introduced and in any case for
more than 14 years in both gcc and clang. MSVC is already excluded from this
code path and we're already using constructors with init priority elsewhere
in compiler-rt without additional check (though mostly in the sanitizer
runtime, which may have more narrow target support). Regardless, I believe
that for our supported compilers, if they support the constructor attribute,
they should also support init priorities.

While we're here, change the init priority from 101, which is the highest
priority for end user applications, to instead use one of the priority levels
reserved for implementations (1-100; lower integers are higher priority).
GCC ended up using `90`, so this commit aligns the value in compiler-rt
to the same value to ensure that there are no subtle initialization order
differences between libgcc and compiler-rt.

[1] 75c4e4909a

Differential Revision: https://reviews.llvm.org/D126424
2022-05-30 20:31:49 +00:00
Pierre Gousseau 4278b7e16a [sanitizers] Fixes strndup API behaviour when intercepted by sanitizers
Sanitizers ignore flag allocator_may_return_null=1 in strndup() calls.
When OOM is emulated, this causes to the unexpected crash.

Committed by pgousseau on behalf of "Kostyantyn Melnik, kmnls.kmnls@gmail.com"

Reviewed by: pgousseau

Differential Revision: https://reviews.llvm.org/D126452
2022-05-30 17:00:10 +01:00
Roland McGrath a27b9139ab [scudo] Clean up Zircon header file uses
Make fuchsia.h and fuchsia.cpp each include what they use.
2022-05-27 21:39:03 -07:00
John Paul Adrian Glaubitz a1ec3c5a88 [scudo] Link against libatomic on all MIPS targets
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D126418
2022-05-26 00:00:16 -07:00
Andrew Browne b2b0322a81 [DFSan] Add option to specify individual library files, and an option to exit with an error code if any library file was not found.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D126336
2022-05-24 16:15:46 -07:00
Mariusz Borsa 8246b2e156 [Sanitizers][Darwin] Replace SANITIZER_MAC with SANITIZER_APPLE in source files
This is a follow up to [Sanitizers][Darwin] Rename Apple macro SANITIZER_MAC -> SANITIZER_APPLE (D125816)

Performed a global search/replace as in title against LLVM sources

Differential Revision: https://reviews.llvm.org/D126263
2022-05-24 12:59:27 -07:00
Leonard Chan 6edbdf80ca Revert "[compiler-rt][scudo] Add missing preprocessor token" and "[compiler-rt][scudo] Simplify TBI checks"
This reverts commit 676eaa2ca9
and f6038cdca0 since builders are still
broken.
2022-05-24 11:30:31 -07:00
Leonard Chan 676eaa2ca9 [compiler-rt][scudo] Add missing preprocessor token
This should fix build errors seen on bots like
https://lab.llvm.org/buildbot/#/builders/57/builds/18263.
2022-05-24 11:12:30 -07:00
Leonard Chan f6038cdca0 [compiler-rt][scudo] Simplify TBI checks
Differential Revision: https://reviews.llvm.org/D111080
2022-05-24 10:53:09 -07:00
Leonard Chan c8644ea88e [compiler-rt][lsan] Update CanBeAHeapPointer for AArch64
While attempting to get the 64-bit lsan allocator working for Fuchsia, I
noticed this function would incorrectly return false for pointers returned
by the 64-bit allocator. On AArch64, this function attempts to get the VMA
size dynamically by counting the number of leading zeros from the function
frame address. This will fail if the frame address is significantly below an
allocated pointer (that is, the frame address has more leading zeros than an
allocated pointer). This is possible on Fuchsia and linux (when not called
from the initial thread stack).

It seems the intended use of this function is to speed up pointer scanning by
filtering out addresses that user code might not be able to access. Other
platforms this check is done on seem to hardcode the VMA size/shift, so it
seems appropriate to do this for aarch64 as well. This implies pointers on
aarch64 where the VMA size is <64 will pass through, but bad pointers will
still be caught by subsequent scan checks.

This patch also renames the function to something more fitting of what it's
trying to do.

Differential Revision: https://reviews.llvm.org/D123814
2022-05-24 10:22:46 -07:00
Julian Lettner 1962389979 [Sanitizer][Darwin] Add explanation for Apple platform macros
Differential Revision: https://reviews.llvm.org/D126229
2022-05-23 11:59:44 -07:00
Julian Lettner 806e8a1c8e [Sanitizer][Darwin] Add SANITIZER_DRIVERKIT platform macro 2022-05-23 11:21:45 -07:00
Julian Lettner ec563c5a90 [ASan] Add sleep_before_init flag
Also do a little bit of refactoring instead of just copy&paste.

Differential Revision: https://reviews.llvm.org/D126037
2022-05-19 20:41:43 -07:00
Mariusz Borsa 77014b9a13 [Sanitizers][Darwin] Rename Apple macro SANITIZER_MAC -> SANITIZER_APPLE
Initial introduction of the new macro before obsoleting the old one - the old name was really confusing.
Also moved SANITIZER_WATCHOS and SANITIZER_TVOS definitions under common #if defined(__APPLE__) block

Differential Revision: https://reviews.llvm.org/D125816
2022-05-18 14:46:41 -07:00
Mitch Phillips f9a3c43eaa [NFCI] clang-format gwp-asan files. 2022-05-18 14:10:44 -07:00
Mitch Phillips e831ea6912 [NFCI] clang-format scudo standalone 2022-05-18 14:04:04 -07:00
Eli Friedman dd20323f51 [compiler-rt builtins] Assert that atomic.c can be compiled correctly.
The spinlock requires that lock-free operations are available;
otherwise, the implementation just calls itself. As discussed in
D120026.

Differential Revision: https://reviews.llvm.org/D123080
2022-05-16 14:40:57 -07:00
John Paul Adrian Glaubitz d4aacc1a01 [sanitizer] Don't use newfstatat for Linux on SPARC
Linux on SPARC uses fstatat64 instead.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D125572
2022-05-16 12:21:55 -07:00
Timm Bäder 791e0d1bc8 [compiler-rt] Add NO_EXEC_STACK_DIRECTIVE on s390x
Differential Revision: https://reviews.llvm.org/D125454
2022-05-13 07:57:10 +02:00
Blue Gaston 9145cb8b7c [Sanitizers][Darwin] Add READ/WRITE detection on arm64 for darwin.
On arm64 the read/write flag is set on the esr register.
	Adding this flag check for arm64 enables a more accurate
	print out for sanitizer signal reports and matches the
	behavior on x86.

	Fixes bug: https://bugs.llvm.org/show_bug.cgi?id=27543 https://github.com/google/sanitizers/issues/653

	These tests are now passing:
		SanitizerCommon-asan-arm64-Darwin :: Posix/illegal_read_test.cpp
		SanitizerCommon-asan-arm64-Darwin :: Posix/illegal_write_test.cpp
		SanitizerCommon-asan-arm64e-Darwin :: Posix/illegal_read_test.cpp
  		SanitizerCommon-asan-arm64e-Darwin :: Posix/illegal_write_test.cpp
  		SanitizerCommon-tsan-arm64-Darwin :: Posix/illegal_read_test.cpp
  		SanitizerCommon-tsan-arm64-Darwin :: Posix/illegal_write_test.cpp
  		SanitizerCommon-tsan-arm64e-Darwin :: Posix/illegal_read_test.cpp
  		SanitizerCommon-tsan-arm64e-Darwin :: Posix/illegal_write_test.cpp
  		SanitizerCommon-ubsan-arm64-Darwin :: Posix/illegal_read_test.cpp
  		SanitizerCommon-ubsan-arm64-Darwin :: Posix/illegal_write_test.cpp
  		SanitizerCommon-ubsan-arm64e-Darwin :: Posix/illegal_read_test.cpp
  		SanitizerCommon-ubsan-arm64e-Darwin :: Posix/illegal_write_test.cpp

rdar://92104440

Differential Revision: https://reviews.llvm.org/D125416
2022-05-12 10:51:49 -07:00
Florian Mayer de67bc8edb [HWASan symbolize] Write error to stderr. 2022-05-10 17:00:57 -07:00
Florian Mayer be17d18ae8 [HWASan] deflake hwasan_symbolize test more.
Don't fail on corrupted ELF file on indexing. This happens because files
change in the directory from concurrent tests.
2022-05-10 16:57:44 -07:00
Florian Mayer b77d16f7f3 [HWASan] deflake hwasan_symbolize test
Also enable on X86_64.

The directory would change during the test execution. This should not
necessarily prevent us from indexing a directory (a user might
potentially do that if they specify a parent directory of the actual
symbols directory, and change unrelated files).

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D125143
2022-05-09 14:11:52 -07:00
Florian Mayer 68cd47e0ca [HWASan] Clean up hwasan_symbolize.
The globals are better expressed as members of the Symbolizer, and all
functions operating on it should be methods instead.

Also using the standard idiom of wrapping the main code in
`if __name__ == '__main__'`.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D125032
2022-05-06 15:45:53 -07:00
Florian Mayer d8564dcbcf [HWASan] Allow to linkify symbolizer output.
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D124950
2022-05-06 15:44:14 -07:00
Peter S. Housel 981523b2e4 [ORC-RT][ORC] Handle dynamic unwind registration for libunwind
This changes the ELFNix platform Orc runtime to use, when available,
the __unw_add_dynamic_eh_frame_section interface provided by libunwind
for registering .eh_frame sections loaded by JITLink. When libunwind
is not being used for unwinding, the ELFNix platform detects this and
defaults to the __register_frame interface provided by libgcc_s.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D114961
2022-05-06 14:00:29 -07:00
Nico Weber c9faea04b1 Revert "[HWASan] Allow to linkify symbolizer output."
This reverts commit 4af9392e13.
The new test fails on several machines (including some bots),
see https://reviews.llvm.org/D124950
2022-05-06 09:53:45 -04:00
Nico Weber f3d31c7f81 Revert "[HWASan] Clean up hwasan_symbolize."
This reverts commit 6ca1df61d2.
Prerequisite for reverting 4af9392e13.
2022-05-06 09:53:45 -04:00
Ben Shi 3902ebdd57 [compiler-rt][builtins] Fix wrong ABI of AVR __mulqi3 & __mulhi3
Reviewed By: aykevl, dylanmckay

Differential Revision: https://reviews.llvm.org/D125077
2022-05-06 13:46:49 +00:00
Florian Mayer 6ca1df61d2 [HWASan] Clean up hwasan_symbolize.
The globals are better expressed as members of the Symbolizer, and all
functions operating on it should be methods instead.

Also using the standard idiom of wrapping the main code in
`if __name__ == '__main__'`.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D125032
2022-05-05 16:41:11 -07:00
Florian Mayer 4af9392e13 [HWASan] Allow to linkify symbolizer output.
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D124950
2022-05-05 16:40:09 -07:00
Ben Shi 70a66c08fc [compiler-rt][builtins] Add helper functions for uint16/sint16/uint8/sint8 div and mod
__udivmodhi4 : uint16 div and mod
__udivmodqi4 : uint8 div and mod
__divmodhi4  : sint16 div and mod
__divmodqi4  : sint8 div and mod

The above helper functions in libgcc have special ABI as described at
https://gcc.gnu.org/wiki/avr-gcc#Exceptions_to_the_Calling_Convention .

Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D124600
2022-05-05 23:29:14 +00:00
H.J. Lu b226894d47 [sanitizer] Correct GetTls for x32
Since x32 pointer size is 4 bytes, the self pointer offset in TCB:

struct
{
  void *tcb;
  dtv_t *dtv;
  void *self;
  ...

should be 8, not 16.

Fixes https://github.com/llvm/llvm-project/issues/55288

Differential Revision: https://reviews.llvm.org/D125025
2022-05-05 13:55:19 -07:00
Tobias Burnus 6f095babc2 sanitizer_common: Define FP_XSTATE_MAGIC1 for old glibc
D116208 (commit 1298273e82) added FP_XSTATE_MAGIC1.
However, when building with glibc < 2.16 for backward-dependency
compatibility, it is not defined - and the build breaks.

Note: The define comes from Linux's asm/sigcontext.h but the
file uses signal.h which includes glibc's bits/sigcontext.h - which
is synced from the kernel's file but lags behind.

Solution: For backward compatility with ancient systems, define
FP_XSTATE_MAGIC1 if undefined.

//For the old systems, we were building with Linux kernel 3.19 but to support really old glibc systems, we build with a sysroot of glibc 2.12. While our kernel (and the users' kernels) have FP_XSTATE_MAGIC1, glibc 2.12 is too old. – With this patch, building the sanitizer libs works again. This showed up for us today as GCC mainline/13 has now synced the sanitizer libs.//

Reviewed By: #sanitizers, vitalybuka

Differential Revision: https://reviews.llvm.org/D124927
2022-05-05 11:05:27 +01:00
Wael Yehia 2407c13aa4 [AIX][PGO] Enable linux style PGO on AIX
This patch switches the PGO implementation on AIX from using the runtime
registration-based section tracking to the __start_SECNAME/__stop_SECNAME
based. In order to enable the recognition of __start_SECNAME/__stop_SECNAME
symbols in the AIX linker, the -bdbg:namedsects:ss needs to be used.

Reviewed By: jsji, MaskRay, davidxl

Differential Revision: https://reviews.llvm.org/D124857
2022-05-05 04:10:39 +00:00
Ayke van Laethem 514371c370
[compiler-rt][AVR] Fix avr_SOURCES CMake variable
D123200 did not include the generic sources, which means that only the
AVR-specific sources were compiled. With this change, generic sources
are included as expected.

Tested with the following commands:

    cmake -G Ninja -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=avr -DCOMPILER_RT_BAREMETAL_BUILD=1 -DCMAKE_C_COMPILER=clang-14 -DCMAKE_C_FLAGS="--target=avr -mmcu=avr5 -nostdlibinc -mdouble=64" ../path/to/builtins

    ninja

Differential Revision: https://reviews.llvm.org/D124969
2022-05-05 02:29:04 +02:00
H.J. Lu f52e365092 [sanitizer] Use newfstatat for x32
Since newfstatat is supported on x32, use it for x32.

Differential Revision: https://reviews.llvm.org/D124968
2022-05-04 15:54:42 -07:00
Ayke van Laethem c1d6dca694
[compiler-rt][AVR] Use correct return value for __ledf2 etc
Previously the default was long, which is 32-bit on AVR. But avr-gcc
expects a smaller value: it reads the return value from r24.

This is actually a regression from https://reviews.llvm.org/D98205.
Before D98205, the return value was an enum (which was 2 bytes in size)
which was compatible with the 1-byte return value that avr-gcc was
expecting. But long is 4 bytes and thus places the significant return
value in a different register.

Differential Revision: https://reviews.llvm.org/D124939
2022-05-04 22:51:39 +02:00
Florian Mayer 1b2704f935 [HWASan] cleanup imports in hwasan_symbolize. 2022-05-04 11:22:36 -07:00
Martin Liska f1b9245199 tsan: fix GCC warnings
Fixes:

tsan/tsan_shadow.h:93:32: warning: enumerated and non-enumerated type in conditional expression [-Wextra]
tsan/tsan_shadow.h:94:44: warning: enumerated and non-enumerated type in conditional expression [-Wextra]

Differential Revision: https://reviews.llvm.org/D124828
2022-05-04 10:22:03 +02:00
Yuanfang Chen a61c8e1ebd tsan: for unittests, change to use test fixtures to clear racy stacks
After cd0a5889d7, unittest would run in shard mode where many tests
share a single process. Need to clear some global state to make the test
results stable.

Reviewed By: thetruestblue, rsundahl

Differential Revision: https://reviews.llvm.org/D124591
2022-05-03 10:18:00 -07:00
Martin Liska 903b8845fb sanitizer: Fix fallthrough detection.
First check for clang::fallthrough attribute that resolves:

sanitizer_stack_store.cpp:258:7: error: use of the 'fallthrough'
attribute is a C++17 extension [-Werror,-Wc++17-attribute-extensions]
2022-05-03 13:55:28 +02:00
Martin Liska 0a1bcab9f3 tsan: fix deadlock in libbacktrace
Fixes deadlock seen in GCC.

Fixes: #55226

Differential Revision: https://reviews.llvm.org/D124838
2022-05-03 12:51:20 +02:00
Martin Liska f496a0eba4 sanitizer: use pragma clang conditionally
Use the pragma only when __clang__ is defined.

Fixes:
sanitizer_common_libcdep.cpp:101: warning: ignoring ‘#pragma clang diagnostic’ [-Wunknown-pragmas]

Differential Revision: https://reviews.llvm.org/D124829
2022-05-03 11:34:30 +02:00
Martin Liska bc8e601257 sanitizer: support GCC's fallthrough attribute
Fixes:
sanitizer_stack_store.cpp:257:13: warning: this statement may fall through [-Wimplicit-fallthrough=]

when being built with GCC.

Differential Revision: https://reviews.llvm.org/D124832
2022-05-03 11:30:13 +02:00
Vitaly Buka eeccdd318d Revert "tsan: model atomic read for failing CAS"
https://lab.llvm.org/buildbot/#/builders/70/builds/21206 hangs.

This reverts commit 2fec52a402.
2022-05-02 22:26:56 -07:00
Evgenii Stepanov 696092c703 [sanitizer] Use canonical syscalls everywhere
These "new" syscalls have been added in 2.6.16, more than 16 years ago.
Surely that's enough time to migrate. Glibc 2.33 is using them on both
i386 and x86_64. Android has an selinux filter to block the legacy
syscalls in the apps.

Differential Revision: https://reviews.llvm.org/D124212
2022-05-02 13:54:01 -07:00
Dmitry Vyukov 2fec52a402 tsan: model atomic read for failing CAS
See the added test and https://github.com/google/sanitizers/issues/1520
for the description of the problem.
The standard says that failing CAS is a memory load only,
model it as such to avoid false positives.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D124507
2022-05-02 12:57:56 +02:00
Ben Shi fb7a435492 [compiler-rt][builtins] Add several helper functions for AVR
__mulqi3 : int8 multiplication
__mulhi3 : int16 multiplication
   _exit : golobal terminator

Reviewed By: MaskRay, aykevl

Differential Revision: https://reviews.llvm.org/D123200
2022-05-02 01:27:46 +00:00
Vitaly Buka 7858219436 [asan] Enable detect_stack_use_after_return=1 by default on Linux
By default -fsanitize=address already compiles with this check, why not use it.
For compatibly it can be disabled with env ASAN_OPTIONS=detect_stack_use_after_return=0.

Reviewed By: eugenis, kda, #sanitizers, hans

Differential Revision: https://reviews.llvm.org/D124057
2022-04-28 21:08:16 -07:00
Dmitry Vyukov 16baf59c6d tsan: avoid false positives related to epoll
An application can use the mere fact of epoll_wait returning an fd
as synchronization with the write on the fd that triggered the notification.
This pattern come up in an internal networking server (b/229276331).

If an fd is added to epoll, setup a link from the fd to the epoll fd
and use it for synchronization as well.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D124518
2022-04-27 16:59:46 +02:00
Vitaly Buka c1e94591bc Revert "[asan] Enable detect_stack_use_after_return=1 by default"
Temporarily revert the option to fix
https://bugs.chromium.org/p/chromium/issues/detail?id=1319387

This reverts option default and documentation of the commit. Test
changes are not being reverted as they are improvement and break
reliance on option defaults.

Additional memory usage is a problem on mobile devices with low memory.
Even heavy thread desktop programs may need some FakeStack tunning.

This reverts commit 4b4437c084.
2022-04-27 00:43:39 -07:00
Martin Storsjö 1692c2fdaa Revert "[compiler-rt] Use C_STANDARD instead of custom logic for adding -std=c11"
This reverts commit 2f251925db.

This was reported to break the Builtins-powerpc64le-linux::qdiv_test.c
test on ppc64le buildbots, e.g. these:

https://lab.llvm.org/buildbot/#/builders/105/builds/24538
https://lab.llvm.org/buildbot/#/builders/121/builds/18755
2022-04-27 00:20:44 +03:00
Martin Storsjö 2f251925db [compiler-rt] Use C_STANDARD instead of custom logic for adding -std=c11
Apply this in add_compiler_rt_runtime instead of manually adding it
to the individual projects. This applies the option on more
parts of compiler-rt than before, but should ideally not make any
difference assuming the other runtimes that lacked the option
also were C11 compatible.

Not marking this as required, to match the existing behaviour (where
`-std=c11` was added only if supported by the compiler).

This was suggested during the review of D110005.

Differential Revision: https://reviews.llvm.org/D124343
2022-04-26 12:36:20 +03:00
Quinn Pham b3e8e43789 [compiler-rt][NFC] Inclusive language: remove use of sanity check/test
from compiler-rt/lib/tsan

[NFC] As part of using inclusive language within the llvm project, this
patch rewords comments to remove sanity check and sanity test.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D124390
2022-04-25 16:13:11 -05:00
Nico Weber 36ba89b5b3 Revert "[sanitizer] Use canonical syscalls everywhere"
This reverts commit 34b676eb60.
Speculative, might have caused test problems on Android.
2022-04-25 08:49:16 -04:00
Vitaly Buka 72e00c45a4 [asan] Don't enable detect_stack_use_after_return on Windows
It's not clear how ready it's there.
2022-04-22 19:10:30 -07:00
Vitaly Buka 4b4437c084 [asan] Enable detect_stack_use_after_return=1 by default
By default -fsanitize=address already compiles with this check,
why not use it.
For compatibly it can be disabled with env ASAN_OPTIONS=detect_stack_use_after_return=0.

Reviewed By: eugenis, kda, #sanitizers, hans

Differential Revision: https://reviews.llvm.org/D124057
2022-04-22 15:31:43 -07:00
Evgenii Stepanov 34b676eb60 [sanitizer] Use canonical syscalls everywhere
These "new" syscalls have been added in 2.6.16, more than 16 years ago.
Surely that's enough time to migrate. Glibc 2.33 is using them on both
i386 and x86_64. Android has an selinux filter to block the legacy
syscalls in the apps.

Differential Revision: https://reviews.llvm.org/D124212
2022-04-22 12:08:13 -07:00
Dominic Chen fcbca197f2 [scudo] Disable memory tagging on arm64_32
arm64_32 is an ILP32 platform

Differential Revision: https://reviews.llvm.org/D124135
2022-04-21 17:22:10 -07:00
Roy Sundahl d179627ef0 Fix sanitizer stack traces on aarch64.
Fixes llvm-project/compiler-rt/test/asan/TestCases/null_deref.cpp on
macOS/aarch64.

The bp (base pointer) variable was being loaded from register LR and
not FP on aarch64 (except for this narrow case):
defined(__IPHONE_8_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0

Without a valid bp from the FP register, it is not possible to traverse
previous frames for a complete stack trace. The rationale for fetching
the LR as the bp for all cases except above is not clear but since the
FP register is the canonical register for use as the frame pointer, this
commit removes the restriction above for unconditional use all aarch64.

rdar://91587039

Differential Revision: https://reviews.llvm.org/D124140
2022-04-21 14:27:59 -07:00
Tyler Mandry d8c1d37ba3 [fuchsia] Don't include duplicate profiling symbols for Fuchsia
InstrProfilingPlatformLinux.c already provides these symbols. Linker order
saved us from noticing before.

Reviewed By: mcgrathr

Differential Revision: https://reviews.llvm.org/D124136
2022-04-21 15:44:37 +00:00
Andrew Browne 204c12eef9 [DFSan] Print an error before calling null extern_weak functions, incase dfsan instrumentation optimized out a null check.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D124051
2022-04-19 17:01:41 -07:00
Kirill Stoimenov 64c929ec09 [ASan] Fixed a reporting bug in (load|store)N functions which would print unknown-crash instead of the proper error message when a the data access is unaligned.
Reviewed By: kda, eugenis

Differential Revision: https://reviews.llvm.org/D123643
2022-04-19 15:07:17 +00:00
Kirill Stoimenov 70f13bd752 Revert "[ASan] Fixed a reporting bug in (load|store)N functions which would print unknown-crash instead of the proper error message when a the data access is unaligned."
This reverts commit d81d317999.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D123966
2022-04-18 23:33:41 +00:00
Kirill Stoimenov d81d317999 [ASan] Fixed a reporting bug in (load|store)N functions which would print unknown-crash instead of the proper error message when a the data access is unaligned.
Reviewed By: kda, eugenis

Differential Revision: https://reviews.llvm.org/D123643
2022-04-18 22:46:37 +00:00
Blue Gaston a6efcf1c31 Format fix in recent change. Removed whitespace. [NFC] 2022-04-18 09:23:01 -07:00
Piotr Kubaj 315d792130 [PowerPC] Fix sanitizers build on FreeBSD
1. Add correct pc, sp and bp for FreeBSD.
2. Since there's no personality.h header on FreeBSD, move SANITIZER_PPC64V2
   case below FREEBSD case.
3. __ppc_get_timebase_freq() is glibc-specific. Add a shim for FreeBSD that
   does the same.
2022-04-18 07:16:13 -05:00
Vitaly Buka eb4d22917e [msan] Set poison_in_dtor=1 by default
It's still disabled by default at compile time.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D123875
2022-04-15 14:40:23 -07:00
Brad Smith 8cf83e9659 [VE][compiler-rt] Correct location of VE support in clear_cache function, NFC
Looks like when the VE support was added it was added a few lines below where it should have been.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D123439
2022-04-14 15:50:26 -04:00
Vitaly Buka c36fbe05a7 Revert "[sanitizer] Don't run malloc hooks for stacktraces"
Msan crashes on clang-s390x-linux bot

This reverts commit d3531fc7f0.
2022-04-13 23:52:36 -07:00
Blue Gaston e0c4454465 [Darwin][ASan][Sanitizer] Fixes Sanitizer NonUnique Identifier to Account for Mac arm64 architectures.
Current check assumes iOS as the only Apple devices running arm64.
    ```#if SANITIZER_MAC && !(defined(__arm64__) && SANITIZER_IOS)```
    Stops Apple Silicon from being flagged as requiring unique RTTI.
    This introduced unexpected behavior within the sanitizer.

    rdar://91446703

Differential Revision: https://reviews.llvm.org/D123736
2022-04-13 21:11:37 -07:00
Florian Mayer ffd656a2fe [HWASan] symbolize: use buildid index for locals.
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D123644
2022-04-13 19:09:04 -07:00
Vitaly Buka d3531fc7f0 [sanitizer] Don't run malloc hooks for stacktraces
Usually when we generated stacktraces the process is in error state, so
running hooks may crash the process and prevent meaningfull error report.

Symbolizer, unwinder and pthread are potential source of mallocs.

https://b.corp.google.com/issues/228110771

Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D123566
2022-04-13 16:33:53 -07:00
Vitaly Buka 5d4df59de1 Revert "[sanitizer] Don't run malloc hooks for stacktraces"
Breaks android and iOS bots.
https://green.lab.llvm.org/green/job/clang-san-iossim/5229/consoleFull#711521816a1ca8a51-895e-46c6-af87-ce24fa4cd561
https://lab.llvm.org/buildbot/#/builders/77/builds/16456

This reverts commit 6345d7f2a8.
2022-04-13 13:13:33 -07:00
Vitaly Buka 6345d7f2a8 [sanitizer] Don't run malloc hooks for stacktraces
Usually when we generated stacktraces the process is in error state, so
running hooks may crash the process and prevent meaningfull error report.

Symbolizer, unwinder and pthread are potential source of mallocs.

https://b.corp.google.com/issues/228110771

Reviewed By: kda

Differential Revision: https://reviews.llvm.org/D123566
2022-04-13 11:44:38 -07:00
Nikita Popov 69fcf6a79e Revert "[ubsan] Simplify ubsan_GetStackTrace"
This reverts commit 63f2d1f4d4.

I don't quite understand why, but this causes a linker error for
me and a number of buildbots:

/home/npopov/repos/llvm-project/compiler-rt/lib/ubsan/../sanitizer_common/sanitizer_stacktrace.h:130: error: undefined reference to '__sanitizer::BufferedStackTrace::UnwindImpl(unsigned long, unsigned long, void*, bool, unsigned int)'
2022-04-13 10:41:23 +02:00
Fangrui Song 63f2d1f4d4 [ubsan] Simplify ubsan_GetStackTrace
Suggested by Vitaly Buka
2022-04-13 00:32:10 -07:00
Vitaly Buka 12e137ab24 [NFC][sanitizer] Consolidate malloc hook invocations 2022-04-12 20:08:29 -07:00
Vitaly Buka b84673b3f4 [NFC][sanitizer] Remove unnececary HOOK macros 2022-04-12 19:47:44 -07:00
Vitaly Buka 47a9528fb4 [NFC][msan] Rename SymbolizerScope to UnwinderScope and hide 2022-04-12 18:57:54 -07:00
Vitaly Buka ce1cb9d2c1 [NFC][sanitizer] Clang format some code 2022-04-12 18:45:50 -07:00
Fangrui Song fdd424e37a [ubsan] Fix print_stacktrace=1:fast_unwind_on_fatal=0 to correctly fallback to fast unwinder
ubsan_GetStackTrace (from 52b751088b) called by
~ScopeReport leaves top/bottom zeroes in the
`!WillUseFastUnwind(request_fast_unwind)` code path.
When BufferedStackTrace::Unwind falls back to UnwindFast,
`if (stack_top < 4096) return;` will return early, leaving just one frame in the stack trace.

Fix this by always initializing top/bottom like 261d6e05d5.

Reviewed By: eugenis, yln

Differential Revision: https://reviews.llvm.org/D123562
2022-04-12 11:24:19 -07:00
Vitaly Buka 6ddaf0ee71 [sanitizer] Fix internal_mmap in internal symbolizer 2022-04-12 00:39:04 -07:00
Vitaly Buka d5f8b8b6e9 [sanitizer] Fix typo in test 2022-04-11 21:11:28 -07:00
Vitaly Buka 7d6528fc37 [sanitizer] Update undefined symbols of symbolizer 2022-04-11 18:58:56 -07:00
Vitaly Buka b87b642aa6 [sanitizer] Fix arg types of internal functions
They didn't match sanitizer_common for 32bit.
2022-04-11 17:36:01 -07:00
Florian Mayer a0570e7750 [HWASan] allow symbolizer script to index binaries by build id.
Tested on an example callstack with misplaced binaries from Android.
Tested Regex against callstack without Build ID to confirm it still works.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D123437
2022-04-11 14:12:31 -07:00
Aaron Ballman bdbfaf0ca7 Giving a lot more functions prototypes; NFC
This should address https://lab.llvm.org/buildbot/#/builders/37/builds/12315
and speculatively fix other similar diagnostics.
2022-04-09 17:25:10 -04:00
Aaron Ballman 40ef3e6df6 Add some prototypes to these functions; NFC
This is expected to fix the issues in this build bot:
https://lab.llvm.org/buildbot/#/builders/37/builds/12312
2022-04-09 10:53:48 -04:00
Aaron Ballman 5af1ca841f Add some prototypes to these checks; NFC
This should address a build bot failure:
https://lab.llvm.org/buildbot/#/builders/18/builds/4495
2022-04-09 08:38:29 -04:00
Vitaly Buka e03c350eee [sanitizer] Disable new test on Android to fix a bot 2022-04-09 00:57:48 -07:00
Fangrui Song bbb72122aa [scudo][test] Link with -no-pie to be agnostic of CLANG_DEFAULT_PIE_ON_LINUX
This keeps the test behavior unchanged when CLANG_DEFAULT_PIE_ON_LINUX switches
to ON by default.

Note: current clang --target=mips64el-linux-gnu -fpie -pie -fuse-ld=lld
does not link with C++ exceptions, using -pie would lead to

```
ld.lld: error: cannot preempt symbol: DW.ref.__gxx_personality_v0
...
ld.lld: error: relocation R_MIPS_64 cannot be used against local symbol; recompile with -fPIC
...
```

when linking `ScudoUnitTests`: https://lab.llvm.org/buildbot/#/builders/169/builds/7311/steps/18/logs/stdio
2022-04-08 23:30:07 -07:00
Kevin Athey e9c8d0ff71 [MSAN] add __b64_pton and __b64_ntop intercepts
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D122849
2022-04-08 15:22:37 -07:00
Fangrui Song 2aa575fd7f Revert D120327 "compiler-rt: Add udivmodei5 to builtins and add bitint library"
It has several problems like not-compilable weak attribute with MSVC
(and the usage needs further scrutiny), and " different types for formal and actual parameter"
https://lab.llvm.org/buildbot/#/builders/127/builds/27760/steps/7/logs/stdio

This reverts commit 8843245ddd, 492c5c05e1, bf2dc4b376.
2022-04-08 12:39:42 -07:00
Matthias Gehre 492c5c05e1 compiler-rt/lib/builtins/udivmodei5.c: Fix missing macro argument 2022-04-08 10:55:35 +01:00
Matthias Gehre bf2dc4b376 compiler-rt: Add udivmodei5 to builtins and add bitint library
According to the RFC [0], this review contains the compiler-rt parts of large integer divison for _BitInt.

It adds the functions
```
/// Computes the unsigned division of a / b for two large integers
/// composed of n significant words.
/// Writes the quotient to quo and the remainder to rem.
///
/// \param quo The quotient represented by n words. Must be non-null.
/// \param rem The remainder represented by n words. Must be non-null.
/// \param a The dividend represented by n + 1 words. Must be non-null.
/// \param b The divisor represented by n words. Must be non-null.

/// \note The word order is in host endianness.
/// \note Might modify a and b.
/// \note The storage of 'a' needs to hold n + 1 elements because some
///       implementations need extra scratch space in the most significant word.
///       The value of that word is ignored.
COMPILER_RT_ABI void __udivmodei5(su_int *quo, su_int *rem, su_int *a,
                                  su_int *b, unsigned int n);

/// Computes the signed division of a / b.
/// See __udivmodei5 for details.
COMPILER_RT_ABI void __divmodei5(su_int *quo, su_int *rem, su_int *a, su_int *b,
                                 unsigned int words);
```
into builtins.
In addition it introduces a new "bitint" library containing only those new functions,
which is meant as a way to provide those when using libgcc as runtime.

[0] https://discourse.llvm.org/t/rfc-add-support-for-division-of-large-bitint-builtins-selectiondag-globalisel-clang/60329

Differential Revision: https://reviews.llvm.org/D120327
2022-04-08 07:43:15 +01:00
Michael Forney 795b07f549 [asan] Always skip first object from dl_iterate_phdr
All platforms return the main executable as the first dl_phdr_info.
FreeBSD, NetBSD, Solaris, and Linux-musl place the executable name
in the dlpi_name field of this entry. It appears that only Linux-glibc
uses the empty string.

To make this work generically on all platforms, unconditionally
skip the first object (like is currently done for FreeBSD and NetBSD).
This fixes first DSO detection on Linux-musl. It also would likely
fix detection on Solaris/Illumos if it were to gain PIE support
(since dlpi_addr would not be NULL).

Additionally, only skip the Linux VDSO on linux.

Finally, use the empty string as the "seen first dl_phdr_info"
marker rather than (char *)-1. If there was no other object, we
would try to dereference it for a string comparison.

Reviewed By: MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D119515
2022-04-07 22:35:24 -07:00
Kevin Athey 0713053e4a [MSAN] extend prctl interceptor to support PR_SCHED_CORE
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D122851
2022-04-07 16:49:25 -07:00
Pengxuan Zheng 1c9415806b [compiler-rt][builtins] Move DMB definition to syn-ops.h
Compiler-rt cross-compile for ARMv5 fails because D99282 made it an error if DMB
is used for any pre-ARMv6 targets. More specifically, the "#error only supported
on ARMv6+" added in D99282 will cause compilation to fail when any source file
which includes assembly.h are compiled for pre-ARMv6 targets. Since the only
place where DMB is used is syn-ops.h (which is only included by
arm/sync_fetch_and_* and these files are excluded from being built for older
targets), this patch moves the definition there to avoid the issues described
above.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D123105
2022-04-07 14:57:41 -07:00
Blue Gaston fc4c872d8f [Darwin][ASan] Fix "interceptor working?" check for DriverKit platform
The previous check for interceptors used `pthread_create()` which is not
available on DriverKit.  We need an intercepted symbol that satisfies
the following constraints:

- Symbol is available in DriverKit
- Symbol is provided by simulator runtime dylibs (`dlsym()` fails to
  look up host-provided symbols)

`puts()` satisfies all of the above constraints.

rdar://87895539

Reviewed By: yln

Differential Revision: https://reviews.llvm.org/D123245
2022-04-06 15:49:22 -07:00
Petr Hosek b0e2ffe151 [CMake][compiler-rt] Make CRT separately buildable
This is useful when building a complete toolchain to ensure that CRT
is built after builtins but before the rest of the compiler-rt.

Differential Revision: https://reviews.llvm.org/D120682
2022-04-06 00:48:49 -07:00
Petr Hosek 1558cddedb Revert "[CMake][compiler-rt] Make CRT separately buildable"
This reverts commit b89b18e350 since
it broke the sanitizer bots.
2022-04-06 00:01:06 -07:00
Petr Hosek b89b18e350 [CMake][compiler-rt] Make CRT separately buildable
This is useful when building a complete toolchain to ensure that CRT
is built after builtins but before the rest of the compiler-rt.

Differential Revision: https://reviews.llvm.org/D120682
2022-04-05 22:58:38 -07:00
Alex Brachet 016e59bf2c Revert "[Scudo] enabling anonymous named pages on Linux 5.17 and onwards."
This reverts commit 6194992523.
2022-04-05 16:38:49 +00:00
David Carlier 6194992523 [Scudo] enabling anonymous named pages on Linux 5.17 and onwards.
Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D122962
2022-04-05 09:46:02 +01:00
Dmitry Vyukov ea624e697b sanitizer_common: add Mutex::TryLock
Will be used in future changes.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D122905
2022-04-01 17:56:19 +02:00
Dmitry Vyukov abc51fac09 sanitizer_common: expose max_address from LoadedModule
Currently LoadedModule provides max_executable_address.
Replace it with just max_address.
It's only used for printing for human inspection and since
modules are non-overlapping, max_address is as good as max_executable_address
for matching addresses/PCs against modules (I assume it's used for that).
On the hand, max_address is more general and can used to match e.g. data addresses.
I want to use it for that purpose in future changes.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D122906
2022-04-01 17:56:03 +02:00
Michał Górny fd1da784ac [compiler-rt] [scudo] Use -mcrc32 on x86 when available
Update the hardware CRC32 logic in scudo to support using `-mcrc32`
instead of `-msse4.2`.  The CRC32 intrinsics use the former flag
in the newer compiler versions, e.g. in clang since 12fa608af4.
With these versions of clang, passing `-msse4.2` is insufficient
to enable the instructions and causes build failures when `-march` does
not enable CRC32 implicitly:

    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.cpp:20:10: error: always_inline function '_mm_crc32_u32' requires target feature 'crc32', but would be inlined into function 'computeHardwareCRC32' that is compiled without support for 'crc32'
      return CRC32_INTRINSIC(Crc, Data);
             ^
    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.h:27:27: note: expanded from macro 'CRC32_INTRINSIC'
    #  define CRC32_INTRINSIC FIRST_32_SECOND_64(_mm_crc32_u32, _mm_crc32_u64)
                              ^
    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/../sanitizer_common/sanitizer_platform.h:132:36: note: expanded from macro 'FIRST_32_SECOND_64'
    #  define FIRST_32_SECOND_64(a, b) (a)
                                       ^
    1 error generated.

For backwards compatibility, use `-mcrc32` when available and fall back
to `-msse4.2`.  The `<smmintrin.h>` header remains in use as it still
works and is compatible with GCC, while clang's `<crc32intrin.h>`
is not.

Use __builtin_ia32*() rather than _mm_crc32*() when using `-mcrc32`
to preserve compatibility with GCC.  _mm_crc32*() are aliases
to __builtin_ia32*() in both compilers but GCC requires `-msse4.2`
for the former, while both use `-mcrc32` for the latter.

Originally reported in https://bugs.gentoo.org/835870.

Differential Revision: https://reviews.llvm.org/D122789
2022-04-01 13:00:21 +02:00