Commit Graph

17683 Commits

Author SHA1 Message Date
Florian Mayer
1a4754c8c8
[NFC] turn comment into static_assert (#71504) 2023-11-08 01:23:55 -08:00
Kenny Yu
1146d96096
[TSAN] Add __tsan_check_no_mutexes_held helper (#71568)
This adds a new helper that can be called from application code to
ensure that no mutexes are held on specific code paths. This is useful
for multiple scenarios, including ensuring no locks are held:

- at thread exit
- in peformance-critical code
- when a coroutine is suspended (can cause deadlocks)

See this discourse thread for more discussion:

https://discourse.llvm.org/t/add-threadsanitizer-check-to-prevent-coroutine-suspending-while-holding-a-lock-potential-deadlock/74051

This resubmits and fixes #69372 (was reverted because of build
breakage).
This also includes the followup change #71471 (to fix a land race).
2023-11-08 08:02:14 +01:00
Mitch Phillips
8a220b229e Disable UBSan vptr tests on Android.
Unclear what's going on here. I can reproduce the test failure at
https://lab.llvm.org/buildbot/#/builders/77/builds/31875 and well before
it as well.

Doesn't look like the device has changed, and I can also repro the
problem on Android 11 and Android 14. Disabling until further notice.
2023-11-07 16:34:36 +01:00
Hans Wennborg
27156dd575 Revert "[TSAN] Add __tsan_check_no_mutexes_held helper (#69372)"
The new lit test fails, see comment on the PR. This also reverts
the follow-up commit, see below.

> This adds a new helper that can be called from application code to
> ensure that no mutexes are held on specific code paths. This is useful
> for multiple scenarios, including ensuring no locks are held:
>
> - at thread exit
> - in peformance-critical code
> - when a coroutine is suspended (can cause deadlocks)
>
> See this discourse thread for more discussion:
>
> https://discourse.llvm.org/t/add-threadsanitizer-check-to-prevent-coroutine-suspending-while-holding-a-lock-potential-deadlock/74051

This reverts commit bd841111f3.
This reverts commit 16a395b74d.
2023-11-07 16:08:01 +01:00
Kirill Stoimenov
4d9f3ca77c
[HWASAN] Add memset interceptor (#71244)
Co-authored-by: Vitaly Buka <vitalybuka@google.com>
2023-11-07 00:01:04 -08:00
Charlie Barto
16a395b74d
Add SANITIZER_CDECL to __tsan_check_no_mutexes_held (#71471)
in https://github.com/llvm/llvm-project/pull/69625 @strega-nil added
cdecl to a huge number of sanitizer interface declarations. It looks
like she was racing against @kennyyu adding a tsan interface function. I
noticed this when merging in the latest changes from llvm/main and
corrected it.

Co-authored-by: Charlie Barto <Charles.Barto@microsoft.com>
2023-11-06 17:29:22 -08:00
Christopher Ferris
e15fcd7ba4
[scudo] Use the releaseAndZeroPagesToOS function. (#71256)
All of the code assumes that when the pages are released, the entry is
zero'd, so use the correct function. On most systems, this does not
change anything.
2023-11-06 12:46:37 -08:00
Shoaib Meenai
1ad920f05e [compiler-rt] Pass CMAKE_TOOLCHAIN_FILE through to custom libc++ build
This can be used to configure runtimes builds (instead of setting flags
individually), and we need to pass it down to the custom libc++ build
for it to work correctly.
2023-11-06 11:27:47 -08:00
Heejin Ahn
d859403037
[sanitizer] Fix pthread_exit interceptor's return type (#71253)
`pthread_exit`'s return type is void.
2023-11-05 22:41:37 -08:00
Jonathan Wakely
c670cdb968
[sanitizers] Do not define __has_feature in sanitizer/common_interface_defs.h (#66628)
Public headers intended for user code should not define `__has_feature`,
because this can break preprocessor checks done later in user code, e.g.
if they test `#ifdef __has_feature` to check for real support in the
compiler.

Replace the only use in the public header with a check for it being
supported before trying to use it. Define the fallback definition in the
internal headers, so that other internal sanitizer headers can continue
to use it as preferred.

This resolves a bug reported to GCC as https://gcc.gnu.org/PR109882
2023-11-05 15:22:56 -08:00
Kirill Stoimenov
3cf9bf343d
[HWASAN] Enable memcpy and memmove interceptors (#71217) 2023-11-03 14:17:45 -07:00
Kirill Stoimenov
ddf4a9ce63
[test][HWASAN] Force interceptors tests for memcmp and bcmp call interceptor (#71215) 2023-11-03 13:55:52 -07:00
Ben Langmuir
05a0d94416
[orc][mach-o] Fix mixing objc and swift code in a single JITDylib (#69258)
The system linker merges __objc_imageinfo flags values to select a
compatible set of flags using the minimum swift version and only
erroring on incompatible ABIs. Match that behaviour in the orc macho
platform. One wrinkle is that the JIT can add new objects after the
dylib is running code. In that case we only check for known incompatible
flags and ignore the swift version. It's too late to change the flags at
that point and swift version is unlikely to change runtime behaviour in
practice.
2023-11-03 08:32:08 -07:00
Kenny Yu
bd841111f3
[TSAN] Add __tsan_check_no_mutexes_held helper (#69372)
This adds a new helper that can be called from application code to
ensure that no mutexes are held on specific code paths. This is useful
for multiple scenarios, including ensuring no locks are held:

- at thread exit
- in peformance-critical code
- when a coroutine is suspended (can cause deadlocks)

See this discourse thread for more discussion:

https://discourse.llvm.org/t/add-threadsanitizer-check-to-prevent-coroutine-suspending-while-holding-a-lock-potential-deadlock/74051
2023-11-03 06:53:52 +01:00
Ryan Prichard
3747cde5e8
[Fuzzer] Enable custom libc++ for Android (#70407)
The Android LLVM build system builds the arm64 fuzzer lib without
HWASan, but then applications that enable HWASan can generated an object
file with a HWASan-ified version of some libc++ symbols (e.g.
`std::__1::piecewise_construct`). The linker can choose the HWASan-ified
definition, but then it cannot resolve the relocation from
libclang_rt.fuzzer-aarch64-android.a to this symbol because the high
bits of the address are unexpectedly set. This produces an error:

```
relocation R_AARCH64_ADR_PREL_PG_HI21 out of range
```

Fix this problem by linking a custom isolated libc++ into Android's
fuzzer library.

We need to pass through ANDROID_NATIVE_API_LEVEL so that the libc++ for
32-bit Android (API < 24) uses LLVM_FORCE_SMALLFILE_FOR_ANDROID.
2023-11-02 14:07:39 -07:00
Zequan Wu
7fa9930847 Rename hasCorrelation to __llvm_profile_has_correlation 2023-11-02 14:45:59 -04:00
Thurston Dang
7d039effc4
[tsan] Increase size of shadow mappings for C/C++ on linux/x86_64 (#70517)
The current TSan mappings for C/C++ on linux/x86_64 have 0.5TB
for low app mem, 1.5TB (1.17TB usable) for mid app mem and
1.5TB for high app mem.
This can get a bit cramped if the apps are huge, and/or (in the
case of mid/high app mem) with significant ASLR entropy
(default ASLR setting of 28-bits = 1TB).

This patch increases the mapping sizes to 2TB, 5TB, and 6TB for
the low, mid and high app regions respectively. This is compatible
with up to 30-bits of ASLR entropy. It is difficult to make the
mappings any larger, given the 44-bit pointer compression.

It also moves the heap region to avoid HeapEnd() overlapping with
the newly enlarged high app region.

For convenience, we now use kShadowAdd instead of kShadowXor for
this set of mappings. This should be roughly equivalent in
runtime performance.
2023-11-02 09:49:19 -07:00
Zequan Wu
56e205a89c [Profile] Fix debug info correlation test failure on mac. 2023-11-02 11:30:26 -04:00
Davide Italiano
d06596516f [build_symbolizer] Fix typo in 2c81d70747ac81b37b6c7639fe7afa328e8f5e79 2023-11-01 18:40:11 -07:00
Davide Italiano
4de92601c8
[build_symbolizer] Introduce ZLIB_SRC to specify an on-disk location for (#70994)
zlib.

Not everyone wants to checkout from `git`. Tested with and without the
env var.
2023-11-01 15:39:01 -07:00
nicole mazzuca
05ebc70453
[MSVC][ASan] fix interface header (#70992)
looks like there may be some missing testing here.
2023-11-01 15:09:49 -07:00
Zequan Wu
d871456659 [Profile] Remove inline for hasCorrelation. 2023-11-01 15:48:50 -04:00
Zequan Wu
3c97c8b6fc
[Profile] Refactor profile correlation. (#70856)
Refactor some code from https://github.com/llvm/llvm-project/pull/69493.

#70712 was reverted due to linking failures. So, `-debug-info-correlate` remains unchanged and no new flag added.
2023-11-01 14:16:43 -04:00
nicole mazzuca
15b0cb4c72
[windows][ASan] Fix build (#70855)
PR #69625 broke the build - I put __cdecl on the wrong side of the `*`
in function pointer declarations.

Lesson learned - run check-all!
2023-10-31 14:14:58 -07:00
Martin Storsjö
703de006d3
[compiler-rt] [test] Apply the MSVC scalbn test exceptions to MinGW too (#70776)
MinGW mode can also use the MSVC/UCRT math functions. On ARM/ARM64,
mingw-w64 has always used the UCRT scalbn function. On x86, mingw-w64
recently changed to prefer the UCRT version for a large number of math
functions.
2023-10-31 22:38:53 +02:00
nicole mazzuca
b799080f19
[ASan][Windows] Add __cdecl to public sanitizer functions (#69625)
This is necessary for many projects which pass `/Gz` to their compiles,
which makes their default calling convention `__stdcall`.

(personal note, I _really_ wish there was a pragma for this)
2023-10-31 12:59:24 -07:00
Daniel Bertalan
fab5c8fa40 [compiler-rt] Build crtbegin.o/crtend.o for SerenityOS
Differential Revision: https://reviews.llvm.org/D154398
2023-10-31 18:46:59 +01:00
Zequan Wu
db7a1ed9a2 Revert "[Profile] Refactor profile correlation. (#70712)"
This reverts commit 4b383d0af9.
2023-10-31 10:53:45 -04:00
Zequan Wu
4b383d0af9
[Profile] Refactor profile correlation. (#70712)
Refactor some code from https://github.com/llvm/llvm-project/pull/69493.

Rebase of https://github.com/llvm/llvm-project/pull/69656 on top of main
as it was messed up.
2023-10-31 10:41:01 -04:00
David Truby
dbb4f90252
[compiler-rt] Don't link builtins against the CRT on Windows (#70675)
compiler-rt/builtins doesn't depend on anything from the CRT but
currently links against it and embeds a `/defaultlib:msvcrt` in the
`.lib` file, forcing anyone linking against it to also link against that
specific CRT. This isn't necessary as the end user can just choose which
CRT they want to use independently.
2023-10-31 12:51:38 +00:00
Vitaly Buka
3e5187ea83 Revert "[HWASAN] Enable memcpy, memmove and memset interceptors (#70387)"
Breaks build bots, details in #70387.

This reverts commit 91cdd7d615.
2023-10-30 21:09:21 -07:00
Kirill Stoimenov
91cdd7d615
[HWASAN] Enable memcpy, memmove and memset interceptors (#70387) 2023-10-30 15:01:21 -07:00
Alan Phipps
f95b2f1acf Reland "[InstrProf][compiler-rt] Enable MC/DC Support in LLVM Source-based Code Coverage (1/3)"
Part 1 of 3. This includes the LLVM back-end processing and profile
reading/writing components. compiler-rt changes are included.

Differential Revision: https://reviews.llvm.org/D138846
2023-10-30 11:15:02 -05:00
Sander de Smalen
e79f0506cf [compiler-rt] Don't use 'vg' in CFI directives for SME ABI routines
This broke some builds where GNU assembler doesn't support 'vg'.
2023-10-30 08:27:10 +00:00
Alexander Shaposhnikov
d4b8572f11 [compiler-rt] Fix src_rep_t_clz and clz_in_sig_frac
This is a follow-up to 910a4bf5b.

1. __builtin_clz takes unsigned int, thus for uint16_t
src_rep_t_clz can't use it directly but should subtract 16
(leading 16 bits of the promoted argument are zero).

2. Fix (and simplify) clz_in_sig_frac.

Test plan: ninja check-compiler-rt
(extendhfsf2_test.c and extenddftf2_test.c)
2023-10-28 10:20:57 +00:00
Ami-zhang
75b0a99668
[test][compiler-rt] Mark several tests as UNSUPPORTED on LoongArch (#69699) 2023-10-27 16:52:10 +08:00
ChiaHungDuan
4e8d6c4f82
[scudo] Pass the max number of blocks to popBlocks (#70243)
Make the cache have the fully control on how many blocks to be popped
(At before, it depended the number of blocks stored in the
TransferBatch)
2023-10-26 15:16:57 -07:00
Matthias Braun
e3cf80c5c1
BlockFrequencyInfoImpl: Avoid big numbers, increase precision for small spreads
BlockFrequencyInfo calculates block frequencies as Scaled64 numbers but as a last step converts them to unsigned 64bit integers (`BlockFrequency`). This improves the factors picked for this conversion so that:

* Avoid big numbers close to UINT64_MAX to avoid users overflowing/saturating when adding multiply frequencies together or when multiplying with integers. This leaves the topmost 10 bits unused to allow for some room.
* Spread the difference between hottest/coldest block as much as possible to increase precision.
* If the hot/cold spread cannot be represented loose precision at the lower end, but keep the frequencies at the upper end for hot blocks differentiable.
2023-10-24 20:27:39 -07:00
Alex Richardson
b745ce9525 [builtins] Revert accidental change to PPC implementation in 05a4212cc7
This commit was supposed to only change the generic implementation.
Should fix the build bot errors.
2023-10-24 17:28:49 -07:00
Alexander Richardson
05a4212cc7
[builtins] Avoid using long double in generic sources (#69754)
Use of long double can be error-prone since it could be one of 80-bit
extended precision float, IEEE 128-bit float, or IBM 128-bit float.
Instead use an explicit xf_float typedef for the remaining cases where
long double is being used in the implementation. This patch does not
touch
the PPC specializations which still use long double.
2023-10-25 01:15:47 +01:00
Leonard Chan
bac3808a12 Reapply "[compiler-rt] Allow Fuchsia to use 64-bit allocator for RISCV (#68343)"
This reverts commit 37432c154f.

The tunings for the lsan allocator for Fuchsia on RISCV should be
adjusted.
2023-10-24 20:45:08 +00:00
Rainer Orth
ad7611dafe
[builtins] Fix floattitf.c etc. compilation on Solaris/SPARC (#70058)
69660ccf2a broke the [Solaris/sparcv9
buildbot](https://lab.llvm.org/staging/#/builders/12/builds/264):
`compiler-rt/lib/builtins/int_to_fp.h` unconditionally uses `*int128_t`
which don't exist on 32-bit SPARC.

As suggested in https://github.com/llvm/llvm-project/pull/67540, this
patch fixes this by moving the `CRT_HAS_TF_MODE` guard up which does the
necessary checks.

Tested on `sparcv9-sun-solaris2.11`.
2023-10-24 19:14:33 +02:00
Alexander Richardson
d2ce3e9621
[builtins] Support building the 128-bit float functions on ld80 platforms (#68132)
GCC provides these functions (e.g. __addtf3, etc.) in libgcc on x86_64.
Since Clang supports float128, we can also enable the existing code by
using float128 for fp_t if either __FLOAT128__ or __SIZEOF_FLOAT128__ is
defined instead of only supporting these builtins for platforms with
128-bit IEEE long doubles.
This commit defines a new tf_float typedef that matches a float with
attribute((mode(TF)) on each given architecture.

There are more tests that could be enabled for x86, but to keep the diff
smaller, I restricted test changes to ones that started failing as part
of this refactoring.

This change has been tested on x86 (natively) and
aarch64,powerpc64,riscv64 and sparc64 via qemu-user.

This supersedes https://reviews.llvm.org/D98261 and should also cover
the changes from https://github.com/llvm/llvm-project/pull/68041.
2023-10-24 17:32:01 +01:00
PiJoules
54fe7ef700
[compiler-rt][lsan][Fuchsia] Adjust lsan allocator settings (#69401)
These now match the settings for the asan allocator on Fuchsia+RISCV.
2023-10-23 11:53:15 -07:00
PiJoules
9efaff1b0c
[NFC][lsan] Extract and rename SizeClassMap type from AP64 (#69526)
This will make it easier to read rather than using SizeClassMap in the
same namespace.
2023-10-23 11:49:59 -07:00
Kazu Hirata
747e0d9f0a [compiler-rt] Use std::clamp (NFC) 2023-10-22 12:32:20 -07:00
Martin Storsjö
8822eaae0f
[compiler-rt] Switch LLD specific tests to a more precise option (#69781)
Prefer the new flag -lld-allow-duplicate-weak (which was added recently
in a67ae8c0fd), over the old -lldmingw.

The -lldmingw option enables a number of different behaviours, while
this test only is interested in one aspect of them.

This should allow making -lldmingw more strict with not enabling MSVC
specific behaviours like inferring lib directories automatically from
the environment, as being pursued in https://reviews.llvm.org/D144084.
2023-10-21 09:42:49 +03:00
Kazu Hirata
d36ddaa665 [compiler-rt] Fix a warning
This patch fixes:

  compiler-rt/lib/builtins/int_to_fp_impl.inc:22:18: error: expression
  is not an integer constant expression; folding it to a constant is a
  GNU extension [-Werror,-Wgnu-folding-constant]

by using enum for constants.
2023-10-20 23:03:55 -07:00
nicole mazzuca
51835dfadb
[MSVC] fix the build (#69634)
MSVC in C mode apparently doesn't consider `const int` to be
sufficiently constant expression

This was broken in #66903.
2023-10-20 14:43:18 -07:00
Mauri de Souza Meneguzzo
51bfeff0e4
[tsan][go]: add atomic or/and functions (#65695)
These atomic primitives are required in order to implement the race
variants of the new And and Or operators in Go's sync/atomic package.
See Github issue golang/go#61395.
2023-10-20 22:52:50 +05:30