19345 Commits

Author SHA1 Message Date
Jake Egan
50fe5b90e7
[sanitizer_common][NFC] Fix sanitizer_symbolizer_libcdep.cpp formatting (#133930) 2025-04-03 10:39:49 -04:00
gbMattN
59074a3760
[ASan] Add metadata to renamed instructions so ASan doesn't use the i… (#119387)
…ncorrect name

Clang needs variables to be represented with unique names. This means
that if a variable shadows another, its given a different name
internally to ensure it has a unique name. If ASan tries to use this
name when printing an error, it will print the modified unique name,
rather than the variable's source code name

Fixes #47326
2025-04-03 15:27:14 +01:00
Florian Mayer
e0c8fc793c
Reapply "[sanitizer] intercept getservent_r, getservbyname_r, getservbyport_r" (#133358) (#133528)
This reverts commit 52d7f14a895eb8669d72cd02754e5586de3e61d8.
2025-04-01 15:25:01 -07:00
Mariusz Borsa
02837acaaf
[Sanitizers][Darwin][Test] Remove community incompliant internal link from sources (#133187)
The malloc_zone.cpp test currently fails on Darwin hosts, in
SanitizerCommon
tests with lsan enabled.

Need to XFAIL this test to buy time to investigate this failure. Also
we're trying to bring the number of test failing on Darwin bots to 0, to
get clearer signal of any new failures.

rdar://145873843

Co-authored-by: Mariusz Borsa <m_borsa@apple.com>
2025-03-31 17:06:41 -07:00
Mircea Trofin
225f6ddb32
[ctxprof][nfc] Remove redundant SANITIZER_NO_THREAD_SAFETY_ANALYSIS (#133784)
With the refactoring in PR #133744, `__llvm_ctx_profile_start_context` doesn't need to be marked `SANITIZER_NO_THREAD_SAFETY_ANALYSIS` because `tryStartContextGivenRoot` (where the bulk of the logic went) is.
2025-03-31 12:49:54 -07:00
Mircea Trofin
b01e5b23dd
[ctxprof][nfc] Refactor __llvm_ctx_profile_start_context (#133744)
Most of the functionality will be reused with the auto-root detection mechanism (which is introduced subsequently in PR #133147).
2025-03-31 12:26:25 -07:00
Wael Yehia
7eb99b8599 [AIX][PGO] Add testcase for D136192
Reviewed By: mandlebug

Differential Revision: https://reviews.llvm.org/D136192
2025-03-31 17:40:55 +00:00
Mircea Trofin
8e1d9f2d84
[ctxprof][nfc] Move 2 implementation functions up in CtxInstrProfiling.cpp (#133146) 2025-03-28 20:53:50 -07:00
Mircea Trofin
63bb0078f8
[ctxprof] Auto root detection: trie for stack samples (#133106)
An initial patch for supporting automated root detection. The auto-detector is introduced subsequently, but this patch introduces a datastructure for capturing sampled stacks, per thread, in a trie, and inferring from such samples which functions are reasonable roots.
2025-03-28 20:08:05 -07:00
Florian Mayer
1e00bb16f4
[sanitizer] actually run preadv2 test (#133529)
it seems the %run was accidentally omitted, otherwise the `assert` calls
would not make sense
2025-03-28 16:31:38 -07:00
Qinkun Bao
45b9e24b1e
Fix some small typos in compiler-rt. NFC (#133388) 2025-03-28 15:51:13 -04:00
Joseph Huber
772173f548
[Clang][AMDGPU] Remove special handling for COV4 libraries (#132870)
Summary:
When we were first porting to COV5, this lead to some ABI issues due to
a change in how we looked up the work group size. Bitcode libraries
relied on the builtins to emit code, but this was changed between
versions. This prevented the bitcode libraries, like OpenMP or libc,
from being used for both COV4 and COV5. The solution was to have this
'none' functionality which effectively emitted code that branched off of
a global to resolve to either version.

This isn't a great solution because it forced every TU to have this
variable in it. The patch in
https://github.com/llvm/llvm-project/pull/131033 removed support for
COV4 from OpenMP, which was the only consumer of this functionality.
Other users like HIP and OpenCL did not use this because they linked the
ROCm Device Library directly which has its own handling (The name was
borrowed from it after all).

So, now that we don't need to worry about backward compatibility with
COV4, we can remove this special handling. Users can still emit COV4
code, this simply removes the special handling used to make the OpenMP
device runtime bitcode version agnostic.
2025-03-28 07:35:16 -05:00
Qinkun Bao
bed2bdf17b
[NFCI] Change compiler_rt_Test_runtime to lowercase (#133362) 2025-03-27 22:20:14 -07:00
Mircea Trofin
68571f9151 Revert "[compiler-rt][nfc] DenseMap needs placement new (#133329)"
This reverts commit 4485e25dd2a57be1ee504b4dd863a1e140f5084c.
Buildbot failures, e.g. https://lab.llvm.org/buildbot/#/builders/66/builds/11827
2025-03-27 22:15:13 -07:00
Mircea Trofin
4485e25dd2
[compiler-rt][nfc] DenseMap needs placement new (#133329) 2025-03-27 21:39:12 -07:00
Florian Mayer
52d7f14a89
Revert "[sanitizer] intercept getservent_r, getservbyname_r, getservbyport_r" (#133358)
Reverts llvm/llvm-project#133339
2025-03-27 22:51:04 -04:00
Florian Mayer
aa3149d204
[sanitizer] intercept getservent_r, getservbyname_r, getservbyport_r (#133339) 2025-03-27 17:05:37 -07:00
Hubert Tong
7712de3062
[compiler-rt][tests][AIX] Use /opt/freeware/bin/env (#133160)
`env -u` is not supported by the system `env` utility on AIX.

`/opt/freeware/bin/env` is the standard path for the GNU coreutils `env`
utility as distributed by the AIX Toolbox for Open Source Software.

Adding `/opt/freeware/bin` to `PATH` causes issues by picking up other
utilities that are less capable, in an AIX context, than the system
ones.

This patch modifies the relevant usage of `env` to use (on AIX) the full
path to `/opt/freeware/bin/env`.
2025-03-27 16:02:40 -04:00
Thurston Dang
e5ec87f3b6
[asan] Print diagnostic if unlimited stack size detected (#133170)
This adds a diagnostic message if the stack size is unlimited. This would have simplified the diagnosis of https://github.com/google/sanitizers/issues/856#issuecomment-2747076811; we anticipate this may help diagnose future issues too.
2025-03-27 08:55:36 -07:00
Thurston Dang
68e90e4f0c
[asan][NFCI] Add ASAN_POISONING_H header guard (#133178) 2025-03-26 22:52:34 -07:00
Wu Yingcong
e54f31a20c
[compiler-rt][builtins] Add missing flag for builtins standalone build (#133046)
When builtins are built with runtimes, it is built before compiler-rt,
and this makes some of the HAS_XXX_FLAGs missing. In this case, the
COMPILER_RT_HAS_FCF_PROTECTION_FLAG is missing which makes it impossible
to enable CET in this case. This patch addresses this issue by also
check for such flag in standalone build instead of relying on the
compiler-rt's detection.
2025-03-27 10:15:48 +08:00
David Tellenbach
03eb825840
[compiler-rt][Darwin][x86] Fix instrprof-darwin-dead-strip test (#132874)
ld issues a warning about section alignment on x86. Explicitly setting
the alignment fixes that.
2025-03-26 09:52:43 -07:00
Alexandros Lamprineas
cd3798d7ef
[FMV][AArch64] Add feature CSSC and detect on linux platform. (#132727)
Also removes priority bits for unused features predres and ls64.

Added to ACLE with https://github.com/ARM-software/acle/pull/390
2025-03-26 08:40:29 +00:00
David CARLIER
1940d7816a
[compiler-rt][sanitizer] setproctitle interception for NetBSD/FreeBSD. (#131648) 2025-03-26 05:17:53 +00:00
Ethan Luis McDonough
80d5185bd4
[PGO][Offload] Don't define GPU entrypoint on Darwin (#132966)
This PR partially reverts 83e180c and instead opts to not define the GPU entry
point on Darwin platforms. Marking `__llvm_write_custom_profile` as used
was causing issues on embedded platforms.
2025-03-25 23:28:01 -05:00
Christopher Ferris
134cb8877e
[scudo] Use a tryLock in secondary release to OS (#132827)
In the caching part of the secondary path, when about to try to release
memory to the OS, we always wait while acquiring the lock. However, if
multiple threads are attempting this at the same time, all other threads
will likely do nothing when the release call is made. Change the
algorithm to skip the release if there is another release in process.

Also, pull the lock outside the releaseOlderThan function. This is so
that in the store path, we use the tryLock and skip if another thread is
releasing. But in the path where a forced release call is being made,
that call will wait for release to complete which guarantees that all
entries are released when requested.
2025-03-25 16:32:16 -07:00
Midhunesh
d75a40a9c1
Add cmake option to enable/disable searching PATH for symbolizer (#129012)
Introduced a cmake option that is disabled by default that suppresses
searching via the PATH variable for a symbolizer. The option will be
enabled for downstream builds where the user will need to specify the
symbolizer path more explicitly, e.g., by using ASAN_SYMBOLIZER_PATH.
2025-03-25 16:29:35 -07:00
Vitaly Buka
03817f0ec0
[NFC][sanitizer] Clang-format sanitizer_symbolizer_posix_libcdep.cpp (#133011) 2025-03-25 15:18:04 -07:00
David Benjamin
e6de45a229
[tsan] Don't treat uncontended pthread_once as a potentially blocking region (#132477)
guard_acquire is a helper function used to implement TSan's
__cxa_guard_acquire and pthread_once interceptors.
https://reviews.llvm.org/D54664 introduced optional hooks to support
cooperative multi-threading. It worked by marking the entire
guard_acquire call as a potentially blocking region.

In principle, only the contended case needs to be a potentially blocking
region. This didn't matter for __cxa_guard_acquire because the compiler
emits an inline fast path before calling __cxa_guard_acquire. That is,
once we call __cxa_guard_acquire at all, we know we're in the contended
case.

https://reviews.llvm.org/D107359 then unified the __cxa_guard_acquire
and pthread_once interceptors, adding the hooks to pthread_once.
However, unlike __cxa_guard_acquire, pthread_once callers are not
expected to have an inline fast path. The fast path is inside the
function.

As a result, TSan unnecessarily calls into the cooperative
multi-threading engine on every pthread_once call, despite applications
generally expecting pthread_once to be fast after initialization. Fix
this by deferring the hooks to the contended case inside guard_acquire.
2025-03-24 19:30:15 -04:00
Thurston Dang
3ce3d889f6
[asan] Re-exec without ASLR if needed on 64-bit Linux (#132682)
This generalizes https://github.com/llvm/llvm-project/pull/131975 to non-32-bit Linux (i.e., 64-bit Linux).

This works around an edge case in 64-bit Linux, whereby the memory layout is incompatible if the stack size is unlimited AND ASLR entropy is 31+ bits (see https://github.com/google/sanitizers/issues/856#issuecomment-2747076811).

More generally, this "re-exec without ASLR if layout is incompatible" is a hammer that can work around most shadow mapping issues, without incurring the overhead of using a dynamic shadow.
2025-03-24 16:24:38 -07:00
David CARLIER
8a8e4cfc0b
[compiler-rt][rtsan] Linux timerfd api interception. (#132709) 2025-03-24 11:47:43 +00:00
Thurston Dang
702c38ed7c [asan] Fix-forward #131975 by renaming 'TryReExecWithoutASLR'
Function definition added in #131975 was missing 'Try' (do or do not ...). My guess is buildbots
mostly didn't trip because usage was gated by 'if (sizeof(uptr) ==
32)', which is rare among buildbots.
2025-03-24 07:00:57 +00:00
Lang Hames
ef3e521a2b [ORC-RT] Add unique_function utility to the ORC runtime.
A bare-bones version of LLVM's unique_function: this behaves like a
std::unique_function, except that it supports move only callable types.

This will be used in upcoming improvements to the ORC runtime.
2025-03-24 15:46:43 +11:00
Lang Hames
5d8e8e82e1 [ORC-RT] Rename extensible_rtti.{h,cpp} to rtti.{h,cpp}. NFCI.
The "extensible_" prefix on these files was inherited from LLVM, where it
distinguished the dynamic RTTI APIs from the LLVM's custom static RTTI APIs.

In the ORC runtime these files will be used to hold all of our RTTI APIs
(the current dynamic ones, and any static ones added in the future), so we
shouldn't use this prefix.
2025-03-24 13:49:23 +11:00
Lang Hames
36b1fb5c7a [ORC-RT] Fix typos in file comments. NFC. 2025-03-24 13:49:23 +11:00
David CARLIER
b2b3cb5f76
[compiler-rt][rtsan] memffd_create for linux interception. (#132571) 2025-03-23 20:37:48 +00:00
Daniel Chen
f73da649cb
Revert "[compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (#131200)" (#132574)
…

This reverts commit 8e773d8a10cc996fbbe834f59ed9f7044c3539e0.
2025-03-22 20:56:47 -04:00
Paddy McDonald
4517a332df
[Darwin][ASan][Test] Create a unoptimized wrapper function in unsanitized dylib for reliable suppression in test. (#131906)
CFStringCreateWithBytes may not always appear on stack due to
optimizations.

Create a wrapper function for the purposes of testing suppression files
that will always appear on stack for test stability.

Test should be suppressing ASan for a function outside of sanitized
code.
Update function to be extern "C" to match function decoration in
original framework and avoid the leak caused by DemangleCXXABI.

rdar://144800068
2025-03-21 17:17:32 -07:00
Justin Cady
954a3de783
Reland [Coverage] Fix region termination for GNU statement expressions (#132222)
Relands #130976 with adjustments to test requirements.

Calls to __noreturn__ functions result in region termination for
coverage mapping. But this creates incorrect coverage results when
__noreturn__ functions (or other constructs that result in region
termination) occur within [GNU statement expressions][1].

In this scenario an extra gap region is introduced within VisitStmt,
such that if the following line does not introduce a new region it
is unconditionally counted as uncovered.

This change adjusts the mapping such that terminate statements
within statement expressions do not propagate that termination
state after the statement expression is processed.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

Fixes #124296
2025-03-21 11:59:01 -04:00
bernhardu
610ade2ed7
[win/asan] GetInstructionSize: Detect 66 90 two-byte NOP at 32-bit too. (#132267)
Observed in Wine when trying to intercept `ExitThread`, which forwards
to `ntdll.RtlExitUserThread`.

`gdb` interprets it as `xchg %ax,%ax`.
`llvm-mc` outputs simply `nop`.

```
==Asan-i386-calls-Dynamic-Test.exe==964==interception_win: unhandled instruction at 0x7be27cf0: 66 90 55 89 e5 56 50 8b
```

```
Wine-gdb> bt
#0  0x789a1766 in __interception::GetInstructionSize (address=<optimized out>, rel_offset=<optimized out>) at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_win.cpp:983
#1  0x789ab480 in __sanitizer::SharedPrintfCode(bool, char const*, char*) () at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_printf.cpp:311
#2  0x789a18e7 in __interception::OverrideFunctionWithHotPatch (old_func=2078440688, new_func=2023702608, orig_old_func=warning: (Internal error: pc 0x792f1a2c in read in CU, but not in symtab.)warning: (Error: pc 0x792f1a2c in address map, but not in symtab.)0x792f1a2c) at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_win.cpp:1118
#3  0x789a1f34 in __interception::OverrideFunction (old_func=2078440688, new_func=2023702608, orig_old_func=warning: (Internal error: pc 0x792f1a2c in read in CU, but not in symtab.)warning: (Error: pc 0x792f1a2c in address map, but not in symtab.)0x792f1a2c) at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_win.cpp:1224
#4  0x789a24ce in __interception::OverrideFunction (func_name=0x78a0bc43 <vtable for __asan::AsanThreadContext+1163> "ExitThread", new_func=2023702608, orig_old_func=warning: (Internal error: pc 0x792f1a2c in read in CU, but not in symtab.)warning: (Error: pc 0x792f1a2c in address map, but not in symtab.)0x792f1a2c)    at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_win.cpp:1369
#5  0x789f40ef in __asan::InitializePlatformInterceptors () at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_win.cpp:190
#6  0x789e0c3c in __asan::InitializeAsanInterceptors () at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:802
#7  0x789ee6b5 in __asan::AsanInitInternal () at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:442
#8  0x789eefb0 in __asan::AsanInitFromRtl () at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:522
#9  __asan::AsanInitializer::AsanInitializer (this=<optimized out>) at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:542
#10 __cxx_global_var_init () at C:/llvm-mingw/llvm-mingw/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:546
...
Wine-gdb> disassemble /r 2078440688,2078440688+20
Dump of assembler code from 0x7be27cf0 to 0x7be27d04:
   0x7be27cf0 <_RtlExitUserThread@4+0>: 66 90                   xchg   %ax,%ax
...
```
2025-03-21 14:45:20 +01:00
Mircea Trofin
dd191d3d4f
[ctxprof][nfc] Share the definition of FunctionData between compiler-rt and llvm (#132136)
Mechanism to keep the compiler-rt and llvm view of `FunctionData` in sync. Since CtxInstrContextNode.h is exactly the same on both sides (there's an existing test, `compiler-rt/test/ctx_profile/TestCases/check-same-ctx-node.test`, checking that), we capture the structure in a macro that is then generated as `struct` fields on the compiler-rt side, and as `Type` objects on the llvm side. The macro needs to be told how to render a few kinds of fields. 

If we add more fields to FunctionData that can be described by the current known types of fields, then the llvm side would automatically be updated. If we need to add more kinds of fields, which we do by adding parameters to the macro, the llvm side (if not updated) would trigger a compilation error.
2025-03-20 12:48:18 -07:00
Thurston Dang
adb57757b9 [asan] Fix-forward by removing sys/personality.h for non-Linux in #131975
Fix Solaris build breakage reported in https://github.com/llvm/llvm-project/pull/131975#issuecomment-2741097471
2025-03-20 17:25:34 +00:00
Thurston Dang
89a1197c1f [asan] Fix-forward by adding SANITIZER_LINUX guard to 131975
Fix Solaris build breakage reported in https://github.com/llvm/llvm-project/pull/131975#issuecomment-2741097471
2025-03-20 17:23:03 +00:00
Wael Yehia
e202ff45df [profile] Implement a non-mmap path when reading profile files from a non-local filesystem (#131177)
On AIX, when accessing mmap'ed memory associated to a file on NFS, a
SIGBUS might be raised at random.
The problem is still in open state with the OS team.

This PR teaches the profile runtime, under certain conditions, to avoid
the mmap when reading the profile file during online merging.
This PR has no effect on any platform other than AIX because I'm not
aware of this problem on other platforms.
Other platforms can easily opt-in to this functionality in the future.

The logic in function `is_local_filesystem` was copied from
[llvm/lib/Support/Unix/Path.inc](f388ca3d9d/llvm/lib/Support/Unix/Path.inc (L515))
(https://reviews.llvm.org/D58801), because it seems that the
compiler-rt/profile cannot reuse code from llvm except through
`InstrProfData.inc`.

Thanks to @hubert-reinterpretcast for substantial feedback downstream.

---------

Co-authored-by: Wael Yehia <wyehia@ca.ibm.com>
Co-authored-by: Hubert Tong <hubert.reinterpretcast@gmail.com>
2025-03-20 17:34:34 +00:00
Thurston Dang
3b3f8c50b6
[asan] Re-exec without ASLR if needed on 32-bit Linux (#131975)
High-entropy ASLR allows up to 16-bits of entropy (2**16 4KB pages ==
256MB; a bit more in practice because of implementation details), which
is a significant chunk of the user address space on 32-bit systems (4GB
or less). This, combined with ASan's shadow (512MB) and ASan's fixed
shadow offset (512MB), makes it possible for large binaries to fail to
map the shadow.

This patch changes ASan to do a one-time re-exec without ASLR if it
cannot map the shadow, thus reclaiming the ~256MB of address space.

Alternatives considered:
1) We don't lower ASan's fixed shadow offset, because that would limit
non-PIE binaries.
2) We don't switch to a dynamic shadow offset, because ASan for 32-bit
Linux relies on the compile-time constant offset to optimize its
instrumentation and compiler-rt.

This is loosely inspired by
https://github.com/llvm/llvm-project/pull/78351,
https://github.com/llvm/llvm-project/pull/85142, and
https://github.com/llvm/llvm-project/pull/85674, though those were
required because there were no static shadow mappings that could fully
shadow the range of user mappings; this is not the case for ASan.
2025-03-20 08:02:48 -07:00
Ethan Luis McDonough
c50d39f073
[PGO][Offload] Allow PGO flags to be used on GPU targets (#94268)
This pull request is the third part of an ongoing effort to extends PGO
instrumentation to GPU device code and depends on
https://github.com/llvm/llvm-project/pull/93365. This PR makes the
following changes:

- Allows PGO flags to be supplied to GPU targets
- Pulls version global from device
- Modifies `__llvm_write_custom_profile` and `lprofWriteDataImpl` to
allow the PGO version to be overridden
2025-03-19 19:01:38 -05:00
Mircea Trofin
0668bb28cc
[ctxprof] Track unhandled call targets (#131417)
Collect profiles for functions we encounter when collecting a contextual profile, that are not associated with a call site. This is expected to happen for signal handlers, but it also - problematically - currently happens for mem{memset|copy|move|set}, which are currently inserted after profile instrumentation.

Collecting a "regular" flat profile in these cases would hide the problem - that we loose better profile opportunities.
2025-03-19 13:51:22 -07:00
Justin Cady
bd2d8c0a7e
Revert "[Coverage] Fix region termination for GNU statement expressions" (#132095)
Reverts llvm/llvm-project#130976

Breaks clang-cmake-x86_64-avx512-linux bot.
2025-03-19 16:48:34 -04:00
Daniel Chen
8e773d8a10
[compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (#131200)
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON is not supported on AIX.
Set it to OFF with a WARNING message on AIX.
2025-03-19 16:35:15 -04:00
Arthur Eubanks
32476b9934 Revert " [profile] Implement a non-mmap path when reading profile files from a non-local filesystem (#131177)"
This reverts commit 14c95e0c8b25f6deba47cd279c5dcdeef3870159.

Test fails on mac, e.g. https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/3899/testReport/junit/Profile-x86_64/Profile-x86_64/instrprof_no_mmap_during_merging_c/
2025-03-19 20:31:32 +00:00