@@ -156,7 +156,10 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
156
156
std::unique_ptr<MaterializationResponsibility> MR,
157
157
std::unique_ptr<MemoryBuffer> ObjBuffer)
158
158
: JITLinkContext(&MR->getTargetJITDylib ()), Layer(Layer),
159
- MR(std::move(MR)), ObjBuffer(std::move(ObjBuffer)) {}
159
+ MR(std::move(MR)), ObjBuffer(std::move(ObjBuffer)) {
160
+ std::lock_guard<std::mutex> Lock (Layer.LayerMutex );
161
+ Plugins = Layer.Plugins ;
162
+ }
160
163
161
164
~ObjectLinkingLayerJITLinkContext () {
162
165
// If there is an object buffer return function then use it to
@@ -168,14 +171,14 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
168
171
JITLinkMemoryManager &getMemoryManager () override { return Layer.MemMgr ; }
169
172
170
173
void notifyMaterializing (LinkGraph &G) {
171
- for (auto &P : Layer. Plugins )
174
+ for (auto &P : Plugins)
172
175
P->notifyMaterializing (*MR, G, *this ,
173
176
ObjBuffer ? ObjBuffer->getMemBufferRef ()
174
177
: MemoryBufferRef ());
175
178
}
176
179
177
180
void notifyFailed (Error Err) override {
178
- for (auto &P : Layer. Plugins )
181
+ for (auto &P : Plugins)
179
182
Err = joinErrors (std::move (Err), P->notifyFailed (*MR));
180
183
Layer.getExecutionSession ().reportError (std::move (Err));
181
184
MR->failMaterialization ();
@@ -317,12 +320,12 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
317
320
if (auto Err = MR->notifyResolved (InternedResult))
318
321
return Err;
319
322
320
- Layer. notifyLoaded (*MR );
323
+ notifyLoaded ();
321
324
return Error::success ();
322
325
}
323
326
324
327
void notifyFinalized (JITLinkMemoryManager::FinalizedAlloc A) override {
325
- if (auto Err = Layer. notifyEmitted (*MR, std::move (A))) {
328
+ if (auto Err = notifyEmitted (std::move (A))) {
326
329
Layer.getExecutionSession ().reportError (std::move (Err));
327
330
MR->failMaterialization ();
328
331
return ;
@@ -344,14 +347,38 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
344
347
return claimOrExternalizeWeakAndCommonSymbols (G);
345
348
});
346
349
347
- Layer.modifyPassConfig (*MR, LG, Config);
350
+ for (auto &P : Plugins)
351
+ P->modifyPassConfig (*MR, LG, Config);
348
352
349
353
Config.PreFixupPasses .push_back (
350
354
[this ](LinkGraph &G) { return registerDependencies (G); });
351
355
352
356
return Error::success ();
353
357
}
354
358
359
+ void notifyLoaded () {
360
+ for (auto &P : Plugins)
361
+ P->notifyLoaded (*MR);
362
+ }
363
+
364
+ Error notifyEmitted (jitlink::JITLinkMemoryManager::FinalizedAlloc FA) {
365
+ Error Err = Error::success ();
366
+ for (auto &P : Plugins)
367
+ Err = joinErrors (std::move (Err), P->notifyEmitted (*MR));
368
+
369
+ if (Err) {
370
+ if (FA)
371
+ Err =
372
+ joinErrors (std::move (Err), Layer.MemMgr .deallocate (std::move (FA)));
373
+ return Err;
374
+ }
375
+
376
+ if (FA)
377
+ return Layer.recordFinalizedAlloc (*MR, std::move (FA));
378
+
379
+ return Error::success ();
380
+ }
381
+
355
382
private:
356
383
// Symbol name dependencies:
357
384
// Internal: Defined in this graph.
@@ -522,7 +549,7 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
522
549
523
550
SymbolDependenceGroup SynthSDG;
524
551
525
- for (auto &P : Layer. Plugins ) {
552
+ for (auto &P : Plugins) {
526
553
auto SynthDeps = P->getSyntheticSymbolDependencies (*MR);
527
554
if (SynthDeps.empty ())
528
555
continue ;
@@ -636,6 +663,7 @@ class ObjectLinkingLayerJITLinkContext final : public JITLinkContext {
636
663
}
637
664
638
665
ObjectLinkingLayer &Layer;
666
+ std::vector<std::shared_ptr<ObjectLinkingLayer::Plugin>> Plugins;
639
667
std::unique_ptr<MaterializationResponsibility> MR;
640
668
std::unique_ptr<MemoryBuffer> ObjBuffer;
641
669
DenseMap<Block *, SymbolNameSet> ExternalBlockDeps;
@@ -702,34 +730,9 @@ void ObjectLinkingLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
702
730
link (std::move (G), std::move (Ctx));
703
731
}
704
732
705
- void ObjectLinkingLayer::modifyPassConfig (MaterializationResponsibility &MR,
706
- LinkGraph &G,
707
- PassConfiguration &PassConfig) {
708
- for (auto &P : Plugins)
709
- P->modifyPassConfig (MR, G, PassConfig);
710
- }
711
-
712
- void ObjectLinkingLayer::notifyLoaded (MaterializationResponsibility &MR) {
713
- for (auto &P : Plugins)
714
- P->notifyLoaded (MR);
715
- }
716
-
717
- Error ObjectLinkingLayer::notifyEmitted (MaterializationResponsibility &MR,
718
- FinalizedAlloc FA) {
719
- Error Err = Error::success ();
720
- for (auto &P : Plugins)
721
- Err = joinErrors (std::move (Err), P->notifyEmitted (MR));
722
-
723
- if (Err) {
724
- if (FA)
725
- Err = joinErrors (std::move (Err), MemMgr.deallocate (std::move (FA)));
726
- return Err;
727
- }
728
-
729
- if (!FA)
730
- return Error::success ();
731
-
732
- Err = MR.withResourceKeyDo (
733
+ Error ObjectLinkingLayer::recordFinalizedAlloc (
734
+ MaterializationResponsibility &MR, FinalizedAlloc FA) {
735
+ auto Err = MR.withResourceKeyDo (
733
736
[&](ResourceKey K) { Allocs[K].push_back (std::move (FA)); });
734
737
735
738
if (Err)
0 commit comments