22#define DEBUG_TYPE "orc"
56 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
57 auto G = std::make_unique<jitlink::LinkGraph>(
58 "<COFFHeaderMU>",
CP.getExecutionSession().getSymbolStringPool(),
61 auto &HeaderSection =
G->createSection(
"__header", MemProt::Read);
65 auto &ImageBaseSymbol =
G->addDefinedSymbol(
66 HeaderBlock, 0, *
R->getInitializerSymbol(), HeaderBlock.getSize(),
67 jitlink::Linkage::Strong, jitlink::Scope::Default,
false,
true);
69 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
71 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
91 struct HeaderBlockContent {
93 COFFHeaderMaterializationUnit::NTHeader NTHeader;
98 HeaderBlockContent Hdr = {};
101 Hdr.DOSHeader.Magic[0] =
'M';
102 Hdr.DOSHeader.Magic[1] =
'Z';
103 Hdr.DOSHeader.AddressOfNewExeHeader =
104 offsetof(HeaderBlockContent, NTHeader);
106 Hdr.NTHeader.PEMagic = PEMagic;
109 switch (
G.getTargetTriple().getArch()) {
117 auto HeaderContent =
G.allocateContent(
118 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
120 return G.createContentBlock(HeaderSection, HeaderContent,
ExecutorAddr(), 8,
126 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
127 offsetof(NTHeader, OptionalHeader) +
153 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
155 const char *VCRuntimePath,
156 std::optional<SymbolAliasMap> RuntimeAliases) {
162 return make_error<StringError>(
"Unsupported COFFPlatform triple: " +
168 auto GeneratorArchive =
170 if (!GeneratorArchive)
171 return GeneratorArchive.takeError();
174 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive));
175 if (!OrcRuntimeArchiveGenerator)
176 return OrcRuntimeArchiveGenerator.takeError();
190 return std::move(Err);
195 if (
auto Err = HostFuncJD.define(
197 {EPC.getJITDispatchInfo().JITDispatchFunction,
199 {ES.
intern(
"__orc_rt_jit_dispatch_ctx"),
200 {EPC.getJITDispatchInfo().JITDispatchContext,
202 return std::move(Err);
209 ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
210 std::move(OrcRuntimeArchiveBuffer), std::move(RuntimeArchive),
211 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath, Err));
213 return std::move(Err);
219 const char *OrcRuntimePath,
221 const char *VCRuntimePath,
222 std::optional<SymbolAliasMap> RuntimeAliases) {
228 return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
229 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
230 std::move(RuntimeAliases));
234 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
236 return PerJDObj.takeError();
239 return make_error<StringError>(
"Could not find per jd object file",
242 auto Buffer = (*PerJDObj)->getAsBinary();
244 return Buffer.takeError();
246 return (*Buffer)->getMemoryBufferRef();
250 ArrayRef<std::pair<const char *, const char *>> AL) {
251 for (
auto &KV : AL) {
252 auto AliasName = ES.
intern(KV.first);
253 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
254 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
260 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
261 *
this, COFFHeaderStartSymbol)))
264 if (
auto Err = ES.
lookup({&JD}, COFFHeaderStartSymbol).takeError())
273 auto PerJDObj = getPerJDObjectFile();
275 return PerJDObj.takeError();
279 return I.takeError();
281 if (
auto Err = ObjLinkingLayer.
add(
285 if (!Bootstrapping) {
286 auto ImportedLibs = StaticVCRuntime
287 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
288 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
290 return ImportedLibs.takeError();
291 for (
auto &
Lib : *ImportedLibs)
292 if (
auto Err = LoadDynLibrary(JD,
Lib))
295 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
304 std::lock_guard<std::mutex> Lock(PlatformMutex);
305 auto I = JITDylibToHeaderAddr.find(&JD);
306 if (
I != JITDylibToHeaderAddr.end()) {
307 assert(HeaderAddrToJITDylib.count(
I->second) &&
308 "HeaderAddrToJITDylib missing entry");
309 HeaderAddrToJITDylib.erase(
I->second);
310 JITDylibToHeaderAddr.erase(
I);
322 RegisteredInitSymbols[&JD].add(InitSym,
326 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
344 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
345 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
346 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
347 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
354 static const std::pair<const char *, const char *>
355 StandardRuntimeUtilityAliases[] = {
356 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
357 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
358 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
359 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
360 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
361 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
364 StandardRuntimeUtilityAliases);
367bool COFFPlatform::supportedTarget(
const Triple &TT) {
368 switch (TT.getArch()) {
376COFFPlatform::COFFPlatform(
378 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
379 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
380 std::unique_ptr<object::Archive> OrcRuntimeArchive,
381 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
382 const char *VCRuntimePath,
Error &Err)
383 : ES(ObjLinkingLayer.getExecutionSession()),
384 ObjLinkingLayer(ObjLinkingLayer),
385 LoadDynLibrary(
std::
move(LoadDynLibrary)),
386 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
387 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
388 StaticVCRuntime(StaticVCRuntime),
389 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
392 Bootstrapping.store(
true);
393 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
399 Err = VCRT.takeError();
402 VCRuntimeBootstrap = std::move(*VCRT);
404 for (
auto &
Lib : OrcRuntimeGenerator->getImportedDynamicLibraries())
405 DylibsToPreload.insert(
Lib);
408 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
409 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
411 Err = ImportedLibs.takeError();
415 for (
auto &
Lib : *ImportedLibs)
416 DylibsToPreload.insert(
Lib);
418 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
427 for (
auto&
Lib : DylibsToPreload)
428 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
434 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
440 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
448 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
453 Bootstrapping.store(
false);
454 JDBootstrapStates.clear();
458COFFPlatform::buildJDDepMap(
JITDylib &JD) {
460 JITDylibDepMap JDDepMap;
463 while (!Worklist.empty()) {
464 auto CurJD = Worklist.
back();
467 auto &
DM = JDDepMap[CurJD];
469 DM.reserve(
O.size());
471 if (KV.first == CurJD)
475 std::lock_guard<std::mutex> Lock(PlatformMutex);
476 if (!JITDylibToHeaderAddr.count(KV.first)) {
478 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
480 << CurJD->getName() <<
"\n";
485 DM.push_back(KV.first);
487 if (!JDDepMap.count(KV.first)) {
488 Worklist.push_back(KV.first);
489 JDDepMap[KV.first] = {};
494 return std::move(JDDepMap);
498void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
500 JITDylibDepMap &JDDepMap) {
505 while (!Worklist.empty()) {
506 auto CurJD = Worklist.back();
509 auto RISItr = RegisteredInitSymbols.find(CurJD);
510 if (RISItr != RegisteredInitSymbols.end()) {
511 NewInitSymbols[CurJD] = std::move(RISItr->second);
512 RegisteredInitSymbols.erase(RISItr);
515 for (
auto *DepJD : JDDepMap[CurJD])
516 if (Visited.insert(DepJD).second)
517 Worklist.push_back(DepJD);
523 if (NewInitSymbols.
empty()) {
525 COFFJITDylibDepInfoMap DIM;
526 DIM.reserve(JDDepMap.size());
527 for (
auto &KV : JDDepMap) {
528 std::lock_guard<std::mutex> Lock(PlatformMutex);
529 COFFJITDylibDepInfo DepInfo;
530 DepInfo.reserve(KV.second.size());
531 for (
auto &Dep : KV.second) {
532 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
534 auto H = JITDylibToHeaderAddr[KV.first];
535 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
542 lookupInitSymbolsAsync(
543 [
this, SendResult = std::move(SendResult), &JD,
544 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
546 SendResult(std::move(Err));
548 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
550 ES, std::move(NewInitSymbols));
553void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
557 std::lock_guard<std::mutex> Lock(PlatformMutex);
558 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
559 if (
I != HeaderAddrToJITDylib.end())
564 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
566 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
568 dbgs() <<
"No JITDylib for header address.\n";
572 SendResult(make_error<StringError>(
"No JITDylib with header addr " +
573 formatv(
"{0:x}", JDHeaderAddr),
578 auto JDDepMap = buildJDDepMap(*JD);
580 SendResult(JDDepMap.takeError());
584 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
587void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
589 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
594 std::lock_guard<std::mutex> Lock(PlatformMutex);
595 auto I = HeaderAddrToJITDylib.find(Handle);
596 if (
I != HeaderAddrToJITDylib.end())
601 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
602 SendResult(make_error<StringError>(
"No JITDylib associated with handle " +
609 class RtLookupNotifyComplete {
611 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
612 : SendResult(
std::
move(SendResult)) {}
615 assert(
Result->size() == 1 &&
"Unexpected result map count");
616 SendResult(
Result->begin()->second.getAddress());
618 SendResult(
Result.takeError());
623 SendSymbolAddressFn SendResult;
632Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
635 using LookupSymbolSPSSig =
637 WFs[ES.
intern(
"__orc_rt_coff_symbol_lookup_tag")] =
639 &COFFPlatform::rt_lookupSymbol);
640 using PushInitializersSPSSig =
642 WFs[ES.
intern(
"__orc_rt_coff_push_initializers_tag")] =
644 this, &COFFPlatform::rt_pushInitializers);
649Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
652 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
655 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
659 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
664Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
667 for (
auto &Initializer : BState.Initializers)
668 if (Initializer.first >= Start && Initializer.first <=
End &&
669 Initializer.second) {
673 return Res.takeError();
678Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
684 {ES.
intern(
"__orc_rt_coff_platform_bootstrap"),
685 &orc_rt_coff_platform_bootstrap},
686 {ES.
intern(
"__orc_rt_coff_platform_shutdown"),
687 &orc_rt_coff_platform_shutdown},
688 {ES.
intern(
"__orc_rt_coff_register_jitdylib"),
689 &orc_rt_coff_register_jitdylib},
690 {ES.
intern(
"__orc_rt_coff_deregister_jitdylib"),
691 &orc_rt_coff_deregister_jitdylib},
692 {ES.
intern(
"__orc_rt_coff_register_object_sections"),
693 &orc_rt_coff_register_object_sections},
694 {ES.
intern(
"__orc_rt_coff_deregister_object_sections"),
695 &orc_rt_coff_deregister_object_sections},
700 if (
auto Err = ES.
callSPSWrapper<
void()>(orc_rt_coff_platform_bootstrap))
705 for (
auto KV : JDBootstrapStates) {
706 auto &JDBState = KV.second;
708 orc_rt_coff_register_jitdylib, JDBState.JDName,
709 JDBState.HeaderAddr))
712 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
715 orc_rt_coff_register_object_sections, JDBState.HeaderAddr,
716 ObjSectionMap,
false))
721 for (
auto KV : JDBootstrapStates) {
722 auto &JDBState = KV.second;
723 if (
auto Err = runBootstrapInitializers(JDBState))
735 {{ES.
intern(SymbolName), &jit_function}});
736 if (!AfterCLookupErr) {
739 return Res.takeError();
743 return AfterCLookupErr;
748void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
752 bool IsBootstrapping =
CP.Bootstrapping.load();
755 if (InitSymbol ==
CP.COFFHeaderStartSymbol) {
756 Config.PostAllocationPasses.push_back(
758 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
763 return preserveInitializerSections(
G, MR);
767 if (!IsBootstrapping)
768 Config.PostFixupPasses.push_back(
770 return registerObjectPlatformSections(
G, JD);
773 Config.PostFixupPasses.push_back(
775 return registerObjectPlatformSectionsInBootstrap(
G, JD);
779Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
781 bool IsBootstraping) {
783 return *Sym->getName() == *CP.COFFHeaderStartSymbol;
785 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
788 std::lock_guard<std::mutex> Lock(
CP.PlatformMutex);
789 auto HeaderAddr = (*I)->getAddress();
790 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
791 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
792 if (!IsBootstraping) {
793 G.allocActions().push_back(
796 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
798 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
800 G.allocActions().push_back(
803 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
804 JDBootstrapState BState;
807 BState.HeaderAddr = HeaderAddr;
808 CP.JDBootstrapStates.emplace(&JD, BState);
814Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
816 COFFObjectSectionsMap ObjSecs;
817 auto HeaderAddr =
CP.JITDylibToHeaderAddr[&JD];
818 assert(HeaderAddr &&
"Must be registered jitdylib");
819 for (
auto &S :
G.sections()) {
822 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
825 G.allocActions().push_back(
826 {
cantFail(WrapperFunctionCall::Create<SPSCOFFRegisterObjectSectionsArgs>(
827 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
829 WrapperFunctionCall::Create<SPSCOFFDeregisterObjectSectionsArgs>(
830 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
836Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
843 for (
auto &InitSection :
G.sections()) {
852 auto &
B = **InitSection.blocks().begin();
853 InitSym = &
G.addDefinedSymbol(
859 for (
auto *
B : InitSection.blocks()) {
863 auto &S =
G.addAnonymousSymbol(*
B, 0,
B->getSize(),
false,
true);
872Error COFFPlatform::COFFPlatformPlugin::
875 std::lock_guard<std::mutex> Lock(
CP.PlatformMutex);
876 auto HeaderAddr =
CP.JITDylibToHeaderAddr[&JD];
877 COFFObjectSectionsMap ObjSecs;
878 for (
auto &S :
G.sections()) {
881 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
884 G.allocActions().push_back(
887 WrapperFunctionCall::Create<SPSCOFFDeregisterObjectSectionsArgs>(
888 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
891 auto &BState =
CP.JDBootstrapStates[&JD];
892 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
895 for (
auto &S :
G.sections())
897 for (
auto *
B : S.blocks()) {
898 if (
B->edges_empty())
900 for (
auto &E :
B->edges())
901 BState.Initializers.push_back(std::make_pair(
902 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.
Manages the enabling and disabling of subtarget specific features.
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[]
@ 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.
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...