Commit Graph

19493 Commits

Author SHA1 Message Date
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 a2ce564720.
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
3764ba2348.
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
Vitaly Buka
d1da41bf4d [ubsan_minimal] Add __ubsan_report_error_fatal (#138999)
Override may need to know if sanitizer in recover mode.
2025-05-08 09:58:48 -07:00
Simi Pallipurath
d178340672 [ARM][Compiler-RT] Add optional exclusion of libc provided ARM AEABI builtins from compiler-rt. (#137952)
This patch introduces a new optional CMake flag:
  COMPILER_RT_EXCLUDE_LIBC_PROVIDED_ARM_AEABI_BUILTINS

When enabled, this flag excludes the following ARM AEABI memory function
implementations from the compiler-rt build:
        __aeabi_memcmp
	__aeabi_memset
	__aeabi_memcpy
	__aeabi_memmove

These functions are already provided by standard C libraries like glibc,
newlib, and picolibc, so excluding them avoids duplicate symbol
definitions and reduces unnecessary code duplication.

Note: 
- libgcc does not define the __aeabi_* functions that overlap with those
provided by the C library. Enabling this option makes compiler-rt behave
consistently with libgcc.
- This prevents duplicate symbol errors when linking, particularly in
bare-metal configurations where compiler-rt is linked first.
- This flag is OFF by default, meaning all AEABI memory builtins will
still be built unless explicitly excluded.

This change is useful for environments where libc provides runtime
routines, supporting more minimal, conflict free builds.
2025-05-08 12:41:07 +01:00
PiJoules
1d073fd1ca [lsan][Fuchsia] Define EarlySanitizerInit for standalone lsan (#138946)
I forgot to add this definition in https://github.com/llvm/llvm-project/pull/131886.
2025-05-07 15:42:51 -07:00
PiJoules
573721bf0c [sanitizer][Fuchsia] Add callback at end of __sanitizer_startup_hook (#131886)
Sanitizers using this hook on Fuchsia can define this function to do any
extra stuff at the end of the startup hook. For now this is only used by
HWASan which needs to explicitly be initialized before libc extensions
are intitialized.
2025-05-06 10:03:38 -07:00
Jake Egan
24cd3a0bc0 [sanitizer_common] Split FREXPF/FREXPL interceptor defines (#138624)
Will allow other platforms, such as AIX, to opt out of these
interceptors individually.
2025-05-06 09:23:46 -04:00
Jake Egan
efaa5295d4 [sanitizer_common] Use internal_memcpy with wcrtomb/wctomb interceptors (#138623) 2025-05-06 09:23:14 -04:00
thetruestblue
c685355811 Unsupported zero_page_pc on iOS. (#137893) 2025-04-29 16:36:46 -07:00
thetruestblue
0864e3c8a9 [Test][Darwin] Mark zero_page_pc test as unsupported for iOS (#137858)
This is handled as a SIGKILL and can't be intercepted by ASan's signal
handler.

rdar://127512190
2025-04-29 12:08:34 -07:00
Koakuma
5d0e26e571 [compiler-rt] Make sure __clzdi2 doesn't call itself recursively on sparc64 (#136737)
On 64-bit platforms, libgcc doesn't ship with __clzsi2, so __builtin_clz
gets lowered to __clzdi2. A check already exists for GCC, but as of
commit 8210ca0198 clang also lowers
__builtin_clz to __clzdi2 on sparc64.

Update the check so that building __clzdi2 with clang/sparc64 also
works.
2025-04-29 07:36:32 +07:00
Vitaly Buka
b111da97e8 [NFC][asan] Try to deflake asan_lsan_deadlock test (#137718)
10s looks not enough. With highly parallel test
execution on VMs it's very possible that Asan
report will have no enough time to produce output.

I can reproduce locally 1s is not always enough,
but likely my workstation is faster then buildbot.

Additionally, don't use puts/CHECK to validate
timeout. We can exit with 0 and it should violate
"not" expectation.

Follow up to #131756.
2025-04-28 15:17:51 -07:00
Tom Stellard
59978b21ad [sanitizer_common] Remove interceptors for deprecated struct termio (#137403)
This struct will be removed from glibc-2.42 and has been deprecated for
a very long time.

Fixes #137321
2025-04-28 13:45:11 -07:00
Vitaly Buka
367b91a6f8 [NFC][CFI] Fix setup of UBSAN_TEST_HAS_CFI (#137424)
For #137245
2025-04-25 17:23:09 -07:00
Vitaly Buka
0f73e89db7 [NFC][CFI] Fix test from #137245 (#137420)
Check if arch supports CFI.

For #137245
2025-04-25 16:47:00 -07:00
kevkevin
8cd628f472 doc: get rid of redundant TODO tag in FuzzedDataProvider.h (#137395)
'list.size()' is determined at runtime, so using static_assert on it as
suggested by the TODO comment is not feasible and produces the following
error when done:

error: static assertion expression is not an integral constant
expression

initially referenced in https://github.com/bitcoin/bitcoin/pull/32024

Co-authored-by: Chand-ra <chandrapratap376@gmail.com>
2025-04-25 14:51:10 -07:00
Vitaly Buka
012cf4ff60 [NFC][CFI] Fix test from #137245 (#137390)
For #137245
2025-04-25 13:05:07 -07:00
Vitaly Buka
0383e545d1 [NFC][CFI] Add minimal runtime test for CFI (#137245)
It's in UBSAN dir, as diagnostic runtime for CFI,
full or minimal is UBSAN.
2025-04-25 12:25:55 -07:00