21#define DEBUG_TYPE "orc"
55 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override {
58 const auto &
TT =
CP.getExecutionSession().getTargetTriple();
60 switch (
TT.getArch()) {
69 auto G = std::make_unique<jitlink::LinkGraph>(
70 "<COFFHeaderMU>", TT, PointerSize, Endianness,
72 auto &HeaderSection =
G->createSection(
"__header", MemProt::Read);
76 auto &ImageBaseSymbol =
G->addDefinedSymbol(
77 HeaderBlock, 0, *
R->getInitializerSymbol(), HeaderBlock.getSize(),
78 jitlink::Linkage::Strong, jitlink::Scope::Default,
false,
true);
80 addImageBaseRelocationEdge(HeaderBlock, ImageBaseSymbol);
82 CP.getObjectLinkingLayer().emit(std::move(R), std::move(
G));
102 struct HeaderBlockContent {
104 COFFHeaderMaterializationUnit::NTHeader NTHeader;
109 HeaderBlockContent Hdr = {};
112 Hdr.DOSHeader.Magic[0] =
'M';
113 Hdr.DOSHeader.Magic[1] =
'Z';
114 Hdr.DOSHeader.AddressOfNewExeHeader =
115 offsetof(HeaderBlockContent, NTHeader);
117 Hdr.NTHeader.PEMagic = PEMagic;
120 switch (
G.getTargetTriple().getArch()) {
128 auto HeaderContent =
G.allocateContent(
129 ArrayRef<char>(
reinterpret_cast<const char *
>(&Hdr),
sizeof(Hdr)));
131 return G.createContentBlock(HeaderSection, HeaderContent,
ExecutorAddr(), 8,
137 auto ImageBaseOffset =
offsetof(HeaderBlockContent, NTHeader) +
138 offsetof(NTHeader, OptionalHeader) +
164 JITDylib &PlatformJD, std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
166 const char *VCRuntimePath, std::optional<SymbolAliasMap> RuntimeAliases) {
170 return make_error<StringError>(
"Unsupported COFFPlatform triple: " +
176 auto GeneratorArchive =
178 if (!GeneratorArchive)
179 return GeneratorArchive.takeError();
182 ObjLinkingLayer,
nullptr, std::move(*GeneratorArchive));
183 if (!OrcRuntimeArchiveGenerator)
184 return OrcRuntimeArchiveGenerator.takeError();
198 return std::move(Err);
203 if (
auto Err = HostFuncJD.define(
205 {EPC.getJITDispatchInfo().JITDispatchFunction,
207 {ES.
intern(
"__orc_rt_jit_dispatch_ctx"),
208 {EPC.getJITDispatchInfo().JITDispatchContext,
210 return std::move(Err);
217 ES, ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
218 std::move(OrcRuntimeArchiveBuffer), std::move(RuntimeArchive),
219 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath, Err));
221 return std::move(Err);
227 JITDylib &PlatformJD,
const char *OrcRuntimePath,
229 const char *VCRuntimePath,
230 std::optional<SymbolAliasMap> RuntimeAliases) {
236 return Create(ES, ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
237 std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
238 std::move(RuntimeAliases));
242 auto PerJDObj = OrcRuntimeArchive->findSym(
"__orc_rt_coff_per_jd_marker");
244 return PerJDObj.takeError();
247 return make_error<StringError>(
"Could not find per jd object file",
250 auto Buffer = (*PerJDObj)->getAsBinary();
252 return Buffer.takeError();
254 return (*Buffer)->getMemoryBufferRef();
258 ArrayRef<std::pair<const char *, const char *>> AL) {
259 for (
auto &KV : AL) {
260 auto AliasName = ES.
intern(KV.first);
261 assert(!Aliases.
count(AliasName) &&
"Duplicate symbol name in alias map");
262 Aliases[std::move(AliasName)] = {ES.
intern(KV.second),
268 if (
auto Err = JD.
define(std::make_unique<COFFHeaderMaterializationUnit>(
269 *
this, COFFHeaderStartSymbol)))
272 if (
auto Err = ES.
lookup({&JD}, COFFHeaderStartSymbol).takeError())
281 auto PerJDObj = getPerJDObjectFile();
283 return PerJDObj.takeError();
287 return I.takeError();
289 if (
auto Err = ObjLinkingLayer.
add(
293 if (!Bootstrapping) {
294 auto ImportedLibs = StaticVCRuntime
295 ? VCRuntimeBootstrap->loadStaticVCRuntime(JD)
296 : VCRuntimeBootstrap->loadDynamicVCRuntime(JD);
298 return ImportedLibs.takeError();
299 for (
auto &
Lib : *ImportedLibs)
300 if (
auto Err = LoadDynLibrary(JD,
Lib))
303 if (
auto Err = VCRuntimeBootstrap->initializeStaticVCRuntime(JD))
312 std::lock_guard<std::mutex> Lock(PlatformMutex);
313 auto I = JITDylibToHeaderAddr.find(&JD);
314 if (
I != JITDylibToHeaderAddr.end()) {
315 assert(HeaderAddrToJITDylib.count(
I->second) &&
316 "HeaderAddrToJITDylib missing entry");
317 HeaderAddrToJITDylib.erase(
I->second);
318 JITDylibToHeaderAddr.erase(
I);
330 RegisteredInitSymbols[&JD].add(InitSym,
334 dbgs() <<
"COFFPlatform: Registered init symbol " << *InitSym <<
" for MU "
352 static const std::pair<const char *, const char *> RequiredCXXAliases[] = {
353 {
"_CxxThrowException",
"__orc_rt_coff_cxx_throw_exception"},
354 {
"_onexit",
"__orc_rt_coff_onexit_per_jd"},
355 {
"atexit",
"__orc_rt_coff_atexit_per_jd"}};
362 static const std::pair<const char *, const char *>
363 StandardRuntimeUtilityAliases[] = {
364 {
"__orc_rt_run_program",
"__orc_rt_coff_run_program"},
365 {
"__orc_rt_jit_dlerror",
"__orc_rt_coff_jit_dlerror"},
366 {
"__orc_rt_jit_dlopen",
"__orc_rt_coff_jit_dlopen"},
367 {
"__orc_rt_jit_dlclose",
"__orc_rt_coff_jit_dlclose"},
368 {
"__orc_rt_jit_dlsym",
"__orc_rt_coff_jit_dlsym"},
369 {
"__orc_rt_log_error",
"__orc_rt_log_error_to_stderr"}};
372 StandardRuntimeUtilityAliases);
375bool COFFPlatform::supportedTarget(
const Triple &TT) {
376 switch (TT.getArch()) {
384COFFPlatform::COFFPlatform(
387 std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
388 std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
389 std::unique_ptr<object::Archive> OrcRuntimeArchive,
390 LoadDynamicLibrary LoadDynLibrary,
bool StaticVCRuntime,
391 const char *VCRuntimePath,
Error &Err)
392 : ES(ES), ObjLinkingLayer(ObjLinkingLayer),
393 LoadDynLibrary(
std::
move(LoadDynLibrary)),
394 OrcRuntimeArchiveBuffer(
std::
move(OrcRuntimeArchiveBuffer)),
395 OrcRuntimeArchive(
std::
move(OrcRuntimeArchive)),
396 StaticVCRuntime(StaticVCRuntime),
397 COFFHeaderStartSymbol(ES.intern(
"__ImageBase")) {
400 Bootstrapping.store(
true);
401 ObjLinkingLayer.
addPlugin(std::make_unique<COFFPlatformPlugin>(*
this));
407 Err = VCRT.takeError();
410 VCRuntimeBootstrap = std::move(*VCRT);
412 for (
auto &
Lib : OrcRuntimeGenerator->getImportedDynamicLibraries())
413 DylibsToPreload.insert(
Lib);
416 StaticVCRuntime ? VCRuntimeBootstrap->loadStaticVCRuntime(PlatformJD)
417 : VCRuntimeBootstrap->loadDynamicVCRuntime(PlatformJD);
419 Err = ImportedLibs.takeError();
423 for (
auto &
Lib : *ImportedLibs)
424 DylibsToPreload.insert(
Lib);
426 PlatformJD.
addGenerator(std::move(OrcRuntimeGenerator));
435 for (
auto&
Lib : DylibsToPreload)
436 if (
auto E2 = this->LoadDynLibrary(PlatformJD,
Lib)) {
442 if (
auto E2 = VCRuntimeBootstrap->initializeStaticVCRuntime(PlatformJD)) {
448 if (
auto E2 = associateRuntimeSupportFunctions(PlatformJD)) {
456 if (
auto E2 = bootstrapCOFFRuntime(PlatformJD)) {
461 Bootstrapping.store(
false);
462 JDBootstrapStates.clear();
466COFFPlatform::buildJDDepMap(
JITDylib &JD) {
468 JITDylibDepMap JDDepMap;
471 while (!Worklist.empty()) {
472 auto CurJD = Worklist.
back();
475 auto &
DM = JDDepMap[CurJD];
477 DM.reserve(
O.size());
479 if (KV.first == CurJD)
483 std::lock_guard<std::mutex> Lock(PlatformMutex);
484 if (!JITDylibToHeaderAddr.count(KV.first)) {
486 dbgs() <<
"JITDylib unregistered to COFFPlatform detected in "
488 << CurJD->getName() <<
"\n";
493 DM.push_back(KV.first);
495 if (!JDDepMap.count(KV.first)) {
496 Worklist.push_back(KV.first);
497 JDDepMap[KV.first] = {};
502 return std::move(JDDepMap);
506void COFFPlatform::pushInitializersLoop(PushInitializersSendResultFn SendResult,
508 JITDylibDepMap &JDDepMap) {
513 while (!Worklist.empty()) {
514 auto CurJD = Worklist.back();
517 auto RISItr = RegisteredInitSymbols.find(CurJD);
518 if (RISItr != RegisteredInitSymbols.end()) {
519 NewInitSymbols[CurJD] = std::move(RISItr->second);
520 RegisteredInitSymbols.erase(RISItr);
523 for (
auto *DepJD : JDDepMap[CurJD])
524 if (!Visited.count(DepJD)) {
525 Worklist.push_back(DepJD);
526 Visited.insert(DepJD);
533 if (NewInitSymbols.
empty()) {
535 COFFJITDylibDepInfoMap DIM;
536 DIM.reserve(JDDepMap.size());
537 for (
auto &KV : JDDepMap) {
538 std::lock_guard<std::mutex> Lock(PlatformMutex);
539 COFFJITDylibDepInfo DepInfo;
540 DepInfo.reserve(KV.second.size());
541 for (
auto &Dep : KV.second) {
542 DepInfo.push_back(JITDylibToHeaderAddr[Dep]);
544 auto H = JITDylibToHeaderAddr[KV.first];
545 DIM.push_back(std::make_pair(
H, std::move(DepInfo)));
552 lookupInitSymbolsAsync(
553 [
this, SendResult = std::move(SendResult), &JD,
554 JDDepMap = std::move(JDDepMap)](
Error Err)
mutable {
556 SendResult(std::move(Err));
558 pushInitializersLoop(std::move(SendResult), JD, JDDepMap);
560 ES, std::move(NewInitSymbols));
563void COFFPlatform::rt_pushInitializers(PushInitializersSendResultFn SendResult,
567 std::lock_guard<std::mutex> Lock(PlatformMutex);
568 auto I = HeaderAddrToJITDylib.find(JDHeaderAddr);
569 if (
I != HeaderAddrToJITDylib.end())
574 dbgs() <<
"COFFPlatform::rt_pushInitializers(" << JDHeaderAddr <<
") ";
576 dbgs() <<
"pushing initializers for " << JD->
getName() <<
"\n";
578 dbgs() <<
"No JITDylib for header address.\n";
582 SendResult(make_error<StringError>(
"No JITDylib with header addr " +
583 formatv(
"{0:x}", JDHeaderAddr),
588 auto JDDepMap = buildJDDepMap(*JD);
590 SendResult(JDDepMap.takeError());
594 pushInitializersLoop(std::move(SendResult), JD, *JDDepMap);
597void COFFPlatform::rt_lookupSymbol(SendSymbolAddressFn SendResult,
599 LLVM_DEBUG(
dbgs() <<
"COFFPlatform::rt_lookupSymbol(\"" << Handle <<
"\")\n");
604 std::lock_guard<std::mutex> Lock(PlatformMutex);
605 auto I = HeaderAddrToJITDylib.find(Handle);
606 if (
I != HeaderAddrToJITDylib.end())
611 LLVM_DEBUG(
dbgs() <<
" No JITDylib for handle " << Handle <<
"\n");
612 SendResult(make_error<StringError>(
"No JITDylib associated with handle " +
619 class RtLookupNotifyComplete {
621 RtLookupNotifyComplete(SendSymbolAddressFn &&SendResult)
622 : SendResult(
std::
move(SendResult)) {}
625 assert(
Result->size() == 1 &&
"Unexpected result map count");
626 SendResult(
Result->begin()->second.getAddress());
628 SendResult(
Result.takeError());
633 SendSymbolAddressFn SendResult;
642Error COFFPlatform::associateRuntimeSupportFunctions(
JITDylib &PlatformJD) {
645 using LookupSymbolSPSSig =
647 WFs[ES.
intern(
"__orc_rt_coff_symbol_lookup_tag")] =
649 &COFFPlatform::rt_lookupSymbol);
650 using PushInitializersSPSSig =
652 WFs[ES.
intern(
"__orc_rt_coff_push_initializers_tag")] =
654 this, &COFFPlatform::rt_pushInitializers);
659Error COFFPlatform::runBootstrapInitializers(JDBootstrapState &BState) {
662 runBootstrapSubsectionInitializers(BState,
".CRT$XIA",
".CRT$XIZ"))
665 if (
auto Err = runSymbolIfExists(*BState.JD,
"__run_after_c_init"))
669 runBootstrapSubsectionInitializers(BState,
".CRT$XCA",
".CRT$XCZ"))
674Error COFFPlatform::runBootstrapSubsectionInitializers(JDBootstrapState &BState,
677 for (
auto &Initializer : BState.Initializers)
678 if (Initializer.first >= Start && Initializer.first <=
End &&
679 Initializer.second) {
683 return Res.takeError();
688Error COFFPlatform::bootstrapCOFFRuntime(
JITDylib &PlatformJD) {
694 {ES.
intern(
"__orc_rt_coff_platform_bootstrap"),
695 &orc_rt_coff_platform_bootstrap},
696 {ES.
intern(
"__orc_rt_coff_platform_shutdown"),
697 &orc_rt_coff_platform_shutdown},
698 {ES.
intern(
"__orc_rt_coff_register_jitdylib"),
699 &orc_rt_coff_register_jitdylib},
700 {ES.
intern(
"__orc_rt_coff_deregister_jitdylib"),
701 &orc_rt_coff_deregister_jitdylib},
702 {ES.
intern(
"__orc_rt_coff_register_object_sections"),
703 &orc_rt_coff_register_object_sections},
704 {ES.
intern(
"__orc_rt_coff_deregister_object_sections"),
705 &orc_rt_coff_deregister_object_sections},
710 if (
auto Err = ES.
callSPSWrapper<
void()>(orc_rt_coff_platform_bootstrap))
715 for (
auto KV : JDBootstrapStates) {
716 auto &JDBState = KV.second;
718 orc_rt_coff_register_jitdylib, JDBState.JDName,
719 JDBState.HeaderAddr))
722 for (
auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
725 orc_rt_coff_register_object_sections, JDBState.HeaderAddr,
726 ObjSectionMap,
false))
731 for (
auto KV : JDBootstrapStates) {
732 auto &JDBState = KV.second;
733 if (
auto Err = runBootstrapInitializers(JDBState))
745 {{ES.
intern(SymbolName), &jit_function}});
746 if (!AfterCLookupErr) {
749 return Res.takeError();
753 return AfterCLookupErr;
758void COFFPlatform::COFFPlatformPlugin::modifyPassConfig(
762 bool IsBootstrapping =
CP.Bootstrapping.load();
765 if (InitSymbol ==
CP.COFFHeaderStartSymbol) {
766 Config.PostAllocationPasses.push_back(
768 return associateJITDylibHeaderSymbol(
G, MR, IsBootstrapping);
773 return preserveInitializerSections(
G, MR);
777 if (!IsBootstrapping)
778 Config.PostFixupPasses.push_back(
780 return registerObjectPlatformSections(
G, JD);
783 Config.PostFixupPasses.push_back(
785 return registerObjectPlatformSectionsInBootstrap(
G, JD);
790COFFPlatform::COFFPlatformPlugin::getSyntheticSymbolDependencies(
792 std::lock_guard<std::mutex> Lock(PluginMutex);
793 auto I = InitSymbolDeps.find(&MR);
794 if (
I != InitSymbolDeps.end()) {
795 SyntheticSymbolDependenciesMap
Result;
797 InitSymbolDeps.erase(&MR);
800 return SyntheticSymbolDependenciesMap();
803Error COFFPlatform::COFFPlatformPlugin::associateJITDylibHeaderSymbol(
805 bool IsBootstraping) {
807 return Sym->getName() == *CP.COFFHeaderStartSymbol;
809 assert(
I !=
G.defined_symbols().end() &&
"Missing COFF header start symbol");
812 std::lock_guard<std::mutex> Lock(
CP.PlatformMutex);
813 auto HeaderAddr = (*I)->getAddress();
814 CP.JITDylibToHeaderAddr[&JD] = HeaderAddr;
815 CP.HeaderAddrToJITDylib[HeaderAddr] = &JD;
816 if (!IsBootstraping) {
817 G.allocActions().push_back(
820 CP.orc_rt_coff_register_jitdylib, JD.
getName(), HeaderAddr)),
822 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
824 G.allocActions().push_back(
827 CP.orc_rt_coff_deregister_jitdylib, HeaderAddr))});
828 JDBootstrapState BState;
831 BState.HeaderAddr = HeaderAddr;
832 CP.JDBootstrapStates.emplace(&JD, BState);
838Error COFFPlatform::COFFPlatformPlugin::registerObjectPlatformSections(
840 COFFObjectSectionsMap ObjSecs;
841 auto HeaderAddr =
CP.JITDylibToHeaderAddr[&JD];
842 assert(HeaderAddr &&
"Must be registered jitdylib");
843 for (
auto &S :
G.sections()) {
846 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
849 G.allocActions().push_back(
850 {
cantFail(WrapperFunctionCall::Create<SPSCOFFRegisterObjectSectionsArgs>(
851 CP.orc_rt_coff_register_object_sections, HeaderAddr, ObjSecs,
true)),
853 WrapperFunctionCall::Create<SPSCOFFDeregisterObjectSectionsArgs>(
854 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
860Error COFFPlatform::COFFPlatformPlugin::preserveInitializerSections(
862 JITLinkSymbolSet InitSectionSymbols;
863 for (
auto &Sec :
G.sections())
865 for (
auto *
B : Sec.blocks())
866 if (!
B->edges_empty())
867 InitSectionSymbols.insert(
868 &
G.addAnonymousSymbol(*
B, 0, 0,
false,
true));
870 std::lock_guard<std::mutex> Lock(PluginMutex);
871 InitSymbolDeps[&MR] = InitSectionSymbols;
875Error COFFPlatform::COFFPlatformPlugin::
878 std::lock_guard<std::mutex> Lock(
CP.PlatformMutex);
879 auto HeaderAddr =
CP.JITDylibToHeaderAddr[&JD];
880 COFFObjectSectionsMap ObjSecs;
881 for (
auto &S :
G.sections()) {
884 ObjSecs.push_back(std::make_pair(S.getName().str(),
Range.getRange()));
887 G.allocActions().push_back(
890 WrapperFunctionCall::Create<SPSCOFFDeregisterObjectSectionsArgs>(
891 CP.orc_rt_coff_deregister_object_sections, HeaderAddr,
894 auto &BState =
CP.JDBootstrapStates[&JD];
895 BState.ObjectSectionsMaps.push_back(std::move(ObjSecs));
898 for (
auto &S :
G.sections())
900 for (
auto *
B : S.blocks()) {
901 if (
B->edges_empty())
903 for (
auto &E :
B->edges())
904 BState.Initializers.push_back(std::make_pair(
905 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.
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.
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.
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.
ObjectLinkingLayer & addPlugin(std::shared_ptr< Plugin > P)
Add a plugin.
Error add(ResourceTrackerSP, std::unique_ptr< jitlink::LinkGraph > G)
Add a LinkGraph to the JITDylib targeted by the given tracker.
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, 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(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< 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...