14892 Commits

Author SHA1 Message Date
Christopher Ferris
7c260d3966
[scudo] Fix reallocate for MTE. (#190086)
For MTE, we can't use the whole size or we might trigger a segfault.
Therefore, use the exact size when MTE is enabled or the exact usable
size parameter is true.

Also, optimize out the call to getUsableSize and use a simpler
calculation.
2026-04-01 16:44:31 -07:00
Sadaf Ebrahimi
7c4b6dee74
[scudo] Ensure that reallocate copies everything
getUsableSize returns the actual capacity of the underlying block, which
may be larger than the size originally requested by the user. If the
user writes data into this extra space accessible via getUsableSize and
subsequently calls reallocate, the existing implementation only copies
the original requested number of bytes. This resulted in data loss for
any information stored beyond the requested size but within the usable
bounds.
2026-04-01 12:30:47 -05:00
jinge90
3f2a9c6f54
[NFC][compiler-rt] Use __builtin_huge_val for CRT_INFINITY for double precision (#188197) 2026-03-31 16:31:15 -07:00
PiJoules
78c5d68029
[asan] Add size/alignment checks for free_[aligned_]sized (#189216)
Historically, alignment and size weren't taken into account when freeing
allocations since `free` just takes a pointer. With `free_sized` and
`free_aligned_sized`, we can do these size and alignment checks in asan
now. This adds a new report type specifically for these functions.

Checking is hidden behind a new env flag `free_size_mismatch` which is
enabled by default, but downstream users can opt out of it.

The bulk of this PR was generated by gemini but thoroughly reviewed and
edited by me to the best of my ability.
2026-03-31 19:10:43 +00:00
Simon Tatham
0cecacd971
[compiler-rt][ARM] Optimized double precision FP add/sub (#179921)
The one new assembly source file, `arm/adddf3.S`, implements both
addition and subtraction via cross-branching after flipping signs, since
both operations must provide substantially the same logic. The new cmake
properties introduced in a prior commit are used to arrange that
including `adddf3.S` supersedes the C versions of both addition and
subtraction, and also informs the test suite that both functions are
available to test.
2026-03-31 12:00:11 +01:00
Roland McGrath
bdf28a6d48
[fuzzer] Use LIBCXX_ABI_UNSTABLE for hermetic libc++ (#189096)
This build of libc++ never interacts with any other, so
it can always use the latest and best ABI.
2026-03-30 11:24:04 -07:00
Brian Cain
a33acdb0b2
[compiler-rt] Enable GWP-ASan for Hexagon (#188410)
Add Hexagon to ALL_GWP_ASAN_SUPPORTED_ARCH, add struct layout
assertions.
2026-03-30 09:26:16 -05:00
Brian Cain
5e7c66013b
[Hexagon][XRay] Fix sled layout and trampoline to preserve retaddr (#188784)
The Hexagon XRay sled was 5 words (20 bytes) and the patched sequence
clobbered r31 (the link register) via callr without saving it first.
When the trampoline returned, the instrumented function's own allocframe
would then save the wrong return address, causing a crash or misrouted
return.

Expand the sled to 7 words (28 bytes) and wrap the call with
allocframe(#0)/deallocframe so the caller's r31:30 are preserved across
the trampoline call.

Detailed fixes:
- HexagonAsmPrinter: emit 6 nop words after the jump (7 words total)
- xray_hexagon.cpp: patch allocframe(#0) as first word, immext+r7 (func
ID), immext+r6 (trampoline), callr r6, deallocframe; write the first
word last for atomicity
- xray_trampoline_hexagon.S: complete rewrite -- properly load and
dereference the global handler pointer, save/restore r0-r5 and r31, add
stack frame with correct 8-byte alignment, add jumpr r31 to actually
return from trampolines
- xray_interface.cpp: update Hexagon cSledLength from 20 to 28
- Update lit tests for 6-nop sled
2026-03-30 09:25:14 -05:00
Simon Tatham
c7706be4bf
[compiler-rt][ARM] Rename endian.h to crt_endian.h (#189336)
Apparently on macOS there's a system header file also called
arm/endian.h, and another system header #includes it with "" rather than
<>, so that this compiler-rt header accidentally shadows it. Worked
around by prefixing "crt" to the name.

No changes are needed except the rename, because the planned functions
that use this header are still under review.
2026-03-30 15:11:00 +01:00
Brian Cain
a8cdc5a483
[compiler-rt][msan] Guard shmat interceptor w SANITIZER_INTERCEPT_SHMCTL (#189198)
The shmat interceptor calls REAL(shmctl), but shmctl is not intercepted
on all targets (e.g. 32-bit Linux with musl). Guard shmat behind
SANITIZER_INTERCEPT_SHMCTL and use a MSAN_MAYBE_INTERCEPT pattern
consistent with other conditional interceptors.
2026-03-29 13:01:39 -05:00
Brian Cain
44f1fa9099
[compiler-rt][msan] Add MSan support for Hexagon (Linux) (#189124)
Add the runtime infrastructure for MemorySanitizer on Hexagon Linux.
Hexagon is 32-bit, so the shadow memory layout uses a compact XOR-based
  mapping that fits within the lower 3GB of address space:

    0x00000000 - 0x10000000  APP-1     (256MB, program text/data/heap)
    0x10000000 - 0x20000000  ALLOCATOR (256MB)
    0x20000000 - 0x40000000  SHADOW-1  (512MB, covers APP-1 + ALLOCATOR)
    0x40000000 - 0x50000000  APP-2     (256MB, shared libs + stack)
    0x60000000 - 0x70000000  SHADOW-2  (256MB, covers APP-2)
    0x70000000 - 0x90000000  ORIGIN-1  (512MB)
    0xB0000000 - 0xC0000000  ORIGIN-2  (256MB)

MEM_TO_SHADOW uses XOR 0x20000000, and SHADOW_TO_ORIGIN adds 0x50000000.
  The dual-APP layout accommodates QEMU user-mode, which places shared
  libraries and the stack at 0x40000000.

  The allocator uses SizeClassAllocator32 with a 256MB region at
  0x10000000, and kMaxAllowedMallocSize is set to 1GB consistent with
  other 32-bit targets.
2026-03-29 12:56:42 -05:00
Brian Cain
670de1f522
[compiler-rt][msan] Fix 32-bit overflow in CheckMemoryLayoutSanity (#189199)
Use start + (end - start) / 2 instead of (start + end) / 2 to compute
the midpoint address. The original expression overflows when start + end
exceeds UPTR_MAX, which happens on 32-bit targets whose memory layout
includes regions above 0x80000000.
2026-03-28 22:14:52 -05:00
Brian Cain
89d57d03bf
[compiler-rt][sanitizer] Add struct_rlimit64_sz for musl (#189197)
On musl, rlimit64 is an alias for rlimit rather than a distinct type
provided by glibc. Add a SANITIZER_MUSL elif branch so that
struct_rlimit64_sz is defined for musl-based Linux targets.
2026-03-28 22:13:32 -05:00
PiJoules
a5fa4dba6e
[compiler-rt] Add interceptors for free_[aligned_]sized for asan+hwasan (#189109) 2026-03-27 23:16:52 +00:00
Luke Wren
efba01ae12
[RISCV] Allocate feature bits for Zifencei and Zmmul (#143306)
As proposed in
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/110.

No real compiler-rt implementation as Linux does not list these
extensions in hwprobe.

Signed-off-by: Luke Wren <wren6991@gmail.com>
2026-03-27 15:47:57 -07:00
Joseph Huber
871d675c52
[compiler-rt] Add PTX feature specifically when CUDA is not available (#189083)
Summary:
People need to be able to build this without a CUDA installation.

Long term we should bump up the minimum version as I'm pretty sure every
architecture before this has been deprecated by NVIDIA.
2026-03-27 14:28:25 -05:00
Aiden Grossman
df6d6c9cd1
[Scudo] Disable ScudoCombinedTests.NewType (#189070)
This is failing in some configurations on AArch64 Linux. Given there are
a lot of follow-up commits that makes this hard to revert, just disable
it for now pending future investigation.
2026-03-27 12:15:46 -07:00
Brian Cain
3bff1a81c1
[XRay] Always register constructor(0) alongside .preinit_array (#188788)
On musl-based systems the dynamic linker does not process
DT_PREINIT_ARRAY, so the .preinit_array entry alone never calls
__xray_init(). Without initialization, the global XRay Flags struct is
zero-initialized and flags()->xray_mode is NULL. When the basic-mode or
FDR-mode static initializers run from .init_array and call
internal_strcmp(flags()->xray_mode, ...), they dereference NULL and
crash.

Fix this by always registering a constructor(0) in addition to the
.preinit_array entry. On glibc where .preinit_array works, __xray_init()
will have already run and the constructor returns immediately (the
function is idempotent). On musl, the constructor ensures __xray_init()
runs before other .init_array entries that depend on XRay flags being
initialized.
2026-03-27 09:32:42 -05:00
Dan Blackwell
6a994417d8
[NFCI][sanitizer_common] Realign #ifdefs in sanitizer_internal_defs.h (#186861)
Currently it is very hard to tell these nested ifdefs apart. This patch
fixes that, while trying to be as light-touch as possible.
2026-03-27 10:13:01 +00:00
Christopher Ferris
6b3556a6ea
[scudo] Add Last entry to ReleaseToOS enum. (#188645)
This allows static asserts to be set in tracing code that might use the
ReleaseToOS values as indexes.

This would have caused a compile failure instead of a runtime crash when
I added the use of a new ReleaseToOS value.
2026-03-26 12:32:56 -07:00
Joseph Huber
ffd6a13b5f
[compiler-rt] Rework profile data handling for GPU targets (#187136)
Summary:
Currently, the GPU iterates through all of the present symbols and
copies them by prefix. This is inefficient as it requires a lot of small
high-latency data transfers rather than a few large ones. Additionally,
we force every single profiling symbol to have protected visibility.
This means potentially hundreds of unnecessary symbols in the symbol
table.

This PR changes the interface to move towards the start / stop section
handling. AMDGPU supports this natively as an ELF target, so we need
little changes. Instead of overriding visibility, we use a single table
to define the bounds that we can obtain with one contiguous load.

Using a table interface should also work for the in-progress HIP
implementation for this, as it wraps the start / stop sections into
standard void pointers which will be inside of an already mapped region
of memory, so they should be accessible from the HIP API.

NVPTX is more difficult as it is an ELF platform without this support. I
have hooked up the 'Other' handling to work around this, but even then
it's a bit of a stretch. I could remove this support here, but I wanted
to demonstrate that we can share the ABI. However, NVPTX will only work
if we force LTO and change the backend to emit variables in the same

TL;DR, we now do this:
```c
struct { start1, stop1, start2, stop2, start3, stop3, version; } device;
struct host = DtoH(lookup("device"));
counters = DtoH(host.stop - host.start)
version = DtoH(host.version);
```
2026-03-26 10:17:43 -05:00
Simon Tatham
80831832e0
[compiler-rt][ARM] Double-precision FP support functions (#179920)
This commit adds C helper functions `dnan2`, `dnorm2` and `dunder` for
handling the less critical edge cases of double-precision arithmetic,
similar to `fnan2`, `fnorm2` and `funder` that were added in commit
f7e652127772e93.

It also adds a header file that defines some register aliases for
handling double-precision numbers in AArch32 software floating point in
an endianness-independent way, by providing aliases `xh` and `xl` for
the high and low words of the first double-precision function argument,
regardless of which of them is in r0 and which in r1, and similarly `yh`
and `yl` for the second argument in r2/r3.
2026-03-26 09:10:15 +00:00
Jake Egan
25904ac915
[sanitizer_common] Implement address sanitizer on AIX: stack unwinding (#138188)
Implement unwind.h-based stack unwinding routines on AIX.

Issue: https://github.com/llvm/llvm-project/issues/138916
2026-03-26 02:13:47 -04:00
Christopher Ferris
a3260f6582
[scudo] Remove some android wrapper checking. (#188339)
Tests for Android specific behavior don't really belong here since it is
affected by the config which is not necessarily the same on Android.
There are already tests that the config options and flag options work
properly. Android wrapper tests belong to Android.
2026-03-25 10:48:22 -07:00
Fabio D'Urso
1d2f14f625
[scudo] Use portable TEST_SKIP macro (#188045)
Which expands to ZXTEST_SKIP on Fuchsia.
2026-03-25 11:46:52 +01:00
Vitaly Buka
cb12534650 [compiler-rt] Suppress unused variable report in emutls
Pull Request: https://github.com/llvm/llvm-project/pull/188329
2026-03-24 18:22:41 -07:00
Vitaly Buka
9fd8bc0f0e
[libFuzzer] Fix -Wunused-variable when building with NDEBUG (#188301)
The variable `FuzzerInitIsRunning` is only used within `assert()`.
Follow up to #178342.
2026-03-24 18:23:37 +00:00
Daniil Kovalev
34875331d9
[PAC][compiler-rt] Use __ptrauth qualifier instead of builtins (#188109)
Since #100830 has landed, we no longer need to rely on builtins
2026-03-24 09:24:19 +00:00
Simon Tatham
44df4116c8
[compiler-rt][ARM] cmake properties for complicated builtin sources (#179919)
In the builtins library, most functions have a portable C implementation
(e.g. `mulsf3.c`), and platforms might provide an optimized assembler
implementation (e.g. `arm/mulsf3.S`). The cmake script automatically
excludes the C source file corresponding to each assembly source file it
includes. Additionally, each source file name is automatically
translated into a flag that lit tests can query, with a name like
`librt_has_mulsf3`, to indicate that a function is available to be
tested.

In future commits I plan to introduce cases where a single .S file
provides more than one function (so that they can share code easily),
and therefore, must supersede more than one existing source file.

I've introduced the `crt_supersedes` cmake property, which you can set
on a .S file to name a list of .c files that it should supersede. Also,
the `crt_provides` property can be set on any source file to indicate a
list of functions it makes available for testing, in addition to the one
implied by its name.
2026-03-23 16:01:12 +00:00
Michael Jones
6891a6ef0e
[compiler-rt] Add bitmask to fix warning (#187812)
After #186881 was merged the gcc libc bots started complaining about the
conversion from u8 to 2 bit integer being unsafe (see:
https://lab.llvm.org/buildbot/#/builders/131/builds/42788). This PR
adds a bitmask that fixes the warning.
2026-03-20 16:46:38 -07:00
Christopher Ferris
8cc0124508
[scudo] Make the default for size/align checks to not die. (#187799) 2026-03-20 15:32:16 -07:00
Christopher Ferris
1b44e34b18
[scudo] Add free_sized and free_aligned_sized (#186881)
Add one new flag, dealloc_align_mismatch that turns on/off alignment
checks. Add three new config parameters, one for deallocate type
mismatch (such as abort on new/free if true), one for checking if the
size parameter matches on dealloc and one for checking if the alignment
is correct on a dealloc.

Add extra flags to be passed for to indicate to do an align/size check.

Update report functions to better indicate the errors. Add unit tests
for all of these.

This is based on these upstream cls by jcking:

https://github.com/llvm/llvm-project/pull/147735
https://github.com/llvm/llvm-project/pull/146556
2026-03-20 13:26:35 -07:00
Roman Vinogradov
ca54948d0b
[ASan] Fix missed poisoned suffix in first granule in __asan_region_is_poisoned (#187466)
Align beg address down instead of up in __asan_region_is_poisoned(), so
the shadow scan includes the first granule. This fixes a false negative
when first granule has an unpoisoned prefix and poisoned suffix.

Add test that covers this scenario.
2026-03-20 10:05:19 -07:00
Joseph Huber
d18a784d41
[compiler-rt] Define GPU specific handling of profiling functions (#185763)
Summary:
The changes in https://www.github.com/llvm/llvm-project/pull/185552
allowed us to
start building the standard `libclang_rt.profile.a` for GPU targets.
This PR expands this by adding an optimized GPU routine for counter
increment and removing the special-case handling of these functions in
the OpenMP runtime.

Vast majority of these functions are boilerplate, but we should be able
to do more interesting things with this in the future, like value or
memory profiling.
2026-03-19 10:51:48 -05:00
Ross Burton
015e3d2b20
[compiler-rt] Unify python shebangs (#187285)
As per PEP-0394[1], there is no real concensus over what binary names
Python has, specifically 'python' could be Python 3, Python 2, or not
exist.

However, everyone has a python3 interpreter and the scripts are all
written for Python 3. Unify the shebangs so that the ~50% of shebangs
that use python now use python3.

[1] https://peps.python.org/pep-0394/
2026-03-18 17:48:08 -07:00
Roman Vinogradov
2caba086ab
[ASan] Fix overflow and last byte handling in __asan_region_is_poisoned (#183900)
__asan_region_is_poisoned() uses an exclusive end address
(end = beg + size) to validate the region [beg, end) and to compute
the aligned inner shadow region. This causes correctness issue
near memory range upper boundary and could trigger address space
overflow on 32-bit targets.

1. Incorrect handling of the last byte of a memory range

   The implementation checks AddrIsInMem(end) instead of the last
   application byte (end - 1). For regions ending at the last byte
   of Low/Mid/HighMem (e.g. __asan_region_is_poisoned(kHighMemEnd, 1)),
   this returns end (kHighMemEnd + 1) instead of the original 
   pointer. This behavior is inconsistent with the function’s 
   semantics and with __asan_address_is_poisoned().

2) address space overflow and invalid shadow range

If a region ends at the top of the virtual address space (kHighMemEnd),
   e.g. on 32-bit targets, end = beg + size could wrap to 0.
   This violated the invariant beg < end and could trigger
   the CHECK failure.

   Additionally, overflow in RoundUpTo alignment computations
   for aligned_b could produce an invalid shadow region spanning
   LowShadow to HighShadow across ShadowGap, leading mem_is_zero()
   to access unmapped memory and crash.

Fix by switching to an inclusive last byte:

  last = beg + size - 1

All checks are now performed on beg and last. The aligned inner 
shadow region is also computed from [beg, last]. Additional guard 
for aligned_b prevents the mapping to shadow if aligned_b is wrapped
(in this case the aligned inner region is also empty and doesn't 
require the shadow scan via mem_is_zero()).

This fixes incorrect return values at memory range ends and 
prevents overflow related crashes on 32-bit targets.

Test is extended to cover these boundary cases.

---------

Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
2026-03-18 09:43:19 -07:00
cherrymui
1098b95dac
[sanitizer_common] Define SANITIZER_WEAK_IMPORT for Go race detector (#186525)
Currently, when building the Go race detector (when SANITIZER_GO
is set), SANITIZER_WEAK_IMPORT is no-op. It is perfectly fine to
define SANITIZER_WEAK_IMPORT for Go just like other cases. That
will tell the Go linker to treat _dyld_get_dyld_header as a weak
import.

Perhaps SANITIZER_WEAK_ATTRIBUTE can also be defined for Go. That
would be a separate patch.
2026-03-16 18:49:56 +00:00
Brian Cain
cef418ec4b
[compiler-rt] Add ASan/UBSan runtime support for Hexagon Linux (#183982)
Add the architecture-specific pieces needed for the ASan and UBSan
sanitizer runtimes to build and run on hexagon-unknown-linux-musl.

Without this patch, building sanitizer runtimes for Hexagon Linux fails
with:

  sanitizer_linux.cpp: error: member access into incomplete type
      'struct stat64'

because musl libc does not provide struct stat64. This patch routes
Hexagon through the statx() syscall path (like LoongArch) to avoid the
stat64 dependency entirely.

Changes:

* asan_mapping.h: Add ASAN_SHADOW_OFFSET_CONST (0x20000000) for Hexagon
with shadow layout documentation.
* sanitizer_linux.cpp: Implement internal_clone() for Hexagon using
inline assembly (trap0 syscall, generic clone argument order: flags,
stack, ptid, ctid, tls). Route Hexagon through the statx() path for stat
operations since musl lacks struct stat64.
* sanitizer_linux.h: Add Hexagon to the internal_clone() declaration
guard.
* sanitizer_stoptheworld_linux_libcdep.cpp: Add Hexagon to the
StopTheWorld architecture guard with register definitions.
* sanitizer_asm.h: Define ASM_TAIL_CALL as 'jump' for Hexagon.
* CMakeLists.txt: Add -fno-emulated-tls for Hexagon targets. Hexagon
Linux uses native TLS via the UGP register; emulated TLS produces broken
sanitizer runtimes with unresolvable __emutls references.
2026-03-12 20:27:11 -05:00
Christopher Ferris
dae2923901
[scudo] Display flags on secondary cache entries. (#185786) 2026-03-12 13:19:33 -07:00
DylanFleming-arm
d682325961
[libc] Remove unused AOR_v20.02 directory (#185951)
As far as I am aware, AOR is no longer used anywhere within LLVM, as
most of the required code has since been ported to elsewhere within the
project.

Removes the entire directory, and updates some now outdated comments.
2026-03-12 10:14:04 -04:00
Keith Packard
ab6bb1bab6
compiler-rt/arm: Check for overflow when adding float denorms (#185245)
When the sum of two sub-normal values is not also subnormal, we need to
set the exponent to one.

Test case:

static volatile float x = 0x1.362b4p-127;
static volatile float x2 = 0x1.362b4p-127 * 2;

int
main (void)
{
	printf("x %a x2 %a x + x %a\n", x, x2, x + x);
	return x2 == x + x ? 0 : 1;
}

Signed-off-by: Keith Packard <keithp@keithp.com>
2026-03-12 10:37:48 +00:00
Alex Crichton
7a43f770a0
[WebAssembly] Remove __c_longjmp from compiler-rt (#185798)
This is similar to #185770 where it removes an
exception-handling-related symbol from `compiler-rt` in favor of having
definitions elsewhere. The compiler-rt library is linked into all shared
objects, for example, which can result in duplicate definitions of a
symbol where this tag wants to have one unique definition. The intention
behind this commit is to defer the definition of this symbol to
downstream libraries, such as the definition of `longjmp` itself. An
example of this is WebAssembly/wasi-libc#772 where the responsibility of
defining this symbol now lies with wasi-libc.
2026-03-10 21:55:06 -07:00
Alex Crichton
a3f28233fc
[WebAssembly] Move __cpp_exception to libunwind (#185770)
The `__cpp_exception` symbol is now defined in libunwind instead of
compiler-rt. This is moved for a few reasons, but the primary reason is
that compiler-rt is linked duplicate-ly into all shared objects meaning
that it's not suitable for define-once symbols such as
`__cpp_exception`. By moving the definition to the user of the symbol,
libunwind itself, that guarantees that the symbol should be defined
exactly once and only when appropriate. A secondary reason for this
movement is that it avoids the need to compile compiler-rt twice: once
with exception and once without, and instead the same build can be used
for both exceptions-and-not.
2026-03-11 00:43:11 +00:00
Joseph Huber
fd069a46bf
[copmiler-rt] Initial support for building profile library on the GPU (#185552)
Summary:
As suggested in https://github.com/llvm/llvm-project/pull/177665, we
should build a GPU version of the compiler-rt profile library instead of
writing it in-line in the lowering. This PR does not define anything GPU
specific, it simply re-uses the baremetal handling. Later PRs will
prevent the GPU specific handling we would want to do to optimize
counter handling on the GPU.

Note that this will require using the cache file, or setting these
options
manually for existing users. Hopefully if people are using the cache
file
as they should it won't break anything.
2026-03-10 13:45:18 -05:00
Christopher Ferris
3e9808befb
[scudo] Use a fixed format for the milliseconds in latest release. (#185097) 2026-03-09 12:50:32 -07:00
Fabio D'Urso
ae8f614a0c
[scudo] Add missing class name specifier in mem_map_fuchsia (#185389) 2026-03-09 18:48:53 +01:00
Matthew Nagy
2a9372ff02
halt_on_error flag for TySan and docs (#182479) 2026-03-09 15:42:25 +00:00
Nico Weber
4d53c42f55 builtins: Make cmake formatting self-consistent aftr #183871
No behavior change.
2026-03-06 15:33:30 -05:00
Saleem Abdulrasool
57f1ec6e0a
builtins: adjust FP80 source management (#183871)
We would previously include the FP80 sources into the Windows build if
we built with the GNU driver rather than the `cl` driver.
2026-03-06 11:12:13 -08:00
Kito Cheng
d64a9fe781
[compiler-rt][RISCV] Initialize length only when __init_riscv_feature… (#115449)
…_bits success

That could give us a simple way to detect `__init_riscv_feature_bits`
got fail.

See also https://github.com/riscv-non-isa/riscv-c-api-doc/pull/95
2026-03-06 19:37:11 +08:00