19290 Commits

Author SHA1 Message Date
B I Mohammed Abbas
28ae2ff2a4
Add truncxfhf2 with tests to compiler-rt (#120372)
Fixes #105181
2024-12-30 14:14:43 -08:00
Muhammad Omair Javaid
5373ed0e79 [fuzzer][test] Disable noasan-strcmp test for AArch64
This patch disables the `noasan-strcmp.test` for AArch64 Linux as it
consistently fails on the buildbot machine while passing on other
AArch64 Linux systems.

We have seen similar issues on noasan-strncmp.test in past which had
random failures on certain machines/environments.

Following buildbot is failing in both check stage1 and stage2:
https://lab.llvm.org/buildbot/#/builders/121/builds/711
2024-12-31 00:52:03 +05:00
Petr Hosek
9a88edeb49
[TYSan][CMake] CMake build fixes (#121224)
TYSan CMake build follows patterns used by other sanitizers, but there's
also a number of issues, like referring to undefined variables, which
breaks the build in some cases (such as cross-compiling). This change
addresses the issues.
2024-12-30 11:51:44 -08:00
Stefan Schulze Frielinghaus
65a2eb0b15
[sanitizer] Fix type in some Min() calls (#119248)
This is a follow-up to 6dec33834d1fd89f16e271dde9607c1de9554144 and
#116957 and #119114.
2024-12-30 10:24:55 -08:00
NAKAMURA Takumi
de294c968b
[profile] Enable testing Continuous mode on Linux (#121238)
Based on #115987, with the introduction of `REQUIRES: continuous-mode`.
Also Linux assumes `runtime_reloc`.

FIXME: image-with-no-counters.c is still excluded.
2024-12-29 12:02:13 +09:00
Vitaly Buka
74496b03f7 [asan][hwasan] Link RTUbsan_cxx into shared runtime
There is no shared version RTUbsan_cxx.
Fix android after #121006.
2024-12-24 23:37:59 -08:00
Vitaly Buka
32962f2b77 [ubsan] Try to fix Windows 2024-12-24 23:08:20 -08:00
Vitaly Buka
a1328c077c [ubsan] Fix android build
Broken by #121006.
2024-12-24 20:26:31 -08:00
Vitaly Buka
1de228fa9b
[ubsan] Remove UBSAN_CAN_USE_CXXABI (#121082)
It's should be enough to provide weak implementation.

Fixes solaris and android linking after #121006.
2024-12-24 20:21:40 -08:00
Vitaly Buka
cd66c9b6a0
[Ubsan][Driver] Remove UBSAN C++ runtime from other sanitizers (#121006)
Linking this runtime requires C++ ABI, which breaks -nostdlib++ builds.
However, UBSAN C++ runtime is only needed for CFI and VPTR checks.

Unblocks #120370.
2024-12-24 13:57:03 -08:00
Mingjie Xu
34d55df73b
[tysan] Replace HandleEarlyAlloc with DlsymAlloc (#120563) 2024-12-23 09:04:00 +08:00
Thurston Dang
d8e10d13d7 [rtsan] Fix-forward TEST(TestRtsanInterceptors, PpollDiesWhenRealtime)
Buildbot breakage:
home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp:1090:19: error: missing field 'tv_nsec' initializer [-Werror,-Wmissing-field-initializers]
 1090 |   timespec ts = {0};

introduced by https://github.com/llvm/llvm-project/pull/120366/files
2024-12-20 20:53:24 +00:00
David CARLIER
f39ecb7b28
[compiler][rtsan] stream based on memory buffer interception. (#120672) 2024-12-20 17:29:30 +00:00
David CARLIER
adfef2a753
[compiler-rt][rtsan] ppoll interception. (#120366) 2024-12-20 17:28:53 +00:00
Sander de Smalen
811f2a652b
[Compiler-rt] Add AArch64 routines for __arm_agnostic("sme_za_state") (#120059)
The specification of these routines can be found here:

https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#sme-support-routines
2024-12-20 15:49:33 +00:00
Hans Wennborg
69ebac7ad6
[win/asan] Don't intercept memset etc. in ntdll (#120397)
When ntdll was added to the list of of "interesting DLLs" list (in
d58230b9dcb3b312a2da8f874daa0cc8dc27da9b), the intention was not to
intercept the "mini CRT" functions it exports. OverrideFunction would
only intercept the *first* function it found when searching the list of
DLLs, and ntdll was put last in that list.

However, after 42cdfbcf3e92466754c175cb0e1e237e9f66749e,
OverrideFunction intercepts *all* matching functions in those DLLs. As
a side-effect, the runtime would now intercept functions like memset
etc. also in ntdll.

This causes a problem when ntdll-internal functions like
RtlDispatchException call the intercepted memset, which tries to
inspect uncommitted shadow memory, raising an exception, and getting
stuck in that loop until the stack overflows.

Since we never intended to intercept ntdll's memset etc., the simplest
fix seems to be to actively ignore ntdll when intercepting those
functions.

Fixes #114793
2024-12-20 11:03:17 +01:00
Hans Wennborg
e10cb443a1 Revert "[compiler-rt] Add weak defs for .*contiguous_container.* functions (#120376)"
This reverts commit a73ca291547cf4f5822a3029dd56315354557517.
2024-12-20 10:56:38 +01:00
Dmitry Chestnykh
a73ca29154
[compiler-rt] Add weak defs for .*contiguous_container.* functions (#120376)
Fix #120278
2024-12-20 07:19:05 +03:00
Vitaly Buka
91e392b283 [ubsan] Fix test on Windows 2024-12-19 19:52:31 -08:00
Vitaly Buka
c2aee50620
[ubsan] Runtime and driver support for local-bounds (#120515)
Implements ``-f[no-]sanitize-trap=local-bounds``,
and ``-f[no-]sanitize-recover=local-bounds``.

LLVM part is here #120513.
2024-12-19 16:38:07 -08:00
Brad Smith
6f983f8853
[compiler-rt] Set the default C++ library to libc++ on OpenBSD (#107694) 2024-12-19 18:33:29 -05:00
ChiaHungDuan
b71c44b9be
[scudo] Add the record of number of attempted page release (#120497)
This also removes the `RangesReleased` which doesn't give much insight
to whether we should adjust the heuristic of doing page release.
2024-12-19 10:47:44 -08:00
Thurston Dang
60a2f32cf5 Revert "[driver] Fix sanitizer libc++ runtime linking (#120370)"
This reverts commit 9af5de320b77d3757ea2b7e3d85c67f88dfbabb5.

Reason: buildbot breakage
(https://lab.llvm.org/buildbot/#/builders/24/builds/3394/steps/10/logs/stdio)
"Unexpectedly Passed Tests (1):
   llvm-libc++-shared.cfg.in :: libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp"
2024-12-19 01:41:14 +00:00
Vitaly Buka
0fd7c49a77
[ubsan] Add runtime test for -fsanitize=local-bounds (#120038) 2024-12-18 15:23:34 -08:00
Vitaly Buka
9af5de320b
[driver] Fix sanitizer libc++ runtime linking (#120370)
1. -f[no-]sanitize-link-c++-runtime suppose to
   override defauld behavior implied from `CCCIsCXX`
2. Take into account -nostdlib++ (unblocks #108357)
3. Fix typo hasFlag vs hasArg.
2024-12-18 10:37:44 -08:00
Kazu Hirata
f8b497ef61
[compiler-rt] Work around a warning from -Wgnu-anonymous-struct (#120314)
This patch works around:


compiler-rt/lib/tysan/../sanitizer_common/sanitizer_platform_limits_posix.h:604:3:
  error: anonymous structs are a GNU extension
  [-Werror,-Wgnu-anonymous-struct]
2024-12-17 19:51:20 -08:00
Florian Hahn
641fbf1524
[TySan] Add initial Type Sanitizer runtime (#76261)
This patch introduces the runtime components for type sanitizer: a
sanitizer for type-based aliasing violations.

It is based on Hal Finkel's https://reviews.llvm.org/D32197.

C/C++ have type-based aliasing rules, and LLVM's optimizer can exploit
these given TBAA metadata added by Clang. Roughly, a pointer of given
type cannot be used to access an object of a different type (with, of
course, certain exceptions). Unfortunately, there's a lot of code in the
wild that violates these rules (e.g. for type punning), and such code
often must be built with -fno-strict-aliasing. Performance is often
sacrificed as a result. Part of the problem is the difficulty of finding
TBAA violations. Hopefully, this sanitizer will help.

For each TBAA type-access descriptor, encoded in LLVM's IR using
metadata, the corresponding instrumentation pass generates descriptor
tables. Thus, for each type (and access descriptor), we have a unique
pointer representation. Excepting anonymous-namespace types, these
tables are comdat, so the pointer values should be unique across the
program. The descriptors refer to other descriptors to form a type
aliasing tree (just like LLVM's TBAA metadata does). The instrumentation
handles the "fast path" (where the types match exactly and no
partial-overlaps are detected), and defers to the runtime to handle all
of the more-complicated cases. The runtime, of course, is also
responsible for reporting errors when those are detected.

The runtime uses essentially the same shadow memory region as tsan, and
we use 8 bytes of shadow memory, the size of the pointer to the type
descriptor, for every byte of accessed data in the program. The value 0
is used to represent an unknown type. The value -1 is used to represent
an interior byte (a byte that is part of a type, but not the first
byte). The instrumentation first checks for an exact match between the
type of the current access and the type for that address recorded in the
shadow memory. If it matches, it then checks the shadow for the
remainder of the bytes in the type to make sure that they're all -1. If
not, we call the runtime. If the exact match fails, we next check if the
value is 0 (i.e. unknown). If it is, then we check the shadow for the
remainder of the byes in the type (to make sure they're all 0). If
they're not, we call the runtime. We then set the shadow for the access
address and set the shadow for the remaining bytes in the type to -1
(i.e. marking them as interior bytes). If the type indicated by the
shadow memory for the access address is neither an exact match nor 0, we
call the runtime.

The instrumentation pass inserts calls to the memset intrinsic to set
the memory updated by memset, memcpy, and memmove, as well as
allocas/byval (and for lifetime.start/end) to reset the shadow memory to
reflect that the type is now unknown. The runtime intercepts memset,
memcpy, etc. to perform the same function for the library calls.

The runtime essentially repeats these checks, but uses the full TBAA
algorithm, just as the compiler does, to determine when two types are
permitted to alias. In a situation where access overlap has occurred and
aliasing is not permitted, an error is generated.

As a note, this implementation does not use the compressed shadow-memory
scheme discussed previously
(http://lists.llvm.org/pipermail/llvm-dev/2017-April/111766.html). That
scheme would not handle the struct-path (i.e. structure offset)
information that our TBAA represents. I expect we'll want to further
work on compressing the shadow-memory representation, but I think it
makes sense to do that as follow-up work.

This includes build fixes for Linux from Mingjie Xu.

Depends on #76260 (Clang support), #76259 (LLVM support)


PR: https://github.com/llvm/llvm-project/pull/76261
2024-12-17 18:49:50 +00:00
lntue
a57f4c7009
[compiler-rt] Fix a bug in fp_div_impl when an intermediate result is out of expected range. (#119449)
Before this fix, `1.0L / (1.0L - 0x1.0p-113L)` will return `2 * (1 +
eps(1))`.
2024-12-17 12:24:57 -05:00
Sander de Smalen
1b8099040e Reland "[compiler-rt][AArch64] Allow platform-specific mangling of SME routines. (#119864)"
Avoid issues caused by `.subsections_via_symbols` directive, by using
numbered labels instead of named labels for the branch locations.

This reverts commit 4032ce3413d0230b0ccba1203536f9cb35e5c3b5.
2024-12-17 11:48:02 +00:00
paperchalice
b07e7b76c5
[cmake] Drop AddFileDependencies and CMakeParseArguments (#120002)
Theses modules are deprecated and have trivial implementations in modern
cmake.
2024-12-17 19:24:32 +08:00
Sander de Smalen
4032ce3413 Revert "[compiler-rt][AArch64] Allow platform-specific mangling of SME routines. (#119864)"
This reverts commit e0fb3acd8a0b2a9340b9b2ae370c84c98f1a5cc2.
2024-12-16 17:39:04 +00:00
Sander de Smalen
e0fb3acd8a
[compiler-rt][AArch64] Allow platform-specific mangling of SME routines. (#119864)
Support platform-specific mangling to avoid the compiler emitting a call
to a function that is mangled differently than the definition in the
runtime library.
2024-12-16 09:12:08 +00:00
Lang Hames
8daf4f16fa [ORC][ORC-RT] Add ORC-RT based lazy compilation support for x86-64.
Adds support for the ORC-RT based lazy compilation scheme that was introduced
in 570ecdcf8b4.
2024-12-15 23:50:31 +00:00
Nico Weber
1464b8ec8a Revert "Move interceptors for libresolv functions to MSan (#119071)"
This reverts commit f5f965058a5f9b835382f96bd4041bc7e608ece0.
Breaks a test on some bots, see
https://github.com/llvm/llvm-project/pull/119071#issuecomment-2544000926
2024-12-15 14:04:56 -05:00
Kirill Stoimenov
71d2fa7988
[ubsan-minimal] Switch to weak symbols for callbacks to allow overriding in client code (#119242) 2024-12-13 15:10:40 -08:00
Kirill Stoimenov
e5e0f23ae8
[nfc][ubsan-minimal] Refactor error reporting to use a single function (#119920)
This refactoring will allow to make this function weak later on so that
it could be overloaded by a client. See #119242.
2024-12-13 13:43:07 -08:00
Mike Hommey
5828aef014
[sanitizer_common] Return nullptr from ASan on ERROR_COMMITMENT_LIMIT (#119753)
Followup to #117929
2024-12-12 23:46:36 -08:00
Lang Hames
ae89be0797 [ORC-RT] Fix comments. NFC.
Fix file name, symbol name, and formatting in comments.
2024-12-13 06:26:19 +00:00
Sander de Smalen
e5371eded9
[compiler-rt] Don't build SME routines if __arm_cpu_features is not initialised. (#119703)
According to the conversation

[here](https://github.com/llvm/llvm-project/pull/119414#issuecomment-2536495859),
some platforms don't enable `__arm_cpu_features` with a global
constructor, but rather do so lazily when called from the FMV resolver.

PR #119414 removed the CMake guard to check to see if the targetted
platform is baremetal or supports sys/auxv. Without this check, the
routines rely on `__arm_cpu_features` being initialised when they may
not be, depending on the platform.

This PR simply avoids building the SME routines for those platforms for
now.
2024-12-12 15:59:48 +00:00
Yi Kong
34d244a941
Fix rtsan build with musl (#119674)
fd_set is defined by `sys/select.h`. On musl, this header is not
transitively included by the other headers.

Failure message:
```
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp:761:37: error: unknown type name 'fd_set'; did you mean 'fd_t'?
  761 | INTERCEPTOR(int, pselect, int nfds, fd_set *readfds, fd_set *writefds,
      |                                     ^~~~~~
      |                                     fd_t
```
2024-12-12 22:57:41 +09:00
bernhardu
f85579fb51
[win/asan] GetInstructionSize: Fix 83 E4 XX to return 3. (#119644)
This consolidates the two different lines for x86 and x86_64 into a
single line for both architectures.
And adds a test line.

CC: @zmodem
2024-12-12 13:37:05 +01:00
Sander de Smalen
cb4f4a8a4d
[compiler-rt][AArch64] Rewrite SME routines to all use __aarch64_cpu_features. (#119414)
When #92921 added the `__arm_get_current_vg` functionality, it used the
FMV feature bits mechanism rather than the mechanism that was previously
added for SME which called `getauxval` on Linux platforms or
`__aarch64_sme_accessible` required for baremetal libraries. It is
better to always use `__aarch64_cpu_features`.

For baremetal we still need to rely on `__arm_sme_accessible` to
initialise the struct.
2024-12-11 15:53:17 +00:00
bernhardu
854ea0cf18
[win/asan] GetInstructionSize: Make 83 EC XX a generic entry. (#119537)
This consolidates the two different lines for x86 and x86_64 into a
single line for both architectures.
And adds a test line.

CC: @zmodem
2024-12-11 14:47:11 +01:00
David Justo
2dc22615fd
[ASan] Honor allocator_may_return_null when set through user-function and fix large alloc edge case (#117929)
**Related:** #117925

**About this PR:**
This PR performs 3 small but related fixes for ASan users on Windows:
1. It ensures that the `allocator_may_return_null` flag is honored when
set through the user function `__asan_default_options`. For more
details, please see: #117925
2. It adds a missing `AllocatorMayReturnNull()` check inside
`InternalAlloc` that's needed to avoid error'ing out when the allocator
_correctly_ returns `null` when `allocator_may_return_null` is set.
3. In `sanitizer_win`'s `ReturnNullptrOnOOMOrDie`, it allows returning
`null` when the last error is set to `ERROR_INVALID_PARAMETER` which may
be set by `VirtualAlloc` on WIndows when attempting to allocate
exceedingly large memory.

I've added test cases that should cover these new behaviors. Happy to
take on any feedback as well. Thank you :-)

---------

Co-authored-by: David Justo <dajusto@microsoft.com>
2024-12-11 10:21:35 +01:00
Min-Yih Hsu
ea76b2d8d8
[XRay][RISCV] RISCV support for XRay (#117368)
Add RISC-V support for XRay. The RV64 implementation has been tested in
both QEMU and in our hardware environment.

Currently this requires D and C extensions, but since both RV64GC and
RVA22/RVA23 are becoming mainstream, I don't think this requirement will
be a big problem.

Based on the previous work by @a-poduval :
https://reviews.llvm.org/D117929

---------

Co-authored-by: Ashwin Poduval <ashwin.poduval@gmail.com>
2024-12-10 17:57:04 -08:00
ChiaHungDuan
5a930339a5
[scudo] Minor refactor on element address validation (NFC) (#119436) 2024-12-10 13:58:02 -08:00
Ellis Hoag
968e3b6823
[memprof] Add flag to control profile dump at exit (#119452)
Add the `dump_at_exit` flag to control whether or not profiles should be
dumped when the program exits. Since we can call
`__memprof_profile_dump()` directly, we don't necessarily need to dump
profiles at exit.
2024-12-10 13:12:08 -08:00
Vitaly Buka
e0f3410be9 [compiler-rt] Fix a few new lines in Maintaners.md 2024-12-10 11:11:45 -08:00
Vitaly Buka
4c04bf8116
[compiler-rt] Convert Maintainers.txt into Maintainers.md (#119169)
Structured similarly to llvm/Maintainers.md.

PR has no intent to change any component maintenter.
2024-12-10 11:05:39 -08:00
Vitaly Buka
9c509a0c6a
[compiler-rt] Update maintainers (#119166) 2024-12-10 11:00:23 -08:00