24#define DEBUG_TYPE "orc"
81 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
82 auto G = std::make_unique<jitlink::LinkGraph>(
83 "<COFFHeaderMU>", CP.getExecutionSession().getSymbolStringPool(),
90 auto &ImageBaseSymbol =
G->addDefinedSymbol(
91 HeaderBlock, 0, *R->getInitializerSymbol(), HeaderBlock.getSize(),
94 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
96 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
99 void discard(
const JITDylib &JD,
const SymbolStringPtr &Sym)
override {}
102 struct HeaderSymbol {
109 object::coff_file_header FileHeader;
111 object::pe32plus_header Header;
116 struct HeaderBlockContent {
117 object::dos_header DOSHeader;
118 COFFHeaderMaterializationUnit::NTHeader NTHeader;
122 jitlink::Section &HeaderSection) {
123 HeaderBlockContent Hdr = {};
126 Hdr.DOSHeader.Magic[0] =
'M';
127 Hdr.DOSHeader.Magic[1] =
'Z';
128 Hdr.DOSHeader.AddressOfNewExeHeader =
129 offsetof(HeaderBlockContent, NTHeader);
130 uint32_t PEMagic = *
reinterpret_cast<const uint32_t *
>(
COFF::PEMagic);
131 Hdr.NTHeader.PEMagic = PEMagic;
134 switch (
G.getTargetTriple().getArch()) {
142 auto HeaderContent =
G.allocateContent(
143 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
145 return G.createContentBlock(HeaderSection, HeaderContent, ExecutorAddr(), 8,
149 static void addImageBaseRelocationEdge(jitlink::Block &
B,
150 jitlink::Symbol &ImageBase) {
151 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
152 offsetof(NTHeader, OptionalHeader) +
153 offsetof(object::pe32plus_header, ImageBase);
157 static MaterializationUnit::Interface
158 createHeaderInterface(COFFPlatform &MOP,
159 const SymbolStringPtr &HeaderStartSymbol) {
164 return MaterializationUnit::Interface(std::move(HeaderSymbolFlags),
176Expected<std::unique_ptr<COFFPlatform>>
178 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
180 const char *VCRuntimePath,
181 std::optional<SymbolAliasMap> RuntimeAliases) {
183 auto &ES = ObjLinkingLayer.getExecutionSession();
186 if (!supportedTarget(ES.getTargetTriple()))
188 ES.getTargetTriple().str(),
191 auto GeneratorArchive =
193 if (!GeneratorArchive)
194 return GeneratorArchive.takeError();
196 std::set<std::string> DylibsToPreload;
198 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive),
200 if (!OrcRuntimeArchiveGenerator)
201 return OrcRuntimeArchiveGenerator.takeError();
215 return std::move(Err);
221 ES.getBootstrapJITDylib(),
222 {{Mangle(rt::DispatchName), Mangle(rt::DispatchCtxName)}});
224 return Exports.takeError();
233 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
234 std::move(DylibsToPreload), std::move(OrcRuntimeArchiveBuffer),
235 std::move(RuntimeArchive), std::move(LoadDynLibrary), StaticVCRuntime,
236 VCRuntimePath, Err));
238 return std::move(Err);
244 const char *OrcRuntimePath,
246 const char *VCRuntimePath,
247 std::optional<SymbolAliasMap> RuntimeAliases) {
253 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
254 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
255 std::move(RuntimeAliases));
259 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
267 auto Buffer = (*PerJDObj)->getAsBinary();
269 return Buffer.takeError();
271 return (*Buffer)->getMemoryBufferRef();
275 ArrayRef<std::pair<const char *, const char *>> AL) {
276 for (
auto &KV : AL) {
277 auto AliasName = ES.
intern(KV.first);
278 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
279 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
285 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
286 *
this, COFFHeaderStartSymbol)))
289 if (
auto Err = ES.lookup({&JD}, COFFHeaderStartSymbol).takeError())
298 auto PerJDObj = getPerJDObjectFile();
300 return PerJDObj.takeError();
304 return I.takeError();
306 if (
auto Err = ObjLinkingLayer.add(
310 if (!Bootstrapping) {
311 auto ImportedLibs = StaticVCRuntime
312 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
313 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
315 return ImportedLibs.takeError();
316 for (
auto &
Lib : *ImportedLibs)
317 if (
auto Err = LoadDynLibrary(JD,
Lib))
320 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
329 std::lock_guard<std::mutex> Lock(PlatformMutex);
330 auto I = JITDylibToHeaderAddr.find(&JD);
331 if (
I != JITDylibToHeaderAddr.end()) {
332 assert(HeaderAddrToJITDylib.count(
I->second) &&
333 "HeaderAddrToJITDylib missing entry");
334 HeaderAddrToJITDylib.erase(
I->second);
335 JITDylibToHeaderAddr.erase(
I);
347 RegisteredInitSymbols[&JD].add(InitSym,
351 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
369 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
370 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
371 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
372 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
379 static const std::pair<const char *, const char *>
380 StandardRuntimeUtilityAliases[] = {
381 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
382 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
383 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
384 {
"__orc_rt_jit_dlupdate",
"__orc_rt_coff_jit_dlupdate"},
385 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
386 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
387 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
390 StandardRuntimeUtilityAliases);
393bool COFFPlatform::supportedTarget(
const Triple &TT) {
394 switch (TT.getArch()) {
402COFFPlatform::COFFPlatform(
404 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
405 std::set<std::string> DylibsToPreload,
406 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
407 std::unique_ptr<object::Archive> OrcRuntimeArchive,
408 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
409 const char *VCRuntimePath,
Error &Err)
410 : ES(ObjLinkingLayer.getExecutionSession()),
411 ObjLinkingLayer(ObjLinkingLayer),
412 LoadDynLibrary(
std::
move(LoadDynLibrary)),
413 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
414 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
415 StaticVCRuntime(StaticVCRuntime),
416 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
419 Bootstrapping.store(
true);
420 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
426 Err = VCRT.takeError();
429 VCRuntimeBootstrap = std::move(*VCRT);
432 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
433 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
435 Err = ImportedLibs.takeError();
439 for (
auto &
Lib : *ImportedLibs)
440 DylibsToPreload.insert(
Lib);
442 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
451 for (
auto&
Lib : DylibsToPreload)
452 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
458 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
464 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
472 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
477 Bootstrapping.store(
false);
478 JDBootstrapStates.clear();
481Expected<COFFPlatform::JITDylibDepMap>
482COFFPlatform::buildJDDepMap(
JITDylib &JD) {
483 return ES.runSessionLocked([&]() -> Expected<JITDylibDepMap> {
484 JITDylibDepMap JDDepMap;
487 while (!Worklist.empty()) {
488 auto CurJD = Worklist.back();
491 auto &
DM = JDDepMap[CurJD];
493 DM.reserve(
O.size());
495 if (KV.first == CurJD)
499 std::lock_guard<std::mutex> Lock(PlatformMutex);
500 if (!JITDylibToHeaderAddr.count(KV.first)) {
502 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
504 << CurJD->getName() <<
"\n";
509 DM.push_back(KV.first);
511 if (JDDepMap.try_emplace(KV.first).second)
512 Worklist.push_back(KV.first);
516 return std::move(JDDepMap);
520void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
522 JITDylibDepMap &JDDepMap) {
524 DenseSet<JITDylib *> Visited({JD.
get()});
525 DenseMap<JITDylib *, SymbolLookupSet> NewInitSymbols;
526 ES.runSessionLocked([&]() {
527 while (!Worklist.empty()) {
528 auto CurJD = Worklist.back();
531 auto RISItr = RegisteredInitSymbols.find(CurJD);
532 if (RISItr != RegisteredInitSymbols.end()) {
533 NewInitSymbols[CurJD] = std::move(RISItr->second);
534 RegisteredInitSymbols.erase(RISItr);
537 for (
auto *DepJD : JDDepMap[CurJD])
538 if (Visited.insert(DepJD).second)
539 Worklist.push_back(DepJD);
545 if (NewInitSymbols.
empty()) {
547 COFFJITDylibDepInfoMap DIM;
548 DIM.reserve(JDDepMap.size());
549 for (
auto &KV : JDDepMap) {
550 std::lock_guard<std::mutex> Lock(PlatformMutex);
551 COFFJITDylibDepInfo DepInfo;
552 DepInfo.reserve(KV.second.size());
553 for (
auto &Dep : KV.second) {
554 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
556 auto H = JITDylibToHeaderAddr[KV.first];
557 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
565 [
this, SendResult = std::move(SendResult), &JD,
566 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
568 SendResult(std::move(Err));
570 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
572 ES, std::move(NewInitSymbols));
575void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
579 std::lock_guard<std::mutex> Lock(PlatformMutex);
580 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
581 if (
I != HeaderAddrToJITDylib.end())
586 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
588 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
590 dbgs() <<
"No JITDylib for header address.\n";
595 formatv(
"{0:x}", JDHeaderAddr),
600 auto JDDepMap = buildJDDepMap(*JD);
602 SendResult(JDDepMap.takeError());
606 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
609void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
611 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
613 JITDylib *JD =
nullptr;
616 std::lock_guard<std::mutex> Lock(PlatformMutex);
617 auto I = HeaderAddrToJITDylib.find(Handle);
618 if (
I != HeaderAddrToJITDylib.end())
623 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
631 class RtLookupNotifyComplete {
633 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
634 : SendResult(std::
move(SendResult)) {}
635 void operator()(Expected<SymbolMap>
Result) {
637 assert(
Result->size() == 1 &&
"Unexpected result map count");
638 SendResult(
Result->begin()->second.getAddress());
640 SendResult(
Result.takeError());
645 SendSymbolAddressFn SendResult;
654Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
657 using LookupSymbolSPSSig =
658 SPSExpected<SPSExecutorAddr>(SPSExecutorAddr,
SPSString);
659 WFs[ES.intern(
"__orc_rt_coff_symbol_lookup_tag")] =
660 ES.wrapAsyncWithSPS<LookupSymbolSPSSig>(
this,
661 &COFFPlatform::rt_lookupSymbol);
662 using PushInitializersSPSSig =
663 SPSExpected<SPSCOFFJITDylibDepInfoMap>(SPSExecutorAddr);
664 WFs[ES.intern(
"__orc_rt_coff_push_initializers_tag")] =
665 ES.wrapAsyncWithSPS<PushInitializersSPSSig>(
666 this, &COFFPlatform::rt_pushInitializers);
668 return ES.registerJITDispatchHandlers(PlatformJD, std::move(WFs));
671Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
674 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
677 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
681 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
686Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
691 ES.getBootstrapJITDylib(),
692 {recordProxy<sps::CallInt32VoidProxySpec>(&CallInitializer)}))
694 for (
auto &Initializer : BState.Initializers)
695 if (Initializer.first >= Start && Initializer.first <= End &&
696 Initializer.second) {
697 auto Res = CallInitializer(ES, Initializer.second);
699 return Res.takeError();
704Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
711 &orc_rt_coff_platform_bootstrap),
714 &orc_rt_coff_platform_shutdown),
717 &orc_rt_coff_register_jitdylib),
720 &orc_rt_coff_deregister_jitdylib),
722 "__orc_rt_coff_register_object_sections"),
723 &orc_rt_coff_register_object_sections),
725 "__orc_rt_coff_deregister_object_sections"),
726 &orc_rt_coff_deregister_object_sections)}))
734 using PlatformBootstrapProxy = Proxy<void()>;
735 using RegisterJITDylibProxy = Proxy<void(std::string, ExecutorAddr)>;
736 using RegisterObjectSectionsProxy =
737 Proxy<void(ExecutorAddr, COFFObjectSectionsMap,
bool)>;
738 using sps::ProxySpec;
740 PlatformBootstrapProxy PlatformBootstrap(
741 ProxySpec<PlatformBootstrapProxy,
742 coff_sps_ci::PlatformBootstrap>::dispatch,
743 orc_rt_coff_platform_bootstrap);
744 RegisterJITDylibProxy RegisterJITDylib(
745 ProxySpec<RegisterJITDylibProxy, coff_sps_ci::RegisterJITDylib>::dispatch,
746 orc_rt_coff_register_jitdylib);
747 RegisterObjectSectionsProxy RegisterObjectSections(
748 ProxySpec<RegisterObjectSectionsProxy,
749 coff_sps_ci::RegisterObjectSections>::dispatch,
750 orc_rt_coff_register_object_sections);
753 if (
auto Err = PlatformBootstrap(ES))
758 for (
auto KV : JDBootstrapStates) {
759 auto &JDBState = KV.second;
760 if (
auto Err = RegisterJITDylib(ES, JDBState.JDName, JDBState.HeaderAddr))
763 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
764 if (
auto Err = RegisterObjectSections(ES, JDBState.HeaderAddr,
765 ObjSectionMap,
false))
770 for (
auto KV : JDBootstrapStates) {
771 auto &JDBState = KV.second;
772 if (
auto Err = runBootstrapInitializers(JDBState))
780 StringRef SymbolName) {
781 ExecutorAddr TargetFn;
793 {recordProxy<sps::CallInt32VoidProxySpec>(&CallFn)}))
796 return CallFn(ES, TargetFn).takeError();
799void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
801 jitlink::PassConfiguration &Config) {
803 bool IsBootstrapping = CP.Bootstrapping.load();
806 if (InitSymbol == CP.COFFHeaderStartSymbol) {
808 [
this, &MR, IsBootstrapping](jitlink::LinkGraph &
G) {
809 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
814 return preserveInitializerSections(
G, MR);
818 if (!IsBootstrapping)
821 return registerObjectPlatformSections(G, JD);
826 return registerObjectPlatformSectionsInBootstrap(G, JD);
830Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
831 jitlink::LinkGraph &
G, MaterializationResponsibility &MR,
832 bool IsBootstraping) {
833 auto I =
llvm::find_if(
G.defined_symbols(), [
this](jitlink::Symbol *Sym) {
834 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
836 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
839 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
840 auto HeaderAddr = (*I)->getAddress();
841 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
842 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
843 if (!IsBootstraping) {
844 G.allocActions().push_back(
846 SPSArgList<SPSString, SPSExecutorAddr>>(
847 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
849 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
851 G.allocActions().push_back(
854 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
855 JDBootstrapState BState;
858 BState.HeaderAddr = HeaderAddr;
859 CP.JDBootstrapStates.emplace(&JD, BState);
865Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
866 jitlink::LinkGraph &
G, JITDylib &JD) {
867 COFFObjectSectionsMap ObjSecs;
868 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
869 assert(HeaderAddr &&
"Must be registered jitdylib");
870 for (
auto &S :
G.sections()) {
871 jitlink::SectionRange
Range(S);
873 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
876 G.allocActions().push_back(
878 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
881 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
887Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
888 jitlink::LinkGraph &
G, MaterializationResponsibility &MR) {
892 jitlink::Symbol *InitSym =
nullptr;
894 for (
auto &InitSection :
G.sections()) {
903 auto &
B = **InitSection.blocks().begin();
904 InitSym = &
G.addDefinedSymbol(
910 for (
auto *
B : InitSection.blocks()) {
914 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
923Error COFFPlatform::COFFPlatformPlugin::
924 registerObjectPlatformSectionsInBootstrap(jitlink::LinkGraph &
G,
926 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
927 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
928 COFFObjectSectionsMap ObjSecs;
929 for (
auto &S :
G.sections()) {
930 jitlink::SectionRange
Range(S);
932 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
935 G.allocActions().push_back(
939 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
942 auto &BState = CP.JDBootstrapStates[&JD];
943 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
946 for (
auto &S :
G.sections())
948 for (
auto *
B : S.blocks()) {
949 if (
B->edges_empty())
951 for (
auto &
E :
B->edges())
952 BState.Initializers.push_back(std::make_pair(
953 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,...
Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
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.
Mangles symbol names then uniques them in the context of an ExecutionSession.
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.
A symbol name together with the naming level (SymbolNameKind) it is expressed in, so that a Mangler /...
static constexpr SymbolNameSpec verbatim(StringRef Name)
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...
LookupPrepareFn recordAddr(SymbolNameSpec Name, ExecutorAddr *A, SymbolLookupFlags LF=SymbolLookupFlags::RequiredSymbol)
Records the address of the symbol with the given name.
@ 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)
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.
void(SPSString, SPSExecutorAddr) SPSSig
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name
void(SPSExecutorAddr, SPSCOFFObjectSectionsMap, bool) SPSSig