23#define DEBUG_TYPE "orc"
55 StringRef
getName()
const override {
return "COFFHeaderMU"; }
57 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
58 auto G = std::make_unique<jitlink::LinkGraph>(
59 "<COFFHeaderMU>", CP.getExecutionSession().getSymbolStringPool(),
60 CP.getExecutionSession().getTargetTriple(), SubtargetFeatures(),
62 auto &HeaderSection =
G->createSection(
"__header", MemProt::Read);
66 auto &ImageBaseSymbol =
G->addDefinedSymbol(
67 HeaderBlock, 0, *
R->getInitializerSymbol(), HeaderBlock.getSize(),
68 jitlink::Linkage::Strong, jitlink::Scope::Default,
false,
true);
70 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
72 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
75 void discard(
const JITDylib &JD,
const SymbolStringPtr &Sym)
override {}
85 object::coff_file_header FileHeader;
87 object::pe32plus_header Header;
92 struct HeaderBlockContent {
93 object::dos_header DOSHeader;
94 COFFHeaderMaterializationUnit::NTHeader NTHeader;
98 jitlink::Section &HeaderSection) {
99 HeaderBlockContent Hdr = {};
102 Hdr.DOSHeader.Magic[0] =
'M';
103 Hdr.DOSHeader.Magic[1] =
'Z';
104 Hdr.DOSHeader.AddressOfNewExeHeader =
105 offsetof(HeaderBlockContent, NTHeader);
106 uint32_t PEMagic = *
reinterpret_cast<const uint32_t *
>(
COFF::PEMagic);
107 Hdr.NTHeader.PEMagic = PEMagic;
110 switch (
G.getTargetTriple().getArch()) {
118 auto HeaderContent =
G.allocateContent(
119 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
121 return G.createContentBlock(HeaderSection, HeaderContent, ExecutorAddr(), 8,
125 static void addImageBaseRelocationEdge(jitlink::Block &
B,
126 jitlink::Symbol &ImageBase) {
127 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
128 offsetof(NTHeader, OptionalHeader) +
129 offsetof(object::pe32plus_header, ImageBase);
133 static MaterializationUnit::Interface
134 createHeaderInterface(COFFPlatform &MOP,
135 const SymbolStringPtr &HeaderStartSymbol) {
140 return MaterializationUnit::Interface(std::move(HeaderSymbolFlags),
152Expected<std::unique_ptr<COFFPlatform>>
154 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
156 const char *VCRuntimePath,
157 std::optional<SymbolAliasMap> RuntimeAliases) {
159 auto &ES = ObjLinkingLayer.getExecutionSession();
162 if (!supportedTarget(ES.getTargetTriple()))
164 ES.getTargetTriple().str(),
167 auto GeneratorArchive =
169 if (!GeneratorArchive)
170 return GeneratorArchive.takeError();
172 std::set<std::string> DylibsToPreload;
174 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive),
176 if (!OrcRuntimeArchiveGenerator)
177 return OrcRuntimeArchiveGenerator.takeError();
191 return std::move(Err);
196 ES.getBootstrapJITDylib(),
197 {{ES.intern(rt::DispatchName), ES.intern(rt::DispatchCtxName)}});
199 return Exports.takeError();
208 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
209 std::move(DylibsToPreload), std::move(OrcRuntimeArchiveBuffer),
210 std::move(RuntimeArchive), std::move(LoadDynLibrary), StaticVCRuntime,
211 VCRuntimePath, Err));
213 return std::move(Err);
219 const char *OrcRuntimePath,
221 const char *VCRuntimePath,
222 std::optional<SymbolAliasMap> RuntimeAliases) {
228 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
229 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
230 std::move(RuntimeAliases));
234 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
242 auto Buffer = (*PerJDObj)->getAsBinary();
244 return Buffer.takeError();
246 return (*Buffer)->getMemoryBufferRef();
250 ArrayRef<std::pair<const char *, const char *>> AL) {
251 for (
auto &KV : AL) {
252 auto AliasName = ES.
intern(KV.first);
253 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
254 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
260 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
261 *
this, COFFHeaderStartSymbol)))
264 if (
auto Err = ES.lookup({&JD}, COFFHeaderStartSymbol).takeError())
273 auto PerJDObj = getPerJDObjectFile();
275 return PerJDObj.takeError();
279 return I.takeError();
281 if (
auto Err = ObjLinkingLayer.add(
285 if (!Bootstrapping) {
286 auto ImportedLibs = StaticVCRuntime
287 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
288 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
290 return ImportedLibs.takeError();
291 for (
auto &
Lib : *ImportedLibs)
292 if (
auto Err = LoadDynLibrary(JD,
Lib))
295 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
304 std::lock_guard<std::mutex> Lock(PlatformMutex);
305 auto I = JITDylibToHeaderAddr.find(&JD);
306 if (
I != JITDylibToHeaderAddr.end()) {
307 assert(HeaderAddrToJITDylib.count(
I->second) &&
308 "HeaderAddrToJITDylib missing entry");
309 HeaderAddrToJITDylib.erase(
I->second);
310 JITDylibToHeaderAddr.erase(
I);
322 RegisteredInitSymbols[&JD].add(InitSym,
326 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
344 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
345 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
346 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
347 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
354 static const std::pair<const char *, const char *>
355 StandardRuntimeUtilityAliases[] = {
356 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
357 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
358 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
359 {
"__orc_rt_jit_dlupdate",
"__orc_rt_coff_jit_dlupdate"},
360 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
361 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
362 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
365 StandardRuntimeUtilityAliases);
368bool COFFPlatform::supportedTarget(
const Triple &TT) {
369 switch (TT.getArch()) {
377COFFPlatform::COFFPlatform(
379 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
380 std::set<std::string> DylibsToPreload,
381 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
382 std::unique_ptr<object::Archive> OrcRuntimeArchive,
383 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
384 const char *VCRuntimePath,
Error &Err)
385 : ES(ObjLinkingLayer.getExecutionSession()),
386 ObjLinkingLayer(ObjLinkingLayer),
387 LoadDynLibrary(
std::
move(LoadDynLibrary)),
388 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
389 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
390 StaticVCRuntime(StaticVCRuntime),
391 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
394 Bootstrapping.store(
true);
395 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
401 Err = VCRT.takeError();
404 VCRuntimeBootstrap = std::move(*VCRT);
407 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
408 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
410 Err = ImportedLibs.takeError();
414 for (
auto &
Lib : *ImportedLibs)
415 DylibsToPreload.insert(
Lib);
417 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
426 for (
auto&
Lib : DylibsToPreload)
427 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
433 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
439 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
447 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
452 Bootstrapping.store(
false);
453 JDBootstrapStates.clear();
456Expected<COFFPlatform::JITDylibDepMap>
457COFFPlatform::buildJDDepMap(
JITDylib &JD) {
458 return ES.runSessionLocked([&]() -> Expected<JITDylibDepMap> {
459 JITDylibDepMap JDDepMap;
462 while (!Worklist.empty()) {
463 auto CurJD = Worklist.back();
466 auto &
DM = JDDepMap[CurJD];
468 DM.reserve(
O.size());
470 if (KV.first == CurJD)
474 std::lock_guard<std::mutex> Lock(PlatformMutex);
475 if (!JITDylibToHeaderAddr.count(KV.first)) {
477 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
479 << CurJD->getName() <<
"\n";
484 DM.push_back(KV.first);
486 if (JDDepMap.try_emplace(KV.first).second)
487 Worklist.push_back(KV.first);
491 return std::move(JDDepMap);
495void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
497 JITDylibDepMap &JDDepMap) {
499 DenseSet<JITDylib *> Visited({JD.
get()});
500 DenseMap<JITDylib *, SymbolLookupSet> NewInitSymbols;
501 ES.runSessionLocked([&]() {
502 while (!Worklist.empty()) {
503 auto CurJD = Worklist.back();
506 auto RISItr = RegisteredInitSymbols.find(CurJD);
507 if (RISItr != RegisteredInitSymbols.end()) {
508 NewInitSymbols[CurJD] = std::move(RISItr->second);
509 RegisteredInitSymbols.erase(RISItr);
512 for (
auto *DepJD : JDDepMap[CurJD])
513 if (Visited.insert(DepJD).second)
514 Worklist.push_back(DepJD);
520 if (NewInitSymbols.
empty()) {
522 COFFJITDylibDepInfoMap DIM;
523 DIM.reserve(JDDepMap.size());
524 for (
auto &KV : JDDepMap) {
525 std::lock_guard<std::mutex> Lock(PlatformMutex);
526 COFFJITDylibDepInfo DepInfo;
527 DepInfo.reserve(KV.second.size());
528 for (
auto &Dep : KV.second) {
529 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
531 auto H = JITDylibToHeaderAddr[KV.first];
532 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
540 [
this, SendResult = std::move(SendResult), &JD,
541 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
543 SendResult(std::move(Err));
545 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
547 ES, std::move(NewInitSymbols));
550void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
554 std::lock_guard<std::mutex> Lock(PlatformMutex);
555 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
556 if (
I != HeaderAddrToJITDylib.end())
561 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
563 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
565 dbgs() <<
"No JITDylib for header address.\n";
570 formatv(
"{0:x}", JDHeaderAddr),
575 auto JDDepMap = buildJDDepMap(*JD);
577 SendResult(JDDepMap.takeError());
581 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
584void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
586 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
588 JITDylib *JD =
nullptr;
591 std::lock_guard<std::mutex> Lock(PlatformMutex);
592 auto I = HeaderAddrToJITDylib.find(Handle);
593 if (
I != HeaderAddrToJITDylib.end())
598 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
606 class RtLookupNotifyComplete {
608 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
609 : SendResult(std::
move(SendResult)) {}
610 void operator()(Expected<SymbolMap>
Result) {
612 assert(
Result->size() == 1 &&
"Unexpected result map count");
613 SendResult(
Result->begin()->second.getAddress());
615 SendResult(
Result.takeError());
620 SendSymbolAddressFn SendResult;
629Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
632 using LookupSymbolSPSSig =
633 SPSExpected<SPSExecutorAddr>(SPSExecutorAddr,
SPSString);
634 WFs[ES.intern(
"__orc_rt_coff_symbol_lookup_tag")] =
635 ES.wrapAsyncWithSPS<LookupSymbolSPSSig>(
this,
636 &COFFPlatform::rt_lookupSymbol);
637 using PushInitializersSPSSig =
638 SPSExpected<SPSCOFFJITDylibDepInfoMap>(SPSExecutorAddr);
639 WFs[ES.intern(
"__orc_rt_coff_push_initializers_tag")] =
640 ES.wrapAsyncWithSPS<PushInitializersSPSSig>(
641 this, &COFFPlatform::rt_pushInitializers);
643 return ES.registerJITDispatchHandlers(PlatformJD, std::move(WFs));
646Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
649 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
652 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
656 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
661Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
666 ES.getBootstrapJITDylib(),
667 {recordProxy<sps::CallInt32VoidProxySpec>(&CallInitializer)}))
669 for (
auto &Initializer : BState.Initializers)
670 if (Initializer.first >= Start && Initializer.first <= End &&
671 Initializer.second) {
672 auto Res = CallInitializer(ES, Initializer.second);
674 return Res.takeError();
679Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
683 PlatformJD, {
recordAddr(
"__orc_rt_coff_platform_bootstrap",
684 &orc_rt_coff_platform_bootstrap),
686 &orc_rt_coff_platform_shutdown),
688 &orc_rt_coff_register_jitdylib),
689 recordAddr(
"__orc_rt_coff_deregister_jitdylib",
690 &orc_rt_coff_deregister_jitdylib),
691 recordAddr(
"__orc_rt_coff_register_object_sections",
692 &orc_rt_coff_register_object_sections),
693 recordAddr(
"__orc_rt_coff_deregister_object_sections",
694 &orc_rt_coff_deregister_object_sections)}))
698 if (
auto Err = ES.callSPSWrapper<
void()>(orc_rt_coff_platform_bootstrap))
703 for (
auto KV : JDBootstrapStates) {
704 auto &JDBState = KV.second;
705 if (
auto Err = ES.callSPSWrapper<
void(
SPSString, SPSExecutorAddr)>(
706 orc_rt_coff_register_jitdylib, JDBState.JDName,
707 JDBState.HeaderAddr))
710 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
711 if (
auto Err = ES.callSPSWrapper<
void(SPSExecutorAddr,
713 orc_rt_coff_register_object_sections, JDBState.HeaderAddr,
714 ObjSectionMap,
false))
719 for (
auto KV : JDBootstrapStates) {
720 auto &JDBState = KV.second;
721 if (
auto Err = runBootstrapInitializers(JDBState))
729 StringRef SymbolName) {
730 ExecutorAddr TargetFn;
732 PlatformJD, {
recordAddr(SymbolName, &TargetFn,
741 {recordProxy<sps::CallInt32VoidProxySpec>(&CallFn)}))
744 return CallFn(ES, TargetFn).takeError();
747void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
749 jitlink::PassConfiguration &Config) {
751 bool IsBootstrapping = CP.Bootstrapping.load();
754 if (InitSymbol == CP.COFFHeaderStartSymbol) {
756 [
this, &MR, IsBootstrapping](jitlink::LinkGraph &
G) {
757 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
762 return preserveInitializerSections(
G, MR);
766 if (!IsBootstrapping)
769 return registerObjectPlatformSections(G, JD);
774 return registerObjectPlatformSectionsInBootstrap(G, JD);
778Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
779 jitlink::LinkGraph &
G, MaterializationResponsibility &MR,
780 bool IsBootstraping) {
781 auto I =
llvm::find_if(
G.defined_symbols(), [
this](jitlink::Symbol *Sym) {
782 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
784 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
787 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
788 auto HeaderAddr = (*I)->getAddress();
789 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
790 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
791 if (!IsBootstraping) {
792 G.allocActions().push_back(
794 SPSArgList<SPSString, SPSExecutorAddr>>(
795 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
797 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
799 G.allocActions().push_back(
802 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
803 JDBootstrapState BState;
806 BState.HeaderAddr = HeaderAddr;
807 CP.JDBootstrapStates.emplace(&JD, BState);
813Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
814 jitlink::LinkGraph &
G, JITDylib &JD) {
815 COFFObjectSectionsMap ObjSecs;
816 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
817 assert(HeaderAddr &&
"Must be registered jitdylib");
818 for (
auto &S :
G.sections()) {
819 jitlink::SectionRange
Range(S);
821 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
824 G.allocActions().push_back(
826 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
829 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
835Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
836 jitlink::LinkGraph &
G, MaterializationResponsibility &MR) {
840 jitlink::Symbol *InitSym =
nullptr;
842 for (
auto &InitSection :
G.sections()) {
851 auto &
B = **InitSection.blocks().begin();
852 InitSym = &
G.addDefinedSymbol(
858 for (
auto *
B : InitSection.blocks()) {
862 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
871Error COFFPlatform::COFFPlatformPlugin::
872 registerObjectPlatformSectionsInBootstrap(jitlink::LinkGraph &
G,
874 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
875 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
876 COFFObjectSectionsMap ObjSecs;
877 for (
auto &S :
G.sections()) {
878 jitlink::SectionRange
Range(S);
880 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
883 G.allocActions().push_back(
887 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
890 auto &BState = CP.JDBootstrapStates[&JD];
891 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
894 for (
auto &S :
G.sections())
896 for (
auto *
B : S.blocks()) {
897 if (
B->edges_empty())
899 for (
auto &
E :
B->edges())
900 BState.Initializers.push_back(std::make_pair(
901 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.