@@ -41,27 +41,48 @@ namespace orc {
41
41
42
42
class ObjectLinkingLayerJITLinkContext ;
43
43
44
+ // / An ObjectLayer implementation built on JITLink.
45
+ // /
46
+ // / Clients can use this class to add relocatable object files to an
47
+ // / ExecutionSession, and it typically serves as the base layer (underneath
48
+ // / a compiling layer like IRCompileLayer) for the rest of the JIT.
44
49
class ObjectLinkingLayer : public ObjectLayer {
45
50
friend class ObjectLinkingLayerJITLinkContext ;
46
51
47
52
public:
48
- // / Function object for receiving object-loaded notifications.
49
- using NotifyLoadedFunction = std::function<void (VModuleKey)>;
53
+ // / Plugin instances can be added to the ObjectLinkingLayer to receive
54
+ // / callbacks when code is loaded or emitted, and when JITLink is being
55
+ // / configured.
56
+ class Plugin {
57
+ public:
58
+ virtual ~Plugin ();
59
+ virtual void modifyPassConfig (MaterializationResponsibility &MR,
60
+ const Triple &TT,
61
+ jitlink::PassConfiguration &Config) {}
62
+ virtual void notifyLoaded (MaterializationResponsibility &MR) {}
63
+ virtual Error notifyEmitted (MaterializationResponsibility &MR) {
64
+ return Error::success ();
65
+ }
66
+ virtual Error notifyRemovingModule (VModuleKey K) {
67
+ return Error::success ();
68
+ }
69
+ virtual Error notifyRemovingAllModules () { return Error::success (); }
70
+ };
50
71
51
- // / Function object for receiving finalization notifications.
52
- using NotifyEmittedFunction = std::function<void (VModuleKey)>;
72
+ // / Construct an ObjectLinkingLayer with the given NotifyLoaded,
73
+ // / and NotifyEmitted functors.
74
+ ObjectLinkingLayer (ExecutionSession &ES,
75
+ jitlink::JITLinkMemoryManager &MemMgr);
53
76
54
- // / Function object for modifying PassConfiguration objects.
55
- using ModifyPassConfigFunction =
56
- std::function<void (const Triple &TT, jitlink::PassConfiguration &Config)>;
77
+ // / Destruct an ObjectLinkingLayer.
78
+ ~ObjectLinkingLayer ();
57
79
58
- // / Construct an ObjectLinkingLayer with the given NotifyLoaded,
59
- // / and NotifyEmitted functors.
60
- ObjectLinkingLayer (
61
- ExecutionSession &ES, jitlink::JITLinkMemoryManager &MemMgr,
62
- NotifyLoadedFunction NotifyLoaded = NotifyLoadedFunction(),
63
- NotifyEmittedFunction NotifyEmitted = NotifyEmittedFunction(),
64
- ModifyPassConfigFunction ModifyPassConfig = ModifyPassConfigFunction());
80
+ // / Add a pass-config modifier.
81
+ ObjectLinkingLayer &addPlugin (std::unique_ptr<Plugin> P) {
82
+ std::lock_guard<std::mutex> Lock (LayerMutex);
83
+ Plugins.push_back (std::move (P));
84
+ return *this ;
85
+ }
65
86
66
87
// / Emit the object.
67
88
void emit (MaterializationResponsibility R,
@@ -101,31 +122,35 @@ class ObjectLinkingLayer : public ObjectLayer {
101
122
private:
102
123
using AllocPtr = std::unique_ptr<jitlink::JITLinkMemoryManager::Allocation>;
103
124
104
- class ObjectResources {
105
- public:
106
- ObjectResources () = default ;
107
- ObjectResources (AllocPtr Alloc, JITTargetAddress EHFrameAddr);
108
- ObjectResources (ObjectResources &&Other);
109
- ObjectResources &operator =(ObjectResources &&Other);
110
- ~ObjectResources ();
111
-
112
- private:
113
- AllocPtr Alloc;
114
- JITTargetAddress EHFrameAddr = 0 ;
115
- };
125
+ void modifyPassConfig (MaterializationResponsibility &MR, const Triple &TT,
126
+ jitlink::PassConfiguration &PassConfig);
127
+ void notifyLoaded (MaterializationResponsibility &MR);
128
+ Error notifyEmitted (MaterializationResponsibility &MR, AllocPtr Alloc);
116
129
117
- void notifyFinalized (ObjectResources OR) {
118
- ObjResources.push_back (std::move (OR));
119
- }
130
+ Error removeModule (VModuleKey K);
131
+ Error removeAllModules ();
120
132
121
133
mutable std::mutex LayerMutex;
122
134
jitlink::JITLinkMemoryManager &MemMgr;
123
- NotifyLoadedFunction NotifyLoaded;
124
- NotifyEmittedFunction NotifyEmitted;
125
- ModifyPassConfigFunction ModifyPassConfig;
126
135
bool OverrideObjectFlags = false ;
127
136
bool AutoClaimObjectSymbols = false ;
128
- std::vector<ObjectResources> ObjResources;
137
+ DenseMap<VModuleKey, AllocPtr> TrackedAllocs;
138
+ std::vector<AllocPtr> UntrackedAllocs;
139
+ std::vector<std::unique_ptr<Plugin>> Plugins;
140
+ };
141
+
142
+ class LocalEHFrameRegistrationPlugin : public ObjectLinkingLayer ::Plugin {
143
+ public:
144
+ Error notifyEmitted (MaterializationResponsibility &MR) override ;
145
+ void modifyPassConfig (MaterializationResponsibility &MR, const Triple &TT,
146
+ jitlink::PassConfiguration &PassConfig) override ;
147
+ Error notifyRemovingModule (VModuleKey K) override ;
148
+ Error notifyRemovingAllModules () override ;
149
+
150
+ private:
151
+ DenseMap<MaterializationResponsibility *, const void *> InProcessLinks;
152
+ DenseMap<VModuleKey, const void *> TrackedEHFrameAddrs;
153
+ std::vector<const void *> UntrackedEHFrameAddrs;
129
154
};
130
155
131
156
} // end namespace orc
0 commit comments