19366 Commits

Author SHA1 Message Date
Thurston Dang
3ad2cd5e70 [asan] Fix-forward #133175 by restricting newly-added tests to Linux
This was failing on Mac
(https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/4107/ and
https://issues.chromium.org/issues/409995888). Since this is an
experimental feature, rather than play whack-a-mole with selectively
disabling failing platforms (previously done for Android), this patch
restricts it to Linux.
2025-04-11 15:09:41 +00:00
Vitaly Buka
862e7190c9
Reland "Replace bool operator== for VersionType in sanitizer_mac.h" (#135276)
Fixes error: ISO C++20 considers use of overloaded operator '==' (with
operand types 'MacosVersion' and 'MacosVersion') to be ambiguous despite
there being a unique best viable function
[-Werror,-Wambiguous-reversed-operator].

This converts the comparison operator from a non-symmetric operator
(const VersionBase<VersionType>& (as "this") and const VersionType &).
into a symmetric operator

Relands #135068

Co-authored-by: Ivan Tadeu Ferreira Antunes Filho <antunesi@google.com>
2025-04-10 19:05:26 -07:00
Thurston Dang
6c51603e4c [asan] Temporarily disable new test cases from #133175 on Android
My patch causes a build breakage on Android
(https://lab.llvm.org/buildbot/#/builders/186/builds/8103/steps/21/logs/stdio).
I can't easily test on Android, which is not the intended audience for
my patch anyway, so temporarily disable the test pending further
investigation.
2025-04-10 22:28:01 +00:00
Thurston Dang
324083b5fe [asan] Fix-forward #133175 by avoiding designated initializers
My patch broke the Windows build:

C:\PROGRA~2\MIB055~1\2019\PROFES~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe  /nologo /TP -DASAN_DYNAMIC=1 -DINTERCEPTION_DYNAMIC_CRT -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IC:\b\slave\sanitizer-windows\build\stage1\projects\compiler-rt\lib\asan -IC:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\asan -IC:\b\slave\sanitizer-windows\build\stage1\include -IC:\b\slave\sanitizer-windows\llvm-project\llvm\include -IC:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\asan\.. /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Z7 /Oi /bigobj /permissive- -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /W4 /O2 /Ob2  -std:c++17 -MD /Oy- /GS- /Zc:threadSafeInit- /Z7 /wd4146 /wd4291 /wd4391 /wd4722 /wd4800 /Zl /GR- /experimental:external /external:W0 /external:anglebrackets /showIncludes /Foprojects\compiler-rt\lib\asan\CMakeFiles\RTAsan_dynamic.x86_64.dir\asan_poisoning.cpp.obj /Fdprojects\compiler-rt\lib\asan\CMakeFiles\RTAsan_dynamic.x86_64.dir\ /FS -c C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\asan\asan_poisoning.cpp
C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\asan\asan_poisoning.cpp(164): error C7555: use of designated initializers requires at least '/std:c++20'
[2/3] Building CXX object projects\compiler-rt\lib\asan\CMakeFiles\RTAsan_dynamic_version_script_dummy.x86_64.dir\dummy.cpp.obj

https://lab.llvm.org/buildbot/#/builders/107/builds/9712/steps/4/logs/stdio
2025-04-10 22:19:13 +00:00
mojyack
801b519dfd
[sanitizer_common] Fix build on ppc64+musl (#120036)
In powerpc64-unknown-linux-musl, signal.h does not include asm/ptrace.h,
which causes "member access into incomplete type 'struct pt_regs'"
errors. Include the header explicitly to fix this.

Also in sanitizer_linux_libcdep.cpp, there is a usage of TlsPreTcbSize
which is not defined in such a platform. Guard the branch with macro.
2025-04-10 14:23:26 -07:00
Thurston Dang
721af7e636
[asan] Add experimental 'poison_history_size' flag (#133175)
This adds an experimental flag that will keep track of where the manual memory poisoning (`__asan_poison_memory_region`) is called from, and print the stack trace if the poisoned region is accessed. (Absent this flag, ASan will tell you what code accessed a poisoned region, but not which code set the poison.)

This implementation performs best-effort record keeping using ring buffers, as suggested by Vitaly. The size of each ring buffer is set by the `poison_history_size` flag.
2025-04-10 13:53:54 -07:00
Joseph Huber
2f41fa387d
[AMDGPU] Fix code object version not being set to 'none' (#135036)
Summary:
Previously, we removed the special handling for the code object version
global. I erroneously thought that this meant we cold get rid of this
weird `-Xclang` option. However, this also emits an LLVM IR module flag,
which will then cause linking issues.
2025-04-10 11:31:21 -05:00
Jonas Devlieghere
7f7f3d91a2
Revert "Replace bool operator== for VersionType in sanitizer_mac.h" (#135127)
Reverts llvm/llvm-project#135068 because it breaks building compiler-rt
on Darwin.

https://green.lab.llvm.org/job/clang-stage1-RA/
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/
2025-04-09 21:09:27 -07:00
Ivan Tadeu Ferreira Antunes Filho
433a63e117
Fix ambiguous reversed operator error in sanitizer_mac.h (#135068)
Fixes error: ISO C++20 considers use of overloaded operator '==' (with
operand types 'MacosVersion' and 'MacosVersion') to be ambiguous despite
there being a unique best viable function
[-Werror,-Wambiguous-reversed-operator].

This converts the comparison operator from a non-symmetric operator
(const VersionBase<VersionType>& (as "this") and const VersionType &).
into a symmetric operator
2025-04-09 18:54:37 -04:00
brandb97
deef64904f
Poison unused tail of FakeFrame (#133689)
Fix [issue#133640](https://github.com/llvm/llvm-project/issues/133640)
2025-04-08 18:33:20 -07:00
Peter Collingbourne
36cb81cced
Change python to python3 in some shebangs.
Reviewers: vitalybuka

Reviewed By: vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/134945
2025-04-08 16:15:39 -07:00
Peter Collingbourne
0428252db3
Fix some page size assumptions in the HWASan tests.
Reviewers: fmayer, vitalybuka

Reviewed By: fmayer, vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/134941
2025-04-08 16:13:41 -07:00
k-kashapov
271399831b
[MSan] Change overflow_size_tls type to IntPtrTy (#117689)
As discussed in
https://github.com/llvm/llvm-project/pull/109284#discussion_r1838819987:
Changed `__msan_va_arg_overflow_size_tls` type from `Int64Ty` to
`IntPtrTy`.
2025-04-08 09:51:13 -07:00
Thurston Dang
df0ccf6df0 [asan] Disable TestCases/Linux/asan_rt_confict_test-2.cpp to fix build
TestCases/Linux/asan_rt_confict_test-2.cpp started failing in https://lab.llvm.org/buildbot/#/builders/66/builds/12265/steps/9/logs/stdio
The only change is "[LLD][ELF] Allow merging XO and RX sections, and add --[no-]xosegment flag (#132412)" (2c1bdd4a08). Based on the test case (which deliberately tries to mix static and dynamically linked ASan), I suspect it's actually the test case that needs to be fixed (probably with a different error message check).

This patch disables TestCases/Linux/asan_rt_confict_test-2.cpp to make the buildbots green while I investigate.
2025-04-08 16:16:22 +00:00
Mircea Trofin
b2dea4fd22
[ctxprof] root autodetection mechanism (#133147)
This is an optional mechanism that automatically detects roots. It's a best-effort mechanism, and its main goal is to *avoid* pointing at the message pump function as a root. This is the function that polls message queue(s) in an infinite loop, and is thus a bad root (it never exits).

High-level, when collection is requested - which should happen when a server has already been set up and handing requests - we spend a bit of time sampling all the server's threads. Each sample is a stack which we insert in a `PerThreadCallsiteTrie`. After a while, we run for each `PerThreadCallsiteTrie` the root detection logic. We then traverse all the `FunctionData`, find the ones matching the detected roots, and allocate a `ContextRoot` for them. From here, we special case `FunctionData` objects, in `__llvm_ctx_profile_get_context, that have a `CtxRoot` and route them to `__llvm_ctx_profile_start_context`.

For this to work, on the llvm side, we need to have all functions call `__llvm_ctx_profile_release_context` because they _might_ be roots. This comes at a slight (percentages) penalty during collection - which we can afford since the overall technique is ~5x faster than normal instrumentation. We can later explore conditionally enabling autoroot detection and avoiding this penalty, if desired. 

Note that functions that `musttail call` can't have their return instrumented this way, and a subsequent patch will harden the mechanism against this case.

The mechanism could be used in combination with explicit root specification, too.
2025-04-08 06:59:38 -07:00
Brad Smith
9fdac840ec
[sanitizer_common] Fix building with NetBSD 10.99.12 or newer (#134708)
16543c4905

__lwp_getprivate_fast() was moved to a new arch-specific header file.

Closes: #125566

Co-authored-by: Thomas Klausner <wiz@gatalith.at>
2025-04-07 15:56:58 -04:00
Brad Smith
8f5a3ec649
[sanitizer_common] Use HW_NCPUONLINE sysctl on NetBSD in GetNumberOfCPUs() (#134704) 2025-04-07 15:15:12 -04:00
David CARLIER
6c9e098b39
[compiler-rt][rtsan] symlink/symlinkat interception. (#134168) 2025-04-05 10:30:45 +01:00
David CARLIER
75bbf768a4
[compiler-rt][rtsan] Linux's eventfd interception. (#132836) 2025-04-05 10:10:44 +01:00
Evan Wilde
0d3f5ec0da
[compiler-rt][CMake] Pass all flags to _Float16 try-compile (#133952)
The try-compile mechanism requires that `CMAKE_REQUIRED_FLAGS` is a
space-separated string instead of a list of flags. The original code
expanded `BUILTIN_FLAGS` into `CMAKE_REQUIRED_FLAGS` as a
space-separated string and then would overwrite `CMAKE_REQUIRED_FLAGS`
with `TARGET_${arch}_CFLAGS` prepended to the unexpanded
`BUILTIN_CFLAGS_${arch}`. This resulted in the first two arguments being
passed into the try-compile invocation, but dropping the other arguments
listed in `BUILTIN_CFLAGS_${arch}`.

This patch appends `TARGET_${arch}_CFLAGS` and `BUILTIN_CFLAGS_${arch}` to
`CMAKE_REQUIRED_FLAGS` before expanding CMAKE_REQUIRED_FLAGS as a
space-separated string. This passes any pre-set required flags, in addition to
all of the builtin and target flags to the Float16 detection.
2025-04-04 09:02:24 -07:00
gbMattN
4da5e9dd32 [ASan] Fix shadowed-stack-serialization test on targets with different stack layout 2025-04-04 10:41:00 +01:00
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