Commit Graph

14751 Commits

Author SHA1 Message Date
anoopkg6
40aa91f12a [TySan] TySan support for SystemZ - Re-submission of original pr#162396 (#169850)
This is a re-submission of original reverted patch [(#162396)
](https://github.com/llvm/llvm-project/pull/162396url)for adding TySan
support for systemzZ along with build failure patch
[#169746](https://github.com/llvm/llvm-project/pull/169746).

See conversations in #169746.

Co-authored-by: anoopkg6 <anoopkg6@github.com>
2025-12-01 17:52:24 +01:00
Koakuma
3e16aef2a6 [SPARC] Properly handle CC for long double on sparc32 (#162226)
Pass and return `long double`s indirectly, as specified in the psABI.
This continues the patch at https://reviews.llvm.org/D89130.

This should fix the issue at https://github.com/llvm/llvm-project/issues/41838.
2025-11-29 21:30:39 +07:00
Mikołaj Piróg
442f853e28 [compiler-rt] Add missing cpuid check for clflushopt (#169900)
As in title.
2025-11-28 18:31:54 +01:00
Matthew Nagy
9e25a423d0 [TySan] Make TySan compatible with UBSan (#169036) 2025-11-28 12:34:33 +00:00
Mikołaj Piróg
e3044cd552 [X86] Sync multiversion features with libgcc and refactor internal feature tables (#168750)
Compiler-rt internal feature table is synced with the one in libgcc
(common/config/i386/i386-cpuinfo.h).

LLVM internal feature table is refactored to include a field ABI_VALUE,
so we won't be relying on ordering to keep the values correct. The table
is also synced to the one in compiler-rt.
2025-11-27 15:29:16 +01:00
Ulrich Weigand
a33fd44372 Revert "[tysan] Type Sanitizer support for SystemZ" (#169726)
Reverts llvm/llvm-project#162396
2025-11-26 21:40:15 +01:00
anoopkg6
e8b9d42170 [tysan] Type Sanitizer support for SystemZ (#162396)
Type Sanitizer support for SystemZ.

Co-authored-by: anoopkg6 <anoopkg6@github.com>
2025-11-26 16:45:13 +01:00
Christopher Ferris
074d17e9c8 [scudo] Lock/unlock MutexTSDs in disable/enable. (#169440)
It is possible that a fork could occur while MutexTSDs is being held and
then cause a deadlock in a forked process when something attempts to
lock it again. Instead add it to the enable/disable list of mutexes.
2025-11-25 13:20:09 -08:00
Christopher Ferris
420f62e05c [scudo] Only print stats when the test fails. (#168000)
When running the tests on other platforms, printing the stats on all of
the passing tests makes it hard to see failure output. Therefore, this
change only prints the stats if the test actually fails.
2025-11-24 15:03:08 -08:00
Florian Mayer
ff80de72c4 Reapply "[UBSan] [compiler-rt] add preservecc variants of handlers" (#168973) (#169091)
This reverts commit 418204d9c1.
2025-11-24 12:44:32 -08:00
Daniel Thornburgh
acab67baa7 [M68k][compiler-rt] Allow compiler-rt builtins to be built for M68k (#169256)
I've tested this locally, and the builtins build proceeds without a
hitch for m68k-none-none. This is part of a larger effort to establish a
working m68k baremetal toolchain.
2025-11-23 19:15:45 -08:00
Christopher Ferris
b27749d8c7 [scudo] Small cleanup of memory tagging code part 2. (#168807)
Make the systemSupportsMemoryTagging() function return even on system
that don't support memory tagging. This avoids the need to always check
if memory tagging is supported before calling the function.

Modify iterateOverChunks() to call useMemoryTagging<>(Options) to
determine if mte is supported. This already uses the cached check of
systemSupportsMemoryTagging() rather than directly calling that
function.

Updated the code that calls systemSupportsMemoryTagging().
2025-11-21 09:08:31 -08:00
Andrew Haberlandt
bb2e4686c1 [TSan] [Darwin] Fix off by one in TSAN init due to MemoryRangeIsAvailable (#169008) 2025-11-21 07:47:11 -08:00
Vitaly Buka
af098e0096 Revert "[ubsan_minimal] Allow UBSan handler from Minimal runtime to accept arguments (#152192)" (#168812)
This partially reverts #152192, keeping updated tests and
some code reordering in clang/lib/CodeGen/CGExpr.cpp.

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp is exact revert
(with followup #152419)

We don't have a good use case for that, so revert it before we are stuck
maintaining this API.

21.x does not have this patch.

This reverts commit a1209d8686.
2025-11-21 01:09:28 -08:00
Florian Mayer
418204d9c1 Revert "[UBSan] [compiler-rt] add preservecc variants of handlers" (#168973)
Reverts llvm/llvm-project#168643
2025-11-20 16:00:44 -08:00
Florian Mayer
49e46a57cc [UBSan] [compiler-rt] add preservecc variants of handlers (#168643) 2025-11-20 15:40:37 -08:00
Paddy McDonald
36f9d5a41f [ASan] Document define to disable container overflow checks at compile time. (#163468)
Document a define to allow library developers to support disabling 
AddressSanitizer's container overflow detection in template code at 
compile time.

The primary motivation is to reduce false positives in environments
where
libraries and frameworks that cannot be recompiled with sanitizers
enabled
are called from application code. This supports disabling checks when
the
runtime environment cannot be reliably controlled to use ASAN_OPTIONS.

Key changes:
- Use the define `__SANITIZER_DISABLE_CONTAINER_OVERFLOW__` to disable
  instrumentation at compile time
- Implemented redefining the container overflow APIs in
common_interface_defs.h
  to use define to provide null implementation when define is present
- Update documentation in AddressSanitizer.rst to suggest and illustrate
  use of the define
- Add details of the define in PrintContainerOverflowHint()
- Add test disable_container_overflow_checks to verify new hints on the
error and fill the testing gap that
ASAN_OPTIONS=detect_container_overflow=0
  works
- Add tests demonstrating the issue around closed source libraries and 
  instrumented apps that both modify containers

This requires no compiler changes and should be supportable cross
compiler toolchains.

An RFC has been opened to discuss: 

https://discourse.llvm.org/t/rfc-add-fsanitize-address-disable-container-overflow-flag-to-addresssanitizer/88349
2025-11-19 11:20:10 -08:00
Nico Weber
87a1fd17e9 [gn] "port" 5efce7392f (arm 32-bit asm compiler-rt) 2025-11-19 12:41:08 -05:00
Jake Egan
c62fc065b4 [asan] Implement address sanitizer on AIX: platform support (#139587)
Adds some general changes for supporting asan on AIX.

Issue: #138916
2025-11-19 09:44:22 -05:00
Michael Kruse
c32c1d0d21 [Runtimes] Default build must use its own output dirs (#168266)
Post-commit fix of #164794 reported at
https://github.com/llvm/llvm-project/pull/164794#issuecomment-3536253493

`LLVM_LIBRARY_OUTPUT_INTDIR` and `LLVM_RUNTIME_OUTPUT_INTDIR` is used by
`AddLLVM.cmake` as output directories. Unless we are in a
bootstrapping-build, It must not point to directories found by
`find_package(LLVM)` which may be read-only directories. MLIR for
instance sets thesese variables to its own build output
directory, so should the runtimes.
2025-11-19 13:51:14 +01:00
Simon Tatham
5efce7392f [compiler-rt][ARM] Optimized mulsf3 and divsf3 (#168394)
(Reland of #161546, fixing three build and test issues)

This commit adds optimized assembly versions of single-precision float
multiplication and division. Both functions are implemented in a style
that can be assembled as either of Arm and Thumb2; for multiplication, a
separate implementation is provided for Thumb1. Also, extensive new
tests are added for multiplication and division.

These implementations can be removed from the build by defining the
cmake variable COMPILER_RT_ARM_OPTIMIZED_FP=OFF.

Outlying parts of the functionality which are not on the fast path, such
as NaN handling and underflow, are handled in helper functions written
in C. These can be shared between the Arm/Thumb2 and Thumb1
implementations, and also reused by other optimized assembly functions
we hope to add in future.
2025-11-18 11:21:23 +00:00
Christopher Ferris
7a14ef0293 [scudo] Skip test if mlock fails. (#168448)
Some linux versions might not support the mlock call, so skip that part
of the test if the mlock fails.
2025-11-17 15:25:33 -08:00
Christopher Ferris
7672a5cee1 [scudo] Fix wrong return type. (#168157) 2025-11-17 10:59:04 -08:00
Mikołaj Piróg
8f6c7aa2b1 [X86] Remove vector length (256 vs 512) distinction of AVX10 (#167736)
As in title. AVX10.x doesn't distinguish between available vector
lengths.

-mattr=avx10.x-512 and defining of macros with _512 is kept for compatibility. 

Bit-positions of avx10.1/2 features in compiler-rt and X86TargetParser
are synced to match those in the gcc.
2025-11-15 15:51:06 +01:00
Andrew Haberlandt
4d3ed10241 [compiler-rt] [Darwin] Strip MTE tags from ASAN and TSAN (#166453)
ASAN and TSAN need to strip tags in order to compute the correct shadow
addresses.

rdar://163518624
2025-11-14 09:48:09 -08:00
Andrew Haberlandt
4fe79a761e [sanitizer-common] [Darwin] Fix overlapping dyld segment addresses (attempt 2) (#167800)
This re-lands #166005, which was reverted due to the issue described in
#167797.

There are 4 small changes:
- Fix LoadedModule leak by calling Clear() on the modules list
- Fix internal_strncpy calls that are not null-terminated
- Improve test to accept the dylib being loaded from a different path
than compiled `{{.*}}[[DYLIB]]`
- strcmp => internal_strncmp

This should not be merged until after #167797.


rdar://163149325
2025-11-13 16:11:14 -08:00
Andrew Haberlandt
6a89439423 [sanitizer_common] Add darwin-specific MemoryRangeIsAvailable (#167797)
The fixes a TOCTOU bug in the code that initializes shadow memory in
ASAN:


4b05581bae/compiler-rt/lib/asan/asan_shadow_setup.cpp (L66-L91)

1. During initialization, we call `FindDynamicShadowStart` to search the
memory mapping for enough space to dynamically allocate shadow memory.
2. We call `MemoryRangeIsAvailable(shadow_start, kHighShadowEnd);`,
which goes into `MemoryMappingLayout`.
3. We actually map the shadow with `ReserveShadowMemoryRange`.

In step 2, `MemoryMappingLayout` makes various allocations using the
internal allocator. This can cause the allocator to map more memory! In
some cases, this can actually allocate memory that overlaps with the
shadow region returned by` FindDynamicShadowStart` in step 1. This is
not actually fatal, but it memory corruption; MAP_FIXED is allowed to
overlap other regions, and the effect is any overlapping memory is
zeroed.

------

To address this, this PR implements `MemoryRangeIsAvailable` on Darwin
without any heap allocations:

- Move `IntervalsAreSeparate` into sanitizer_common.h
- Guard existing sanitizer_posix implementation of
`MemoryRangeIsAvailable` behind !SANITIZER_APPLE
- `IsAddressInMappedRegion` in sanitizer_mac becomes
`MemoryRangeIsAvailable`, which also checks for overlap with the DYLD
shared cache.

After this fix, it should be possible to re-land #166005, which
triggered this issue on the x86 iOS simulators.

rdar://164208439
2025-11-13 21:42:45 +00:00
Christopher Ferris
3e28992b30 [scudo] Always zero on linux even if the memory cannot be released. (#167788)
If a caller has locked memory, then the madvise call will fail. In that
case, zero the memory so that we don't return non-zeroed memory for
calloc calls since we thought the memory had been released.
2025-11-13 13:01:28 -08:00
Simon Tatham
1c196452dd Revert "[compiler-rt][ARM] Optimized mulsf3 and divsf3" (#167906)
Reverts llvm/llvm-project#161546

One of the buildbots reported a cmake error I don't understand, and
which I didn't get in my own test builds:
```
CMake Error at /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/cmake/Modules/CheckAssemblerFlag.cmake:23 (try_compile):
  COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE
```

My best guess is that the thing I did in `CheckAssemblerFlag.cmake` only
works on some versions of cmake. But I don't understand the problem well
enough to fix it quickly, so I'm reverting the whole patch and will
reland it later.
2025-11-13 16:58:21 +00:00
Simon Tatham
f7e6521277 [compiler-rt][ARM] Optimized mulsf3 and divsf3 (#161546)
This commit adds optimized assembly versions of single-precision float
multiplication and division. Both functions are implemented in a style
that can be assembled as either of Arm and Thumb2; for multiplication, a
separate implementation is provided for Thumb1. Also, extensive new
tests are added for multiplication and division.

These implementations can be removed from the build by defining the
cmake variable COMPILER_RT_ARM_OPTIMIZED_FP=OFF.

Outlying parts of the functionality which are not on the fast path, such
as NaN handling and underflow, are handled in helper functions written
in C. These can be shared between the Arm/Thumb2 and Thumb1
implementations, and also reused by other optimized assembly functions
we hope to add in future.
2025-11-13 16:26:01 +00:00
Martin Storsjö
825706be7d Revert "[compiler-rt] [builtins] Remove unused/misnamed x86 chkstk functions"
This reverts parts of commit 885d7b759b,
and adds verbose comments explaining all the variants of this
function, for clarity for future readers.

It turns out that those functions actually weren't misnamed or
unused after all: Apparently Clang doesn't match GCC when it comes
to what stack probe function is referenced on i386 mingw. GCC < 4.6
references a symbol named "___chkstk", with three leading underscores,
and GCC >= 4.6 references "___chkstk_ms".

Restore these functions, to allow linking object files built with
GCC with compiler-rt.
2025-11-13 10:07:46 +02:00
Martin Storsjö
d2f0b27ef5 Revert "[compiler-rt] Rename the now lone i386/chkstk2.S to i386/chkstk.S"
This reverts commit 1f9eff100c.

This is done in preparation of reverting parts of
885d7b759b.
2025-11-13 10:07:46 +02:00
Aiden Grossman
769c1ef1fa [ASan] Fix forward 141c2b
When landing 141c2b I didn't realize that none of these files actually
got built either locally or by premerge. I had some minor syntax
mistakes that caused the build to fail. This patch fixes those issues
and has been verified on a Windows machine.
2025-11-13 02:05:13 +00:00
Aiden Grossman
141c2bf0be [ASan][Windows] Add new instruction sizes (#167734)
These instructions show up when building asan in the premerge container
and do not on other bots, likely due to different standard library
versions.
2025-11-12 16:18:30 -08:00
Andrew Haberlandt
10e97641f5 Revert "[sanitizer-common] [Darwin] Fix overlapping dyld segment addresses (#167649)
Revert #166005 due to breaking x86 iOS sims

We're sometimes hitting a allocator assert when running x86 iOS sim
tests. I don't believe this PR is at fault, but there's probably a
memory safety / allocator issue somewhere which the allocation pattern
here is exposing.
2025-11-12 00:59:22 -08:00
Alan Zhao
dc0ccbdfc7 [compiler-rt][asan] Fix a test on Windows (#167591)
Windows doesn't support `pthread_attr`, which was introduced to
asan_test.cpp in #165198, so this change `#ifdef`s out the changes made
in that PR.

Originally reported by Chrome as https://crbug.com/459880605.
2025-11-11 22:44:55 +00:00
Riyaz Ahmad
385aa01212 [Asan] Ensure minimum stack size 128KB in ThreadedStressStackReuseTest (#165198)
Asan test `ThreadedStressStackReuseTest ` fails on AIX due to smaller
default thread stack size. Set thread stack size to a minimum of 128KB
to ensure reliable test behavior across platforms (platforms with
smaller default thread stack size).

---------

Co-authored-by: Riyaz Ahmad <riyaz.ahmad@ibm.com>
2025-11-11 09:32:29 -08:00
Christopher Ferris
9c7fe126f4 Revert "[scudo] Small cleanup of memory tagging code." (#167425)
Reverts llvm/llvm-project#166860

The local static variable causes build failures.
2025-11-10 16:48:19 -08:00
Christopher Ferris
046ae85536 [scudo] Small cleanup of memory tagging code. (#166860)
Make the systemSupportsMemoryTagging() function return even on system
that don't support memory tagging. This avoids the need to always check
if memory tagging is supported before calling th function.

Make systemSupportsMemoryTagging() cache the getauxval return value
instead of calling the function every time.

Updated the code that calls systemSupportsMemoryTagging().
2025-11-10 14:17:23 -08:00
Csanád Hajdú
9d18e92ee7 [compiler-rt] Add CMake option to enable execute-only code generation on AArch64 (#140555)
For a full toolchain supporting execute-only code generation the runtime
libraries also need to be pre-compiled with it enabled. The generic
`RUNTIMES_EXECUTE_ONLY_CODE` CMake option can now be used during build
configuration to enable execute-only code generation in compiler-rt.

The build option can only be enabled for a runtimes build of
compiler-rt, because a recent version of Clang is needed to correctly
compile assembly files with execute-only code support.

Related RFC:
https://discourse.llvm.org/t/rfc-execute-only-code-support-for-runtime-libraries-on-aarch64/86180
2025-11-07 09:36:18 +01:00
Andrew Haberlandt
e330985551 [sanitizer-common] [Darwin] Fix overlapping dyld segment addresses (#166005)
This fixes two problems:
- dyld itself resides within the shared cache. MemoryMappingLayout
incorrectly computes the slide for dyld's segments, causing them to
(appear to) overlap with other modules. This can cause symbolication
issues.
- The MemoryMappingLayout ranges on Darwin are not disjoint due to the
fact that the LINKEDIT segments overlap for each module. We now ignore
these segments to ensure the mapping is disjoint.

This adds a check for disjointness, and a runtime warning if this is
ever violated (as that suggests issues in the sanitizer memory mapping).
There is now a test to ensure that these problems do not recur.

rdar://163149325
2025-11-06 12:18:16 -08:00
Andrew Haberlandt
a51d219ee7 [sanitizer_common] Add arm64e module type (#166018)
This will fix some symbolication failures on arm64e machines when the
symbolicator passes the (wrong) architecture string to atos.
2025-11-04 14:32:06 -08:00
quic-k
a3a99c3996 [compiler-rt][x86] Don't use assert.h when building without a libc (#165384)
fixes https://github.com/llvm/llvm-project/issues/164932

Signed-off-by: Kushal Pal <kushpal@qti.qualcomm.com>
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
2025-11-04 04:35:31 +00:00
Andrew Haberlandt
148a42bdd2 [sanitizer-common] [Darwin] Provide warnings for common sandbox issues (#165907)
We currently do not handle errors in task_set_exc_guard_behavior. If
this fails, mmap can unexpectedly crash.
We also do not currently provide a clear warning if no external
symbolizers are found.

rdar://163798535
2025-11-03 14:40:01 -08:00
Christopher Ferris
0e3612e751 [scudo] Add config option to modify get usable size behavior (#158710)
Currently, Scudo always returns the exact size allocated when calling
getUsableSize. This can be a performance issue where some programs will
get the usable size and do unnecessary calls to realloc since they think
there isn't enough space in the allocation. By default, usable size will
still return the exact size of the allocation.

Note that if the exact behavior is disabled and MTE is on, then the code
will still give an exact usable size.
2025-11-03 14:31:11 -08:00
Matthew Nagy
6a275de13f Revert "[UBSan] Improve error message when a misalignment is due to t… (#166197)
…arget de…"

This reverts commit 47c54d55c9.
2025-11-03 17:24:55 +00:00
Matthew Nagy
47c54d55c9 [UBSan] Improve error message when a misalignment is due to target default assumed alignment 2025-11-03 15:37:26 +00:00
gbMattN
7a957bd2c8 [TySan] Add option to outline instrumentation (#120582)
Added a command line option to use function calls rather than inline
checks for TySan instrumentation.
2025-10-31 16:51:55 +00:00
quic-likaid
bf99f6693e lsan: fix allocator on arm64 Android (#165656)
The default config is too large for arm64 Android devices, which are
typically configured with 39-bit address space. This change brings it
inline with sanitizer_allocator_test.cpp.
2025-10-30 19:43:07 -07:00
Clement Courbet
cc22c9c455 Revert "[nsan] More unit tests for float128. (#165248)" (#165391)
This reverts commit 2f869c427b.

Breaks build on some configurations
2025-10-28 14:38:34 +01:00