Commit Graph

18960 Commits

Author SHA1 Message Date
Thurston Dang
70af40ba74 [hwasan] Fix forward '[hwasan] Flush stderr/stdout in tests (#114083)'
3754fc1e9a 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
Thurston Dang
e205929399 [asan] Flush stderr in test (#114084)
This is the ASan equivalent of
https://github.com/llvm/llvm-project/pull/114083.

The x86_64_lam_qemu buildbots started failing

(https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio).
Based on the logs, it appears the ASan check is correct but it did not
match the stderr/stdout output. This patch attempts to fix the issue by
flushing stderr as appropriate.
2024-10-29 12:40:54 -07:00
Thurston Dang
3754fc1e9a [hwasan] Flush stderr/stdout in tests (#114083)
The x86_64_lam_qemu buildbots started failing
(https://lab.llvm.org/buildbot/#/builders/139/builds/5462/steps/2/logs/stdio).
Based on the logs, it appears the HWASan check is correct but it did not
match the stderr/stdout output. This patch attempts to fix the issue by
flushing stderr/stdout as appropriate.
2024-10-29 12:38:56 -07:00
Sebastian Kreutzer
a388df7127 [XRay] Remove reliance on default PIC behavior in DSO tests (#113892)
Compiling with `-fxray-shared` requires position-independent code
(introduced in #113548).
Some tests do not explicitly specify this, thus falling back to the
compiler default.
If, for example, Clang is compiled with
`-DCLANG_DEFAULT_PIE_ON_LINUX=OFF`, these checks fail.

This patch addresses this issue in two tests:
- Removing a check in `xray-shared.cpp` that only tests default PIC
behavior
- Adding `-fPIC` explicitly in `clang-xray-shared.cpp`
2024-10-29 09:40:53 -05:00
Eisuke Kawashima
61353cc1f6 [compiler-rt] Fix invalid escape sequences in python files (#94030)
\d, \( and \) are not valid escape sequences; since python 3.12
they give SyntaxWarning, and will raise SyntaxError in future.
https://docs.python.org/3.12/whatsnew/3.12.html#other-language-changes

r"\(\d\)" and "\\(\\d\\)" are equivalent but the former is the shorter.

Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2024-10-28 17:32:36 -07:00
Chris Apple
7c554265ce Revert "[rtsan] Intercept aligned_alloc on all versions of OSX if available on build machine (#112780)" (#113982)
This reverts commit 97fb21ac1d.

Due to issue brought up in #112780

> Unfortunately this breaks the build on our (automerger) bots, which
have -mmacosx-version-min=10.13 and also
-Werror=unguarded-availability-new . I was thinking about patching it
via wrapping in __builtin_available check (which I believe is the right
one to use, as it should match the -mmacosx-version-min ) - but can't
actually think of a quick fix, due to interceptors being defined via C
macros.

>
llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp:475:21:
error: 'aligned_alloc' is only available on macOS 10.15 or newer
[-Werror,-Wunguarded-availability-new] 475 | INTERCEPTOR(void *,
aligned_alloc, SIZE_T alignment, SIZE_T size) {
2024-10-28 16:55:27 -07:00
Prabhuk
9f69da35e2 [NFC][compiler-rt] Add missing header include (#113951)
Include `cstdlib` which was originally included transitively but the
changes to `vector` in libcpp breaks new builds due to missing cstdlib
header for `abort()` function call.
2024-10-28 15:24:47 -07:00
Chris Apple
97fb21ac1d [rtsan] Intercept aligned_alloc on all versions of OSX if available on build machine (#112780) 2024-10-28 10:33:29 -07:00
Nikolas Klauser
3ac75ee8ec Revert "[runtimes] Allow building against an installed LLVM tree" (#113920)
Reverts llvm/llvm-project#86209

This patch breaks running tests locally, which is extremely disruptive
to libc++ development.
2024-10-28 16:25:58 +01:00
Vassil Vassilev
f6b513a785 Revert "Add explicit symbol visibility macros to InstrProfData.inc (#110732)"
This reverts commit d7ca703eab in llvm/llvm-project#110732
2024-10-28 08:57:57 +00:00
Thomas Fransham
d7ca703eab Add explicit symbol visibility macros to InstrProfData.inc (#110732)
Add explicit symbol visibility macros to InstrProfData.inc

Annotating these symbols will fix missing symbols for InstrProfTest when
using shared library builds on windows with explicit visibility macros
enabled.
Add a empty fallback definition for LLVM_ABI macro so the code works in
compiler-rt.

This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on
window.

```
llvm\lld-link : error : undefined symbol: public: void ValueProfData::deserializeTo(InstrProfRecord&,  InstrProfSymtab*)
>>> referenced by unittests\ProfileData\InstrProfTest.cpp:1372 void ValueProfileReadWriteTest_value_prof_data_read_write_Test::TestBody()
```
2024-10-28 10:47:40 +02:00
davidtrevelyan
4102625380 [rtsan][llvm][NFC] Rename sanitize_realtime_unsafe attr to sanitize_realtime_blocking (#113155)
# What

This PR renames the newly-introduced llvm attribute
`sanitize_realtime_unsafe` to `sanitize_realtime_blocking`. Likewise,
sibling variables such as `SanitizeRealtimeUnsafe` are renamed to
`SanitizeRealtimeBlocking` respectively. There are no other functional
changes.


# Why?

- There are a number of problems that can cause a function to be
real-time "unsafe",
- we wish to communicate what problems rtsan detects and *why* they're
unsafe, and
- a generic "unsafe" attribute is, in our opinion, too broad a net -
which may lead to future implementations that need extra contextual
information passed through them in order to communicate meaningful
reasons to users.
- We want to avoid this situation and make the runtime library boundary
API/ABI as simple as possible, and
- we believe that restricting the scope of attributes to names like
`sanitize_realtime_blocking` is an effective means of doing so.

We also feel that the symmetry between `[[clang::blocking]]` and
`sanitize_realtime_blocking` is easier to follow as a developer.

# Concerns

- I'm aware that the LLVM attribute `sanitize_realtime_unsafe` has been
part of the tree for a few weeks now (introduced here:
https://github.com/llvm/llvm-project/pull/106754). Given that it hasn't
been released in version 20 yet, am I correct in considering this to not
be a breaking change?
2024-10-26 13:06:11 +01:00
Martin Storsjö
ef9629c64a Revert "Add extendhfxf2 into compiler rt (#111099)"
This reverts commit 5f7bad07b9.

These tests fail to build in multiple configurations, see
https://github.com/llvm/llvm-project/pull/111099.
2024-10-26 12:34:45 +03:00
B I Mohammed Abbas
5f7bad07b9 Add extendhfxf2 into compiler rt (#111099)
Retry pr #109090 with updated extendhfxf2 test
2024-10-25 20:05:23 -04:00
Florian Mayer
2ec5c69b68 Revert "[Sanitizers] Intercept timer_create" (#113710)
Reverts llvm/llvm-project#112285
2024-10-25 09:42:01 -07:00
Sebastian Kreutzer
e738a5d8e3 Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 (#90959)" (#113548)
This fixes remaining issues in my previous PR #90959.

Changes:
- Removed dependency on LLVM header in `xray_interface.cpp`
- Fixed XRay patching for some targets due to missing changes in
architecture-specific patching functions
- Addressed some remaining compiler warnings that I missed in the
previous patch
- Formatting

I have tested these changes on `x86_64` (natively), as well as
`ppc64le`, `aarch64` and `arm32` (cross-compiled and emulated using
qemu).

**Original description:**

This PR introduces shared library (DSO) support for XRay based on a
revised version of the implementation outlined in [this
RFC](https://discourse.llvm.org/t/rfc-upstreaming-dso-instrumentation-support-for-xray/73000).
The feature enables the patching and handling of events from DSOs,
supporting both libraries linked at startup or explicitly loaded, e.g.
via `dlopen`.
This patch adds the following:
- The `-fxray-shared` flag to enable the feature (turned off by default)
- A small runtime library that is linked into every instrumented DSO,
providing position-independent trampolines and code to register with the
main XRay runtime
- Changes to the XRay runtime to support management and patching of
multiple objects

These changes are fully backward compatible, i.e. running without
instrumented DSOs will produce identical traces (in terms of recorded
function IDs) to the previous implementation.

Due to my limited ability to test on other architectures, this feature
is only implemented and tested with x86_64. Extending support to other
architectures is fairly straightforward, requiring only a
position-independent implementation of the architecture-specific
trampoline implementation (see
`compiler-rt/lib/xray/xray_trampoline_x86_64.S` for reference).

This patch does not include any functionality to resolve function IDs
from DSOs for the provided logging/tracing modes. These modes still work
and will record calls from DSOs, but symbol resolution for these
functions in not available. Getting this to work properly requires
recording information about the loaded DSOs and should IMO be discussed
in a separate RFC, as there are mulitple feasible approaches.

---------

Co-authored-by: Sebastian Kreutzer <sebastian.kreutzer@tu-darmstadt.de>
2024-10-25 10:15:25 +02:00
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 b515d9ea1e 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