21#define DEBUG_TYPE "orc"
45 return SPSMachOJITDylibDepInfo::AsArgList::serialize(OB, DDI.
Sealed,
51 return SPSMachOJITDylibDepInfo::AsArgList::deserialize(IB, DDI.
Sealed,
62std::unique_ptr<jitlink::LinkGraph> createPlatformGraph(
MachOPlatform &MOP,
68 switch (
TT.getArch()) {
78 return std::make_unique<jitlink::LinkGraph>(std::move(
Name), TT, PointerSize,
93 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
94 auto G = createPlatformGraph(MOP,
"<MachOHeaderMU>");
95 addMachOHeader(*
G, MOP,
R->getInitializerSymbol());
103 auto &HeaderSection =
G.createSection(
"__header", MemProt::Read);
104 auto &HeaderBlock = createHeaderBlock(
G, HeaderSection);
107 G.addDefinedSymbol(HeaderBlock, 0, *InitializerSymbol,
108 HeaderBlock.getSize(), jitlink::Linkage::Strong,
109 jitlink::Scope::Default,
false,
true);
110 for (
auto &HS : AdditionalHeaderSymbols)
111 G.addDefinedSymbol(HeaderBlock,
HS.Offset,
HS.Name, HeaderBlock.getSize(),
112 jitlink::Linkage::Strong, jitlink::Scope::Default,
117 struct HeaderSymbol {
122 static constexpr HeaderSymbol AdditionalHeaderSymbols[] = {
123 {
"___mh_executable_header", 0}};
129 switch (
G.getTargetTriple().getArch()) {
150 auto HeaderContent =
G.allocateContent(
151 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
153 return G.createContentBlock(HeaderSection, HeaderContent,
ExecutorAddr(), 8,
163 for (
auto &HS : AdditionalHeaderSymbols)
174constexpr MachOHeaderMaterializationUnit::HeaderSymbol
175 MachOHeaderMaterializationUnit::AdditionalHeaderSymbols[];
178class MachOPlatformCompleteBootstrapMaterializationUnit
181 MachOPlatformCompleteBootstrapMaterializationUnit(
189 MOP(MOP), PlatformJDName(PlatformJDName),
190 CompleteBootstrapSymbol(std::move(CompleteBootstrapSymbol)),
191 DeferredAAs(std::move(DeferredAAs)),
192 PlatformBootstrap(PlatformBootstrap),
193 PlatformShutdown(PlatformShutdown), RegisterJITDylib(RegisterJITDylib),
194 DeregisterJITDylib(DeregisterJITDylib),
195 MachOHeaderAddr(MachOHeaderAddr) {}
198 return "MachOPlatformCompleteBootstrap";
201 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
202 using namespace jitlink;
203 auto G = createPlatformGraph(MOP,
"<OrcRTCompleteBootstrap>");
204 auto &PlaceholderSection =
205 G->createSection(
"__orc_rt_cplt_bs", MemProt::Read);
206 auto &PlaceholderBlock =
207 G->createZeroFillBlock(PlaceholderSection, 1,
ExecutorAddr(), 1, 0);
208 G->addDefinedSymbol(PlaceholderBlock, 0, *CompleteBootstrapSymbol, 1,
209 Linkage::Strong, Scope::Hidden,
false,
true);
212 G->allocActions().reserve(DeferredAAs.size() + 2);
215 G->allocActions().push_back(
221 G->allocActions().push_back(
224 RegisterJITDylib, PlatformJDName, MachOHeaderAddr)),
226 DeregisterJITDylib, MachOHeaderAddr))});
229 std::move(DeferredAAs.begin(), DeferredAAs.end(),
230 std::back_inserter(
G->allocActions()));
257 std::unique_ptr<DefinitionGenerator> OrcRuntime,
258 std::optional<SymbolAliasMap> RuntimeAliases) {
262 return make_error<StringError>(
"Unsupported MachOPlatform triple: " +
274 return std::move(Err);
277 if (
auto Err = PlatformJD.
define(
279 {EPC.getJITDispatchInfo().JITDispatchFunction,
281 {ES.
intern(
"___orc_rt_jit_dispatch_ctx"),
282 {EPC.getJITDispatchInfo().JITDispatchContext,
284 return std::move(Err);
289 ES, ObjLinkingLayer, PlatformJD, std::move(OrcRuntime), Err));
291 return std::move(Err);
297 JITDylib &PlatformJD,
const char *OrcRuntimePath,
298 std::optional<SymbolAliasMap> RuntimeAliases) {
301 auto OrcRuntimeArchiveGenerator =
303 if (!OrcRuntimeArchiveGenerator)
304 return OrcRuntimeArchiveGenerator.takeError();
306 return Create(ES, ObjLinkingLayer, PlatformJD,
307 std::move(*OrcRuntimeArchiveGenerator),
308 std::move(RuntimeAliases));
312 if (
auto Err = JD.
define(std::make_unique<MachOHeaderMaterializationUnit>(
313 *
this, MachOHeaderStartSymbol)))
316 return ES.
lookup({&JD}, MachOHeaderStartSymbol).takeError();
320 std::lock_guard<std::mutex> Lock(PlatformMutex);
321 auto I = JITDylibToHeaderAddr.find(&JD);
322 if (
I != JITDylibToHeaderAddr.end()) {
323 assert(HeaderAddrToJITDylib.count(
I->second) &&
324 "HeaderAddrToJITDylib missing entry");
325 HeaderAddrToJITDylib.erase(
I->second);
326 JITDylibToHeaderAddr.erase(
I);
328 JITDylibToPThreadKey.erase(&JD);
339 RegisteredInitSymbols[&JD].add(InitSym,
342 dbgs() <<
"MachOPlatform: Registered init symbol " << *InitSym <<
" for MU "
353 ArrayRef<std::pair<const char *, const char *>> AL) {
354 for (
auto &KV : AL) {
355 auto AliasName = ES.
intern(KV.first);
356 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
357 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
371 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
372 {
"___cxa_atexit",
"___orc_rt_macho_cxa_atexit"}};
379 static const std::pair<const char *, const char *>
380 StandardRuntimeUtilityAliases[] = {
381 {
"___orc_rt_run_program",
"___orc_rt_macho_run_program"},
382 {
"___orc_rt_jit_dlerror",
"___orc_rt_macho_jit_dlerror"},
383 {
"___orc_rt_jit_dlopen",
"___orc_rt_macho_jit_dlopen"},
384 {
"___orc_rt_jit_dlclose",
"___orc_rt_macho_jit_dlclose"},
385 {
"___orc_rt_jit_dlsym",
"___orc_rt_macho_jit_dlsym"},
386 {
"___orc_rt_log_error",
"___orc_rt_log_error_to_stderr"}};
389 StandardRuntimeUtilityAliases);
392bool MachOPlatform::supportedTarget(
const Triple &TT) {
393 switch (TT.getArch()) {
402MachOPlatform::MachOPlatform(
405 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
Error &Err)
406 : ES(ES), PlatformJD(PlatformJD), ObjLinkingLayer(ObjLinkingLayer) {
408 ObjLinkingLayer.
addPlugin(std::make_unique<MachOPlatformPlugin>(*
this));
409 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
469 if ((Err = PlatformJD.
define(std::make_unique<MachOHeaderMaterializationUnit>(
470 *
this, MachOHeaderStartSymbol))))
472 if ((Err = ES.
lookup(&PlatformJD, MachOHeaderStartSymbol).takeError()))
479 {PlatformBootstrap.Name, PlatformShutdown.Name,
480 RegisterJITDylib.Name, DeregisterJITDylib.Name,
481 RegisterObjectPlatformSections.Name,
482 DeregisterObjectPlatformSections.Name,
483 CreatePThreadKey.Name}))
489 std::unique_lock<std::mutex> Lock(BI.Mutex);
490 BI.CV.wait(Lock, [&]() {
return BI.ActiveGraphs == 0; });
495 auto BootstrapCompleteSymbol = ES.
intern(
"__orc_rt_macho_complete_bootstrap");
496 if ((Err = PlatformJD.
define(
497 std::make_unique<MachOPlatformCompleteBootstrapMaterializationUnit>(
498 *
this, PlatformJD.
getName(), BootstrapCompleteSymbol,
499 std::move(BI.DeferredAAs), PlatformBootstrap.Addr,
500 PlatformShutdown.Addr, RegisterJITDylib.Addr,
501 DeregisterJITDylib.Addr, BI.MachOHeaderAddr))))
505 std::move(BootstrapCompleteSymbol))
510 if ((Err = associateRuntimeSupportFunctions()))
514Error MachOPlatform::associateRuntimeSupportFunctions() {
517 using PushInitializersSPSSig =
519 WFs[ES.
intern(
"___orc_rt_macho_push_initializers_tag")] =
521 this, &MachOPlatform::rt_pushInitializers);
523 using LookupSymbolSPSSig =
525 WFs[ES.
intern(
"___orc_rt_macho_symbol_lookup_tag")] =
527 &MachOPlatform::rt_lookupSymbol);
532void MachOPlatform::pushInitializersLoop(
533 PushInitializersSendResultFn SendResult,
JITDylibSP JD) {
539 while (!Worklist.empty()) {
542 auto DepJD = Worklist.back();
546 if (JDDepMap.count(DepJD))
550 auto &DM = JDDepMap[DepJD];
551 DepJD->withLinkOrderDo([&](const JITDylibSearchOrder &O) {
553 if (KV.first == DepJD)
555 DM.push_back(KV.first);
556 Worklist.push_back(KV.first);
561 auto RISItr = RegisteredInitSymbols.find(DepJD);
562 if (RISItr != RegisteredInitSymbols.end()) {
563 NewInitSymbols[DepJD] = std::move(RISItr->second);
564 RegisteredInitSymbols.erase(RISItr);
571 if (NewInitSymbols.
empty()) {
580 std::lock_guard<std::mutex> Lock(PlatformMutex);
581 for (
auto &KV : JDDepMap) {
582 auto I = JITDylibToHeaderAddr.find(KV.first);
583 if (
I != JITDylibToHeaderAddr.end())
584 HeaderAddrs[KV.first] =
I->second;
589 MachOJITDylibDepInfoMap DIM;
590 DIM.reserve(JDDepMap.size());
591 for (
auto &KV : JDDepMap) {
592 auto HI = HeaderAddrs.
find(KV.first);
594 if (HI == HeaderAddrs.
end())
597 MachOJITDylibDepInfo DepInfo;
598 for (
auto &Dep : KV.second) {
599 auto HJ = HeaderAddrs.
find(Dep);
600 if (HJ != HeaderAddrs.
end())
601 DepInfo.DepHeaders.push_back(HJ->second);
603 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
610 lookupInitSymbolsAsync(
611 [
this, SendResult = std::move(SendResult), JD](
Error Err)
mutable {
613 SendResult(std::move(Err));
615 pushInitializersLoop(std::move(SendResult), JD);
617 ES, std::move(NewInitSymbols));
620void MachOPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
624 std::lock_guard<std::mutex> Lock(PlatformMutex);
625 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
626 if (
I != HeaderAddrToJITDylib.end())
631 dbgs() <<
"MachOPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
633 dbgs() <<
"pushing initializers for " << JD->getName() <<
"\n";
635 dbgs() <<
"No JITDylib for header address.\n";
640 make_error<StringError>(
"No JITDylib with header addr " +
646 pushInitializersLoop(std::move(SendResult), JD);
649void MachOPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
652 dbgs() <<
"MachOPlatform::rt_lookupSymbol(\""
659 std::lock_guard<std::mutex> Lock(PlatformMutex);
660 auto I = HeaderAddrToJITDylib.find(Handle);
661 if (
I != HeaderAddrToJITDylib.end())
667 dbgs() <<
" No JITDylib for handle "
670 SendResult(make_error<StringError>(
"No JITDylib associated with handle " +
677 class RtLookupNotifyComplete {
679 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
680 : SendResult(
std::
move(SendResult)) {}
683 assert(
Result->size() == 1 &&
"Unexpected result map count");
684 SendResult(
Result->begin()->second.getAddress());
686 SendResult(
Result.takeError());
691 SendSymbolAddressFn SendResult;
697 LookupKind::DLSym, {{JD, JITDylibLookupFlags::MatchExportedSymbolsOnly}},
703 if (!CreatePThreadKey.Addr)
704 return make_error<StringError>(
705 "Attempting to create pthread key in target, but runtime support has "
706 "not been loaded yet",
711 CreatePThreadKey.Addr,
Result))
712 return std::move(Err);
716void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
720 using namespace jitlink;
722 bool InBootstrapPhase =
726 if (InBootstrapPhase) {
728 [
this](LinkGraph &
G) {
return bootstrapPipelineStart(
G); });
730 return bootstrapPipelineRecordRuntimeFunctions(
G);
740 if (InitSymbol == MP.MachOHeaderStartSymbol && !InBootstrapPhase) {
742 return associateJITDylibHeaderSymbol(
G, MR);
751 if (
auto Err = preserveInitSections(
G, MR))
753 return processObjCImageInfo(
G, MR);
762 return fixTLVSectionsAndEdges(
G, JD);
769 return registerObjectPlatformSections(
G, JD, InBootstrapPhase);
774 if (InBootstrapPhase)
776 [
this](LinkGraph &
G) {
return bootstrapPipelineEnd(
G); });
780MachOPlatform::MachOPlatformPlugin::getSyntheticSymbolDependencies(
782 std::lock_guard<std::mutex> Lock(PluginMutex);
783 auto I = InitSymbolDeps.find(&MR);
784 if (
I != InitSymbolDeps.end()) {
785 SyntheticSymbolDependenciesMap
Result;
787 InitSymbolDeps.erase(&MR);
790 return SyntheticSymbolDependenciesMap();
793Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineStart(
796 std::lock_guard<std::mutex> Lock(MP.Bootstrap.load()->Mutex);
797 ++MP.Bootstrap.load()->ActiveGraphs;
801Error MachOPlatform::MachOPlatformPlugin::
804 std::pair<StringRef, ExecutorAddr *> RuntimeSymbols[] = {
805 {*MP.MachOHeaderStartSymbol, &MP.Bootstrap.load()->MachOHeaderAddr},
806 {*MP.PlatformBootstrap.Name, &MP.PlatformBootstrap.Addr},
807 {*MP.PlatformShutdown.Name, &MP.PlatformShutdown.Addr},
808 {*MP.RegisterJITDylib.Name, &MP.RegisterJITDylib.Addr},
809 {*MP.DeregisterJITDylib.Name, &MP.DeregisterJITDylib.Addr},
810 {*MP.RegisterObjectPlatformSections.Name,
811 &MP.RegisterObjectPlatformSections.Addr},
812 {*MP.DeregisterObjectPlatformSections.Name,
813 &MP.DeregisterObjectPlatformSections.Addr},
814 {*MP.CreatePThreadKey.Name, &MP.CreatePThreadKey.Addr}};
816 bool RegisterMachOHeader =
false;
818 for (
auto *Sym :
G.defined_symbols()) {
819 for (
auto &RTSym : RuntimeSymbols) {
820 if (Sym->hasName() && Sym->getName() == RTSym.first) {
822 return make_error<StringError>(
823 "Duplicate " + RTSym.first +
824 " detected during MachOPlatform bootstrap",
827 if (Sym->getName() == *MP.MachOHeaderStartSymbol)
828 RegisterMachOHeader =
true;
830 *RTSym.second = Sym->getAddress();
835 if (RegisterMachOHeader) {
838 std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
839 MP.JITDylibToHeaderAddr[&MP.PlatformJD] =
840 MP.Bootstrap.load()->MachOHeaderAddr;
841 MP.HeaderAddrToJITDylib[MP.Bootstrap.load()->MachOHeaderAddr] =
848Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineEnd(
850 std::lock_guard<std::mutex> Lock(MP.Bootstrap.load()->Mutex);
851 assert(MP.Bootstrap &&
"DeferredAAs reset before bootstrap completed");
852 --MP.Bootstrap.load()->ActiveGraphs;
855 if (MP.Bootstrap.load()->ActiveGraphs == 0)
856 MP.Bootstrap.load()->CV.notify_all();
860Error MachOPlatform::MachOPlatformPlugin::associateJITDylibHeaderSymbol(
863 return Sym->getName() == *MP.MachOHeaderStartSymbol;
865 assert(
I !=
G.defined_symbols().end() &&
"Missing MachO header start symbol");
868 std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
869 auto HeaderAddr = (*I)->getAddress();
870 MP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
871 MP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
874 G.allocActions().push_back(
877 MP.RegisterJITDylib.Addr, JD.getName(), HeaderAddr)),
879 MP.DeregisterJITDylib.Addr, HeaderAddr))});
883Error MachOPlatform::MachOPlatformPlugin::preserveInitSections(
886 JITLinkSymbolSet InitSectionSymbols;
889 auto *InitSection =
G.findSectionByName(InitSectionName);
896 for (
auto &Sym : InitSection->symbols()) {
897 auto &
B = Sym->getBlock();
898 if (Sym->isLive() && Sym->getOffset() == 0 &&
899 Sym->getSize() ==
B.getSize() && !AlreadyLiveBlocks.
count(&
B)) {
900 InitSectionSymbols.insert(Sym);
906 for (
auto *
B : InitSection->blocks())
907 if (!AlreadyLiveBlocks.
count(
B))
908 InitSectionSymbols.insert(
909 &
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true));
912 if (!InitSectionSymbols.empty()) {
913 std::lock_guard<std::mutex> Lock(PluginMutex);
914 InitSymbolDeps[&MR] = std::move(InitSectionSymbols);
920Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
933 auto ObjCImageInfoBlocks = ObjCImageInfo->blocks();
936 if (ObjCImageInfoBlocks.empty())
938 " section in " +
G.getName(),
942 if (std::next(ObjCImageInfoBlocks.begin()) != ObjCImageInfoBlocks.end())
943 return make_error<StringError>(
"Multiple blocks in " +
945 " section in " +
G.getName(),
950 for (
auto &Sec :
G.sections()) {
951 if (&Sec != ObjCImageInfo)
952 for (
auto *
B : Sec.blocks())
953 for (
auto &
E :
B->edges())
954 if (
E.getTarget().isDefined() &&
955 &
E.getTarget().getBlock().getSection() == ObjCImageInfo)
957 " is referenced within file " +
962 auto &ObjCImageInfoBlock = **ObjCImageInfoBlocks.begin();
963 auto *ObjCImageInfoData = ObjCImageInfoBlock.getContent().data();
969 std::lock_guard<std::mutex> Lock(PluginMutex);
972 if (ObjCImageInfoItr != ObjCImageInfos.end()) {
975 if (ObjCImageInfoItr->second.first != Version)
976 return make_error<StringError>(
977 "ObjC version in " +
G.getName() +
978 " does not match first registered version",
980 if (ObjCImageInfoItr->second.second != Flags)
981 return make_error<StringError>(
"ObjC flags in " +
G.getName() +
982 " do not match first registered flags",
986 for (
auto *S : ObjCImageInfo->symbols())
987 G.removeDefinedSymbol(*S);
988 G.removeBlock(ObjCImageInfoBlock);
998Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges(
1002 for (
auto *Sym :
G.external_symbols())
1003 if (Sym->getName() ==
"__tlv_bootstrap") {
1004 Sym->setName(
"___orc_rt_macho_tlv_get_addr");
1010 std::optional<uint64_t>
Key;
1012 std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
1013 auto I = MP.JITDylibToPThreadKey.find(&JD);
1014 if (
I != MP.JITDylibToPThreadKey.end())
1019 if (
auto KeyOrErr = MP.createPThreadKey())
1022 return KeyOrErr.takeError();
1028 for (
auto *
B : ThreadDataSec->blocks()) {
1029 if (
B->getSize() != 3 *
G.getPointerSize())
1030 return make_error<StringError>(
"__thread_vars block at " +
1031 formatv(
"{0:x}",
B->getAddress()) +
1032 " has unexpected size",
1035 auto NewBlockContent =
G.allocateBuffer(
B->getSize());
1036 llvm::copy(
B->getContent(), NewBlockContent.data());
1037 memcpy(NewBlockContent.data() +
G.getPointerSize(), &PlatformKeyBits,
1038 G.getPointerSize());
1039 B->setContent(NewBlockContent);
1044 for (
auto *
B :
G.blocks())
1045 for (
auto &
E :
B->edges())
1048 E.setKind(jitlink::x86_64::
1049 RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable);
1054std::optional<MachOPlatform::MachOPlatformPlugin::UnwindSections>
1055MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
1057 using namespace jitlink;
1065 if (Sec.blocks().empty())
1067 SecRange = (*Sec.blocks().begin())->getRange();
1068 for (
auto *
B : Sec.blocks()) {
1069 auto R =
B->getRange();
1070 SecRange.Start = std::min(SecRange.Start,
R.Start);
1071 SecRange.End = std::max(SecRange.End,
R.End);
1072 for (
auto &
E :
B->edges()) {
1073 if (!
E.getTarget().isDefined())
1075 auto &TargetBlock =
E.getTarget().getBlock();
1076 auto &TargetSection = TargetBlock.getSection();
1077 if ((TargetSection.getMemProt() & MemProt::Exec) == MemProt::Exec)
1084 ScanUnwindInfoSection(*EHFrameSec, US.DwarfSection);
1086 if (Section *CUInfoSec =
1088 ScanUnwindInfoSection(*CUInfoSec, US.CompactUnwindSection);
1092 if (CodeBlocks.
empty())
1093 return std::nullopt;
1098 return LHS->getAddress() <
RHS->getAddress();
1100 for (
auto *
B : CodeBlocks) {
1101 if (US.CodeRanges.empty() || US.CodeRanges.back().End !=
B->getAddress())
1102 US.CodeRanges.push_back(
B->getRange());
1104 US.CodeRanges.back().End =
B->getRange().End;
1108 dbgs() <<
"MachOPlatform identified unwind info in " <<
G.getName() <<
":\n"
1110 if (US.DwarfSection.Start)
1111 dbgs() << US.DwarfSection <<
"\n";
1114 dbgs() <<
" Compact-unwind: ";
1115 if (US.CompactUnwindSection.Start)
1116 dbgs() << US.CompactUnwindSection <<
"\n";
1119 <<
"for code ranges:\n";
1120 for (
auto &CR : US.CodeRanges)
1121 dbgs() <<
" " << CR <<
"\n";
1122 if (US.CodeRanges.size() >=
G.sections_size())
1123 dbgs() <<
"WARNING: High number of discontiguous code ranges! "
1124 "Padding may be interfering with coalescing.\n";
1130Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
1143 if (ThreadDataSection)
1144 G.mergeSections(*ThreadDataSection, *ThreadBSSSection);
1146 ThreadDataSection = ThreadBSSSection;
1155 for (
auto &SecName : DataSections) {
1156 if (
auto *Sec =
G.findSectionByName(SecName)) {
1159 MachOPlatformSecs.
push_back({SecName,
R.getRange()});
1165 if (ThreadDataSection) {
1180 for (
auto &SecName : PlatformSections) {
1181 auto *Sec =
G.findSectionByName(SecName);
1188 MachOPlatformSecs.
push_back({SecName,
R.getRange()});
1194 if (
auto UI = findUnwindSectionInfo(
G))
1195 UnwindInfo = std::make_tuple(std::move(UI->CodeRanges), UI->DwarfSection,
1196 UI->CompactUnwindSection);
1198 if (!MachOPlatformSecs.
empty() || UnwindInfo) {
1201 std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
1202 auto I = MP.JITDylibToHeaderAddr.find(&JD);
1203 assert(
I != MP.JITDylibToHeaderAddr.end() &&
1204 "Missing header for JITDylib");
1205 HeaderAddr =
I->second;
1210 dbgs() <<
"MachOPlatform: Scraped " <<
G.getName() <<
" init sections:\n";
1211 for (
auto &KV : MachOPlatformSecs)
1212 dbgs() <<
" " << KV.first <<
": " << KV.second <<
"\n";
1215 using SPSRegisterObjectPlatformSectionsArgs =
SPSArgList<
1223 : MP.Bootstrap.load()->DeferredAAs;
1225 allocActions.push_back(
1227 WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
1228 MP.RegisterObjectPlatformSections.Addr, HeaderAddr, UnwindInfo,
1229 MachOPlatformSecs)),
1231 WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
1232 MP.DeregisterObjectPlatformSections.Addr, HeaderAddr,
1233 UnwindInfo, MachOPlatformSecs))});
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_LIKELY(EXPR)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
Implements a dense probed hash-table based set.
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
const std::string & str() const
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
An Addressable with content and edges.
const std::string & getName() const
Get the name for this JITLinkDylib.
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
Represents an object file section.
An ExecutionSession represents a running JIT program.
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
const Triple & getTargetTriple() const
Return the triple for the executor.
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
static JITDispatchHandlerFunction wrapAsyncWithSPS(HandlerT &&H)
Wrap a handler that takes concrete argument types (and a sender for a concrete return type) to produc...
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Error registerJITDispatchHandlers(JITDylib &JD, JITDispatchHandlerAssociationMap WFs)
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of...
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Represents an address in the executor process.
uint64_t getValue() const
Represents a JIT'd dynamic library.
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization pseudo-symbol, if any.
JITDylib & getTargetJITDylib() const
Returns the target JITDylib that these symbols are being materialized into.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
virtual StringRef getName() const =0
Return the name of this materialization unit.
virtual void materialize(std::unique_ptr< MaterializationResponsibility > R)=0
Implementations of this method should materialize all symbols in the materialzation unit,...
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
An ObjectLayer implementation built on JITLink.
ObjectLinkingLayer & addPlugin(std::unique_ptr< Plugin > P)
Add a pass-config modifier.
void emit(std::unique_ptr< MaterializationResponsibility > R, std::unique_ptr< MemoryBuffer > O) override
Emit an object file.
API to remove / transfer ownership of JIT resources.
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load(ObjectLayer &L, const char *FileName, GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibraryDefinitionGenerator from the given path.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Pointer to a pooled string representing a symbol name.
A utility class for serializing to a blob from a variadic list.
SPS tag type for expecteds, which are either a T or a string representing an error.
SPS tag type for optionals.
Output char buffer with overflow check.
SPS tag type for sequences.
static bool serialize(SPSOutputBuffer &OB, const MachOPlatform::MachOJITDylibDepInfo &DDI)
static size_t size(const MachOPlatform::MachOJITDylibDepInfo &DDI)
static bool deserialize(SPSInputBuffer &IB, MachOPlatform::MachOJITDylibDepInfo &DDI)
Specialize to describe how to serialize/deserialize to/from the given concrete type.
static Expected< WrapperFunctionCall > Create(ExecutorAddr FnAddr, const ArgTs &...Args)
Create a WrapperFunctionCall using the given SPS serializer to serialize the arguments.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
void swapStruct(fat_header &mh)
constexpr uint64_t PointerSize
aarch64 pointer size.
@ RequestTLVPAndTransformToPCRel32TLVPLoadREXRelaxable
A TLVP entry getter/constructor, transformed to Delta32ToTLVPLoadREXRelaxable.
const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
SPSTuple< SPSExecutorAddr, SPSExecutorAddr > SPSExecutorAddrRange
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
StringRef MachOThreadBSSSectionName
StringRef MachOThreadVarsSectionName
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
StringRef MachOCompactUnwindInfoSectionName
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
StringRef MachOSwift5ProtosSectionName
StringRef MachOEHFrameSectionName
StringRef MachOModInitFuncSectionName
StringRef MachODataDataSectionName
StringRef MachOSwift5ProtoSectionName
static void addAliases(ExecutionSession &ES, SymbolAliasMap &Aliases, ArrayRef< std::pair< const char *, const char * > > AL)
StringRef MachOObjCClassListSectionName
StringRef MachOObjCSelRefsSectionName
StringRef MachOInitSectionNames[6]
StringRef MachOSwift5TypesSectionName
StringRef MachOObjCImageInfoSectionName
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
StringRef MachOThreadDataSectionName
StringRef MachODataCommonSectionName
value_type byte_swap(value_type value, endianness endian)
uint32_t read32(const void *P, endianness E)
constexpr endianness system_endianness()
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
OutputIt copy(R &&Range, OutputIt Out)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
LinkGraphPassList PostAllocationPasses
Post-allocation passes.
LinkGraphPassList PostFixupPasses
Post-fixup passes.
LinkGraphPassList PostPrunePasses
Post-prune passes.
LinkGraphPassList PrePrunePasses
Pre-prune passes.
Represents an address range in the exceutor process.