aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc
AgeCommit message (Collapse)AuthorFilesLines
2025-01-20[ORC] Use BinaryFormat to convert Triple to MachO cputype / cpusubtype values.Lang Hames1-12/+8
2025-01-20[ORC][MachO] Add a TODO comment.Lang Hames1-0/+6
2025-01-15[JITLink] Add convenience methods to LinkGraph to find symbols by name.Lang Hames1-23/+17
Adds new convenience methods findDefinedSymbolByName, findExternalSymbolByName and findAbsoluteSymbolByName to the LinkGraph class. These should be used to find symbols of the given types by name. COFFLinkGraphBuilder and MachOPlatform are updated to take advantage of the new methods.
2025-01-14[JITLink] Use target triple for LinkGraph pointer size and endianness.Lang Hames9-129/+36
Removes LinkGraph's PointerSize and Endianness members and uses the triple to find these values instead. Also removes some redundant Triple copies.
2025-01-10[ORC][MachO] Fix deferred action handling during MachOPlatform bootstrap.Lang Hames1-40/+36
DeferredAAs should only capture bootstrap actions, but after 30b73ed7bd it was capturing all actions, including those from other plugins. This is problematic as other plugins may introduce actions that need to run before the platform actions (e.g. on arm64e we need pointer signing to run before we access any global pointers in the graph). Note that this effectively undoes 30b73ed7bd, which was a buggy attempt to synchronize writes to the DeferredAAs vector. This patch fixes that issue the obvious way by locking the bootstrap mutex while accessing the DeferredAAs vector. No testcase yet: So far I've only seen this fail during bootstrap of arm64e JIT'd programs.
2025-01-10Reapply "[ORC][llvm-jitlink] Add SimpleLazyReexportsSpeculator..." with fixes.Lang Hames3-42/+249
This reapplies 6d72bf47606, which was reverted in 57447d3ddf to investigate build failures, e.g. https://lab.llvm.org/buildbot/#/builders/3/builds/10114. The original patch contained an invalid unused friend declaration of std::make_shared. This has been removed.
2025-01-10Revert "[ORC][llvm-jitlink] Add SimpleLazyReexportsSpeculator, use in ↵Lang Hames3-249/+42
llvm-jitlink." This reverts commit 6d72bf47606c2a288b911d682fd96129c9c1466d while I fix bot failures.
2025-01-10[ORC][llvm-jitlink] Add SimpleLazyReexportsSpeculator, use in llvm-jitlink.Lang Hames3-42/+249
Also adds a new IdleTask type and updates DynamicThreadPoolTaskDispatcher to schedule IdleTasks whenever the total number of threads running is less than the maximum number of MaterializationThreads. A SimpleLazyReexportsSpeculator instance maintains a list of speculation suggestions ((JITDylib, Function) pairs) and registered lazy reexports. When speculation opportunities are available (having been added via addSpeculationSuggestions or when lazy reexports were created) it schedules an IdleTask that triggers the next speculative lookup as soon as resources are available. Speculation suggestions are processed first, followed by lookups for lazy reexport bodies. A callback can be registered at object construction time to record lazy reexport executions as they happen, and these executions can be fed back into the speculator as suggestions on subsequent executions. The llvm-jitlink tool is updated to support speculation when lazy linking is used via three new arguments: -speculate=[none|simple] : When the 'simple' value is specified a SimpleLazyReexportsSpeculator instances is used for speculation. -speculate-order <path> : Specifies a path to a CSV containing (jit dylib name, function name) triples to use as speculative suggestions in the current run. -record-lazy-execs <path> : Specifies a path in which to record lazy function executions as a CSV of (jit dylib name, function name) pairs, suitable for use with -speculate-order. The same path can be passed to -speculate-order and -record-lazy-execs, in which case the file will be overwritten at the end of the execution. No testcase yet: Speculative linking is difficult to test (since by definition execution behavior should be unaffected by speculation) and this is an new prototype of the concept*. Tests will be added in the future once the interface and behavior settle down. * An earlier implementation of the speculation concept can be found in llvm/include/llvm/ExecutionEngine/Orc/Speculation.h. Both systems have the same goal (hiding compilation latency) but different mechanisms. This patch relies entirely on information available in the controller, where the old system could receive additional information from the JIT'd runtime via callbacks. I aim to combine the two in the future, but want to gain more practical experience with speculation first.
2025-01-09[ORC] Fail materialization in tasks that are destroyed before running.Lang Hames1-1/+11
If a MaterialiaztionTask is destroyed before running then we need to call failMaterialization on the MaterializationResponsibility member.
2025-01-09[ORC] Remove an unused typedef.Lang Hames1-2/+0
2025-01-09[ORC] Fix Task cleanup during DynamicThreadPoolTaskDispatcher::shutdown.Lang Hames1-2/+13
Threads created by DynamicThreadPoolTaskDispatcher::dispatch had been holding a unique_ptr to the most recent Task, meaning that the Task would be destroyed when the thread object was destroyed, but this would happen *after* the thread signaled the Dispatcher that it was finished. This could cause DynamicThreadPoolTaskDispatcher::shutdown to return (and consequently ExecutionSession to be destroyed) before all Tasks were destroyed, with Task destructors accessing ExecutionSession and related objects after they were freed. The fix is to reset the Task pointer immediately after it is run to trigger cleanup, *then* (if there are no other tasks to run) signal the Dispatcher that the thread is finished. This patch also updates DynamicThreadPoolTaskDispatcher::dispatch to reject any new Tasks dispatched after DynamicThreadPoolTaskDispatcher::shutdown is called.
2025-01-08[llvm-jitlink] Use -num-threads=0 for regression tests relying on debug output.Lang Hames1-19/+5
ORC and JITLink debugging output write the dbgs() raw_ostream, which isn't thread-safe. Use -num-threads=0 to force single-threaded linking for tests that produce debugging output. The llvm-jitlink tool is updated to suggest -num-threads=0 when debugging output is enabled.
2025-01-03[ORC][MachO] Avoid another race condition in MachOPlatform bootstrap.Lang Hames1-5/+7
Similar to a9e75b1d4d1: During MachOPlatform bootstrap we need to defer actions until essential platform functionality has been loaded, but the platform itself may be loaded under a concurrent dispatcher so we have to guard against the deferred actions vector being accessed concurrently. This fixes a probablistic failure in the ORC runtime regression tests on Darwin/x86-64 that was spotted after edca1d9bad2 (which turned on concurrent linking by default in llvm-jitlink).
2025-01-03[ORC] Fix bug in source file name finding in DebuggerSupportPlugin.Lang Hames1-8/+18
The debug section map was using MachO section names (with the "__" prefix), but DWARFContext expects section names with the object format prefix stripped off. This was preventing DWARFContext from accessing the debug_str section, resulting in bogus source name strings.
2024-12-23[ORC] Don't notify condition variable when condition is not met.Lang Hames1-1/+2
Avoids waking threads when the condition to proceed won't be met. NFC.
2024-12-23[ORC] Make LazyReexportManager::KeyToReentryAddrs plural, use vector::insert.Lang Hames1-15/+14
Cleanup to recent LazyReexportManager changes: KeyToReentryAddr now maps to multiple addrs, so make its name plural. Use vector insert rather than a for loop. NFC.
2024-12-17[ORC] Fix LazyReexports resource key management.Lang Hames1-6/+18
Multiple reentry points may be associated with a single key.
2024-12-17[ORC] Make LazyReexportsManager implement ResourceManager.Lang Hames1-15/+43
This ensures that the reexports mappings are cleared when the resource tracker associated with each mapping is removed.
2024-12-17[ORC] Introduce LinkGraphLayer interface and LinkGraphLinkingLayer. (#120182)Lang Hames4-766/+795
Introduces a new layer interface, LinkGraphLayer, that can be used to add LinkGraphs to an ExecutionSession. This patch moves most of ObjectLinkingLayer's functionality into a new LinkGraphLinkingLayer which should (in the future) be able to be used without linking libObject. ObjectLinkingLayer now inherits from LinkGraphLinkingLayer and just handles conversion of object files to LinkGraphs, which are then handed down to LinkGraphLinkingLayer to be linked.
2024-12-16[ORC] Make ObjectLinkingLayerJITLinkContext a private nested class.Lang Hames1-10/+7
This class is an implementation detail, so doesn't need a publicly accessible name.
2024-12-15[ORC][ORC-RT] Add ORC-RT based lazy compilation support for x86-64.Lang Hames1-0/+4
Adds support for the ORC-RT based lazy compilation scheme that was introduced in 570ecdcf8b4.
2024-12-13[ORC] Improve JITLinkReentryTrampolines "arch not supported" error message.Lang Hames1-2/+4
"Architecture not supported" becomes "JITLinkReentryTrampolines: architecture <arch> not supported".
2024-12-09Reapply "[ORC] Introduce LazyReexportsManager, ... (#118923)" with fixes.Lang Hames7-9/+399
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-09Revert "Reapply "[ORC] Introduce LazyReexportsManager, … (#118923)" with ↵Lang Hames7-399/+9
fixes" This reverts commit 41652c6c92958a87b8505b9b1e6f008856e392ac while I investigate more bot failures.
2024-12-09Reapply "[ORC] Introduce LazyReexportsManager, … (#118923)" with fixesLang Hames7-9/+399
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-07Revert "[ORC] Introduce LazyReexportsManager, JITLinkTrampolines, … (#118923)"Lang Hames6-385/+5
This reverts commit 570ecdcf8b44aec853ce381a5f6b77222b041afa while I investigate bot failures, e.g. https://lab.llvm.org/buildbot/#/builders/17/builds/4446.
2024-12-07[ORC] Introduce LazyReexportsManager, JITLinkTrampolines, ORC-RT base… ↵Lang Hames6-5/+385
(#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-06[ORC] Provide default MemoryAccess in SimpleRemoteEPC, add WritePointers impl.Lang Hames3-1/+27
Make EPCGenericMemoryAccess the default implementation for the MemoryAccess object in SimpleRemoteEPC, and add support for the WritePointers operation to OrcTargetProcess (previously this operation was unimplemented and would have triggered an error if accessed in a remote-JIT setup). No testcase yet: This functionality requires cross-process JITing to test (or a much more elaborate unit-test setup). It can be tested once the new top-level ORC runtime project lands.
2024-12-06[ORC] Remove an unused variable.Lang Hames1-1/+0
2024-12-06[JITLink] Switch to SymbolStringPtr for Symbol names (#115796)Jared Wyles14-93/+85
Use SymbolStringPtr for Symbol names in LinkGraph. This reduces string interning on the boundary between JITLink and ORC, and allows pointer comparisons (rather than string comparisons) between Symbol names. This should improve the performance and readability of code that bridges between JITLink and ORC (e.g. ObjectLinkingLayer and ObjectLinkingLayer::Plugins). To enable use of SymbolStringPtr a std::shared_ptr<SymbolStringPool> is added to LinkGraph and threaded through to its construction sites in LLVM and Bolt. All LinkGraphs that are to have symbol names compared by pointer equality must point to the same SymbolStringPool instance, which in ORC sessions should be the pool attached to the ExecutionSession. --------- Co-authored-by: Lang Hames <lhames@gmail.com>
2024-12-04[ORC] Move ostream operator for SymbolStringPtrBase into OrcShared.Lang Hames3-4/+19
This will allow clients outside ORC (e.g. JITLink) to use the operator without taking a dependence on ORC.
2024-12-04[ORC] Merge ostream operators for SymbolStringPtrs into SymbolStringPool.h. NFC.Lang Hames2-8/+5
These are simple and commonly used. Having them in the SymbolStringPool header saves clients from having to #include "DebugUtils.h" everywhere.
2024-12-03Re-apply "[ORC][JITLink] Add jitlink::Scope::SideEffectsOnly" with fixes.Lang Hames4-15/+15
This reapplies aba6bb0820b, which was reverted in 28e2a891210 due to bot failures. It contains fixes to silence warnings for uncovered switches, and for incorrect initializer-symbol handling on ELF and COFF.
2024-12-03Revert "[ORC][JITLink] Add jitlink::Scope::SideEffectsOnly, use it in ORC ↵Lang Hames4-11/+11
Platforms." This reverts commit aba6bb0820b247d4caf4b5e00810909214a58053 while I investigate bot failures (e.g. https://lab.llvm.org/buildbot/#/builders/143/builds/3848)
2024-12-03[ORC][JITLink] Add jitlink::Scope::SideEffectsOnly, use it in ORC Platforms.Lang Hames4-11/+11
SideEffectsOnly is a new jitlink::Scope value that corresponds to the JITSymbolFlags::MaterializationSideEffectsOnly flag: Symbols with this scope can be looked up (and form part of the initial interface of a LinkGraph) but never actually resolve to an address (so can only be looked up with a WeaklyReferencedSymbol lookup). Previously ObjectLinkingLayer implicitly treated JITLink symbols as having this scope, regardless of a Symbol's actual scope, if the MaterializationSideEffectsOnly flag was set on the corresponding symbol in the MaterializationResponsibility object. Using an explicit scope in JITLink for this (1) allows JITLink plugins to identify and correctly handle side-effects-only symbols, and (2) allows raw LinkGraphs to define side-effects-only symbols without clients having to manually modify their `MaterializationUnit::Interface`.
2024-12-03Re-apply "[ORC] Track all dependencies on symbols that aren't..." with fixes.Lang Hames1-7/+8
This reapplies 427fb5cc5ac, which was reverted in 08c1a6b3e18 due to bot failures. The fix was to remove an incorrect assertion: In IL_emit, during the initial worklist loop, an EDU can have all of its dependencies removed without becoming ready (because it may still have implicit dependencies that will be added back during the subsequent propagateExtraEmitDeps operation). The EDU will be marked Ready at the end of IL_emit if its Dependencies set is empty at that point. Prior to that we can only assert that it's either Emitted or Ready (which is already covered by other assertions).
2024-12-03[ORC] Fix typo in comment. NFC.Lang Hames1-1/+1
2024-12-02Revert "[ORC] Track all dependencies on symbols that aren't Ready yet."Lang Hames1-8/+5
This reverts commit 427fb5cc5ac34414c4682c90d3db0c63c5a1b227 while I investigate the bot failure in https://lab.llvm.org/buildbot/#/builders/95/builds/6835.
2024-12-02[ORC] Remove redundant check from ObjectLinkingLayer.Lang Hames1-2/+2
Non-locally scoped symbols must have names.
2024-12-02[ORC] Track all dependencies on symbols that aren't Ready yet.Lang Hames1-5/+8
AsynchronousSymbolQuery tracks the symbols that it depends on in order to (1) detach the query in the event of a failure, and (2) report those dependencies to clients of the ExecutionSession::lookup method (via the RegisterDependencies argument). Previously we tracked only dependencies on symbols that didn't meet the required state (the only symbols that the query needs to be attached to), but this is insufficient to report all necessary dependencies to lookup clients. E.g. A lookup requiring SymbolState::Resolved where some matched symbol is already Resolved but not yet Emitted or Ready would result in the dependency on that symbol not being reported, which could result in illegal access in concurrent JIT setups. (This bug was discovered by @mikaoP on discord with a simple concurrent JIT setup). This patch tracks and reports all dependencies on symbols that aren't Ready yet, correcting the under-reporting issue. AsynchronousSymbolQuery::detach is updated to stop asserting that all depended-upon symbols have a query attached.
2024-11-29[Support][Error] Add ErrorAsOutParameter constructor that takes an Error by ref.Lang Hames7-8/+8
ErrorAsOutParameter's Error* constructor supports cases where an Error might not be passed in (because in the calling context it's known that this call won't fail). Most clients always have an Error present however, and for them an Error& overload is more convenient.
2024-11-28[ORC] Fail early in ExecutionSession::registerJITDispatchHandlers.Lang Hames1-13/+21
Check that we're not reusing any handler tag addresses before installing any handlers. This ensures that either all of the handlers are installed*, or none of them are, simplifying error recovery. * Ignoring handlers whose tags couldn't be resolved at all: these were never installed.
2024-11-27[ORC] Fix typo in comment: instruction is ldr literal, not adr. NFC.Lang Hames1-1/+1
2024-11-19[ExecutionEngine] Remove unused includes (NFC) (#116749)Kazu Hirata32-64/+0
Identified with misc-include-cleaner.
2024-11-18[ORC] Add LazyObjectLinkingLayer, lazy-linking support to llvm-jitlink (#116002)Lang Hames3-1/+116
LazyObjectLinkingLayer can be used to add object files that will not be linked into the executor unless some function that they define is called at runtime. (References to data members defined by these objects will still trigger immediate linking) To implement lazy linking, LazyObjectLinkingLayer uses the lazyReexports utility to construct stubs for each function in a given object file, and an ObjectLinkingLayer::Plugin to rename the function bodies at link-time. (Data symbols are not renamed) The llvm-jitlink utility is extended with a -lazy option that can be passed before input files or archives to add them using the lazy linking layer rather than the base ObjectLinkingLayer.
2024-11-11[ORC] Move absoluteSymbols from Core.h to new AbsoluteSymbols.h header. NFC.Lang Hames10-41/+67
Continuing Core.h clean-up. If you see any errors about a missing absoluteSymbols function you need to include the new AbsoluteSymbols.h header.
2024-11-07[ORC] Switch to new visibility macros for JIT debug symbols (#113848)Thomas Fransham1-2/+3
Use LLVM_ALWAYS_EXPORT for __jit_debug_descriptor and __jit_debug_register_code so there exported even if LLVM is not built as a shared library. This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and plugins on windows #109483.
2024-11-06[ORC][Runtime] Add `dlupdate` for elf (#110406)SahilPatidar2-5/+5
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[ORC] lazyReexports: Swap IndirectStubsManager for RedirectableSymbolsManager.Lang Hames2-23/+45
RedirectableSymbolsManager is a native SymbolStringPtr API (requires fewer string operations) and has a narrower interface that permits a wider range of implementations. IndirectStubsManager is updated to make it a RedirectableSymbolsManager so that existing uses continue to work.
2024-11-06[ORC] Replace RedirectionManager::SymbolAddrMap typedef with SymbolMap. NFC.Lang Hames1-4/+3
They're the same type -- no need for a separate typedef here.