Commit Graph

19064 Commits

Author SHA1 Message Date
Chris Apple
af4ae12780 [rtsan] Add fork/execve interceptors (#117198) 2024-12-04 16:38:37 -08:00
ChiaHungDuan
9c5217c4ed [scudo] Use internal list to manage the LRU cache (#117946) 2024-12-04 11:31:41 -08:00
bernhardu
b8d857efac [win/asan] Populate test for function GetInstructionSize. (#118204)
This puts the content of GetInstructionSize into a test.
There are 5 cases missing, which I have already or would like to propose
a fix later.
2024-12-04 18:47:13 +01:00
Mészáros Gergely
bba2507c19 [compiler-rt][MSVC][CMake] Wrap Linker flags for ICX (#118496)
RFC:
https://discourse.llvm.org/t/rfc-cmake-linker-flags-need-wl-equivalent-for-intel-c-icx-on-windows/82446

My previous pass missed some flags because I used
`-Werror=unknown-argument`, but `/D`, `/I` and `/O` are accepted by
clang (even when only linking), but mean different things than intended
for `link.exe`.
2024-12-04 10:09:29 +01:00
ronryvchin
ff281f7d37 [PGO] Add option to always instrumenting loop entries (#116789)
This patch extends the PGO infrastructure with an option to prefer the
instrumentation of loop entry blocks.
This option is a generalization of
19fb5b467b,
and helps to cover cases where the loop exit is never executed.
An example where this can occur are event handling loops.

Note that change does NOT change the default behavior.
2024-12-04 07:56:46 +01:00
Phoebe Wang
a63931292b [X86] Fix typo of gracemont (#118486) 2024-12-03 20:56:52 +08:00
Cyndy Ishida
877b934831 [CompilerRT] Remove sanitizer support for i386 watchsim (#117013)
This patch removes remaining support for i386 simulators, watch was the
only one left though.

resolves: rdar://102741146
2024-12-02 19:34:25 -08:00
Dimitry Andric
867a1d621d [sanitizer_common] mark __elf_aux_vector as weak on FreeBSD (#118110)
At some point FreeBSD introduced libsys as a wrapper between syscalls
and libc, and then linking sanitized programs started failing with:

```text
  # c++ -fsanitize=address main.cc
  ld: error: undefined symbol: __elf_aux_vector
  >>> referenced by sanitizer_linux_libcdep.cpp:950 (/usr/src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp:950)
  >>>               sanitizer_linux_libcdep.o:(__sanitizer::ReExec()) in archive /usr/lib/clang/17/lib/freebsd/libclang_rt.asan-x86_64.a
  c++: error: linker command failed with exit code 1 (use -v to see invocation)
```

Mark `__elf_aux_vector` as weak in the internal sanitizer declaration,
so the linker will accept it at link time. The dynamic linker will then
take care of the symbol at run time.
2024-12-03 00:31:19 +01:00
Brian Cain
c906907d87 [hexagon][cmake] Disable ctx_profile (#117965)
Since #105495, we will build sanitizer_common when
COMPILER_RT_BUILD_CTX_PROFILE is set. But we have outstanding failures
when building sanitizer_common, so for now we'll disable ctx_profile
too.
2024-12-02 15:47:20 -06:00
Alexander Richardson
7545283194 [compiler-rt] Don't detect a versioned clang test compiler as GCC
I was trying to build compiler-rt with /usr/bin/clang-17 and the testsuite
failed due to the code in lit.common.cfg.py:
```
# GCC-ASan uses dynamic runtime by default (since config.bits is not set).
if config.compiler_id == "GNU":
    gcc_dir = os.path.dirname(config.clang)
    libasan_dir = os.path.join(gcc_dir, "..", "lib" + config.bits)
    push_dynamic_library_lookup_path(config, libasan_dir)
```

Fix this in two ways: First, if the test compiler matches the library
compiler, set COMPILER_RT_TEST_COMPILER_ID to CMAKE_C_COMPILER_ID. Second,
relax the regex detecting clang to allow any kind of suffix.

Reviewed By: compnerd

Pull Request: https://github.com/llvm/llvm-project/pull/117812
2024-12-02 11:49:52 -08:00
Alexander Richardson
d33dc14833 [compiler-rt] Allow running extendhfxf2_test without int128 support
We don't need 128-bit integers here, instead rewrite the fp_test.h helpers
to avoid the need for __int128. Also change the high argument for
compareResultF80() and F80FromRep80() to be uint16_t since values greater
than this do not make any sense. This should allow the compiler to detect
accidentally swapping the arguments.

Reviewed By: biabbas, alexander-shaposhnikov

Pull Request: https://github.com/llvm/llvm-project/pull/117818
2024-12-02 10:52:58 -08:00
Paul Osmialowski
fed07a0545 [compiler-rt][tests] Make this test case pass on AArch64 (#117628)
See also D92832 and GCC bug
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80878
2024-12-02 16:41:53 +00:00
Chris Apple
eae30a240e [rtsan] Add syscall interceptor (#118250)
This is a complex one - `syscall` is used when people want to bypass
libc and make the call directly

However, this call:
* Has a variable amount of arguments (up to 6, typically)
* Has arguments that can be any type, (think of whatever arguments go in
to the libc call, or see more details here
https://syscalls.mebeim.net/?table=x86/64/x64/latest)


I've tried to put in a couple tests to ensure we aren't mucking with the
underlying functionality and they seem to be working.
2024-12-02 06:29:54 -08:00
Phoebe Wang
3348b4688f [X86][compiler-rt] Split CPU names even they have the same subtype (#118237)
Fixes: #118205
2024-12-02 18:51:19 +08:00
David Spickett
fec0eb4c3e [compiler-rt] Move CODE_OWNERS.txt to Maintainers.txt (#118086)
To align with https://llvm.org/docs/DeveloperPolicy.html#maintainers

No format change, I just want each project to have a `Maintainers.*`
file so it is easy to find.
2024-12-02 09:13:28 +00:00
Chris Apple
4a074330c6 [rtsan] Intercept various file system functions (#118183)
Adds interceptors for
* chmod
* fchmod
* mkdir
* rmdir
* umask
2024-12-01 07:40:04 -08:00
Chris Apple
f28e071dc0 [rtsan] NFC: Fix style of some interceptors not using MAYBE (#118145)
There were a few interceptors that weren't using the newer MAYBE style -
fixed them up for uniform style.
2024-11-29 15:50:33 -08:00
bernhardu
a943922c0d [win/asan] GetInstructionSize: Remove duplicate instruction FF 25 .... (#116894)
It appears already some lines above with this comment:
  "Cannot overwrite control-instruction. Return 0 to indicate failure.".

Replacing just the comment in the first appearance.

Found after creating the test in #113085.
2024-11-29 09:17:37 +01:00
Min-Yih Hsu
96dd39c575 [XRay] Add __xray_default_options to specify build-time defined options (#117921)
Similar to `__asan_default_options`, users can specify default options
upon building the instrumented binaries by providing their own
definition of `__xray_default_options` which returns the option strings.

This is useful in cases where setting the `XRAY_OPTIONS` environment
variable might be difficult. Plus, it's a convenient way to populate
XRay options when you always want the instrumentation to be enabled.
2024-11-28 22:48:57 -08:00
Alexander Richardson
a4c8ef0f40 [compiler-rt] Fix detecting _Float16 support for secondary targets (#117813)
It turns out we were not passing -m32 to the check_c_source_compiles()
invocation since CMAKE_REQUIRE_FLAGS needs to be string separated list
and
we were passing a ;-separated CMake list which appears to be parsed by
CMake as 'ignore all arguments beyond the first'.
Fix this by transforming the list to a command line first.

With this change, Clang 17 no longer claims to support _Float16 for
i386.
2024-11-28 19:42:47 +01:00
Josh Stone
bc1e0c53a2 [profile] Make the binary-id-offset.c test more robust (#117647)
Using a `--section-start` address in the test was causing link errors on
some targets. Now it uses a linker script to move the note after `.bss`,
which should still have the kind of memory offset we're looking for.

This is a follow-up to #114907 to fix buildbot errors.
2024-11-27 00:06:30 -05:00
B I Mohammed Abbas
06d24da131 Fix extendhfxf2 test (#117665)
Fix changes in #113897

Co-authored-by: Alex Richardson <alexrichardson@google.com>
2024-11-26 15:27:53 -08:00
Chris Apple
3a8b28f698 [rtsan] Add ioctl interceptor (#117569) 2024-11-26 15:17:04 -08:00
Vitaly Buka
8ffe63fb55 [nfc][asan] Fix typo in comment 2024-11-26 14:30:26 -08:00
Joel E. Denny
81349b84eb [sanitizer] Use /tmp/ not /tmp/dir/ in tests (#117759)
Tests fail if the user doesn't own /tmp/dir/. On hosts with multiple
users running the test suite, who owns /tmp/dir/ can become a race.
2024-11-26 14:22:14 -08:00
bernhardu
36b1811da4 [win/asan] Add a test skeleton for function GetInstructionSize. (#116948)
Was first part of PR #113085.
2024-11-26 11:02:48 +01:00
B I Mohammed Abbas
a5dd646360 Add extendhfxf2 into compiler rt (#113897)
Retry of pr #109090 and #111099.

Co-authored-by: Alexander Richardson <alexrichardson@google.com>
2024-11-25 10:19:27 -08:00
Alexander Richardson
3cb28522ba Reapply "[runtimes] Allow building against an installed LLVM tree"
This relands #86209 which was reverted because ./bin/llvm no longer
accepted test paths in the source tree instead of the build tree. This was
happening because `add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit`
was called before all tsst suites were registered, and therefore it was
missing the source->build dir mappings.

Original commit message:

I am currently trying to test the LLVM runtimes (including compiler-rt)
against an installed LLVM tree rather than a build tree (since that is
no longer available). Currently, the runtimes build of compiler-rt assumes
that LLVM_BINARY_DIR is writable since it uses configure_file() to write
there during the CMake configure stage. Instead, generate this file inside
CMAKE_CURRENT_BINARY_DIR, which will match LLVM_BINARY_DIR when invoked
from llvm/runtimes/CMakeLists.txt.

I also needed to make a minor change to the hwasan tests: hwasan_symbolize
was previously found in the LLVM_BINARY_DIR, but since it is generated as
part of the compiler-rt build it is now inside the CMake build directory
instead. I fixed this by passing the output directory to lit as
config.compiler_rt_bindir and using llvm_config.add_tool_substitutions().

For testing that we no longer write to the LLVM install directory as
part of testing or configuration, I created a read-only bind mount and
configured the runtimes builds as follows:
```
$ sudo mount --bind --read-only ~/llvm-install /tmp/upstream-llvm-readonly
$ cmake -DCMAKE_BUILD_TYPE=Debug \
  -DCMAKE_C_COMPILER=/tmp/upstream-llvm-readonly/bin/clang \
  -DCMAKE_CXX_COMPILER=/tmp/upstream-llvm-readonly/bin/clang++ \
  -DLLVM_INCLUDE_TESTS=TRUE -DLLVM_ENABLE_ASSERTIONS=TRUE \
  -DCOMPILER_RT_INCLUDE_TESTS=TRUE -DCOMPILER_RT_DEBUG=OFF \
  -DLLVM_ENABLE_RUNTIMES=compiler-rt \
  -DCMAKE_DISABLE_FIND_PACKAGE_LLVM=TRUE \
  -DCMAKE_DISABLE_FIND_PACKAGE_Clang=TRUE \
  -G Ninja -S ~/upstream-llvm-project/runtimes \
  -B ~/upstream-llvm-project/runtimes/cmake-build-debug-llvm-git
```

Pull Request: https://github.com/llvm/llvm-project/pull/114307
2024-11-25 10:13:00 -08:00
Hans
55f5d68c2d [win/asan] Recognize mov QWORD PTR [rip + X], reg (#117335)
This comes up when intercepting clang-built `__sanitizer_cov` functions.
2024-11-25 09:50:08 +01:00
gbMattN
4d4a353b8e [TSan] Increase the number of simultaneously locked mutexes that a thread can hold (#116409)
I've run into an issue where TSan can't be used on some code without
turning off deadlock detection because a thread tries to hold too many
mutexes. It would be preferable to be able to use deadlock detection as
that is a major benefit of TSan.

Its mentioned in https://github.com/google/sanitizers/issues/950 that
the 64 mutex limit was an arbitrary number. I've increased it to 128 and
all the tests still pass. Considering the increasing number of cores on
CPUs and how programs can now use more threads to take advantage of it,
I think raising the limit to 128 would be some good future proofing

---------

Co-authored-by: Vitaly Buka <vitalybuka@google.com>
2024-11-24 00:58:39 -08:00
Vitaly Buka
5fa0345d90 [tsan] Unwind for CHECK according to fast_unwind_on_fatal (#117470)
It's needed for #116409, which hangs with slow
unwind.
2024-11-24 00:25:06 -08:00
bernhardu
6c52a18a1d [win/asan] GetInstructionSize: Fix 8A 05 ... to return 6 again. (#116889)
This was already the case before 3bd8f4e,
which probably accidentally inserted
a few new instructions and a return 4 in between.
2024-11-21 23:17:11 +02:00
Thurston Dang
9ba6672b9f [sanitizer_common] Intercept timespec_get except for hwasan (#117080)
Intercept timespec_get for all sanitizers except for hwasan
2024-11-21 12:29:18 -08:00
bernhardu
b89e774672 [win/asan] Avoid warnings in compiling interception_win_test.cpp. (#116887)
Example:
  warning: unused variable 'kPatchableCode12' [-Wunused-const-variable]
2024-11-21 22:11:49 +02:00
Josh Stone
667e1fadcf [profile] Use base+vaddr for __llvm_write_binary_ids note pointers (#114907)
This function is always examining its own ELF headers in memory, but it
was trying to use conditions between examining files or memory, and it
wasn't accounting for LOAD offsets at runtime. This is especially bad if
a loaded segment has additional padding that's not in the file offsets.

Now we do a first scan of the program headers to figure out the runtime
base address based on `PT_PHDR` and/or `PT_DYNAMIC` (else assume zero),
similar to libc's `do_start`. Then each `PT_NOTE` pointer is simply the
base plus the segments's `pt_vaddr`, which includes LOAD offsets.

Fixes #114605
2024-11-21 10:14:29 -08:00
Chris Apple
595e484c08 [rtsan] Add option to allow printing of duplicate stacks (suppress_equal_stacks) (#117069)
Following the example of tsan, where we took the name

This would allow users to determine if they want to see ALL output from
rtsan.

Additionally, remove the UNLIKELY hint, as it is now up to the flag whether or
not it is likely that we go through this conditional.
2024-11-21 06:32:05 -08:00
Chris Apple
963b8e36bb [rtsan] Add sched_yield interceptor (#117084)
This calls the system calls switch_pri and sys_ulock_wait. It also is
one of the more straightforwardly rt-unsafe, in that it gives up this
thread's timeslice.
2024-11-21 06:30:45 -08:00
Lang Hames
7c0786363e [ORC-RT] Test basic C++ static initialization support in the ORC runtime.
This tests that a simple C++ static initializer works as expected.

Compared to the architecture specific, assembly level regression tests for the
ORC runtime; this test is expected to catch cases where the compiler adopts
some new MachO feature that the ORC runtime does not yet support (e.g. a new
initializer section).
2024-11-21 18:20:43 +11:00
Chris Apple
934140a335 [rtsan] Remove mkfifoat interceptor (#116997)
This partially reverts #116915
[fce917d](fce917d39d)

mkfifoat was improperly guarded against in MacOS systems
2024-11-20 08:27:58 -08:00
Chris Apple
fce917d39d [rtsan] Add pipe, mkfifo interceptors (#116915)
## Why we think this are unsafe

Again, these correspond directly to system calls on linux and OSX. They
are two ways to do interprocess communication so it would make sense
that they take some synchronization by the OS.
2024-11-20 07:47:14 -08:00
Daniel Kiss
77bf34c315 [AArch64][compiler-rt] Add LSE support for Windows. (#116706) 2024-11-20 11:05:31 +01:00
Fangrui Song
ac38ab594f [lsan] Use VReport if not REGISTERS_AVAILABLE (#116555)
Certain tests (many are from lld/test) run `... '2>&1 | count 0` to
ensure that there is no stderr message.

GetRegistersAndSP may rarely fail, leading to
a spurious failure like (with a local hack to make `count` dump the
input):

```
+ /home/ray/llvm/out/asan/bin/ld.lld func1-gcs.o func2-gcs.o func3-gcs.o -o /dev/null -z gcs-report=warning -z gcs=never
+ /home/ray/llvm/out/asan/bin/count 0
Expected 0 lines, got 1.
==2403039==Unable to get registers from thread 2403018.
```

The failure can reliably be reproduced by running `ninja check-lld` a
few times under asan+lsan (see the bot
sanitizer-x86_64-linux-bootstrap-asan).
2024-11-20 01:07:28 -08:00
Chris Apple
3c8818cf2d [rtsan] Add more file descriptor interceptors - dup*, lseek (#116853)
# Why we think these are real-time unsafe

They correspond directly to system calls in linux and OSX, they are
manipulating a shared resource, which likely takes some operating-system
synchronization.
2024-11-19 14:54:14 -08:00
Chris Apple
7c41b5ccdc [rtsan] Add support for ReportErrorSummary (#116424)
Adding support for the extra SUMMARY line that is output by most
compilers. This also adds the ability for end-users to specify their own
handlers for reporting these errors (see the test).
2024-11-19 14:53:47 -08:00
Florian Mayer
0488d1774b Reland "[Sanitizers] Intercept timer_create" (#113710) (#116717)
Original commit 2ec5c69b68 only
intercepted timer_create.

Because of how versioned libc symbols work, this could cause problems
where a newer `timer_create`
was used, and the result would be used by an older version. This would
cause crashes. This is why we
need to intercept all of the related functions.

Addresses https://github.com/llvm/llvm-project/issues/111847
2024-11-18 23:18:54 -08:00
Wael Yehia
a17f11baa1 [test][PGO] Add a multi-threaded test for continuous PGO. 2024-11-19 04:57:33 +00:00
Chris Apple
9c3665c8d2 [rtsan] Add I/O multiplexing interceptors (#115227)
Intercepts in the family of `poll`, `select` and modern equivalents
`epoll` (linux only) and `kqueue` bsd family only.

These calls mirror the names of the system calls they call, which have
been verified on mac at least (e.g. kevent calls the system call
kevent).
2024-11-18 15:29:49 -08:00
Wael Yehia
7b525495e8 [test][PGO] Use -fprofile-update=atomic instead of mllvm option in ContinuousSyncMode/online-merging.c 2024-11-18 20:04:20 +00:00
Freddy Ye
97836bed63 Reland "[X86] Support -march=diamondrapids (#113881)" (#116564)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-11-18 10:40:32 +08:00
Freddy Ye
90e92239bd Revert "[X86] Support -march=diamondrapids (#113881)" (#116563)
This reverts commit 826b845c9e.
2024-11-18 08:45:28 +08:00