18793 Commits

Author SHA1 Message Date
Nico Weber
99ade15d19 Revert "[compiler-rt] prctl interception update, SECCOMP_MODE_FILTER support. (#107722)"
This reverts commit b75174d05aa033a382d4c088e96e068a774f46da.
Does not build on Android, see comments on
https://github.com/llvm/llvm-project/pull/107722
2024-09-24 11:27:06 -04:00
davidtrevelyan
216e1b90c4
[rtsan] Remove std::variant from rtsan diagnostics (#109786)
Following issue #109529 and PR
#109715, this PR removes the
`std::variant` in rtsan's diagnostics code, in favour of a solution by
`enum` without the C++ runtime.
2024-09-24 07:36:07 -07:00
David CARLIER
b75174d05a
[compiler-rt] prctl interception update, SECCOMP_MODE_FILTER support. (#107722) 2024-09-24 09:44:18 +01:00
Rainer Orth
d814006c0a
[ASan][test] Fix Posix/coverage-fork.cpp on Solaris (#109626)
With ASan testing enabled on SPARC as per PR #107405, the
```
  AddressSanitizer-sparc-sunos-dynamic :: TestCases/Posix/coverage-fork.cpp
```
test occasionally `FAIL`s on Solaris/sparcv9:
```
compiler-rt/test/asan/TestCases/Posix/coverage-fork.cpp:46:15: error: CHECK-DAG: expected string not found in input
// CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
              ^
```
It turns out that the output for parent and child processes is
interleaved like
```
Parent PID: Child PID: 27426
27425
```
Checking with `truss` shows that the `fprintf`s are implemented as 3
separate `write`s:
```
28489:  write(2, " P a r e n t   P I D :  ", 12)        = 12
28489:  write(2, " 2 8 4 8 9", 5)                       = 5
28489:  write(2, "\n", 1)                               = 1
```

To avoid this, this patch switches the test to use `snprintf`/`write` to
guarantee the output is atomic.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.
2024-09-24 09:38:01 +02:00
Rainer Orth
4a264c5599
[sanitizer_common] Fix GetArgsAndEnv on Linux/sparc64 (#109109)
When ASan testing is enabled on SPARC as per PR #107405, the
```
  AddressSanitizer-sparc-linux :: TestCases/Posix/print_cmdline.cpp
```
test `FAIL`s. Either `ASAN_OPTIONS=print_cmdline=true` yielded binary
garbage in the `Command:` output or just an empty string.

It turns out one needs to apply an offset to `__libc_stack_end` to get
at the actual `argc`/`argv`, as described in `glibc`'s
`sysdeps/sparc/sparc{32,64}/dl-machine.h` (`DL_STACK_END`).

This patch does this, fixing the test.

Tested on `sparc64-unknown-linux-gnu`.
2024-09-24 09:36:40 +02:00
Rainer Orth
3907d186d6
[sanitizer_common] Heed __ndbl_ prefix for 32-bit Linux/sparc64 inter… (#109106)
…ceptors

When ASan testing is enabled on SPARC as per PR #107405, a couple of
tests `FAIL` on Linux/sparc64:
```
  AddressSanitizer-sparc-linux :: TestCases/printf-2.c
  AddressSanitizer-sparc-linux :: TestCases/printf-3.c
  AddressSanitizer-sparc-linux :: TestCases/printf-4.c
  AddressSanitizer-sparc-linux :: TestCases/printf-5.c

  SanitizerCommon-asan-sparc-Linux :: Linux/unexpected_format_specifier_test.cpp
```
It turns out the interceptors aren't used since on Linux/sparc64
`double` and `long double` are the same, and a couple of `stdio`
functions are prefixed with `__nldbl_` (no long double) accordingly.

This patch handles this.

Tested on `sparc64-unknown-linux-gnu`.
2024-09-24 09:35:08 +02:00
Rainer Orth
1493c247b6
[ASan][test] Fix TestCases/Posix/stack-overflow.cpp on Solaris/sparcv9 (#109101)
When ASan testing is enabled on SPARC as per PR #107405, the
```
  AddressSanitizer-sparc-sunos :: TestCases/Posix/stack-overflow.cpp
```
test `FAIL`s:
```
compiler-rt/test/asan/TestCases/Posix/stack-overflow.cpp:80:12: error: CHECK: expected string not found in input
 // CHECK: {{stack-overflow on address 0x.* \(pc 0x.* bp 0x.* sp 0x.* T.*\)}}
           ^
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
=================================================================
==11358==ERROR: AddressSanitizer: SEGV on unknown address 0xff3fff90 (pc 0x000db0c0 bp 0xfeed59f8 sp 0xfeed5978 T0)
==11358==The signal is caused by a READ memory access.
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer: nested bug in the same thread, aborting.
```
It turns out that `sanitizer_linux.cpp` (`GetPcSpBp`) tries to
dereference the stack pointer to get at the saved frame pointer, which
cannot work since `sp` has been invalidated by the stack overflow in the
test. The access attempt thus leads to a second `SEGV`.

Solaris `walkcontext(3C)` doesn't have that problem: in the original
OpenSolaris sources (`$SRC/lib/libc/port/gen/walkstack.c`) they used
`/proc/self/as` to avoid the fault, which is quite heavy-handed. Solaris
11.4 uses a non-faulting load instead (`load_no_fault_uint32`, which
just uses the `lduwa` insn).

This patch follows this lead, returning a `NULL` `bp` in the failure
case. Unfortunately, this leads to `SEGV`s in the depth of the unwinder,
so this patch avoids printing a stack trace in this case.

Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu`.
2024-09-24 09:33:17 +02:00
c8ef
86c6403232
[compiler-rt][nsan] Add check-cmp flag (#108707)
Add check-cmp flag.

Closes #108435.
2024-09-23 18:49:36 -07:00
Wael Yehia
606557ddd6 [PGO] use atomics for profile counters in instrprof-dlopen-norpath.test
When two threads dlopen a shared library, one instance of the library
is loaded. Hence, code inside the library needs to be thread safe,
so use atomic updates for profile counters.
2024-09-23 15:09:08 +00:00
Chris Apple
a4232dc676
[rtsan][tsan] Fix va_args handling in open functions (#108291)
Check oflag to see if it contains O_CREAT / O_TMPFILE before unpacking parameters to avoid UB
2024-09-23 06:55:14 -07:00
Rainer Orth
02711a77c0
[ASan][test] XFAIL Linux/preinstalled_signal.cpp on Linux/sparc64 (#109623)
With ASan testing enabled on SPARC as per PR #107405, the
```
  AddressSanitizer-sparc-linux-dynamic :: TestCases/Linux/preinstalled_signal.cpp
```
test `FAIL`s on Linux/sparc64. See Issue #109573 for all the details,
but the core is that `syscall(__NR_rt_sigaction)` cannot be used because
it takes an additional argument that isn't accessible outside of `libc`,
while switching to `sigaction` instead changes the order of
`AsanInitInternal` and `Init`, breaking the test.

Therefore this patch `XFAIL`s the test.

Tested on `sparc64-unknown-linux-gnu` and `x86_64-pc-linux-gnu`.
2024-09-23 10:11:39 +02:00
Vitaly Buka
81c3499531 [NFC][sanitizer] Skip test if O_TMPFILE EINVAL on some FS 2024-09-22 18:46:58 -07:00
Vitaly Buka
1429204352 [NFC][sanitizer] Debug errno in test 2024-09-22 18:39:35 -07:00
Vitaly Buka
a0879f2054 [NFC][sanitizer] Skip O_TMPFILE if FS does not support it 2024-09-22 18:12:59 -07:00
Vitaly Buka
f5ec00b79b [NFC][sanitizer] Remove leftover from previous run 2024-09-22 16:22:25 -07:00
Vitaly Buka
397b96aa87 [NFC][sanitizer] Make test Android friendly 2024-09-22 16:16:24 -07:00
Vitaly Buka
2603c8b23b [NFC][sanitizer] Undo "RUN:" part of 4ab22d7b3cc92d08c6371df367ae21716d1b6942
It was not compartible with mobile tests.
2024-09-22 13:47:58 -07:00
Vitaly Buka
2e729bac35
[NFC][sanitizer] Debug test on bot
Remove unneded _GNU_SOURCE.
Add perror.
2024-09-22 12:57:55 -07:00
Vitaly Buka
76cffc2aa5 [sanitizer] Add O_TMPFILE test
For #108291
2024-09-22 12:35:57 -07:00
Vitaly Buka
4ab22d7b3c [NFC][sanitizer] Extract test from main function
And extract cleanup into RUN: command
2024-09-22 12:35:56 -07:00
Vitaly Buka
e5d174c792 [NFC][sanitizer] Don't use FileCheck in test
`assert` is enough.
2024-09-22 12:35:56 -07:00
Vitaly Buka
3ad3f05ac8 [NFC][tsan] Move variadic-open test
There is nothing Darwin or tsan specific in the test.

For #108291
2024-09-22 12:35:56 -07:00
Hans
9f3d083c49
[win/asan] Ensure errno gets set correctly for strtol (#109258)
This fixes two problems with asan's interception of `strtol` on Windows:

1. In the dynamic runtime, the `strtol` interceptor calls out to ntdll's
`strtol` to perform the string conversion. Unfortunately, that function
doesn't set `errno`. This has been a long-standing problem (#34485), but
it was not an issue when using the static runtime. After the static
runtime was removed recently (#107899), the problem became more urgent.

2. A module linked against the static CRT will have a different instance
of `errno` than the ASan runtime, since that's now always linked against
the dynamic CRT. That means even if the ASan runtime sets `errno`
correctly, the calling module will not see it.

This patch fixes the first problem by making the `strtol` interceptor
call out to `strtoll` instead, and do 32-bit range checks on the result.

I can't think of any reasonable way to fix the second problem, so we
should stop intercepting `strtol` in the static runtime thunk. I checked
the list of functions in the thunk, and `strtol` and `strtoll` are the
only ones that set `errno`. (`strtoll` was already missing, probably by
mistake.)
2024-09-22 19:05:20 +02:00
Vitaly Buka
6dcd0d4b50
[NFC][sanitizer] Update DTLS_on_tls_get_addr failure comment (#109546)
Also return `nullptr` on failure. All callers
do nothing for `nullptr` or `{tls_beg, 0}`,
but with `nullptr` they continue earlier.
2024-09-21 13:05:51 -07:00
Vitaly Buka
b620fde2be
[NFC][sanitizer] Early returns in DTLS_on_tls_get_addr (#109539) 2024-09-21 12:27:07 -07:00
Chris Apple
6032feee33
[rtsan][NFC] Standardize lambda function case, fix autos (#109541) 2024-09-21 12:15:17 -06:00
davidtrevelyan
a04db2c7a6
[rtsan] Decouple assertions from error actions (#109535)
Decouples sanitizer assertion `ExpectNotRealtime` from the action that
should happen if a real-time context is detected.
2024-09-21 12:14:11 -06:00
Chris Apple
1b6019388c
[rtsan][compiler-rt] Introduce __rtsan_notify_blocking_call (#109529)
# Why?

In llvm, we need to add a call to `__rtsan_notify_blocking_call()` when
a function is marked `[[clang::blocking]]`. This will produce a
different error message than a call to an unsafe malloc etc
2024-09-21 10:08:18 -06:00
davidtrevelyan
cf85b33e96
[rtsan] Prune rtsan context and assertions tests (#109503)
Disentangles (and simplifies) integration-like tests for
`__rtsan::ExpectNotRealtime` and `__rtsan::Context` into simpler unit
tests. None of the tests are new, but their assertions have changed to
reflect the more direct testing strategy.
2024-09-20 20:55:36 -06:00
Chris Apple
0a84f12208
[rtsan][NFC] Rename _expect_not_realtime function (#109487) 2024-09-20 18:50:30 -06:00
davidtrevelyan
ce0c41cb0c
[rtsan][NFC] Move assertions and diagnostics into own impl files (#109500)
In preparation for providing more information to rtsan's diagnostics
output (via `__rtsan_expect_not_realtime`), this PR separates out all
logic for i) making rtsan's assertions about real-time context state and
ii) displaying diagnostics to the user - disentangling them both from
the rtsan `Context`.

We'll follow up this PR with a simplification to the unit tests that
reflect this new separation.
2024-09-20 18:48:13 -06:00
Chris Apple
07045b5679
[compiler-rt][rtsan] Create colorized reports (#109419) 2024-09-20 15:29:25 -06:00
Alexandros Lamprineas
d497f465df
[FMV][AArch64] Unify ls64, ls64_v and ls64_accdata. (#108024)
Originally I tried spliting these features in the compiler with
https://github.com/llvm/llvm-project/pull/101712, but we decided to lump
those features in the ACLE specification (see
https://github.com/ARM-software/acle/pull/346). Since there are no
hardware implementations out there which implement ls64 without ls64_v
or ls64_accdata, this shouldn't be a regression for feature detection.
2024-09-20 19:10:54 +01:00
Chris Apple
03635b3215
[rtsan][compiler-rt] Add 64 bit file interceptors, test for _FILE_OFFSET_BITS (#108057)
From #107988 

We were not intercepting the 64 bit versions of these calls, leading to
tests failing when _FILE_OFFSET_BITS = 64.
2024-09-20 07:13:52 -06:00
Rainer Orth
f322f4a55e
[sanitizer_common] Provide dummy ThreadDescriptorSize on Solaris (#109285)
Since 2c69a09bee94acca859a1adf5b04d01dc13f7295, the Solaris build is
broken like
```
Undefined			first referenced
 symbol  			    in file
_ZN11__sanitizer20ThreadDescriptorSizeEv projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.i386.dir/sanitizer_linux_libcdep.cpp.o
```
The `ThreadDescriptorSize` reference is from
`sanitizer_linux_libcdep.cpp` (`GetTls`), l.590. This isn't actually
needed on non-glibc targets AFAICS, so this patch provides a dummy to
restore the build.

Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and
`x86_64-pc-linux-gnu`.
2024-09-20 09:35:28 +02:00
ChiaHungDuan
0347c11226
[scudo] Remove unused field in BatchGroup (#109322)
Also fix the logic while determining the size of BatchClass and update
some legacy comments.
2024-09-19 13:58:47 -07:00
Charlie Barto
0265981b6e
[sanitizers] convert some errant CRLF line endings to LF (#108454)
(nfc) 

https://github.com/llvm/llvm-project/pull/107899 Added some files with
CRLF line endings. Mixed line endings are somewhat gross, so I've
converted them all to unix.
2024-09-19 10:45:45 -07:00
Kazu Hirata
b55d4a39a9 [compiler-rt] Fix a warning
This patch fixes:

  compiler-rt/lib/builtins/truncxfbf2.c:16:7: error: ISO C requires a
  translation unit to contain at least one declaration
  [-Werror,-Wempty-translation-unit]
2024-09-19 08:58:40 -07:00
Charlie Barto
3bd8f4e0a0 [sanitizer][asan][msvc] Teach GetInstructionSize about many instructions that appear in MSVC generated code. (#69490)
MSVC can sometimes generate instructions in function prologues that asan
previously didn't know the size of. This teaches asan those sizes. This isn't
super useful for using ASAN with non-msvc compilers, but it does stand alone.

From https://reviews.llvm.org/D151008
2024-09-19 15:44:08 +02:00
Hans Wennborg
04ccbe6e70 Fix typos in interception_win.cpp 2024-09-19 13:11:10 +02:00
Rainer Orth
0a3b6af768
[ASan][test] Skip Linux/odr_c_test.c on SPARC (#109111)
When ASan testing is enabled on SPARC as per PR #107405, the
```
  AddressSanitizer-sparc-linux :: TestCases/Linux/odr_c_test.c

```
test `FAIL`s on Linux/sparc64:
```
+ projects/compiler-rt/test/asan/SPARCLinuxConfig/TestCases/Linux/Output/odr_c_test.c.tmp
+ count 0
Expected 0 lines, got 13.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==4165420==ERROR: AddressSanitizer: BUS on unknown address (pc 0x7012d5b4 bp 0xffa3b938 sp 0xffa3b8d0 T0)
==4165420==The signal is caused by a READ memory access.
==4165420==Hint: this fault was caused by a dereference of a high value address (see register values below).  Disassemble the provided pc to learn which register was used.
```
The test relies on an unaligned access, which cannot work on a
strict-alignment target like SPARC.

Thus this patch skips the test.

Tested on `sparc64-unknown-linux-gnu`.
2024-09-19 10:04:18 +02:00
Phoebe Wang
c18be32185
Reland "[X86][BF16] Add libcall for F80 -> BF16 (#109116)" (#109143)
This reverts commit ababfee78714313a0cad87591b819f0944b90d09.

Add X86 FP80 check.
2024-09-19 15:39:07 +08:00
Vitaly Buka
4e659c6ca3
[NFC][sanitizer] Use InitializePlatformEarly() in test (#109224)
Fix windows test after #108921.
2024-09-18 17:28:49 -07:00
Vitaly Buka
999313debe
[sanitizer] Switch from lazy ThreadDescriptorSize (#108923)
`ThreadDescriptorSize` uses `dlsym` which may use
malloc in unexpected time.

It's relatively easy to init size from the main init.
2024-09-18 16:45:43 -07:00
Vitaly Buka
d1544da533
[NFC][sanitizer] Move InitTlsSize (#108922)
Move after ThreadDescriptorSizeFallback to be able to use it.
2024-09-18 16:29:18 -07:00
Vitaly Buka
a0bb2e21c1
[NFC][sanitizer] Move InitTlsSize into InitializePlatformEarly (#108921) 2024-09-18 16:19:35 -07:00
Vitaly Buka
38752ffd41
[sanitizer] Adjust size for begin/start mismatch (#109079)
Follow up to 51d913af827567e6a0999609e7e624a422781870.
2024-09-18 16:10:16 -07:00
Phoebe Wang
a10c9f994b
Revert "[X86][BF16] Add libcall for F80 -> BF16" (#109140)
Reverts llvm/llvm-project#109116
2024-09-18 21:35:38 +08:00
Chris Apple
aa43f3abe0
[compiler-rt][rtsan] Use Die instead of exit, define cf.exitcode (#107635) 2024-09-18 07:34:18 -06:00
Phoebe Wang
76eda76f9f
[X86][BF16] Add libcall for F80 -> BF16 (#109116)
This fixes #108936, but the calling convention doesn't match with GCC. I
doubt we have such a lib function for now, so leave the calling
convention as is.
2024-09-18 21:23:10 +08:00