19009 Commits

Author SHA1 Message Date
Wu Yingcong
6c9256dc5c
[ASAN] fix a nullptr dereference error. (#116011)
`parent_context` is used without checking for nullptr and we can see in
LINE 50 that it could totally be nullptr. This patch addresses this
issue.
2024-11-13 15:46:57 -08:00
Daniel Kiss
2a1586dfb5
[compiler-rt] Add cpu model init for Windows. (#111961) 2024-11-13 11:05:40 +01:00
NAKAMURA Takumi
1c9467f148 compiler-rt/lib: Fix newline at eof 2024-11-12 23:41:25 +09:00
Feng Zou
28e4aad45a
[X86][BF16] Add libcall for FP128 -> BF16 (#115825)
This is to fix #115710.
2024-11-12 15:54:09 +08:00
Florian Mayer
f9125ddc1f
Revert "[libfuzzer] use timer_create() instead of setitimer() for linux" (#115811)
Reverts llvm/llvm-project#110274

Buildbots broke
2024-11-11 19:50:30 -08:00
Min
3b29a8a008
[libfuzzer] use timer_create() instead of setitimer() for linux (#110274)
SetTimer() now uses setitimer() to sending SIGALRM every `
UnitTimeoutSec/2 + 1` s
Set UnitTimeoutSec with the `-timeout=` option

"POSIX.1-2008 marks getitimer() and setitimer() obsolete" and also has
some issues regarding accuracy of the timers under load . See
https://linux.die.net/man/2/setitimer.
I propose using timer_create() and sigaction() ,See
http://man7.org/linux/man-pages/man2/timer_create.2.html

# test result on my x86_64 linux
`make check-fuzzer`

![image](https://github.com/user-attachments/assets/19b4e073-16a5-4daa-95ed-2cf4830c042f)
2024-11-11 19:12:30 -08:00
Vitaly Buka
9254b81990
[tsan] Fix typo in type (#115769)
Introduced with #114931
Fixes https://github.com/golang/go/issues/70283
2024-11-11 13:16:27 -08:00
Alexander Richardson
5082acce4f
[compiler-rt] Add custom libc++ workaround for CMake < 3.26
The INSTALL_BYPRODUCTS ExternalProject_Add() argument was only added in
CMake 3.26 and the current minimum is 3.20. Work around this by using an
explicit ExternalProject_Add_Step() call for the install step with a
BYPRODUCTS argument. We can't keep using the `install` name here since that
is reserved by the CMake implementation and results in errors when used.

This commit should be reverted once LLVM depends on CMake 3.26.

Pull Request: https://github.com/llvm/llvm-project/pull/115677
2024-11-10 20:30:23 -08:00
c8ef
59770a4382
[NFC] Correct imprecise file location in the comment. (#115630) 2024-11-10 15:23:58 +08:00
Alexander Richardson
a29e623e12
[compiler-rt] Make add_custom_libcxx() resilient to DESTDIR being set
If DESTDIR is set in the environment during the build/test stage, the
local libc++ installation will be installed under DESTDIR instead of being
in the build directory.

See https://github.com/llvm/llvm-project/pull/115077#issuecomment-2464640457
and https://gitlab.kitware.com/cmake/cmake/-/issues/18165.

Pull Request: https://github.com/llvm/llvm-project/pull/115525
2024-11-08 11:45:38 -08:00
Alexandros Lamprineas
799e520c51
[FMV] Remove feature dgh. (#115363)
It belongs to the HINT space so it can be executed as NOP if the
hardware doesn't support it.

Reviewed in ACLE -> https://github.com/ARM-software/acle/pull/357
2024-11-08 10:18:41 +00:00
Sebastian Kreutzer
1adca7af21
Reapply "[XRay][AArch64] Support -fxray-shared (#114431)" (#115300)
This patch implements support for `-fxray-shared` on AArch64 and fixes a
remaining issue in the previous PR #114431.

A bug in the XRay `CMakeLists.txt` caused the XRay assembly sources to
be built for every architecture in `XRAY_DSO_SUPPORTED_ARCH` on Apple.
This led to the compiler trying to compile AArch64 assembly for X86
targets and vice versa.
This is addressed here by ensuring that assembly sources are only built
for the matching architecture (see fixup commit).

**Original PR description:**
This patch adds support for `-fxray-shared` on AArch64. This feature,
introduced in #113548 for x86_64, enables the instrumentation of shared
libraries with XRay.

Changes:
- Adds AArch64 to the list of targets supporting `-fxray-shared`
- Introduces PIC versions of the AArch64 XRay trampolines 
- Adjusts relevant XRay tests
2024-11-07 23:21:04 -08:00
Alexandros Lamprineas
e8b7d8bfb5
[FMV][AArch64] Remove features which expose non exploitable runtime behavior. (#114387)
Features ebf16, memtag3, and rpres allow existing instructions to behave
differently depending on the value of certain control registers. FMV
does not read the content of control registers making these features
unsuitable for runtime dispatch. See the ACLE patch for more info:
https://github.com/ARM-software/acle/pull/355
2024-11-07 17:15:23 +00:00
Keith Packard
5a8956ea8b
[compiler-rt][libunwind] Support aarch64 without FPU (#111235)
These two libraries don't build for `-march=armv8-a+nofp
-mabi=aapcs-soft` as a couple of uses of floating point instructions and
registers have crept in.

In libunwind, skip save/restore of FPU registers on targets without them.
In compiler-rt, fall back to the old C implementation of __arm_sc_memset when
the target doesn't have an FPU.

---------

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-11-07 08:32:45 -08:00
Kito Cheng
522880cb99
[compiler-rt][RISCV] Avoid using __init_riscv_feature_bits as a direc… (#115316)
…t constructor

`__init_riscv_feature_bits` takes an argument that can be
platform-specific, potentially pointing to the VDSO address of the
hwprobe system call for Linux. However, marking it as a constructor does
not guarantee that 0/NULL will always be passed to this argument, which
may result in treating an uninitialized or garbage value as a pointer to
hwprobe, leading to a crash.

The simplest solution is to introduce a small constructor function to
ensure that the platform-specific argument is set to 0/NULL.
2024-11-08 00:06:48 +08:00
Martin Storsjö
87f4bc0aca
[compiler-rt] [fuzzer] Skip trying to set the thread name on MinGW (#115167)
Since b4130bee6bfd34d8045f02fc9f951bcb5db9d85c, we check for
_LIBCPP_HAS_THREAD_API_PTHREAD to decide between using
SetThreadDescription or pthread_setname_np for setting the thread name.

c6f3b7bcd0596d30f8dabecdfb9e44f9a07b6e4c changed how libcxx defines
their configuration macros - now they are always defined, but defined to
0 or 1, while they previously were either defined or undefined.

As these libcxx defines used to be defined to an empty string (rather
than expanding to 1) if enabled, we can't easily produce an expression
that works both with older and newer libcxx. Additionally, these defines
are libcxx internal config macros that aren't a detail that isn't
supported and isn't meant to be relied upon.

Simply skip trying to set thread name on MinGW as we can't easily know
which kind of thread native handle we have. Setting the thread name is
only a nice to have, quality of life improvement - things should work
the same even without it.

Additionally, libfuzzer isn't generally usable on MinGW targets yet
(Clang doesn't include it in the getSupportedSanitizers() method for the
MinGW target), so this shouldn't make any difference in practice anyway.
2024-11-07 00:18:57 +02:00
Alexander Richardson
a036d18f1a
[compiler-rt] Reduce build output for tests
Use CMAKE_INSTALL_MESSAGE=LAZY to only print the local libc++(abi)
installation messages for changed files instead of all files.

Pull Request: https://github.com/llvm/llvm-project/pull/115085
2024-11-06 11:58:41 -08:00
Alexander Richardson
e7bad34475
[compiler-rt] Use installed libc++(abi) for tests instead of build tree
Using the build tree is somewhat fragile since the layout is not
guaranteed to be stable and means the tests are tightly coupled to the
libc++/libc++abi build tree layout. Instead update the ExternalProject
to install the library and headers and do not add the build tree to
the include/linker flags.

Pull Request: https://github.com/llvm/llvm-project/pull/115077
2024-11-06 11:57:47 -08:00
Chris Apple
8699f301ae
[rtsan] Add more socket interceptors (#115020)
Adds getaddrinfo, getnameinfo, bind, listen, accept and connect
2024-11-06 07:43:48 -08:00
SahilPatidar
f363f9d61e
[ORC][Runtime] Add dlupdate for elf (#110406)
With the help of @lhames, This pull request introduces the dlupdate
function in the ORC runtime. dlupdate enables incremental execution of
new initializers introduced in the REPL environment. Unlike traditional
dlopen, which manages initializers, code mapping, and library reference
counts, dlupdate focuses exclusively on running new initializers.
2024-11-06 21:26:00 +11:00
Sylvestre Ledru
6d719d9700 Revert "[SystemZ][XRay] XRay runtime support for SystemZ (#113252)"
for causing: https://github.com/llvm/llvm-project/issues/115129

This reverts commit db1882e2484013066139f0b3f77d968d84a79158.
2024-11-06 08:31:58 +01:00
Vitaly Buka
4d374479be
[nfc][tsan] Replace some macros with templates (#114931) 2024-11-05 16:16:35 -08:00
Vitaly Buka
823625cf1d
[nfc][tsan] Simplify morder conversion (#115075)
All valid values should fit into a byte.
This slightly reduce generated code on x86_64.
2024-11-05 13:50:46 -08:00
Kai Nacke
db1882e248
[SystemZ][XRay] XRay runtime support for SystemZ (#113252)
Adds the runtime support routines for XRay on SystemZ. Only function
entry/exit is implemented.
2024-11-05 15:36:59 -05:00
Vitaly Buka
17d956588a
Reapply "[tsan] Don't use enum __tsan_memory_order in tsan interface"" (#115034)
In C++ it's UB to use undeclared values as enum.
And there is support __ATOMIC_HLE_ACQUIRE and
__ATOMIC_HLE_RELEASE need such values.

So use `int` in TSAN interface, and mask out
irrelevant bits and cast to enum ASAP.

`ThreadSanitizer.cpp` already declare morder parameterd
in these functions as `i32`.

This may looks like a slight change, as we
previously didn't mask out additional bits for `fmo`,
and `NoTsanAtomic` call. But from implementation
it's clear that they are expecting exact enum.


Reverts llvm/llvm-project#115032
Reapply llvm/llvm-project#114724
2024-11-05 11:23:52 -08:00
Vitaly Buka
b14c436311
Revert "[tsan] Don't use enum __tsan_memory_order in tsan interface" (#115032)
Reverts llvm/llvm-project#114724

Breaks OSX builds
2024-11-05 09:43:29 -08:00
Nico Weber
a6fdfefbd0
[compiler-rt] Include stdlib.h for exit() (#115025)
It was originally included transitively, but no longer is after recent
<vector> cleanups in libc++.

Similar to #113951.
2024-11-05 12:30:23 -05:00
Vitaly Buka
1e50958399
[tsan] Don't use enum __tsan_memory_order in tsan interface (#114724)
In C++ it's UB to use undeclared values as enum.
And there is support `__ATOMIC_HLE_ACQUIRE` and
`__ATOMIC_HLE_RELEASE` need such values.

Internal implementation was switched to `class enum`,
where that behavior is defined. But interface is C, so
we just switch to `int`.
2024-11-05 09:21:19 -08:00
Felipe de Azevedo Piovezan
cb9700ebe4
Revert "[XRay][AArch64] Support -fxray-shared" (#115022)
Reverts llvm/llvm-project#114431
2024-11-05 08:43:37 -08:00
Chris Apple
15c7e9f903
[rtsan][NFC] Remove some unneeded headers, make guards more obvious (#114911) 2024-11-05 07:03:06 -08:00
Chris Apple
a5e189877a
[rtsan] NFC: Simplify 64 file offset naming in unit tests (#114908) 2024-11-05 07:02:41 -08:00
Hans
cdfd4cff55
[win/asan] Search both higher and lower in AllocateTrampolineRegion (#114212)
There may not always be available virtual memory at higher addresses
than the target function. Therefore, search also lower addresses while
ensuring that we stay within the accessible memory range.

Additionally, add more ReportError calls to make the reasons for
interception failure more clear.
2024-11-05 10:06:39 +01:00
Jérôme Duval
d084bc291a
[compiler-rt][profile] Add support for LLVM profile for Haiku (#107575)
Haiku uses typical UNIX interfaces.

All tests pass except
instrprof-error.c
Posix/gcov-dlopen.c
Posix/gcov-destructor.c
Posix/instrprof-dlopen-norpath.test

---------

Co-authored-by: Petr Hosek <phosek@google.com>
2024-11-05 03:14:25 -05:00
Sebastian Kreutzer
7767aa45ab
[XRay][AArch64] Support -fxray-shared (#114431)
This patch adds support for `-fxray-shared` on AArch64. This feature,
introduced in #113548 for x86_64, enables the instrumentation of shared
libraries with XRay.

Changes:
- Adds AArch64 to the list of targets supporting `-fxray-shared`
- Introduces PIC versions of the AArch64 XRay trampolines 
- Adjusts relevant XRay tests
2024-11-04 23:05:05 -08:00
Vitaly Buka
a9f829a3d7
[nfc][tsan] Move out morder params from __VA_ARGS__ (#114916)
In #114724 I'd like to cast from int to enum, but
existing code `mo = convert_morder(mo)` does not
allow that.
2024-11-04 21:04:57 -08:00
Vitaly Buka
fade3be83d
[nfc][tsan] Wrap Atomic/NoTsanAtomic int struct (#114909)
Prepare to replace macro with template.

Related to #114724, but it's not strictly needed.
2024-11-04 18:47:25 -08:00
Chris Apple
61e50b9f03
[rtsan] Added mmap and shm interceptors (#114862)
# Why do we think these are unsafe?

mmap and munmap are used for mapping a specific manipulation of the
virtual memory of a process. Typically used in things like databases and
area allocators.

They call the system calls `mmap` and `munmap` under the hood (confirmed
on mac using dtrace)

shm_open/unlink interact with shared memory across processes. 

Similarly under the hood, they call the `shm_open`/`shm_unlink` system
calls (confirmed on mac using dtrace)
2024-11-04 16:53:54 -08:00
Louis Dionne
6127724786
[cmake] Remove obsolete files, docs and CMake variables related to the standalone build (#112741)
The runtimes used to support a build mode called the "Standalone build",
which isn't supported anymore (and hasn't been for a few years).
However, various places in the code still contained stuff whose only
purpose was to support that build mode, and some outdated documentation.
This patch cleans that up (although I probably missed some).

- Remove HandleOutOfTreeLLVM.cmake which isn't referenced anymore
- Remove the LLVM_PATH CMake variable which isn't used anymore
- Update some outdated documentation referencing standalone builds
2024-11-04 17:53:38 -05:00
Vitaly Buka
3e15454eed
[tsan] Clang format a few files (#114725) 2024-11-04 12:22:00 -08:00
Rainer Orth
cec147ae5c
[ASan][test] Enable ASan tests on SPARC (#107405)
With PR #107223 and PR #107403, ASan testing can be enabled on SPARC.
This patch does so, 32-bit only on both Solaris and Linux. There is no
64-bit support even in GCC.

Apart from the obvious CMake changes, this patch includes a couple of
testcase adjustments necessary for SPARC:
- In `asan_oob_test.cpp`, the `OOB_int` subtest needs to be disabled: it
performs unaligned accesses that cannot work on a strict-alignment
target like SPARC.
- `asan_test.cpp` needs to disable subtests that depend on support for
`__builtin_setjmp` and `__builtin_longjmp`.
- `zero_page_pc.cpp` reports `0x5` as the faulting address on access to
`0x4`. I don't really know why, but it's consistent between Solaris and
Linux.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.
2024-11-04 09:33:55 +01:00
Koakuma
23d209f350
[SPARC] Allow overaligned allocas (#107223)
SPARC ABI doesn't use stack realignment, so let LLVM know about it in
`SparcFrameLowering`. This has the side effect of making all overaligned
allocations go through `LowerDYNAMIC_STACKALLOC`, so implement the
missing logic there too for overaligned allocations.
This makes the SPARC backend not crash on overaligned `alloca`s and fix
https://github.com/llvm/llvm-project/issues/89569.
2024-11-03 22:53:03 +07:00
c8ef
b57b3f6425
[NFC] Simple typo correction. (#114548) 2024-11-02 00:40:57 +08:00
Kyle Evans
2606a58bc0
compiler-rt: sanitizer_common: use close_range() instead of looping (#114442)
_SC_OPEN_MAX is quite high on FreeBSD, which makes this close() loop a
quite obvious problem when attempting to do any kind of debugging in a
process that uses StartSubprocess. Switch to using close_range(2)
instead to close them all in a single syscall and dramatically reduce
the runtime and syscall trace noise

Linux has an equivalent syscall, but I do not have the capacity to test
that it works there, so this is limited to SANITIZER_FREEBSD for the
time being.
2024-10-31 19:20:46 -07:00
Thurston Dang
083a5cdbea Revert "[sanitizer_common] AND signals in BlockSignals instead of deleting (#113443)"
This reverts commit 25fd366d6a7d40266ff27c134ed8beb0a90cc33b.

Reason: buildbot breakage (https://lab.llvm.org/buildbot/#/builders/186/builds/3642)
2024-10-31 21:08:22 +00:00
Thurston Dang
25fd366d6a
[sanitizer_common] AND signals in BlockSignals instead of deleting (#113443)
My earlier patch https://github.com/llvm/llvm-project/pull/98200 caused a regression because it unconditionally unblocked synchronous signals, even if the user program had deliberately blocked them. This patch fixes the issue by checking the current signal mask, as suggested by Vitaly. It also adds tests.

Fixes #113385

---------

Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
2024-10-31 11:07:41 -07:00
Chris Apple
4ccd2b0c8f
Reland "[rtsan] Intercept aligned_alloc on all versions of OSX if available on the build machine" (#114153)
This commit reverts commit 7c55426 (relands commit 97fb21ac)

With the additional step of ignoring a warning that we don't care about. (-Wunguarded-availability-new)

> We know that aligned_alloc will never be called on systems that do not have aligned_alloc defined because the client OSX won't provide it. This function is actually guarded on OS's lower than 10.15 because aligned_alloc declaration won't exist on that version. There will be no way to call this function from code.
2024-10-31 07:52:20 -07:00
Chris Apple
dbece8edb4
[rtsan][NFC] Put in comment describing why freeing a nullptr is safe (#113720)
Just documenting this for future devs.

Also moved to `nullptr` and deleted unnecessary braces as per the coding
standard.
2024-10-30 17:39:28 -07:00
Alexandros Lamprineas
5dac2db5a8
[FMV][AArch64] Remove features which can be expressed as a combination of others. (#113580)
Removes sve-bf16, sve-ebf16, and sve-i8mm since they are obsolete. One
could write target_version("sve+bf16") instead of sve-bf16 for instance.

Approved in ACLE as https://github.com/ARM-software/acle/pull/353
2024-10-30 11:53:50 +00:00
Thurston Dang
50dd9225f8 Revert "[asan] Flush stderr in test (#114084)"
This reverts commit e205929399d9ee4782b2d8ef1b659f918bdfe7c2.

Reason: did not solve the QEMU bot issues (https://lab.llvm.org/buildbot/#/builders/139/builds/5552/steps/30/logs/stdio) and it shouldn't have been necessary anyway (https://github.com/llvm/llvm-project/pull/114084#issuecomment-2445513320)
2024-10-29 23:46:54 +00:00
Thurston Dang
70af40ba74 [hwasan] Fix forward '[hwasan] Flush stderr/stdout in tests (#114083)'
3754fc1e9af38951aa00181c0e8110174d3f94fd broke the build because subsequent checks depend on the line numbers

https://lab.llvm.org/buildbot/#/builders/174/builds/7534/steps/6/logs/FAIL__HWAddressSanitizer-x86_64__use-after-free_c
2024-10-29 20:14:14 +00:00