summaryrefslogtreecommitdiff
path: root/llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
AgeCommit message (Collapse)Author
2025-04-13[ExecutionEngine] Avoid repeated map lookups (NFC) (#135541)Kazu Hirata
2025-01-14[JITLink] Use target triple for LinkGraph pointer size and endianness.Lang Hames
Removes LinkGraph's PointerSize and Endianness members and uses the triple to find these values instead. Also removes some redundant Triple copies.
2024-12-06[JITLink] Switch to SymbolStringPtr for Symbol names (#115796)Jared Wyles
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-11-29[Support][Error] Add ErrorAsOutParameter constructor that takes an Error by ref.Lang Hames
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-19[ExecutionEngine] Remove unused includes (NFC) (#116749)Kazu Hirata
Identified with misc-include-cleaner.
2023-04-03[Orc] Add AutoRegisterCode option for DebugObjectManagerPluginStefan Gränitz
Configure the plugin to automatically call the debugger rendezvous breakpoint `__jit_debug_register_code()` for every translation unit (enabled) or never at all (disabled). Default API and behavior remain unchanged. If AutoRegisterCode is turned off, it's the client's own responsibility to call the rendezvous breakpoint function at an appropriate time. Depending on the complexity of the debugger's rendezvous breakpoint implementation, this can provide significant performance improvements in cases where many debug objects are added in sequence. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D147310
2023-04-03[Orc] Print section load-addresses for debug objects as hex againStefan Gränitz
Apparently, the refactor in 8b1771bd9f304be39d4dcbdcccedb6d3bcd18200 broke the logic behind formatv here: ``` 140736272011264 .rodata 140736272015360 .text 140736272011424 .eh_frame ```
2023-03-31[ORC] Remove redundant ExecutorAddr temporaries.Lang Hames
Most ORC APIs work with ExecutorAddr by default since 8b1771bd9f3, so we don't need to wrap these values in ExecutorAddr(...) calls any more.
2023-03-31[Orc] Drop arch check in the DebugObjectManagerPlugin for ELFStefan Gränitz
Tested this with the new AArch32 backend on armv7l and it works without issues in GDB. The size of the load-address field is only 32-bit here, but we implicitly account for it by writing a ELFT::uint which is: https://github.com/llvm/llvm-project/blob/release/16.x/llvm/include/llvm/Object/ELFTypes.h#L57 So, instead of adding a newly supported machine type, let's just drop this restriction althogether.
2023-03-31[Orc] Add RequireDebugSections option in the DebugObjectManagerPluginStefan Gränitz
Sometimes it's useful to be able and debug code even without actual debug info, e.g. for setting breakpoints on function names. This patch adds a new API option to make it possible in Orc. The existing API and behavior remains unchanged: non-debug objects are not passed to exectuors.
2023-03-31[Orc] Reflow comment and improve name after fix (NFC)Stefan Gränitz
2023-03-31[Orc] Avoid unused variable warning in builds without assertsBenjamin Kramer
DebugObjectManagerPlugin.cpp:372:8: error: unused variable 'ItInserted' [-Werror,-Wunused-variable] auto ItInserted = Sections.try_emplace(Name, std::move(Section)); ^
2023-03-31[Orc] Refactor debug section requirements into a more flexible flags field (NFC)Stefan Gränitz
When the initial DebugObjectManagerPlugin landed, it was not clear whether we will have more patching requirements for debug section. Also, there were no other use-cases for debug object flags. Adding options to the plugin gives us a use-case and we can re-use the field for it. This commit only refactors the infrastructure in preparation for two more patches to come.
2023-03-31[Orc] Filter sections for debug load-address patching upfrontStefan Gränitz
Originally, the DebugObjectManagerPlugin recorded all sections and filtered some of them for load-address patching. Then we spotted problems with duplicate section names and started additional filtering upfront (see b26f45e5a49ae363164e7dbbf57eadd9e78d612c). This seems the better approach. Let's go for it and stop filtering in two locations.
2023-03-31[Orc] Skip sections with duplicate names in DebugObjectManagerPluginStefan Gränitz
Compiler-generated section names can clash. Examples are group sections or profile counter sections. We don't need to abort debug registration for the entire LinkGraph in such a case. Instead, let's skip the relevant sections and add a note to the debug log.
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).
2022-12-19[ORC] Add JITDylib argument to ResourceManager notify-removing/transferring ops.Lang Hames
In some cases it's helpful to group trackers by JITDylib. E.g. Platform classes may want to track initializer symbols with a `JITDylib -> Tracker -> [ Symbol ]` map. This makes it easy to collect all symbols for the JITDylib, while still allowing efficient removal of a single tracker. Passing the JITDylib as an argument to ResourceManager::notifyRemovingResources and ResourceManager::notifyTransferringResources supports such use-cases.
2022-10-25[ORC] Skip non-SHF_ALLOC sections in DebugObjectManagerPlugin.Lang Hames
We don't need to provide a load-address for non-alloc sections. Skipping them allows us to avoid some complications, like handling duplicate .group sections.
2022-10-22[ORC] Add more information to duplicate section error message.Lang Hames
Now includes the name of the graph and duplicate section.
2022-02-06[llvm] Use = default (NFC)Kazu Hirata
2022-01-06Re-apply "[JITLink] Update JITLink to use ExecutorAddr rather... " with fixes.Lang Hames
This re-applies 133f86e95492b2a00b944e070878424cfa73f87c, which was reverted in c5965a411c635106a47738b8d2e24db822b7416f while I investigated bot failures. The original failure contained an arithmetic conversion think-o (on line 419 of EHFrameSupport.cpp) that could cause failures on 32-bit platforms. The issue should be fixed in this patch.
2022-01-06Revert "[JITLink] Update JITLink to use ExecutorAddr rather than..."Lang Hames
This reverts commit 133f86e95492b2a00b944e070878424cfa73f87c while I investigate the bot failures at https://lab.llvm.org/buildbot#builders/186/builds/3370.
2022-01-06[JITLink] Update JITLink to use ExecutorAddr rather than JITTargetAddress.Lang Hames
ExecutorAddr is the preferred representation for executor process addresses now.
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-03-22[Orc] Make usage of ResourceKeys thread-safe in DebugObjectManagerPluginStefan Gränitz
Don't leak ResourceKeys from MaterializationResponsibility::withResourceKeyDo() in notifyEmitted(). Also make some improvements in the overall implementation. Differential Revision: https://reviews.llvm.org/D98863
2021-03-22[Orc] Fix tracking of pending debug objects in DebugObjectManagerPluginStefan Gränitz
There can be multiple MaterializationResponsibilitys in-flight for a single ResourceKey. Hence, pending debug objects must be tracked by MaterializationResponsibility and not by ResourceKey. Differential Revision: https://reviews.llvm.org/D98785
2021-03-13[Orc] Deallocate debug objects properly when removing resources from ↵Stefan Gränitz
DebugObjectManagerPlugin
2021-03-12[JITLink][ORC] Make the LinkGraph available to modifyPassConfig.Lang Hames
This makes the target triple, graph name, and full graph content available when making decisions about how to populate the linker pass pipeline. Also updates the LLJITWithObjectLinkingLayerPlugin example to show more API use, including use of the API changes in this patch.
2021-03-12[Orc] Fix race condition in DebugObjectManagerPluginStefan Gränitz
During finalization the debug object is registered with the target. Materialization must wait for this process to finish. Otherwise we might start running code before the debugger finished processing the corresponding debug info. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D98417
2021-03-11[Orc] Deallocate debug objects explicitly when destroying the ↵Stefan Gränitz
DebugObjectManagerPlugin
2021-03-09[Orc] Always check mapped sections for ELFDebugObject are in bounds of ↵Stefan Gränitz
working memory buffer As stated in the JITLink user guide: Do not assume that the input object is well formed. https://llvm.org/docs/JITLink.html#tips-for-jitlink-backend-developers
2021-03-09[Orc] Fix working memory buffer for section mapping in ELFDebugObjectStefan Gränitz
2021-03-02[Orc] Fix MSVC error: conversion from 'initializer list' requires a narrowingStefan Gränitz
2021-03-02[Orc] Add JITLink debug support plugin for ELF x86-64Stefan Gränitz
Add a new ObjectLinkingLayer plugin `DebugObjectManagerPlugin` and infrastructure to handle creation of `DebugObject`s as well as their registration in OrcTargetProcess. The current implementation only covers ELF on x86-64, but the infrastructure is not limited to that. The journey starts with a new `LinkGraph` / `JITLinkContext` pair being created for a `MaterializationResponsibility` in ORC's `ObjectLinkingLayer`. It sends a `notifyMaterializing()` notification, which is forwarded to all registered plugins. The `DebugObjectManagerPlugin` aims to create a `DebugObject` form the provided target triple and object buffer. (Future implementations might create `DebugObject`s from a `LinkGraph` in other ways.) On success it will track it as the pending `DebugObject` for the `MaterializationResponsibility`. This patch only implements the `ELFDebugObject` for `x86-64` targets. It follows the RuntimeDyld approach for debug object setup: it captures a copy of the input object, parses all section headers and prepares to patch their load-address fields with their final addresses in target memory. It instructs the plugin to report the section load-addresses once they are available. The plugin overrides `modifyPassConfig()` and installs a JITLink post-allocation pass to capture them. Once JITLink emitted the finalized executable, the plugin emits and registers the `DebugObject`. For emission it requests a new `JITLinkMemoryManager::Allocation` with a single read-only segment, copies the object with patched section load-addresses over to working memory and triggers finalization to target memory. For registration, it notifies the `DebugObjectRegistrar` provided in the constructor and stores the previously pending`DebugObject` as registered for the corresponding MaterializationResponsibility. The `DebugObjectRegistrar` registers the `DebugObject` with the target process. `llvm-jitlink` uses the `TPCDebugObjectRegistrar`, which calls `llvm_orc_registerJITLoaderGDBWrapper()` in the target process via `TargetProcessControl` to emit a `jit_code_entry` compatible with the GDB JIT interface [1]. So far the implementation only supports registration and no removal. It appears to me that it wouldn't raise any new design questions, so I left this as an addition for the near future. [1] https://sourceware.org/gdb/current/onlinedocs/gdb/JIT-Interface.html Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D97335