Commit Graph

14352 Commits

Author SHA1 Message Date
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
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
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
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
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 b04847b427
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 d6524c8dfa. This
reverts commit b1bd73700a.

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
Lang Hames
d6524c8dfa Reapply "[ORC] Enable JIT support for the compact-unwind frame..." with fixes.
This reapplies 4f0325873f (and follow up patches 26fc07d5d8, a001cc0e6c,
c9bc242e38, and fd174f0ff3), which were reverted in 212cdc9a37 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 d0052ebbe2. 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
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] ae484c21c0

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
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
Lang Hames
212cdc9a37 Revert "[ORC] Enable JIT support for the compact-unwind frame info format..."
This reverts 4f0325873f and follow-up patches
(see below) while I investigate some ongoing failures on the buildbots.

---

Revert "[clang-repl] Try to XFAIL testcase on arm32 without affecting arm64
darwin."

This reverts commit fd174f0ff3.

Revert "[clang-repl] The simple-exception test now passes on arm64-darwin."

This reverts commit c9bc242e38.

Revert "[ORC] Destroy defunct MaterializationUnits outside the session lock."

This reverts commit a001cc0e6c.

Revert "[ORC] Add explicit narrowing casts to fix build errors."

This reverts commit 26fc07d5d8.

Revert "[ORC] Enable JIT support for the compact-unwind frame info format on
Darwin."

This reverts commit 4f0325873f.
2025-01-24 17:32:12 +11:00
David CARLIER
f3d2e75ead [compiler-rt][rtsan] inotify api for Linux interception. (#124177) 2025-01-24 05:07:49 +00:00
David CARLIER
02a3004992 [compiler-rt][rtsan] preadv(64)/pwritev(64) interception. (#124115) 2025-01-24 05:07:33 +00:00
Lang Hames
4f0325873f [ORC] Enable JIT support for the compact-unwind frame info format on Darwin.
For Darwin/arm64 (including Apple Silicon Macs) this will enable exception
handling and stack unwinding in JIT'd code.

Darwin supports two unwind-info formats: DWARF eh-frames and compact-unwind. On
Darwin/x86-64 compilers usually produce both by default, and ORC supported
exceptions and unwinding via eh-frames (same as on Linux), discarding the
redundant compact-unwind info. On Darwin/arm64 compilers typically default to
producing compact-unwind only, with DWARF eh-frames as a fallback for functions
that can't be described in compact-unwind. Since ORC did not previously support
the compact-unwind format and eh-frames were not present ORC was unable to
handle exceptions or unwinding by default in Darwin/arm64 JIT'd code.

This patch enables support for the compact-unwind-info format, and contains
three major moving parts:

(1) The JITLink CompactUnwindManager class is responsible for transforming the
    __compact_unwind records produced by the linker into the __unwind_info
    tables that libunwind parses during unwinding. To enable this the
    CompactUnwindManager class provides three JITLink passes: The
    prepareForPrune pass that splits the __compact_unwind section into
    single-record blocks, allowing unused records to be dead-stripped; the
    processAndReserveUnwindInfo pass that reserves space for the final
    __unwind_info section, and the writeUnwindInfo pass that writes the
    __unwind_info section.

(2) The OrcTargetProcess UnwindInfoManager class maintains a table of
    registered JIT'd __unwind_info and __eh_frame sections, and handles
    requests from libunwind for unwind info sections (by registering a callback
    with libunwind's __unw_add_find_dynamic_unwind_sections function).

(3) The Orc UnwindInfoRegistrationPlugin, which scans LinkGraphs for
    __unwind_info and __eh_frame sections to register with the
    UnwindInfoManager.

This commit adds the CompactUnwindManager passes to the default JITLink
pipelines for Darwin/arm64 and Darwin/x86-64, and UnwindInfoManager intances to
the SelfExecutorProcessControl class (when built for apple platforms) and the
llvm-jitlink-executor tool.

The LLJIT class will now create an UnwindInfoRegistrationPlugin when targeting
a process running on Darwin if it detects that an UnwindInfoManager is
available to handle the registrations.

The ORC runtime macho_platform class already supported libunwind callbacks, so
out-of-process execution and unwinding support will work when loading the ORC
runtime.

The llvm-jitlink tool will only support compact-unwind when the orc-runtime is
loaded, as the UnwindInfoRegistrationPlugin requires access to an IR compiler
to load a helper module and llvm-jitlink does not provide an IR compiler.
2025-01-23 22:55:01 +00:00
thetruestblue
0b7cbd23a0 [Darwin][Sanitizers][CrashReporter] Adopt initializer for Crash Reporter Annotations struct (#123978)
An initializer for the Crash Reporter Annotatoins struct was added in
version 5. For the simplicity of not needing to always update the struct
in subsequent versions, this patchs checks for the initializer before
attempting to redefine the struct on its own.

Note -- we have an existing test for this that is disabled by default,
it is inherently flakey due to the nature of crash reporter. But we can
run that when making crash reporter related changes.

rdar://136156203
2025-01-23 12:48:33 -08:00
Brad Smith
e0cd57decb [compiler-rt] Remove support and workarounds for Android 4 and older (#124056) 2025-01-23 13:00:39 -05:00
Paweł Bylica
091741a880 [libfuzzer] Clarify -max_len behavior on bigger files (#123095) 2025-01-23 09:19:21 +01:00
David CARLIER
939f2900d0 [compiler-rt][rtsan] getsockopt/setsockopt interception. (#124004) 2025-01-22 23:23:32 +00:00
David CARLIER
630177ccdd [compiler-rt][rtsan] Fix madvise/posix_madvise for macOs. (#124020)
only bsd and linux intercept these syscalls.
Fix #123601
2025-01-22 23:03:48 +00:00
Victor Campos
ffde2687be [compiler-rt] Make Arm builtins aware of endianness in VMOVs (#123204)
This patch makes Arm builtins aware of endianness in VMOVs.

Before this patch, the functions' definitions assumed little endian,
which made any program compiled for big endian incorrect.
2025-01-22 10:56:48 +00:00
David CARLIER
c745ece254 [compiler-rt][rtsan] page regions api interception update. (#123601)
madvise/mprotect/msync/mincore calls with care for signature difference
for the latter.
2025-01-22 10:40:04 +00:00
David CARLIER
6123a81b47 [compiler-rt][rtsan] Fix process_vm_readv/process_vm_writev signatures. (#123914)
missing pid_t first argument. Fix #123839
2025-01-22 19:05:58 +09:00
bernhardu
56592a8108 [win/asan] GetInstructionSize: Support some more 4 byte instructions. (#123709)
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-22 10:27:05 +01:00
bernhardu
5f40570714 [win/asan] GetInstructionSize: Support some more 5 byte instructions. (#123844)
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-22 10:22:02 +01:00
Yi Kong
2ee36d40f0 [compiler-rt][rtsan] Fix sendmmsg and recvmmsg rtsan interceptor for MUSL (#123907)
MUSL have different signatures for sendmmsg and recvmmsg.

This fixes build breakage from #123484.
2025-01-22 18:18:18 +09:00
David CARLIER
8fad58a648 [compiler-rt][rtsan] process_vm_readv/process_vm_writev interception. (#123839) 2025-01-22 06:23:39 +00:00
David CARLIER
a31e25396e [compiler-rt][rtsan] Fix recvmmsg rtsan interceptor for glibc < 2.21 (#123664)
linux/glibc prior to 2.21 had a different signature for recvmmsg.

Fix llvm#123484
2025-01-21 18:54:48 +00:00