18754 Commits

Author SHA1 Message Date
Hans Wennborg
04ccbe6e70 Fix typos in interception_win.cpp 2024-09-19 13:11:10 +02:00
Rainer Orth
0a3b6af768
[ASan][test] Skip Linux/odr_c_test.c on SPARC (#109111)
When ASan testing is enabled on SPARC as per PR #107405, the
```
  AddressSanitizer-sparc-linux :: TestCases/Linux/odr_c_test.c

```
test `FAIL`s on Linux/sparc64:
```
+ projects/compiler-rt/test/asan/SPARCLinuxConfig/TestCases/Linux/Output/odr_c_test.c.tmp
+ count 0
Expected 0 lines, got 13.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==4165420==ERROR: AddressSanitizer: BUS on unknown address (pc 0x7012d5b4 bp 0xffa3b938 sp 0xffa3b8d0 T0)
==4165420==The signal is caused by a READ memory access.
==4165420==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
```
The test relies on an unaligned access, which cannot work on a
strict-alignment target like SPARC.

Thus this patch skips the test.

Tested on `sparc64-unknown-linux-gnu`.
2024-09-19 10:04:18 +02:00
Phoebe Wang
c18be32185
Reland "[X86][BF16] Add libcall for F80 -> BF16 (#109116)" (#109143)
This reverts commit ababfee78714313a0cad87591b819f0944b90d09.

Add X86 FP80 check.
2024-09-19 15:39:07 +08:00
Vitaly Buka
4e659c6ca3
[NFC][sanitizer] Use InitializePlatformEarly() in test (#109224)
Fix windows test after #108921.
2024-09-18 17:28:49 -07:00
Vitaly Buka
999313debe
[sanitizer] Switch from lazy ThreadDescriptorSize (#108923)
`ThreadDescriptorSize` uses `dlsym` which may use
malloc in unexpected time.

It's relatively easy to init size from the main init.
2024-09-18 16:45:43 -07:00
Vitaly Buka
d1544da533
[NFC][sanitizer] Move InitTlsSize (#108922)
Move after ThreadDescriptorSizeFallback to be able to use it.
2024-09-18 16:29:18 -07:00
Vitaly Buka
a0bb2e21c1
[NFC][sanitizer] Move InitTlsSize into InitializePlatformEarly (#108921) 2024-09-18 16:19:35 -07:00
Vitaly Buka
38752ffd41
[sanitizer] Adjust size for begin/start mismatch (#109079)
Follow up to 51d913af827567e6a0999609e7e624a422781870.
2024-09-18 16:10:16 -07:00
Phoebe Wang
a10c9f994b
Revert "[X86][BF16] Add libcall for F80 -> BF16" (#109140)
Reverts llvm/llvm-project#109116
2024-09-18 21:35:38 +08:00
Chris Apple
aa43f3abe0
[compiler-rt][rtsan] Use Die instead of exit, define cf.exitcode (#107635) 2024-09-18 07:34:18 -06:00
Phoebe Wang
76eda76f9f
[X86][BF16] Add libcall for F80 -> BF16 (#109116)
This fixes #108936, but the calling convention doesn't match with GCC. I
doubt we have such a lib function for now, so leave the calling
convention as is.
2024-09-18 21:23:10 +08:00
Chris Apple
cb47b45d78
[rtsan] Fix RTTI issue, make a better c test (#108720)
Later in a development branch, our c tests were failing, this was due to
the lack of RTTI.

This follows very similar patterns found in the other sanitizers
2024-09-18 05:48:24 -06:00
Hans
3d2925b9de
[win/asan] AllocateMemoryForTrampoline within 2 GB of the module's base address (#108822)
Since we may copy code (see CopyInstructions) to the trampoline which
could reference data inside the original module, we really want the
trampoline to be within 2 GB of not just the original function, but
within anything that function may have rip-relative accesses to, i.e.
within 2 GB of that function's whole module.

This fixes interception failures like the following scenario:

1. Intercept `CreateProcess` in kernel32.dll, allocating a trampoline
region right after
2. Start intercepting `memcpy` in the main executable, which is loaded
at a lower address than kernel32.dll, but still within 2 GB of the
trampoline region so we keep using it.
3. Try to copy instructions from `memcpy` to the trampoline. Turns out
one instruction references data that is more than 2GB away from the
trampoline, so it can't be relocated.
4. The process exits due to a CHECK failure

(Full story at https://crbug.com/341936875#comment45 and following.)
2024-09-18 08:58:14 +02:00
Vitaly Buka
51d913af82 [sanitizer] Remove CHECK from __sanitizer_get_dtls_size
The check is too strict. It works for 2.38 I have,
but not for older glibc which used different
allocation code.

The check was introduced with #108345.
2024-09-17 18:21:20 -07:00
Vitaly Buka
5bb1ce8ea6
[NFC][sanitizer] Make GetLibcVersion void (#108915)
It can't fail if guarded with SANITIZER_GLIBC.
2024-09-17 13:12:57 -07:00
Vitaly Buka
71a91c1194
[tsan] Use DlSymAllocator (#108920)
`DlSymAllocator` allows early allocations, when
tsan is not yet initialized, e.g. from `dlsym`.

All other sanitizers with interceptors already use
`DlSymAllocator`.

Existing `in_symbolizer()` tsan logic is very similar.
However, we need to keep both as `DlSymAllocator`
does not support large allocations, needed for Symolizer.
2024-09-17 11:06:26 -07:00
Vitaly Buka
2c69a09bee
[NFC][sanitizer] Move ThreadDescriptorSize into GLIBC/FREEBSD block (#108913) 2024-09-17 10:50:14 -07:00
Vitaly Buka
3d87e21ac8
[NFC][sanitizer] Consolidate version checking branches of ThreadDescriptorSizeFallback (#108912) 2024-09-17 09:23:51 -07:00
Vitaly Buka
e5bc842a9c
[NFC][sanitizer] Remove #elif to simplify ThreadDescriptorSizeFallback (#108911) 2024-09-17 09:22:03 -07:00
Vitaly Buka
8982f9854f
[NFC][sanitizer] Remove else if from ThreadDescriptorSizeFallback (#108909) 2024-09-16 19:20:20 -07:00
Vitaly Buka
fab60a6bae
[NFC][sanitizer] Simplify ThreadDescriptorSizeFallback using early return (#108908) 2024-09-16 19:15:25 -07:00
Enna1
a20794b574
[Sanitizer] Call Die() instead of Abort() when failed to reserve shadow memory range (#107833)
I grep the code and find that `Abort()` is only called in `Die()` when
the flag `abort_on_error` is set.
Thus, if reserving shadow memory range fails, `Die()` rather than
`Abort()` should be called. In this case, the flag `abort_on_error` will
be respected and the die callbacks will be called.
2024-09-17 09:53:17 +08:00
Enna1
7b3d4e38dd
[NFC][ASan] Replace calls to Report() and Die() with ReportIncompatibleRT() in AsanCheckIncompatibleRT() (#107991) 2024-09-17 09:52:49 +08:00
Vitaly Buka
ad06e9562a
Reapply "[NFC][sanitizer] Switch to gnu_get_libc_version (#108724)" (#108885)
In #108724 `#ifdef` was used instead of `#if`.

This reverts commit 68e4518598d63efa02230f400e50263baccbb8e4.
2024-09-16 14:54:01 -07:00
Vitaly Buka
f13b7d0b02
Reland "[sanitizer] Fix partially initialized static TLS range" (#108883)
Reland llvm/llvm-project#108685

Arguments order was wrong on Windows and Darwin.
2024-09-16 14:05:00 -07:00
Vitaly Buka
9a1d0744ed
Revert "[sanitizer] Fix partially initialized static TLS range" (#108881)
Reverts llvm/llvm-project#108685

Breaks Darwin and Windows
https://lab.llvm.org/buildbot/#/builders/107/builds/2930
https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/as-lldb-cmake/11684/
2024-09-16 13:51:23 -07:00
Thurston Dang
ddd1a02048 Revert "[scudo] Update secondary cache time-based release logic (#107507)"
This reverts commit e5271fef8fd8931370f04702ba2f9e8b2ab0e523.

Reason: buildbot breakage: https://lab.llvm.org/buildbot/#/builders/139/builds/3806
2024-09-16 20:43:55 +00:00
Vitaly Buka
b7c9ebe4ec
[sanitizer] Fix partially initialized static TLS range (#108685)
Fixes asan, msan crash on check added in #108684.
The #108684 includes reproducer of the issue.

Change interface of `GetThreadStackAndTls` to
set `tls_begin` and `tls_end` at the same time.
2024-09-16 12:48:24 -07:00
Thurston Dang
68e4518598 Revert "[NFC][sanitizer] Switch to gnu_get_libc_version (#108724)"
This reverts commit 69f3244da76586be393d1e97b01660c6f03d666c.

Reason: buildbot breakage because Android doesn't have <gnu/libc-version.h>
https://lab.llvm.org/buildbot/#/builders/186/builds/2381

(It's probably easy to fix but I don't readily have an Android device to test.)
2024-09-16 19:11:27 +00:00
Joshua Baehring
e5271fef8f
[scudo] Update secondary cache time-based release logic (#107507)
Secondary cache entries are now released to the OS from least recent to
most recent entries. This helps to avoid unnecessary scans of the cache
since entries ready to be released (specifically, entries that are
considered old relative to the configurable release interval) will
always be at the tail of the list of committed entries by the LRU
ordering. For this same reason, the `OldestTime` variable is no longer
needed to indicate when releases are necessary so it has been removed.
2024-09-16 11:33:03 -07:00
Vitaly Buka
0ea0e3a1b6
[sanitizer] Add CHECK that static TLS info is ready (#108684)
There is possibility of
static_tls_begin is set and static_tls_end is not yet

The test reproduces the case.
Stack trace looks like this:
* `MsanThread::Init`
* `SetThreadStackAndTls`
* `GetThreadStackAndTls`
* `GetThreadStackTopAndBottom`
* `pthread_getattr_np`
* `realloc`
* `__sanitizer_malloc_hook`
* TLS access
* `___interceptor___tls_get_addr`
* `DTLS_on_tls_get_addr`

The issue is that `SetThreadStackAndTls` implementation
stores `tls_begin` before `GetThreadStackTopAndBottom`,
and `tls_end` after. So we have partially initialized
state in `DTLS_on_tls_get_addr`.
2024-09-16 11:21:08 -07:00
Rainer Orth
9ec1f65814 Revert "[NFC][sanitizer] Simplify ifdef"
Breaks the [Solaris/sparcv9](https://lab.llvm.org/buildbot/#/builders/13/builds/2219) and [Solaris/amd64](https://lab.llvm.org/staging/#/builders/120/builds/1770) builds.

This reverts commit c21909a530f438bcc942c11e6d7b875bb28a028a.
2024-09-16 20:14:54 +02:00
Vitaly Buka
d3014e1f3b
[NFC][sanitizer] Use RTLD_DEFAULT for _dl_get_tls_static_info (#108723)
We don't intercept this one, no reason to use RTLD_NEXT.

Co-authored-by: Sam Elliott <quic_aelliott@quicinc.com>
2024-09-16 11:00:13 -07:00
Vitaly Buka
69f3244da7
[NFC][sanitizer] Switch to gnu_get_libc_version (#108724)
`gnu_get_libc_version` unlike `confstr` is not
intercepted. We should be able to use this
function earier.

Looks like we use `confstr` staring from
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60038
but there is no specific reason to refer it over
`gnu_get_libc_version`.
2024-09-16 09:53:19 -07:00
goussepi
79c4ece75f
[tsan] Allow unloading of ignored libraries (#105660)
Allows unloading and reloading of ignored libraries. We don't attempt to
reuse or free memory of unloaded library. So TSan will assert if an
ignored library is reloaded 128 times.

Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
2024-09-16 15:12:46 +01:00
Rainer Orth
961bc37d44
[ASan][test] XFAIL global-overflow.cpp etc. on SPARC (#108200)
When enabling ASan testing on SPARC as per PR #107405, two tests `FAIL`
in similar ways as detailed in Issue #108194: at `-O1` and above, one
line of the stacktrace lacks the line number info, causing the tests to
`FAIL`. I could trace this to `clang` generating incomplete line number
info; `g++` gets this right.

To avoid this, this patch `XFAIL`s the affected tests on SPARC.

Tested on `sparcv9-sun-solaris2.11`.
2024-09-16 09:47:38 +02:00
Rainer Orth
d76966e317
[sanitizer_common][test] Disable sanitizer_coverage_trace_pc_guard.cp… (#108206)
…p etc. on SPARC

When enabling ASan testing on SPARC as per PR #107405, two tests `FAIL`:
```
  SanitizerCommon-asan-sparc-SunOS :: sanitizer_coverage_trace_pc_guard-dso.cpp
  SanitizerCommon-asan-sparc-SunOS :: sanitizer_coverage_trace_pc_guard.cpp

```
The issue is the same in both cases:
```
WARNING: No coverage file for projects/compiler-rt/test/sanitizer_common/asan-sparc-SunOS/Output/sanitizer_coverage_trace_pc_guard.cpp.tmp
WARNING: No coverage file for sanitizer_coverage_trace_pc_guard.cpp.tmp.22766.sancov
ERROR: No valid coverage files given.

```
Checking the file with `sancov -print` reveals `Wrong magic:
4294967090`. There seems to be an endianess bug somewhere, since the
tests are already disabled on other big-endian targets.

This patch matches this.

Tested on `sparcv9-sun-solaris2.11`.
2024-09-16 09:45:20 +02:00
Rainer Orth
9b237b4013
[ASan] Disable InstallAtForkHandler on Linux/sparc64 (#108542)
When SPARC Asan testing is enabled by PR #107405, many Linux/sparc64
tests just hang like
```
#0  0xf7ae8e90 in syscall () from /usr/lib32/libc.so.6
#1  0x701065e8 in __sanitizer::FutexWait(__sanitizer::atomic_uint32_t*, unsigned int) ()
    at compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:766
#2  0x70107c90 in Wait ()
    at compiler-rt/lib/sanitizer_common/sanitizer_mutex.cpp:35
#3  0x700f7cac in Lock ()
    at compiler-rt/lib/asan/../sanitizer_common/sanitizer_mutex.h:196
#4  Lock ()
    at compiler-rt/lib/asan/../sanitizer_common/sanitizer_thread_registry.h:98
#5  LockThreads ()
    at compiler-rt/lib/asan/asan_thread.cpp:489
#6  0x700e9c8c in __asan::BeforeFork() ()
    at compiler-rt/lib/asan/asan_posix.cpp:157
#7  0xf7ac83f4 in ?? () from /usr/lib32/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
```
It turns out that this happens in tests using `internal_fork` (e.g.
invoking `llvm-symbolizer`): unlike most other Linux targets, which use
`clone`, Linux/sparc64 has to use `__fork` instead. While `clone`
doesn't trigger `pthread_atfork` handlers, `__fork` obviously does,
causing the hang.

To avoid this, this patch disables `InstallAtForkHandler` and lets the
ASan tests run to completion.

Tested on `sparc64-unknown-linux-gnu`.
2024-09-16 09:44:07 +02:00
Vitaly Buka
0b041f1da5 [NFC][sanitizer] Extend DlSymAllocator
Preparation for using in`tsan`.
2024-09-15 17:14:08 -07:00
Vitaly Buka
bafe3a4b0c [NFC][tsan] Fix reallocarray, calloc parameters order
Implementation is commutative, so it should make
no difference. It's done just for consistency with
documentation.
2024-09-15 17:02:28 -07:00
Vitaly Buka
c21909a530 [NFC][sanitizer] Simplify ifdef 2024-09-14 19:12:42 -07:00
Vitaly Buka
7005772e45 [NFC][sanitizer] Clang format sanitizer_linux_test.cpp 2024-09-14 18:32:40 -07:00
Vitaly Buka
b78d4c1fd9 [NFC][sanitizer] Clang-format sanitizer_common_nolibc.cpp 2024-09-14 18:32:40 -07:00
Vitaly Buka
8bce263820 [NFC][sanitizer] Use nullptr instead of 0 2024-09-13 23:00:17 -07:00
hev
1825cf28dc
[LoongArch][sanitizer] Fix SC_ADDRERR_{RD,WR} missing in the musl environment (#108557)
Fixes #108550
2024-09-14 11:19:34 +08:00
Ganesh
02e4186d0b
[X86] AMD Zen 5 Initial enablement (#107964)
This patch enables the basic skeleton enablement of AMD next gen zen5 CPUs.
2024-09-13 17:45:33 +01:00
Vitaly Buka
f0b3287297
[sanitizer] Disable new test on powerpc64le (#108505)
The reason is not clear
https://lab.llvm.org/buildbot/#/builders/72/builds/3260

The test was introduced in #108349.
2024-09-12 23:33:11 -07:00
Vitaly Buka
55afd5b9e8 [sanitizer] Try to fix the test on powerpc bot
It silently fails with tsan.
https://lab.llvm.org/buildbot/#/builders/72/builds/3257
2024-09-12 22:54:00 -07:00
Arthur Eubanks
d9ed8b018d
[test][compiler-rt] Mark dlsym_alloc.c as unsupported on macos (#108439)
With #106912, the test now fails on macos, e.g.

https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/2058/.
2024-09-12 20:52:24 -07:00
Vitaly Buka
95eab0d195
[sanitizer] Test for __sanitizer_get_dtls_size (#108349)
Test for #108348 which is almost NFC. However, the test
may fail on some platforms, and a few iterations could be
needed to filter out unsupported platforms.
2024-09-12 13:43:42 -07:00