18738 Commits

Author SHA1 Message Date
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
Vitaly Buka
dd66aaf85a
[sanitizer] Allow to override GetDTLSRange (#108348)
And rename it into __sanitizer_get_dtls_size.

The test will be in a separate patch, as I
expected reverts of the test.
2024-09-12 13:38:53 -07:00
Charlie Barto
81935c5e96
[compiler-rt] [MSVC] Detect MSVC as a compiler-id for lit. (#108255)
This is only for "real" msvc and is to support running sanitizer tests
with "real" MSVC. Most compiler-rt tests do not yet pass with msvc,
which will be addressed in future PRs for asan, sanitizer_common, and
the fuzzer.

We've been using these changes to lit to run CI for the version of
address sanitizer that ships with MSVC, by upstreaming them we can avoid
being broken by future lit changes and allow contributors (importantly
_us_) to run the MSVC tests on changes developed in the open.
2024-09-12 10:30:13 -07:00
Vitaly Buka
ee9264522c
[sanitizer] Change GetDTLSRange (#108345)
We only need to change size, tls_beg should be unchanged.
2024-09-12 10:27:54 -07:00
Saleem Abdulrasool
73535076f2 builtins: replicate aarch64.c change into aarch64.h
Perform the same macro expansion in the header to improve handling
the various ARM64 environments which use different CPU architecture
identification macro spellings.
2024-09-12 08:42:51 -07:00
Vitaly Buka
b07f1be92c
[sanitizer] Remove DTLS_on_libc_memalign (#108120)
`DTLS_on_libc_memalign` is called from primary
allocator, so `__sanitizer_get_allocated_begin`
should also be aware of allocation,
and correctly handled by `GetDTLSRange`.
2024-09-12 00:50:54 -07:00
Charlie Barto
447b32fb19
[asan] add the new/delete code back to RTAsan_dynamic (#108329)
the new/delete code was removed from RTAsan_dynamic in
https://github.com/llvm/llvm-project/pull/107899, but that broke things
on macos. This reverts the offending change.
2024-09-11 23:28:49 -07:00
Charlie Barto
e31efd8f6f
[asan][windows] use __builtin_function_address to avoid problematic codegen in weak function registration (#108327)
Previously we were relying on optnone for this, but that didn't seem to
be sufficient.
2024-09-11 23:26:22 -07:00
tmiasko
ae0ed3d586
[lsan] Fix free(NULL) interception during initialization (#106912)
Previously an attempt to free a null pointer during initialization would
fail on ENSURE_LSAN_INITED assertion (since a null pointer is not owned
by DlsymAlloc).
2024-09-11 15:37:02 -07:00
Vitaly Buka
1797174ea6
[NFC][sanitizer] Commit test for #106912 (#108289)
Almost all sanitizers already support the test.
* Tsan does not use DlsymAlloc yet.
* Lsan will support with #106912.

memprof,rtsan,nsan are not tested as part of
sanitizer_common, but we should keep them here to
show up when it happen.

---------

Co-authored-by: Xiaofeng Tian <110771974+txff99@users.noreply.github.com>
2024-09-11 14:44:06 -07:00
Chris Apple
ec7c8cd45f
[compiler-rt][NFC] Add preprocessor definitions for 64 bit file interceptors that were missing (#108059)
These are needed in #108057
2024-09-11 15:34:45 -06:00
ChiaHungDuan
63d8bd2727
[scudo] Add thread-safety annotation on getMemoryGroupFragmentationIn… (#108277)
Add thread-safety annotation on getMemoryGroupFragmentationInfoInRegion
2024-09-11 14:22:47 -07:00
Saleem Abdulrasool
4570984e7f builtins: honour _M_ARM64 as __aarch64__
When clang is used as `clang-cl`, we use MSVC style macros. The spelling
of `__aarch64__` is converted to `_M_ARM64`. Account for this
alternative spelling in the conditional check. While in the area, add a
tertiary spelling of `__arm64__` to ensure that we catch more of the
variants.
2024-09-11 12:16:24 -07:00
ChiaHungDuan
323911de27
Reapply "[scudo] Fix the logic of MaxAllowedFragmentedPages" (#108130) (#108134)
This reverts commit 76151c449080b7239c8b442291514a4300d51cba.

Also changed to check MaxAllowedFragmentedPages.
2024-09-10 22:24:06 -07:00
ChiaHungDuan
76151c4490
Revert "[scudo] Fix the logic of MaxAllowedFragmentedPages" (#108130)
Reverts llvm/llvm-project#107927

We are supposed to check the MaxAllowedFragmentedPages instead.
2024-09-10 18:56:49 -07:00
SahilPatidar
68f31aaae9
[ORC][Runtime] Add dlupdate for MachO (#97441)
With the help of @lhames, This pull request introduces the `dlupdate`
function in the ORC runtime. `dlupdate` enables incremental execution of
new initializers introduced in the REPL environment. Unlike traditional
`dlopen`, which manages initializers, code mapping, and library
reference counts, `dlupdate` focuses exclusively on running new
initializers.
2024-09-11 10:50:01 +10:00
ChiaHungDuan
6e854a6a01
[scudo] Fix the logic of MaxAllowedFragmentedPages (#107927)
MTE doesn't support MaxReleasedCachePages which may break the assumption
that only the first 4 pages will have memory tagged.
2024-09-10 17:46:02 -07:00