25#define DEBUG_TYPE "orc"
82 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
83 auto G = std::make_unique<jitlink::LinkGraph>(
84 "<COFFHeaderMU>", CP.getExecutionSession().getSymbolStringPool(),
85 CP.getExecutionSession().getTargetTriple(),
86 CP.getExecutionSession().getTargetTriple().getArchPointerBitWidth() / 8,
92 auto &ImageBaseSymbol =
G->addDefinedSymbol(
93 HeaderBlock, 0, *R->getInitializerSymbol(), HeaderBlock.getSize(),
96 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
98 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
101 void discard(
const JITDylib &JD,
const SymbolStringPtr &Sym)
override {}
104 struct HeaderSymbol {
111 object::coff_file_header FileHeader;
113 object::pe32plus_header Header;
118 struct HeaderBlockContent {
119 object::dos_header DOSHeader;
120 COFFHeaderMaterializationUnit::NTHeader NTHeader;
124 jitlink::Section &HeaderSection) {
125 HeaderBlockContent Hdr = {};
128 Hdr.DOSHeader.Magic[0] =
'M';
129 Hdr.DOSHeader.Magic[1] =
'Z';
130 Hdr.DOSHeader.AddressOfNewExeHeader =
131 offsetof(HeaderBlockContent, NTHeader);
132 uint32_t PEMagic = *
reinterpret_cast<const uint32_t *
>(
COFF::PEMagic);
133 Hdr.NTHeader.PEMagic = PEMagic;
136 switch (
G.getTargetTriple().getArch()) {
144 auto HeaderContent =
G.allocateContent(
145 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
147 return G.createContentBlock(HeaderSection, HeaderContent, ExecutorAddr(), 8,
151 static void addImageBaseRelocationEdge(jitlink::Block &
B,
152 jitlink::Symbol &ImageBase) {
153 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
154 offsetof(NTHeader, OptionalHeader) +
155 offsetof(object::pe32plus_header, ImageBase);
159 static MaterializationUnit::Interface
160 createHeaderInterface(COFFPlatform &MOP,
161 const SymbolStringPtr &HeaderStartSymbol) {
166 return MaterializationUnit::Interface(std::move(HeaderSymbolFlags),
178Expected<std::unique_ptr<COFFPlatform>>
180 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
182 const char *VCRuntimePath,
183 std::optional<SymbolAliasMap> RuntimeAliases) {
185 auto &ES = ObjLinkingLayer.getExecutionSession();
188 if (!supportedTarget(ES.getTargetTriple()))
190 ES.getTargetTriple().str(),
193 auto GeneratorArchive =
195 if (!GeneratorArchive)
196 return GeneratorArchive.takeError();
198 std::set<std::string> DylibsToPreload;
200 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive),
202 if (!OrcRuntimeArchiveGenerator)
203 return OrcRuntimeArchiveGenerator.takeError();
217 return std::move(Err);
223 ES.getBootstrapJITDylib(),
224 {{Mangle(rt::DispatchName), Mangle(rt::DispatchCtxName)}});
226 return Exports.takeError();
235 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
236 std::move(DylibsToPreload), std::move(OrcRuntimeArchiveBuffer),
237 std::move(RuntimeArchive), std::move(LoadDynLibrary), StaticVCRuntime,
238 VCRuntimePath, Err));
240 return std::move(Err);
246 const char *OrcRuntimePath,
248 const char *VCRuntimePath,
249 std::optional<SymbolAliasMap> RuntimeAliases) {
255 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
256 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
257 std::move(RuntimeAliases));
261 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
269 auto Buffer = (*PerJDObj)->getAsBinary();
271 return Buffer.takeError();
273 return (*Buffer)->getMemoryBufferRef();
277 ArrayRef<std::pair<const char *, const char *>> AL) {
278 for (
auto &KV : AL) {
279 auto AliasName = ES.
intern(KV.first);
280 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
281 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
287 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
288 *
this, COFFHeaderStartSymbol)))
291 if (
auto Err = ES.lookup({&JD}, COFFHeaderStartSymbol).takeError())
300 auto PerJDObj = getPerJDObjectFile();
302 return PerJDObj.takeError();
306 return I.takeError();
308 if (
auto Err = ObjLinkingLayer.add(
312 if (!Bootstrapping) {
313 auto ImportedLibs = StaticVCRuntime
314 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
315 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
317 return ImportedLibs.takeError();
318 for (
auto &
Lib : *ImportedLibs)
319 if (
auto Err = LoadDynLibrary(JD,
Lib))
322 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
331 std::lock_guard<std::mutex> Lock(PlatformMutex);
332 auto I = JITDylibToHeaderAddr.find(&JD);
333 if (
I != JITDylibToHeaderAddr.end()) {
334 assert(HeaderAddrToJITDylib.count(
I->second) &&
335 "HeaderAddrToJITDylib missing entry");
336 HeaderAddrToJITDylib.erase(
I->second);
337 JITDylibToHeaderAddr.erase(
I);
349 RegisteredInitSymbols[&JD].add(InitSym,
353 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
371 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
372 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
373 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
374 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
381 static const std::pair<const char *, const char *>
382 StandardRuntimeUtilityAliases[] = {
383 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
384 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
385 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
386 {
"__orc_rt_jit_dlupdate",
"__orc_rt_coff_jit_dlupdate"},
387 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
388 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
389 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
392 StandardRuntimeUtilityAliases);
395bool COFFPlatform::supportedTarget(
const Triple &TT) {
396 switch (TT.getArch()) {
404COFFPlatform::COFFPlatform(
406 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
407 std::set<std::string> DylibsToPreload,
408 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
409 std::unique_ptr<object::Archive> OrcRuntimeArchive,
410 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
411 const char *VCRuntimePath,
Error &Err)
412 : ES(ObjLinkingLayer.getExecutionSession()),
413 ObjLinkingLayer(ObjLinkingLayer),
414 LoadDynLibrary(
std::
move(LoadDynLibrary)),
415 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
416 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
417 StaticVCRuntime(StaticVCRuntime),
418 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
421 Bootstrapping.store(
true);
422 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
428 Err = VCRT.takeError();
431 VCRuntimeBootstrap = std::move(*VCRT);
434 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
435 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
437 Err = ImportedLibs.takeError();
441 for (
auto &
Lib : *ImportedLibs)
442 DylibsToPreload.insert(
Lib);
444 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
453 for (
auto&
Lib : DylibsToPreload)
454 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
460 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
466 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
474 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
479 Bootstrapping.store(
false);
480 JDBootstrapStates.clear();
483Expected<COFFPlatform::JITDylibDepMap>
484COFFPlatform::buildJDDepMap(
JITDylib &JD) {
485 return ES.runSessionLocked([&]() -> Expected<JITDylibDepMap> {
486 JITDylibDepMap JDDepMap;
489 while (!Worklist.empty()) {
490 auto CurJD = Worklist.back();
493 auto &
DM = JDDepMap[CurJD];
495 DM.reserve(
O.size());
497 if (KV.first == CurJD)
501 std::lock_guard<std::mutex> Lock(PlatformMutex);
502 if (!JITDylibToHeaderAddr.count(KV.first)) {
504 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
506 << CurJD->getName() <<
"\n";
511 DM.push_back(KV.first);
513 if (JDDepMap.try_emplace(KV.first).second)
514 Worklist.push_back(KV.first);
518 return std::move(JDDepMap);
522void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
524 JITDylibDepMap &JDDepMap) {
526 DenseSet<JITDylib *> Visited({JD.
get()});
527 DenseMap<JITDylib *, SymbolLookupSet> NewInitSymbols;
528 ES.runSessionLocked([&]() {
529 while (!Worklist.empty()) {
530 auto CurJD = Worklist.back();
533 auto RISItr = RegisteredInitSymbols.find(CurJD);
534 if (RISItr != RegisteredInitSymbols.end()) {
535 NewInitSymbols[CurJD] = std::move(RISItr->second);
536 RegisteredInitSymbols.erase(RISItr);
539 for (
auto *DepJD : JDDepMap[CurJD])
540 if (Visited.insert(DepJD).second)
541 Worklist.push_back(DepJD);
547 if (NewInitSymbols.
empty()) {
549 COFFJITDylibDepInfoMap DIM;
550 DIM.reserve(JDDepMap.size());
551 for (
auto &KV : JDDepMap) {
552 std::lock_guard<std::mutex> Lock(PlatformMutex);
553 COFFJITDylibDepInfo DepInfo;
554 DepInfo.reserve(KV.second.size());
555 for (
auto &Dep : KV.second) {
556 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
558 auto H = JITDylibToHeaderAddr[KV.first];
559 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
567 [
this, SendResult = std::move(SendResult), &JD,
568 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
570 SendResult(std::move(Err));
572 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
574 ES, std::move(NewInitSymbols));
577void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
581 std::lock_guard<std::mutex> Lock(PlatformMutex);
582 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
583 if (
I != HeaderAddrToJITDylib.end())
588 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
590 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
592 dbgs() <<
"No JITDylib for header address.\n";
597 formatv(
"{0:x}", JDHeaderAddr),
602 auto JDDepMap = buildJDDepMap(*JD);
604 SendResult(JDDepMap.takeError());
608 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
611void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
613 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
615 JITDylib *JD =
nullptr;
618 std::lock_guard<std::mutex> Lock(PlatformMutex);
619 auto I = HeaderAddrToJITDylib.find(Handle);
620 if (
I != HeaderAddrToJITDylib.end())
625 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
633 class RtLookupNotifyComplete {
635 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
636 : SendResult(std::
move(SendResult)) {}
637 void operator()(Expected<SymbolMap>
Result) {
639 assert(
Result->size() == 1 &&
"Unexpected result map count");
640 SendResult(
Result->begin()->second.getAddress());
642 SendResult(
Result.takeError());
647 SendSymbolAddressFn SendResult;
656Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
657 using LookupSymbolSPSSig =
658 SPSExpected<SPSExecutorAddr>(SPSExecutorAddr,
SPSString);
660 using PushInitializersSPSSig =
661 SPSExpected<SPSCOFFJITDylibDepInfoMap>(SPSExecutorAddr);
663 return ES.registerCallControllerHandlers(
667 &COFFPlatform::rt_lookupSymbol),
670 &COFFPlatform::rt_pushInitializers));
673Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
676 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
679 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
683 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
688Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
693 ES.getBootstrapJITDylib(),
694 {recordProxy<sps::CallInt32VoidProxySpec>(&CallInitializer)}))
696 for (
auto &Initializer : BState.Initializers)
697 if (Initializer.first >= Start && Initializer.first <= End &&
698 Initializer.second) {
699 auto Res = CallInitializer(ES, Initializer.second);
701 return Res.takeError();
706Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
712 &orc_rt_coff_platform_bootstrap),
714 &orc_rt_coff_platform_shutdown),
716 &orc_rt_coff_register_jitdylib),
718 &orc_rt_coff_deregister_jitdylib),
721 &orc_rt_coff_register_object_sections),
724 &orc_rt_coff_deregister_object_sections)}))
732 using PlatformBootstrapProxy = Proxy<void()>;
733 using RegisterJITDylibProxy = Proxy<void(std::string, ExecutorAddr)>;
734 using RegisterObjectSectionsProxy =
735 Proxy<void(ExecutorAddr, COFFObjectSectionsMap,
bool)>;
736 using sps::ProxySpec;
738 PlatformBootstrapProxy PlatformBootstrap(
739 ProxySpec<PlatformBootstrapProxy,
740 coff_sps_ci::PlatformBootstrap>::dispatch,
741 orc_rt_coff_platform_bootstrap);
742 RegisterJITDylibProxy RegisterJITDylib(
743 ProxySpec<RegisterJITDylibProxy, coff_sps_ci::RegisterJITDylib>::dispatch,
744 orc_rt_coff_register_jitdylib);
745 RegisterObjectSectionsProxy RegisterObjectSections(
746 ProxySpec<RegisterObjectSectionsProxy,
747 coff_sps_ci::RegisterObjectSections>::dispatch,
748 orc_rt_coff_register_object_sections);
751 if (
auto Err = PlatformBootstrap(ES))
756 for (
auto KV : JDBootstrapStates) {
757 auto &JDBState = KV.second;
758 if (
auto Err = RegisterJITDylib(ES, JDBState.JDName, JDBState.HeaderAddr))
761 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
762 if (
auto Err = RegisterObjectSections(ES, JDBState.HeaderAddr,
763 ObjSectionMap,
false))
768 for (
auto KV : JDBootstrapStates) {
769 auto &JDBState = KV.second;
770 if (
auto Err = runBootstrapInitializers(JDBState))
778 StringRef SymbolName) {
779 ExecutorAddr TargetFn;
790 {recordProxy<sps::CallInt32VoidProxySpec>(&CallFn)}))
793 return CallFn(ES, TargetFn).takeError();
796void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
798 jitlink::PassConfiguration &Config) {
800 bool IsBootstrapping = CP.Bootstrapping.load();
803 if (InitSymbol == CP.COFFHeaderStartSymbol) {
805 [
this, &MR, IsBootstrapping](jitlink::LinkGraph &
G) {
806 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
811 return preserveInitializerSections(
G, MR);
815 if (!IsBootstrapping)
818 return registerObjectPlatformSections(G, JD);
823 return registerObjectPlatformSectionsInBootstrap(G, JD);
827Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
828 jitlink::LinkGraph &
G, MaterializationResponsibility &MR,
829 bool IsBootstraping) {
830 auto I =
llvm::find_if(
G.defined_symbols(), [
this](jitlink::Symbol *Sym) {
831 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
833 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
836 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
837 auto HeaderAddr = (*I)->getAddress();
838 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
839 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
840 if (!IsBootstraping) {
841 G.allocActions().push_back(
843 SPSArgList<SPSString, SPSExecutorAddr>>(
844 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
846 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
848 G.allocActions().push_back(
851 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
852 JDBootstrapState BState;
855 BState.HeaderAddr = HeaderAddr;
856 CP.JDBootstrapStates.emplace(&JD, BState);
862Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
863 jitlink::LinkGraph &
G, JITDylib &JD) {
864 COFFObjectSectionsMap ObjSecs;
865 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
866 assert(HeaderAddr &&
"Must be registered jitdylib");
867 for (
auto &S :
G.sections()) {
868 jitlink::SectionRange
Range(S);
870 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
873 G.allocActions().push_back(
875 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
878 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
884Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
885 jitlink::LinkGraph &
G, MaterializationResponsibility &MR) {
889 jitlink::Symbol *InitSym =
nullptr;
891 for (
auto &InitSection :
G.sections()) {
900 auto &
B = **InitSection.blocks().begin();
901 InitSym = &
G.addDefinedSymbol(
907 for (
auto *
B : InitSection.blocks()) {
911 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
920Error COFFPlatform::COFFPlatformPlugin::
921 registerObjectPlatformSectionsInBootstrap(jitlink::LinkGraph &
G,
923 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
924 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
925 COFFObjectSectionsMap ObjSecs;
926 for (
auto &S :
G.sections()) {
927 jitlink::SectionRange
Range(S);
929 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
932 G.allocActions().push_back(
936 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
939 auto &BState = CP.JDBootstrapStates[&JD];
940 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
943 for (
auto &S :
G.sections())
945 for (
auto *
B : S.blocks()) {
946 if (
B->edges_empty())
948 for (
auto &
E :
B->edges())
949 BState.Initializers.push_back(std::make_pair(
950 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.
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 c(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
ExecutionSession::CallControllerHandlerBinding bindCallControllerHandlerSPS(SymbolNameSpec Name, HandlerT &&Handler, SymbolLookupFlags LF=SymbolLookupFlags::RequiredSymbol)
Bind a call-controller handler that takes concrete argument types (and a sender for a concrete return...
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