summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2019-04-26 22:58:39 +0000
committerLang Hames <lhames@gmail.com>2019-04-26 22:58:39 +0000
commita9fdf375b3769a1df18d72aa6eb1e627a22a29e7 (patch)
treed0da4440cb41c3968535132865e0823055a1930b /llvm/include
parent353f593976d8edf4310498358582e3d49f807754 (diff)
downloadbcm5719-llvm-a9fdf375b3769a1df18d72aa6eb1e627a22a29e7.tar.gz
bcm5719-llvm-a9fdf375b3769a1df18d72aa6eb1e627a22a29e7.zip
[ORC] Add a 'plugin' interface to ObjectLinkingLayer for events/configuration.
ObjectLinkingLayer::Plugin provides event notifications when objects are loaded, emitted, and removed. It also provides a modifyPassConfig callback that allows plugins to modify the JITLink pass configuration. This patch moves eh-frame registration into its own plugin, and teaches llvm-jitlink to only add that plugin when performing execution runs on non-Windows platforms. This should allow us to re-enable the test case that was removed in r359198. llvm-svn: 359357
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h7
-rw-r--r--llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h91
2 files changed, 63 insertions, 35 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h b/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
index 5c1c276d372..1563e97fb08 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
@@ -27,14 +27,17 @@ Error registerEHFrameSection(const void *EHFrameSectionAddr);
/// Deregisters all FDEs in the given eh-frame section with the current process.
Error deregisterEHFrameSection(const void *EHFrameSectionAddr);
+using StoreFrameAddressFunction = std::function<void(JITTargetAddress)>;
+
/// Creates a pass that records the address of the EH frame section. If no
/// eh-frame section is found, it will set EHFrameAddr to zero.
///
/// Authors of JITLinkContexts can use this function to register a post-fixup
/// pass that records the address of the eh-frame section. This address can
/// be used after finalization to register and deregister the frame.
-AtomGraphPassFunction createEHFrameRecorderPass(const Triple &TT,
- JITTargetAddress &EHFrameAddr);
+AtomGraphPassFunction
+createEHFrameRecorderPass(const Triple &TT,
+ StoreFrameAddressFunction StoreFrameAddress);
} // end namespace jitlink
} // end namespace llvm
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
index f4cafb5cdcc..4a45ad2b92e 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h
@@ -41,27 +41,48 @@ namespace orc {
class ObjectLinkingLayerJITLinkContext;
+/// An ObjectLayer implementation built on JITLink.
+///
+/// Clients can use this class to add relocatable object files to an
+/// ExecutionSession, and it typically serves as the base layer (underneath
+/// a compiling layer like IRCompileLayer) for the rest of the JIT.
class ObjectLinkingLayer : public ObjectLayer {
friend class ObjectLinkingLayerJITLinkContext;
public:
- /// Function object for receiving object-loaded notifications.
- using NotifyLoadedFunction = std::function<void(VModuleKey)>;
+ /// Plugin instances can be added to the ObjectLinkingLayer to receive
+ /// callbacks when code is loaded or emitted, and when JITLink is being
+ /// configured.
+ class Plugin {
+ public:
+ virtual ~Plugin();
+ virtual void modifyPassConfig(MaterializationResponsibility &MR,
+ const Triple &TT,
+ jitlink::PassConfiguration &Config) {}
+ virtual void notifyLoaded(MaterializationResponsibility &MR) {}
+ virtual Error notifyEmitted(MaterializationResponsibility &MR) {
+ return Error::success();
+ }
+ virtual Error notifyRemovingModule(VModuleKey K) {
+ return Error::success();
+ }
+ virtual Error notifyRemovingAllModules() { return Error::success(); }
+ };
- /// Function object for receiving finalization notifications.
- using NotifyEmittedFunction = std::function<void(VModuleKey)>;
+ /// Construct an ObjectLinkingLayer with the given NotifyLoaded,
+ /// and NotifyEmitted functors.
+ ObjectLinkingLayer(ExecutionSession &ES,
+ jitlink::JITLinkMemoryManager &MemMgr);
- /// Function object for modifying PassConfiguration objects.
- using ModifyPassConfigFunction =
- std::function<void(const Triple &TT, jitlink::PassConfiguration &Config)>;
+ /// Destruct an ObjectLinkingLayer.
+ ~ObjectLinkingLayer();
- /// Construct an ObjectLinkingLayer with the given NotifyLoaded,
- /// and NotifyEmitted functors.
- ObjectLinkingLayer(
- ExecutionSession &ES, jitlink::JITLinkMemoryManager &MemMgr,
- NotifyLoadedFunction NotifyLoaded = NotifyLoadedFunction(),
- NotifyEmittedFunction NotifyEmitted = NotifyEmittedFunction(),
- ModifyPassConfigFunction ModifyPassConfig = ModifyPassConfigFunction());
+ /// Add a pass-config modifier.
+ ObjectLinkingLayer &addPlugin(std::unique_ptr<Plugin> P) {
+ std::lock_guard<std::mutex> Lock(LayerMutex);
+ Plugins.push_back(std::move(P));
+ return *this;
+ }
/// Emit the object.
void emit(MaterializationResponsibility R,
@@ -101,31 +122,35 @@ public:
private:
using AllocPtr = std::unique_ptr<jitlink::JITLinkMemoryManager::Allocation>;
- class ObjectResources {
- public:
- ObjectResources() = default;
- ObjectResources(AllocPtr Alloc, JITTargetAddress EHFrameAddr);
- ObjectResources(ObjectResources &&Other);
- ObjectResources &operator=(ObjectResources &&Other);
- ~ObjectResources();
-
- private:
- AllocPtr Alloc;
- JITTargetAddress EHFrameAddr = 0;
- };
+ void modifyPassConfig(MaterializationResponsibility &MR, const Triple &TT,
+ jitlink::PassConfiguration &PassConfig);
+ void notifyLoaded(MaterializationResponsibility &MR);
+ Error notifyEmitted(MaterializationResponsibility &MR, AllocPtr Alloc);
- void notifyFinalized(ObjectResources OR) {
- ObjResources.push_back(std::move(OR));
- }
+ Error removeModule(VModuleKey K);
+ Error removeAllModules();
mutable std::mutex LayerMutex;
jitlink::JITLinkMemoryManager &MemMgr;
- NotifyLoadedFunction NotifyLoaded;
- NotifyEmittedFunction NotifyEmitted;
- ModifyPassConfigFunction ModifyPassConfig;
bool OverrideObjectFlags = false;
bool AutoClaimObjectSymbols = false;
- std::vector<ObjectResources> ObjResources;
+ DenseMap<VModuleKey, AllocPtr> TrackedAllocs;
+ std::vector<AllocPtr> UntrackedAllocs;
+ std::vector<std::unique_ptr<Plugin>> Plugins;
+};
+
+class LocalEHFrameRegistrationPlugin : public ObjectLinkingLayer::Plugin {
+public:
+ Error notifyEmitted(MaterializationResponsibility &MR) override;
+ void modifyPassConfig(MaterializationResponsibility &MR, const Triple &TT,
+ jitlink::PassConfiguration &PassConfig) override;
+ Error notifyRemovingModule(VModuleKey K) override;
+ Error notifyRemovingAllModules() override;
+
+private:
+ DenseMap<MaterializationResponsibility *, const void *> InProcessLinks;
+ DenseMap<VModuleKey, const void *> TrackedEHFrameAddrs;
+ std::vector<const void *> UntrackedEHFrameAddrs;
};
} // end namespace orc
OpenPOWER on IntegriCloud