155 Commits

Author SHA1 Message Date
Keith Smiley
332f5e7113 [compiler-rt][ORC] Remove unused cmake variables (NFC) (#87742) 2024-05-14 12:24:12 -07:00
Nikita Popov
47682e4b4a Revert "[ORC] Implement basic reoptimization. (#67050)"
This reverts commit 0d288e5b0c.

Breaks the build.
2024-04-26 14:47:48 +09:00
Sunho Kim
0d288e5b0c [ORC] Implement basic reoptimization. (#67050) 2024-04-25 22:43:06 -07:00
Alexander Richardson
55b90b5140 [compiler-rt] Remove llvm_gtest dependency from unit tests
All these unit tests already include ${COMPILER_RT_GTEST_SOURCE} as an
input source file and the target llvm_gtest does not exist for
standalone builds. Currently the DEPS argument is ignored for standalone
builds so the missing target is not a problem, but as part of fixing a
build race for standalone builds I am planning to include those
dependencies in COMPILER_RT_TEST_STANDALONE_BUILD_LIBS configurations.

Reviewed By: vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/83649
2024-03-13 11:28:44 -07:00
Alexandre Ganea
bd9bec8e78 [compiler-rt][ORC] Silence warning when building on MSVC/Windows
This fixes (the ORC lib already builds with exceptions disabled):
```
[5/11] Building CXX object projects\compiler-rt\lib\orc\CMakeFiles\RTOrc.x86_64.dir\dlfcn_wrapper.cpp.obj
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\vector(1619): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
```
2024-01-17 07:23:57 -05:00
Alexandre Ganea
6736cc60ed [ORC-RT] Silence warning when building with Clang ToT on Windows
This fixes several of these:
```
[3524/7446] Building CXX object projects\compiler-rt\lib\orc\CMakeFiles\RTOrc.x86_64.dir\dlfcn_wrapper.cpp.obj
In file included from C:\git\llvm-project\compiler-rt\lib\orc\dlfcn_wrapper.cpp:15:
C:\git\llvm-project\compiler-rt\lib\orc\wrapper_function_utils.h(299,27): warning: address of '__orc_rt_jit_dispatch_ctx' will always evaluate to 'true' [-Wpointer-bool-conversion]
  299 |     if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch_ctx))
      |                         ~ ^~~~~~~~~~~~~~~~~~~~~~~~~
C:\git\llvm-project\compiler-rt\lib\orc\compiler.h(60,55): note: expanded from macro 'ORC_RT_UNLIKELY'
   60 | #define ORC_RT_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
      |                                                       ^~~~
1 warning generated.
```
2024-01-17 07:23:57 -05:00
Alexandre Ganea
63a3c4cc85 [compiler-rt] Silence warning with MSVC 19.38 (Visual Studio 2022 17.8.3)
This fixes:
```
C:\git\llvm-project\compiler-rt\lib\orc\coff_platform.cpp(512): warning C4189: 'JDState': local variable is initialized but not referenced
```
2024-01-17 07:23:56 -05:00
Ben Langmuir
40b4ac278e [ORC] Refactor executor symbol lookup to use ExecutorSymbolDef (NFC) (#76989)
This migrates the dylib manager lookup and related APIs to replace
ExecutorAddress with ExecutorSymbolDef so that in the future we can
model JITSymbolFlags for these symbols. The current change should be NFC
as we are only setting the Exported symbol flag.
2024-01-04 13:13:22 -08:00
Ben Langmuir
dc58f781b6 [ORC-RT] Fix ptrauth signing for dlsym return value (#75972)
dlsym signs text symbols as functions rather than data in dyld, so match
that for orc runtime dlsym. This fixes run_program on arm64e.
2023-12-19 14:56:42 -08:00
Ben Langmuir
1c58a6b8b4 [orc-rt] Add ORC_ENABLE_OSX to control whether to build the orc runtime (#75536)
Embedded Darwin platforms have generalized COMPILER_RT_ENABLE_<PLATFORM>
configuration settings, but currently 'osx' is always eabled on Darwin.
Add ORC_ENABLE_OSX to allow explicitly *disabling* the orc runtime for
macOS platform. This can be useful if you only want to build a specific
embedded platform. It would be nice to generalize this to handle other
compiler-rt projects (i.e. add COMPILER_RT_ENABLE_OSX), but would
require additional attention from each compiler-rt project.

Note: some tests currently only are configured for osx, so these are
disabled when osx is disabled.
2023-12-14 15:28:45 -08:00
Jan Svoboda
f1e3e8a14f [ORC-RT][ORC][MachO] Fix build after 437b4f1c 2023-12-08 18:09:44 -08:00
Lang Hames
437b4f1c2e [ORC-RT][ORC][MachO] Refactor dlsym to extract a reusable bulk-lookup API.
MachOPlatformRuntimeState::lookupSymbols encapsulates the approach used in
dlsym in bb41fc682e, but generalizes it to multiple symbols:
  1. try to resolve symbols locally
  2. issue a push-request for any unresolved symbols
  3. re-try local resolution

In the future lookupSymbols can serve as the basis for a public bulk lookup
API in the ORC runtime.
2023-12-08 16:20:37 -08:00
Lang Hames
93509b4462 [ORC-RT][ORC][MachO] Fix some issues with executor-side symbol tables.
1. Prevent deadlock by unlocking JDStatesMutex when calling back to the
   controller to request a push of new symbols. (If JDStatesMutex is locked
   then the push operation can't register the new symbols, and so can't
   complete).

2. Record MachOPlatform runtime symbols during bootstrap and attach their
   registration to the bootstrap-completion graph, similar to the way that
   deferred allocation actions are handled. We can't register the symbols
   the normal way during bootstrap since the symbol registration function is
   itself in the process of being materialized.

3. Add dlsym testcases to exercise these fixes.
2023-12-07 14:38:51 -08:00
Lang Hames
bb41fc682e [ORC-RT][ORC][MachO] Add executor-side symbol tables to MachO platform support.
Adds symbol tables to the JITDylibState struct in the ORC runtime
MachOPlatformRuntimeState class. This table will hold the addresses of
materialized symbols (registered by a new JITLink pass in MachOPlatform),
allowing these to be looked up in the executor without an IPC request to the
controller.

The old lookup-symbols callback (made by the runtime in response to dlsym
lookups) is replaced with a push-symbols callback that can trigger
materialization of requested symbols.

Holding a symbol table on the executor side should make repeat calls to dlsym
(and other symbol lookup operations) cheaper since the IPC to trigger
materialization happens at most once per symbol. It should also enable us (at
some point in the future) to symbolicate backtraces in JIT'd code even if the
controller process is gone (e.g. detached or crashed). The trade-off for this
is increased memory consumption in the executor and larger JIT'd data transfers
(since symbol names are now transferred to the executor unconditionally, even
though they may never be used).
2023-12-02 15:25:25 -08:00
Lang Hames
7138fabfbc [ORC-RT] Add SPS serialization for std::tuple.
This will be used in upcoming changes to macho_platform.
2023-11-27 09:48:56 -08:00
Lang Hames
d97981c98a [ORC-RT] Add missing cstdint include.
This should have been included in b2bbe8cc1c. Adding it should fix the bot
failures in https://lab.llvm.org/buildbot/#/builders/85/builds/20288
2023-11-16 16:45:29 -08:00
Lang Hames
b2bbe8cc1c [ORC-RT] Add bitmask-enum and bit_ceil utilities to the ORC runtime.
bitmask_enum.h is essentially a copy of llvm/ADT/BitmaskEnum.h, with some minor
cleanup and renaming.

The bit_ceil function is a placeholder for std::bit_ceil, which we can use once
compiler-rt can use c++20.

These utilities will be used to simplify bitfield enum usage in upcoming
ORC-RT patches.
2023-11-16 16:14:15 -08:00
Kai Luo
9c38a178d3 [JITLink][PowerPC] Add basic TLS support for ppc64
Add basic TLS support for ppc64. Only global-dynamic model is supported.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D155926
2023-08-02 05:02:36 +00:00
Lang Hames
6098e2e552 [ORC-RT] Fix typo in debugging output. 2023-07-28 16:22:57 -07:00
Martin Storsjö
c6bd873403 [CMake] Switch the CMP0091 policy (MSVC_RUNTIME_LIBRARY) to the new behaviour
With the new behaviour, the /MD or similar options aren't added to
e.g. CMAKE_CXX_FLAGS_RELEASE, but are added separately by CMake.
They can be changed by the cmake variable
CMAKE_MSVC_RUNTIME_LIBRARY or with the target property
MSVC_RUNTIME_LIBRARY.

LLVM has had its own custom CMake flags, e.g. LLVM_USE_CRT_RELEASE,
which affects which CRT is used for release mode builds. Deprecate
these and direct users to use CMAKE_MSVC_RUNTIME_LIBRARY directly
instead (and do a best effort attempt at setting CMAKE_MSVC_RUNTIME_LIBRARY
based on the existing LLVM_USE_CRT_ flags). This only handles the
simple cases, it doesn't handle multi-config generators with
different LLVM_USE_CRT_* variables for different configs though,
but that's probably fine - we should move over to the new upstream
CMake mechanism anyway, and push users towards that.

Change code in compiler-rt, that previously tried to override the
CRT choice to /MT, to set CMAKE_MSVC_RUNTIME_LIBRARY instead of
meddling in the old variables.

This resolves the policy issue in
https://github.com/llvm/llvm-project/issues/63286, and should
handle the issues that were observed originally when the
minimum CMake version was bumped, in
https://github.com/llvm/llvm-project/issues/62719 and
https://github.com/llvm/llvm-project/issues/62739.

Differential Revision: https://reviews.llvm.org/D155233
2023-07-17 09:59:05 +03:00
Mark de Wever
42478d1473 [compiler-rt] Removes CMake work-arounds.
CMake older than 3.20.0 is no longer supported.
This removes work-arounds for no longer supported versions.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D152102
2023-06-07 17:42:28 +02:00
Lang Hames
66530ba0b6 [ORC-RT] Fix typo in include-guard comment. 2023-04-20 21:46:51 -07:00
Lang Hames
61d535ac36 [ORC-RT] Don't check for objc image registration functions unless needed.
If we don't have any ObjC metadata to register we shouldn't require these
symbols to be available.
2023-04-17 13:51:33 -07:00
Lang Hames
9d701c8a8d [ORC] Fix fallout from switch to _objc_map/load_images-based registration.
In f448d44663 we switched to calling _objc_map_images and _objc_load_images
for MachO language metadata registration. This patch fixes some bugs arising
from that change:

(1) __objc_imageinfo processing was moved to a post-allocation pass, but this
    prevents us from discarding the redundant copies. This commit moves
    processing back to a pre-prune pass and inserts a symbol for the uniqued
    __objc_image section. Runtime objects use an edge pointing to this symbol
    to access the address.

(2) We were assuming that _objc_map_images & _objc_load_images were available
    in the Objective-C runtime on 10.15, but these functions didn't become
    available until later. This commit bumps the macOS version requirement to
    13.1 where the functions should be available.

(3) The ORC-RT trivial-swift-types-section.S test was missing an
    __objc_unwindinfo section, which triggered an assert that should have
    been an error. The assert has been turned into an error, and the testcase
    has been updated to include an __objc_imageinfo.

rdar://107846455
2023-04-11 16:48:26 -07:00
Lang Hames
f448d44663 [ORC][ORC-RT][MachO] Use _objc_(map|load)_images for ObjC & Swift registration.
This patch drops the individual registration calls to the ObjC and Swift
runtimes (for selectors, classes, etc.), and instead creates a Mach header and
load commands that can be passed to _objc_map_images and _objc_load_images to
trigger registration and execution of +load methods. This approach supports
categories (for which there is no current registration API), and more closely
follows dyld's ObjC & Swift registration path.
2023-04-08 15:54:02 -07:00
Lang Hames
cd3f2749ed [ORC][ORC-RT][ELF] Move selection of eh-frame registration APIs into orc-rt.
ORC's ELF platform support prefers the newer libunwind registration functions
(__unw_add_dynamic_eh_frame_section, __unw_remove_dynamic_eh_frame_section) when
they're available, and falls back to the older registration functions
(__register_frame, __deregister_frame) when they're not.

Until now the choice of registration functions has been made on the controller
side in ELFNixPlatform: The platform JITDylib was searched for the registration
functions and aliases set depending on which ones were found. This patch drops
that selection logic from ELFNixPlatform and instead uses weak imports of the
registration functions in elfnix_platform.cpp to identify which ones are
available and choose which ones to use.

This has a few small benefits:
(1) The registration functions don't need to be defined in the same JITDylib as
the ORC runtime -- it's sufficient for them to be defined in a JITDylib that the
ORC runtime's JITDylib links against.

(2) THe elfnix_platfrom code is more readable, as we don't have to dig into
ELFNixPlatform.cpp on the controller side to discover the definition of the
registration aliases.

(3) We may save a separate round-trip to look up the registration APIs (the
lookup will be folded into the ordinary external symbol lookup when linking the
runtime).
2023-04-06 16:31:55 +00:00
Lang Hames
34fccfb23c [ORC-RT] Remove the '__' prefix from the ORC runtime's public API.
The '__' prefix should only be used for the parts of the ORC runtime that
implement compiler / loader runtime details (e.g. ORC-RT's __tlv_get_addr
implementations).

This patch only fixes the public API. Future changes will fix internal names.
2023-02-21 18:37:10 -08:00
Lang Hames
332a934ced [ORC-RT][MachO] Use 'UseCallbackStyleUnwindInfo' flag, rather than re-test.
The UseCallbackStyleUnwindInfo flag already captures the original conditional,
and using the flag everywhere makes it easier to switch registration styles
when debugging.
2023-02-21 16:48:14 -08:00
Lang Hames
3507df9c20 [ORC][ORC-RT] Add support for callback-based lookup of JIT'd MachO unwind info.
In LLVM the MachOPlatform class is modified to identify unwind info sections
and the address ranges of the functions these sections cover. These address
ranges are then communicated to the ORC runtime by attaching them to the
register-object-platform-sections allocation action.

In the ORC runtime the unwind-info section addresses are recorded and used to
support lookup of unwind info via the new `findDynamicUnwindSections` function.
At bootstrap time the ORC runtime checks for the presence of new
unwind-info-lookup-registration functions in libunwind (see
https://reviews.llvm.org/D142176), and if available uses them to register the
`findDynamicUnwindSections` function with libunwind to enable callback-based
lookup. If the new unwind-info-lookup-registration functions are not available
then the ORC runtime falls back to using the existing libunwind registration
APIs.

The callback-based scheme is intended to address three shortcomings in the
current registration scheme for JIT'd unwind info on Darwin: (1) Lack of
compact-unwind support, (2) inability to describe the subarchitecture of JIT'd
frames, and (3) lack of efficient address-based lookup data structures in
libunwind.

For more details see the proposed libunwind changes in
https://reviews.llvm.org/D142176.
2023-01-19 22:37:57 -08:00
Lang Hames
ad4b66fd9b [ORC-RT] Specialize non-coalescing-IntervalMap to allow non-comparable values.
In non-coalescing IntervalMaps the value type should not be requried to be
equality-comparable.
2023-01-18 17:39:45 -08:00
Lang Hames
bbb73fbceb [ORC-RT] Reapply ab59185fbf (Add IntervalMap/Set), with missing files included.
The original commit was reverted in c151e8428a due missing files (thanks Kazu!).
2023-01-17 13:47:47 -08:00
Kazu Hirata
c151e8428a Revert "[ORC-RT] Add IntervalMap and IntervalSet collections."
This reverts commit ab59185fbf.

It looks like this commit is missing interval_set_test.cpp.
2023-01-17 13:36:03 -08:00
Lang Hames
ab59185fbf [ORC-RT] Add IntervalMap and IntervalSet collections.
IntervalMap is an optionally-coalescing map -- it uses half-open ranges as keys,
allows lookups based on elements of the ranges (returning an iterator to the
containing range) and optionally coalesces adjacent ranges that have the same
value.

IntervalSet is an optionally-coalescing set based on IntervalMap.

These collections will be used to store and lookup metadata section ranges,
e.g. unwind-info ranges.
2023-01-17 13:25:25 -08:00
Lang Hames
9afe78d1fc [ORC-RT] Fix a typo in file header. 2023-01-15 22:25:10 -08:00
Lang Hames
217fd59cc5 [ORC] Introduce deferred allocation-actions scheme for MachOPlatform bootstrap.
This patch modifies the MachOPlatform bootstrap process to record allocation
actions for ORC runtime platform support code in a "deferred actions" vector
rather than attaching it to the corresponding LinkGraphs up-front. The deferred
allocation-actions are run after all the platform support code has been loaded
by attaching them to a separate "bootstrap-complete" graph.

This change should allow the mach-o platform support code in the ORC runtime to
use advanced mach-o platform features (e.g. static inits, TLVs), provided that
the support code does not use these features at runtime before the bootstrap
process completes, or after the shutdown process starts. This is a nice
improvement in and of itself but is motivated by specific future plans: we
want to start recording unwind info in the mach-o platform state object*, and
the recording functions will have their own frame info that needs registering.
The deferred allocation-actions scheme allows for this.

* The plan is to add a new unwind-info-lookup path to libunwind to allow it to
  call back to the ORC runtime to find unwind sections. This will simplify the
  implementation of support for JIT'd compact-unwind info.
2023-01-13 16:15:57 -08:00
Lang Hames
a0a51a805f [ORC][ORC-RT] Add SimplePackedSerialization support for optionals.
This allows optionals to be serialized and deserialized, and used as arguments
and return values in SPS wrapper functions.

Serialization of optional values is indicated by use of the SPSOptional tag.
SPSOptionals are serialized serialized as a bool (false for no value, true for
value) plus the serialization of the contained value if any. Serialization
to/from std::optional is included in this commit.

This commit includes updates to SimplePackedSerialization in both ORC and the
ORC runtime.

, std::optional serialization.
2022-12-22 17:37:32 -08:00
Lang Hames
e7707464a3 [ORC-RT][MachO] Unlock JDStatesMutex during push-initializers to avoid deadlock.
During __orc_rt_macho_jit_dlopen the ORC runtime will make a request to the JIT
to push any new initializers. Since this call may add new JD-state to the
runtime (and is expected to in general) we need to unlock the JDStatesMutex
during this operation (and similarly when running initializers and atexits, as
these may call trigger push-initializers recursively).

No testcase yet: I haven't been able to reproduce the deadlock when running
llvm-jitlink in in-process mode, and we don't support out-of-process mode in
regression tests yet.
2022-11-11 16:01:25 -08:00
Lang Hames
8fda8901e2 [ORC-RT] Add a SymbolStringPool class to the ORC runtime.
This is a counterpart to llvm::orc::SymbolStringPool. It holds uniqued,
ref-counted strings; and can be used to avoid redundant storage of strings,
and speed up comparison of strings held in the pool (these become pointer
comparisons).
2022-11-09 21:26:18 -08:00
Lang Hames
873584b6cb [ORC-RT][MachO] Add RecordSectionsTracker utility to track metadata sections.
Newly added sections can be processed by calling processNewSections. Calling
reset moves all sections back to the "new" state for reprocessing (expected to
be used by dlclose).
2022-11-09 21:26:17 -08:00
Kazu Hirata
3f8d2c917c Ensure newlines at the end of files (NFC) 2022-10-22 09:29:40 -07:00
Lang Hames
0e43f3b04d [ORC][ORC-RT] Make WrapperFunctionCall::Create support void functions.
Serialized calls to void-wrapper-functions should have zero bytes of argument
data, but accessing ArgData[0] may (and will, in the case of SmallVector) fail
if the argument data buffer is empty.

This commit fixes the issue by adding a check for empty argument buffers.
2022-09-18 17:53:45 -07:00
Lang Hames
47e9e58808 [ORC][ORC-RT][MachO] Reset __data and __common sections on library close.
If we want to be able to close and then re-open a library then we need to reset
the data section states when the library is closed. This commit updates
MachOPlatform and the ORC runtime to track __data and __common sections, and
reset the state in MachOPlatformRuntimeState::dlcloseDeinitialize.

This is only a first step to full support -- there are other data sections that
we're not capturing, and we'll probably want a more efficient representation
for the sections (rather than passing their string name over IPC), but this is
a reasonable first step.

This commit also contains a fix to MapperJITLinkMemoryManager that prevents it
from calling OnDeallocated twice in the case of an error.
2022-09-16 13:40:19 -07:00
Lang Hames
9cd28d3f11 [ORC-RT] Update COFF, ELF support after ExecutorAddrDiff change in 4c43483186. 2022-09-15 22:26:36 -07:00
jacquesguan
cbd7bc66c4 [ORC-RT] Remove wrong getValue of ExecutorAddrDiff. 2022-09-16 11:18:27 +08:00
Lang Hames
4c43483186 [ORC-RT] Make ExecutorAddrDiff an alias for uint64_t.
Unlike ExecutorAddr, there's limited value to having a distinct type for
ExecutorAddrDiff, and it's occasionally awkward to work with. The corresponding
LLVM type (llvm::orc::ExecutorAddrDiff) was already made a type-alias in
9e2cfb061a.
2022-09-15 19:11:51 -07:00
Lang Hames
35ea0c6d56 [ORC-RT] Update headers for rename of include/orc in a85e4aa37d.
The ORC runtime include directory was renamed from 'orc' to 'orc_rt' in
a85e4aa37d. Update includes to match.
2022-09-12 17:09:06 -07:00
Lang Hames
a85e4aa37d [ORC-RT] Drop the 'clang_rt.' prefix from the ORC runtime.
The ORC runtime isn't used by clang -- the prefix was just cargo-culted with
the rest of the XRay config when the ORC runtime was introduced. We now want to
make parts of it available for clients to link directly, so this seems like a
good time to fix the name.
2022-09-12 16:48:20 -07:00
sunho
73c4033987 [ORC][ORC_RT][COFF] Support dynamic VC runtime.
Supports dynamic VC runtime. It implements atexits handling which is required to load msvcrt.lib successfully. (the object file containing atexit symbol somehow resolves to static vc runtim symbols) It also default to dynamic vc runtime which tends to be more robust.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D132525
2022-09-10 15:25:49 +09:00
Lang Hames
1169586dcd [ORC-RT] Refactor ORC runtime CMake for future test tool(s).
We want to move functionality from the LLVM ORCTargetProcess library into the
ORC runtime, and this will mean implementing remote-executor testing tools
(like llvm-jitlink-executor and lli-child-target) in the ORC runtime.

This patch refactors the ORC runtime build system to introduce an
add_orc_tool function that can be used to add new test tools. The code is
modeled on existing functions for adding unit tests.

A placeholder orc-rt-executor tool and test are added to verify that the
config changes behave as expected.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D133084
2022-09-02 20:59:57 -07:00
Lang Hames
6ca9f42189 [ORC][ORC-RT] Consistently use pointed-to type as template arg to wrap/unwrap.
Saves wrap/unwrap implementers from having to use std::remove_pointer_t to get
at the pointed-to type.
2022-09-01 20:54:24 -07:00