19249 Commits

Author SHA1 Message Date
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
Jens Reidel
c9f1d2cbf1
[compiler-rt][Mips] Fix mips SP register definition (#124493)
The mainline Linux kernel defines EF_R29, not EF_REG29 [1]. Further, the
asm/reg.h header requires `_MIPS_SIM_*` to be defined, which reside in
asm/sgidefs.h [2].

[1]:
https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/reg.h#L151
[2]:
https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/sgidefs.h#L33-L35

---------

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2025-02-10 19:28:04 -08:00
Charlie Barto
73114e43ee
[compiler-rt][windows] Test fixups for MSVC. (#109887)
- add XFAIL/UNSUPPORTED annotations for tests run wtih real MSVC 
- macroify usages of clang-specific attributes in asan tests

- Add substitution for /Oy-/-fno-omit-frame-pointer
  This makes the dll_intercept_memset test work with mingw

These are most of the changes that are required to get things running
with MSVC, however there are some remaining build-flag tweaks.

Nothing in here should be a functional change.
2025-02-10 10:51:08 -08:00
David CARLIER
427b24a408
[compiler-rt][rtsan] adding readlink(at) interception (#126262) 2025-02-07 21:33:29 +00:00
Christopher Ferris
3d35246c50
[scudo] Make guard pages optional in the secondary (#125960)
Add an optional flag for the secondary allocator called
`EnableGuardPages` to enable/disable the use of guard pages. By default,
this option is enabled.
2025-02-06 17:03:30 -08:00
Kai Nacke
b7279ed5b3
[SystemZ][XRay] Make xray work with gcc (#126154)
It seems that depending on the platform, gcc acceptts or does not accept
`-mvx` without specifying an architecture actually having vector
instructions. The solution which seems to work across different versions
of gcc and clang is to specify the least architecture which has vector
instructions.

In addition, initialization of the unused variable CPU prevents a
compiler warning from gcc.
2025-02-06 19:00:20 -05:00
Zequan Wu
8d925a1c72 [compiler-rt] Fix binary-id-path.c after da053415d214d6a66ff5f8c69eb35b2c9ada9caf 2025-02-06 14:22:34 -08:00
Kai Nacke
d905c7e316
[XRay][SystemZ] Use stckf for non-clang compilers (#125289)
Turns out there are users who use gcc to compile compiler-rt. Using the
clang-specific builtin function `__builtin_readcyclecounter()` does not
work in this case.
Solution is to use inline assembly using the stckf instruction in case
the compiler is not clang.
2025-02-06 16:08:05 -05:00
Sinkevich Artem
da053415d2
[profile] Add %b LLVM_PROFILE_FILE option for binary ID (#123963)
Add support for expanding `%b` in `LLVM_PROFILE_FILE` to the binary ID
(build ID). It can be used with `%m` to avoid its signature collisions.

This is supported on all platforms where writing binary IDs into
profiles is implemented, as the `__llvm_write_binary_ids` function is
used.

Fixes #51560.
2025-02-06 16:05:10 -05:00
funsafe-ptr
6575154b6e
[compiler-rt] Fixed Android 8.1 getauxval(AT_PAGESZ) crashes if called from .preinit_array. (#113427) (#116121)
Signed-off-by: funsafe-ptr <funsafe-ptr@proton.me>
2025-02-06 09:40:22 -08:00
Lang Hames
e00f824e9a [ORC-RT] Use templates to express deeply nested function calls in testcase.
Makes this test smaller and more readable.
2025-02-06 17:31:08 +11:00
Lang Hames
88f55d16c4 [ORC] Fix buggy calculation of second-level-page offset in unwind-info.
SecondLevelPageOffset should be incremented by SecondLevelPageSize bytes, not
one byte.

Failure to calculate the offset correctly leads to corrupted unwind-info (and
consequently broken exceptions / unwinding) when more than one second level
page is needed. Since JITLink's unwind support only produces
UNWIND_SECOND_LEVEL_REGULAR-style pages this would trigger for any file
containing more than 511 functions with unwind info. The included test-case
contains 1022 functions (sufficient for both the current format and any
future implementation that supports UNWIND_SECOND_LEVEL_COMPRESSED pages).

Thanks to @edoardo on discord for spotting this bug!
2025-02-06 11:02:06 +11:00
Lang Hames
aefa30e230 [ORC-RT] Add a comment explaining the purpose of this testcase. NFC. 2025-02-06 11:02:06 +11:00
Zack Johnson
94d51fdadb
[asan][test][MSVC] Disabling test on MSVC x86 because of optimized builds (#125871)
Including #124987, we have failures on Windows on x86 with `/O2` builds,
similar to Darwin. This disables the test for MSVC-x86.
2025-02-05 16:53:54 -05:00
David CARLIER
fa100470ab
[compiler-rt][rtsan] chdir/fchdir interception. (#125895) 2025-02-05 19:43:19 +00:00
Ellis Hoag
f9dbf1a18b
[MemProf] Use correct print_text value (#125793) 2025-02-05 09:02:13 -08:00
Lang Hames
eae6d6d18b Re-reapply "[ORC] Enable JIT support for the compact-unwind..." with fixes.
Re-enables compact-unwind support in JITLink, which was reverted in b04847b427d
due to buildbot failures.

The underlying cause for the failures on the buildbots was the lack of
compact-unwind registration support on older Darwin OSes. Since the
CompactUnwindManager pass now removes eh-frames by default we were left with
unwind-info that could not be registered. On x86-64, where eh-frame info is
produced by default the solution is to fall back to using eh-frames. On arm64
we simply can't support exceptions on older OSes.

This patch updates the EHFrameRegistrationPlugin to remove the compact-unwind
section (__LD,__compact_unwind) when installed, forcing use of eh-frames when
the EHFrameRegistrationPlugin is used. In LLJIT, the EHFrameRegistrationPlugin
continues to be used for all non-Darwin platform, and will be added on Darwin
platforms when the a CompactUnwindRegistrationPlugin instance can't be created
(e.g. due to missing support for compact-unwind info registration).

The lit.cfg.py script is updated to check whether the host OSes default unwind
info supports JIT registration, allowing tests to be disabled for older Darwin
OSes on arm64.
2025-02-05 19:40:30 +11:00
Christopher Ferris
84fbed86ff
[scudo] Refactor the secondary test (#125595)
Remove all redundant code and create a couple of structs to handle
automatic init and destruction. This replaces the test fixtures in
prepartion for passing in multiple configs for some of these tests. This
is necessary because not all of the gtest features are supported here,
and there is no easy way to create a test fixture with a template.
2025-02-04 08:46:26 -08:00
Kai Nacke
64142391fd
[SystemZ][XRay] Reland XRay runtime support for SystemZ (#124611)
Adds the runtime support routines for XRay on SystemZ. Only function
entry/exit is implemented.

The original PR 113252 was reverted due to errors caused by adding DSO
support to XRay.
This PR is the original implementation with the changed function
signatures. I'll add an implementation with DSO support later.
2025-01-31 12:13:26 -05:00
thetruestblue
50a5c4f6b9
[Sanitizers][Apple] Fix logic bugs that break RestrictMemoryToMaxAddress (#124712)
There are two logic bugs breaking RestrictMemoryToMaxAddress.
1. adding left_padding within MapDynamicShadow.
- RoundUpTo((uptr)free_begin + left_padding, alignment) already adjusts
for left padding. Adding this additionally within MapDynamicShadow
causes us to allocate a page larger than necessary.
- This incorrect calculation also means RestrictMemoryToMaxAddress will
never find a big enough gap.


2. There is also an issue with the expectation of hitting
KERN_INVALID_ADDRESS when we are beyond the addressable regions.
- For most embedded scenarios, we exceed vm_max_address without getting
KREN_INVALID_ADDRESS so we setting max_occupied_address to a memory
region the process doesn't have access to, beyond the max address, and
that space is never marked as available so we never find a valid gap in
those regions.
- At some point previous it seems the assumption was once we were beyond
the Max address we could expect KREN_INVALID_ADDRESS, which is no longer
true up through the extended space not given to most processes.
- Because of this, the check` if (new_max_vm < max_occupied_addr)` will
always fail and we will never restrict the address on smaller devices.
- Additionally because of the extra page added by adding left_padding,
and how we only minimally restrict the vm, there's a chance we restrict
the vm only enough for the correctly calculated size of shadow. In these
cases, restricting the vm max address and will always fail due to the
extra page added to space size.

credit to @delcypher for the left_padding diagnosis, remembered his old
radar and PR when investigating this. https://reviews.llvm.org/D85389

Will monitor closely for fall out.

rdar://66603866
2025-01-30 15:55:15 -08:00
Ben Langmuir
b04847b427
Revert "Reapply "[ORC] Enable JIT support for the compact-unwind frame..." with fixes." (#125098)
This reverts commit d6524c8dfa37634257050ca71d16e117b802181c. This
reverts commit b1bd73700a1fb6f450e0f6f9c405a9c8bde2cae7.

This was causing bot failures on Darwin


https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-cmake-RA-incremental/7315/
  Clang.Interpreter.simple-exception.cpp

Clang-Unit.Interpreter/ExceptionTests/_/ClangReplInterpreterExceptionTests/0.1
  LLVM.ExecutionEngine/OrcLazy.minimal-throw-catch.ll

https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/3415/
  ORC-x86_64-darwin.TestCases/Darwin/Generic.exceptions.cpp
  ORC-x86_64-darwin.TestCases/Darwin/x86-64.lljit-ehframe.cpp
2025-01-30 11:27:43 -08:00
Christopher Ferris
c8f4189eeb
[scudo] Clean up secondary tests. (#124999)
Change names to all begin with ScudoSecondary and change tests names
appropriately.

Move the cache option test to the cache test fixture.

Force the allocator test to use the no cached config so that all of
the allocations always fully exercise the allocator function and
don't skip this by using a previously cached element.
2025-01-30 10:15:40 -08:00
Ben Langmuir
4985804c06 [asan][test] Disable suppressions-alloc-dealloc-mismatch.cpp on Darwin
The suppressions mechanism doesn't work reliably in optimized builds,
which turns out to be a known issue (see b87543c704724 / svn r308908).
Disable this test, as it is also testing a feature (alloc/dealloc
mismatch) that is disabled by default on Darwin anyway.

rdar://143830493
2025-01-30 09:21:00 -08:00
Lang Hames
b1bd73700a [ORC] Add missing files from d6524c8dfa3. 2025-01-30 13:48:08 +11:00
Lang Hames
d6524c8dfa Reapply "[ORC] Enable JIT support for the compact-unwind frame..." with fixes.
This reapplies 4f0325873fa (and follow up patches 26fc07d5d88, a001cc0e6cdc,
c9bc242e387, and fd174f0ff3e), which were reverted in 212cdc9a377 to
investigate bot failures (e.g.
https://lab.llvm.org/buildbot/#/builders/108/builds/8502)

The fix to address the bot failures was landed in d0052ebbe2e. This patch also
restricts construction of the UnwindInfoManager object to Apple platforms (as
it won't be used on other platforms).
2025-01-30 13:42:10 +11:00
Vitaly Buka
751ae26b95 [asan][android] XFAIL suppressions-alloc-dealloc-mismatch
Android is missing suppression file on device.

Follow up to #124197.
2025-01-29 18:24:43 -08:00
Brad Smith
59613ac237
Revert "[asan] Enable wait4 test on Android" (#125011)
Reverts llvm/llvm-project#124879
2025-01-29 20:34:24 -05:00
Ben Langmuir
f0d05b099d
[asan][test] Attempt to fix suppressions-alloc-dealloc-mismatch.cpp on Darwin (#124987)
Add %env_asan_opts=alloc_dealloc_mismatch=1 since it is disabled by
default.

rdar://143830493
2025-01-29 16:07:15 -08:00
Brad Smith
349eab1869
[asan] Enable wait4 test on Android (#124879) 2025-01-29 10:29:49 -05:00
Brad Smith
540402c05b
[sanitizer_common] Remove workarounds for older Android (#124881)
Anything supported has CPU_COUNT and sched_getaffinity().
2025-01-29 10:27:19 -05:00
David CARLIER
23763a1200
[compiler-rt][rtsan] mremap for Linux interception. (#124234) 2025-01-29 03:58:44 +00:00
andrewjcg
6b654a09c2
[sanitizer] Support "alloc_dealloc_mismatch" suppressions (#124197)
This adds a stack-based suppression for alloc-dealloc-mismatch
violations, using the function name to match.
2025-01-28 18:04:12 -08:00
Julian Lettner
a34159f85e
[TSan][Apple] Fix interceptor build error (#124351)
In certain cases, the SDK headers declare
`OSSpinLock*` APIs as macros (instead of
functions), so users can be transparently
forwarded to non-deprecated APIs.

When enabled, building of TSan interceptors failed
because these macros interfere with the
interceptor machinery, i.e., they prevent proper
forward declaration of intercepted APIs.

In a previous change [1], we misattributed this to
the deprecation of `OSSpinLock*` APIs.

[1] ae484c21c05668f84b13304c28bc39f753e493de

rdar://143193907
2025-01-27 15:48:29 -08:00
Jens Reidel
b707d52fc5
[compiler-rt][Mips] Properly guard references to _ABIN32 (#124492)
When targeting ABIO32 (mips32), _ABIN32 is undefined and the
preprocessor directives cause compile errors. Guard references to
_ABIN32 with defined(_ABIN32), just like the references to _ABIO32.

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2025-01-27 13:49:44 -08:00
Meng Zhuo
4e81275674
[tsan] Add support for linux/riscv64 in lib/tsan/go/buildgo.sh (#124557) 2025-01-27 10:39:40 -08:00
David CARLIER
e21b80464a
[compiler-rt][rtsan] socketpair interception. (#124107) 2025-01-27 12:52:35 +00:00
David CARLIER
cfdd7d736a
[compiler-rt][rtsan] sched cpu affinity for linux interception. (#124194) 2025-01-27 12:50:10 +00:00
bernhardu
bbf377060a
[win/asan] GetInstructionSize: Support some more 7 or 8 byte instructions. (#124011)
This patch adds several instructions seen when trying to run a
executable built with ASan with llvm-mingw.
(x86 and x86_64, using the git tip in llvm-project).

Also includes instructions collected by
Roman Pišl and Eric Pouech in the Wine bug reports below.

```
Related: https://github.com/llvm/llvm-project/issues/96270

Co-authored-by: Roman Pišl <rpisl@seznam.cz>
                https://bugs.winehq.org/show_bug.cgi?id=50993
                https://bugs.winehq.org/attachment.cgi?id=70233
Co-authored-by: Eric Pouech <eric.pouech@gmail.com>
                https://bugs.winehq.org/show_bug.cgi?id=52386
                https://bugs.winehq.org/attachment.cgi?id=71626
```
2025-01-27 10:50:54 +01:00
bernhardu
351ee30529
[win/asan] GetInstructionSize: Support some more 6 byte instructions. (#124006)
This patch adds several instructions seen when trying to run a
executable built with ASan with llvm-mingw.
(x86 and x86_64, using the git tip in llvm-project).

Also includes instructions collected by
Roman Pišl and Eric Pouech in the Wine bug reports below.

```
Related: https://github.com/llvm/llvm-project/issues/96270

Co-authored-by: Roman Pišl <rpisl@seznam.cz>
                https://bugs.winehq.org/show_bug.cgi?id=50993
                https://bugs.winehq.org/attachment.cgi?id=70233
Co-authored-by: Eric Pouech <eric.pouech@gmail.com>
                https://bugs.winehq.org/show_bug.cgi?id=52386
                https://bugs.winehq.org/attachment.cgi?id=71626
```
2025-01-27 10:49:07 +01:00
Ellis Hoag
12f82fbe07
[compiler-rt] Fix Windows test after profile summary change (#124318)
Fix a Windows compiler-rt test that
https://github.com/llvm/llvm-project/pull/105915 broke.
2025-01-24 10:01:02 -08:00
Alexandros Lamprineas
474f5d2aef
[FMV][AArch64] Remove features predres and ls64. (#124266)
These cannot be detected by reading the ID_AA64ISAR1_EL1 register since
their corresponding bitfields are hidden. Additionally the instructions
that these features enable are unusable from EL0.

ACLE: https://github.com/ARM-software/acle/pull/382
2025-01-24 17:22:27 +00:00