27#define DEBUG_TYPE "orc"
59 StringRef
getName()
const override {
return "COFFHeaderMU"; }
61 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
62 auto G = std::make_unique<jitlink::LinkGraph>(
63 "<COFFHeaderMU>", CP.getExecutionSession().getSymbolStringPool(),
64 CP.getExecutionSession().getTargetTriple(), SubtargetFeatures(),
66 auto &HeaderSection =
G->createSection(
"__header", MemProt::Read);
70 auto &ImageBaseSymbol =
G->addDefinedSymbol(
71 HeaderBlock, 0, *
R->getInitializerSymbol(), HeaderBlock.getSize(),
72 jitlink::Linkage::Strong, jitlink::Scope::Default,
false,
true);
74 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
76 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
79 void discard(
const JITDylib &JD,
const SymbolStringPtr &Sym)
override {}
89 object::coff_file_header FileHeader;
91 object::pe32plus_header Header;
96 struct HeaderBlockContent {
97 object::dos_header DOSHeader;
98 COFFHeaderMaterializationUnit::NTHeader NTHeader;
102 jitlink::Section &HeaderSection) {
103 HeaderBlockContent Hdr = {};
106 Hdr.DOSHeader.Magic[0] =
'M';
107 Hdr.DOSHeader.Magic[1] =
'Z';
108 Hdr.DOSHeader.AddressOfNewExeHeader =
109 offsetof(HeaderBlockContent, NTHeader);
110 uint32_t PEMagic = *
reinterpret_cast<const uint32_t *
>(
COFF::PEMagic);
111 Hdr.NTHeader.PEMagic = PEMagic;
114 switch (
G.getTargetTriple().getArch()) {
122 auto HeaderContent =
G.allocateContent(
123 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
125 return G.createContentBlock(HeaderSection, HeaderContent, ExecutorAddr(), 8,
129 static void addImageBaseRelocationEdge(jitlink::Block &
B,
130 jitlink::Symbol &ImageBase) {
131 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
132 offsetof(NTHeader, OptionalHeader) +
133 offsetof(object::pe32plus_header, ImageBase);
137 static MaterializationUnit::Interface
138 createHeaderInterface(COFFPlatform &MOP,
139 const SymbolStringPtr &HeaderStartSymbol) {
144 return MaterializationUnit::Interface(std::move(HeaderSymbolFlags),
156Expected<std::unique_ptr<COFFPlatform>>
158 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
160 const char *VCRuntimePath,
161 std::optional<SymbolAliasMap> RuntimeAliases) {
163 auto &ES = ObjLinkingLayer.getExecutionSession();
166 if (!supportedTarget(ES.getTargetTriple()))
168 ES.getTargetTriple().str(),
171 auto GeneratorArchive =
173 if (!GeneratorArchive)
174 return GeneratorArchive.takeError();
176 std::set<std::string> DylibsToPreload;
178 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive),
180 if (!OrcRuntimeArchiveGenerator)
181 return OrcRuntimeArchiveGenerator.takeError();
195 return std::move(Err);
200 ES.getBootstrapJITDylib(),
201 {{ES.intern(rt::DispatchName), ES.intern(rt::DispatchCtxName)}});
203 return Exports.takeError();
212 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
213 std::move(DylibsToPreload), std::move(OrcRuntimeArchiveBuffer),
214 std::move(RuntimeArchive), std::move(LoadDynLibrary), StaticVCRuntime,
215 VCRuntimePath, Err));
217 return std::move(Err);
223 const char *OrcRuntimePath,
225 const char *VCRuntimePath,
226 std::optional<SymbolAliasMap> RuntimeAliases) {
232 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
233 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
234 std::move(RuntimeAliases));
238 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
246 auto Buffer = (*PerJDObj)->getAsBinary();
248 return Buffer.takeError();
250 return (*Buffer)->getMemoryBufferRef();
254 ArrayRef<std::pair<const char *, const char *>> AL) {
255 for (
auto &KV : AL) {
256 auto AliasName = ES.
intern(KV.first);
257 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
258 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
264 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
265 *
this, COFFHeaderStartSymbol)))
268 if (
auto Err = ES.lookup({&JD}, COFFHeaderStartSymbol).takeError())
277 auto PerJDObj = getPerJDObjectFile();
279 return PerJDObj.takeError();
283 return I.takeError();
285 if (
auto Err = ObjLinkingLayer.add(
289 if (!Bootstrapping) {
290 auto ImportedLibs = StaticVCRuntime
291 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
292 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
294 return ImportedLibs.takeError();
295 for (
auto &
Lib : *ImportedLibs)
296 if (
auto Err = LoadDynLibrary(JD,
Lib))
299 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
308 std::lock_guard<std::mutex> Lock(PlatformMutex);
309 auto I = JITDylibToHeaderAddr.find(&JD);
310 if (
I != JITDylibToHeaderAddr.end()) {
311 assert(HeaderAddrToJITDylib.count(
I->second) &&
312 "HeaderAddrToJITDylib missing entry");
313 HeaderAddrToJITDylib.erase(
I->second);
314 JITDylibToHeaderAddr.erase(
I);
326 RegisteredInitSymbols[&JD].add(InitSym,
330 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
348 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
349 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
350 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
351 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
358 static const std::pair<const char *, const char *>
359 StandardRuntimeUtilityAliases[] = {
360 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
361 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
362 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
363 {
"__orc_rt_jit_dlupdate",
"__orc_rt_coff_jit_dlupdate"},
364 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
365 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
366 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
369 StandardRuntimeUtilityAliases);
372bool COFFPlatform::supportedTarget(
const Triple &TT) {
373 switch (TT.getArch()) {
381COFFPlatform::COFFPlatform(
383 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
384 std::set<std::string> DylibsToPreload,
385 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
386 std::unique_ptr<object::Archive> OrcRuntimeArchive,
387 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
388 const char *VCRuntimePath,
Error &Err)
389 : ES(ObjLinkingLayer.getExecutionSession()),
390 ObjLinkingLayer(ObjLinkingLayer),
391 LoadDynLibrary(
std::
move(LoadDynLibrary)),
392 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
393 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
394 StaticVCRuntime(StaticVCRuntime),
395 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
398 Bootstrapping.store(
true);
399 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
405 Err = VCRT.takeError();
408 VCRuntimeBootstrap = std::move(*VCRT);
411 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
412 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
414 Err = ImportedLibs.takeError();
418 for (
auto &
Lib : *ImportedLibs)
419 DylibsToPreload.insert(
Lib);
421 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
430 for (
auto&
Lib : DylibsToPreload)
431 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
437 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
443 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
451 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
456 Bootstrapping.store(
false);
457 JDBootstrapStates.clear();
460Expected<COFFPlatform::JITDylibDepMap>
461COFFPlatform::buildJDDepMap(
JITDylib &JD) {
462 return ES.runSessionLocked([&]() -> Expected<JITDylibDepMap> {
463 JITDylibDepMap JDDepMap;
466 while (!Worklist.empty()) {
467 auto CurJD = Worklist.back();
470 auto &
DM = JDDepMap[CurJD];
472 DM.reserve(
O.size());
474 if (KV.first == CurJD)
478 std::lock_guard<std::mutex> Lock(PlatformMutex);
479 if (!JITDylibToHeaderAddr.count(KV.first)) {
481 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
483 << CurJD->getName() <<
"\n";
488 DM.push_back(KV.first);
490 if (JDDepMap.try_emplace(KV.first).second)
491 Worklist.push_back(KV.first);
495 return std::move(JDDepMap);
499void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
501 JITDylibDepMap &JDDepMap) {
503 DenseSet<JITDylib *> Visited({JD.
get()});
504 DenseMap<JITDylib *, SymbolLookupSet> NewInitSymbols;
505 ES.runSessionLocked([&]() {
506 while (!Worklist.empty()) {
507 auto CurJD = Worklist.back();
510 auto RISItr = RegisteredInitSymbols.find(CurJD);
511 if (RISItr != RegisteredInitSymbols.end()) {
512 NewInitSymbols[CurJD] = std::move(RISItr->second);
513 RegisteredInitSymbols.erase(RISItr);
516 for (
auto *DepJD : JDDepMap[CurJD])
517 if (Visited.insert(DepJD).second)
518 Worklist.push_back(DepJD);
524 if (NewInitSymbols.
empty()) {
526 COFFJITDylibDepInfoMap DIM;
527 DIM.reserve(JDDepMap.size());
528 for (
auto &KV : JDDepMap) {
529 std::lock_guard<std::mutex> Lock(PlatformMutex);
530 COFFJITDylibDepInfo DepInfo;
531 DepInfo.reserve(KV.second.size());
532 for (
auto &Dep : KV.second) {
533 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
535 auto H = JITDylibToHeaderAddr[KV.first];
536 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
544 [
this, SendResult = std::move(SendResult), &JD,
545 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
547 SendResult(std::move(Err));
549 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
551 ES, std::move(NewInitSymbols));
554void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
558 std::lock_guard<std::mutex> Lock(PlatformMutex);
559 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
560 if (
I != HeaderAddrToJITDylib.end())
565 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
567 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
569 dbgs() <<
"No JITDylib for header address.\n";
574 formatv(
"{0:x}", JDHeaderAddr),
579 auto JDDepMap = buildJDDepMap(*JD);
581 SendResult(JDDepMap.takeError());
585 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
588void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
590 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
592 JITDylib *JD =
nullptr;
595 std::lock_guard<std::mutex> Lock(PlatformMutex);
596 auto I = HeaderAddrToJITDylib.find(Handle);
597 if (
I != HeaderAddrToJITDylib.end())
602 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
610 class RtLookupNotifyComplete {
612 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
613 : SendResult(std::
move(SendResult)) {}
614 void operator()(Expected<SymbolMap>
Result) {
616 assert(
Result->size() == 1 &&
"Unexpected result map count");
617 SendResult(
Result->begin()->second.getAddress());
619 SendResult(
Result.takeError());
624 SendSymbolAddressFn SendResult;
633Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
636 using LookupSymbolSPSSig =
637 SPSExpected<SPSExecutorAddr>(SPSExecutorAddr,
SPSString);
638 WFs[ES.intern(
"__orc_rt_coff_symbol_lookup_tag")] =
639 ES.wrapAsyncWithSPS<LookupSymbolSPSSig>(
this,
640 &COFFPlatform::rt_lookupSymbol);
641 using PushInitializersSPSSig =
642 SPSExpected<SPSCOFFJITDylibDepInfoMap>(SPSExecutorAddr);
643 WFs[ES.intern(
"__orc_rt_coff_push_initializers_tag")] =
644 ES.wrapAsyncWithSPS<PushInitializersSPSSig>(
645 this, &COFFPlatform::rt_pushInitializers);
647 return ES.registerJITDispatchHandlers(PlatformJD, std::move(WFs));
650Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
653 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
656 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
660 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
665Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
670 ES.getBootstrapJITDylib(),
671 {recordProxy<sps::CallInt32VoidProxySpec>(&CallInitializer)}))
673 for (
auto &Initializer : BState.Initializers)
674 if (Initializer.first >= Start && Initializer.first <= End &&
675 Initializer.second) {
676 auto Res = CallInitializer(ES, Initializer.second);
678 return Res.takeError();
683Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
687 PlatformJD, {
recordAddr(
"__orc_rt_coff_platform_bootstrap",
688 &orc_rt_coff_platform_bootstrap),
690 &orc_rt_coff_platform_shutdown),
692 &orc_rt_coff_register_jitdylib),
693 recordAddr(
"__orc_rt_coff_deregister_jitdylib",
694 &orc_rt_coff_deregister_jitdylib),
695 recordAddr(
"__orc_rt_coff_register_object_sections",
696 &orc_rt_coff_register_object_sections),
697 recordAddr(
"__orc_rt_coff_deregister_object_sections",
698 &orc_rt_coff_deregister_object_sections)}))
702 if (
auto Err = ES.callSPSWrapper<
void()>(orc_rt_coff_platform_bootstrap))
707 for (
auto KV : JDBootstrapStates) {
708 auto &JDBState = KV.second;
709 if (
auto Err = ES.callSPSWrapper<
void(
SPSString, SPSExecutorAddr)>(
710 orc_rt_coff_register_jitdylib, JDBState.JDName,
711 JDBState.HeaderAddr))
714 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
715 if (
auto Err = ES.callSPSWrapper<
void(SPSExecutorAddr,
717 orc_rt_coff_register_object_sections, JDBState.HeaderAddr,
718 ObjSectionMap,
false))
723 for (
auto KV : JDBootstrapStates) {
724 auto &JDBState = KV.second;
725 if (
auto Err = runBootstrapInitializers(JDBState))
733 StringRef SymbolName) {
734 ExecutorAddr jit_function;
737 {{ES.intern(SymbolName), &jit_function}});
738 if (!AfterCLookupErr) {
742 {recordProxy<sps::CallInt32VoidProxySpec>(&CallFn)}))
744 auto Res = CallFn(ES, jit_function);
746 return Res.takeError();
749 if (!AfterCLookupErr.isA<SymbolsNotFound>())
750 return AfterCLookupErr;
755void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
757 jitlink::PassConfiguration &Config) {
759 bool IsBootstrapping = CP.Bootstrapping.load();
762 if (InitSymbol == CP.COFFHeaderStartSymbol) {
764 [
this, &MR, IsBootstrapping](jitlink::LinkGraph &
G) {
765 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
770 return preserveInitializerSections(
G, MR);
774 if (!IsBootstrapping)
777 return registerObjectPlatformSections(G, JD);
782 return registerObjectPlatformSectionsInBootstrap(G, JD);
786Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
787 jitlink::LinkGraph &
G, MaterializationResponsibility &MR,
788 bool IsBootstraping) {
789 auto I =
llvm::find_if(
G.defined_symbols(), [
this](jitlink::Symbol *Sym) {
790 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
792 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
795 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
796 auto HeaderAddr = (*I)->getAddress();
797 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
798 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
799 if (!IsBootstraping) {
800 G.allocActions().push_back(
802 SPSArgList<SPSString, SPSExecutorAddr>>(
803 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
805 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
807 G.allocActions().push_back(
810 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
811 JDBootstrapState BState;
814 BState.HeaderAddr = HeaderAddr;
815 CP.JDBootstrapStates.emplace(&JD, BState);
821Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
822 jitlink::LinkGraph &
G, JITDylib &JD) {
823 COFFObjectSectionsMap ObjSecs;
824 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
825 assert(HeaderAddr &&
"Must be registered jitdylib");
826 for (
auto &S :
G.sections()) {
827 jitlink::SectionRange
Range(S);
829 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
832 G.allocActions().push_back(
834 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
837 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
843Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
844 jitlink::LinkGraph &
G, MaterializationResponsibility &MR) {
848 jitlink::Symbol *InitSym =
nullptr;
850 for (
auto &InitSection :
G.sections()) {
859 auto &
B = **InitSection.blocks().begin();
860 InitSym = &
G.addDefinedSymbol(
866 for (
auto *
B : InitSection.blocks()) {
870 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
879Error COFFPlatform::COFFPlatformPlugin::
880 registerObjectPlatformSectionsInBootstrap(jitlink::LinkGraph &
G,
882 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
883 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
884 COFFObjectSectionsMap ObjSecs;
885 for (
auto &S :
G.sections()) {
886 jitlink::SectionRange
Range(S);
888 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
891 G.allocActions().push_back(
895 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
898 auto &BState = CP.JDBootstrapStates[&JD];
899 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
902 for (
auto &S :
G.sections())
904 for (
auto *
B : S.blocks()) {
905 if (
B->edges_empty())
907 for (
auto &
E :
B->edges())
908 BState.Initializers.push_back(std::make_pair(
909 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
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::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.
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
LLVM_ABI void lookupAndRecordAddrs(unique_function< void(Error)> OnRecorded, ExecutionSession &ES, LookupKind K, const JITDylibSearchOrder &SearchOrder, std::vector< std::pair< SymbolStringPtr, ExecutorAddr * > > Pairs, SymbolLookupFlags LookupFlags=SymbolLookupFlags::RequiredSymbol)
Record addresses of the given symbols in the given ExecutorAddrs.
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,...
LLVM_ABI void lookupAndApply(unique_function< void(Error)> OnApplied, ExecutionSession &ES, 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...
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.
void consumeError(Error Err)
Consume a Error without doing anything.
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.