20#define DEBUG_TYPE "orc"
44 return SPSMachOJITDylibDepInfo::AsArgList::serialize(OB, DDI.
Sealed,
50 return SPSMachOJITDylibDepInfo::AsArgList::deserialize(IB, DDI.
Sealed,
61std::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.allocateString(
151 StringRef(
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()));
249StringRef DataCommonSectionName =
"__DATA,__common";
250StringRef DataDataSectionName =
"__DATA,__data";
251StringRef EHFrameSectionName =
"__TEXT,__eh_frame";
252StringRef CompactUnwindInfoSectionName =
"__TEXT,__unwind_info";
253StringRef ModInitFuncSectionName =
"__DATA,__mod_init_func";
254StringRef ObjCClassListSectionName =
"__DATA,__objc_classlist";
255StringRef ObjCImageInfoSectionName =
"__DATA,__objc_image_info";
256StringRef ObjCSelRefsSectionName =
"__DATA,__objc_selrefs";
257StringRef Swift5ProtoSectionName =
"__TEXT,__swift5_proto";
258StringRef Swift5ProtosSectionName =
"__TEXT,__swift5_protos";
259StringRef Swift5TypesSectionName =
"__TEXT,__swift5_types";
260StringRef ThreadBSSSectionName =
"__DATA,__thread_bss";
261StringRef ThreadDataSectionName =
"__DATA,__thread_data";
262StringRef ThreadVarsSectionName =
"__DATA,__thread_vars";
265 ModInitFuncSectionName, ObjCSelRefsSectionName, ObjCClassListSectionName,
266 Swift5ProtosSectionName, Swift5ProtoSectionName, Swift5TypesSectionName};
275 JITDylib &PlatformJD,
const char *OrcRuntimePath,
276 std::optional<SymbolAliasMap> RuntimeAliases) {
281 if (!supportedTarget(EPC.getTargetTriple()))
282 return make_error<StringError>(
"Unsupported MachOPlatform triple: " +
283 EPC.getTargetTriple().str(),
292 return std::move(Err);
296 {{ES.
intern(
"___orc_rt_jit_dispatch"),
297 {EPC.getJITDispatchInfo().JITDispatchFunction.getValue(),
299 {ES.
intern(
"___orc_rt_jit_dispatch_ctx"),
300 {EPC.getJITDispatchInfo().JITDispatchContext.getValue(),
302 return std::move(Err);
306 ObjLinkingLayer, OrcRuntimePath, EPC.getTargetTriple());
307 if (!OrcRuntimeArchiveGenerator)
308 return OrcRuntimeArchiveGenerator.takeError();
312 auto P = std::unique_ptr<MachOPlatform>(
314 std::move(*OrcRuntimeArchiveGenerator), Err));
316 return std::move(Err);
321 if (
auto Err = JD.
define(std::make_unique<MachOHeaderMaterializationUnit>(
322 *
this, MachOHeaderStartSymbol)))
325 return ES.
lookup({&JD}, MachOHeaderStartSymbol).takeError();
329 std::lock_guard<std::mutex> Lock(PlatformMutex);
330 auto I = JITDylibToHeaderAddr.find(&JD);
331 if (
I != JITDylibToHeaderAddr.end()) {
332 assert(HeaderAddrToJITDylib.count(
I->second) &&
333 "HeaderAddrToJITDylib missing entry");
334 HeaderAddrToJITDylib.erase(
I->second);
335 JITDylibToHeaderAddr.erase(
I);
337 JITDylibToPThreadKey.erase(&JD);
348 RegisteredInitSymbols[&JD].add(InitSym,
351 dbgs() <<
"MachOPlatform: Registered init symbol " << *InitSym <<
" for MU "
362 ArrayRef<std::pair<const char *, const char *>> AL) {
363 for (
auto &KV : AL) {
364 auto AliasName = ES.
intern(KV.first);
365 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
366 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
380 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
381 {
"___cxa_atexit",
"___orc_rt_macho_cxa_atexit"}};
388 static const std::pair<const char *, const char *>
389 StandardRuntimeUtilityAliases[] = {
390 {
"___orc_rt_run_program",
"___orc_rt_macho_run_program"},
391 {
"___orc_rt_jit_dlerror",
"___orc_rt_macho_jit_dlerror"},
392 {
"___orc_rt_jit_dlopen",
"___orc_rt_macho_jit_dlopen"},
393 {
"___orc_rt_jit_dlclose",
"___orc_rt_macho_jit_dlclose"},
394 {
"___orc_rt_jit_dlsym",
"___orc_rt_macho_jit_dlsym"},
395 {
"___orc_rt_log_error",
"___orc_rt_log_error_to_stderr"}};
398 StandardRuntimeUtilityAliases);
403 for (
auto &
Name : InitSectionNames) {
404 if (
Name.startswith(SegName) &&
Name.substr(7) == SectName)
410bool MachOPlatform::supportedTarget(
const Triple &TT) {
411 switch (TT.getArch()) {
420MachOPlatform::MachOPlatform(
423 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
Error &Err)
424 : ES(ES), PlatformJD(PlatformJD), ObjLinkingLayer(ObjLinkingLayer) {
426 ObjLinkingLayer.
addPlugin(std::make_unique<MachOPlatformPlugin>(*
this));
427 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
487 if ((Err = PlatformJD.
define(std::make_unique<MachOHeaderMaterializationUnit>(
488 *
this, MachOHeaderStartSymbol))))
490 if ((Err = ES.
lookup(&PlatformJD, MachOHeaderStartSymbol).takeError()))
497 {PlatformBootstrap.Name, PlatformShutdown.Name,
498 RegisterJITDylib.Name, DeregisterJITDylib.Name,
499 RegisterObjectPlatformSections.Name,
500 DeregisterObjectPlatformSections.Name,
501 CreatePThreadKey.Name}))
507 std::unique_lock<std::mutex> Lock(BI.Mutex);
508 BI.CV.wait(Lock, [&]() {
return BI.ActiveGraphs == 0; });
513 auto BootstrapCompleteSymbol = ES.
intern(
"__orc_rt_macho_complete_bootstrap");
514 if ((Err = PlatformJD.
define(
515 std::make_unique<MachOPlatformCompleteBootstrapMaterializationUnit>(
516 *
this, PlatformJD.
getName(), BootstrapCompleteSymbol,
517 std::move(BI.DeferredAAs), PlatformBootstrap.Addr,
518 PlatformShutdown.Addr, RegisterJITDylib.Addr,
519 DeregisterJITDylib.Addr, BI.MachOHeaderAddr))))
523 std::move(BootstrapCompleteSymbol))
528 if ((Err = associateRuntimeSupportFunctions()))
532Error MachOPlatform::associateRuntimeSupportFunctions() {
535 using PushInitializersSPSSig =
537 WFs[ES.
intern(
"___orc_rt_macho_push_initializers_tag")] =
539 this, &MachOPlatform::rt_pushInitializers);
541 using LookupSymbolSPSSig =
543 WFs[ES.
intern(
"___orc_rt_macho_symbol_lookup_tag")] =
545 &MachOPlatform::rt_lookupSymbol);
550void MachOPlatform::pushInitializersLoop(
551 PushInitializersSendResultFn SendResult,
JITDylibSP JD) {
557 while (!Worklist.empty()) {
560 auto DepJD = Worklist.back();
564 if (JDDepMap.count(DepJD))
568 auto &DM = JDDepMap[DepJD];
569 DepJD->withLinkOrderDo([&](const JITDylibSearchOrder &O) {
571 if (KV.first == DepJD)
573 DM.push_back(KV.first);
574 Worklist.push_back(KV.first);
579 auto RISItr = RegisteredInitSymbols.find(DepJD);
580 if (RISItr != RegisteredInitSymbols.end()) {
581 NewInitSymbols[DepJD] = std::move(RISItr->second);
582 RegisteredInitSymbols.erase(RISItr);
589 if (NewInitSymbols.
empty()) {
598 std::lock_guard<std::mutex> Lock(PlatformMutex);
599 for (
auto &KV : JDDepMap) {
600 auto I = JITDylibToHeaderAddr.find(KV.first);
601 if (
I != JITDylibToHeaderAddr.end())
602 HeaderAddrs[KV.first] =
I->second;
607 MachOJITDylibDepInfoMap DIM;
608 DIM.reserve(JDDepMap.size());
609 for (
auto &KV : JDDepMap) {
610 auto HI = HeaderAddrs.
find(KV.first);
612 if (HI == HeaderAddrs.
end())
615 MachOJITDylibDepInfo DepInfo;
616 for (
auto &Dep : KV.second) {
617 auto HJ = HeaderAddrs.
find(Dep);
618 if (HJ != HeaderAddrs.
end())
619 DepInfo.DepHeaders.push_back(HJ->second);
621 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
628 lookupInitSymbolsAsync(
629 [
this, SendResult = std::move(SendResult), JD](
Error Err)
mutable {
631 SendResult(std::move(Err));
633 pushInitializersLoop(std::move(SendResult), JD);
635 ES, std::move(NewInitSymbols));
638void MachOPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
642 std::lock_guard<std::mutex> Lock(PlatformMutex);
643 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
644 if (
I != HeaderAddrToJITDylib.end())
649 dbgs() <<
"MachOPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
651 dbgs() <<
"pushing initializers for " << JD->getName() <<
"\n";
653 dbgs() <<
"No JITDylib for header address.\n";
658 make_error<StringError>(
"No JITDylib with header addr " +
664 pushInitializersLoop(std::move(SendResult), JD);
667void MachOPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
670 dbgs() <<
"MachOPlatform::rt_lookupSymbol(\""
677 std::lock_guard<std::mutex> Lock(PlatformMutex);
678 auto I = HeaderAddrToJITDylib.find(Handle);
679 if (
I != HeaderAddrToJITDylib.end())
685 dbgs() <<
" No JITDylib for handle "
688 SendResult(make_error<StringError>(
"No JITDylib associated with handle " +
695 class RtLookupNotifyComplete {
697 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
698 : SendResult(
std::
move(SendResult)) {}
701 assert(
Result->size() == 1 &&
"Unexpected result map count");
704 SendResult(
Result.takeError());
709 SendSymbolAddressFn SendResult;
715 LookupKind::DLSym, {{JD, JITDylibLookupFlags::MatchExportedSymbolsOnly}},
721 if (!CreatePThreadKey.Addr)
722 return make_error<StringError>(
723 "Attempting to create pthread key in target, but runtime support has "
724 "not been loaded yet",
729 CreatePThreadKey.Addr,
Result))
730 return std::move(Err);
734void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(
738 using namespace jitlink;
740 bool InBootstrapPhase =
744 if (InBootstrapPhase) {
746 [
this](LinkGraph &
G) {
return bootstrapPipelineStart(
G); });
748 return bootstrapPipelineRecordRuntimeFunctions(
G);
758 if (InitSymbol == MP.MachOHeaderStartSymbol && !InBootstrapPhase) {
760 return associateJITDylibHeaderSymbol(
G, MR);
769 if (
auto Err = preserveInitSections(
G, MR))
771 return processObjCImageInfo(
G, MR);
780 return fixTLVSectionsAndEdges(
G, JD);
787 return registerObjectPlatformSections(
G, JD, InBootstrapPhase);
792 if (InBootstrapPhase)
794 [
this](LinkGraph &
G) {
return bootstrapPipelineEnd(
G); });
798MachOPlatform::MachOPlatformPlugin::getSyntheticSymbolDependencies(
800 std::lock_guard<std::mutex> Lock(PluginMutex);
801 auto I = InitSymbolDeps.find(&MR);
802 if (
I != InitSymbolDeps.end()) {
803 SyntheticSymbolDependenciesMap
Result;
805 InitSymbolDeps.erase(&MR);
808 return SyntheticSymbolDependenciesMap();
811Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineStart(
814 std::lock_guard<std::mutex> Lock(MP.Bootstrap.load()->Mutex);
815 ++MP.Bootstrap.load()->ActiveGraphs;
819Error MachOPlatform::MachOPlatformPlugin::
822 std::pair<StringRef, ExecutorAddr *> RuntimeSymbols[] = {
823 {*MP.MachOHeaderStartSymbol, &MP.Bootstrap.load()->MachOHeaderAddr},
824 {*MP.PlatformBootstrap.Name, &MP.PlatformBootstrap.Addr},
825 {*MP.PlatformShutdown.Name, &MP.PlatformShutdown.Addr},
826 {*MP.RegisterJITDylib.Name, &MP.RegisterJITDylib.Addr},
827 {*MP.DeregisterJITDylib.Name, &MP.DeregisterJITDylib.Addr},
828 {*MP.RegisterObjectPlatformSections.Name,
829 &MP.RegisterObjectPlatformSections.Addr},
830 {*MP.DeregisterObjectPlatformSections.Name,
831 &MP.DeregisterObjectPlatformSections.Addr},
832 {*MP.CreatePThreadKey.Name, &MP.CreatePThreadKey.Addr}};
834 bool RegisterMachOHeader =
false;
836 for (
auto *Sym :
G.defined_symbols()) {
837 for (
auto &RTSym : RuntimeSymbols) {
838 if (Sym->hasName() && Sym->getName() == RTSym.first) {
840 return make_error<StringError>(
841 "Duplicate " + RTSym.first +
842 " detected during MachOPlatform bootstrap",
845 if (Sym->getName() == *MP.MachOHeaderStartSymbol)
846 RegisterMachOHeader =
true;
848 *RTSym.second = Sym->getAddress();
853 if (RegisterMachOHeader) {
856 std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
857 MP.JITDylibToHeaderAddr[&MP.PlatformJD] =
858 MP.Bootstrap.load()->MachOHeaderAddr;
859 MP.HeaderAddrToJITDylib[MP.Bootstrap.load()->MachOHeaderAddr] =
866Error MachOPlatform::MachOPlatformPlugin::bootstrapPipelineEnd(
868 std::lock_guard<std::mutex> Lock(MP.Bootstrap.load()->Mutex);
869 assert(MP.Bootstrap &&
"DeferredAAs reset before bootstrap completed");
870 --MP.Bootstrap.load()->ActiveGraphs;
873 if (MP.Bootstrap.load()->ActiveGraphs == 0)
874 MP.Bootstrap.load()->CV.notify_all();
878Error MachOPlatform::MachOPlatformPlugin::associateJITDylibHeaderSymbol(
881 return Sym->getName() == *MP.MachOHeaderStartSymbol;
883 assert(
I !=
G.defined_symbols().end() &&
"Missing MachO header start symbol");
886 std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
887 auto HeaderAddr = (*I)->getAddress();
888 MP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
889 MP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
892 G.allocActions().push_back(
895 MP.RegisterJITDylib.Addr, JD.getName(), HeaderAddr)),
897 MP.DeregisterJITDylib.Addr, HeaderAddr))});
901Error MachOPlatform::MachOPlatformPlugin::preserveInitSections(
904 JITLinkSymbolSet InitSectionSymbols;
905 for (
auto &InitSectionName : InitSectionNames) {
907 auto *InitSection =
G.findSectionByName(InitSectionName);
914 for (
auto &Sym : InitSection->symbols()) {
915 auto &
B = Sym->getBlock();
916 if (Sym->isLive() && Sym->getOffset() == 0 &&
917 Sym->getSize() ==
B.getSize() && !AlreadyLiveBlocks.
count(&
B)) {
918 InitSectionSymbols.insert(Sym);
924 for (
auto *
B : InitSection->blocks())
925 if (!AlreadyLiveBlocks.
count(
B))
926 InitSectionSymbols.insert(
927 &
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true));
930 if (!InitSectionSymbols.empty()) {
931 std::lock_guard<std::mutex> Lock(PluginMutex);
932 InitSymbolDeps[&MR] = std::move(InitSectionSymbols);
938Error MachOPlatform::MachOPlatformPlugin::processObjCImageInfo(
947 auto *ObjCImageInfo =
G.findSectionByName(ObjCImageInfoSectionName);
951 auto ObjCImageInfoBlocks = ObjCImageInfo->blocks();
954 if (ObjCImageInfoBlocks.empty())
955 return make_error<StringError>(
"Empty " + ObjCImageInfoSectionName +
956 " section in " +
G.getName(),
960 if (std::next(ObjCImageInfoBlocks.begin()) != ObjCImageInfoBlocks.end())
961 return make_error<StringError>(
"Multiple blocks in " +
962 ObjCImageInfoSectionName +
963 " section in " +
G.getName(),
968 for (
auto &Sec :
G.sections()) {
969 if (&Sec != ObjCImageInfo)
970 for (
auto *
B : Sec.blocks())
971 for (
auto &
E :
B->edges())
972 if (
E.getTarget().isDefined() &&
973 &
E.getTarget().getBlock().getSection() == ObjCImageInfo)
974 return make_error<StringError>(ObjCImageInfoSectionName +
975 " is referenced within file " +
980 auto &ObjCImageInfoBlock = **ObjCImageInfoBlocks.begin();
981 auto *ObjCImageInfoData = ObjCImageInfoBlock.getContent().data();
987 std::lock_guard<std::mutex> Lock(PluginMutex);
990 if (ObjCImageInfoItr != ObjCImageInfos.end()) {
993 if (ObjCImageInfoItr->second.first != Version)
994 return make_error<StringError>(
995 "ObjC version in " +
G.getName() +
996 " does not match first registered version",
998 if (ObjCImageInfoItr->second.second != Flags)
999 return make_error<StringError>(
"ObjC flags in " +
G.getName() +
1000 " do not match first registered flags",
1004 for (
auto *S : ObjCImageInfo->symbols())
1005 G.removeDefinedSymbol(*S);
1006 G.removeBlock(ObjCImageInfoBlock);
1016Error MachOPlatform::MachOPlatformPlugin::fixTLVSectionsAndEdges(
1020 for (
auto *Sym :
G.external_symbols())
1021 if (Sym->getName() ==
"__tlv_bootstrap") {
1022 Sym->setName(
"___orc_rt_macho_tlv_get_addr");
1027 if (
auto *ThreadDataSec =
G.findSectionByName(ThreadVarsSectionName)) {
1028 std::optional<uint64_t>
Key;
1030 std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
1031 auto I = MP.JITDylibToPThreadKey.find(&JD);
1032 if (
I != MP.JITDylibToPThreadKey.end())
1037 if (
auto KeyOrErr = MP.createPThreadKey())
1040 return KeyOrErr.takeError();
1046 for (
auto *
B : ThreadDataSec->blocks()) {
1047 if (
B->getSize() != 3 *
G.getPointerSize())
1048 return make_error<StringError>(
"__thread_vars block at " +
1049 formatv(
"{0:x}",
B->getAddress()) +
1050 " has unexpected size",
1053 auto NewBlockContent =
G.allocateBuffer(
B->getSize());
1054 llvm::copy(
B->getContent(), NewBlockContent.data());
1055 memcpy(NewBlockContent.data() +
G.getPointerSize(), &PlatformKeyBits,
1056 G.getPointerSize());
1057 B->setContent(NewBlockContent);
1062 for (
auto *
B :
G.blocks())
1063 for (
auto &
E :
B->edges())
1066 E.setKind(jitlink::x86_64::
1067 RequestGOTAndTransformToPCRel32GOTLoadREXRelaxable);
1072std::optional<MachOPlatform::MachOPlatformPlugin::UnwindSections>
1073MachOPlatform::MachOPlatformPlugin::findUnwindSectionInfo(
1075 using namespace jitlink;
1083 if (Sec.blocks().empty())
1085 SecRange = (*Sec.blocks().begin())->getRange();
1086 for (
auto *
B : Sec.blocks()) {
1087 auto R =
B->getRange();
1088 SecRange.Start = std::min(SecRange.Start,
R.Start);
1089 SecRange.End = std::max(SecRange.End,
R.End);
1090 for (
auto &
E :
B->edges()) {
1091 if (!
E.getTarget().isDefined())
1093 auto &TargetBlock =
E.getTarget().getBlock();
1094 auto &TargetSection = TargetBlock.getSection();
1095 if ((TargetSection.getMemProt() & MemProt::Exec) == MemProt::Exec)
1101 if (Section *EHFrameSec =
G.findSectionByName(EHFrameSectionName))
1102 ScanUnwindInfoSection(*EHFrameSec, US.DwarfSection);
1104 if (Section *CUInfoSec =
G.findSectionByName(CompactUnwindInfoSectionName))
1105 ScanUnwindInfoSection(*CUInfoSec, US.CompactUnwindSection);
1109 if (CodeBlocks.
empty())
1110 return std::nullopt;
1115 return LHS->getAddress() <
RHS->getAddress();
1117 for (
auto *
B : CodeBlocks) {
1118 if (US.CodeRanges.empty() || US.CodeRanges.back().End !=
B->getAddress())
1119 US.CodeRanges.push_back(
B->getRange());
1121 US.CodeRanges.back().End =
B->getRange().End;
1125 dbgs() <<
"MachOPlatform identified unwind info in " <<
G.getName() <<
":\n"
1127 if (US.DwarfSection.Start)
1128 dbgs() << US.DwarfSection <<
"\n";
1131 dbgs() <<
" Compact-unwind: ";
1132 if (US.CompactUnwindSection.Start)
1133 dbgs() << US.CompactUnwindSection <<
"\n";
1136 <<
"for code ranges:\n";
1137 for (
auto &CR : US.CodeRanges)
1138 dbgs() <<
" " << CR <<
"\n";
1139 if (US.CodeRanges.size() >=
G.sections_size())
1140 dbgs() <<
"WARNING: High number of discontiguous code ranges! "
1141 "Padding may be interfering with coalescing.\n";
1147Error MachOPlatform::MachOPlatformPlugin::registerObjectPlatformSections(
1153 G.findSectionByName(ThreadDataSectionName);
1156 if (
auto *ThreadBSSSection =
G.findSectionByName(ThreadBSSSectionName)) {
1160 if (ThreadDataSection)
1161 G.mergeSections(*ThreadDataSection, *ThreadBSSSection);
1163 ThreadDataSection = ThreadBSSSection;
1169 StringRef DataSections[] = {DataDataSectionName, DataCommonSectionName,
1170 EHFrameSectionName};
1171 for (
auto &SecName : DataSections) {
1172 if (
auto *Sec =
G.findSectionByName(SecName)) {
1175 MachOPlatformSecs.
push_back({SecName,
R.getRange()});
1181 if (ThreadDataSection) {
1184 MachOPlatformSecs.
push_back({ThreadDataSectionName,
R.getRange()});
1190 ModInitFuncSectionName, ObjCClassListSectionName,
1191 ObjCImageInfoSectionName, ObjCSelRefsSectionName,
1192 Swift5ProtoSectionName, Swift5ProtosSectionName,
1193 Swift5TypesSectionName,
1196 for (
auto &SecName : PlatformSections) {
1197 auto *Sec =
G.findSectionByName(SecName);
1204 MachOPlatformSecs.
push_back({SecName,
R.getRange()});
1210 if (
auto UI = findUnwindSectionInfo(
G))
1211 UnwindInfo = std::make_tuple(std::move(UI->CodeRanges), UI->DwarfSection,
1212 UI->CompactUnwindSection);
1214 if (!MachOPlatformSecs.
empty() || UnwindInfo) {
1217 std::lock_guard<std::mutex> Lock(MP.PlatformMutex);
1218 auto I = MP.JITDylibToHeaderAddr.find(&JD);
1219 assert(
I != MP.JITDylibToHeaderAddr.end() &&
1220 "Missing header for JITDylib");
1221 HeaderAddr =
I->second;
1226 dbgs() <<
"MachOPlatform: Scraped " <<
G.getName() <<
" init sections:\n";
1227 for (
auto &KV : MachOPlatformSecs)
1228 dbgs() <<
" " << KV.first <<
": " << KV.second <<
"\n";
1231 using SPSRegisterObjectPlatformSectionsArgs =
SPSArgList<
1239 : MP.Bootstrap.load()->DeferredAAs;
1241 allocActions.push_back(
1243 WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
1244 MP.RegisterObjectPlatformSections.Addr, HeaderAddr, UnwindInfo,
1245 MachOPlatformSecs)),
1247 WrapperFunctionCall::Create<SPSRegisterObjectPlatformSectionsArgs>(
1248 MP.DeregisterObjectPlatformSections.Addr, HeaderAddr,
1249 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.
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.
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
const Triple & getTargetTriple() const
Return the Triple for the target process.
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.
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...
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.
static void addAliases(ExecutionSession &ES, SymbolAliasMap &Aliases, ArrayRef< std::pair< const char *, const char * > > AL)
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
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.