19591 Commits

Author SHA1 Message Date
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
Christopher Ferris
34b3ea367c
[scudo] Make release to OS test more specific. (#147852)
The original version of ResidentMemorySize could be a little flaky.
Replace the test with a version that verifies exactly how much of the
map is resident.
2025-07-16 19:25:57 -07:00
Peter Collingbourne
968d38d1d7 compiler-rt: test: Use the host instead of the target to select %expect_crash.
When running tests in a cross-compiled build, %expect_crash is
run on the host, not the target, so we need to check the host
OS. config.host_os surprisingly refers to the target OS because it
is derived from CMAKE_SYSTEM_NAME which specifies the target. See:
https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html

Another speculative fix for:
https://lab.llvm.org/buildbot/#/builders/193/builds/9070
2025-07-15 19:46:12 -07:00
Peter Collingbourne
de31584001
Reapply "compiler-rt: Introduce runtime functions for emulated PAC."
This reverts commit 0c0aa56cdcf1fe3970a5f3875db412530512fc07.

This time with the following fixes for buildbot failures:
- Add underscore prefixes to symbol names on Apple platforms.
- Modify the test so that it skips the crash tests on platforms where
  they are not expected to pass:
  - Platforms that implement FEAT_PAuth but not FEAT_FPAC (e.g.
    Apple M1, Cortex-A78C)
  - Platforms where DA key is disabled (e.g. older Linux kernels,
    Linux kernels with PAC disabled, likely Windows)

Original commit message follows:

The emulated PAC runtime functions emulate the ARMv8.3a pointer
authentication instructions and are intended for use in heterogeneous
testing environments. For more information, see the associated RFC:
https://discourse.llvm.org/t/rfc-emulated-pac/85557

Reviewers: mstorsjo, pawosm-arm, atrosinenko

Reviewed By: atrosinenko

Pull Request: https://github.com/llvm/llvm-project/pull/148094
2025-07-14 13:13:32 -07:00
Christopher Ferris
309bb1ed68
[scudo] Fix c wrappers double free test. (#148066)
The previous test simply tried to double free the pointer in the
EXPECT_DEATH macro. Unfortunately, the gtest infrastructure can allocate
a pointer that happens to be the previously freed pointer. Thus the free
doesn't fail since the spawned process does not attempt to free all of
the pointers allocated in the original test.

NOTE: Scudo should be checked to make sure that the TSD is not always
returning pointers in the same order they are freed. Although this
appears to be a problem with a program that only does a small number of
allocations.
2025-07-14 11:15:10 -07:00
Jake Egan
a742ee6a43
[sanitizer_common][NFC] Fix sanitizer_platform_limits_posix.h formatting (#147864)
From running `clang-format` on the whole file.
2025-07-11 21:15:57 -04:00
Peter Collingbourne
0c0aa56cdc Revert "compiler-rt: Introduce runtime functions for emulated PAC."
As well as followup "builtins: Speculative MSVC fix."

This reverts commits 5b1db59fb87b4146f827d17396f54ef30ae0dc40 and
f1c4df5b7bb79efb3e9be7fa5f8176506499d0a6.

Needs fixes for failing tests which will take time to implement.
2025-07-10 13:16:36 -07:00
Jessica Clarke
9320d1d484
[compiler-rt] Don't handle Linux-specific shmctl commands in sanitizer (#143116)
Despite being defined in the system headers, these commands are not in
fact part of the FreeBSD system call interface. They exist solely for
the Linuxulator, i.e. running Linux binaries on FreeBSD, and any attempt
to use them from a FreeBSD binary will return EINVAL. The fact we needed
to define _KERNEL (which, as the name implies, means we are compiling
the kernel) to even get the definition of shminfo should have been a
strong indicator that IPC_INFO at least was not a userspace interface.
2025-07-10 19:33:24 +01:00
Hervé Poussineau
34f49aa2e9
[compiler-rt][sanitizer] Add Windows MIPS32 support (#145110)
As LLVM supports mipsel-windows-gnu and mipsel-windows-msvc triples,
also support this configuration in compiler-rt
2025-07-10 17:52:19 +01:00
Takuto Ikuta
f7cdff7bdd
[compiler-rt] Include missing headers for libFuzzer (#146828)
This is to fix modules build errors in chromium like
*
https://ci.chromium.org/ui/p/chromium/builders/try/linux-libfuzzer-asan-rel/2292144/overview
*
https://ci.chromium.org/ui/p/chromium/builders/try/linux-libfuzzer-asan-rel/2292444/overview

---------

Co-authored-by: Petr Hosek <phosek@google.com>
2025-07-10 10:56:08 +02:00
Peter Collingbourne
f1c4df5b7b builtins: Speculative MSVC fix.
Attempt to fix these build failures:
https://lab.llvm.org/buildbot/#/builders/107/builds/12601

The suspected cause is that #133530 caused us to start
passing -std:c11 to MSVC, which activated this code path
that uses _Complex, which MSVC does not support. See:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/complex-math-support

Fix it by also checking _MSC_VER.
2025-07-09 18:32:41 -07:00
Jake Egan
d286540734
[sanitizer_common] Introduce SANITIZER_MMAP_BEGIN macro (#147645)
To prepare for other platforms, such as 64-bit AIX, that have a non-zero
mmap beginning address.

---------

Co-authored-by: David Justo <david.justo.1996@gmail.com>
2025-07-09 20:14:23 -04:00
Peter Collingbourne
5b1db59fb8
compiler-rt: Introduce runtime functions for emulated PAC.
The emulated PAC runtime functions emulate the ARMv8.3a pointer
authentication instructions and are intended for use in heterogeneous
testing environments. For more information, see the associated RFC:
https://discourse.llvm.org/t/rfc-emulated-pac/85557

Reviewers: llvm-beanz, petrhosek

Pull Request: https://github.com/llvm/llvm-project/pull/133530
2025-07-09 16:18:37 -07:00
ChiaHungDuan
4ea0ef2e94
[scudo] Move out the definitions of member functions in primary allocators (#147601)
This greatly improves the readability so that we are able to tell the
design by the concise class definition.
2025-07-09 13:42:02 -07:00
Justin King
64453c802e
rtsan: Support free_sized and free_aligned_sized from C23 (#145085)
Adds support to RTSan for `free_sized` and `free_aligned_sized` from
C23.

Other sanitizers will be handled with their own separate PRs.

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

Signed-off-by: Justin King <jcking@google.com>
2025-07-09 10:36:59 -07:00
Justin King
5cf4537fe1
hwasan: refactor new/delete interceptor macros (#146698)
Same as #146696 but for #145357.

---------

Signed-off-by: Justin King <jcking@google.com>
2025-07-08 15:19:04 -07:00
ChiaHungDuan
8b65c9d1ed
[scudo] Make block storage in TransferBatch trailing objects (#144204)
This allows us to change the number of blocks stored according to the
size of BatchClass.

Also change the name `TransferBatch` to `Batch` given that it's never
the unit of transferring blocks.
2025-07-08 11:07:05 -07:00
Jake Egan
875581b3ca
[asan][AIX] Move import/export lists to an AIX-specific subdirectory (#145936)
This makes it more clear that these lists are AIX-specific.
2025-07-08 10:06:54 -04:00
Brad Smith
18292a4ea2
[sanitizer_common] Drop remaining support for Android 5 or older (#146187)
Dependent on https://github.com/llvm/llvm-project/pull/145227
2025-07-07 22:01:44 -04:00
Brad Smith
fe56f69810
[sanitizer_common] Drop support for Android 5 (#145227) 2025-07-07 21:06:07 -04:00
Dan Blackwell
a0e8462770
[compiler-rt][sanitizer_common] Improve handling of env vars for iOS simulator tests (#146721)
* Fix splitting of arguments such as `LSAN_OPTIONS=suppressions=lsan.supp`
* Prevent environment variables set in parent process being overwritten
* Replace hard-coded `env` with `%env` to allow overriding depending on target
* Replace deprecated `pipes` usage with `shlex`
* Run formatter over `iossim_env.py`
2025-07-03 10:25:08 -07:00
David Justo
0d7e64f5d2
[ASan][Windows] Honor asan config flags on windows when set through the user function (#122990)
**Related to:** https://github.com/llvm/llvm-project/issues/117925 
**Follow up to:** https://github.com/llvm/llvm-project/pull/117929

**Context:**
As noted in the linked issue, some ASan configuration flags are not
honored on Windows when set through the `__asan_default_options` user
function. The reason for this is that `__asan_default_options` is not
available by the time `AsanInitInternal` executes, which is responsible
for applying the ASan flags.

To fix this properly, we'll probably need a deep re-design of ASan
initialization so that it is consistent across OS'es.
In the meantime, this PR offers a practical workaround.

**This PR:** refactors part of `AsanInitInternal` so that **idempotent**
flag-applying steps are extracted into a new function `ApplyOptions`.
This function is **also** invoked in the "weak function callback" on
Windows (which gets called when `__asan_default_options` is available)
so that, if any flags were set through the user-function, they are
safely applied _then_.

Today, `ApplyOptions` contains only a subset of flags. My hope is that
`ApplyOptions` will over time, through incremental refactorings
`AsanInitInternal` so that **all** flags are eventually honored.

Other minor changes:
* The introduction of a `ApplyAllocatorOptions` helper method, needed to
implement `ApplyOptions` for allocator options without re-initializing
the entire allocator. Reinitializing the entire allocator is expensive,
as it may do a whole pass over all the marked memory. To my knowledge,
this isn't needed for the options captured in `ApplyAllocatorOptions`.
* Rename `ProcessFlags` to `ValidateFlags`, which seems like a more
accurate name to what that function does, and prevents confusion when
compared to the new `ApplyOptions` function.
2025-07-02 15:37:28 -07:00
Justin King
e3edc1bd87
asan: refactor new/delete interceptor macros (#146696)
Refactors new/delete interceptor macros per the discussion in #145087.

Signed-off-by: Justin King <jcking@google.com>
2025-07-02 11:18:55 -07:00
Kunqiu Chen
0aafeb8ba1
Reland [TSan] Clarify and enforce shadow end alignment (#146676)
#144648 was reverted because it failed the new sanitizer test
`munmap_clear_shadow.c` in IOS's CI.
That issue could be fixed by disabling the test on some platforms, due
to the incompatibility of the test on these platforms.

In detail, we should disable the test in FreeBSD, Apple, NetBSD,
Solaris, and Haiku, where `ReleaseMemoryPagesToOS` executes
`madvise(beg, end, MADV_FREE)`, which tags the relevant pages as 'FREE'
and does not release them immediately.
2025-07-02 20:28:30 +08:00
Kunqiu Chen
9eac5f72f6
Revert "[TSan] Clarify and enforce shadow end alignment" (#146674)
Reverts llvm/llvm-project#144648 due to a test failure of the new added
test case `munmap_clear_shadow.c` in IOS .
2025-07-02 20:11:11 +08:00