189 Commits

Author SHA1 Message Date
Victor Vianna
90a202f2ff
[cpp23] Remove usage of std::aligned_union<> in llvm (#135146)
std::aligned_union<> is deprecated in C++23. See more details in the
linked bug.

Bug: https://crbug.com/388068052
2025-04-11 16:16:33 -04:00
Lang Hames
ef3e521a2b [ORC-RT] Add unique_function utility to the ORC runtime.
A bare-bones version of LLVM's unique_function: this behaves like a
std::unique_function, except that it supports move only callable types.

This will be used in upcoming improvements to the ORC runtime.
2025-03-24 15:46:43 +11:00
Lang Hames
5d8e8e82e1 [ORC-RT] Rename extensible_rtti.{h,cpp} to rtti.{h,cpp}. NFCI.
The "extensible_" prefix on these files was inherited from LLVM, where it
distinguished the dynamic RTTI APIs from the LLVM's custom static RTTI APIs.

In the ORC runtime these files will be used to hold all of our RTTI APIs
(the current dynamic ones, and any static ones added in the future), so we
shouldn't use this prefix.
2025-03-24 13:49:23 +11:00
Lang Hames
36b1fb5c7a [ORC-RT] Fix typos in file comments. NFC. 2025-03-24 13:49:23 +11:00
Lang Hames
2c8b2dc3f4 [ORC-RT] Rename 'orc_rt_*CWrapper*' types and functions to 'orc_rt_*Wrapper*'.
The orc_rt_ prefix implies C API anyway (the C++ API should use the orc_rc::
namespace), so the 'C' is redundant here.
2025-03-07 14:31:42 +11:00
Lang Hames
eae6d6d18b Re-reapply "[ORC] Enable JIT support for the compact-unwind..." with fixes.
Re-enables compact-unwind support in JITLink, which was reverted in b04847b427d
due to buildbot failures.

The underlying cause for the failures on the buildbots was the lack of
compact-unwind registration support on older Darwin OSes. Since the
CompactUnwindManager pass now removes eh-frames by default we were left with
unwind-info that could not be registered. On x86-64, where eh-frame info is
produced by default the solution is to fall back to using eh-frames. On arm64
we simply can't support exceptions on older OSes.

This patch updates the EHFrameRegistrationPlugin to remove the compact-unwind
section (__LD,__compact_unwind) when installed, forcing use of eh-frames when
the EHFrameRegistrationPlugin is used. In LLJIT, the EHFrameRegistrationPlugin
continues to be used for all non-Darwin platform, and will be added on Darwin
platforms when the a CompactUnwindRegistrationPlugin instance can't be created
(e.g. due to missing support for compact-unwind info registration).

The lit.cfg.py script is updated to check whether the host OSes default unwind
info supports JIT registration, allowing tests to be disabled for older Darwin
OSes on arm64.
2025-02-05 19:40:30 +11:00
Ben Langmuir
b04847b427
Revert "Reapply "[ORC] Enable JIT support for the compact-unwind frame..." with fixes." (#125098)
This reverts commit d6524c8dfa37634257050ca71d16e117b802181c. This
reverts commit b1bd73700a1fb6f450e0f6f9c405a9c8bde2cae7.

This was causing bot failures on Darwin


https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-cmake-RA-incremental/7315/
  Clang.Interpreter.simple-exception.cpp

Clang-Unit.Interpreter/ExceptionTests/_/ClangReplInterpreterExceptionTests/0.1
  LLVM.ExecutionEngine/OrcLazy.minimal-throw-catch.ll

https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/3415/
  ORC-x86_64-darwin.TestCases/Darwin/Generic.exceptions.cpp
  ORC-x86_64-darwin.TestCases/Darwin/x86-64.lljit-ehframe.cpp
2025-01-30 11:27:43 -08:00
Lang Hames
d6524c8dfa Reapply "[ORC] Enable JIT support for the compact-unwind frame..." with fixes.
This reapplies 4f0325873fa (and follow up patches 26fc07d5d88, a001cc0e6cdc,
c9bc242e387, and fd174f0ff3e), which were reverted in 212cdc9a377 to
investigate bot failures (e.g.
https://lab.llvm.org/buildbot/#/builders/108/builds/8502)

The fix to address the bot failures was landed in d0052ebbe2e. This patch also
restricts construction of the UnwindInfoManager object to Apple platforms (as
it won't be used on other platforms).
2025-01-30 13:42:10 +11:00
Lang Hames
212cdc9a37 Revert "[ORC] Enable JIT support for the compact-unwind frame info format..."
This reverts 4f0325873faccfbe171bae4babceb65975ca892e and follow-up patches
(see below) while I investigate some ongoing failures on the buildbots.

---

Revert "[clang-repl] Try to XFAIL testcase on arm32 without affecting arm64
darwin."

This reverts commit fd174f0ff3e793fe96a6663b1488ed159cfe042f.

Revert "[clang-repl] The simple-exception test now passes on arm64-darwin."

This reverts commit c9bc242e387f4a4a3dfcd86561f3ec0ca8a72d62.

Revert "[ORC] Destroy defunct MaterializationUnits outside the session lock."

This reverts commit a001cc0e6cdcfa672b8aff9ce6d14782bb96356a.

Revert "[ORC] Add explicit narrowing casts to fix build errors."

This reverts commit 26fc07d5d88760ad659599184fd10181287d2d9e.

Revert "[ORC] Enable JIT support for the compact-unwind frame info format on
Darwin."

This reverts commit 4f0325873faccfbe171bae4babceb65975ca892e.
2025-01-24 17:32:12 +11:00
Lang Hames
4f0325873f [ORC] Enable JIT support for the compact-unwind frame info format on Darwin.
For Darwin/arm64 (including Apple Silicon Macs) this will enable exception
handling and stack unwinding in JIT'd code.

Darwin supports two unwind-info formats: DWARF eh-frames and compact-unwind. On
Darwin/x86-64 compilers usually produce both by default, and ORC supported
exceptions and unwinding via eh-frames (same as on Linux), discarding the
redundant compact-unwind info. On Darwin/arm64 compilers typically default to
producing compact-unwind only, with DWARF eh-frames as a fallback for functions
that can't be described in compact-unwind. Since ORC did not previously support
the compact-unwind format and eh-frames were not present ORC was unable to
handle exceptions or unwinding by default in Darwin/arm64 JIT'd code.

This patch enables support for the compact-unwind-info format, and contains
three major moving parts:

(1) The JITLink CompactUnwindManager class is responsible for transforming the
    __compact_unwind records produced by the linker into the __unwind_info
    tables that libunwind parses during unwinding. To enable this the
    CompactUnwindManager class provides three JITLink passes: The
    prepareForPrune pass that splits the __compact_unwind section into
    single-record blocks, allowing unused records to be dead-stripped; the
    processAndReserveUnwindInfo pass that reserves space for the final
    __unwind_info section, and the writeUnwindInfo pass that writes the
    __unwind_info section.

(2) The OrcTargetProcess UnwindInfoManager class maintains a table of
    registered JIT'd __unwind_info and __eh_frame sections, and handles
    requests from libunwind for unwind info sections (by registering a callback
    with libunwind's __unw_add_find_dynamic_unwind_sections function).

(3) The Orc UnwindInfoRegistrationPlugin, which scans LinkGraphs for
    __unwind_info and __eh_frame sections to register with the
    UnwindInfoManager.

This commit adds the CompactUnwindManager passes to the default JITLink
pipelines for Darwin/arm64 and Darwin/x86-64, and UnwindInfoManager intances to
the SelfExecutorProcessControl class (when built for apple platforms) and the
llvm-jitlink-executor tool.

The LLJIT class will now create an UnwindInfoRegistrationPlugin when targeting
a process running on Darwin if it detects that an UnwindInfoManager is
available to handle the registrations.

The ORC runtime macho_platform class already supported libunwind callbacks, so
out-of-process execution and unwinding support will work when loading the ORC
runtime.

The llvm-jitlink tool will only support compact-unwind when the orc-runtime is
loaded, as the UnwindInfoRegistrationPlugin requires access to an IR compiler
to load a helper module and llvm-jitlink does not provide an IR compiler.
2025-01-23 22:55:01 +00:00
Lang Hames
8daf4f16fa [ORC][ORC-RT] Add ORC-RT based lazy compilation support for x86-64.
Adds support for the ORC-RT based lazy compilation scheme that was introduced
in 570ecdcf8b4.
2024-12-15 23:50:31 +00:00
Lang Hames
ae89be0797 [ORC-RT] Fix comments. NFC.
Fix file name, symbol name, and formatting in comments.
2024-12-13 06:26:19 +00:00
Lang Hames
f2d18a4d00 Reapply "[ORC] Introduce LazyReexportsManager, ... (#118923)" with fixes.
This re-applies 570ecdcf8b4, which was reverted in 74e8a37ff32 due to bot
failures. This commit renames sysv_resolve.cpp to resolve.cpp, which was the
cause of the config errors.
2024-12-09 03:22:51 +00:00
Lang Hames
f6c51ea84a [ORC-RT] Fix unit tests on Linux.
The unit tests may transiently depend on __orc_rt_log_error, which is usually
provided by an alias when loading the runtime through the JIT. The unit tests
statically link the runtime, so this patch provides a fixed definition.
2024-12-09 13:41:24 +11:00
Lang Hames
74e8a37ff3 Revert "Reapply "[ORC] Introduce LazyReexportsManager, … (#118923)" with fixes"
This reverts commit 41652c6c92958a87b8505b9b1e6f008856e392ac while I investigate
more bot failures.
2024-12-09 12:38:59 +11:00
Lang Hames
41652c6c92 Reapply "[ORC] Introduce LazyReexportsManager, … (#118923)" with fixes
This reapplies 570ecdcf8b4, which was reverted in 6073dd923b8 due to bot
failures.

The test failures on Linux were fixed by:
1. Removing an overly restrictive assertion (query dependence on a symbol no
longer implies a MaterializingInfo for that symbol)
2. Adding reentry and resolver files to the ORC runtime CMakeLists.txt for
Linux.
3. Adding the __orc_rt_reentry -> __orc_rt_sysv_reentry alias to ELFNixPlatform.
2024-12-09 12:08:07 +11:00
Lang Hames
6073dd923b Revert "[ORC] Introduce LazyReexportsManager, JITLinkTrampolines, … (#118923)"
This reverts commit 570ecdcf8b44aec853ce381a5f6b77222b041afa while I investigate
bot failures, e.g. https://lab.llvm.org/buildbot/#/builders/17/builds/4446.
2024-12-07 22:15:27 +11:00
Lang Hames
570ecdcf8b
[ORC] Introduce LazyReexportsManager, JITLinkTrampolines, ORC-RT base… (#118923)
…d reentry.

These utilities provide new, more generic and easier to use support for
lazy compilation in ORC.

LazyReexportsManager is an alternative to LazyCallThroughManager. It
takes requests for lazy re-entry points in the form of an alias map:
lazy-reexports = {
  ( <entry point symbol #1>, <implementation symbol #1> ),
  ( <entry point symbol #2>, <implementation symbol #2> ),
  ...
  ( <entry point symbol #n>, <implementation symbol #n> )
}

LazyReexportsManager then:
1. binds the entry points to the implementation names in an internal
table.
2. creates a JIT re-entry trampoline for each entry point.
3. creates a redirectable symbol for each of the entry point name and
binds redirectable symbol to the corresponding reentry trampoline.

When an entry point symbol is first called at runtime (which may be on
any thread of the JIT'd program) it will re-enter the JIT via the
trampoline and trigger a lookup for the implementation symbol stored in
LazyReexportsManager's internal table. When the lookup completes the
entry point symbol will be updated (via the RedirectableSymbolManager)
to point at the implementation symbol, and execution will proceed to the
implementation symbol.

Actual construction of the re-entry trampolines and redirectable symbols
is delegated to an EmitTrampolines functor and the
RedirectableSymbolsManager respectively.

JITLinkReentryTrampolines.h provides a JITLink-based implementation of
the EmitTrampolines functor. (AArch64 only in this patch, but other
architectures will be added in the near future).

Register state save and reentry functionality is added to the ORC
runtime in the __orc_rt_sysv_resolve and __orc_rt_resolve_implementation
functions (the latter is generic, the former will need custom
implementations for each ABI and architecture to be supported, however
this should be much less effort than the existing OrcABISupport
approach, since the ORC runtime allows this code to be written as native
assembly).

The resulting system:
1. Works equally well for in-process and out-of-process JIT'd code.
2. Requires less boilerplate to set up.

Given an ObjectLinkingLayer and PlatformJD (JITDylib containing the ORC
runtime), setup is just:

```c++
auto RSMgr = JITLinkRedirectableSymbolManager::Create(OLL);
if (!RSMgr)
  return RSMgr.takeError();

auto LRMgr = createJITLinkLazyReexportsManager(OLL, **RSMgr, PlatformJD);
if (!LRMgr)
  return LRMgr.takeError();
```

after which lazy reexports can be introduced with:

```c++
JD.define(lazyReexports(LRMgr, <alias map>));
```

LazyObectLinkingLayer is updated to use this new method, but the LLVM-IR
level CompileOnDemandLayer will continue to use LazyCallThroughManager
and OrcABISupport until the new system supports a wider range of
architectures and ABIs.

The llvm-jitlink utility's -lazy option now uses the new scheme. Since
it depends on the ORC runtime, the lazy-link.ll testcase and associated
helpers are moved to the ORC runtime.
2024-12-07 21:08:39 +11:00
SahilPatidar
f363f9d61e
[ORC][Runtime] Add dlupdate for elf (#110406)
With the help of @lhames, This pull request introduces the dlupdate
function in the ORC runtime. dlupdate enables incremental execution of
new initializers introduced in the REPL environment. Unlike traditional
dlopen, which manages initializers, code mapping, and library reference
counts, dlupdate focuses exclusively on running new initializers.
2024-11-06 21:26:00 +11:00
SahilPatidar
5f9e6c811b
[Orc][Runtime] Refactor dlupdate to remove the mode argument (#110491) 2024-10-17 09:42:01 +11:00
Sunho Kim
188ede28e0 [ORC] Implement basic reoptimization. 2024-10-12 01:21:05 +09:00
Lang Hames
6292f117c3 [ORC-RT] Rename sections_tracker.h to record_section_tracker.h.
This matches the type name defined in this header.
2024-09-30 13:20:02 +10:00
Kazu Hirata
969abfea48 [compiler-rt] Fix a warning
This patch fixes:

  compiler-rt/lib/orc/elfnix_platform.cpp:48:7: error: unused function
  'validatePointerSectionExtent' [-Werror,-Wunused-function]
2024-09-28 01:28:10 -07:00
SahilPatidar
f597ce03a6
[ORC][Runtime] Enhancing ELF Platform with Push-Request Model for Initializers (#102846)
With the help of @lhames, this PR introduces a push-request model to manage
initializers in the runtime state for each `JITDylib`, similar to how `MachO`
and `COFF` handle it. Previously, the ELF runtime lacked the ability to
register, deregister, or retain initializers, causing issues when re-running
`dlopen`. Initializers were erased after `rt_getInitializers` was used.

To address this, we introduce `__orc_rt_elfnix_register_init_sections` and
`__orc_rt_elfnix_register_jitdylib` (and corresponding deregister functions).
This model allows the runtime to request the push of initializers for the
`JITDylib`, with the platform handling this via a record method. Additionally,
we leverage `MachO`'s `RecordSectionsTracker` to store initializers, ensuring
only newly updated initializers are executed using `processNewSections`,
improving the runtime's efficiency and reliability.
2024-09-28 17:33:19 +10:00
SahilPatidar
68f31aaae9
[ORC][Runtime] Add dlupdate for MachO (#97441)
With the help of @lhames, This pull request introduces the `dlupdate`
function in the ORC runtime. `dlupdate` enables incremental execution of
new initializers introduced in the REPL environment. Unlike traditional
`dlopen`, which manages initializers, code mapping, and library
reference counts, `dlupdate` focuses exclusively on running new
initializers.
2024-09-11 10:50:01 +10:00
Lang Hames
69f8923efa Re-apply "[ORC-RT] Replace FnTag arg of WrapperFunction::call..." with fixes.
This reapplies commits 462251b80b7 and 9b67c99dc5b, which were reverted in
53d35c4e86b due to bot failures for the wrapper_function_utils_test.cpp unit
test.
2024-09-10 19:55:31 +10:00
Mikhail Goncharov
53d35c4e86 Revert "[ORC-RT] Replace FnTag arg of WrapperFunction::call with generic dispatch arg."
This reverts commit 462251b80b7ba51dc6c2ef3676cf50ee92867d34.
This reverts commit 9b67c99dc5b0d669a28b714e10e257d3988d1066.

Build fails for compiler-rt/lib/orc/tests/unit/wrapper_function_utils_test.cpp

https://buildkite.com/llvm-project/upstream-bazel/builds/109731#0191da59-6710-4420-92ef-aa6e0355cb2c
2024-09-10 10:19:27 +02:00
Lang Hames
9b67c99dc5 [ORC-RT] Fix typo in 462251b80b7. 2024-09-10 15:20:06 +10:00
Lang Hames
462251b80b [ORC-RT] Replace FnTag arg of WrapperFunction::call with generic dispatch arg.
This decouples function argument serialization / deserialization from the
function call dispatch mechanism. This will eventually allow us to replace the
existing __orc_rt_jit_dispatch function with a system that supports pre-linking
parts of the ORC runtime into the executor.
2024-09-10 15:11:40 +10:00
Mikhail Goncharov
dbd81ba2e8 complete rename of __orc_rt namespace
for 3e04ad428313dde40c779af6d675b162e150125e

it's bizzare that none of the builbots were broken, only bazel build
https://buildkite.com/llvm-project/upstream-bazel/builds/109623#0191d5d0-2b3e-4ee7-b8dd-1e2580977e9b
2024-09-09 11:49:34 +02:00
Lang Hames
3e04ad4283 [ORC-RT] Remove double underscore from the orc_rt namespace.
We should use `orc_rt` as the public C++ API namespace for the ORC runtime and
control symbol visibility to hide implementation details, rather than rely on
the '__' prefix.
2024-09-09 18:04:28 +10:00
Ben Langmuir
fa089efa6c
[orc][mach-o] Unlock the JITDylib state mutex during +load (#105333)
Similar to what was already done for static initializers, we need to
unlock the state mutext when calling out to libobjc to run +load methods
in case they cause us to reenter the runtime, which was previously
deadlocking. No test for now, because we don't have any code paths in
llvm-jitlink itself that could lead to this deadlock. If we interpose
calls to dlopen to go back to the JIT in the future then calling dlopen
from a +load is the easiest way to reproduce this.

rdar://133430490
2024-08-23 10:32:14 -07:00
Lang Hames
112aa10563 [ORC-RT] Fix typo in comment. 2024-07-08 12:56:38 +10:00
Michael Kruse
a35ac42fac
[compiler-rt] Revise IDE folder structure (#89753)
Update the folder titles for targets in the monorepository that have not
seen taken care of for some time. These are the folders that targets are
organized in Visual Studio and XCode
(`set_property(TARGET <target> PROPERTY FOLDER "<title>")`)
when using the respective CMake's IDE generator.

 * Ensure that every target is in a folder
 * Use a folder hierarchy with each LLVM subproject as a top-level folder
 * Use consistent folder names between subprojects
 * When using target-creating functions from AddLLVM.cmake, automatically
deduce the folder. This reduces the number of
`set_property`/`set_target_property`, but are still necessary when
`add_custom_target`, `add_executable`, `add_library`, etc. are used. A
LLVM_SUBPROJECT_TITLE definition is used for that in each subproject's
root CMakeLists.txt.
2024-06-04 09:26:45 +02:00
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 0d288e5b0ccf217e41944ad4fd8772d8ae45daa1.

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 bb41fc682ee, 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 b2bbe8cc1c7. 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