25#define DEBUG_TYPE "orc"
57 StringRef
getName()
const override {
return "COFFHeaderMU"; }
59 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
60 auto G = std::make_unique<jitlink::LinkGraph>(
61 "<COFFHeaderMU>", CP.getExecutionSession().getSymbolStringPool(),
62 CP.getExecutionSession().getTargetTriple(), SubtargetFeatures(),
64 auto &HeaderSection =
G->createSection(
"__header", MemProt::Read);
68 auto &ImageBaseSymbol =
G->addDefinedSymbol(
69 HeaderBlock, 0, *
R->getInitializerSymbol(), HeaderBlock.getSize(),
70 jitlink::Linkage::Strong, jitlink::Scope::Default,
false,
true);
72 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
74 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
77 void discard(
const JITDylib &JD,
const SymbolStringPtr &Sym)
override {}
87 object::coff_file_header FileHeader;
89 object::pe32plus_header Header;
94 struct HeaderBlockContent {
95 object::dos_header DOSHeader;
96 COFFHeaderMaterializationUnit::NTHeader NTHeader;
100 jitlink::Section &HeaderSection) {
101 HeaderBlockContent Hdr = {};
104 Hdr.DOSHeader.Magic[0] =
'M';
105 Hdr.DOSHeader.Magic[1] =
'Z';
106 Hdr.DOSHeader.AddressOfNewExeHeader =
107 offsetof(HeaderBlockContent, NTHeader);
108 uint32_t PEMagic = *
reinterpret_cast<const uint32_t *
>(
COFF::PEMagic);
109 Hdr.NTHeader.PEMagic = PEMagic;
112 switch (
G.getTargetTriple().getArch()) {
120 auto HeaderContent =
G.allocateContent(
121 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
123 return G.createContentBlock(HeaderSection, HeaderContent, ExecutorAddr(), 8,
127 static void addImageBaseRelocationEdge(jitlink::Block &
B,
128 jitlink::Symbol &ImageBase) {
129 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
130 offsetof(NTHeader, OptionalHeader) +
131 offsetof(object::pe32plus_header, ImageBase);
135 static MaterializationUnit::Interface
136 createHeaderInterface(COFFPlatform &MOP,
137 const SymbolStringPtr &HeaderStartSymbol) {
142 return MaterializationUnit::Interface(std::move(HeaderSymbolFlags),
154Expected<std::unique_ptr<COFFPlatform>>
156 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
158 const char *VCRuntimePath,
159 std::optional<SymbolAliasMap> RuntimeAliases) {
161 auto &ES = ObjLinkingLayer.getExecutionSession();
164 if (!supportedTarget(ES.getTargetTriple()))
166 ES.getTargetTriple().str(),
169 auto GeneratorArchive =
171 if (!GeneratorArchive)
172 return GeneratorArchive.takeError();
174 std::set<std::string> DylibsToPreload;
176 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive),
178 if (!OrcRuntimeArchiveGenerator)
179 return OrcRuntimeArchiveGenerator.takeError();
193 return std::move(Err);
198 ES.getBootstrapJITDylib(),
199 {{ES.intern(rt::DispatchName), ES.intern(rt::DispatchCtxName)}});
201 return Exports.takeError();
210 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
211 std::move(DylibsToPreload), std::move(OrcRuntimeArchiveBuffer),
212 std::move(RuntimeArchive), std::move(LoadDynLibrary), StaticVCRuntime,
213 VCRuntimePath, Err));
215 return std::move(Err);
221 const char *OrcRuntimePath,
223 const char *VCRuntimePath,
224 std::optional<SymbolAliasMap> RuntimeAliases) {
230 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
231 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
232 std::move(RuntimeAliases));
236 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
244 auto Buffer = (*PerJDObj)->getAsBinary();
246 return Buffer.takeError();
248 return (*Buffer)->getMemoryBufferRef();
252 ArrayRef<std::pair<const char *, const char *>> AL) {
253 for (
auto &KV : AL) {
254 auto AliasName = ES.
intern(KV.first);
255 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
256 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
262 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
263 *
this, COFFHeaderStartSymbol)))
266 if (
auto Err = ES.lookup({&JD}, COFFHeaderStartSymbol).takeError())
275 auto PerJDObj = getPerJDObjectFile();
277 return PerJDObj.takeError();
281 return I.takeError();
283 if (
auto Err = ObjLinkingLayer.add(
287 if (!Bootstrapping) {
288 auto ImportedLibs = StaticVCRuntime
289 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
290 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
292 return ImportedLibs.takeError();
293 for (
auto &
Lib : *ImportedLibs)
294 if (
auto Err = LoadDynLibrary(JD,
Lib))
297 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
306 std::lock_guard<std::mutex> Lock(PlatformMutex);
307 auto I = JITDylibToHeaderAddr.find(&JD);
308 if (
I != JITDylibToHeaderAddr.end()) {
309 assert(HeaderAddrToJITDylib.count(
I->second) &&
310 "HeaderAddrToJITDylib missing entry");
311 HeaderAddrToJITDylib.erase(
I->second);
312 JITDylibToHeaderAddr.erase(
I);
324 RegisteredInitSymbols[&JD].add(InitSym,
328 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
346 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
347 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
348 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
349 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
356 static const std::pair<const char *, const char *>
357 StandardRuntimeUtilityAliases[] = {
358 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
359 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
360 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
361 {
"__orc_rt_jit_dlupdate",
"__orc_rt_coff_jit_dlupdate"},
362 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
363 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
364 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
367 StandardRuntimeUtilityAliases);
370bool COFFPlatform::supportedTarget(
const Triple &TT) {
371 switch (TT.getArch()) {
379COFFPlatform::COFFPlatform(
381 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
382 std::set<std::string> DylibsToPreload,
383 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
384 std::unique_ptr<object::Archive> OrcRuntimeArchive,
385 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
386 const char *VCRuntimePath,
Error &Err)
387 : ES(ObjLinkingLayer.getExecutionSession()),
388 ObjLinkingLayer(ObjLinkingLayer),
389 LoadDynLibrary(
std::
move(LoadDynLibrary)),
390 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
391 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
392 StaticVCRuntime(StaticVCRuntime),
393 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
396 Bootstrapping.store(
true);
397 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
403 Err = VCRT.takeError();
406 VCRuntimeBootstrap = std::move(*VCRT);
409 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
410 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
412 Err = ImportedLibs.takeError();
416 for (
auto &
Lib : *ImportedLibs)
417 DylibsToPreload.insert(
Lib);
419 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
428 for (
auto&
Lib : DylibsToPreload)
429 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
435 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
441 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
449 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
454 Bootstrapping.store(
false);
455 JDBootstrapStates.clear();
458Expected<COFFPlatform::JITDylibDepMap>
459COFFPlatform::buildJDDepMap(
JITDylib &JD) {
460 return ES.runSessionLocked([&]() -> Expected<JITDylibDepMap> {
461 JITDylibDepMap JDDepMap;
464 while (!Worklist.empty()) {
465 auto CurJD = Worklist.back();
468 auto &
DM = JDDepMap[CurJD];
470 DM.reserve(
O.size());
472 if (KV.first == CurJD)
476 std::lock_guard<std::mutex> Lock(PlatformMutex);
477 if (!JITDylibToHeaderAddr.count(KV.first)) {
479 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
481 << CurJD->getName() <<
"\n";
486 DM.push_back(KV.first);
488 if (JDDepMap.try_emplace(KV.first).second)
489 Worklist.push_back(KV.first);
493 return std::move(JDDepMap);
497void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
499 JITDylibDepMap &JDDepMap) {
501 DenseSet<JITDylib *> Visited({JD.
get()});
502 DenseMap<JITDylib *, SymbolLookupSet> NewInitSymbols;
503 ES.runSessionLocked([&]() {
504 while (!Worklist.empty()) {
505 auto CurJD = Worklist.back();
508 auto RISItr = RegisteredInitSymbols.find(CurJD);
509 if (RISItr != RegisteredInitSymbols.end()) {
510 NewInitSymbols[CurJD] = std::move(RISItr->second);
511 RegisteredInitSymbols.erase(RISItr);
514 for (
auto *DepJD : JDDepMap[CurJD])
515 if (Visited.insert(DepJD).second)
516 Worklist.push_back(DepJD);
522 if (NewInitSymbols.
empty()) {
524 COFFJITDylibDepInfoMap DIM;
525 DIM.reserve(JDDepMap.size());
526 for (
auto &KV : JDDepMap) {
527 std::lock_guard<std::mutex> Lock(PlatformMutex);
528 COFFJITDylibDepInfo DepInfo;
529 DepInfo.reserve(KV.second.size());
530 for (
auto &Dep : KV.second) {
531 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
533 auto H = JITDylibToHeaderAddr[KV.first];
534 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
542 [
this, SendResult = std::move(SendResult), &JD,
543 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
545 SendResult(std::move(Err));
547 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
549 ES, std::move(NewInitSymbols));
552void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
556 std::lock_guard<std::mutex> Lock(PlatformMutex);
557 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
558 if (
I != HeaderAddrToJITDylib.end())
563 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
565 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
567 dbgs() <<
"No JITDylib for header address.\n";
572 formatv(
"{0:x}", JDHeaderAddr),
577 auto JDDepMap = buildJDDepMap(*JD);
579 SendResult(JDDepMap.takeError());
583 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
586void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
588 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
590 JITDylib *JD =
nullptr;
593 std::lock_guard<std::mutex> Lock(PlatformMutex);
594 auto I = HeaderAddrToJITDylib.find(Handle);
595 if (
I != HeaderAddrToJITDylib.end())
600 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
608 class RtLookupNotifyComplete {
610 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
611 : SendResult(std::
move(SendResult)) {}
612 void operator()(Expected<SymbolMap>
Result) {
614 assert(
Result->size() == 1 &&
"Unexpected result map count");
615 SendResult(
Result->begin()->second.getAddress());
617 SendResult(
Result.takeError());
622 SendSymbolAddressFn SendResult;
631Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
634 using LookupSymbolSPSSig =
635 SPSExpected<SPSExecutorAddr>(SPSExecutorAddr,
SPSString);
636 WFs[ES.intern(
"__orc_rt_coff_symbol_lookup_tag")] =
637 ES.wrapAsyncWithSPS<LookupSymbolSPSSig>(
this,
638 &COFFPlatform::rt_lookupSymbol);
639 using PushInitializersSPSSig =
640 SPSExpected<SPSCOFFJITDylibDepInfoMap>(SPSExecutorAddr);
641 WFs[ES.intern(
"__orc_rt_coff_push_initializers_tag")] =
642 ES.wrapAsyncWithSPS<PushInitializersSPSSig>(
643 this, &COFFPlatform::rt_pushInitializers);
645 return ES.registerJITDispatchHandlers(PlatformJD, std::move(WFs));
648Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
651 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
654 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
658 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
663Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
666 auto CallInitializer = rt::sps::Int32VoidCaller::Create(ES);
667 if (!CallInitializer)
668 return CallInitializer.takeError();
669 for (
auto &Initializer : BState.Initializers)
670 if (Initializer.first >= Start && Initializer.first <= End &&
671 Initializer.second) {
672 auto Res = (*CallInitializer)(Initializer.second);
674 return Res.takeError();
679Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
685 {ES.intern(
"__orc_rt_coff_platform_bootstrap"),
686 &orc_rt_coff_platform_bootstrap},
687 {ES.intern(
"__orc_rt_coff_platform_shutdown"),
688 &orc_rt_coff_platform_shutdown},
689 {ES.intern(
"__orc_rt_coff_register_jitdylib"),
690 &orc_rt_coff_register_jitdylib},
691 {ES.intern(
"__orc_rt_coff_deregister_jitdylib"),
692 &orc_rt_coff_deregister_jitdylib},
693 {ES.intern(
"__orc_rt_coff_register_object_sections"),
694 &orc_rt_coff_register_object_sections},
695 {ES.intern(
"__orc_rt_coff_deregister_object_sections"),
696 &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 jit_function;
736 {{ES.intern(SymbolName), &jit_function}});
737 if (!AfterCLookupErr) {
738 auto CallFn = rt::sps::Int32VoidCaller::Create(ES);
740 return CallFn.takeError();
741 auto Res = (*CallFn)(jit_function);
743 return Res.takeError();
746 if (!AfterCLookupErr.isA<SymbolsNotFound>())
747 return AfterCLookupErr;
752void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
754 jitlink::PassConfiguration &Config) {
756 bool IsBootstrapping = CP.Bootstrapping.load();
759 if (InitSymbol == CP.COFFHeaderStartSymbol) {
761 [
this, &MR, IsBootstrapping](jitlink::LinkGraph &
G) {
762 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
767 return preserveInitializerSections(
G, MR);
771 if (!IsBootstrapping)
774 return registerObjectPlatformSections(G, JD);
779 return registerObjectPlatformSectionsInBootstrap(G, JD);
783Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
784 jitlink::LinkGraph &
G, MaterializationResponsibility &MR,
785 bool IsBootstraping) {
786 auto I =
llvm::find_if(
G.defined_symbols(), [
this](jitlink::Symbol *Sym) {
787 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
789 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
792 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
793 auto HeaderAddr = (*I)->getAddress();
794 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
795 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
796 if (!IsBootstraping) {
797 G.allocActions().push_back(
799 SPSArgList<SPSString, SPSExecutorAddr>>(
800 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
802 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
804 G.allocActions().push_back(
807 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
808 JDBootstrapState BState;
811 BState.HeaderAddr = HeaderAddr;
812 CP.JDBootstrapStates.emplace(&JD, BState);
818Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
819 jitlink::LinkGraph &
G, JITDylib &JD) {
820 COFFObjectSectionsMap ObjSecs;
821 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
822 assert(HeaderAddr &&
"Must be registered jitdylib");
823 for (
auto &S :
G.sections()) {
824 jitlink::SectionRange
Range(S);
826 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
829 G.allocActions().push_back(
831 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
834 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
840Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
841 jitlink::LinkGraph &
G, MaterializationResponsibility &MR) {
845 jitlink::Symbol *InitSym =
nullptr;
847 for (
auto &InitSection :
G.sections()) {
856 auto &
B = **InitSection.blocks().begin();
857 InitSym = &
G.addDefinedSymbol(
863 for (
auto *
B : InitSection.blocks()) {
867 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
876Error COFFPlatform::COFFPlatformPlugin::
877 registerObjectPlatformSectionsInBootstrap(jitlink::LinkGraph &
G,
879 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
880 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
881 COFFObjectSectionsMap ObjSecs;
882 for (
auto &S :
G.sections()) {
883 jitlink::SectionRange
Range(S);
885 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
888 G.allocActions().push_back(
892 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
895 auto &BState = CP.JDBootstrapStates[&JD];
896 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
899 for (
auto &S :
G.sections())
901 for (
auto *
B : S.blocks()) {
902 if (
B->edges_empty())
904 for (
auto &
E :
B->edges())
905 BState.Initializers.push_back(std::make_pair(
906 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
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,...
jitlink::Block & createHeaderBlock(MachOPlatform &MOP, const MachOPlatform::HeaderOptions &Opts, JITDylib &JD, jitlink::LinkGraph &G, jitlink::Section &HeaderSection)
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.