Commit Graph

18924 Commits

Author SHA1 Message Date
Vitaly Buka
9a4661cf31 [nfc][ubsan] Fix case of UNSUPPORTED: 2024-10-18 12:39:24 -07:00
Vitaly Buka
203b972289 [ubsan] Disable test on Darwin
Broken after #111497
2024-10-18 12:38:07 -07:00
Vitaly Buka
53e85d44ad [nfc][ubsan] Reorder RUNs and preconditions in test 2024-10-18 12:35:59 -07:00
Vitaly Buka
d60fdc1ca3 [nfc][lsan] Parametrize ScanForPointers with loader (#112803)
Use `DirectLoader` which is equivalent to existing
behaviour of loading pointers directly from memory.
2024-10-18 11:42:13 -07:00
Mike Hommey
ce4618a9c4 [ASan][windows] Recognize movzx r11d, BYTE PTR [rdx] in interception_win (#111638)
The instruction is present in some library in the 24H2 update for
Windows 11:

==8508==interception_win: unhandled instruction at 0x7ff83e193a40: 44 0f
b6 1a 4c 8b d2 48

This could be generalized, but getting all the ModR/M byte combinations
right is tricky. Many other classes of instructions handled in this file
could use some generalization too.
2024-10-18 12:42:03 +00:00
Vitaly Buka
bbccc521c6 [lsan] Disable test with barriers on Darwin (#112810) 2024-10-17 19:23:08 -07:00
Vitaly Buka
7106de9573 [sanitizer] Add MemCpyAccessible (#112794)
A layer over `TryMemCpy` to copy only available pages.
2024-10-17 17:27:57 -07:00
Vitaly Buka
46df20ab63 [sanitizer] Add TryMemCpy (#112668)
For posix implementation is similar to
`IsAccessibleMemoryRange`, using `pipe`.

We need this because we can't rely on non-atomic
`IsAccessibleMemoryRange` + `memcpy`, as the
protection or mapping may change and we may
crash.
2024-10-17 16:59:49 -07:00
Vitaly Buka
70865844cb [sanitizer] Large range support in IsAccessibleMemoryRange (#112665)
The comment stated that it's slow, but likely it's a deadlock,
as write can be blocked.

Also we can't be sure that `page_size * 10` is appropriate size.

Still most likely this is NFC, as the max `size` we use is 32,
and should fit in any buffer.
2024-10-17 13:07:02 -07:00
Chris Apple
29097dd2f3 [rtsan][NFC] Remove rtsan_ prefix from stats variables (#112762) 2024-10-17 11:58:07 -07:00
Vitaly Buka
ed7868de03 [nfc][sanitizer] Replace mmap with InternalMmapVector in test (#112756) 2024-10-17 11:07:43 -07:00
Chris Apple
8f8d5f005a [rtsan] Add statistics for suppression count (#112718) 2024-10-17 10:02:08 -07:00
Qiongsi Wu
f9d0789064 [PGO] Initialize GCOV Writeout and Reset Functions in the Runtime on AIX (#108570)
This PR registers the writeout and reset functions for `gcov` for all
modules in the PGO runtime, instead of registering them
using global constructors in each module. The change is made for AIX
only, but the same mechanism works on Linux on Power.

When registering such functions using global constructors in each module
without `-ffunction-sections`, the AIX linker cannot garbage collect
unused undefined symbols, because such symbols are grouped in the same
section as the `__sinit` symbol. Keeping such undefined symbols causes
link errors (see test case
https://github.com/llvm/llvm-project/pull/108570/files#diff-500a7e1ba871e1b6b61b523700d5e30987900002add306e1b5e4972cf6d5a4f1R1
for this scenario). This PR implements the initialization in the
runtime, hence avoiding introducing `__sinit` into each module.

The implementation adds a new global variable `__llvm_covinit_functions`
to each module. This new global variable contains the function pointers
to the `Writeout` and `Reset` functions. `__llvm_covinit_functions`'s
section is the named section `__llvm_covinit`. The linker will aggregate
all the `__llvm_covinit` sections from each module
to form one single named section in the final binary. The pair of
functions
```
const __llvm_gcov_init_func_struct *__llvm_profile_begin_covinit();
const __llvm_gcov_init_func_struct *__llvm_profile_end_covinit();
```
are implemented to return the start and end address of this named
section in the final binary, and they are used in function
```
__llvm_profile_gcov_initialize()
```
(which is a constructor function in the runtime) so the runtime knows
the addresses of all the `Writeout` and `Reset` functions from all the
modules.

One noticeable implementation detail relevant to AIX is that to preserve
the `__llvm_covinit` from the linker's garbage collection, a `.ref`
pseudo instruction is inserted into them, referring to the section that
contains the `__llvm_gcov_ctr` variables, which are used in the
instrumented code. The `__llvm_gcov_ctr` variables did not belong to
named sections before, but this PR added them to the
`__llvm_gcov_ctr_section` named section, so we can add a `.ref` pseudo
instruction that refers to them in the `__llvm_covinit` section.
2024-10-17 09:32:10 -04:00
NAKAMURA Takumi
40d9561b2d InstrProfilingMerge.c: Fix potential misalignment in SrcBitmapStart
Currently it is not an issue. It will be a problem if Bitmap is
located after single byte counters.
2024-10-17 20:04:00 +09:00
Hans Wennborg
9d5ceccbd9 Speculatively un-XFAIL TestCases/Misc/Posix/ubsan_options.cpp on Darwin
After https://github.com/llvm/llvm-project/pull/111497 the test started
unexpectedly passing (https://crbug.com/373891811), probably because it
does actually work but wasn't run when it lived in the Misc/Linux/
directory.
2024-10-17 10:00:00 +02:00
Vitaly Buka
3142dff704 [nfc][lsan] Extract significant part of the loop into a function (#112610)
Co-authored-by: thetruestblue <92476612+thetruestblue@users.noreply.github.com>
2024-10-16 22:45:40 -07:00
Wu Yingcong
d54953ef47 [fuzzer] fix clang-cl build fuzzer lit test failure (#112339)
The `check-fuzzer` runs fine with cl build llvm, but the following lit
tests fail with clang-cl build llvm
```
********************
Timed Out Tests (2):
  libFuzzer-x86_64-default-Windows :: fork-ubsan.test
  libFuzzer-x86_64-default-Windows :: fuzzer-oom.test

********************
Failed Tests (22):
  libFuzzer-x86_64-default-Windows :: acquire-crash-state.test
  libFuzzer-x86_64-default-Windows :: cross_over_copy.test
  libFuzzer-x86_64-default-Windows :: cross_over_insert.test
  libFuzzer-x86_64-default-Windows :: exit_on_src_pos.test
  libFuzzer-x86_64-default-Windows :: fuzzer-alignment-assumption.test
  libFuzzer-x86_64-default-Windows :: fuzzer-implicit-integer-sign-change.test
  libFuzzer-x86_64-default-Windows :: fuzzer-implicit-signed-integer-truncation-or-sign-change.test
  libFuzzer-x86_64-default-Windows :: fuzzer-implicit-signed-integer-truncation.test
  libFuzzer-x86_64-default-Windows :: fuzzer-implicit-unsigned-integer-truncation.test
  libFuzzer-x86_64-default-Windows :: fuzzer-printcovpcs.test
  libFuzzer-x86_64-default-Windows :: fuzzer-timeout.test
  libFuzzer-x86_64-default-Windows :: fuzzer-ubsan.test
  libFuzzer-x86_64-default-Windows :: minimize_crash.test
  libFuzzer-x86_64-default-Windows :: minimize_two_crashes.test
  libFuzzer-x86_64-default-Windows :: null-deref-on-empty.test
  libFuzzer-x86_64-default-Windows :: null-deref.test
  libFuzzer-x86_64-default-Windows :: print-func.test
  libFuzzer-x86_64-default-Windows :: stack-overflow-with-asan.test
  libFuzzer-x86_64-default-Windows :: trace-malloc-2.test
  libFuzzer-x86_64-default-Windows :: trace-malloc-unbalanced.test
  libFuzzer-x86_64-default-Windows :: trace-malloc.test
```

The related commits are
53a81d4d26
and
e31efd8f6f.
Following the change in
e31efd8f6f
can fix these failures.

As for the issue mentioned in the comment that alternatename support in
clang not good enough(https://bugs.llvm.org/show_bug.cgi?id=40218). I
find that using `__builtin_function_start(func)` instead of directly
using `func` would make it work as intended.
2024-10-17 10:17:16 +08:00
Vitaly Buka
6ffd3bbcd7 [nfc][lsan] Restructure loop in ProcessThreads (#112609)
The goal is to move `SuspendedThreadsList` related code into
the beginning of the loop, and prepare for extraction the rest
of the loop body into a function.
2024-10-16 18:32:14 -07:00
Vitaly Buka
dd9a34fd7e [nfc][lsan] Move up vectors cleanup (#112608) 2024-10-16 18:30:20 -07:00
Vitaly Buka
4c98a71993 [nfc][sanitizer] Unmap memory in test (#112644) 2024-10-16 18:29:15 -07:00
Vitaly Buka
1834660b4c [nfc][lsan] Replace suspended_threads.GetThreadID(i) with local var (#112607) 2024-10-16 16:40:24 -07:00
Chris Apple
1efa6625ef [rtsan] Introduce function-name-matches suppression (#112108)
Introduces a new type of suppression:

1. function-name-matches - allows users to disable `malloc`, `free`,
`pthread_mutex_lock` or similar. This could be helpful if a user thinks
these are real-time safe on their OS. Also allows disabling of any
function marked [[blocking]].

This is useful as a **more performant "early outs" compared to the
`call-stack-contains` suppression**. `call-stack-contains` is inherently
VERY costly, needing to inspect every frame of every stack for a
matching string. This new suppression has an early out before we unwind
the stack.
2024-10-16 16:38:14 -07:00
SahilPatidar
5f9e6c811b [Orc][Runtime] Refactor dlupdate to remove the mode argument (#110491) 2024-10-17 09:42:01 +11:00
Wael Yehia
92ad0397f4 [AIX][PGO] Enable some profile-rt tests now that -fprofile-instr-generate works on AIX 2024-10-16 15:33:56 +00:00
Lang Hames
7937fe1a17 [ORC][llvm-jitlink] Add support for forced loading of archive members.
This patch adds support for forced loading of archive members, similar to the
behavior of the -all_load and -ObjC options in ld64. To enable this, the
StaticLibraryDefinitionGenerator class constructors are extended with a
VisitMember callback that is called on each member file in the archive at
generator construction time. This callback can be used to unconditionally add
the member file to a JITDylib at that point.

To test this the llvm-jitlink utility is extended with -all_load (all platforms)
and -ObjC (darwin only) options. Since we can't refer to symbols in the test
objects directly (these would always cause the member to be linked in, even
without the new flags) we instead test side-effects of force loading: execution
of constructors and registration of Objective-C metadata.

rdar://134446111
2024-10-16 15:21:51 +11:00
Vitaly Buka
b2b0e6c01e [NFC][lsan] Fix name of local var 2024-10-15 20:44:51 -07:00
Christopher Ferris
ed0fd13783 [scudo] Double frees result in chunk state error (#110345)
Fixes bug where a device that supports tagged pointers doesn't use
the tagged pointer when computing the checksum.

Add tests to verify that double frees result in chunk state error
not corrupted header errors.
2024-10-15 17:14:50 -07:00
Vitaly Buka
01b78b220b [NFC] Fix flakiness in test if run unsharded (#112439)
If we run all test in a single process, there is high
probability that `99` is already claimed.
2024-10-15 14:40:06 -07:00
Vitaly Buka
e12fbdf877 [NFC] Remove unnececary check from test (#112438)
Important part of the test to have correct
`ThreadDescriptorSize` after `InitTlsSize()`.

It's not a problem if another test called
`InitTlsSize()` before.

Fixes #112399.
2024-10-15 14:37:48 -07:00
Tacet
c76045d9bf [compiler-rt][ASan] Add function copying annotations (#91702)
This PR adds a `__sanitizer_copy_contiguous_container_annotations`
function, which copies annotations from one memory area to another. New
area is annotated in the same way as the old region at the beginning
(within limitations of ASan).

Overlapping case: The function supports overlapping containers, however
no assumptions should be made outside of no false positives in new
buffer area. (It doesn't modify old container annotations where it's not
necessary, false negatives may happen in edge granules of the new
container area.) I don't expect this function to be used with
overlapping buffers, but it's designed to work with them and not result
in incorrect ASan errors (false positives).

If buffers have granularity-aligned distance between them (`old_beg %
granularity == new_beg % granularity`), copying algorithm works faster.
If the distance is not granularity-aligned, annotations are copied byte
after byte.

```cpp
void __sanitizer_copy_contiguous_container_annotations(
    const void *old_storage_beg_p, const void *old_storage_end_p,
    const void *new_storage_beg_p, const void *new_storage_end_p) {
```

This function aims to help with short string annotations and similar
container annotations. Right now we change trait types of
`std::basic_string` when compiling with ASan and this function purpose
is reverting that change as soon as possible.


87f3407856/libcxx/include/string (L738-L751)

The goal is to not change `__trivially_relocatable` when compiling with
ASan. If this function is accepted and upstreamed, the next step is
creating a function like `__memcpy_with_asan` moving memory with ASan.
And then using this function instead of `__builtin__memcpy` while moving
trivially relocatable objects.


11a6799740/libcxx/include/__memory/uninitialized_algorithms.h (L644-L646)

---

I'm thinking if there is a good way to address fact that in a container
the new buffer is usually bigger than the previous one. We may add two
more arguments to the functions to address it (the beginning and the end
of the whole buffer.

Another potential change is removing `new_storage_end_p` as it's
redundant, because we require the same size.

Potential future work is creating a function `__asan_unsafe_memmove`,
which will be basically memmove, but with turned off instrumentation
(therefore it will allow copy data from poisoned area).

---------

Co-authored-by: Vitaly Buka <vitalybuka@google.com>
2024-10-15 13:26:39 +02:00
Rainer Orth
11903e8c96 [sanitizer][test] Unify LD_LIBRARY_PATH handling (#111498)
When testing on Linux/sparc64 with a `runtimes` build, the
`UBSan-Standalone-sparc :: TestCases/Misc/Linux/sigaction.cpp` test
`FAIL`s:
```
runtimes/runtimes-bins/compiler-rt/test/ubsan/Standalone-sparc/TestCases/Misc/Linux/Output/sigaction.cpp.tmp: error while loading shared libraries: libclang_rt.ubsan_standalone.so: wrong ELF class: ELFCLASS64
```
It turns out SPARC needs the same `LD_LIBRARY_PATH` handling as x86.

This is what this patch does, at the same time noticing that the current
duplication between `lit.common.cfg.py` and
`asan/Unit/lit.site.cfg.py.in` isn't necessary.

Tested on `sparc64-unknown-linux-gnu` and `x86_64-pc-linux-gnu`.
2024-10-15 10:06:11 +02:00
Rainer Orth
e290152181 [ubsan][test] Enable Misc/Linux tests on all Posix systems (#111497)
When investigating PR #101634, it turned out that
`UBSan-Standalone-sparc :: TestCases/Misc/Linux/diag-stacktrace.cpp`
isn't Linux-specific at all. In fact, none of the
`ubsan/TestCases/Misc/Linux` tests are.

Therefore this patch moves them to `Misc/Posix` instead.

Tested on `sparc64-unknown-linux-gnu`, `sparcv9-sun-solaris2.11`,
`x86_64-pc-linux-gnu`, and `amd64-pc-solaris2.11`.
2024-10-15 09:49:57 +02:00
ChiaHungDuan
cb3e7b39a5 Reapply "[scudo] Apply the min release threshold to the group" (#112252) (#112266)
This reverts commit 037938d637.

Fixed the iterator to avoid infinite loop
2024-10-14 21:30:44 -07:00
David CARLIER
706c9dae50 [compiler-rt] Fix GH-112254 DumpAllRegs for win arm64. (#112305) 2024-10-15 05:12:52 +01:00
Florian Mayer
b373278767 [Sanitizers] Intercept timer_create (#112285) 2024-10-14 20:46:45 -07:00
David CARLIER
b8ee0aac2a [compiler-rt] DumpAllRegisters implementation for windows arm64. (#112254) 2024-10-14 23:13:37 +01:00
Paul Kirth
c4131cb56c [Fuchsia][cmake] Avoid referencing cxx_shared in compiler-rt (#112257)
After https://github.com/llvm/llvm-project/pull/80007 Fuchsia builds are
now always building cxx_shared for arm64 and x64 Linux. Ultimately, this
is because the LIBCXX_ENABLE_SHARED is not used in compiler-rt to select
the correct libc++ target, and because cxx_shared is now always defined,
it is selected as a dependency when building runtimes tests.

---------

Co-authored-by: Petr Hosek <phosek@google.com>
2024-10-14 14:41:19 -07:00
ChiaHungDuan
037938d637 Revert "[scudo] Apply the min release threshold to the group" (#112252)
Reverts llvm/llvm-project#112014

The change didn't update the iterator
2024-10-14 12:53:07 -07:00
Thomas Petazzoni
a1217020da Undef _TIME_BITS along with _FILE_OFFSET_BITS
This change is identical to
26800a2c7e ("[sanitizer] Undef
_TIME_BITS along with _FILE_OFFSET_BITS on Linux"), but for
sanitizer_procmaps_solaris.cpp.

Indeed, even though sanitizer_procmaps_solaris.cpp is Solaris
specific, it also gets built on Linux platforms. It also includes
sanitizer_platform.h, which also ends up including features-time64.h,
causing a build failure on 32-bit Linux platforms on which 64-bit
time_t is enabled by setting _TIME_BITS=64.

To fix this, we do the same change: undefine _TIME_BITS, which anyway
will cause no harm as the rest of this file is inside a
SANITIZER_SOLARIS compile-time conditional.

Fixes:

In file included from /home/thomas/buildroot/buildroot/output/host/i686-buildroot-linux-gnu/sysroot/usr/include/features.h:394,
                 from ../../../../libsanitizer/sanitizer_common/sanitizer_platform.h:25,
                 from ../../../../libsanitizer/sanitizer_common/sanitizer_procmaps_solaris.cpp:14:
/home/thomas/buildroot/buildroot/output/host/i686-buildroot-linux-gnu/sysroot/usr/include/features-time64.h:26:5: error: #error "_TIME_BITS=64 is al
lowed only with _FILE_OFFSET_BITS=64"
   26 | #   error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
      |     ^~~~~

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Closes: https://github.com/llvm/llvm-project/pull/99699
2024-10-14 20:02:26 +01:00
ChiaHungDuan
53c9553562 [scudo] Apply the min release threshold to the group (#112014)
For the block smaller than a page size, one block is unlikely to
introduce more unused pages (at most 2 if it acrosses the page boundary
and both touched pages are unused). So it's better to apply the
threshold to reduce the time of scanning groups that can't release any
new pages.
2024-10-14 10:46:12 -07:00
Yuta Saito
d4efc3e097 [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (#111332)
Currently, WebAssembly/WASI target does not provide direct support for
code coverage.
This patch set fixes several issues to unlock the feature. The main
changes are:

1. Port `compiler-rt/lib/profile` to WebAssembly/WASI.
2. Adjust profile metadata sections for Wasm object file format.
- [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections
instead of data segments.
    - [lld] Align the interval space of custom sections at link time.
- [llvm-cov] Copy misaligned custom section data if the start address is
not aligned.
    - [llvm-cov] Read `__llvm_prf_names` from data segments
3. [clang] Link with profile runtime libraries if requested

See each commit message for more details and rationale.
This is part of the effort to add code coverage support in Wasm target
of Swift toolchain.
2024-10-15 02:41:43 +09:00
Raul Tambre
9cc6d6e9a9 [compiler-rt] Explicitly enable C extensions for profile (#110555)
The profiling code requires GNU extensions as it uses functions such as getpagesize(), fdopen(), etc.

The problem manifests when the compiler is built to not default to the extensions mode, e.g. custom config with -std=c2x. CMake didn't support this scenario very well, but it's been fixed by CMP0128. Set the policy to NEW as we now conform to it.
2024-10-14 15:07:11 +03:00
NAKAMURA Takumi
851817b494 fuzzer/strncmp.test: Increase iteration to 20M.
I saw cases that this finised before finding `BINGO`, possibly
insufficient number of iteration. In my case, 11,067,133 satisfied.

So, increase the number for now. This change may increase the duration
of this in failing (`BINGO` not found) case.
2024-10-14 18:34:36 +09:00
Yangyu Chen
7fc3491c04 [compiler-rt][RISCV] Use u64 data type for marchid and mimpid (#112163)
Base on https://github.com/riscv-non-isa/riscv-c-api-doc/pull/91 , the
marchid and mimpid are MXLEN bits wide, and kernel returned them as u64
data type. So we should use u64 data type for marchid and mimpid in
__riscv_cpu_model struct here.

Signed-off-by: Yangyu Chen <cyy@cyyself.name>
2024-10-14 16:23:01 +08:00
David CARLIER
e866e6b8bb [compiler-rt] Implements DumpAllRegisters for windows intel archs. (#108688) 2024-10-12 21:10:47 +01:00
Chris Apple
4468d58080 [rtsan] Support basic call stack suppressions (#111608)
This adds basic support for suppressions, which is a first class feature
of the other sanitizers.
2024-10-12 11:13:36 -07:00
Vitaly Buka
fa81868fe6 [lsan] Log thread history (#111949)
Only with high verbosity and leak reports, or thread logging requested.
2024-10-11 18:09:37 -07:00
Vitaly Buka
aa44f59abf [NFC][sanitizer] Add Debug utility to print thread history (#111948)
For #111949
2024-10-11 16:58:42 -07:00
Vitaly Buka
e1cff8bf81 [lsan] Add debug option to "deflake" leaks (#112037)
There are hard to debug leaks which look like
false.

In general, repeating leak checking should not
affect set of leaks significantly, especial
`at_exit` leak checking.

But if we see significant discrepancy, it may give
us a clue for investigation.
2024-10-11 16:57:19 -07:00
Vitaly Buka
abe148a09f [NFC][sanitizer][asan] Promote stack_id into ThreadContextBase (#111917)
`parent_id` and `stack_id` represent location
where the thread was created, so it's reasonable
to keep them togeter.

For now, only Asan and MemProf use `stack_id`,
but it will be halpfull to print thread origin from
other sanitizers as well.

For #111948
2024-10-11 14:47:01 -07:00