18286 Commits

Author SHA1 Message Date
Mitch Phillips
11e12bd82b
[NFC] [GWP-ASan] Rename Check() to check() (#96605)
Change this function to be LLVM-style in name.
2024-06-25 10:22:29 +02:00
Tulio Magno Quites Machado Filho
b515d9ea1e
[hwasan][aarch64] Fix missing DT_AARCH64_BTI_PLT flag (#95796)
When building hwasan on aarch64, the DT_AARCH64_BTI_PLT flag is missing
from libclang_rt.hwasan.so because some object files without
DT_AARCH64_BTI_PLT are linked in the final DSO.
These files are specific to riscv64 and x86_64, ending up with no
aarch64 code in them.

Avoid building and linking architecture-specific files unless the
architecture is listed in HWASAN_SUPPORTED_ARCH.
2024-06-21 20:57:24 -03:00
Fabio D'Urso
513644b5a3
[scudo] Add TEST_SKIP macro to skip the current test (#96192) 2024-06-21 21:45:53 +02:00
Gabriel Baraldi
e9af6eeb91
Enable building 16 bit floating point builtins in apple platforms if supported by the compiler (#84192)
Currently we will not build float16/bfloat16 builtins on apple
platforms, LLVM will include calls to those builtins and fail to link.

I copied the test code we perform for non apple platforms because oddly
we branch on it being apple for building builtins
2024-06-21 13:41:20 -04:00
earnol
138ea7d1fb
Revert "[ubsan] Display correct runtime messages for negative _BitInt" (#96239)
Reverts llvm/llvm-project#93612 due to the issues with ppc64le platform.
2024-06-21 08:33:46 -04:00
Alexander Shaposhnikov
e674e739d7
[compiler-rt] Fix build breakage (#96235)
Add missing flags in cmake.
Follow-up to cae6d458a.
2024-06-20 21:51:18 -07:00
NAKAMURA Takumi
2fe8498654 mmapForContinuousMode: Redo #95702: Align Linux's impl to __APPLE__'s a little.
I've made this small cosmetic changes,
`s/CountersOffsetInBiasMode/FileOffsetToCounters/`
2024-06-21 09:38:25 +09:00
NAKAMURA Takumi
e908320a03 Revert "mmapForContinuousMode: Align Linux's impl to __APPLE__'s more. NFC. (#95702)"
This reverts commit 7cf84d3b0bc5eda3a907dfd026d51a17e28114a3.
(llvmorg-19-init-14939-g7cf84d3b0bc5)

This has my wrong assumptions possibly. This was failing fuchsia.
2024-06-21 08:00:22 +09:00
Florian Mayer
7a49c90ab6
[NFC] fix incorrect #endif comment (#95991) 2024-06-20 13:32:08 -07:00
earnol
49001d584c
[ubsan] Display correct runtime messages for negative _BitInt (#93612)
Without this patch compiler-rt ubsan library has a bug displaying
incorrect values for variables of the _BitInt (previously called
_ExtInt) type. This patch affects affects both: generation of metadata
inside code generator and runtime part. The runtime part provided only
for i386 and x86_64 runtimes. Other runtimes should be updated to take
full benefit of this patch.
The patch is constructed the way to be backward compatible and int and
float type runtime diagnostics should be unaffected for not yet updated
runtimes.

This patch fixes issue:
https://github.com/llvm/llvm-project/issues/64100.

Co-authored-by: Vladislav Aranov <vladislav.aranov@ericsson.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-06-20 16:31:32 -04:00
NAKAMURA Takumi
7cf84d3b0b
mmapForContinuousMode: Align Linux's impl to __APPLE__'s more. NFC. (#95702) 2024-06-20 16:50:54 +09:00
Fangrui Song
ef83c25b0e
[nsan] Fix style issue
The initial check-in of compiler-rt/lib/nsan #94322 has a lot of style
issues. Fix them before the history becomes more useful.

Pull Request: https://github.com/llvm/llvm-project/pull/96142
2024-06-20 00:46:10 -07:00
Alexander Shaposhnikov
cae6d458a0
[CompilerRT] Add support for numerical sanitizer (#94322)
This diff contains the compiler-rt changes / preparations for nsan.

Test plan:

1. cd build/runtimes/runtimes-bins && ninja check-nsan
2. ninja check-all
2024-06-19 15:20:36 -07:00
Fabio D'Urso
7fc975aa26
Reland "[scudo] Apply filling when realloc shrinks and re-grows a block in-place" (#95838)
Reland of #93212, which had been reverted in
commit bddd8eae17df6511aee789744ccdc158de817081.
2024-06-19 09:37:23 +02:00
Jon Roelofs
0c0281130e
fixup! [compiler-rt][AArch64][FMV] Use the hw.optional.arm.caps fast path (#95275)
https://github.com/llvm/llvm-project/pull/95275#issuecomment-2177366693
2024-06-18 19:04:03 -07:00
Caslyn Tonelli
6f13f0b3fe
[scudo] Test secondary cache options only if enabled (#95872)
Configs that use `MapAllocatorNoCache` for its secondary cache will
return `false` if `setOption` is called with some [specific
options](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/scudo/standalone/secondary.h#L104),
and this breaks with the `SecondaryOptions` test.

This change will gate testing all `setOption` expectations for cache
options only if the allocator cache is enabled. This will unblock
[github.com/llvm/llvm-project/pull/95595
](https://github.com/llvm/llvm-project/pull/95595) from merging into
Fuchsia.
2024-06-18 10:28:04 -07:00
Florian Mayer
c6049e67ef Reapply "[HWASan] [compiler-rt] support non-4k pages on Android" (#95853)
Updated MapDynamicShadow callsite in asan_win.
2024-06-17 15:20:57 -07:00
Florian Mayer
1adf0fae05
Revert "[HWASan] [compiler-rt] support non-4k pages on Android" (#95853)
Reverts llvm/llvm-project#95069

Broke windows bot
2024-06-17 14:38:26 -07:00
Joshua Baehring
16aa39ad94
[scudo] Update error handling for seondary cache entry count (#95595)
Initially, the scudo allocator would return an error if the user
attempted to set the cache capacity
(i.e. the number of possible entries in the cache) above the maximum
cache capacity.
Now the allocator will resort to using the maximum cache capacity in
this event.
An error will still be returned if the user attempts to set the number
of entries to a negative value.
2024-06-17 14:06:31 -07:00
Florian Mayer
5b04b6fe3f
[HWASan] [compiler-rt] support non-4k pages on Android (#95069) 2024-06-17 13:21:34 -07:00
NAKAMURA Takumi
d442bf0435 mmapForContinuousMode: Calculate FileOffsetToBitmap from FileOffsetToCounters. NFC. 2024-06-16 21:57:31 +09:00
NAKAMURA Takumi
f4ce3448be Reformat 2024-06-16 21:57:31 +09:00
Youngsuk Kim
3ecba1ad1f
[compiler-rt] Remove 'memprof_meminfoblock.h' from MEMPROF_HEADERS (NFC) (#95334)
Commit 8306968b592d942cc49bde2e387061e673a9fbb7 deleted file
`compiler-rt/lib/memprof/memprof_meminfoblock.h`, but didn't remove it
from MEMPROF_HEADERS in `compiler-rt/lib/memprof/CMakeLists.txt`.

Remove unneeded leftover line in
`compiler-rt/lib/memprof/CMakeLists.txt`.

p.s.
GH #54777 reported a llvm14 build failure due to the existence of the
leftover line, but I'm unable to reproduce the build failure with llvm19
trunk.
2024-06-14 14:11:43 -04:00
NAKAMURA Takumi
71f8b441ed Reapply: [MC/DC][Coverage] Loosen the limit of NumConds from 6 (#82448)
By storing possible test vectors instead of combinations of conditions,
the restriction is dramatically relaxed.

This introduces two options to `cc1`:

* `-fmcdc-max-conditions=32767`
* `-fmcdc-max-test-vectors=2147483646`

This change makes coverage mapping, profraw, and profdata incompatible
with Clang-18.

- Bitmap semantics changed. It is incompatible with previous format.
- `BitmapIdx` in `Decision` points to the end of the bitmap.
- Bitmap is packed per function.
- `llvm-cov` can understand `profdata` generated by `llvm-profdata-18`.

RFC:
https://discourse.llvm.org/t/rfc-coverage-new-algorithm-and-file-format-for-mc-dc/76798

--
Change(s) since llvmorg-19-init-14288-g7ead2d8c7e91

- Update compiler-rt/test/profile/ContinuousSyncMode/image-with-mcdc.c
2024-06-14 19:31:56 +09:00
Jon Roelofs
4f8c961924
[compiler-rt][AArch64][FMV] Use the hw.optional.arm.caps fast path (#95275)
MacOS 15.0 and iOS 18.0 added a new sysctl to fetch a bitvector of all
the hw.optional.arm.FEAT_*'s in one go. Using this has a perf advantage
over doing multiple round-trips to the kernel and back, but since it's
not present in older oses, we still need the slow fallback.
2024-06-13 18:06:20 -07:00
Florian Mayer
41c50f0836 [HWASan] comment why hwasan_symbolize_stack_uas is arm64 only 2024-06-13 17:55:56 -07:00
Thurston Dang
0ca05e8221
Reland '[hwasan] Add fixed_shadow_base flag (#73980)' (#95445)
This was reverted in https://github.com/llvm/llvm-project/pull/95435
because it broke Android static hwasan binaries. This reland limits the
change to !SANITIZER_ANDROID.

Original commit message:
When set to non-zero, the HWASan runtime will map the shadow base at the
specified constant address.

This is particularly useful in conjunction with the existing compiler
option 'hwasan-mapping-offset', which bakes a hardcoded constant address
into the instrumentation.

---------

Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
2024-06-13 17:47:04 -07:00
Florian Mayer
8fa7cf000a [HWASan] disable hwasan_symbolize_stack_uas on x86 2024-06-13 14:51:58 -07:00
Jay Foad
d4a0154902
[llvm-project] Fix typo "seperate" (#95373) 2024-06-13 20:20:27 +01:00
Andrew Browne
cd94fa7e75
[DFSan] Fix sscanf checking that ordinary characters match. (#95333)
Fixes: #94769
2024-06-13 11:54:40 -07:00
Florian Mayer
12f77e811b
Revert "[hwasan] Add fixed_shadow_base flag" (#95435)
Reverts llvm/llvm-project#73980

This broke static hwasan binaries in Android, for some reason the
fixed_shadow_base branch gets taken
2024-06-13 10:07:49 -07:00
Logikable
6499c5d70c
[compiler-rt][builtins] Add opt-in pthread_mutex_t locks to libatomic (#95326)
When an uninstrumented libatomic is used with a TSan instrumented
memcpy, TSan may report a data race in circumstances where writes are
arguably safe.

This occurs because __atomic_compare_exchange won't be instrumented in
an uninstrumented libatomic, so TSan doesn't know that the subsequent
memcpy is race-free.

On the other hand, pthread_mutex_(un)lock will be intercepted by TSan,
meaning an uninstrumented libatomic will not report this false-positive.

pthread_mutexes also may try a number of different strategies to acquire
the lock, which may bound the amount of time a thread has to wait for a
lock during contention.

While pthread_mutex_lock has a larger overhead (due to the function call
and some dispatching), a dispatch to libatomic already predicates a lack
of performance guarantees.
2024-06-13 10:03:15 -07:00
Florian Mayer
389142efa0
[HWASan] add test for hwasan_symbolize of stack uas (#95186) 2024-06-13 09:56:45 -07:00
Hans Wennborg
4afd286022 Revert "[asan] Make frame number checks more flexable (#94307)"
It broke tests on Mac, see comment on the PR.

> Use more flexable regex ([0-9]+) for frame number checks. Since the
> frame numbers might change if some functions are not inlined.
>
> Similar to
> *
> 0360f3218a
> *
> 404bc5ca2a

This reverts commit 98174fb6ec9784d9eb7be313ee1317ca6e703d90
and the follow-up commit 86d8aec97fd9e009e9b360ffeee744d3acce730d.
2024-06-13 16:12:02 +02:00
Alexandros Lamprineas
933d6be8e8
[FMV][compiler-rt] Fix cpu features initialization. (#95149)
To detect features we either use HWCAPs or directly extract system
register bitfields and compare with a value. In many cases equality
comparisons give wrong results for example FEAT_SVE is not set if SVE2
is available (see the issue #93651). I am also making the access to
__aarch64_cpu_features atomic.

The corresponding PR for the ACLE specification is
https://github.com/ARM-software/acle/pull/322.
2024-06-13 11:45:39 +01:00
Mitch Phillips
7adb7aa494
[GWP-ASan] Various test fixes. (#94938)
When running some tests with --gtest_repeat=100 --gtest_shuffle, I
encountered some problems because the allocator wasn't torn down
completely, and the singleton pointer ended up pointing to a
use-after-scope'd object.

This patch has a couple of fixes and niceties:
 1. Removing the once-init stuff from tests, now that it's implicitly
    done in GuardedPoolAllocator::installAtFork() anyway.
 2. Calling uninitTestOnly() in the late_init test.
 3. Resetting the HasReportedBadPoolAccess when the signal handlers are
    installed (allowing for --gtest_repeat w/ recoverable mode).
 4. Adding a check and resetting the singleton pointer in
    uninitTestOnly().
2024-06-13 09:21:31 +01:00
dyung
86d8aec97f
[asan] Attempt to fix tests broken by #94307. (#95340) 2024-06-12 17:58:24 -07:00
Hau Hsu
98174fb6ec
[asan] Make frame number checks more flexable (#94307)
Use more flexable regex ([0-9]+) for frame number checks. Since the
frame numbers might change if some functions are not inlined.

Similar to
*
0360f3218a
*
404bc5ca2a
2024-06-12 22:49:37 +08:00
Kerry McLaughlin
038725468f
[AArch64][compiler-rt] Disable SME ABI routines if function multiversioning is not supported (#94973)
This prevents build failures when building with `DISABLE_AARCH64_FMV`,
see https://github.com/llvm/llvm-project/pull/92921.
2024-06-12 09:35:57 +01:00
Ben Langmuir
0f286f8a36
[ORC][MachO] Register objc protolist, protorefs, nlclslist metadata sections (#95144)
Add missing __DATA sections that the objc runtime expects to register.
This fixes running objc code that makes use of `@protocol` references
and `__attribute__((objc_nonlazy_class))` classes.

rdar://129368761
2024-06-11 16:52:42 -07:00
ChiaHungDuan
cc04bbb275
[scudo] Fix the calculation of PushedBytesDelta (#95177)
BytesInBG is always greater or equal to BG->BytesInBGAtLastCheckpoint.

Note that the bug led to unnecessary attempts of page releasing and
doesn't have critical impact on the correctness.
2024-06-11 14:52:28 -07:00
Fabio D'Urso
bddd8eae17 Revert "[scudo] Apply filling when realloc shrinks and re-grows a block in-place (#93212)"
This reverts commit 760d880ea602117aa2e6bba4cf31069f09225b4b.

It broke https://lab.llvm.org/buildbot/#/builders/169/builds/32309
2024-06-10 13:35:42 +02:00
Fabio D'Urso
760d880ea6
[scudo] Apply filling when realloc shrinks and re-grows a block in-place (#93212) 2024-06-10 10:39:17 +02:00
Marc Auberer
cac7821438
[compiler-rt] Replace deprecated aligned_storage with aligned byte array (#94171)
`std::aligned_storage` is deprecated with C++23, see
[here](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1413r3.pdf).

This replaces the usages of `std::aligned_storage` within compiler-rt
with an aligned `std::byte` array.
I will provide patches for other subcomponents as well.
2024-06-08 12:29:01 +02:00
Thurston Dang
221336c8e2
[dfsan] Fix release_shadow_space.c (#94770)
DFSan's sscanf is incorrect
(https://github.com/llvm/llvm-project/issues/94769), which results in
erroneous matches when scraping RSS from /proc/maps. This patch works
around the issue by using strstr as a secondary check.

It also adds a loose validity check for the initial RSS measurement, to
guard against regressions in get_rss_kb().

Fixes https://github.com/llvm/llvm-project/issues/91287
2024-06-07 21:10:13 -07:00
Jan Voung
c467e6097e
Check if LLD is built when checking if lto_supported (#92752)
Otherwise, older copies of LLD may not understand the latest bitcode
versions (for example, if we increase
`ModuleSummaryIndex::BitCodeSummaryVersion`)

Related to
https://github.com/llvm/llvm-project/pull/90692#issuecomment-2113250317
2024-06-07 09:29:31 -07:00
Thurston Dang
79cd6c3d01
[dfsan] Add test case for sscanf (#94700)
This test case shows a limitation of DFSan's sscanf implementation
(introduced in https://reviews.llvm.org/D153775): it simply ignores
ordinary characters in the format string, instead of actually comparing
them against the input. This may change the semantics of instrumented
programs.

Importantly, this also means that DFSan's release_shadow_space.c test,
which relies on sscanf to scrape the RSS from /proc/maps output, will
incorrectly match lines that don't contain RSS information. As a result,
it adding together numbers from irrelevant output (e.g., base
addresses), resulting in test flakiness
(https://github.com/llvm/llvm-project/issues/91287).
2024-06-06 17:48:37 -07:00
Alexander Richardson
92a870888c
[compiler-rt] Map internal_sigaction to __sys_sigaction on FreeBSD (#84441)
This function is called during very early startup and which can result
in a crash on FreeBSD. The sigaction() function in libc is indirected
via a table so that it can be interposed by the threading library
rather than calling the syscall directly. In the crash I was observing
this table had not yet been relocated, so we ended up jumping to an
invalid address. To avoid this problem we can call __sys_sigaction,
which calls the syscall directly and in FreeBSD 15 is part of libsys
rather than libc, so does not depend on libc being fully initialized.
2024-06-07 00:22:07 +02:00
Thurston Dang
19bbbcbedc
[sanitizer_common] Change allocator base in test case for compatibili… (#93234)
…ty with high-entropy ASLR

With high-entropy ASLR (e.g., 32-bits == 16TB), the allocator base of
0x700000000000 (112TB) may collide with the placement of the libraries
(e.g., on Linux, the mmap base could be 128TB - 16TB == 112TB). This
results in a segfault in the test case.

This patch moves the allocator base below the PIE program segment,
inspired by fb77ca05ffb4f8e666878f2f6718a9fb4d686839. As per that patch:
1) we are leaving the old behavior for Apple 2) since ASLR cannot be set
above 32-bits for x86-64 Linux, we expect this new layout to be durable.

Note that this is only changing a test case, not the behavior of
sanitizers. Sanitizers have their own settings for initializing the
allocator base.

Reproducer:
1. ninja check-sanitizer # Just to build the test binary needed below;
no need to actually run the tests here
2. sudo sysctl vm.mmap_rnd_bits=32 # Increase ASLR entropy
3. for f in `seq 1 10000`; do echo $f;
GTEST_FILTER=*SizeClassAllocator64Dense
./projects/compiler-rt/lib/sanitizer_common/tests/Sanitizer-x86_64-Test
> /tmp/x; if [ $? -ne 0 ]; then cat /tmp/x; fi; done
2024-06-06 14:49:12 -07:00
Nikita Popov
b1861429cb
[sanitizer] Make CHECKs in bitvector more precise (NFC) (#94630)
These CHECKs are all checking indices, which must be strictly smaller
than the size (otherwise they would go out of bounds).
2024-06-06 14:48:23 -07:00