22#define DEBUG_TYPE "orc"
56 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
59 const auto &
TT =
CP.getExecutionSession().getTargetTriple();
61 switch (
TT.getArch()) {
70 auto G = std::make_unique<jitlink::LinkGraph>(
71 "<COFFHeaderMU>",
CP.getExecutionSession().getSymbolStringPool(), TT,
73 auto &HeaderSection =
G->createSection(
"__header", MemProt::Read);
77 auto &ImageBaseSymbol =
G->addDefinedSymbol(
78 HeaderBlock, 0, *
R->getInitializerSymbol(), HeaderBlock.getSize(),
79 jitlink::Linkage::Strong, jitlink::Scope::Default,
false,
true);
81 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
83 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
103 struct HeaderBlockContent {
105 COFFHeaderMaterializationUnit::NTHeader NTHeader;
110 HeaderBlockContent Hdr = {};
113 Hdr.DOSHeader.Magic[0] =
'M';
114 Hdr.DOSHeader.Magic[1] =
'Z';
115 Hdr.DOSHeader.AddressOfNewExeHeader =
116 offsetof(HeaderBlockContent, NTHeader);
118 Hdr.NTHeader.PEMagic = PEMagic;
121 switch (
G.getTargetTriple().getArch()) {
129 auto HeaderContent =
G.allocateContent(
130 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
132 return G.createContentBlock(HeaderSection, HeaderContent,
ExecutorAddr(), 8,
138 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
139 offsetof(NTHeader, OptionalHeader) +
165 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
167 const char *VCRuntimePath,
168 std::optional<SymbolAliasMap> RuntimeAliases) {
174 return make_error<StringError>(
"Unsupported COFFPlatform triple: " +
180 auto GeneratorArchive =
182 if (!GeneratorArchive)
183 return GeneratorArchive.takeError();
186 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive));
187 if (!OrcRuntimeArchiveGenerator)
188 return OrcRuntimeArchiveGenerator.takeError();
202 return std::move(Err);
207 if (
auto Err = HostFuncJD.define(
209 {EPC.getJITDispatchInfo().JITDispatchFunction,
211 {ES.
intern(
"__orc_rt_jit_dispatch_ctx"),
212 {EPC.getJITDispatchInfo().JITDispatchContext,
214 return std::move(Err);
221 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
222 std::move(OrcRuntimeArchiveBuffer), std::move(RuntimeArchive),
223 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath, Err));
225 return std::move(Err);
231 const char *OrcRuntimePath,
233 const char *VCRuntimePath,
234 std::optional<SymbolAliasMap> RuntimeAliases) {
240 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
241 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
242 std::move(RuntimeAliases));
246 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
248 return PerJDObj.takeError();
251 return make_error<StringError>(
"Could not find per jd object file",
254 auto Buffer = (*PerJDObj)->getAsBinary();
256 return Buffer.takeError();
258 return (*Buffer)->getMemoryBufferRef();
262 ArrayRef<std::pair<const char *, const char *>> AL) {
263 for (
auto &KV : AL) {
264 auto AliasName = ES.
intern(KV.first);
265 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
266 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
272 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
273 *
this, COFFHeaderStartSymbol)))
276 if (
auto Err = ES.
lookup({&JD}, COFFHeaderStartSymbol).takeError())
285 auto PerJDObj = getPerJDObjectFile();
287 return PerJDObj.takeError();
291 return I.takeError();
293 if (
auto Err = ObjLinkingLayer.
add(
297 if (!Bootstrapping) {
298 auto ImportedLibs = StaticVCRuntime
299 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
300 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
302 return ImportedLibs.takeError();
303 for (
auto &
Lib : *ImportedLibs)
304 if (
auto Err = LoadDynLibrary(JD,
Lib))
307 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
316 std::lock_guard<std::mutex> Lock(PlatformMutex);
317 auto I = JITDylibToHeaderAddr.find(&JD);
318 if (
I != JITDylibToHeaderAddr.end()) {
319 assert(HeaderAddrToJITDylib.count(
I->second) &&
320 "HeaderAddrToJITDylib missing entry");
321 HeaderAddrToJITDylib.erase(
I->second);
322 JITDylibToHeaderAddr.erase(
I);
334 RegisteredInitSymbols[&JD].add(InitSym,
338 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
356 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
357 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
358 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
359 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
366 static const std::pair<const char *, const char *>
367 StandardRuntimeUtilityAliases[] = {
368 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
369 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
370 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
371 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
372 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
373 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
376 StandardRuntimeUtilityAliases);
379bool COFFPlatform::supportedTarget(
const Triple &TT) {
380 switch (TT.getArch()) {
388COFFPlatform::COFFPlatform(
390 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
391 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
392 std::unique_ptr<object::Archive> OrcRuntimeArchive,
393 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
394 const char *VCRuntimePath,
Error &Err)
395 : ES(ObjLinkingLayer.getExecutionSession()),
396 ObjLinkingLayer(ObjLinkingLayer),
397 LoadDynLibrary(
std::
move(LoadDynLibrary)),
398 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
399 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
400 StaticVCRuntime(StaticVCRuntime),
401 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
404 Bootstrapping.store(
true);
405 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
411 Err = VCRT.takeError();
414 VCRuntimeBootstrap = std::move(*VCRT);
416 for (
auto &
Lib : OrcRuntimeGenerator->getImportedDynamicLibraries())
417 DylibsToPreload.insert(
Lib);
420 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
421 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
423 Err = ImportedLibs.takeError();
427 for (
auto &
Lib : *ImportedLibs)
428 DylibsToPreload.insert(
Lib);
430 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
439 for (
auto&
Lib : DylibsToPreload)
440 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
446 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
452 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
460 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
465 Bootstrapping.store(
false);
466 JDBootstrapStates.clear();
470COFFPlatform::buildJDDepMap(
JITDylib &JD) {
472 JITDylibDepMap JDDepMap;
475 while (!Worklist.empty()) {
476 auto CurJD = Worklist.
back();
479 auto &
DM = JDDepMap[CurJD];
481 DM.reserve(
O.size());
483 if (KV.first == CurJD)
487 std::lock_guard<std::mutex> Lock(PlatformMutex);
488 if (!JITDylibToHeaderAddr.count(KV.first)) {
490 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
492 << CurJD->getName() <<
"\n";
497 DM.push_back(KV.first);
499 if (!JDDepMap.count(KV.first)) {
500 Worklist.push_back(KV.first);
501 JDDepMap[KV.first] = {};
506 return std::move(JDDepMap);
510void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
512 JITDylibDepMap &JDDepMap) {
517 while (!Worklist.empty()) {
518 auto CurJD = Worklist.back();
521 auto RISItr = RegisteredInitSymbols.find(CurJD);
522 if (RISItr != RegisteredInitSymbols.end()) {
523 NewInitSymbols[CurJD] = std::move(RISItr->second);
524 RegisteredInitSymbols.erase(RISItr);
527 for (
auto *DepJD : JDDepMap[CurJD])
528 if (Visited.insert(DepJD).second)
529 Worklist.push_back(DepJD);
535 if (NewInitSymbols.
empty()) {
537 COFFJITDylibDepInfoMap DIM;
538 DIM.reserve(JDDepMap.size());
539 for (
auto &KV : JDDepMap) {
540 std::lock_guard<std::mutex> Lock(PlatformMutex);
541 COFFJITDylibDepInfo DepInfo;
542 DepInfo.reserve(KV.second.size());
543 for (
auto &Dep : KV.second) {
544 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
546 auto H = JITDylibToHeaderAddr[KV.first];
547 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
554 lookupInitSymbolsAsync(
555 [
this, SendResult = std::move(SendResult), &JD,
556 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
558 SendResult(std::move(Err));
560 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
562 ES, std::move(NewInitSymbols));
565void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
569 std::lock_guard<std::mutex> Lock(PlatformMutex);
570 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
571 if (
I != HeaderAddrToJITDylib.end())
576 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
578 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
580 dbgs() <<
"No JITDylib for header address.\n";
584 SendResult(make_error<StringError>(
"No JITDylib with header addr " +
585 formatv(
"{0:x}", JDHeaderAddr),
590 auto JDDepMap = buildJDDepMap(*JD);
592 SendResult(JDDepMap.takeError());
596 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
599void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
601 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
606 std::lock_guard<std::mutex> Lock(PlatformMutex);
607 auto I = HeaderAddrToJITDylib.find(Handle);
608 if (
I != HeaderAddrToJITDylib.end())
613 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
614 SendResult(make_error<StringError>(
"No JITDylib associated with handle " +
621 class RtLookupNotifyComplete {
623 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
624 : SendResult(
std::
move(SendResult)) {}
627 assert(
Result->size() == 1 &&
"Unexpected result map count");
628 SendResult(
Result->begin()->second.getAddress());
630 SendResult(
Result.takeError());
635 SendSymbolAddressFn SendResult;
644Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
647 using LookupSymbolSPSSig =
649 WFs[ES.
intern(
"__orc_rt_coff_symbol_lookup_tag")] =
651 &COFFPlatform::rt_lookupSymbol);
652 using PushInitializersSPSSig =
654 WFs[ES.
intern(
"__orc_rt_coff_push_initializers_tag")] =
656 this, &COFFPlatform::rt_pushInitializers);
661Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
664 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
667 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
671 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
676Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
679 for (
auto &Initializer : BState.Initializers)
680 if (Initializer.first >= Start && Initializer.first <=
End &&
681 Initializer.second) {
685 return Res.takeError();
690Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
696 {ES.
intern(
"__orc_rt_coff_platform_bootstrap"),
697 &orc_rt_coff_platform_bootstrap},
698 {ES.
intern(
"__orc_rt_coff_platform_shutdown"),
699 &orc_rt_coff_platform_shutdown},
700 {ES.
intern(
"__orc_rt_coff_register_jitdylib"),
701 &orc_rt_coff_register_jitdylib},
702 {ES.
intern(
"__orc_rt_coff_deregister_jitdylib"),
703 &orc_rt_coff_deregister_jitdylib},
704 {ES.
intern(
"__orc_rt_coff_register_object_sections"),
705 &orc_rt_coff_register_object_sections},
706 {ES.
intern(
"__orc_rt_coff_deregister_object_sections"),
707 &orc_rt_coff_deregister_object_sections},
712 if (
auto Err = ES.
callSPSWrapper<
void()>(orc_rt_coff_platform_bootstrap))
717 for (
auto KV : JDBootstrapStates) {
718 auto &JDBState = KV.second;
720 orc_rt_coff_register_jitdylib, JDBState.JDName,
721 JDBState.HeaderAddr))
724 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
727 orc_rt_coff_register_object_sections, JDBState.HeaderAddr,
728 ObjSectionMap,
false))
733 for (
auto KV : JDBootstrapStates) {
734 auto &JDBState = KV.second;
735 if (
auto Err = runBootstrapInitializers(JDBState))
747 {{ES.
intern(SymbolName), &jit_function}});
748 if (!AfterCLookupErr) {
751 return Res.takeError();
755 return AfterCLookupErr;
760void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
764 bool IsBootstrapping =
CP.Bootstrapping.load();
767 if (InitSymbol ==
CP.COFFHeaderStartSymbol) {
768 Config.PostAllocationPasses.push_back(
770 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
775 return preserveInitializerSections(
G, MR);
779 if (!IsBootstrapping)
780 Config.PostFixupPasses.push_back(
782 return registerObjectPlatformSections(
G, JD);
785 Config.PostFixupPasses.push_back(
787 return registerObjectPlatformSectionsInBootstrap(
G, JD);
791Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
793 bool IsBootstraping) {
795 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
797 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
800 std::lock_guard<std::mutex> Lock(
CP.PlatformMutex);
801 auto HeaderAddr = (*I)->getAddress();
802 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
803 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
804 if (!IsBootstraping) {
805 G.allocActions().push_back(
808 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
810 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
812 G.allocActions().push_back(
815 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
816 JDBootstrapState BState;
819 BState.HeaderAddr = HeaderAddr;
820 CP.JDBootstrapStates.emplace(&JD, BState);
826Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
828 COFFObjectSectionsMap ObjSecs;
829 auto HeaderAddr =
CP.JITDylibToHeaderAddr[&JD];
830 assert(HeaderAddr &&
"Must be registered jitdylib");
831 for (
auto &S :
G.sections()) {
834 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
837 G.allocActions().push_back(
838 {
cantFail(WrapperFunctionCall::Create<SPSCOFFRegisterObjectSectionsArgs>(
839 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
841 WrapperFunctionCall::Create<SPSCOFFDeregisterObjectSectionsArgs>(
842 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
848Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
855 for (
auto &InitSection :
G.sections()) {
864 auto &
B = **InitSection.blocks().begin();
865 InitSym = &
G.addDefinedSymbol(
871 for (
auto *
B : InitSection.blocks()) {
875 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
884Error COFFPlatform::COFFPlatformPlugin::
887 std::lock_guard<std::mutex> Lock(
CP.PlatformMutex);
888 auto HeaderAddr =
CP.JITDylibToHeaderAddr[&JD];
889 COFFObjectSectionsMap ObjSecs;
890 for (
auto &S :
G.sections()) {
893 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
896 G.allocActions().push_back(
899 WrapperFunctionCall::Create<SPSCOFFDeregisterObjectSectionsArgs>(
900 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
903 auto &BState =
CP.JDBootstrapStates[&JD];
904 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
907 for (
auto &S :
G.sections())
909 for (
auto *
B : S.blocks()) {
910 if (
B->edges_empty())
912 for (
auto &E :
B->edges())
913 BState.Initializers.push_back(std::make_pair(
914 S.getName().str(), E.getTarget().getAddress() + E.getAddend()));
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
#define offsetof(TYPE, MEMBER)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - 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.
Implements a dense probed hash-table based set.
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.
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,...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
const std::string & str() const
An Addressable with content and edges.
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.
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
Represents an object file section.
Block & getBlock()
Return the Block for this Symbol (Symbol must be defined).
static Expected< std::unique_ptr< Archive > > create(MemoryBufferRef Source)
static 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.
ExecutorProcessControl & getExecutorProcessControl()
Get the ExecutorProcessControl object associated with this ExecutionSession.
const Triple & getTargetTriple() const
Return the triple for the executor.
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
static JITDispatchHandlerFunction wrapAsyncWithSPS(HandlerT &&H)
Wrap a handler that takes concrete argument types (and a sender for a concrete return type) to produc...
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
Error registerJITDispatchHandlers(JITDylib &JD, JITDispatchHandlerAssociationMap WFs)
For each tag symbol name, associate the corresponding AsyncHandlerWrapperFunction with the address of...
decltype(auto) runSessionLocked(Func &&F)
Run the given lambda with the session mutex locked.
Represents an address in the executor process.
virtual Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr)=0
Run function with a int (*)(void) signature.
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.
void addToLinkOrder(const JITDylibSearchOrder &NewLinks)
Append the given JITDylibSearchOrder to the link order for this JITDylib (discarding any elements alr...
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
ExecutionSession & getExecutionSession()
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.
virtual void materialize(std::unique_ptr< MaterializationResponsibility > R)=0
Implementations of this method should materialize all symbols in the materialzation unit,...
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
An ObjectLayer implementation built on JITLink.
virtual Error add(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > O, MaterializationUnit::Interface I)
Adds a MaterializationUnit for the object file in the given memory buffer to the JITDylib for the giv...
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 set of symbols to look up, each associated with a SymbolLookupFlags value.
Pointer to a pooled string representing a symbol name.
Used to notify clients when symbols can not be found during a lookup.
A utility class for serializing to a blob from a variadic list.
SPS tag type for expecteds, which are either a T or a string representing an error.
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[]
constexpr uint64_t PointerSize
aarch64 pointer size.
@ Pointer64
A plain 64-bit pointer value relocation.
const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
constexpr llvm::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
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.
std::unique_ptr< ReExportsMaterializationUnit > symbolAliases(SymbolAliasMap Aliases)
Create a ReExportsMaterializationUnit with the given aliases.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
@ MatchExportedSymbolsOnly
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)
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)
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
bool isCOFFInitializerSection(StringRef Name)
@ Ready
Emitted to memory, but waiting on transitive dependencies.
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.
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)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...