summaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
AgeCommit message (Collapse)Author
2025-06-26[ORC] Extract MemoryAccess from ExecutorProcessControl, break up header. ↵Lang Hames
(#145671) This moves the MemoryAccess interface out of the ExecutorProcessControl class and splits implementation classes InProcessMemoryManager and SelfExecutorProcessControl out of ExecutorProcessControl.h and into their own headers.
2025-06-25[ORC] Sink DynamicLibrary.h header include into ExecutorProcessControl.cpp.Lang Hames
This include is only used for implementation, so shouldn't be in the public header.
2025-02-12[ORC] Switch to singleton pattern for UnwindInfoManager. (#126691)Lang Hames
The find-dynamic-unwind-info callback registration APIs in libunwind limit the number of callbacks that can be registered. If we use multiple UnwindInfoManager instances, each with their own own callback function (as was the case prior to this patch) we can quickly exceed this limit (see https://github.com/llvm/llvm-project/issues/126611). This patch updates the UnwindInfoManager class to use a singleton pattern, with the single instance shared between all LLVM JITs in the process. This change does _not_ apply to compact unwind info registered through the ORC runtime (which currently installs its own callbacks). As a bonus this change eliminates the need to load an IR "bouncer" module to supply the unique callback for each instance, so support for compact-unwind can be extended to the llvm-jitlink tools (which does not support adding IR).
2025-02-07[ORC] Force eh-frame use for older Darwins on x86-64 in MachOPlatform, LLJIT.Lang Hames
The system libunwind on older Darwins does not support JIT registration of compact-unwind. Since the CompactUnwindManager utility discards redundant eh-frame FDEs by default we need to remove the compact-unwind section first when targeting older libunwinds in order to preserve eh-frames. While LLJIT was already doing this as of eae6d6d18bd, MachOPlatform was not. This was causing buildbot failures in the ORC runtime (e.g. in https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/3479/). This patch updates both LLJIT and MachOPlatform to check a bootstrap value, "darwin-use-ehframes-only", to determine whether to forcibly preserve eh-frame sections. If this value is present and set to true then compact-unwind sections will be discarded, causing eh-frames to be preserved. If the value is absent or set to false then compact-unwind will be used and redundant FDEs in eh-frames discarded (FDEs that are needed by the compact-unwind section are always preserved). rdar://143895614
2025-02-07[ORC] Add a FIXME. NFC.Lang Hames
2025-02-05Re-reapply "[ORC] Enable JIT support for the compact-unwind..." with fixes.Lang Hames
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-01-30Revert "Reapply "[ORC] Enable JIT support for the compact-unwind frame..." ↵Ben Langmuir
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-30Reapply "[ORC] Enable JIT support for the compact-unwind frame..." with fixes.Lang Hames
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-24Revert "[ORC] Enable JIT support for the compact-unwind frame info format..."Lang Hames
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-23[ORC] Enable JIT support for the compact-unwind frame info format on Darwin.Lang Hames
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.
2024-11-19[ExecutionEngine] Remove unused includes (NFC) (#116749)Kazu Hirata
Identified with misc-include-cleaner.
2024-10-23[ORC] Move EPC load-dylib and lookup operations into their own class.Lang Hames
This keeps common operations together, and should make it easier to write re-usable dylib managers in the future (e.g. a DylibManager that uses the EPC's remote-execution APIs to implement load and lookup).
2024-04-23Re-apply "[ORC] Unify task dispatch across ExecutionSession..." with more fixes.Lang Hames
This re-applies 6094b3b7db7, which was reverted in e7efd37c229 (and before that in 1effa19de24) due to bot failures. The test failures were fixed by having SelfExecutorProcessControl use an InPlaceTaskDispatcher by default, rather than a DynamicThreadPoolTaskDispatcher. This shouldn't be necessary (and indicates a concurrency issue elsewhere), but InPlaceTaskDispatcher is a less surprising default, and better matches the existing behavior (compilation on current thread by default), so the change seems reasonable. I've filed https://github.com/llvm/llvm-project/issues/89870 to investigate the concurrency issue as a follow-up. Coding my way home: 6.25133S 127.94177W
2024-04-22Revert "Re-apply [ORC] Unify task dispatch across ExecutionSession and..."Lang Hames
This reverts commit 1effa19de24 while I investigate the test failure at https://lab.llvm.org/buildbot/#/builders/285/builds/888.
2024-04-22Re-apply "[ORC] Unify task dispatch across ExecutionSession and..." with fix.Lang Hames
This re-applies 6094b3b7db7, which was reverted in a28557aadd8 due to broken bots. As far as I can tell all failures were due to a missing #include <deque>, which has been adedd in this commit.
2024-04-22Revert "[ORC] Unify task dispatch across ExecutionSession and ↵Mehdi Amini
ExecutorProcessControl." This reverts commit 6094b3b7db7eab8318b9d30dec2691d231c7bdff. Multiple bots are broken.
2024-04-22[ORC] Unify task dispatch across ExecutionSession and ExecutorProcessControl.Lang Hames
Updates ExecutionSession to use the ExecutorProcessControl object's TaskDispatcher rather than having a separate dispatch function. This gives the TaskDispatcher a global view of all tasks to be executed, and provides a single point to wait on for tasks to complete when shutting down the JIT.
2024-02-12[ORC] Make EPCDynamicLibrarySearchGenerator asyncBen Langmuir
Switch the primary implementation of EPC lookupSymbols to be async, keeping a synchronous wrapper for compatibility. Use the new async implementation inside EPCDynamicLibrarySearchGenerator to work working towards a fully async search generator. Provide an asynchronous lookup API for EPCGenericDylibManager and adopt that from the SimpleRemoteEPC. This enables an end-to-end async EPCDynamicLibrarySearchGenerator. Note: currently we keep the current per-dlhandle lookup model, but a future improvement could do a single async call for a given lookup operation.
2024-01-04[ORC] Refactor executor symbol lookup to use ExecutorSymbolDef (NFC) (#76989)Ben Langmuir
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.
2023-09-20[ORC] Add writePointers to ExecutorProcessControl's MemoryAccessSunho Kim
Add pointer write functionality to MemoryAccess that is needed for implementing redirection manager. It also refactors the code a bit by introducing InProcessMemoryAccess class. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D157378
2023-08-23[ORC] Use EPC bootstrap symbols to communicate eh-frame registration fn addrs.Lang Hames
By using bootstrap symbols to communicate these addresseses, rather than dlsym lookups, we no longer need them to be exported from the main executable. On ELF, where symbols aren't exported from the main executable by default, this eliminates a common source of missing symbol errors and allows for smaller executables (if exports from the main executable aren't otherwise needed and can be removed).
2023-03-27[ORC] Move most ORC APIs to ExecutorAddr, introduce ExecutorSymbolDef.Lang Hames
ExecutorAddr was introduced in b8e5f918166 as an eventual replacement for JITTargetAddress. ExecutorSymbolDef is introduced in this patch as a replacement for JITEvaluatedSymbol: ExecutorSymbolDef is an (ExecutorAddr, JITSymbolFlags) pair, where JITEvaluatedSymbol was a (JITTargetAddress, JITSymbolFlags) pair. A number of APIs had already migrated from JITTargetAddress to ExecutorAddr, but many of ORC's internals were still using the older type. This patch aims to address that. Some public APIs are affected as well. If you need to migrate your APIs you can use the following operations: * ExecutorAddr::toPtr replaces jitTargetAddressToPointer and jitTargetAddressToFunction. * ExecutorAddr::fromPtr replace pointerToJITTargetAddress. * ExecutorAddr(JITTargetAddress) creates an ExecutorAddr value from a JITTargetAddress. * ExecutorAddr::getValue() creates a JITTargetAddress value from an ExecutorAddr. JITTargetAddress and JITEvaluatedSymbol will remain in JITSymbol.h for now, but the aim will be to eventually deprecate and remove these types (probably when MCJIT and RuntimeDyld are deprecated).
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2022-10-25[ORC] Update SelfExecutorProcessControl to allow user-supplied handles.Lang Hames
SelfExecutorProcessControl no longer requires that handles passed to lookupSymbols be ones that were previously returned from loadDylib. This brings SelfExecutorPRocessControl into alignment with SimpleRemoteEPC, which was updated in 6613f4aff85.
2022-10-24[ORC] Use raw OS handle values, ExecutorAddr for EPC dylib handles.Lang Hames
Updates tpctypes::DylibHandle to be an ExecutorAddr (rather than a uint64_t), and SimpleExecutorDylibManager to hold and return raw OS handle values (as ExecutorAddrs) rather than index values into a map of DynamicLibrary instances. This will allow clients to use EPCGenericDylibManager in contexts where the existing DynamicLibrary interface is too limited to be used. (e.g. to look up JIT symbols in a dylib that was loaded with RTLD_LOCAL).
2022-08-11[ORC][COFF] Introduce COFFVCRuntimeBootstrapper.Sunho Kim
Introduces COFFVCRuntimeBootstrapper that loads/initialize vc runtime libraries. In COFF, we *must* jit-link vc runtime libraries as COFF relocation types have no proper way to deal with out-of-reach data symbols ragardless of linking mode. (even dynamic version msvcrt.lib have tons of static data symbols that must be jit-linked) This class tries to load vc runtime library files from msvc installations with an option to override the path. There are some complications when dealing with static version of vc runtimes. First, they need static initializers to be ran that requires COFFPlatform support but orc runtime will not be usable before vc runtimes are fully initialized. (as orc runtime will use msvc stl libraries) COFFPlatform that will be introduced in a following up patch will collect static initializers and run them manually in host before boostrapping itself. So, the user will have to do the following. 1. Create COFFPlatform that addes static initializer collecting passes. 2. LoadVCRuntime 3. InitializeVCRuntime 4. COFFPlatform.bootstrap() Second, the internal crt initialization function had to be reimplemented in orc side. There are other ways of doing this, but this is the simplest implementation that makes platform fully responsible for static initializer. The complication comes from the fact that crt initialization functions (such as acrt_initialize or dllmain_crt_process_attach) actually run all static initializers by traversing from `__xi_a` symbol to `__xi_z`. This requires symbols to be contiguously allocated in sections alphabetically sorted in memory, which is not possible right now and not practical in jit setting. We might ignore emission of `__xi_a` and `__xi_z` symbol and allocate them ourselves, but we have to take extra care after orc runtime boostrap has been done -- as that point orc runtime should be the one running the static initializers. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D130456
2022-02-06[llvm] Use = default (NFC)Kazu Hirata
2021-10-30[ORC] Move CWrapperFunctionResult out of the detail:: namespace.Lang Hames
This type has been moved up into the llvm::orc::shared namespace. This type was originally put in the detail:: namespace on the assumption that few (if any) LLVM source files would need to use it. In practice it has been needed in many places, and will continue to be needed until/unless OrcTargetProcess is fully merged into the ORC runtime.
2021-10-28Reapply e32b1eee6aa "[ORC] Change SPSExecutorAddr serialization,..." with fixes.Lang Hames
This re-applies e32b1eee6aab52e2b7b75ee15e506b3e7dd30e68, which was reverted in 20675d8f7dab293172266fdde426c2173b5b3997 due to broken unit tests. This patch includes fixes for the tests.
2021-10-27Revert "[ORC] Change SPSExecutorAddr serialization, SupportFunctionCall struct."Lang Hames
This reverts commit e32b1eee6aab52e2b7b75ee15e506b3e7dd30e68. Reverting while I fix some broken unit tests.
2021-10-27[ORC] Change SPSExecutorAddr serialization, SupportFunctionCall struct.Lang Hames
SPSExecutorAddr will now be serializable to/from ExecutorAddr, rather than uint64_t. This improves type safety when working with serialized addresses. Also updates the SupportFunctionCall to use an ExecutorAddrRange (rather than a separate ExecutorAddr addr and uint64_t size field), and updates the tpctypes::*Write data structures to use ExecutorAddr rather than JITTargetAddress.
2021-10-12[ORC] Shut down dispatcher in ExecutorProcessControl implementations.Lang Hames
f3411616896 added a task dispatcher for async handlers, but didn't add a TaskDispatcher::shutdown call to SelfExecutorProcessControl or SimpleRemoteEPC. This patch adds the missing call, which ensures that we don't destroy the dispatcher while tasks are still running. This should fix the use-after-free crash seen in https://lab.llvm.org/buildbot/#/builders/5/builds/13063
2021-10-11Re-apply e50aea58d59, "Major JITLinkMemoryManager refactor". with fixes.Lang Hames
Adds explicit narrowing casts to JITLinkMemoryManager.cpp. Honors -slab-address option in llvm-jitlink.cpp, which was accidentally dropped in the refactor. This effectively reverts commit 6641d29b70993bce6dbd7e0e0f1040753d38842f.
2021-10-11Revert "[JITLink][ORC] Major JITLinkMemoryManager refactor."Lang Hames
This reverts commit e50aea58d59c8cfae807a7fee21c4227472c0678 while I investigate bot failures.
2021-10-11[JITLink][ORC] Major JITLinkMemoryManager refactor.Lang Hames
This commit substantially refactors the JITLinkMemoryManager API to: (1) add asynchronous versions of key operations, (2) give memory manager implementations full control over link graph address layout, (3) enable more efficient tracking of allocated memory, and (4) support "allocation actions" and finalize-lifetime memory. Together these changes provide a more usable API, and enable more powerful and efficient memory manager implementations. To support these changes the JITLinkMemoryManager::Allocation inner class has been split into two new classes: InFlightAllocation, and FinalizedAllocation. The allocate method returns an InFlightAllocation that tracks memory (both working and executor memory) prior to finalization. The finalize method returns a FinalizedAllocation object, and the InFlightAllocation is discarded. Breaking Allocation into InFlightAllocation and FinalizedAllocation allows InFlightAllocation subclassses to be written more naturally, and FinalizedAlloc to be implemented and used efficiently (see (3) below). In addition to the memory manager changes this commit also introduces a new MemProt type to represent memory protections (MemProt replaces use of sys::Memory::ProtectionFlags in JITLink), and a new MemDeallocPolicy type that can be used to indicate when a section should be deallocated (see (4) below). Plugin/pass writers who were using sys::Memory::ProtectionFlags will have to switch to MemProt -- this should be straightworward. Clients with out-of-tree memory managers will need to update their implementations. Clients using in-tree memory managers should mostly be able to ignore it. Major features: (1) More asynchrony: The allocate and deallocate methods are now asynchronous by default, with synchronous convenience wrappers supplied. The asynchronous versions allow clients (including JITLink) to request and deallocate memory without blocking. (2) Improved control over graph address layout: Instead of a SegmentRequestMap, JITLinkMemoryManager::allocate now takes a reference to the LinkGraph to be allocated. The memory manager is responsible for calculating the memory requirements for the graph, and laying out the graph (setting working and executor memory addresses) within the allocated memory. This gives memory managers full control over JIT'd memory layout. For clients that don't need or want this degree of control the new "BasicLayout" utility can be used to get a segment-based view of the graph, similar to the one provided by SegmentRequestMap. Once segment addresses are assigned the BasicLayout::apply method can be used to automatically lay out the graph. (3) Efficient tracking of allocated memory. The FinalizedAlloc type is a wrapper for an ExecutorAddr and requires only 64-bits to store in the controller. The meaning of the address held by the FinalizedAlloc is left up to the memory manager implementation, but the FinalizedAlloc type enforces a requirement that deallocate be called on any non-default values prior to destruction. The deallocate method takes a vector<FinalizedAlloc>, allowing for bulk deallocation of many allocations in a single call. Memory manager implementations will typically store the address of some allocation metadata in the executor in the FinalizedAlloc, as holding this metadata in the executor is often cheaper and may allow for clean deallocation even in failure cases where the connection with the controller is lost. (4) Support for "allocation actions" and finalize-lifetime memory. Allocation actions are pairs (finalize_act, deallocate_act) of JITTargetAddress triples (fn, arg_buffer_addr, arg_buffer_size), that can be attached to a finalize request. At finalization time, after memory protections have been applied, each of the "finalize_act" elements will be called in order (skipping any elements whose fn value is zero) as ((char*(*)(const char *, size_t))fn)((const char *)arg_buffer_addr, (size_t)arg_buffer_size); At deallocation time the deallocate elements will be run in reverse order (again skipping any elements where fn is zero). The returned char * should be null to indicate success, or a non-null heap-allocated string error message to indicate failure. These actions allow finalization and deallocation to be extended to include operations like registering and deregistering eh-frames, TLS sections, initializer and deinitializers, and language metadata sections. Previously these operations required separate callWrapper invocations. Compared to callWrapper invocations, actions require no extra IPC/RPC, reducing costs and eliminating a potential source of errors. Finalize lifetime memory can be used to support finalize actions: Sections with finalize lifetime should be destroyed by memory managers immediately after finalization actions have been run. Finalize memory can be used to support finalize actions (e.g. with extra-metadata, or synthesized finalize actions) without incurring permanent memory overhead.
2021-10-10[ORC] Add optional RunPolicy to ExecutorProcessControl::callWrapperAsync.Lang Hames
The callWrapperAsync and callSPSWrapperAsync methods take a handler object that is run on the return value of the call when it is ready. The new RunPolicy parameters allow clients to control how these handlers are run. If no policy is specified then the handler will be packaged as a GenericNamedTask and dispatched using the ExecutorProcessControl's TaskDispatch member. Callers can use the ExecutorProcessControl::RunInPlace policy to cause the handler to be run directly instead, which may be preferrable for simple handlers, or they can write their own policy object (e.g. to dispatch as some other kind of Task, rather than GenericNamedTask).
2021-10-10[ORC] Add TaskDispatch API and thread it through ExecutorProcessControl.Lang Hames
ExecutorProcessControl objects will now have a TaskDispatcher member which should be used to dispatch work (in particular, handling incoming packets in the implementation of remote EPC implementations like SimpleRemoteEPC). The GenericNamedTask template can be used to wrap function objects that are callable as 'void()' (along with an optional name to describe the task). The makeGenericNamedTask functions can be used to create GenericNamedTask instances without having to name the function object type. In a future patch ExecutionSession will be updated to use the ExecutorProcessControl's dispatcher, instead of its DispatchTaskFunction.
2021-10-10[ORC] Reorder callWrapperAsync and callSPSWrapperAsync parameters.Lang Hames
The callee address is now the first parameter and the 'SendResult' function the second. This change improves consistentency with the non-async functions where the callee is the first address and the return value the second.
2021-09-27[ORC] Switch from JITTargetAddress to ExecutorAddr for EPC-call APIs.Lang Hames
Part of the ongoing move to ExecutorAddr.
2021-09-27[ORC] Hold shared_ptr<SymbolStringPool> in errors containing SymbolStringPtrs.Lang Hames
This allows these error values to remain valid, even if they tear down the JIT itself.
2021-09-23[ORC] Rename ExecutorAddress to ExecutorAddr.Lang Hames
Removing the 'ess' suffix improves the ergonomics without sacrificing clarity. Since this class is likely to be used more frequently in the future it's worth some short term pain to fix this now.
2021-08-20[ORC] Add 'Async' suffix to ExecutorProcessControl::MemoryAccess methods.Lang Hames
This prevents the async methods (which shoud be overridden by subclasses) from hiding the blocking helper methods, avoiding a lot of 'using MemoryAccess::...' boilerplate.
2021-07-27[ORC] Require ExecutorProcessControl when constructing an ExecutionSession.Lang Hames
Wrapper function call and dispatch handler helpers are moved to ExecutionSession, and existing EPC-based tools are re-written to take an ExecutionSession argument instead. Requiring an ExecutorProcessControl instance simplifies existing EPC based utilities (which only need to take an ES now), and should encourage more utilities to use the EPC interface. It also simplifies process termination, since the session can automatically call ExecutorProcessControl::disconnect (previously this had to be done manually, and carefully ordered with the rest of JIT tear-down to work correctly).
2021-07-19[ORC][ORC-RT] Introduce ORC-runtime based MachO-Platform.Lang Hames
Adds support for MachO static initializers/deinitializers and eh-frame registration via the ORC runtime. This commit introduces cooperative support code into the ORC runtime and ORC LLVM libraries (especially the MachOPlatform class) to support macho runtime features for JIT'd code. This commit introduces support for static initializers, static destructors (via cxa_atexit interposition), and eh-frame registration. Near-future commits will add support for MachO native thread-local variables, and language runtime registration (e.g. for Objective-C and Swift). The llvm-jitlink tool is updated to use the ORC runtime where available, and regression tests for the new MachOPlatform support are added to compiler-rt. Notable changes on the ORC runtime side: 1. The new macho_platform.h / macho_platform.cpp files contain the bulk of the runtime-side support. This includes eh-frame registration; jit versions of dlopen, dlsym, and dlclose; a cxa_atexit interpose to record static destructors, and an '__orc_rt_macho_run_program' function that defines running a JIT'd MachO program in terms of the jit- dlopen/dlsym/dlclose functions. 2. Replaces JITTargetAddress (and casting operations) with ExecutorAddress (copied from LLVM) to improve type-safety of address management. 3. Adds serialization support for ExecutorAddress and unordered_map types to the runtime-side Simple Packed Serialization code. 4. Adds orc-runtime regression tests to ensure that static initializers and cxa-atexit interposes work as expected. Notable changes on the LLVM side: 1. The MachOPlatform class is updated to: 1.1. Load the ORC runtime into the ExecutionSession. 1.2. Set up standard aliases for macho-specific runtime functions. E.g. ___cxa_atexit -> ___orc_rt_macho_cxa_atexit. 1.3. Install the MachOPlatformPlugin to scrape LinkGraphs for information needed to support MachO features (e.g. eh-frames, mod-inits), and communicate this information to the runtime. 1.4. Provide entry-points that the runtime can call to request initializers, perform symbol lookup, and request deinitialiers (the latter is implemented as an empty placeholder as macho object deinits are rarely used). 1.5. Create a MachO header object for each JITDylib (defining the __mh_header and __dso_handle symbols). 2. The llvm-jitlink tool (and llvm-jitlink-executor) are updated to use the runtime when available. 3. A `lookupInitSymbolsAsync` method is added to the Platform base class. This can be used to issue an async lookup for initializer symbols. The existing `lookupInitSymbols` method is retained (the GenericIRPlatform code is still using it), but is deprecated and will be removed soon. 4. JIT-dispatch support code is added to ExecutorProcessControl. The JIT-dispatch system allows handlers in the JIT process to be associated with 'tag' symbols in the executor, and allows the executor to make remote procedure calls back to the JIT process (via __orc_rt_jit_dispatch) using those tags. The primary use case is ORC runtime code that needs to call bakc to handlers in orc::Platform subclasses. E.g. __orc_rt_macho_jit_dlopen calling back to MachOPlatform::rt_getInitializers using __orc_rt_macho_get_initializers_tag. (The system is generic however, and could be used by non-runtime code). The new ExecutorProcessControl::JITDispatchInfo struct provides the address (in the executor) of the jit-dispatch function and a jit-dispatch context object, and implementations of the dispatch function are added to SelfExecutorProcessControl and OrcRPCExecutorProcessControl. 5. OrcRPCTPCServer is updated to support JIT-dispatch calls over ORC-RPC. 6. Serialization support for StringMap is added to the LLVM-side Simple Packed Serialization code. 7. A JITLink::allocateBuffer operation is introduced to allocate writable memory attached to the graph. This is used by the MachO header synthesis code, and will be generically useful for other clients who want to create new graph content from scratch.
2021-07-01[ORC] Add wrapper-function support methods to ExecutorProcessControl.Lang Hames
Adds support for both synchronous and asynchronous calls to wrapper functions using SPS (Simple Packed Serialization). Also adds support for wrapping functions on the JIT side in SPS-based wrappers that can be called from the executor. These new methods simplify calls between the JIT and Executor, and will be used in upcoming ORC runtime patches to enable communication between ORC and the runtime.
2021-07-01[ORC] Rename TargetProcessControl to ExecutorProcessControl. NFC.Lang Hames
This is a first step towards consistently using the term 'executor' for the process that executes JIT'd code. I've opted for 'executor' as the preferred term over 'target' as target is already heavily overloaded ("the target machine for the executor" is much clearer than "the target machine for the target").