26#define DEBUG_TYPE "orc"
58 StringRef
getName()
const override {
return "COFFHeaderMU"; }
60 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
61 auto G = std::make_unique<jitlink::LinkGraph>(
62 "<COFFHeaderMU>", CP.getExecutionSession().getSymbolStringPool(),
63 CP.getExecutionSession().getTargetTriple(), SubtargetFeatures(),
65 auto &HeaderSection =
G->createSection(
"__header", MemProt::Read);
69 auto &ImageBaseSymbol =
G->addDefinedSymbol(
70 HeaderBlock, 0, *
R->getInitializerSymbol(), HeaderBlock.getSize(),
71 jitlink::Linkage::Strong, jitlink::Scope::Default,
false,
true);
73 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
75 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
78 void discard(
const JITDylib &JD,
const SymbolStringPtr &Sym)
override {}
88 object::coff_file_header FileHeader;
90 object::pe32plus_header Header;
95 struct HeaderBlockContent {
96 object::dos_header DOSHeader;
97 COFFHeaderMaterializationUnit::NTHeader NTHeader;
101 jitlink::Section &HeaderSection) {
102 HeaderBlockContent Hdr = {};
105 Hdr.DOSHeader.Magic[0] =
'M';
106 Hdr.DOSHeader.Magic[1] =
'Z';
107 Hdr.DOSHeader.AddressOfNewExeHeader =
108 offsetof(HeaderBlockContent, NTHeader);
109 uint32_t PEMagic = *
reinterpret_cast<const uint32_t *
>(
COFF::PEMagic);
110 Hdr.NTHeader.PEMagic = PEMagic;
113 switch (
G.getTargetTriple().getArch()) {
121 auto HeaderContent =
G.allocateContent(
122 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
124 return G.createContentBlock(HeaderSection, HeaderContent, ExecutorAddr(), 8,
128 static void addImageBaseRelocationEdge(jitlink::Block &
B,
129 jitlink::Symbol &ImageBase) {
130 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
131 offsetof(NTHeader, OptionalHeader) +
132 offsetof(object::pe32plus_header, ImageBase);
136 static MaterializationUnit::Interface
137 createHeaderInterface(COFFPlatform &MOP,
138 const SymbolStringPtr &HeaderStartSymbol) {
143 return MaterializationUnit::Interface(std::move(HeaderSymbolFlags),
155Expected<std::unique_ptr<COFFPlatform>>
157 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
159 const char *VCRuntimePath,
160 std::optional<SymbolAliasMap> RuntimeAliases) {
162 auto &ES = ObjLinkingLayer.getExecutionSession();
165 if (!supportedTarget(ES.getTargetTriple()))
167 ES.getTargetTriple().str(),
170 auto GeneratorArchive =
172 if (!GeneratorArchive)
173 return GeneratorArchive.takeError();
175 std::set<std::string> DylibsToPreload;
177 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive),
179 if (!OrcRuntimeArchiveGenerator)
180 return OrcRuntimeArchiveGenerator.takeError();
194 return std::move(Err);
199 ES.getBootstrapJITDylib(),
200 {{ES.intern(rt::DispatchName), ES.intern(rt::DispatchCtxName)}});
202 return Exports.takeError();
211 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
212 std::move(DylibsToPreload), std::move(OrcRuntimeArchiveBuffer),
213 std::move(RuntimeArchive), std::move(LoadDynLibrary), StaticVCRuntime,
214 VCRuntimePath, Err));
216 return std::move(Err);
222 const char *OrcRuntimePath,
224 const char *VCRuntimePath,
225 std::optional<SymbolAliasMap> RuntimeAliases) {
231 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
232 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
233 std::move(RuntimeAliases));
237 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
245 auto Buffer = (*PerJDObj)->getAsBinary();
247 return Buffer.takeError();
249 return (*Buffer)->getMemoryBufferRef();
253 ArrayRef<std::pair<const char *, const char *>> AL) {
254 for (
auto &KV : AL) {
255 auto AliasName = ES.
intern(KV.first);
256 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
257 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
263 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
264 *
this, COFFHeaderStartSymbol)))
267 if (
auto Err = ES.lookup({&JD}, COFFHeaderStartSymbol).takeError())
276 auto PerJDObj = getPerJDObjectFile();
278 return PerJDObj.takeError();
282 return I.takeError();
284 if (
auto Err = ObjLinkingLayer.add(
288 if (!Bootstrapping) {
289 auto ImportedLibs = StaticVCRuntime
290 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
291 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
293 return ImportedLibs.takeError();
294 for (
auto &
Lib : *ImportedLibs)
295 if (
auto Err = LoadDynLibrary(JD,
Lib))
298 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
307 std::lock_guard<std::mutex> Lock(PlatformMutex);
308 auto I = JITDylibToHeaderAddr.find(&JD);
309 if (
I != JITDylibToHeaderAddr.end()) {
310 assert(HeaderAddrToJITDylib.count(
I->second) &&
311 "HeaderAddrToJITDylib missing entry");
312 HeaderAddrToJITDylib.erase(
I->second);
313 JITDylibToHeaderAddr.erase(
I);
325 RegisteredInitSymbols[&JD].add(InitSym,
329 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
347 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
348 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
349 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
350 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
357 static const std::pair<const char *, const char *>
358 StandardRuntimeUtilityAliases[] = {
359 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
360 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
361 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
362 {
"__orc_rt_jit_dlupdate",
"__orc_rt_coff_jit_dlupdate"},
363 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
364 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
365 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
368 StandardRuntimeUtilityAliases);
371bool COFFPlatform::supportedTarget(
const Triple &TT) {
372 switch (TT.getArch()) {
380COFFPlatform::COFFPlatform(
382 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
383 std::set<std::string> DylibsToPreload,
384 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
385 std::unique_ptr<object::Archive> OrcRuntimeArchive,
386 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
387 const char *VCRuntimePath,
Error &Err)
388 : ES(ObjLinkingLayer.getExecutionSession()),
389 ObjLinkingLayer(ObjLinkingLayer),
390 LoadDynLibrary(
std::
move(LoadDynLibrary)),
391 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
392 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
393 StaticVCRuntime(StaticVCRuntime),
394 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
397 Bootstrapping.store(
true);
398 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
404 Err = VCRT.takeError();
407 VCRuntimeBootstrap = std::move(*VCRT);
410 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
411 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
413 Err = ImportedLibs.takeError();
417 for (
auto &
Lib : *ImportedLibs)
418 DylibsToPreload.insert(
Lib);
420 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
429 for (
auto&
Lib : DylibsToPreload)
430 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
436 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
442 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
450 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
455 Bootstrapping.store(
false);
456 JDBootstrapStates.clear();
459Expected<COFFPlatform::JITDylibDepMap>
460COFFPlatform::buildJDDepMap(
JITDylib &JD) {
461 return ES.runSessionLocked([&]() -> Expected<JITDylibDepMap> {
462 JITDylibDepMap JDDepMap;
465 while (!Worklist.empty()) {
466 auto CurJD = Worklist.back();
469 auto &
DM = JDDepMap[CurJD];
471 DM.reserve(
O.size());
473 if (KV.first == CurJD)
477 std::lock_guard<std::mutex> Lock(PlatformMutex);
478 if (!JITDylibToHeaderAddr.count(KV.first)) {
480 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
482 << CurJD->getName() <<
"\n";
487 DM.push_back(KV.first);
489 if (JDDepMap.try_emplace(KV.first).second)
490 Worklist.push_back(KV.first);
494 return std::move(JDDepMap);
498void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
500 JITDylibDepMap &JDDepMap) {
502 DenseSet<JITDylib *> Visited({JD.
get()});
503 DenseMap<JITDylib *, SymbolLookupSet> NewInitSymbols;
504 ES.runSessionLocked([&]() {
505 while (!Worklist.empty()) {
506 auto CurJD = Worklist.back();
509 auto RISItr = RegisteredInitSymbols.find(CurJD);
510 if (RISItr != RegisteredInitSymbols.end()) {
511 NewInitSymbols[CurJD] = std::move(RISItr->second);
512 RegisteredInitSymbols.erase(RISItr);
515 for (
auto *DepJD : JDDepMap[CurJD])
516 if (Visited.insert(DepJD).second)
517 Worklist.push_back(DepJD);
523 if (NewInitSymbols.
empty()) {
525 COFFJITDylibDepInfoMap DIM;
526 DIM.reserve(JDDepMap.size());
527 for (
auto &KV : JDDepMap) {
528 std::lock_guard<std::mutex> Lock(PlatformMutex);
529 COFFJITDylibDepInfo DepInfo;
530 DepInfo.reserve(KV.second.size());
531 for (
auto &Dep : KV.second) {
532 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
534 auto H = JITDylibToHeaderAddr[KV.first];
535 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
543 [
this, SendResult = std::move(SendResult), &JD,
544 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
546 SendResult(std::move(Err));
548 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
550 ES, std::move(NewInitSymbols));
553void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
557 std::lock_guard<std::mutex> Lock(PlatformMutex);
558 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
559 if (
I != HeaderAddrToJITDylib.end())
564 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
566 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
568 dbgs() <<
"No JITDylib for header address.\n";
573 formatv(
"{0:x}", JDHeaderAddr),
578 auto JDDepMap = buildJDDepMap(*JD);
580 SendResult(JDDepMap.takeError());
584 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
587void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
589 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
591 JITDylib *JD =
nullptr;
594 std::lock_guard<std::mutex> Lock(PlatformMutex);
595 auto I = HeaderAddrToJITDylib.find(Handle);
596 if (
I != HeaderAddrToJITDylib.end())
601 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
609 class RtLookupNotifyComplete {
611 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
612 : SendResult(std::
move(SendResult)) {}
613 void operator()(Expected<SymbolMap>
Result) {
615 assert(
Result->size() == 1 &&
"Unexpected result map count");
616 SendResult(
Result->begin()->second.getAddress());
618 SendResult(
Result.takeError());
623 SendSymbolAddressFn SendResult;
632Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
635 using LookupSymbolSPSSig =
636 SPSExpected<SPSExecutorAddr>(SPSExecutorAddr,
SPSString);
637 WFs[ES.intern(
"__orc_rt_coff_symbol_lookup_tag")] =
638 ES.wrapAsyncWithSPS<LookupSymbolSPSSig>(
this,
639 &COFFPlatform::rt_lookupSymbol);
640 using PushInitializersSPSSig =
641 SPSExpected<SPSCOFFJITDylibDepInfoMap>(SPSExecutorAddr);
642 WFs[ES.intern(
"__orc_rt_coff_push_initializers_tag")] =
643 ES.wrapAsyncWithSPS<PushInitializersSPSSig>(
644 this, &COFFPlatform::rt_pushInitializers);
646 return ES.registerJITDispatchHandlers(PlatformJD, std::move(WFs));
649Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
652 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
655 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
659 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
664Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
669 ES.getBootstrapJITDylib(),
670 {recordProxy<sps::CallInt32VoidProxySpec>(&CallInitializer)}))
672 for (
auto &Initializer : BState.Initializers)
673 if (Initializer.first >= Start && Initializer.first <= End &&
674 Initializer.second) {
675 auto Res = CallInitializer(ES, Initializer.second);
677 return Res.takeError();
682Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
686 PlatformJD, {
recordAddr(
"__orc_rt_coff_platform_bootstrap",
687 &orc_rt_coff_platform_bootstrap),
689 &orc_rt_coff_platform_shutdown),
691 &orc_rt_coff_register_jitdylib),
692 recordAddr(
"__orc_rt_coff_deregister_jitdylib",
693 &orc_rt_coff_deregister_jitdylib),
694 recordAddr(
"__orc_rt_coff_register_object_sections",
695 &orc_rt_coff_register_object_sections),
696 recordAddr(
"__orc_rt_coff_deregister_object_sections",
697 &orc_rt_coff_deregister_object_sections)}))
701 if (
auto Err = ES.callSPSWrapper<
void()>(orc_rt_coff_platform_bootstrap))
706 for (
auto KV : JDBootstrapStates) {
707 auto &JDBState = KV.second;
708 if (
auto Err = ES.callSPSWrapper<
void(
SPSString, SPSExecutorAddr)>(
709 orc_rt_coff_register_jitdylib, JDBState.JDName,
710 JDBState.HeaderAddr))
713 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
714 if (
auto Err = ES.callSPSWrapper<
void(SPSExecutorAddr,
716 orc_rt_coff_register_object_sections, JDBState.HeaderAddr,
717 ObjSectionMap,
false))
722 for (
auto KV : JDBootstrapStates) {
723 auto &JDBState = KV.second;
724 if (
auto Err = runBootstrapInitializers(JDBState))
732 StringRef SymbolName) {
733 ExecutorAddr TargetFn;
735 PlatformJD, {
recordAddr(SymbolName, &TargetFn,
744 {recordProxy<sps::CallInt32VoidProxySpec>(&CallFn)}))
747 return CallFn(ES, TargetFn).takeError();
750void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
752 jitlink::PassConfiguration &Config) {
754 bool IsBootstrapping = CP.Bootstrapping.load();
757 if (InitSymbol == CP.COFFHeaderStartSymbol) {
759 [
this, &MR, IsBootstrapping](jitlink::LinkGraph &
G) {
760 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
765 return preserveInitializerSections(
G, MR);
769 if (!IsBootstrapping)
772 return registerObjectPlatformSections(G, JD);
777 return registerObjectPlatformSectionsInBootstrap(G, JD);
781Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
782 jitlink::LinkGraph &
G, MaterializationResponsibility &MR,
783 bool IsBootstraping) {
784 auto I =
llvm::find_if(
G.defined_symbols(), [
this](jitlink::Symbol *Sym) {
785 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
787 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
790 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
791 auto HeaderAddr = (*I)->getAddress();
792 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
793 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
794 if (!IsBootstraping) {
795 G.allocActions().push_back(
797 SPSArgList<SPSString, SPSExecutorAddr>>(
798 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
800 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
802 G.allocActions().push_back(
805 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
806 JDBootstrapState BState;
809 BState.HeaderAddr = HeaderAddr;
810 CP.JDBootstrapStates.emplace(&JD, BState);
816Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
817 jitlink::LinkGraph &
G, JITDylib &JD) {
818 COFFObjectSectionsMap ObjSecs;
819 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
820 assert(HeaderAddr &&
"Must be registered jitdylib");
821 for (
auto &S :
G.sections()) {
822 jitlink::SectionRange
Range(S);
824 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
827 G.allocActions().push_back(
829 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
832 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
838Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
839 jitlink::LinkGraph &
G, MaterializationResponsibility &MR) {
843 jitlink::Symbol *InitSym =
nullptr;
845 for (
auto &InitSection :
G.sections()) {
854 auto &
B = **InitSection.blocks().begin();
855 InitSym = &
G.addDefinedSymbol(
861 for (
auto *
B : InitSection.blocks()) {
865 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
874Error COFFPlatform::COFFPlatformPlugin::
875 registerObjectPlatformSectionsInBootstrap(jitlink::LinkGraph &
G,
877 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
878 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
879 COFFObjectSectionsMap ObjSecs;
880 for (
auto &S :
G.sections()) {
881 jitlink::SectionRange
Range(S);
883 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
886 G.allocActions().push_back(
890 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
893 auto &BState = CP.JDBootstrapStates[&JD];
894 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
897 for (
auto &S :
G.sections())
899 for (
auto *
B : S.blocks()) {
900 if (
B->edges_empty())
902 for (
auto &
E :
B->edges())
903 BState.Initializers.push_back(std::make_pair(
904 S.getName().str(),
E.getTarget().getAddress() +
E.getAddend()));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
#define offsetof(TYPE, MEMBER)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static StringRef getName(Value *V)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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.
Error takeError()
Take ownership of the stored error.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Triple - Helper class for working with autoconf configuration names.
void addEdge(Edge::Kind K, Edge::OffsetT Offset, Symbol &Target, Edge::AddendT Addend)
Add an edge to this block.
const std::string & getName() const
Get the name for this JITLinkDylib.
Block & getBlock()
Return the Block for this Symbol (Symbol must be defined).
static Expected< std::unique_ptr< Archive > > create(MemoryBufferRef Source)
static LLVM_ABI Expected< std::unique_ptr< COFFVCRuntimeBootstrapper > > Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, const char *RuntimePath=nullptr)
Try to create a COFFVCRuntimeBootstrapper instance.
static std::unique_ptr< DLLImportDefinitionGenerator > Create(ExecutionSession &ES, ObjectLinkingLayer &L)
Creates a DLLImportDefinitionGenerator instance.
An ExecutionSession represents a running JIT program.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
DenseMap< SymbolStringPtr, JITDispatchHandlerFunction > JITDispatchHandlerAssociationMap
A map associating tag names with asynchronous wrapper function implementations in the JIT.
Represents an address in the executor 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.
LinkGraphLinkingLayer & addPlugin(std::shared_ptr< Plugin > P)
Add a plugin.
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.
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
An ObjectLayer implementation built on JITLink.
API to remove / transfer ownership of JIT resources.
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > ArchiveBuffer, std::unique_ptr< object::Archive > Archive, VisitMembersFunction VisitMembers=VisitMembersFunction(), GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibrarySearchGenerator from the given memory buffer and Archive object.
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 sequences.
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.
@ IMAGE_FILE_MACHINE_AMD64
static const char PEMagic[]
@ Pointer64
A plain 64-bit pointer value relocation.
LLVM_ABI const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
SPSSequence< SPSExecutorAddr > SPSCOFFJITDylibDepInfo
SPSSequence< char > SPSString
SPS tag type for strings, which are equivalent to sequences of chars.
SPSArgList< SPSExecutorAddr, SPSCOFFObjectSectionsMap, bool > SPSCOFFRegisterObjectSectionsArgs
SPSSequence< SPSTuple< SPSString, SPSExecutorAddrRange > > SPSCOFFObjectSectionsMap
SPSSequence< SPSTuple< SPSExecutorAddr, SPSCOFFJITDylibDepInfo > > SPSCOFFJITDylibDepInfoMap
SPSArgList< SPSExecutorAddr, SPSCOFFObjectSectionsMap > SPSCOFFDeregisterObjectSectionsArgs
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.
IntrusiveRefCntPtr< JITDylib > JITDylibSP
Proxy< int32_t(ExecutorAddr)> CallInt32VoidProxy
Protocol-agnostic interface for running an int32_t() function in the executor.
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
LLVM_ABI void lookupAndApply(unique_function< void(Error)> OnApplied, LookupKind K, const JITDylibSearchOrder &SearchOrder, ArrayRef< LookupPrepareFn > PrepareFns)
Resolve the symbols contributed by every prepare function with a single lookup, then let each of thei...
std::unique_ptr< ReExportsMaterializationUnit > reexports(JITDylib &SourceJD, SymbolAliasMap Aliases, JITDylibLookupFlags SourceJDLookupFlags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Create a materialization unit for re-exporting symbols from another JITDylib with alternative names/f...
@ MatchExportedSymbolsOnly
static void addAliases(ExecutionSession &ES, SymbolAliasMap &Aliases, ArrayRef< std::pair< const char *, const char * > > AL)
LLVM_ABI Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
jitlink::Block & createHeaderBlock(MachOPlatform &MOP, const MachOPlatform::HeaderOptions &Opts, JITDylib &JD, jitlink::LinkGraph &G, jitlink::Section &HeaderSection)
LookupPrepareFn recordAddr(StringRef Name, ExecutorAddr *A, SymbolLookupFlags LF=SymbolLookupFlags::RequiredSymbol)
Records the address of the symbol with the given name.
LLVM_ABI RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
LLVM_ABI bool isCOFFInitializerSection(StringRef Name)
@ Ready
Emitted to memory, but waiting on transitive dependencies.
DenseMap< SymbolStringPtr, SymbolAliasMapEntry > SymbolAliasMap
A map of Symbols to (Symbol, Flags) pairs.
LLVM_ABI Expected< SymbolAliasMap > buildSimpleReexportsAliasMap(JITDylib &SourceJD, const SymbolNameSet &Symbols)
Build a SymbolAliasMap for the common case where you want to re-export symbols from another JITDylib ...
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::little, unaligned > ulittle32_t
This is an optimization pass for GlobalISel generic memory operations.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
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.
Implement std::hash so that hash_code can be used in STL containers.
LinkGraphPassList PostAllocationPasses
Post-allocation passes.
LinkGraphPassList PostFixupPasses
Post-fixup passes.
LinkGraphPassList PrePrunePasses
Pre-prune passes.