[PATCH] D97335: [Orc] Add JITLink debug support plugin for ELF x86-64

Stefan Gränitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 23 14:03:40 PST 2021


sgraenitz created this revision.
sgraenitz added reviewers: lhames, dblaikie.
Herald added subscribers: pengfei, hiraditya, mgorny.
sgraenitz requested review of this revision.
Herald added a project: LLVM.

This patch adds a new ObjectLinkingLayer plugin `DebugObjectManagerPlugin` and infrastructure to handle creation of `DebugObject`s in JITLink and their registration in OrcTargetProcess.

For now the provided implementation only covers ELF on x86-64 and follows the RuntimeDyld approach for debug object setup: it captures a copy of the input object and patches section load-addresses with their actual addresses in target memory. The proposed infrastructure, however, is not limited to that and offers extension points to support other approaches of debug object construction, i.e. "from-scratch" creation from raw link graphs.

Our journey starts with a newly added notification `JITLinkContext::notifyMaterializing()`, which is triggered right after a new `LinkGraph` / `JITLinkContext` pair is created. The implementation in `ObjectLinkingLayerJITLinkContext` forwards it to all registered plugins. The `DebugObjectManagerPlugin` sets up tracking for a pending `DebugObject` that it requests from the given `JITLinkContext`. `ObjectLinkingLayerJITLinkContext` implements this function by copying the input object into a new buffer and forwarding the request to `jitlink::createDebugObjectFromBuffer()`. (Future implementations might create some kind of debug object builder for the given `LinkGraph` at this point.) Arriving on the JITLink side, we only support ELF for now. The `ELFDebugObject` requests a new `JITLinkMemoryManager::Allocation` for the `JITLinkDylib` with a single read-only segment that contains the given object buffer.

Once linking starts, the `DebugObjectManagerPlugin` receives the `modifyPassConfig()` notification and forwards it to the pending `DebugObject`. Now, the `ELFDebugObject` installs a `PostAllocationPass` to capture the actual section load-addresses in target memory and patchs its underlying object buffer.

Once linking finished `DebugObjectManagerPlugin` receives the `notifyLoaded()` notification. It calls `finalizeAsync()` on the pending `DebugObject`, passes a continuation that marks the `DebugObject` as registered and notifies the `DebugObjectRegistrar` for emmission. For `ELFDebugObject`, we now finalize the `JITLinkMemoryManager::Allocation`.

The `DebugObjectRegistrar` is responsible for registering the `DebugObject` with the target process. The `TPCDebugObjectRegistrar` we use in `llvm-jitlink` is created in `createJITLoaderGDBRegistrar()`, which sets up a TPC-based registrar that reaches out to `llvm_orc_registerJITLoaderGDBWrapper()` in the target process 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.

A LIT test that covers the core functionality in this patch will follow in a separate review (it requires a few changes in lli).

[1] https://sourceware.org/gdb/current/onlinedocs/gdb/JIT-Interface.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97335

Files:
  llvm/include/llvm/ExecutionEngine/JITLink/DebugSupport.h
  llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
  llvm/include/llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h
  llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
  llvm/include/llvm/ExecutionEngine/Orc/TPCDebugObjectRegistrar.h
  llvm/include/llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h
  llvm/lib/ExecutionEngine/JITLink/CMakeLists.txt
  llvm/lib/ExecutionEngine/JITLink/DebugSupport.cpp
  llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
  llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
  llvm/lib/ExecutionEngine/Orc/DebugObjectManagerPlugin.cpp
  llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp
  llvm/lib/ExecutionEngine/Orc/TPCDebugObjectRegistrar.cpp
  llvm/lib/ExecutionEngine/Orc/TargetProcess/CMakeLists.txt
  llvm/lib/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.cpp
  llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
  llvm/tools/llvm-jitlink/llvm-jitlink.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97335.325896.patch
Type: text/x-patch
Size: 41235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210223/4a039a04/attachment.bin>


More information about the llvm-commits mailing list