26#define DEBUG_TYPE "orc"
75 SPSExecutorAddr, SPSString)> {
98 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
99 auto G = std::make_unique<jitlink::LinkGraph>(
100 "<COFFHeaderMU>", CP.getExecutionSession().getSymbolStringPool(),
101 CP.getExecutionSession().getTargetTriple(),
102 CP.getExecutionSession().getTargetTriple().getArchPointerBitWidth() / 8,
104 auto &HeaderSection =
G->createSection(
"__header",
MemProt::Read);
108 auto &ImageBaseSymbol =
G->addDefinedSymbol(
109 HeaderBlock, 0, *R->getInitializerSymbol(), HeaderBlock.getSize(),
112 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
114 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
117 void discard(
const JITDylib &JD,
const SymbolStringPtr &Sym)
override {}
120 struct HeaderSymbol {
127 object::coff_file_header FileHeader;
129 object::pe32plus_header Header;
134 struct HeaderBlockContent {
135 object::dos_header DOSHeader;
136 COFFHeaderMaterializationUnit::NTHeader NTHeader;
140 jitlink::Section &HeaderSection) {
141 HeaderBlockContent Hdr = {};
144 Hdr.DOSHeader.Magic[0] =
'M';
145 Hdr.DOSHeader.Magic[1] =
'Z';
146 Hdr.DOSHeader.AddressOfNewExeHeader =
147 offsetof(HeaderBlockContent, NTHeader);
148 uint32_t PEMagic = *
reinterpret_cast<const uint32_t *
>(
COFF::PEMagic);
149 Hdr.NTHeader.PEMagic = PEMagic;
152 switch (
G.getTargetTriple().getArch()) {
160 auto HeaderContent =
G.allocateContent(
161 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
163 return G.createContentBlock(HeaderSection, HeaderContent, ExecutorAddr(), 8,
167 static void addImageBaseRelocationEdge(jitlink::Block &
B,
168 jitlink::Symbol &ImageBase) {
169 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
170 offsetof(NTHeader, OptionalHeader) +
171 offsetof(object::pe32plus_header, ImageBase);
175 static MaterializationUnit::Interface
176 createHeaderInterface(COFFPlatform &MOP,
177 const SymbolStringPtr &HeaderStartSymbol) {
182 return MaterializationUnit::Interface(std::move(HeaderSymbolFlags),
194Expected<std::unique_ptr<COFFPlatform>>
196 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
198 const char *VCRuntimePath,
199 std::optional<SymbolAliasMap> RuntimeAliases) {
201 auto &ES = ObjLinkingLayer.getExecutionSession();
204 if (!supportedTarget(ES.getTargetTriple()))
206 ES.getTargetTriple().str(),
209 auto GeneratorArchive =
211 if (!GeneratorArchive)
212 return GeneratorArchive.takeError();
214 std::set<std::string> DylibsToPreload;
216 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive),
218 if (!OrcRuntimeArchiveGenerator)
219 return OrcRuntimeArchiveGenerator.takeError();
233 return std::move(Err);
239 ES.getBootstrapJITDylib(),
240 {{Mangle(rt::DispatchName), Mangle(rt::DispatchCtxName)}});
242 return Exports.takeError();
251 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
252 std::move(DylibsToPreload), std::move(OrcRuntimeArchiveBuffer),
253 std::move(RuntimeArchive), std::move(LoadDynLibrary), StaticVCRuntime,
254 VCRuntimePath, Err));
256 return std::move(Err);
262 const char *OrcRuntimePath,
264 const char *VCRuntimePath,
265 std::optional<SymbolAliasMap> RuntimeAliases) {
271 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
272 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
273 std::move(RuntimeAliases));
277 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
285 auto Buffer = (*PerJDObj)->getAsBinary();
287 return Buffer.takeError();
289 return (*Buffer)->getMemoryBufferRef();
293 ArrayRef<std::pair<const char *, const char *>> AL) {
294 for (
auto &KV : AL) {
295 auto AliasName = ES.
intern(KV.first);
296 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
297 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
303 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
304 *
this, COFFHeaderStartSymbol)))
307 if (
auto Err = ES.lookup({&JD}, COFFHeaderStartSymbol).takeError())
316 auto PerJDObj = getPerJDObjectFile();
318 return PerJDObj.takeError();
322 return I.takeError();
324 if (
auto Err = ObjLinkingLayer.add(
328 if (!Bootstrapping) {
329 auto ImportedLibs = StaticVCRuntime
330 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
331 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
333 return ImportedLibs.takeError();
334 for (
auto &
Lib : *ImportedLibs)
335 if (
auto Err = LoadDynLibrary(JD,
Lib))
338 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
347 std::lock_guard<std::mutex> Lock(PlatformMutex);
348 auto I = JITDylibToHeaderAddr.find(&JD);
349 if (
I != JITDylibToHeaderAddr.end()) {
350 assert(HeaderAddrToJITDylib.count(
I->second) &&
351 "HeaderAddrToJITDylib missing entry");
352 HeaderAddrToJITDylib.erase(
I->second);
353 JITDylibToHeaderAddr.erase(
I);
365 RegisteredInitSymbols[&JD].add(InitSym,
369 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
387 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
388 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
389 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
390 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
397 static const std::pair<const char *, const char *>
398 StandardRuntimeUtilityAliases[] = {
399 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
400 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
401 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
402 {
"__orc_rt_jit_dlupdate",
"__orc_rt_coff_jit_dlupdate"},
403 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
404 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
405 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
408 StandardRuntimeUtilityAliases);
411bool COFFPlatform::supportedTarget(
const Triple &TT) {
412 switch (TT.getArch()) {
420COFFPlatform::COFFPlatform(
422 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
423 std::set<std::string> DylibsToPreload,
424 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
425 std::unique_ptr<object::Archive> OrcRuntimeArchive,
426 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
427 const char *VCRuntimePath,
Error &Err)
428 : ES(ObjLinkingLayer.getExecutionSession()),
429 ObjLinkingLayer(ObjLinkingLayer),
430 LoadDynLibrary(
std::
move(LoadDynLibrary)),
431 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
432 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
433 StaticVCRuntime(StaticVCRuntime),
434 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
437 Bootstrapping.store(
true);
438 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
444 Err = VCRT.takeError();
447 VCRuntimeBootstrap = std::move(*VCRT);
450 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
451 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
453 Err = ImportedLibs.takeError();
457 for (
auto &
Lib : *ImportedLibs)
458 DylibsToPreload.insert(
Lib);
460 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
469 for (
auto&
Lib : DylibsToPreload)
470 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
476 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
482 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
490 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
495 Bootstrapping.store(
false);
496 JDBootstrapStates.clear();
499Expected<COFFPlatform::JITDylibDepMap>
500COFFPlatform::buildJDDepMap(
JITDylib &JD) {
501 return ES.runSessionLocked([&]() -> Expected<JITDylibDepMap> {
502 JITDylibDepMap JDDepMap;
505 while (!Worklist.empty()) {
506 auto CurJD = Worklist.back();
509 auto &
DM = JDDepMap[CurJD];
511 DM.reserve(
O.size());
513 if (KV.first == CurJD)
517 std::lock_guard<std::mutex> Lock(PlatformMutex);
518 if (!JITDylibToHeaderAddr.count(KV.first)) {
520 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
522 << CurJD->getName() <<
"\n";
527 DM.push_back(KV.first);
529 if (JDDepMap.try_emplace(KV.first).second)
530 Worklist.push_back(KV.first);
534 return std::move(JDDepMap);
538void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
540 JITDylibDepMap &JDDepMap) {
542 DenseSet<JITDylib *> Visited({JD.
get()});
543 DenseMap<JITDylib *, SymbolLookupSet> NewInitSymbols;
544 ES.runSessionLocked([&]() {
545 while (!Worklist.empty()) {
546 auto CurJD = Worklist.back();
549 auto RISItr = RegisteredInitSymbols.find(CurJD);
550 if (RISItr != RegisteredInitSymbols.end()) {
551 NewInitSymbols[CurJD] = std::move(RISItr->second);
552 RegisteredInitSymbols.erase(RISItr);
555 for (
auto *DepJD : JDDepMap[CurJD])
556 if (Visited.insert(DepJD).second)
557 Worklist.push_back(DepJD);
563 if (NewInitSymbols.
empty()) {
565 COFFJITDylibDepInfoMap DIM;
566 DIM.reserve(JDDepMap.size());
567 for (
auto &KV : JDDepMap) {
568 std::lock_guard<std::mutex> Lock(PlatformMutex);
569 COFFJITDylibDepInfo DepInfo;
570 DepInfo.reserve(KV.second.size());
571 for (
auto &Dep : KV.second) {
572 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
574 auto H = JITDylibToHeaderAddr[KV.first];
575 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
583 [
this, SendResult = std::move(SendResult), &JD,
584 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
586 SendResult(std::move(Err));
588 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
590 ES, std::move(NewInitSymbols));
593void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
597 std::lock_guard<std::mutex> Lock(PlatformMutex);
598 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
599 if (
I != HeaderAddrToJITDylib.end())
604 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
606 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
608 dbgs() <<
"No JITDylib for header address.\n";
613 formatv(
"{0:x}", JDHeaderAddr),
618 auto JDDepMap = buildJDDepMap(*JD);
620 SendResult(JDDepMap.takeError());
624 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
627void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
629 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
631 JITDylib *JD =
nullptr;
634 std::lock_guard<std::mutex> Lock(PlatformMutex);
635 auto I = HeaderAddrToJITDylib.find(Handle);
636 if (
I != HeaderAddrToJITDylib.end())
641 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
649 class RtLookupNotifyComplete {
651 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
652 : SendResult(std::
move(SendResult)) {}
653 void operator()(Expected<SymbolMap>
Result) {
655 assert(
Result->size() == 1 &&
"Unexpected result map count");
656 SendResult(
Result->begin()->second.getAddress());
658 SendResult(
Result.takeError());
663 SendSymbolAddressFn SendResult;
672Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
673 return ES.registerCallControllerHandlers(
676 this, &COFFPlatform::rt_lookupSymbol),
678 this, &COFFPlatform::rt_pushInitializers));
681Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
684 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
687 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
691 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
696Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
701 ES.getBootstrapJITDylib(),
702 {recordProxy<sps::CallInt32VoidProxySpec>(&CallInitializer)}))
704 for (
auto &Initializer : BState.Initializers)
705 if (Initializer.first >= Start && Initializer.first <=
End &&
706 Initializer.second) {
707 auto Res = CallInitializer(ES, Initializer.second);
709 return Res.takeError();
714Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
720 &orc_rt_coff_platform_bootstrap),
722 &orc_rt_coff_platform_shutdown),
724 &orc_rt_coff_register_jitdylib),
726 &orc_rt_coff_deregister_jitdylib),
729 &orc_rt_coff_register_object_sections),
732 &orc_rt_coff_deregister_object_sections)}))
740 using PlatformBootstrapProxy = Proxy<void()>;
741 using RegisterJITDylibProxy = Proxy<void(std::string, ExecutorAddr)>;
742 using RegisterObjectSectionsProxy =
743 Proxy<void(ExecutorAddr, COFFObjectSectionsMap,
bool)>;
744 using sps::ProxySpec;
746 PlatformBootstrapProxy PlatformBootstrap(
747 ProxySpec<coff_sps_ci::PlatformBootstrap>::dispatch,
748 orc_rt_coff_platform_bootstrap);
749 RegisterJITDylibProxy RegisterJITDylib(
750 ProxySpec<coff_sps_ci::RegisterJITDylib>::dispatch,
751 orc_rt_coff_register_jitdylib);
752 RegisterObjectSectionsProxy RegisterObjectSections(
753 ProxySpec<coff_sps_ci::RegisterObjectSections>::dispatch,
754 orc_rt_coff_register_object_sections);
757 if (
auto Err = PlatformBootstrap(ES))
762 for (
auto KV : JDBootstrapStates) {
763 auto &JDBState = KV.second;
764 if (
auto Err = RegisterJITDylib(ES, JDBState.JDName, JDBState.HeaderAddr))
767 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
768 if (
auto Err = RegisterObjectSections(ES, JDBState.HeaderAddr,
769 ObjSectionMap,
false))
774 for (
auto KV : JDBootstrapStates) {
775 auto &JDBState = KV.second;
776 if (
auto Err = runBootstrapInitializers(JDBState))
784 StringRef SymbolName) {
785 ExecutorAddr TargetFn;
796 {recordProxy<sps::CallInt32VoidProxySpec>(&CallFn)}))
799 return CallFn(ES, TargetFn).takeError();
802void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
804 jitlink::PassConfiguration &Config) {
806 bool IsBootstrapping = CP.Bootstrapping.load();
809 if (InitSymbol == CP.COFFHeaderStartSymbol) {
811 [
this, &MR, IsBootstrapping](jitlink::LinkGraph &
G) {
812 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
817 return preserveInitializerSections(
G, MR);
821 if (!IsBootstrapping)
824 return registerObjectPlatformSections(G, JD);
829 return registerObjectPlatformSectionsInBootstrap(G, JD);
833Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
834 jitlink::LinkGraph &
G, MaterializationResponsibility &MR,
835 bool IsBootstraping) {
836 auto I =
llvm::find_if(
G.defined_symbols(), [
this](jitlink::Symbol *Sym) {
837 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
839 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
842 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
843 auto HeaderAddr = (*I)->getAddress();
844 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
845 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
846 if (!IsBootstraping) {
847 G.allocActions().push_back(
849 SPSArgList<SPSString, SPSExecutorAddr>>(
850 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
852 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
854 G.allocActions().push_back(
857 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
858 JDBootstrapState BState;
861 BState.HeaderAddr = HeaderAddr;
862 CP.JDBootstrapStates.emplace(&JD, BState);
868Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
869 jitlink::LinkGraph &
G, JITDylib &JD) {
870 COFFObjectSectionsMap ObjSecs;
871 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
872 assert(HeaderAddr &&
"Must be registered jitdylib");
873 for (
auto &S :
G.sections()) {
874 jitlink::SectionRange
Range(S);
876 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
879 G.allocActions().push_back(
881 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
884 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
890Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
891 jitlink::LinkGraph &
G, MaterializationResponsibility &MR) {
895 jitlink::Symbol *InitSym =
nullptr;
897 for (
auto &InitSection :
G.sections()) {
906 auto &
B = **InitSection.blocks().begin();
907 InitSym = &
G.addDefinedSymbol(
913 for (
auto *
B : InitSection.blocks()) {
917 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
926Error COFFPlatform::COFFPlatformPlugin::
927 registerObjectPlatformSectionsInBootstrap(jitlink::LinkGraph &
G,
929 std::lock_guard<std::mutex> Lock(CP.PlatformMutex);
930 auto HeaderAddr = CP.JITDylibToHeaderAddr[&JD];
931 COFFObjectSectionsMap ObjSecs;
932 for (
auto &S :
G.sections()) {
933 jitlink::SectionRange
Range(S);
935 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
938 G.allocActions().push_back(
942 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
945 auto &BState = CP.JDBootstrapStates[&JD];
946 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
949 for (
auto &S :
G.sections())
951 for (
auto *
B : S.blocks()) {
952 if (
B->edges_empty())
954 for (
auto &
E :
B->edges())
955 BState.Initializers.push_back(std::make_pair(
956 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.
Base class for specs that bind handlers for calls with the SPS signature SPSSigT.
#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.
ExecutionSession::CallControllerHandlerBinding bindCallControllerHandler(HandlerT &&H, SymbolLookupFlags LF=SymbolLookupFlags::RequiredSymbol)
Bind H, using the given spec, to the tag with the spec's default name.
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.
@ End
Run the machine verifier once, at the end of the pipeline.
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
static constexpr SymbolNameSpec Name
static constexpr SymbolNameSpec Name