0
0
mirror of https://github.com/llvm/llvm-project.git synced 2025-04-18 14:56:44 +00:00

1159 Commits

Author SHA1 Message Date
Jonas Paulsson
6d03f51f0c
[SystemZ] Add support for 16-bit floating point. ()
- _Float16 is now accepted by Clang.

- The half IR type is fully handled by the backend.

- These values are passed in FP registers and converted to/from float around
  each operation.

- Compiler-rt conversion functions are now built for s390x including the missing
  extendhfdf2 which was added.

Fixes 
2025-04-16 20:02:56 +02:00
Brad Smith
d1fd97737e
[compiler-rt][sanitizer] add Haiku support ()
Co-authored-by: Jérôme Duval <jerome.duval@gmail.com>
2025-04-11 16:21:00 -04:00
Joseph Huber
2f41fa387d
[AMDGPU] Fix code object version not being set to 'none' ()
Summary:
Previously, we removed the special handling for the code object version
global. I erroneously thought that this meant we cold get rid of this
weird `-Xclang` option. However, this also emits an LLVM IR module flag,
which will then cause linking issues.
2025-04-10 11:31:21 -05:00
Qinkun Bao
45b9e24b1e
Fix some small typos in compiler-rt. NFC () 2025-03-28 15:51:13 -04:00
Joseph Huber
772173f548
[Clang][AMDGPU] Remove special handling for COV4 libraries ()
Summary:
When we were first porting to COV5, this lead to some ABI issues due to
a change in how we looked up the work group size. Bitcode libraries
relied on the builtins to emit code, but this was changed between
versions. This prevented the bitcode libraries, like OpenMP or libc,
from being used for both COV4 and COV5. The solution was to have this
'none' functionality which effectively emitted code that branched off of
a global to resolve to either version.

This isn't a great solution because it forced every TU to have this
variable in it. The patch in
https://github.com/llvm/llvm-project/pull/131033 removed support for
COV4 from OpenMP, which was the only consumer of this functionality.
Other users like HIP and OpenCL did not use this because they linked the
ROCm Device Library directly which has its own handling (The name was
borrowed from it after all).

So, now that we don't need to worry about backward compatibility with
COV4, we can remove this special handling. Users can still emit COV4
code, this simply removes the special handling used to make the OpenMP
device runtime bitcode version agnostic.
2025-03-28 07:35:16 -05:00
Wu Yingcong
e54f31a20c
[compiler-rt][builtins] Add missing flag for builtins standalone build ()
When builtins are built with runtimes, it is built before compiler-rt,
and this makes some of the HAS_XXX_FLAGs missing. In this case, the
COMPILER_RT_HAS_FCF_PROTECTION_FLAG is missing which makes it impossible
to enable CET in this case. This patch addresses this issue by also
check for such flag in standalone build instead of relying on the
compiler-rt's detection.
2025-03-27 10:15:48 +08:00
Daniel Chen
f73da649cb
Revert "[compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. ()" ()
…

This reverts commit 8e773d8a10cc996fbbe834f59ed9f7044c3539e0.
2025-03-22 20:56:47 -04:00
Daniel Chen
8e773d8a10
[compiler-rt] Disable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. ()
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON is not supported on AIX.
Set it to OFF with a WARNING message on AIX.
2025-03-19 16:35:15 -04:00
Kai Nacke
64142391fd
[SystemZ][XRay] Reland XRay runtime support for SystemZ ()
Adds the runtime support routines for XRay on SystemZ. Only function
entry/exit is implemented.

The original PR 113252 was reverted due to errors caused by adding DSO
support to XRay.
This PR is the original implementation with the changed function
signatures. I'll add an implementation with DSO support later.
2025-01-31 12:13:26 -05:00
Ami-zhang
79231a8684
[ORC-RT][LoongArch] Add initial support for loongarch64 in ELFNixPlatform ()
Enable ELFNixPlatform support for loongarch64. These are few simple
changes, but it allows us to use the orc runtime in ELF/LoongArch64
backend.

This change adds test cases targeting the LoongArch64 Linux platform to
the ORC runtime integration test suite. Since jitlink for loongarch64 is
ready for general use, and ELF-based platforms support defining multiple
static initializer table sections with differing priorities, some
relevant test cases in compiler-rt for ELFNixPlatform support can be
enabled.
2025-01-21 14:25:03 +08:00
Tristan Ross
783dc59b3b
[compiler-rt] Check codesign in path before using ()
Fixes an issue discovered with Nix where codesign is executed but Nix
cannot use codesign without faults. Use `find_program` in CMake to
ensure it is in `$PATH`.

Can be tested on macOS and change your path in such a way that
`codesign` isn't in it.

Related: https://github.com/NixOS/nixpkgs/pull/329058
2025-01-08 18:57:32 -08:00
thetruestblue
75325c658e
[Darwin][CompilerRT] Set compiler ID to 'Clang' for Compiler RT Tests for Apple Clang ()
This patch restores previous behavior. Even when the Compiler ID is set
to AppleClang, we expect Compiler RT Tests to use Clang as the compiler
ID. This impacts various make and lit commands.

Caused by: https://github.com/llvm/llvm-project/pull/117812/files

rdar://141548700
2025-01-07 13:19:55 -08:00
Amara Emerson
3c8344f7ba
[AArch64][SME] Fix broken compiler check for SME2 support in compiler-rt ()
This compile time test uses inline asm with `.arch` directives to set
the target feature. It is however broken and always fails, since each
`asm()` construct in LLVM sets up a new AsmParser, and therefore the
`.arch` directive has no effect on later `asm()` contents. To fix this
we need to use a single inline `asm()` call with the entire code chunk
to emit contained inside.
2025-01-06 01:37:56 -08:00
Sander de Smalen
811f2a652b
[Compiler-rt] Add AArch64 routines for __arm_agnostic("sme_za_state") ()
The specification of these routines can be found here:

https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#sme-support-routines
2024-12-20 15:49:33 +00:00
Florian Hahn
641fbf1524
[TySan] Add initial Type Sanitizer runtime ()
This patch introduces the runtime components for type sanitizer: a
sanitizer for type-based aliasing violations.

It is based on Hal Finkel's https://reviews.llvm.org/D32197.

C/C++ have type-based aliasing rules, and LLVM's optimizer can exploit
these given TBAA metadata added by Clang. Roughly, a pointer of given
type cannot be used to access an object of a different type (with, of
course, certain exceptions). Unfortunately, there's a lot of code in the
wild that violates these rules (e.g. for type punning), and such code
often must be built with -fno-strict-aliasing. Performance is often
sacrificed as a result. Part of the problem is the difficulty of finding
TBAA violations. Hopefully, this sanitizer will help.

For each TBAA type-access descriptor, encoded in LLVM's IR using
metadata, the corresponding instrumentation pass generates descriptor
tables. Thus, for each type (and access descriptor), we have a unique
pointer representation. Excepting anonymous-namespace types, these
tables are comdat, so the pointer values should be unique across the
program. The descriptors refer to other descriptors to form a type
aliasing tree (just like LLVM's TBAA metadata does). The instrumentation
handles the "fast path" (where the types match exactly and no
partial-overlaps are detected), and defers to the runtime to handle all
of the more-complicated cases. The runtime, of course, is also
responsible for reporting errors when those are detected.

The runtime uses essentially the same shadow memory region as tsan, and
we use 8 bytes of shadow memory, the size of the pointer to the type
descriptor, for every byte of accessed data in the program. The value 0
is used to represent an unknown type. The value -1 is used to represent
an interior byte (a byte that is part of a type, but not the first
byte). The instrumentation first checks for an exact match between the
type of the current access and the type for that address recorded in the
shadow memory. If it matches, it then checks the shadow for the
remainder of the bytes in the type to make sure that they're all -1. If
not, we call the runtime. If the exact match fails, we next check if the
value is 0 (i.e. unknown). If it is, then we check the shadow for the
remainder of the byes in the type (to make sure they're all 0). If
they're not, we call the runtime. We then set the shadow for the access
address and set the shadow for the remaining bytes in the type to -1
(i.e. marking them as interior bytes). If the type indicated by the
shadow memory for the access address is neither an exact match nor 0, we
call the runtime.

The instrumentation pass inserts calls to the memset intrinsic to set
the memory updated by memset, memcpy, and memmove, as well as
allocas/byval (and for lifetime.start/end) to reset the shadow memory to
reflect that the type is now unknown. The runtime intercepts memset,
memcpy, etc. to perform the same function for the library calls.

The runtime essentially repeats these checks, but uses the full TBAA
algorithm, just as the compiler does, to determine when two types are
permitted to alias. In a situation where access overlap has occurred and
aliasing is not permitted, an error is generated.

As a note, this implementation does not use the compressed shadow-memory
scheme discussed previously
(http://lists.llvm.org/pipermail/llvm-dev/2017-April/111766.html). That
scheme would not handle the struct-path (i.e. structure offset)
information that our TBAA represents. I expect we'll want to further
work on compressing the shadow-memory representation, but I think it
makes sense to do that as follow-up work.

This includes build fixes for Linux from Mingjie Xu.

Depends on  (Clang support),  (LLVM support)


PR: https://github.com/llvm/llvm-project/pull/76261
2024-12-17 18:49:50 +00:00
paperchalice
b07e7b76c5
[cmake] Drop AddFileDependencies and CMakeParseArguments ()
Theses modules are deprecated and have trivial implementations in modern
cmake.
2024-12-17 19:24:32 +08:00
Min-Yih Hsu
ea76b2d8d8
[XRay][RISCV] RISCV support for XRay ()
Add RISC-V support for XRay. The RV64 implementation has been tested in
both QEMU and in our hardware environment.

Currently this requires D and C extensions, but since both RV64GC and
RVA22/RVA23 are becoming mainstream, I don't think this requirement will
be a big problem.

Based on the previous work by @a-poduval :
https://reviews.llvm.org/D117929

---------

Co-authored-by: Ashwin Poduval <ashwin.poduval@gmail.com>
2024-12-10 17:57:04 -08:00
Cyndy Ishida
877b934831
[CompilerRT] Remove sanitizer support for i386 watchsim ()
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
Brian Cain
c906907d87
[hexagon][cmake] Disable ctx_profile ()
Since , 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
3cb28522ba
Reapply "[runtimes] Allow building against an installed LLVM tree"
This relands  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
Alexander Richardson
5082acce4f
[compiler-rt] Add custom libc++ workaround for CMake < 3.26
The INSTALL_BYPRODUCTS ExternalProject_Add() argument was only added in
CMake 3.26 and the current minimum is 3.20. Work around this by using an
explicit ExternalProject_Add_Step() call for the install step with a
BYPRODUCTS argument. We can't keep using the `install` name here since that
is reserved by the CMake implementation and results in errors when used.

This commit should be reverted once LLVM depends on CMake 3.26.

Pull Request: https://github.com/llvm/llvm-project/pull/115677
2024-11-10 20:30:23 -08:00
Alexander Richardson
a29e623e12
[compiler-rt] Make add_custom_libcxx() resilient to DESTDIR being set
If DESTDIR is set in the environment during the build/test stage, the
local libc++ installation will be installed under DESTDIR instead of being
in the build directory.

See https://github.com/llvm/llvm-project/pull/115077#issuecomment-2464640457
and https://gitlab.kitware.com/cmake/cmake/-/issues/18165.

Pull Request: https://github.com/llvm/llvm-project/pull/115525
2024-11-08 11:45:38 -08:00
Sebastian Kreutzer
1adca7af21
Reapply "[XRay][AArch64] Support -fxray-shared ()" ()
This patch implements support for `-fxray-shared` on AArch64 and fixes a
remaining issue in the previous PR .

A bug in the XRay `CMakeLists.txt` caused the XRay assembly sources to
be built for every architecture in `XRAY_DSO_SUPPORTED_ARCH` on Apple.
This led to the compiler trying to compile AArch64 assembly for X86
targets and vice versa.
This is addressed here by ensuring that assembly sources are only built
for the matching architecture (see fixup commit).

**Original PR description:**
This patch adds support for `-fxray-shared` on AArch64. This feature,
introduced in  for x86_64, enables the instrumentation of shared
libraries with XRay.

Changes:
- Adds AArch64 to the list of targets supporting `-fxray-shared`
- Introduces PIC versions of the AArch64 XRay trampolines 
- Adjusts relevant XRay tests
2024-11-07 23:21:04 -08:00
Alexander Richardson
a036d18f1a
[compiler-rt] Reduce build output for tests
Use CMAKE_INSTALL_MESSAGE=LAZY to only print the local libc++(abi)
installation messages for changed files instead of all files.

Pull Request: https://github.com/llvm/llvm-project/pull/115085
2024-11-06 11:58:41 -08:00
Alexander Richardson
e7bad34475
[compiler-rt] Use installed libc++(abi) for tests instead of build tree
Using the build tree is somewhat fragile since the layout is not
guaranteed to be stable and means the tests are tightly coupled to the
libc++/libc++abi build tree layout. Instead update the ExternalProject
to install the library and headers and do not add the build tree to
the include/linker flags.

Pull Request: https://github.com/llvm/llvm-project/pull/115077
2024-11-06 11:57:47 -08:00
Sylvestre Ledru
6d719d9700 Revert "[SystemZ][XRay] XRay runtime support for SystemZ ()"
for causing: https://github.com/llvm/llvm-project/issues/115129

This reverts commit db1882e2484013066139f0b3f77d968d84a79158.
2024-11-06 08:31:58 +01:00
Kai Nacke
db1882e248
[SystemZ][XRay] XRay runtime support for SystemZ ()
Adds the runtime support routines for XRay on SystemZ. Only function
entry/exit is implemented.
2024-11-05 15:36:59 -05:00
Felipe de Azevedo Piovezan
cb9700ebe4
Revert "[XRay][AArch64] Support -fxray-shared" ()
Reverts 
2024-11-05 08:43:37 -08:00
Jérôme Duval
d084bc291a
[compiler-rt][profile] Add support for LLVM profile for Haiku ()
Haiku uses typical UNIX interfaces.

All tests pass except
instrprof-error.c
Posix/gcov-dlopen.c
Posix/gcov-destructor.c
Posix/instrprof-dlopen-norpath.test

---------

Co-authored-by: Petr Hosek <phosek@google.com>
2024-11-05 03:14:25 -05:00
Sebastian Kreutzer
7767aa45ab
[XRay][AArch64] Support -fxray-shared ()
This patch adds support for `-fxray-shared` on AArch64. This feature,
introduced in  for x86_64, enables the instrumentation of shared
libraries with XRay.

Changes:
- Adds AArch64 to the list of targets supporting `-fxray-shared`
- Introduces PIC versions of the AArch64 XRay trampolines 
- Adjusts relevant XRay tests
2024-11-04 23:05:05 -08:00
Louis Dionne
6127724786
[cmake] Remove obsolete files, docs and CMake variables related to the standalone build ()
The runtimes used to support a build mode called the "Standalone build",
which isn't supported anymore (and hasn't been for a few years).
However, various places in the code still contained stuff whose only
purpose was to support that build mode, and some outdated documentation.
This patch cleans that up (although I probably missed some).

- Remove HandleOutOfTreeLLVM.cmake which isn't referenced anymore
- Remove the LLVM_PATH CMake variable which isn't used anymore
- Update some outdated documentation referencing standalone builds
2024-11-04 17:53:38 -05:00
Nikolas Klauser
3ac75ee8ec
Revert "[runtimes] Allow building against an installed LLVM tree" ()
Reverts 

This patch breaks running tests locally, which is extremely disruptive
to libc++ development.
2024-10-28 16:25:58 +01:00
Sebastian Kreutzer
e738a5d8e3
Reapply " [XRay] Add support for instrumentation of DSOs on x86_64 ()" ()
This fixes remaining issues in my previous PR .

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
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
Yuta Saito
d4efc3e097
[Coverage][WebAssembly] Add initial support for WebAssembly/WASI ()
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 ()
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
Mikhail Goncharov
90627a5a19 Revert "[XRay] Add support for instrumentation of DSOs on x86_64 ()"
This reverts commit a4402039bffd788b9af82435fd5a2fb311fdc6e8 and 4451f9f812d458f6b53785b27869674caf01e67b
2024-10-11 14:01:58 +02:00
Sebastian Kreutzer
a4402039bf
[XRay] Add support for instrumentation of DSOs on x86_64 ()
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.

@petrhosek @jplehr
2024-10-11 11:23:34 +02:00
Brian Cain
ea62db0c03
[cmake] Add hexagon-linux cmake cache files ()
These can be used to create a fully-bootstrapped toolchain to target
hexagon {baremetal,linux} with scripts like the ones in
https://github.com/quic/toolchain_for_hexagon
2024-10-03 08:11:34 -05:00
Raul Tambre
c26a5227c1
[compiler-rt] Fix C and C++ compilers being switched when compiling tests ()
The logic was simply switched. Fixes building tests for me.  
Not sure how I haven't stumbled upon this before considering this code hasn't changed lately and my setup's been the same.

Fixes: 07317bbc66d1f2d7663af3c9f04d0f6c0487ac03
2024-10-01 09:59:12 +03:00
Charlie Barto
81935c5e96
[compiler-rt] [MSVC] Detect MSVC as a compiler-id for lit. ()
This is only for "real" msvc and is to support running sanitizer tests
with "real" MSVC. Most compiler-rt tests do not yet pass with msvc,
which will be addressed in future PRs for asan, sanitizer_common, and
the fuzzer.

We've been using these changes to lit to run CI for the version of
address sanitizer that ships with MSVC, by upstreaming them we can avoid
being broken by future lit changes and allow contributors (importantly
_us_) to run the MSVC tests on changes developed in the open.
2024-09-12 10:30:13 -07:00
Petr Hosek
26a4edf655
[CMake][compiler-rt] Support for using compiler-rt atomic library ()
Not every toolchain provides and want to use libatomic which is a part
of GCC, some toolchains may opt into using compiler-rt atomic library.
2024-09-03 10:28:49 -07:00
Martin Storsjö
5ea9dd8c70
[compiler-rt] Support building runtimes for Windows on arm32 ()
In these environments, the architecture name is armv7; recognize that
and enable the relevant runtimes.

Fix building the sanitizer_common library for this target, by using the
right registers for the architecture - this is similar to what
0c391133c9201ef29273554a1505ef855ce17668 did for aarch64.

(Still, address sanitizer doesn't support hooking functions at runtime
on armv7 or aarch64 - but other runtimes such as ubsan do work.)
2024-08-08 13:51:07 +03:00
Alexander Richardson
1ae837ab34
[compiler-rt] Update AllSupportedArchDefs.cmake for FreeBSD
This syncs the list of supported sanitizers with the matching code
in clang (`FreeBSD::getSupportedSanitizers()`),

Reviewed By: emaste, DimitryAndric

Pull Request: https://github.com/llvm/llvm-project/pull/84280
2024-08-02 14:53:45 -07:00
h-vetinari
89946bda5e
[cmake] switch to CMake's native check_{compiler,linker}_flag ()
Broken out from 

Somewhat closing the loop opened by 7017e6c9cfd2de.

Co-authored-by: Ryan Prichard <rprichard@google.com>
2024-07-31 10:31:13 -04:00
Rainer Orth
c34d673b02
[asan][cmake][test] Fix finding dynamic asan runtime lib ()
In a `runtimes` build on Solaris/amd64, there are two failues:
```
  AddressSanitizer-Unit :: ./Asan-i386-calls-Dynamic-Test/failed_to_discover_tests_from_gtest
  AddressSanitizer-Unit :: ./Asan-i386-inline-Dynamic-Test/failed_to_discover_tests_from_gtest
```
This happens when `lit` enumerates the tests with `--gtest_list_tests
--gtest_filter=-*DISABLED_*`. The error is twofold:

- The `LD_LIBRARY_PATH*` variables point at the 64-bit directory
(`lib/clang/19/lib/x86_64-pc-solaris2.11`) for a 32-bit test:
  ``` 
ld.so.1: Asan-i386-calls-Dynamic-Test: fatal:
/var/llvm/local-amd64-release-stage2-A-flang-clang18-runtimes/tools/clang/stage2-bins/./lib/../lib/clang/19/lib/x86_64-pc-solaris2.11/libclang_rt.asan.so:
wrong ELF class: ELFCLASS64
  ```
- While the tests are linked with `-Wl,-rpath`, that path always is the
64-bit directory again.

Accordingly, the fix consists of two parts:
- The code in `compiler-rt/test/asan/Unit/lit.site.cfg.py.in` to adjust
the `LD_LIBRARY_PATH*` variables is guarded by a `config.target_arch !=
config.host_arch` condition. This is wrong in two ways:
- The adjustment is always needed independent of the host arch. This is
what `compiler-rt/test/lit.common.cfg.py` already does.
- Besides, `config.host_arch` is ultimately set from
`CMAKE_HOST_SYSTEM_PROCESSOR`. On Linux/x86_64, this is `x86_64` (`uname
-m`) while on Solaris/amd64 it's `i386` (`uname -p`), explaining why the
transformation is skipped on Solaris, but not on Linux.
- Besides, `RPATH` needs to be set to the correct subdirectory, so
instead of using the default arch in `compiler-rt/CMakeLists.txt`, this
patch moves the code to a function which takes the test's arch into
account.

Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`.
2024-07-24 10:03:47 +02:00
Chris Apple
b2060965fd
[rtsan] Remove android support ()
Based on failing build:
https://lab.llvm.org/buildbot/#/builders/186/builds/829

Follow up to 
2024-07-22 15:17:07 -07:00
Chris Apple
b846176950
[compiler-rt] Moved cmake libatomic check to top level config-ix ()
Also add atomic check to rtsan for when the tests are merged (related
review )
2024-07-22 13:40:20 -07:00
davidtrevelyan
b177ac4a44
[compiler-rt][rtsan] Use sanitizer internal allocator during rtsan init to avoid segfault in dlsym ()
Follows https://github.com/llvm/llvm-project/pull/98268 with a fix for a
segfault during preinit on `ubuntu:20.04` environments. Previously,
`rtsan` was not handling the situation where `dlsym` calls `calloc`
during the interceptors initialization, resulting in a call to a
function at a null address.

@cjappl and I took inspiration from the solution in `nsan`, but we
re-used the sanitizer internal allocator instead of our own static
buffer. This PR also re-enables the existing non-instrumented `rtsan`
tests for `x86_64` and `arm64` architectures.

---------

Co-authored-by: Chris Apple <cja-private@pm.me>
2024-07-22 13:35:37 -07:00