@@ -540,6 +540,7 @@ struct JITObjectInfo {
540
540
};
541
541
542
542
class JLDebuginfoPlugin : public ObjectLinkingLayer ::Plugin {
543
+ std::mutex PluginMutex;
543
544
std::map<MaterializationResponsibility *, std::unique_ptr<JITObjectInfo>> PendingObjs;
544
545
// Resources from distinct MaterializationResponsibilitys can get merged
545
546
// after emission, so we can have multiple debug objects per resource key.
@@ -560,33 +561,40 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
560
561
auto NewObj =
561
562
cantFail (object::ObjectFile::createObjectFile (NewBuffer->getMemBufferRef ()));
562
563
563
- assert (PendingObjs.count (&MR) == 0 );
564
- PendingObjs[&MR] = std::unique_ptr<JITObjectInfo>(
565
- new JITObjectInfo{std::move (NewBuffer), std::move (NewObj), {}});
564
+ {
565
+ std::lock_guard<std::mutex> lock (PluginMutex);
566
+ assert (PendingObjs.count (&MR) == 0 );
567
+ PendingObjs[&MR] = std::unique_ptr<JITObjectInfo>(
568
+ new JITObjectInfo{std::move (NewBuffer), std::move (NewObj), {}});
569
+ }
566
570
}
567
571
568
572
Error notifyEmitted (MaterializationResponsibility &MR) override
569
573
{
570
- auto It = PendingObjs.find (&MR);
571
- if (It == PendingObjs.end ())
572
- return Error::success ();
573
-
574
- auto NewInfo = PendingObjs[&MR].get ();
575
- auto getLoadAddress = [NewInfo](const StringRef &Name) -> uint64_t {
576
- auto result = NewInfo->SectionLoadAddresses .find (Name);
577
- if (result == NewInfo->SectionLoadAddresses .end ()) {
578
- LLVM_DEBUG ({
579
- dbgs () << " JLDebuginfoPlugin: No load address found for section '"
580
- << Name << " '\n " ;
581
- });
582
- return 0 ;
583
- }
584
- return result->second ;
585
- };
574
+ {
575
+ std::lock_guard<std::mutex> lock (PluginMutex);
576
+ auto It = PendingObjs.find (&MR);
577
+ if (It == PendingObjs.end ())
578
+ return Error::success ();
579
+
580
+ auto NewInfo = PendingObjs[&MR].get ();
581
+ auto getLoadAddress = [NewInfo](const StringRef &Name) -> uint64_t {
582
+ auto result = NewInfo->SectionLoadAddresses .find (Name);
583
+ if (result == NewInfo->SectionLoadAddresses .end ()) {
584
+ LLVM_DEBUG ({
585
+ dbgs () << " JLDebuginfoPlugin: No load address found for section '"
586
+ << Name << " '\n " ;
587
+ });
588
+ return 0 ;
589
+ }
590
+ return result->second ;
591
+ };
586
592
587
- jl_register_jit_object (*NewInfo->Object , getLoadAddress, nullptr );
593
+ jl_register_jit_object (*NewInfo->Object , getLoadAddress, nullptr );
594
+ }
588
595
589
596
cantFail (MR.withResourceKeyDo ([&](ResourceKey K) {
597
+ std::lock_guard<std::mutex> lock (PluginMutex);
590
598
RegisteredObjs[K].push_back (std::move (PendingObjs[&MR]));
591
599
PendingObjs.erase (&MR);
592
600
}));
@@ -596,19 +604,22 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
596
604
597
605
Error notifyFailed (MaterializationResponsibility &MR) override
598
606
{
607
+ std::lock_guard<std::mutex> lock (PluginMutex);
599
608
PendingObjs.erase (&MR);
600
609
return Error::success ();
601
610
}
602
611
603
612
Error notifyRemovingResources (ResourceKey K) override
604
613
{
614
+ std::lock_guard<std::mutex> lock (PluginMutex);
605
615
RegisteredObjs.erase (K);
606
616
// TODO: If we ever unload code, need to notify debuginfo registry.
607
617
return Error::success ();
608
618
}
609
619
610
620
void notifyTransferringResources (ResourceKey DstKey, ResourceKey SrcKey) override
611
621
{
622
+ std::lock_guard<std::mutex> lock (PluginMutex);
612
623
auto SrcIt = RegisteredObjs.find (SrcKey);
613
624
if (SrcIt != RegisteredObjs.end ()) {
614
625
for (std::unique_ptr<JITObjectInfo> &Info : SrcIt->second )
@@ -620,13 +631,16 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
620
631
void modifyPassConfig (MaterializationResponsibility &MR, jitlink::LinkGraph &,
621
632
jitlink::PassConfiguration &PassConfig) override
622
633
{
634
+ std::lock_guard<std::mutex> lock (PluginMutex);
623
635
auto It = PendingObjs.find (&MR);
624
636
if (It == PendingObjs.end ())
625
637
return ;
626
638
627
639
JITObjectInfo &Info = *It->second ;
628
- PassConfig.PostAllocationPasses .push_back ([&Info](jitlink::LinkGraph &G) -> Error {
640
+ PassConfig.PostAllocationPasses .push_back ([&Info, this ](jitlink::LinkGraph &G) -> Error {
641
+ std::lock_guard<std::mutex> lock (PluginMutex);
629
642
for (const jitlink::Section &Sec : G.sections ()) {
643
+ #ifdef _OS_DARWIN_
630
644
// Canonical JITLink section names have the segment name included, e.g.
631
645
// "__TEXT,__text" or "__DWARF,__debug_str". There are some special internal
632
646
// sections without a comma separator, which we can just ignore.
@@ -639,6 +653,9 @@ class JLDebuginfoPlugin : public ObjectLinkingLayer::Plugin {
639
653
continue ;
640
654
}
641
655
auto SecName = Sec.getName ().substr (SepPos + 1 );
656
+ #else
657
+ auto SecName = Sec.getName ();
658
+ #endif
642
659
// https://github.com/llvm/llvm-project/commit/118e953b18ff07d00b8f822dfbf2991e41d6d791
643
660
#if JL_LLVM_VERSION >= 140000
644
661
Info.SectionLoadAddresses [SecName] = jitlink::SectionRange (Sec).getStart ().getValue ();
@@ -1051,7 +1068,7 @@ JuliaOJIT::JuliaOJIT()
1051
1068
OptSelLayer (Pipelines)
1052
1069
{
1053
1070
#ifdef JL_USE_JITLINK
1054
- # if defined(_OS_DARWIN_) && defined( LLVM_SHLIB)
1071
+ # if defined(LLVM_SHLIB)
1055
1072
// When dynamically linking against LLVM, use our custom EH frame registration code
1056
1073
// also used with RTDyld to inform both our and the libc copy of libunwind.
1057
1074
auto ehRegistrar = std::make_unique<JLEHFrameRegistrar>();
0 commit comments