19609 Commits

Author SHA1 Message Date
Chris Apple
b983431c28
[rtsan] Fix issue when intercepted function was not execve in test (#144018) 2025-06-15 06:55:22 -07:00
Chris Apple
147a4c7743
[rtsan] Fix issue where close test would lead to crash (#144017) 2025-06-15 06:54:11 -07:00
Kunqiu Chen
2796c41249
[MSan] Fix minor issues in testcases (#144073)
Previously,
1. ifaddrs.cpp : mistake `size_t (xxx)` as `sizeof (xxx)`, resulting in 
inadequate checks.
2. qsort.cpp : mistake `kSize2` as `kSize1`, resulting in an unexpected
buffer overlow issue.
2025-06-14 14:59:36 +08:00
Kazu Hirata
cd573e0a54
[compiler-rt] Remove unused local variables (NFC) (#144010) 2025-06-12 22:45:08 -07:00
Charles Zablit
20d5d09e99
[compiler-rt] remove unused default in compiler-rt lit tests (#143738)
In https://github.com/llvm/llvm-project/pull/143183 was mistakenly added
a default value to `python_root_dir` in lit tests of compiler-rt.

This is unused by the lit tests of compiler-rt, as it was meant to be
used by `lldb`.

This patch removes this change.
2025-06-12 11:37:25 +01:00
Jameson Nash
082251bba4
[AArch64] fix trampoline implementation: use X15 (#126743)
AAPCS64 reserves any of X9-X15 for a compiler to choose to use for this
purpose, and says not to use X16 or X18 like GCC (and the previous
implementation) chose to use. The X18 register may need to get used by
the kernel in some circumstances, as specified by the platform ABI, so
it is generally an unwise choice. Simply choosing a different register
fixes the problem of this being broken on any platform that actually
follows the platform ABI (which is all of them except EABI, if I am
reading this linux kernel bug correctly
https://lkml2.uits.iu.edu/hypermail/linux/kernel/2001.2/01502.html). As
a side benefit, also generate slightly better code and avoids needing
the compiler-rt to be present. I did that by following the XCore
implementation instead of PPC (although in hindsight, following the
RISCV might have been slightly more readable). That X18 is wrong to use
for this purpose has been known for many years (e.g.
https://www.mail-archive.com/gcc@gcc.gnu.org/msg76934.html) and also
known that fixing this to use one of the correct registers is not an ABI
break, since this only appears inside of a translation unit. Some of the
other temporary registers (e.g. X9) are already reserved inside llvm for
internal use as a generic temporary register in the prologue before
saving registers, while X15 was already used in rare cases as a scratch
register in the prologue as well, so I felt that seemed the most logical
choice to choose here.
2025-06-11 21:49:01 -04:00
Jake Egan
d7c6cad744
[sanitizer_common] Implement interception on AIX (#138606)
Adjust AIX interceptor support in sanitizer_common. 

Issue: https://github.com/llvm/llvm-project/issues/138916
2025-06-11 20:22:15 -04:00
Aiden Grossman
3cef099ced
[TySan][CMake] Depend on tysan for check-tysan in runtimes build (#143597)
The runtimes build expects libclang_rt.tysan.a to be available, but the
check-tysan target does not actually depend on it when built using a
runtimes build with LLVM_ENABLE_RUNTIMES pointing at ./llvm. This means
we get test failures when running check-compiler-rt due to the missing
static archive.

This patch also makes check-tysan depend on tysan when we are using the
runtimes build.

This is causing premerge failures currently since we recently migrated
to the runtimes build.
2025-06-10 18:06:13 -07:00
Florian Mayer
32d2b6ba47
[HWASAN] Disable LSan test on Android (#143625)
Android HWASan does not support LSan.
2025-06-10 15:58:53 -07:00
Andrew Rogers
c30952592a
[compiler-rt] replicate changes from llvm/ProfileData/InstrProfData.inc (#143574)
## Purpose
The compiler-rt project `check-same-common-code.test` test case started
failing after #142861 was merged. This change addresses the failure.

## Overview
This patch replicates the changes made by #142861 to
llvm/include/llvm/ProfileData/InstrProfData.inc in the duplicated file
compiler-rt/include/profile/InstrProfData.inc. These files otherwise
match.

## Validation
Locally built `check-profile` target and verified
`check-same-common-code.test` now passes.
2025-06-10 10:45:21 -07:00
Victor Campos
a59a8ae1a9
[compiler-rt][ARM] Add missing PACBTI support to assembly aeabi functions (#142400)
Some of the aeabi functions were missing PACBTI support. The lack of it
resulted in exceptions at runtime if the running environment had PAC
and/or BTI enabled.

This patch adds this support. This involves the addition of PACBTI
instructions, depending on whether each of these features is enabled,
plus the saving and restoring of the PAC code that resides in r12. Some
of the common code has been put in preprocessor macros to reduce
duplication, but not all, especially since some register saving and
restoring is very specific to each context.
2025-06-10 10:20:42 +01:00
Peter Collingbourne
b3837f1392
cfi: Re-enable tests with lld on i386. NFCI.
Originally disabled because of #34200 but that bug has long since
been fixed.

Reviewers: fmayer

Reviewed By: fmayer

Pull Request: https://github.com/llvm/llvm-project/pull/143459
2025-06-09 16:41:13 -07:00
Sam Elliott
6f6dc9c8ba
[RISCV] Implement Feature Bits for B, E, H (#143436)
As defined in riscv-non-isa/riscv-c-api-doc#109.
2025-06-09 15:01:18 -07:00
Thurston Dang
a178c06add
[tsan] Don't symbolize stack traces if dl_iterate_phdr is not ready (#143199)
When a CHECK() fails during TSan initialization, it may segfault (e.g., https://github.com/google/sanitizers/issues/837#issuecomment-2939267531). This is because a failed CHECK() will attempt to print a symbolized stack trace, which requires dl_iterate_phdr, but the interceptor may not yet be set up.

This patch fixes the issue by not symbolizing the stack trace if the dl_iterate_phdr interceptor is not ready.
2025-06-09 09:29:16 -07:00
Charles Zablit
b62488f832
[lldb] make lit use the same PYTHONHOME for building and testing (#143183)
When testing LLDB, we want to make sure to use the same Python as the
one we used to build it.

This patch used the CMake variable `Python3_ROOT_DIR` to set the
`PYTHONHOME` env variable in LLDB lit tests, in order to ensure of this.

Please see https://github.com/swiftlang/swift/pull/82063 for the
original issue.
2025-06-09 10:20:39 +01:00
Victor Campos
a6532bd154
[compiler-rt][AArch64] Readd SME ABI routines files to the build (#142953)
Commit 75c3ff8c0b29f374d31ba99e51852f7f6851a6c8 inadvertently removed
some files from the build related to the SME ABI routines.

This patch fixes the issue by reintroducing the files to the build in
CMake.
2025-06-05 14:27:42 +01:00
Rainer Orth
70fce92027
[sanitizer_common] Remove <procfs.h> workaround on Solaris (#142758)
`sanitizer_procmaps_solaris.cpp` currently uses `#undef
_FILE_OFFSET_BITS` to hack around the fact that old versions of Solaris
`<procfs.h>` don't work in a largefile environment:

```
/usr/include/sys/procfs.h:42:2: error: #error "Cannot use procfs in the large file compilation environment"
   42 | #error  "Cannot use procfs in the large file compilation environment"
      |  ^~~~~
```

However, this is no longer an issue on either Solaris 11.4 or Illumos.
The workaround only existed for the benefit of Solaris 11.3. While that
had never been supported by LLVM, the sanitizer runtime libs were
imported into GCC's `libsanitzer`. With the removal of Solaris 11.3
support in GCC 15, this is no longer an issue and the workaround can be
removed.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
2025-06-05 08:34:09 +02:00
Florian Mayer
0eccf1385c
[LSan] skip leaks from dlerror (#142876)
We have known false positives, and the return value is never
user-managed anyway.
2025-06-04 20:04:16 -07:00
Florian Mayer
dbee0d5644
[NFCI] [hwasan] Add test demonstrating hwasan lsan false positive (#142874) 2025-06-04 20:02:51 -07:00
Thurston Dang
96c1fd40bc
[tsan] Change personality CHECK to Printf() + Die() (#142821)
Currently, if TSan needs to disable ASLR but is unable to do so, it
aborts with a cryptic message:
```
    ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:290 "((personality(old_personality | ADDR_NO_RANDOMIZE))) != ((-1))"
```
and a segfault
(https://github.com/google/sanitizers/issues/837#issuecomment-2939267531).

This patch replaces the CHECK with more user-friendly diagnostics and
suggestions via printf, followed by Die().
2025-06-04 13:23:50 -07:00
Victor Campos
75c3ff8c0b
[compiler-rt][AArch64] Provide basic implementations of SME memcpy/memmove in case of strictly aligned memory access (#138250)
The existing implementations, written in assembly, make use of unaligned
accesses for performance reasons. They are not compatible with strict
aligned configurations, i.e. with `-mno-unaligned-access`.

If the functions are used in this scenario, an exception is raised due
to unaligned memory accesses.

This patch reintroduces vanilla implementations for these functions to
be used in strictly aligned configurations. The actual code is largely
based on the code from https://github.com/llvm/llvm-project/pull/77496
2025-06-03 10:59:25 +01:00
Sam Elliott
458307694e
[compiler-rt][RISC-V] ILP32E/LP64E Save/Restore Grouping (#95398)
This changes the save/restore procedures to save/restore registers one
by one - to match the stack alignment for the ILP32E/LP64E ABIs, rather
than the larger batches of the conventional ABIs. The implementations of
the save routines are not tail-shared, to reduce the number of
instructions. I think this also helps code size but I need to check this
again.

I would expect (but haven't measured) that the majority of functions
compiled for the ILP32E/LP64E ABIs will in fact use both callee-saved
registers, and therefore there are still savings to be had, but I think
those can come later, with more data (especially if those changes are
just to the instruction sequences we use to save the registers, rather
than the number and alignment of how this is done).

This is a potential break for all of the ILP32E/LP64E ABI - we may
instead have to teach the compiler to emit the CFI information correctly
for the grouping we already have implemented (because that grouping
matches GCC). It depends on how intentional we think the grouping is in
the original ILP32E/LP64E save/restore implementation was, and whether
we think we can fix that now.
2025-06-02 21:18:55 -07:00
bernhardu
32973408bc
[win/asan] GetInstructionSize: Support 48 bX movabsq instructions. (#141625)
Created for Wine's memset by clang or mingw-gcc,
the latter places it quite at the start of the function:

```
   0x00006ffffb67e210 <memset+0>:       0f b6 d2                movzbl %dl,%edx
   0x00006ffffb67e213 <memset+3>:       48 b8 01 01 01 01 01 01 01 01   movabs $0x101010101010101,%rax
```

`3200      uint64_t v = 0x101010101010101ull * (unsigned char)c;`


290fd532ee/dlls/msvcrt/string.c (L3200)
2025-06-02 08:59:43 +02:00
Ellis Hoag
79da1c405d
[Sanitizer] Use %device_rundir/ to fix test (#142274)
I attempted to fix this test in
https://github.com/llvm/llvm-project/pull/142235 but we a new error.


https://lab.llvm.org/buildbot/#/builders/186/builds/9524/steps/26/logs/stdio
> ERROR: Can't create directory: /var

The path we want is actually at `/data/local/tmp/Output/var/...`.

I found `%device_rundir/` evaluates to this prefix on android, and
nothing otherwise.


f057a593a7/compiler-rt/test/lit.common.cfg.py (L658)
2025-05-31 07:33:11 -07:00
Ellis Hoag
74420ce524
[Sanitizer][NFC] Remove extra env from test (#142247) 2025-05-30 21:56:03 -07:00
Ellis Hoag
c979d1f812
[Sanitizer] Fix android test env issue (#142235)
I attempted to fix android tests in
https://github.com/llvm/llvm-project/pull/142207 (broken by
https://github.com/llvm/llvm-project/pull/141820). They are still
failing but now I have more info.


https://lab.llvm.org/buildbot/#/builders/186/builds/9504/steps/16/logs/stdio

ERROR: Can't open file: //foo.8862 (reason: 30)

I believe the reason is that on android the HOME and TMPDIR environment
variables are not being set correctly, or they are not read correctly.
(https://github.com/llvm/llvm-project/pull/142234#issuecomment-2923694428)
2025-05-30 19:26:26 -07:00
Ellis Hoag
986f519d1f
[Sanitizer][test] Emit to stderr to fix android (#142207)
This test is broken on android by
https://github.com/llvm/llvm-project/pull/141820

https://lab.llvm.org/buildbot/#/builders/186/builds/9498

> FileCheck error: '' is empty.

I suspect that on android printf only works if its emitted to stderr
because this use to work


a2ce564720/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_path_test.cpp (L21-L22)

Only emit to stderr and see if that fixes the test.
2025-05-30 13:15:59 -07:00
Ellis Hoag
5301f4c469
[Sanitizer] Use % patterns in report paths (#141820)
Support `%` patterns in sanitizer report paths, similar to the patterns
supported in IRPGO

4bf67cdf02/compiler-rt/lib/profile/InstrProfilingFile.c (L999-L1017)

* `%%` becomes `%`
* `%H` expands to the environment variable `HOME`
* `%t` expands to the environment variable `TMPDIR`
* `%p` expands to the process ID (PID)

In particular, the `%H` pattern is useful to resolve the home directory
at runtime, which is not possible before this PR.

Also, avoid using `Report()` before the report path has been set.
2025-05-30 07:57:51 -07:00
gbMattN
2b1ebef8b8
Fixed small memory leak in libprofile (#141739)
Inside `getCurFilename`, there is this code snippit
```
if (!lprofCurFilename.FilenamePat || !lprofCurFilename.FilenamePat[0])
    return 0;
```
If this is true, we return `"\0"`, but would leak the memory in
`FilenameBuf`.
This pull request adds a free before then to properly free the memory.
There was already a check that we allocated memory, so there is no need
to worry about freeing unallocated memory.
2025-05-28 14:51:50 +01:00
Jan Patrick Lehr
bf6cd24aaa
Revert "[compiler-rt][XRay] Make xray_interface.h C compliant" (#141570)
Reverts llvm/llvm-project#140068

Failures on PPC buildbots.
2025-05-27 11:15:47 +02:00
Jan André Reuter
80da58da34
[compiler-rt][XRay] Make xray_interface.h C compliant (#140068)
The XRay interface header uses no C++ specific features aside from using
the `std` namespace and including the C++ variant of C headers. Yet,
these changes prevent using `xray_interface.h` in external tools relying
on C for different reasons. Make this header C compliant by using C
headers, removing the `std` namespace from `std::size_t` and guard
`extern "C"`.

To make sure that further changes to not break the interface
accidentally, port one test from C++ to C. This requires the C23
standard to officially support the attribute syntax used in this test
case.

Note that this only resolves this issue for `xray_interface.h`.
`xray_records.h` is also not C compliant, but requires more work to
port.

Fixes #139902

Signed-off-by: Jan André Reuter <j.reuter@fz-juelich.de>
2025-05-27 09:59:14 +02:00
Jake Egan
75e61333f0
[interception] Implement interception on AIX (#138608)
Implement AIX specific interception functions.

Issue: https://github.com/llvm/llvm-project/issues/138916
2025-05-26 11:40:20 -04:00
Paul Kirth
1590ef3dec
[asan][test] Disable asan_lsan_deadlock test (#141145)
While the current test exercised the deadlock behavior prior to #131756,
deadlock still can occur intermittently. Since this results in test
flakes in CI, we disable this test until the locking behavior can be
fixed in the runtime. See #140646 for details.
2025-05-23 12:55:12 -07:00
Usama Hameed
afd3133945
Revert "[compiler-rt][cmake] Test COMPILER_RT_HAS_AARCH64_SME with ar… (#141280)
…m64 (#141115)"

This reverts commit a2ce5647200ad40ae356affd44db7d054de444d2.
2025-05-23 11:57:10 -07:00
Stefan Bossbaly
0cf3c437c1
[HWASan] Improve symbol indexing (#135967)
Previously we would add any ELF that contained a build id regardless
whether the ELF contained symbols or not. This works for Android since
soong will strip the symbols into a new directory. However other
build systems, like BUCK, will write the stripped file in the same
directory as the unstripped file. This would cause the hwasan_symbolize
script sometimes add then stripped ELF to its index and ignore the
symbolized ELF. The logic has now been changed to only add ELFs that
contain symbols to the index. If two symbolized ELFs are encountered
with the same build id, we now exit out with an error.

Fixes #135966

---------

Co-authored-by: Stefan Bossbaly <sboss@meta.com>
2025-05-23 09:43:04 -07:00
Martin Storsjö
a2f72ede22
[compiler-rt] [test] Don't apply the "arm" or "armhf" patterns for targets starting with "arm64" (#141226)
This fixes finding the builtins library for arm64ec in tests.

This matches a corresponding condition added in cmake in
3764ba23484afda683eea390407103e609ef4354.
2025-05-23 19:25:09 +03:00
Steven Wu
e9304cb7bb
[TSan][Test] Disable signal_recursive.cpp test on Darwin (#141135)
Mark signal_recursive.cpp test as unsupported on Darwin due to
deprecated API `sem_init` and test receives error:

`sem_init failed (errno=78)`
2025-05-22 16:22:21 -07:00
Usama Hameed
a2ce564720
[compiler-rt][cmake] Test COMPILER_RT_HAS_AARCH64_SME with arm64 (#141115)
architecture only.

Apple configures CMake only once for compiler-rt, even when building for
multiple architectures. As a result, we need to explicitly test for
arm64 specific attributes by building for that architecture
2025-05-22 15:08:10 -07:00
Jakob Widauer
1aa746d300
[tsan] Fix nested signal handling (#138599)
This PR fixes the bug reported in #134358.

In the current implementation of the tsan posix interceptors, the signal
set does not get restored to the correct original set, if a signal
handler gets called, while already inside of a signal handler. This
leads to the wrong signal set being set for the thread in which the
signal handler was called.

To fix this I introduced a stack of `__sanitizer_sigset_t` to keep all
the correct old signal sets and restore them in the correct order.

There was also already an existing test that tested nested / recursive
signal handlers, but it was disabled.
I therefore reenabled it, made it more robust by waiting for the second
thread to have been properly started and added checks for the signal
sets.
This test then failed before the introduction of the interceptor fix and
didn't fail with the fix.

@dvyukov What are your thoughts?
2025-05-22 09:44:53 -07:00
Dan Blackwell
4964d98057
[compiler-rt] Replace deprecated os_trace calls on mac (#138908)
Currently there are deprecation warnings suppressed for `os_trace`; this
patch replaces all uses with `os_log_error`.

rdar://140295247
2025-05-20 11:31:40 -07:00
Justin Cady
0931874b21
[Coverage] Add testing to validate code coverage for exceptions (#133463)
While investigating an issue with code coverage reporting around
exceptions it was useful to have a baseline of what works today.

This change adds end-to-end testing to validate code coverage behavior
that is currently working with regards to exception handling.
2025-05-20 13:43:32 -04:00
Justin Cady
025639bc39
[Coverage] Fix mapping for do-while loops with terminating statements (#139777)
The current region mapping for do-while loops that contain statements
such as break or continue results in inaccurate line coverage reports
for the line following the loop.

This change handles terminating statements the same way that other loop
constructs do, correcting the region mapping for accurate reports. It
also fixes a fragile test relying on exact line numbers.

Fixes #139122
2025-05-19 15:49:26 -04:00
William
e8a307498d
[builtins][AArch32] Fix __gnu_* functions (#137638)
Move to a consistent calling convention for both Clang/GNU such that
they can be linked with each other.

All ARM targets now use the soft-float calling convention for
`__gnu_h2f_ieee` and `__gnu_f2h_ieee`, as described in
https://github.com/ARM-software/abi-aa/blob/main/rtabi32/rtabi32.rst#the-floating-point-helper-functions.
2025-05-19 13:09:12 +01:00
Dan Blackwell
e620f10f57
[compiler-rt][sanitizer_common] Alter sanitizer_set_report_path_test to not assume a fixed file path (#139282)
Currently, `Posix/sanitizer_set_report_path_test.cpp` contains the
following check: `// CHECK: ERROR: Can't create directory:
{{.*}}Posix/Output/sanitizer_set_report_path_test.cpp.tmp`. This makes
an assumption that the test file resides in `Posix/Output`, however when
testing on a remote device, an alternative temporary directory path is
used. This patch instead checks that the path in the error message
matches the requested path dynamically.
2025-05-16 10:02:54 -07:00
Jacek Caban
3764ba2348
[compiler-rt] Add initial ARM64EC builtins support (#139279)
Use the aarch64 variants of assembly functions.

Co-authored-by: Billy Laws <blaws05@gmail.com>
2025-05-15 11:42:55 +02:00
David Tenty
224ec839a4
[AIX] Opt in to per-target runtime dir (#139620)
Many targets have already migrated to the per-target runtime directory
layout, which is generally preferred. For AIX however, we are currently
using per-target runtime directories by default for some runtimes (i.e.
`flang-rt`) but not others. This change makes things consistent for
other runtimes (most primarily `compiler-rt`) as well, adopting the
layout uniformly for the AIX target.

This change also normalizes the triple used for building compiler-rt to
remove any OS version number, as there is currently no need to version
the runtimes this way and the driver code doesn't expect this anyhow.
2025-05-13 12:00:59 -04:00
Mariusz Kwiczala
f4b80b9109
LLVM symbolizer gsym support - attempt 2 (#139686)
Add support for gsym files to llvm-symbolizer.

co-author @sfc-gh-sgiesecke

Notes:
There was a PR that was 
approved and merged: https://github.com/llvm/llvm-project/pull/134847 
and reverted: https://github.com/llvm/llvm-project/pull/139660
Due to buildbot failures:
https://lab.llvm.org/buildbot/#/builders/66/builds/13851 - it looks like
related
https://lab.llvm.org/buildbot/#/builders/51/builds/16018 - it looks like
related
https://lab.llvm.org/buildbot/#/builders/146/builds/2905 - it looks like
it's not related to changes

Fix:
To fix missing GSYM symbols 
```
+ diff -u expected.new undefined.new
+_ZN4llvm4gsym10GsymReader8openFileENS_9StringRefE U
+_ZN4llvm4gsym10GsymReaderC1EOS1_ U
+_ZN4llvm4gsym10GsymReaderD1Ev U
+_ZN4llvm4gsym13GsymDIContextC1ENSt20__InternalSymbolizer10unique_ptrINS0_10GsymReaderENS2_14default_deleteIS4_EEEE U
+ echo 'Failed: unexpected symbols'
```
for script
compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
LLVMDebugInfoGSYM was added. 
Please check the commit:

ba55425db9
That's the only change compare to
https://github.com/llvm/llvm-project/pull/134847
2025-05-13 08:27:05 -07:00
Jake Egan
5b2fc2bfb9
[sanitizer_common][AIX] Use scoped pragma to suppress atomic alignment warnings (#139272)
Have the warning suppression apply only to the code that is currently
affected. The suppression is guarded via preprocessor conditions to
cases where it is tested and known to be needed.

Issue: https://github.com/llvm/llvm-project/issues/138916

Co-authored-by: Hubert Tong <hubert.reinterpretcast@gmail.com>
2025-05-12 16:32:29 -04:00
Jacek Caban
6ade80ce18
[compiler-rt] Use mangled function names on ARM64EC (#137960)
On ARM64EC, function names and calls (but not address-taking or data
symbol references) use symbols prefixed with "#". Since it's an unique
behavior, introduce a new `FUNC_SYMBOL` macro instead of reusing
something like `SYMBOL_NAME`, which is also used for data symbols.

Based on patch by Billy Laws.
2025-05-09 14:29:58 +02:00
Vitaly Buka
856632bfc1
[NFC][ubsan_minimal] Clang-format a file (#139000) 2025-05-08 14:43:16 -07:00