19289 Commits

Author SHA1 Message Date
David CARLIER
616d1046c3
[compiler-rt][rtsan] fix ioctl interception for musl. (#131464) 2025-03-16 13:33:56 +00:00
Wael Yehia
f83726e6ad
[profile] Use fprofile-continuous in compiler-rt tests (#126617)
PR #124353 introduced the clang option `-fprofile-continuous` to enable
continuous mode. Use this option in all compiler-rt tests, where applicable.

Changes can be summarized as follows:
1) tests that use `-fprofile-instr-generate` (`%clang_profgen`), which
is an option that takes profile file name, are changed like so:
```
-// RUN: %clang_profgen_cont <SOME-OPTIONS> -o %t.exe %s
-// RUN: env LLVM_PROFILE_FILE="%c%t.profraw" %run %t.exe
+// RUN: %clang_profgen=%t.profraw -fprofile-continuous <SOME-OPTIONS> -o %t.exe %s
+// RUN: %run %t.exe
```
2) tests that use `-fprofile-generate` (`%clang_pgogen`), which is an
option that takes a profile directory, are on case-by-case basis. Where
the default name "default_%m.profraw" works, those tests were changed to
use `%clang_pgogen=<dir>`, and the rest (`set-filename.c` and
`get-filename.c`) continued to use the `LLVM_PROFILE_FILE` environment
variable .
3) `set-file-object.c` uses different filename for different run of the
same executable, so it continued to use the `LLVM_PROFILE_FILE`
environment variable.
4) `pid-substitution.c` add a clang_profgen variation.

---------

Co-authored-by: Wael Yehia <wyehia@ca.ibm.com>
2025-03-15 11:59:30 -04:00
Mircea Trofin
b034905c82
[ctxprof] Capture sampling info for context roots (#131201)
When we collect a contextual profile, we sample the threads entering its root and only collect on one at a time (see `ContextRoot::Taken`). If we want to compare profiles between contextual profiles, and/or flat profiles, we have a problem: we don't know how to compare the counter values relative to each other. To that end, we add `ContextRoot::TotalEntries`, which is incremented every time a root is entered and serves as multiplier for the counter values collected under that root.

We expose this in the profile and leave the normalization to the user of the profile, for a few reasons:

* it's only needed if reasoning about all profiles in aggregate.
* the goal, in compiler_rt, is to flush out the profile as quickly as possible, and performing multiplications adds an overhead that may not even be necessary if the consumer of the profile doesn't care about combining profiles
* the information itself may be interesting as an indication of relative sampling of various contexts.
2025-03-14 21:10:22 -07:00
Paddy McDonald
78f74f686b
[Darwin][ASan][Test] Create a noinlined wrapper function for reliable suppression in test. (#131247)
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.

rdar://144800068
2025-03-14 13:14:33 -07:00
Mariusz Borsa
ab58a3c35b
XFAIL malloc_zone.cpp for darwin/lsan (#131234)
Silence darwin bot while we investigate the problem

rdar://145873843

Co-authored-by: Mariusz Borsa <m_borsa@apple.com>
2025-03-13 16:01:32 -07:00
Mircea Trofin
8aa835c2b5
[ctxprof] Fix warnings post PR #130655 (#131198) 2025-03-13 12:54:48 -07:00
Ellis Hoag
2044dd07da
[InstrProf] Remove -forder-file-instrumentation (#130192) 2025-03-13 08:28:16 -07:00
Thurston Dang
143bf95d41
[hwasan] Don't check code model if there are no globals (#131152)
Currently, the code model check is always performed even if there are no
globals, because:
1) the HWASan compiler pass always leaves a note
2) the HWASan runtime always performs the check if there is a HWASan
globals note.
This unnecessarily adds a 2**32 byte size limit.

This patch elides the check if the globals note doesn't actually contain
globals, thus allowing larger libraries to be successfully instrumented
without globals.

Sent from my iPhone
2025-03-13 11:18:18 -04:00
davidtrevelyan
481a55a3d9
[rtsan][Apple] Add interceptor for _os_nospin_lock_lock (#131034)
Follows the discussion here:
https://github.com/llvm/llvm-project/pull/129309

Recently, the test
`TestRtsan.AccessingALargeAtomicVariableDiesWhenRealtime` has been
failing on newer MacOS versions, because the internal locking mechanism
in `std::atomic<T>::load` (for types `T` that are larger than the
hardware lock-free limit), has changed to a function that wasn't being
intercepted by rtsan.

This PR introduces an interceptor for `_os_nospin_lock_lock`, which is
the new internal locking mechanism.

_Note: we'd probably do well to introduce interceptors for
`_os_nospin_lock_unlock` (and `os_unfair_lock_unlock`) too, which also
appear to have blocking implementations. This can follow in a separate
PR._
2025-03-13 10:18:25 +00:00
Mircea Trofin
07d86d25c9
[ctxprof] Flat profile collection (#130655)
Collect flat profiles. We only do this for function activations that aren't otherwise collectible under a context root are encountered. 

This allows us to reason about the full profile without concerning ourselves wether we are double-counting. For example we can combine (during profile use) flattened contextual profiles with flat profiles.
2025-03-12 07:47:58 -07:00
gbMattN
0ede277b62
Spelling in lit.cfg.py 2025-03-10 11:27:23 +00:00
Mariusz Borsa
62a6d63d63
[Sanitizers][Darwin] Correct iterating of MachO load commands (#130161)
The condition to stop iterating so far was to look for load command cmd
field == 0. The iteration would continue past the commands area, and
would finally find lc->cmd ==0, if lucky. Or crash with bus error, if
out of luck.

Correcting this by limiting the number of iterations to the count
specified in mach_header(_64) ncmds field.

rdar://143903403

---------

Co-authored-by: Mariusz Borsa <m_borsa@apple.com>
2025-03-09 10:58:46 -07:00
Lang Hames
2c8b2dc3f4 [ORC-RT] Rename 'orc_rt_*CWrapper*' types and functions to 'orc_rt_*Wrapper*'.
The orc_rt_ prefix implies C API anyway (the C++ API should use the orc_rc::
namespace), so the 'C' is redundant here.
2025-03-07 14:31:42 +11:00
Lang Hames
a22881c9db [ORC-RT] Fix type name in comment. NFC. 2025-03-06 16:13:10 +11:00
Mircea Trofin
5223ddd83f
[ctxprof] Prepare profile format for flat profiles (#129626)
The profile format has now a separate section called "Contexts" - there will be a corresponding one for flat profiles. The root has a separate tag because, in addition to not having a callsite ID as all the other context nodes have under it, it will have additional fields in subsequent patches.

The rest of this patch amounts to a bit of refactorings in the reader/writer (for better reuse later) and tests fixups.
2025-03-05 07:22:35 -08:00
Mircea Trofin
1b46db7776
[ctxprof] ProfileWriter abstraction (#129590)
Introduce a `ProfileWriter` abstraction to replace the callback passed to `__llvm_ctx_profile_fetch`. Subsequent changes will add support for flat profile collection (as in, collection of non-contextual profile for those functions not under a contextual root), which require also a change in the profile format. The abstraction makes it easy to add "write flat" - related capabilities without constantly complicating the signature of `__llvm_ctx_profile_fetch`.
2025-03-04 12:41:16 -08:00
Alexander Shaposhnikov
a32d5438ac Revert "[compiler-rt][ubsan] Add support for f16 (#129624)"
This reverts commit 23a30e68888e764b2f4d32e51d415b50fa5f5cac.
The commit has broken some build bots.
2025-03-04 09:04:46 +00:00
Alexander Shaposhnikov
23a30e6888
[compiler-rt][ubsan] Add support for f16 (#129624)
LLVM supports long double <-> f16 conversions so we can remove the old FIXME.
2025-03-04 00:38:14 -08:00
Alexander Shaposhnikov
2127af80fa
[compiler-rt][ubsa] Reformat cast-overflow test. NFC (#129662)
Reformat cast-overflow test. NFC
2025-03-03 23:56:21 -08:00
Alexander Shaposhnikov
39402cde61
[compiler-rt][ubsan] Refactor cast-overflow test (#129460)
This PR cleans up cast-overflow.cpp, more specifically:
1. avoid using undefined value as an exit code (old case `9`)
2. narrowing conversions are allowed to produce `inf` and they are
well-defined. Remove dead code (old case `8`)
3. the same applies to the conversion int -> float16. Remove dead code
(old case `7`)

See also
https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#:~:text=%2Dfsanitize%3Dfloat%2Dcast,to%20integer%20types.

Currently ubsan doesn't properly detect UB on float16 -> int casts, I
have a fix for that (will send as a separate PR).
2025-03-03 12:32:58 -08:00
pirama-arumuga-nainar
5cf9435fd4
[compiler-rt][rtsan] Do not intercept [f]truncate64 for musl (#129331)
Musl has 64-bit off_t by default and has macros that redefine
[f]truncate64 to [f]truncate.
2025-02-28 15:08:06 -08:00
PiJoules
fcc571eeb1
[asan] Define mallopt and mallinfo for Fuchsia asan runtime (#129105) 2025-02-28 11:14:39 -08:00
Meng Zhuo
76910f914c
[tsan][RISCV] Add Go support for linux/riscv64 (#127295)
This is needed to support race detector in Golang.

See also: https://github.com/golang/go/issues/64345
2025-02-28 18:27:48 +08:00
GkvJwa
1594fa8e5a
[asan][win] Fix CreateThread leak (#126738)
Fix #126541

Since ```t->Destroy``` cannot be called after ```start_routine```(When
calling standard thread_start in crt)

Intercept `ExitThread` and free the memory created by `VirtualAlloc'
2025-02-28 09:38:08 +08:00
David CARLIER
9a54c77aa3
Reland copy file range san (#129114) 2025-02-27 12:58:51 -08:00
Daniel Thornburgh
e5d93100b6 Revert "[compiler-rt][sanitizer_common] copy_file_range syscall interception. (#125816)" and fix
This reverts commit 7521207e415b19b2924930ac95c2fcf07d56f2f2.
This reverts commit 5f6a3e63a31aaebc620a18c47bc5590f6f705c98.
2025-02-27 12:12:51 -08:00
David CARLIER
7521207e41
[compiler-rt][sanitizer_common] fix copy_file_range test. (#129010)
Passing Large File Support.

Address #125816
2025-02-27 07:12:26 +00:00
David CARLIER
5f6a3e63a3
[compiler-rt][sanitizer_common] copy_file_range syscall interception. (#125816) 2025-02-27 05:33:38 +00:00
David CARLIER
f3b4d94f35
[compiler-rt][rtsan] truncate/ftruncate interception. (#128904) 2025-02-26 22:57:29 +00:00
Chris Apple
58035b5ef5
Revert "[compiler-rt][rtsan] stat api interception." (#128465)
Reverts llvm/llvm-project#128430

Reverting this as I could repro the failure here:

> Hi @devnexen I believe this change is causing failures on a bot. Any
idea what might be causing the problems?
> https://lab.llvm.org/staging/#/builders/202/builds/1324

https://github.com/llvm/llvm-project/pull/128430#issuecomment-2677298624
2025-02-24 14:21:52 +09:00
Vitaly Buka
8b1d38480b
[sanitizer] Support "bB" printf GLIBC extension (#128449)
https://www.gnu.org/software/libc/manual/html_node/Table-of-Output-Conversions.html

Without the patch llc triggers non-fatal Asan warning.
2025-02-23 18:46:52 -08:00
Vitaly Buka
8c917f3ccd
[NFC][sanitizer] Add test for length sub-specifier "z" (#128448) 2025-02-23 18:30:40 -08:00
David CARLIER
4d928d5b58
[compiler-rt][rtsan] stat api interception. (#128430) 2025-02-23 23:37:18 +00:00
David CARLIER
a8fb2d0c1c
[compiler-rt][rtsan] adding unlink/unlinkat interception. (#128292) 2025-02-23 09:17:48 +00:00
Cullen Rhodes
6d5ba79c66
[compiler-rt][asan] Re-enable ManyThreadsTest on AArch64 (#127795)
Disabled in 2ab51bf13a1f6ca96823b755c036227dfd0892f9, doesn't hang for
me on AArch64 (Graviton 3, tested 1000 iterations). May still be an
issue, but hard to know unless we enable it again to find out.

n.b. test was also disabled on PowerPC in
467afc5f847f72221a42d9142c5b4733b44b52dc for same reason and it has also
been observed on x86:
https://lists.llvm.org/pipermail/llvm-dev/2016-January/094607.html

Fixes: https://github.com/llvm/llvm-project/issues/24763
2025-02-21 09:45:58 +00:00
l0rinc
aad74dc971
[compiler-rt] FuzzedDataProvider: modernize outdated trait patterns (#127811) 2025-02-21 10:17:26 +01:00
Lang Hames
6c90f87b74 [ORC-RT] Add -num-threads=0 to testcase.
This testcase depends on stable output, which isn't guaranteed when
concurrent linking is enabled (the default).
2025-02-21 16:55:49 +11:00
Sirraide
b0210fee94
[Clang] [NFC] Fix more -Wreturn-type warnings in tests everywhere (#123470)
With the goal of eventually being able to make `-Wreturn-type` default to an 
error in all language modes, this is a follow-up to #123464 and updates even
more tests, mainly clang-tidy and clangd tests.
2025-02-20 19:49:37 +01:00
Cullen Rhodes
61cfa53896
[compiler-rt][asan] Re-enable forkpty test on AArch64 (NFC) (#127667)
Disabled in 86474c7a1addf59d511050552b697b8b2af61838, no longer failing
on AArch64 (for me at least).

Fixes: https://github.com/llvm/llvm-project/issues/24774
2025-02-18 17:01:23 -08:00
Lang Hames
059f044309 [ORC] Propagate weak & hidden flags when creating lazy reexports, redirectables.
Updates JITLinkRedirectableSymbolManager to take alias flags into account when
setting the scope and linkage of the created stubs (weak aliases get now get weak
linkage, hidden stubs get hidden visibility).

Updates lazyReexports to propagate alias flags (rather than trampoline flags)
when building the initial destinations map for the redirectable symbols manager.

Together these changes allow the LazyObjectLinkingLayer to link objects
containing weak and hidden symbols.
2025-02-18 22:18:34 +11:00
Ethan Luis McDonough
83e180cb70
[Clang][PGO] Fix profile function visibility bug (#127257)
This pull request fixes an issue that was introduced in #93365.
`__llvm_write_custom_profile` visibility was causing issues on Darwin.
This function needs to be publicly accessible in order to be accessed by
libomptarget, so this pull request makes `__llvm_write_custom_profile`
an explicitly exported symbol on Darwin. Tested on M3 and X86 macs.
2025-02-17 13:46:37 -06:00
Victor Campos
43d308dd0d
[compiler-rt] Add support for big endian for Arm's __negdf2vfp (#127096)
In soft floating-point ABI, this function takes the double argument as a
pair of registers r0 and r1.

The ordering of these two registers follow the endianness rules,
therefore the register on which the bit flipping must happen depends on
the endianness.
2025-02-17 11:43:36 +00:00
Jens Reidel
8730fd7c64
[compiler-rt][Mips] Align definition of __sanitizer_sigaction with musl (#124494)
The definition of __sanitizer_sigaction for MIPS matches the one in
glibc [1]. musl however uses a single definition of sigaction for all
architectures [2] that is more similar to the other architectures
supported by glibc. Fix the conditional logic so that
__sanitizer_sigaction matches the musl definition on MIPS.

[1]:
https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/mips/bits/sigaction.h;h=f7e3ad88abbf3c497aaed44247bc1085efebe462;hb=dc650eb715df0a272ce43dfb55a209d5b018cc04
[2]: https://git.musl-libc.org/cgit/musl/tree/include/signal.h#n169

---------

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2025-02-14 10:39:55 -08:00
Florian Mayer
8ed36373a2 [NFC] [sanitizer] allow getauxval in symbolizer 2025-02-12 17:20:28 -08:00
Florian Mayer
6936fadfc3
[compiler-rt] [sanitizer] avoid UB in allocator (#126977) 2025-02-12 15:49:55 -08:00
Ethan Luis McDonough
9e5c136d5a
[PGO][Offload] Profile profraw generation for GPU instrumentation #76587 (#93365)
This pull request is the second part of an ongoing effort to extends PGO
instrumentation to GPU device code and depends on #76587. This PR makes
the following changes:

- Introduces `__llvm_write_custom_profile` to PGO compiler-rt library.
This is an external function that can be used to write profiles with
custom data to target-specific files.
- Adds `__llvm_write_custom_profile` as weak symbol to libomptarget so
that it can write the collected data to a profraw file.
- Adds `PGODump` debug flag and only displays dump when the
aforementioned flag is set
2025-02-11 23:30:54 -06:00
Christopher Ferris
9db0f91ceb
[scudo] Modify header corrupption error message (#126812)
Update the error message to be explicit that this is likely due to
memory corruption.

In addition, check if the chunk header is all zero, which could mean
corruption or an attempt to free a pointer after the memory has been
released to the kernel. This case results in a slightly different error
message to also indicate this could still be a double free.
2025-02-11 17:41:15 -08:00
Victor Campos
dd369c771e
[compiler-rt] Fix tests of __aeabi_(idivmod|uidivmod|uldivmod) to support big endian (#126277)
This patch makes these functions' tests work in big endian mode:
 - `__aeabi_idivmod`.
 - `__aeabi_uidivmod`.
 -  `__aeabi_uldivmod`.

The three functions return a struct containing two fields, quotient and
remainder, via *value in regs* calling convention. They differ in the
integer type of each field.

In the tests of the first two, a 64-bit integer is used as the return
type of the call. And as consequence of the ABI rules for structs
(Composite Types), the quotient resides in `r0` and the remainder in
`r1` regardless of endianness. So, in order to access each component
from the 64-bit integer in the caller code, care must be taken to access
the correct bits as they do depend on endianness in this case.

In the test of the third one, the caller code has inline assembly to
access the components. This assembly code assumed little endian, so it
had to be made flexible for big endian as well.

`_YUGA_BIG_ENDIAN` is defined in `int_endianness.h`. It's a macro
internal to compiler-rt that's in theory compatible with more toolchains
than gcc and clang.
2025-02-11 09:49:56 +00:00
Rainer Orth
a0587414cb
[sanitizer_common][test] Remove second SanitizerCommon.ReportFile tem… (#126509)
…p file

The `SanitizerCommon.ReportFile` test leaves a temp file behind on every
run. While this is not a problem for manual builds, on buildbots those
files accumulate over time, interfering with other bots on the same
system.

The files in question are named like
`sanitizer_common.reportfile.tmp.XXXXXX.<pid>`. The issue can be seen in
Solaris `truss` output:
```
22633:	fstatat64(AT_FDCWD, "/tmp/sanitizer_common.reportfile.tmp.rzVEja", 0xFEFFBAD0, AT_SYMLINK_NOFOLLOW) Err#2 ENOENT
22633:	openat64(AT_FDCWD, "/tmp/sanitizer_common.reportfile.tmp.rzVEja", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
22633:	openat64(AT_FDCWD, "/tmp/sanitizer_common.reportfile.tmp.rzVEja.22633", O_WRONLY|O_CREAT|O_TRUNC, 0660) = 4
22633:	unlinkat(AT_FDCWD, "/tmp/sanitizer_common.reportfile.tmp.rzVEja", 0) = 0
```
The first temp file, created by `temp_file_name`, is removed at the end
of the test, the second one, created in `ReportFile::GetReportPath`
using `OpenFile`, is not.

This patch fixes this, simply removing the file.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.
2025-02-11 09:02:05 +01:00
Piyou Chen
2cd8207b26
[RISCV][compiler-rt] drop __riscv_vendor_feature_bits (#126460)
Address https://github.com/riscv-non-isa/riscv-c-api-doc/pull/101
2025-02-11 15:19:19 +08:00