19044 Commits

Author SHA1 Message Date
Freddy Ye
c4248fa3ed
[X86] Support MOVRS and AVX10.2 instructions. (#113274)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-10-25 09:00:19 +08:00
Alexander Richardson
b1be21394e
[runtimes] Allow building against an installed LLVM tree
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 \
  -DLLVM_BINARY_DIR=/tmp/upstream-llvm-readonly \
  -G Ninja -S ~/upstream-llvm-project/runtimes \
  -B ~/upstream-llvm-project/runtimes/cmake-build-debug-llvm-git
```

Reviewed By: ldionne

Pull Request: https://github.com/llvm/llvm-project/pull/86209
2024-10-24 17:35:07 -07:00
Alexander Richardson
4c8779388f
sanitizer_allocator.cpp: Ensure at least sizeof(void*) alignment
Some platforms (e.g. 64-bit CHERI) have stronger alignment requirements
on values returned from allocators. For all other platforms this does
not result in any functional change.

Reviewed By: cjappl, vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/84440
2024-10-24 14:09:05 -07:00
Martin Storsjö
a14a83d9a1
[compiler-rt] [test] Fix using toolchains that rely on Clang default configs (#113491)
The use of CLANG_NO_DEFAULT_CONFIG in the tests was added because some
Linux distributions had a global default config file, that added flags
relating to hardening, which interfere with the sanitizer tests. By
setting CLANG_NO_DEFAULT_CONFIG, the global default config files that
are found are ignored, and the sanitizers get the expected default
compiler behaviour.

(This was https://github.com/llvm/llvm-project/issues/60394, which was
fixed in 8ab762557fb057af1a3015211ee116a975027e78.)

However, some toolchains may rely on default config files for mandatory
parts required for functioning at all - setting things like sysroots,
-rtlib, -unwindlib, -stdlib, -fuse-ld etc. In such a case we can't
forcibly disable any default config, because it will break the otherwise
working toolchain.

Add a test for whether the compiler works while passing
--no-default-config to it. If the option is accepted and the toolchain
still works while that is set, set CLANG_NO_DEFAULT_CONFIG while running
tests.

(This adds a little bit of inconsistency, as we're testing for the
command line option, while using the environment variable. However doing
compile testing with an environment variable isn't quite as easily
doable, and passing an extra command line flag to all compile commands
while testing, is a bit clumsy - therefore this inconsistency.)
2024-10-24 23:45:14 +03:00
Eisuke Kawashima
0af6c304e4
[NFC][compiler-rt] fix(compiler-rt/**.py): fix comparison to None (#94015)
from PEP8
(https://peps.python.org/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or
is not, never the equality operators.
2024-10-24 07:32:10 -07:00
Chris Apple
9ed6f7f99b
[rtsan] Add include guards around posix interceptors, tests (#113188) 2024-10-23 15:40:05 -07:00
Martin Storsjö
2002533802 [compiler-rt] [test] Mark a couple files as requiring LF newlines
Some of the profile test files fail if they have CRLF newlines;
add a .gitattributes file that forces them to be checked out
with LF newlines, regarless of the user Git configuration.
2024-10-23 22:43:50 +03:00
David Spickett
cb46662fde [compiler-rt][profile] Disable oneline-merging-windows.c on Windows on Arm
This test has been failing since https://lab.llvm.org/buildbot/#/builders/161/builds/2899,
but no change in that build caused it.

I think this has always failed but https://github.com/llvm/llvm-zorg/pull/252
only recently enabled in on the bot.
2024-10-23 16:07:25 +00:00
Alexandros Lamprineas
a91ebcdd91
[FMV][AArch64] Unify aes with pmull and sve2-aes with sve2-pmull128. (#111673)
According to the Arm Architecture Reference Manual for A-profile
architecture you can't have one feature without having the other:

ID_AA64ZFR0_EL1.AES, bits [7:4]

> FEAT_SVE_AES implements the functionality identified by the value
0b0001.
> FEAT_SVE_PMULL128 implements the functionality identified by the value
0b0010.
> The permitted values are 0b0000 and 0b0010.

(The following was removed from the latest release of the specification,
but it appears to be a mistake that was not intended to relax the
architecture constraints. The discrepancy has been reported)

ID_AA64ISAR0_EL1.AES, bits [7:4]

> FEAT_AES implements the functionality identified by the value 0b0001.
> FEAT_PMULL implements the functionality identified by the value
0b0010.
> From Armv8, the permitted values are 0b0000 and 0b0010.

Approved in ACLE as https://github.com/ARM-software/acle/pull/352
2024-10-23 16:28:55 +01:00
Marco Vanotti
848bc1c383
Fix GetRandom in sanitizer_fuchsia.cpp (#110155)
The `zx_cprng_draw` system call has no limit on how much you can draw.

Co-authored-by: Marco Vanotti <mvanotti@users.noreply.github.com>
2024-10-22 22:44:35 -07:00
Freddy Ye
9e3d4653af
[X86] Update Model value for Arrow Lake. (#113273)
Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
2024-10-23 09:44:26 +08:00
Yuta Saito
7a90ff752c
[compiler-rt][profile] Use flock shim on Windows even if detection fails (#112695) 2024-10-22 07:09:16 +09:00
Alexandros Lamprineas
b6e9ba017f
[FMV][AArch64] Unify features memtag and memtag2. (#112511)
If we split these features in the compiler (see relevant pull request
https://github.com/llvm/llvm-project/pull/109299), we would only be able
to hand-write a 'memtag2' version using inline assembly since the
compiler cannot generate the instructions that become available with
FEAT_MTE2. However these instructions only work at Exception Level 1, so
they would be unusable since FMV is a user space facility. I am
therefore unifying them.

Approved in ACLE as https://github.com/ARM-software/acle/pull/351
2024-10-21 21:40:57 +01:00
Hans Wennborg
8417f6af54 [win/asan] Fix instruction size for 44 0f b6 1a
movzx  r11d,BYTE PTR [rdx]

is four bytes long.

Follow-up to #111638
2024-10-21 17:55:47 +02:00
Chris Apple
1e07c4800c
[rtsan][NFC] Rename *interceptors.cpp to *interceptors_posix.cpp (#112935)
Done in preparation of exploring rtsan on windows.
2024-10-21 07:48:56 -07:00
Martin Storsjö
c2717a89b8 [compiler-rt] [test] Remove an unintended grep parameter
This parameter seems unintentional here; we're trying to grep
the input on stdin, from the earlier stage in the pipeline.

Since a recent update on Github Actions runners, the previous
form (grepping a file, while piping in data on stdin) would fail
running the test, with the test runner Python script throwing
an exception when evaluating it:

      File "D:\a\llvm-mingw\llvm-mingw\llvm-project\llvm\utils\lit\lit\TestRunner.py", line 935, in _executeShCmd
        out = procs[i].stdout.read()
              ^^^^^^^^^^^^^^^^^^^^^^
      File "C:\hostedtoolcache\windows\Python\3.12.7\x64\Lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: a bytes-like object is required, not 'NoneType'
2024-10-20 22:56:41 +03:00
Nico Weber
5aec88f0e6 [hwasan], [gn]: Fix formatting of hwasan cmake; re-sync gn file for b515d9ea1e43 2024-10-19 09:57:56 -04:00
Vitaly Buka
b5fa4fee46
[lsan] Fix compilation on Android (#113003) 2024-10-18 18:40:29 -07:00
Vitaly Buka
0138adb68f
[nfc][lsan] Rename ScanExtraStack and pass region_type (#113004) 2024-10-18 16:35:59 -07:00
Vitaly Buka
f4c6088346
[lsan] Process non-suspended threads (#112807)
For such threads we have no registers, so no exact
stack range, and no guaranties that stack is mapped
at all.

To avoid crashes on unmapped memory,
 `MemCpyAccessible` copies intersting range into
 temporarily buffer, and we search for pointers there.
2024-10-18 15:23:52 -07:00
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