19565 Commits

Author SHA1 Message Date
Csanád Hajdú
c088b5ffca
[compiler-rt][AArch64] Add GCS property in assembly files (#152502)
Only BTI and PAC properties were added previously.

Fixes https://github.com/llvm/llvm-project/issues/152427.
2025-08-07 16:40:36 +02:00
Sharjeel Khan
d9f9064cfa
[ubsan_minimal] Add address argument to Android's abort message function (#152419)
https://github.com/llvm/llvm-project/pull/152192 forgot to make the
argument changes to Android code in UBsan minimal causing a build error
for Android LLVM:
```
/b/f/w/src/git/out/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:102:3: error: no matching function for call to 'format_msg'
  102 |   format_msg(kind, caller, msg_buf, msg_buf + sizeof(msg_buf));
      |   ^~~~~~~~~~
/b/f/w/src/git/out/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:37:13:
note: candidate function not viable: requires 5 arguments, but 4 were
provided
   37 | static void format_msg(const char *kind, uintptr_t caller,
      |             ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |                        const uintptr_t *address, char *buf,
const char *end) {
```
This change adds the address argument to abort_with_message just like
__ubsan_report_error_fatal so it can be passed to format_msg.
2025-08-06 20:36:21 -07:00
Thurston Dang
01472d8e35
[NFC][asan] Update shadow mapping comments for AArch64 non-Android Linux (#152412)
This adds commentary to explain why ASan does not work for AArch64
non-Android Linux with 39-bit and 42-bit VMAs (e.g.,
https://github.com/llvm/llvm-project/issues/145259).

Additionally, it updates the 42-bit VMA shadow map comment, which has
been outdated for the last 10 years
(18b2258c92df93c83bc7fce94c20baff3c06e2c6 changed 39-bit and 42-bit to
use the same offset), and adds a comment for the 48-bit VMA shadow map.
2025-08-06 18:06:05 -07:00
Andrew Lazarev
a1209d8686
[ubsan_minimal] Allow UBSan handler from Minimal runtime to accept arguments (#152192)
+ Changed type_mismatch minimal handler to accept and print pointer.
This will allow to distinguish null pointer use, misallignment and
incorrect object size.

The change increases binary size by ~1% and has almost no performance
impact.

Fixes #149943
2025-08-06 11:21:49 -07:00
Dan Blackwell
b24ad98caa
[sanitizer_common] Disable SanitizerCommon lsan tests on Apple arm64 (#151929)
There is an issue tracking lsan incompatibility on these platforms:
https://github.com/llvm/llvm-project/issues/131678. Many of these tests
are currently failing and creating CI noise.

rdar://157252316
2025-08-06 10:08:57 +01:00
Thurston Dang
435b8b51dc
[sanitizer] Don't TestPTrace() if SPARC; don't give up if internal_fork() fails (#152072)
Fixes corner cases of https://github.com/llvm/llvm-project/pull/151406:
- Don't run TestPTrace() on SPARC, because internal_fork() on SPARC
actually calls __fork(). We can't safely __fork(), because it's possible
seccomp has been configured to disallow fork() but allow clone().
- if internal_fork() fails for whatever reason, we shouldn't give up. It
is strictly worse to give up early than to attempt StopTheWorld.

Also updates some comments/TODOs.
2025-08-05 16:31:35 -07:00
gulfemsavrun
4a13f0912a
Revert "[compiler-rt][test] Apply CFLAGS from sanitizer_common to all tests" (#152177)
Reverts llvm/llvm-project#120798 because it caused an AddressSanitizer
test breakage in global-overflow-bfd.cpp:

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8707434189452310849/overview
2025-08-05 10:15:27 -07:00
Thurston Dang
abc394c657 [sanitizer] Fix-forward "[sanitizer] Print diagnostic if ptrace syscall fails #151406"
Use internal__exit instead of _exit

Buildbot: https://lab.llvm.org/buildbot/#/builders/174/builds/22276
2025-08-04 22:50:31 +00:00
Thurston Dang
a708b4bf21
[sanitizer] Print diagnostic if ptrace syscall fails (#151406)
StopTheWorld() clones a child process (with shared virtual address space
and shared TLS) that calls ptrace before releasing a mutex; the parent
process yields until the mutex is unlocked. If seccomp kills the child
process, the parent process will silently hang. The parent process
cannot use waitpid to detect that the child process has been killed,
because the processes share errno.

This patch forks the process one-time to test whether ptrace is allowed.
If it fails, it prints an informational message (though it does not
abort the sanitizer).

Fixes https://github.com/llvm/llvm-project/issues/150380 and
https://github.com/google/sanitizers/issues/777
2025-08-04 15:39:56 -07:00
Aaron Puchert
b757bc8b13
[compiler-rt][test] Apply CFLAGS from sanitizer_common to all tests (#120798)
Sanitizer-specific tests don't use the sanitizer_common flags, but the
issues they address probably also apply to the individual sanitizers.

This was observed in #119071: moving a test from sanitizer_common to
msan broke it in builds with CMAKE_SYSROOT set, because the --sysroot
argument was no longer applied to the test.
2025-08-04 22:39:07 +02:00
jinge90
de7ee884a6
Relax muldc3 test to avoid precision issue (#151663) 2025-08-02 13:09:21 +08:00
Dan Blackwell
23bcc239ac
[TSan] Fix tsan_rtl_access printf type warnings (#151508)
When compiling TSan I currently get a handful of warnings like this:
"warning: format specifies type 'void *' but the argument has type 'X
*'". This patch adds the necessary casts to fix them.
2025-08-01 08:34:48 -07:00
Dan Blackwell
e7e74945a6
[TSan] Fix asan_mac.cpp function pointer cast warnings (#151517)
Fixes these compiler warnings:
```
.../llvm-project/compiler-rt/lib/asan/asan_mac.cpp:252:4: warning: cast from 'dispatch_function_t' (aka 'void (*)(void *)') to 'void (*)(void *, size_t)' (aka 'void (*)(void *, unsigned long)') converts to incompatible function type [-Wcast-function-type-mismatch]
  252 |   ((void (*)(void *, size_t))asan_ctxt->func)(asan_ctxt->block, iteration);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../llvm-project/compiler-rt/lib/asan/asan_mac.cpp:259:32: warning: cast from 'void (*)(void *, size_t)' (aka 'void (*)(void *, unsigned long)') to 'dispatch_function_t' (aka 'void (*)(void *)') converts to incompatible function type [-Wcast-function-type-mismatch]
  259 |       alloc_asan_context(ctxt, (dispatch_function_t)work, &stack);
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~
```
2025-08-01 08:33:23 -07:00
Andrew Lazarev
f8a2ed7aac
[ubsan_minimal] Introduce custom substitutions for clang with minimal runtime (#151613)
Make clang calls using custom suffix to allow correct calls without
reading cfg.py. As I see tests for other other specific checks are doing
it too (e.g. %clangxx_asan).
2025-07-31 18:10:55 -07:00
Snehasish Kumar
d1e43f6c1a
[MemProf] Write out raw profile bytes in little endian. (#150375)
Instead of writing out in native endian, write out the raw profile bytes
in little endian. Also update the MIB data in little endian. Also clean
up some lint and unused includes in rawprofile.cpp.
2025-07-30 21:44:20 -07:00
Christopher Ferris
ef962752d9
[scudo] Allow the quarantine code to be compiled out (#151064)
Add a new configuration option QuarantineDisabled that allows all of the
quarantine code to be compiled out.

Add new tests that verify that the code is removed properly.

On Android, this saves ~4000 bytes for 32 bit and ~6000 bytes for 64
bit.

On Android, I used some microbenchmarks that do malloc/free in a loop
and for allocations in the primary, the performance is about the same
for both 32 bit and 64 bit. For secondary allocations, I saw ~8% speed
up on 32 bit and ~3% on 64 bit speed up which feels like it could just
be code size improvements.
2025-07-30 19:41:14 -07:00
Snehasish Kumar
08e40c12fa
Reapply "[MemProf] Change histogram storage from uint64_t to uint16_t… (#151431)
Reapply #147854 after fixes merged in #151398.

Change memory access histogram storage from uint64_t to uint16_t to
reduce profile size on disk. This change updates the raw profile format
to v5. Also add a histogram test in compiler-rt since we didn't have one
before. With this change the histogram memprof raw for the basic test
reduces from 75KB -> 20KB.
2025-07-30 18:28:53 -07:00
Snehasish Kumar
8377f90c21
[MemProf] Add sanitizer interface decls for histogram funcs. (#151398)
Add the necessary sanitizer interface decls required when the memprof
runtime is built in dynamic mode.  This was a latent issue since we didn't
add tests for the histogram feature in compiler-rt. These tests are run
with `ninja check-memprof-dynamic`.  I discovered this after the CI
failures for #147854.
2025-07-30 16:27:10 -07:00
Snehasish Kumar
24f9482abd
Revert "[MemProf] Change histogram storage from uint64_t to uint16_t" (#151382)
Reverts llvm/llvm-project#147854

Test failure when building with gcc.
https://lab.llvm.org/buildbot/#/builders/174/builds/21989
2025-07-30 12:36:45 -07:00
Snehasish Kumar
1bf89e90a8
[MemProf] Change histogram storage from uint64_t to uint16_t (#147854)
Change memory access histogram storage from uint64_t to uint16_t to
reduce profile size on disk. This change updates the raw profile format
to v5. Also add a histogram test in compiler-rt since we didn't have one
before. With this change the histogram memprof raw for the basic test
reduces from 75KB -> 20KB.
2025-07-30 11:52:31 -07:00
Dan Blackwell
26f9166ca1
[TSan][compiler-rt] Defer symbolization of Reports to as late as possible (#151120)
This is the refactoring portion of:
https://github.com/llvm/llvm-project/pull/149516. My aim is for this
change to replicate current behaviour - just with Symbolization done
explicitly (and later than previously).

This change will enable us to perform symboliaztion after releasing the
locks in `OutputReport`; this is necessary on Apple platforms in order
to avoid a deadlock.
2025-07-30 09:20:33 -07:00
Aiden Grossman
88c23ada9a Reapply "[compiler-rt] Remove %T from tests (#151265)"
This reverts commit 3c3523c15850f3c42de35ae725288368414e4e91.

Keeping the directory structure the same as before fixes the failures.
They trivially reproduced locally and only passed before because I was
not cleaning up the temp test directory in between invocations.
2025-07-30 15:13:13 +00:00
Aiden Grossman
3c3523c158 Revert "[compiler-rt] Remove %T from tests (#151265)"
This reverts commit 05bfcd8ae3f1764145b0d7f491f059bcf8537da3.

This broke some buildbots.

https://lab.llvm.org/buildbot/#/builders/66/builds/17200
https://lab.llvm.org/buildbot/#/builders/72/builds/13632
https://lab.llvm.org/buildbot/#/builders/199/builds/4902
2025-07-30 04:10:13 +00:00
Aiden Grossman
05bfcd8ae3
[compiler-rt] Remove %T from tests (#151265)
%T has been deprecated for about seven years and use is to be avoided
given it doesn't actually create a unique test directory per test, which
can lead to races. Remove it from compiler-rt so we can hopefully remove
it from within llvm-lit.

This patch just touches the tests. There are still uses in some
substitutions defined in compiler-rt/test/lit.common.cfg.py that I want
to leave for a separate patch because it is quite a bit more thorny.
2025-07-29 19:02:30 -07:00
Dan Blackwell
ba2e49cac9
[libFuzzer] Mark libFuzzer SIGTRAP test unsupported on windows (#151109)
This change is based on the UNSUPPORTED mark from the existing sigusr
test
c59cc54284/compiler-rt/test/fuzzer/sigusr.test (L4)
2025-07-29 17:08:02 -04:00
davidtrevelyan
875491f59e
[rtsan][compiler-rt] Fix ioctl test causing segfault on exit (#151182)
I was observing segfaults at executable exit in the rtsan instrumented
unit tests. Bisecting the offending test led to observing that this test
is not using our safe test fixture for anything involving a file
descriptor. Changing to use the fixture eliminated the segfault on exit.
2025-07-29 17:31:19 +01:00
Daniil Kovalev
19ba224fb8
[PAC][compiler-rt] Fix init/fini array signing schema (#150691)
When `ptrauth_calls` is present but `ptrauth_init_fini` is not, compiler
emits raw unsigned pointers in `.init_array`/`.fini_array` sections.
Previously, `__do_init`/`__do_fini` pointers, which are explicitly added
to the sections, were implicitly signed (due to the presense of
`ptrauth_calls`), while all the other pointers in the sections were
implicitly added by the compiler and thus non-signed.. As a result, the
sections contained a mix of unsigned function pointers and function
pointers signed with default signing schema.

This patch introduces use of inline assembly for this particular case,
so we can manually specify that we do not want to sign the pointers.

Note that we cannot use `__builtin_ptrauth_strip` for this purpose since
its result is not a constant expression.
2025-07-29 04:29:04 +00:00
Christopher Ferris
30532c13d2
[scudo] Fix secondary caching for mte (#150156)
The current code always unmaps a secondary allocation when MTE is
enabled. Fix this to match the comment, namely only unmap if MTE was
enabled and is no longer enabled after acquiring the lock.

In addition, allow quaratine to work in the secondary even if MTE is not
enabled.
2025-07-28 12:56:16 -07:00
Dan Blackwell
33cc58f46f
[compiler-rt][libFuzzer] Add support for capturing SIGTRAP exits. (#149120)
Swift's FatalError raises a SIGTRAP, which currently causes the fuzzer
to exit without writing out the crashing input.

rdar://142975522
2025-07-28 07:46:48 -07:00
Chris Apple
26808ef7c2
[rtsan] Disable pthread_cond_wait test (#150807)
Related to #150776 and #146120

Disable to fix test runner:
https://lab.llvm.org/buildbot/#/builders/208/builds/3123
2025-07-26 16:27:32 -07:00
Chris Apple
b60aed6fba
[rtsan] Add test for pthread_cond_wait segfault (#150776)
Introduce the test from
https://github.com/llvm/llvm-project/issues/146120

For future readers of this PR, if this test causes a segfault please
comment out the line indicated by the comment (or revert this entire
commit).

My plan is to commit this, see if any test runners fail, then submit the
fix in a follow on.

I cannot repro this bug on my machine so I need some confirmation of the
bug being fixed as it is submitted.
2025-07-26 13:33:48 -07:00
Andreas Schwab
c99b1bcd50
Remove reference to obsolete termio ioctls
The termio ioctls are no longer used after commit 59978b21ad9c
("[sanitizer_common] Remove interceptors for deprecated struct termio
(#137403)"), remove them.  Fixes this build error:

../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:765:27: error: invalid application of ‘sizeof’ to incomplete type ‘__sanitizer::termio’
  765 |   unsigned IOCTL_TCGETA = TCGETA;
      |                           ^~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:769:27: error: invalid application of ‘sizeof’ to incomplete type ‘__sanitizer::termio’
  769 |   unsigned IOCTL_TCSETA = TCSETA;
      |                           ^~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:770:28: error: invalid application of ‘sizeof’ to incomplete type ‘__sanitizer::termio’
  770 |   unsigned IOCTL_TCSETAF = TCSETAF;
      |                            ^~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:771:28: error: invalid application of ‘sizeof’ to incomplete type ‘__sanitizer::termio’
  771 |   unsigned IOCTL_TCSETAW = TCSETAW;
      |                            ^~~~~~~
Part-of: https://github.com/llvm/llvm-project/pull/138822
Closes: https://github.com/llvm/llvm-project/pull/138822
2025-07-25 19:44:34 +01:00
Kunqiu Chen
84dc97e51e
[MSan] Fix check overflow in a test case (#150429)
Supplement to PR #144073

Previously, _msan_check_mem_is_initialized.cpp_ initialized a 32-byte
stack array, but checked the shadow for the offset range [12, 42),
exceeding the stack array size.

MSan does not guarantee that the shadow corresponding to the overflow
part is 0, so it is undefined to require the overflow part to be
unpoisoned.
2025-07-25 14:05:53 +08:00
cqwrteur
0a17483c48
[sanitizer] Remove usage of termios ioctl constants on Linux glibc since 2.41 (#149140)
glibc 2.42 made all usage of termios ioctl constants strictly internal

Therefore, we remove all usage for those removed constants.

This should only apply for Linux.

Fix #149103

Reference:

3d3572f590

@fweimer-rh @tstellar
2025-07-24 12:49:49 -07:00
thetruestblue
5ce04b473c
[ASan][Darwin][GCD] Add interceptor for dispatch_apply (#149238)
ASan had a gap in coverage for wqthreads blocks submitted by
dispatch_apply

This adds interceptor for dispatch_apply and dispatch_apply_f and adds a
test that a failure in a dispatch apply block contains thread and stack
info.

rdar://139660648
2025-07-23 10:27:09 -07:00
Jake Egan
8e072b9d49
[sanitizer_common][nfc] Rename tid_t to avoid conflicting declarations (#149011)
`tid_t` is also defined in the AIX header `/usr/include/sys/types.h`
which is included by system `pthread.h`. The use of `tid_t` by AIX is
conforming according to
[POSIX](https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html):
> Implementations may add symbols to the headers shown in the following
table [ ... ]
2025-07-23 09:39:19 -04:00
Zack Johnson
8c4fa11dd8
[compiler-rt][MSVC] Update check to include clang-cl (#150108)
Follow up to #149823 to include `clang-cl` for AArch64 builtins sources.
2025-07-22 21:19:33 -04:00
Justin King
681c2ee4df
asan: refactor interceptor allocation/deallocation functions (#145087)
Do some refactoring to allocation/deallocation interceptors. Expose
explicit per-alloc_type functions and stop accepting explicit AllocType.
This ensures we do not accidentally mix.

NOTE: This change rejects attempts to call `operator new(<some_size>,
static_cast<std::align_val_t>(0))`.

For https://github.com/llvm/llvm-project/issues/144435

Signed-off-by: Justin King <jcking@google.com>
2025-07-22 15:47:23 -07:00
Matthias Braun
abdd654feb
build_symbolizer.sh: Ensure libcxx include path comes first (#149431)
libc++ expects to come first in the search path, before libc. See for
example:
https://github.com/llvm/llvm-project/blob/main/libcxx/include/cstddef#L45

Make sure the C++ include path comes first even if custom paths to libc
and other packages are passed in via the `FLAGS` variable.
2025-07-22 12:19:16 -07:00
int-zjt
006c0c8767
[sanitizer] Fix libcxx cache existence check in symbolizer build (#149249)
The script incorrectly checked ${LLVM_BUILD}/build.ninja to determine if
cached libcxx is available, while it should be checking the actual
libcxx build directory at ${LIBCXX_BUILD}/build.ninja.
2025-07-22 12:18:04 -07:00
Deák Lajos
3fc723ec2c
[compiler-rt][sanitizer] fix msghdr for musl (#136195)
Ran into the issue on Alpine when building with TSAN that
`__sanitizer_msghdr` and the `msghdr` provided by musl did not match.
This caused lots of tsan reports and an eventual termination of the
application by the oom during a `sendmsg`.
2025-07-22 11:31:28 -07:00
Nico Weber
30d3bb598f [compiler-rt] Tweak cmake formatting
No behavior change. For easier extraction of sources by grepping
(such as done by llvm/utils/gn/build/sync_source_lists_from_cmake.py).
2025-07-22 09:22:47 -04:00
Zack Johnson
7cfd32a1d5
[compiler-rt][MSVC] Conditionally remove emupac.cpp for msvc (#149823)
#148094 introduces logic for emulated PAC, which utilizes language
extensions not available on MSVC.
2025-07-22 08:54:36 -04:00
Fabio D'Urso
fcdcc4ea7a
[scudo] Make Ptr volatile so that the malloc and free calls are not optimized out (#149944)
This fixes the test failure seen in the discussion about
https://github.com/llvm/llvm-project/pull/148066.
2025-07-22 03:31:35 +02:00
Jens Reidel
a5d6fa68e3
[compiler-rt][Mips] Fix stat size check on mips64 musl (#143301)
The sizes of the struct stat on MIPS64 differ in musl vs glibc.

See https://godbolt.org/z/qf9bcq8Y8 for the proof. Prior to this change,
compilation for MIPS64 musl would fail.

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2025-07-18 20:01:44 -04:00
Jake Egan
4e6b843cf5
[asan] Revert global check for non-AIX (#149245)
287b24e1899eb6ce62eb9daef5a24faae5e66c1e moved the
`GetGlobalAddressInformation` call earlier, but this broke a chromium
test, so make this workaround for AIX only.
2025-07-17 15:50:44 -04:00
Peter Collingbourne
e68efed71b Fix more compiler-rt tests after #149015. 2025-07-17 12:35:18 -07:00
Peter Collingbourne
2c0c87be12 Speculative buildbot fix. 2025-07-17 11:28:36 -07:00
Peter Collingbourne
3fa07ed5b3
Rename config.host_os to config.target_os.
config.host_os is derived from CMAKE_SYSTEM_NAME
which specifies the target. See:
https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html

To reduce confusion, rename it to config.target_os.

The variable name config.target_os was already being used by the Orc
tests. Rename it to config.orc_test_target_os with a FIXME to remove.

Reviewers: JDevlieghere, MaskRay

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/149015
2025-07-17 11:12:29 -07:00
thetruestblue
1c541aa9f9
[Apple][NFC] Update macOS aligned version for lit config (#143576)
This updates the aligned version for version 26.

Note: This change is for correctness only and has no functional impact
currently. `get_macos_aligned_version` is currently only consumed when
substituting flags based on min version.

rdar://152851947
2025-07-16 20:17:37 -07:00