30#define DEBUG_TYPE "dyld"
34enum RuntimeDyldErrorCode {
35 GenericRTDyldError = 1
41class RuntimeDyldErrorCategory :
public std::error_category {
43 const char *
name()
const noexcept override {
return "runtimedyld"; }
45 std::string message(
int Condition)
const override {
46 switch (
static_cast<RuntimeDyldErrorCode
>(Condition)) {
47 case GenericRTDyldError:
return "Generic RuntimeDyld error";
62 static RuntimeDyldErrorCategory RTDyldErrorCategory;
63 return std::error_code(GenericRTDyldError, RTDyldErrorCategory);
77 MemMgr.deregisterEHFrames();
82 dbgs() <<
"----- Contents of section " << S.
getName() <<
" " << State
86 dbgs() <<
"\n <section not emitted>\n";
90 const unsigned ColsPerRow = 16;
95 unsigned StartPadding = LoadAddr & (ColsPerRow - 1);
96 unsigned BytesRemaining = S.
getSize();
100 LoadAddr & ~(
uint64_t)(ColsPerRow - 1)) <<
":";
101 while (StartPadding--)
105 while (BytesRemaining > 0) {
106 if ((LoadAddr & (ColsPerRow - 1)) == 0)
107 dbgs() <<
"\n" <<
format(
"0x%016" PRIx64, LoadAddr) <<
":";
122 std::lock_guard<sys::Mutex> locked(
lock);
151 unsigned Idx = Rel.first;
153 LLVM_DEBUG(
dbgs() <<
"Resolving relocations Section #" << Idx <<
"\t"
154 <<
format(
"%p", (uintptr_t)Addr) <<
"\n");
162 std::lock_guard<sys::Mutex> locked(
lock);
163 for (
unsigned i = 0, e =
Sections.size(); i != e; ++i) {
164 if (
Sections[i].getAddress() == LocalAddress) {
183 std::lock_guard<sys::Mutex> locked(
lock);
192 if (
MemMgr.needsToReserveAllocationSpace()) {
194 Align CodeAlign, RODataAlign, RWDataAlign;
196 RODataAlign, RWDataSize, RWDataAlign))
197 return std::move(Err);
198 MemMgr.reserveAllocationSpace(
CodeSize, CodeAlign, RODataSize, RODataAlign,
199 RWDataSize, RWDataAlign);
216 for (
auto &Sym : Obj.
symbols()) {
224 if (
auto NameOrErr = Sym.getName())
225 Symbols.insert(*NameOrErr);
227 return NameOrErr.takeError();
231 if (
auto ResultOrErr =
Resolver.getResponsibilitySet(Symbols))
232 ResponsibilitySet = std::move(*ResultOrErr);
234 return ResultOrErr.takeError();
252 if (
auto SymTypeOrErr =
I->getType())
253 SymType = *SymTypeOrErr;
255 return SymTypeOrErr.takeError();
259 if (
auto NameOrErr =
I->getName())
262 return NameOrErr.takeError();
267 return JITSymFlags.takeError();
273 if (JITSymFlags->isWeak() || JITSymFlags->isCommon()) {
279 if (!ResponsibilitySet.count(Name))
284 if (JITSymFlags->isWeak())
286 if (JITSymFlags->isCommon()) {
293 CommonSymbolsToAllocate.push_back(*
I);
300 if (
auto AddrOrErr =
I->getAddress())
303 return AddrOrErr.takeError();
307 LLVM_DEBUG(
dbgs() <<
"\tType: " << SymType <<
" (absolute) Name: " << Name
308 <<
" SID: " << SectionID
309 <<
" Offset: " <<
format(
"%p", (uintptr_t)Addr)
310 <<
" flags: " << *FlagsOrErr <<
"\n");
323 if (
auto SIOrErr =
I->getSection())
326 return SIOrErr.takeError();
334 return std::move(Err);
336 bool IsCode =
SI->isText();
338 if (
auto SectionIDOrErr =
340 SectionID = *SectionIDOrErr;
342 return SectionIDOrErr.takeError();
345 <<
" SID: " << SectionID
346 <<
" Offset: " <<
format(
"%p", (uintptr_t)SectOffset)
347 <<
" flags: " << *FlagsOrErr <<
"\n");
360 return std::move(Err);
373 if (RelocatedSection == SE)
382 bool IsCode = RelocatedSection->
isText();
383 unsigned SectionID = 0;
386 SectionID = *SectionIDOrErr;
388 return SectionIDOrErr.takeError();
396 return IOrErr.takeError();
403 for (
auto &KV : Stubs) {
417 StringRef SymbolName = GSTMapEntry.first();
418 auto &GSTEntry = GSTMapEntry.second;
419 if (GSTEntry.getSectionID() == VR.SectionID &&
420 GSTEntry.getOffset() == VR.Offset) {
437 if (LocalSections.find(*
SI) != LocalSections.end())
440 bool IsCode =
SI->isText();
441 if (
auto SectionIDOrErr =
443 LLVM_DEBUG(
dbgs() <<
"\tSectionID: " << (*SectionIDOrErr) <<
"\n");
445 return SectionIDOrErr.takeError();
451 return std::move(Err);
456 return LocalSections;
466 for (
uint64_t SectionSize : SectionSizes)
467 TotalSize +=
alignTo(SectionSize, Alignment);
476 const coff_section *CoffSection = COFFObj->getCOFFSection(Section);
487 return HasContent && !IsDiscardable;
500 return ((COFFObj->getCOFFSection(Section)->Characteristics &
517 return COFFObj->getCOFFSection(Section)->Characteristics &
521 unsigned SectionType =
MachO->getSectionType(Section);
538 Align &RWDataAlign) {
540 std::vector<uint64_t> CodeSectionSizes;
541 std::vector<uint64_t> ROSectionSizes;
542 std::vector<uint64_t> RWSectionSizes;
555 Align Alignment = Section.getAlignment();
556 bool IsCode = Section.isText();
558 bool IsTLS =
isTLS(Section);
568 if (Name ==
".eh_frame")
570 if (StubBufSize != 0)
580 if (Name ==
".eh_frame")
587 CodeAlign = std::max(CodeAlign, Alignment);
588 CodeSectionSizes.push_back(SectionSize);
589 }
else if (IsReadOnly) {
590 RODataAlign = std::max(RODataAlign, Alignment);
591 ROSectionSizes.push_back(SectionSize);
593 RWDataAlign = std::max(RWDataAlign, Alignment);
594 RWSectionSizes.push_back(SectionSize);
603 RWSectionSizes.push_back(GotSize);
623 CommonAlign = Alignment;
624 CommonSize =
alignTo(CommonSize, Alignment) +
Size;
627 if (CommonSize != 0) {
628 RWSectionSizes.push_back(CommonSize);
629 RWDataAlign = std::max(RWDataAlign, CommonAlign);
632 if (!CodeSectionSizes.empty()) {
634 CodeSectionSizes.push_back(64);
661 GotSize += GotEntrySize;
670 if (!
MemMgr.allowStubAllocation()) {
681 unsigned StubBufSize = 0;
690 if (!(RelSecI == Section))
695 StubBufSize += StubSize;
703 Align Alignment = Section.getAlignment();
708 if (StubAlignment > EndAlignment)
709 StubBufSize += StubAlignment.
value() - EndAlignment.
value();
714 unsigned Size)
const {
719 Result = (Result << 8) | *Src--;
722 Result = (Result << 8) | *Src++;
728 unsigned Size)
const {
731 *Dst++ =
Value & 0xFF;
737 *Dst-- =
Value & 0xFF;
752 if (SymbolsToAllocate.empty())
756 unsigned SectionID =
Sections.size();
757 uint8_t *Addr =
MemMgr.allocateDataSection(CommonSize, CommonAlign, SectionID,
758 "<common symbols>",
false);
763 SectionEntry(
"<common symbols>", Addr, CommonSize, CommonSize, 0));
764 memset(Addr, 0, CommonSize);
767 <<
" new addr: " <<
format(
"%p", Addr)
768 <<
" DataSize: " << CommonSize <<
"\n");
771 for (
auto &Sym : SymbolsToAllocate) {
772 uint32_t Alignment = Sym.getAlignment();
775 if (
auto NameOrErr = Sym.getName())
778 return NameOrErr.takeError();
789 return JITSymFlags.takeError();
791 LLVM_DEBUG(
dbgs() <<
"Allocating common symbol " << Name <<
" address "
792 <<
format(
"%p", Addr) <<
"\n");
808 Align Alignment = Section.getAlignment();
810 unsigned PaddingSize = 0;
811 unsigned StubBufSize = 0;
813 bool IsVirtual = Section.isVirtual();
816 bool IsTLS =
isTLS(Section);
829 if (Name ==
".eh_frame")
833 unsigned SectionID =
Sections.size();
836 const char *pData =
nullptr;
840 if (!IsVirtual && !IsZeroInit) {
846 return E.takeError();
853 if (StubBufSize != 0) {
861 Allocate =
DataSize + PaddingSize + StubBufSize;
865 auto TLSSection =
MemMgr.allocateTLSSection(Allocate, Alignment.
value(),
867 Addr = TLSSection.InitializationImage;
868 LoadAddress = TLSSection.Offset;
870 Addr =
MemMgr.allocateCodeSection(Allocate, Alignment.
value(), SectionID,
873 Addr =
MemMgr.allocateDataSection(Allocate, Alignment.
value(), SectionID,
880 if (IsZeroInit || IsVirtual)
886 if (PaddingSize != 0) {
887 memset(Addr +
DataSize, 0, PaddingSize);
897 LLVM_DEBUG(
dbgs() <<
"emitSection SectionID: " << SectionID <<
" Name: "
898 << Name <<
" obj addr: " <<
format(
"%p", pData)
899 <<
" new addr: " <<
format(
"%p", Addr) <<
" DataSize: "
900 <<
DataSize <<
" StubBufSize: " << StubBufSize
901 <<
" Allocate: " << Allocate <<
"\n");
909 dbgs() <<
"emitSection SectionID: " << SectionID <<
" Name: " << Name
910 <<
" obj addr: " <<
format(
"%p",
data.data()) <<
" new addr: 0"
911 <<
" DataSize: " <<
DataSize <<
" StubBufSize: " << StubBufSize
912 <<
" Allocate: " << Allocate <<
"\n");
921 Sections.back().setLoadAddress(LoadAddress);
935 unsigned SectionID = 0;
936 ObjSectionToIDMap::iterator i = LocalSections.find(Section);
937 if (i != LocalSections.end())
938 SectionID = i->second;
940 if (
auto SectionIDOrErr =
emitSection(Obj, Section, IsCode))
941 SectionID = *SectionIDOrErr;
943 return SectionIDOrErr.takeError();
944 LocalSections[Section] = SectionID;
950 unsigned SectionID) {
963 assert(!SymbolName.empty() &&
964 "Empty symbol should not be in GlobalSymbolTable");
974 unsigned AbiVariant) {
1010 const unsigned LuiT9Instr = 0x3c190000, AdduiT9Instr = 0x27390000;
1011 const unsigned NopInstr = 0x0;
1012 unsigned JrT9Instr = 0x03200008;
1015 JrT9Instr = 0x03200009;
1031 const unsigned LuiT9Instr = 0x3c190000, DaddiuT9Instr = 0x67390000,
1032 DsllT9Instr = 0x19CC38;
1033 const unsigned NopInstr = 0x0;
1034 unsigned JrT9Instr = 0x03200008;
1036 JrT9Instr = 0x03200009;
1056 if (AbiVariant == 2) {
1106 dbgs() <<
"Reassigning address for section " << SectionID <<
" ("
1109 <<
" -> " <<
format(
"0x%016" PRIx64, Addr) <<
"\n");
1110 Sections[SectionID].setLoadAddress(Addr);
1118 Sections[RE.SectionID].getAddress() ==
nullptr)
1129 if (Name.size() == 0) {
1139 auto RRI = ExternalSymbolMap.
find(Name);
1140 assert(RRI != ExternalSymbolMap.
end() &&
"No result for symbol");
1141 Addr = RRI->second.getAddress();
1142 Flags = RRI->second.getFlags();
1153 if (!Addr && !
Resolver.allowsZeroSymbols())
1155 "' which could not be resolved!");
1166 LLVM_DEBUG(
dbgs() <<
"Resolving relocations Name: " << Name <<
"\t"
1167 <<
format(
"0x%lx", Addr) <<
"\n");
1189 !ResolvedSymbols.count(Name))
1190 NewSymbols.insert(Name);
1193 if (NewSymbols.empty())
1197 using ExpectedLookupResult =
1203 auto NewSymbolsP = std::make_shared<std::promise<ExpectedLookupResult>>();
1204 auto NewSymbolsF = NewSymbolsP->get_future();
1207 NewSymbolsP->set_value(std::move(Result));
1210 auto NewResolverResults = NewSymbolsF.get();
1212 if (!NewResolverResults)
1213 return NewResolverResults.takeError();
1215 assert(NewResolverResults->size() == NewSymbols.size() &&
1216 "Should have errored on unresolved symbols");
1218 for (
auto &RRKV : *NewResolverResults) {
1219 assert(!ResolvedSymbols.count(RRKV.first) &&
"Redundant resolution?");
1220 ExternalSymbolMap.
insert(RRKV);
1221 ResolvedSymbols.insert(RRKV.first);
1232 std::unique_ptr<RuntimeDyldImpl> This,
1234 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>,
Error)>
1237 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> Info) {
1239 auto SharedThis = std::shared_ptr<RuntimeDyldImpl>(std::move(This));
1240 auto PostResolveContinuation =
1241 [SharedThis, OnEmitted = std::move(OnEmitted), O = std::move(O),
1242 Info = std::move(Info)](
1245 OnEmitted(std::move(O), std::move(Info), Result.takeError());
1251 for (
auto &KV : *Result)
1252 Resolved[KV.first] = KV.second;
1254 SharedThis->applyExternalSymbolRelocations(Resolved);
1255 SharedThis->resolveLocalRelocations();
1256 SharedThis->registerEHFrames();
1258 if (SharedThis->MemMgr.finalizeMemory(&ErrMsg))
1259 OnEmitted(std::move(O), std::move(Info),
1268 for (
auto &RelocKV : SharedThis->ExternalSymbolRelocations) {
1272 assert(!SharedThis->GlobalSymbolTable.count(Name) &&
1273 "Name already processed. RuntimeDyld instances can not be re-used "
1274 "when finalizing with finalizeAsync.");
1275 Symbols.insert(Name);
1278 if (!Symbols.empty()) {
1279 SharedThis->Resolver.lookup(Symbols, std::move(PostResolveContinuation));
1281 PostResolveContinuation(std::map<StringRef, JITEvaluatedSymbol>());
1292 return RTDyld.Sections[
I->second].getLoadAddress();
1305void RuntimeDyld::MemoryManager::anchor() {}
1306void JITSymbolResolver::anchor() {}
1307void LegacyJITSymbolResolver::anchor() {}
1311 : MemMgr(MemMgr), Resolver(Resolver) {
1319 ProcessAllSections =
false;
1324static std::unique_ptr<RuntimeDyldCOFF>
1329 std::unique_ptr<RuntimeDyldCOFF> Dyld =
1331 Dyld->setProcessAllSections(ProcessAllSections);
1332 Dyld->setNotifyStubEmitted(std::move(NotifyStubEmitted));
1336static std::unique_ptr<RuntimeDyldELF>
1340 std::unique_ptr<RuntimeDyldELF> Dyld =
1342 Dyld->setProcessAllSections(ProcessAllSections);
1343 Dyld->setNotifyStubEmitted(std::move(NotifyStubEmitted));
1347static std::unique_ptr<RuntimeDyldMachO>
1351 bool ProcessAllSections,
1353 std::unique_ptr<RuntimeDyldMachO> Dyld =
1355 Dyld->setProcessAllSections(ProcessAllSections);
1356 Dyld->setNotifyStubEmitted(std::move(NotifyStubEmitted));
1360std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
1366 std::move(NotifyStubEmitted));
1370 std::move(NotifyStubEmitted));
1374 std::move(NotifyStubEmitted));
1379 if (!Dyld->isCompatibleFile(Obj))
1382 auto LoadedObjInfo = Dyld->loadObject(Obj);
1383 MemMgr.notifyObjectLoaded(*
this, Obj);
1384 return LoadedObjInfo;
1390 return Dyld->getSymbolLocalAddress(Name);
1394 assert(Dyld &&
"No RuntimeDyld instance attached");
1395 return Dyld->getSymbolSectionID(Name);
1401 return Dyld->getSymbol(Name);
1406 return std::map<StringRef, JITEvaluatedSymbol>();
1407 return Dyld->getSymbolTable();
1413 Dyld->reassignSectionAddress(SectionID, Addr);
1418 Dyld->mapSectionAddress(LocalAddress, TargetAddress);
1426 bool MemoryFinalizationLocked = MemMgr.FinalizationLocked;
1427 MemMgr.FinalizationLocked =
true;
1430 if (!MemoryFinalizationLocked) {
1431 MemMgr.finalizeMemory();
1432 MemMgr.FinalizationLocked =
false;
1437 assert(Dyld &&
"No Dyld instance attached");
1438 return Dyld->getSectionContent(SectionID);
1442 assert(Dyld &&
"No Dyld instance attached");
1443 return Dyld->getSectionLoadAddress(SectionID);
1448 Dyld->registerEHFrames();
1453 Dyld->deregisterEHFrames();
1461 bool ProcessAllSections,
1464 std::map<StringRef, JITEvaluatedSymbol>)>
1467 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>,
Error)>
1473 auto Info = RTDyld.
loadObject(*O.getBinary());
1476 OnEmitted(std::move(O), std::move(Info),
1482 if (
auto Err = OnLoaded(*O.getBinary(), *Info, RTDyld.
getSymbolTable())) {
1483 OnEmitted(std::move(O), std::move(Info), std::move(Err));
1488 std::move(O), std::move(Info));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static StringRef getName(Value *V)
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.
Represents a symbol that has been evaluated to an address already.
Flags for symbols in the JIT.
static LLVM_ABI Expected< JITSymbolFlags > fromObjectSymbol(const object::SymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
Symbol resolution interface.
std::set< StringRef > LookupSet
RelocationEntry - used to represent relocations internally in the dynamic linker.
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
static std::unique_ptr< RuntimeDyldCOFF > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
static std::unique_ptr< RuntimeDyldELF > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
virtual bool relocationNeedsGot(const RelocationRef &R) const
void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress)
virtual void processNewSymbol(const SymbolRef &ObjSymbol, SymbolTableEntry &Entry)
StringMap< RelocationList > ExternalSymbolRelocations
void reassignSectionAddress(unsigned SectionID, uint64_t Addr)
NotifyStubEmittedFunction NotifyStubEmitted
virtual uint64_t modifyAddressBasedOnFlags(uint64_t Addr, JITSymbolFlags Flags) const
Modify the given target address based on the given symbol flags.
virtual Expected< relocation_iterator > processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs)=0
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
std::map< SectionRef, unsigned > ObjSectionToIDMap
virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value)=0
A object file specific relocation resolver.
virtual Align getStubAlignment()=0
void writeInt32BE(uint8_t *Addr, uint32_t Value)
virtual Error finalizeLoad(const ObjectFile &ObjImg, ObjSectionToIDMap &SectionMap)
void applyExternalSymbolRelocations(const StringMap< JITEvaluatedSymbol > ExternalSymbolMap)
void resolveRelocationList(const RelocationList &Relocs, uint64_t Value)
Resolves relocations from Relocs list with address from Value.
SmallVector< RelocationEntry, 64 > RelocationList
std::map< RelocationValueRef, uintptr_t > StubMap
void deregisterEHFrames()
void writeInt16BE(uint8_t *Addr, uint16_t Value)
static const unsigned AbsoluteSymbolSection
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
virtual void registerEHFrames()
bool IsTargetLittleEndian
JITSymbolResolver & Resolver
virtual ~RuntimeDyldImpl()
static void finalizeAsync(std::unique_ptr< RuntimeDyldImpl > This, unique_function< void(object::OwningBinary< object::ObjectFile >, std::unique_ptr< RuntimeDyld::LoadedObjectInfo >, Error)> OnEmitted, object::OwningBinary< object::ObjectFile > O, std::unique_ptr< RuntimeDyld::LoadedObjectInfo > Info)
Error emitCommonSymbols(const ObjectFile &Obj, CommonSymbolList &CommonSymbols, uint64_t CommonSize, uint32_t CommonAlign)
Given the common symbols discovered in the object file, emit a new section for them and update the sy...
Expected< unsigned > emitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode)
Emits section data from the object file to the MemoryManager.
virtual unsigned sizeAfterAddingDLLImportStub(unsigned Size) const
std::unordered_map< unsigned, RelocationList > Relocations
std::vector< SymbolRef > CommonSymbolList
RuntimeDyld::MemoryManager & MemMgr
void resolveLocalRelocations()
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
virtual bool relocationNeedsStub(const RelocationRef &R) const
unsigned computeGOTSize(const ObjectFile &Obj)
virtual void setMipsABI(const ObjectFile &Obj)
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
virtual size_t getGOTEntrySize()
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
virtual bool relocationNeedsDLLImportStub(const RelocationRef &R) const
uint64_t getSectionLoadAddress(unsigned SectionID) const
virtual unsigned getMaxStubSize() const =0
Error computeTotalAllocSize(const ObjectFile &Obj, uint64_t &CodeSize, Align &CodeAlign, uint64_t &RODataSize, Align &RODataAlign, uint64_t &RWDataSize, Align &RWDataAlign)
unsigned computeSectionStubBufSize(const ObjectFile &Obj, const SectionRef &Section)
void resolveRelocations()
RTDyldSymbolTable GlobalSymbolTable
virtual Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &Sym)
Generate JITSymbolFlags from a libObject symbol.
Expected< ObjSectionToIDMap > loadObjectImpl(const object::ObjectFile &Obj)
Error resolveExternalSymbols()
Resolve relocations to external symbols.
static std::unique_ptr< RuntimeDyldMachO > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
Create a RuntimeDyldMachO instance for the given target architecture.
Information about the loaded object.
uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const override
Obtain the Load Address of a section by SectionRef.
ObjSectionToIDMap ObjSecToIDMap
virtual TLSSection allocateTLSSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName)
Allocate a memory block of (at least) the given size to be used for thread-local storage (TLS).
LLVM_ABI void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress)
Map a section to its target address space value.
void setProcessAllSections(bool ProcessAllSections)
By default, only sections that are "required for execution" are passed to the RTDyldMemoryManager,...
LLVM_ABI void reassignSectionAddress(unsigned SectionID, uint64_t Addr)
LLVM_ABI uint64_t getSectionLoadAddress(unsigned SectionID) const
If the section was loaded, return the section's load address, otherwise return std::nullopt.
LLVM_ABI void * getSymbolLocalAddress(StringRef Name) const
Get the address of our local copy of the symbol.
LLVM_ABI std::map< StringRef, JITEvaluatedSymbol > getSymbolTable() const
Returns a copy of the symbol table.
LLVM_ABI void resolveRelocations()
Resolve the relocations for all symbols we currently know about.
LLVM_ABI void finalizeWithMemoryManagerLocking()
Perform all actions needed to make the code owned by this RuntimeDyld instance executable:
std::function< void( StringRef FileName, StringRef SectionName, StringRef SymbolName, unsigned SectionID, uint32_t StubOffset)> NotifyStubEmittedFunction
LLVM_ABI void deregisterEHFrames()
LLVM_ABI void registerEHFrames()
Register any EH frame sections that have been loaded but not previously registered with the memory ma...
LLVM_ABI StringRef getSectionContent(unsigned SectionID) const
Returns the section's working memory.
LLVM_ABI JITEvaluatedSymbol getSymbol(StringRef Name) const
Get the target address and flags for the named symbol.
LLVM_ABI RuntimeDyld(MemoryManager &MemMgr, JITSymbolResolver &Resolver)
Construct a RuntimeDyld instance.
LLVM_ABI std::unique_ptr< LoadedObjectInfo > loadObject(const object::ObjectFile &O)
Add the referenced object file to the list of objects to be loaded and relocated.
LLVM_ABI StringRef getErrorString()
LLVM_ABI unsigned getSymbolSectionID(StringRef Name) const
Get the section ID for the section containing the given symbol.
SectionEntry - represents a section emitted into memory by the dynamic linker.
StringRef getName() const
uint8_t * getAddress() const
uint64_t getLoadAddress() const
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringMapIterBase< SymbolTableEntry, true > const_iterator
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringRef - Represent a constant reference to a string, i.e.
Symbol info for RuntimeDyld.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
bool isLittleEndian() const
StringRef getFileName() const
uint64_t getFlags() const
This class is the base class for all object file types.
virtual section_iterator section_end() const =0
symbol_iterator_range symbols() const
virtual Triple::ArchType getArch() const =0
virtual section_iterator section_begin() const =0
This is a value type class that represents a single relocation in the list of relocations in the obje...
This is a value type class that represents a single section in the list of sections in the object fil...
uint64_t getAddress() const
bool isText() const
Whether this section contains instructions.
This is a value type class that represents a single symbol in the list of symbols in the object file.
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
virtual basic_symbol_iterator symbol_begin() const =0
virtual basic_symbol_iterator symbol_end() const =0
This class implements an extremely fast bulk output stream that can only output to a stream.
unique_function is a type-erasing functor similar to std::function.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_CNT_INITIALIZED_DATA
@ S_GB_ZEROFILL
S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 gigabytes).
@ S_ZEROFILL
S_ZEROFILL - Zero fill on demand section.
content_iterator< SectionRef > section_iterator
content_iterator< RelocationRef > relocation_iterator
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
static std::unique_ptr< RuntimeDyldMachO > createRuntimeDyldMachO(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver, bool ProcessAllSections, RuntimeDyld::NotifyStubEmittedFunction NotifyStubEmitted)
FunctionAddr VTableAddr uintptr_t uintptr_t DataSize
static bool isTLS(const SectionRef Section)
static void dumpSectionMemory(const SectionEntry &S, StringRef State)
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
static std::unique_ptr< RuntimeDyldCOFF > createRuntimeDyldCOFF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver, bool ProcessAllSections, RuntimeDyld::NotifyStubEmittedFunction NotifyStubEmitted)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
static bool isReadOnlyData(const SectionRef Section)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
LLVM_ABI void jitLinkForORC(object::OwningBinary< object::ObjectFile > O, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver, bool ProcessAllSections, unique_function< Error(const object::ObjectFile &Obj, RuntimeDyld::LoadedObjectInfo &, std::map< StringRef, JITEvaluatedSymbol >)> OnLoaded, unique_function< void(object::OwningBinary< object::ObjectFile >, std::unique_ptr< RuntimeDyld::LoadedObjectInfo >, Error)> OnEmitted)
static std::unique_ptr< RuntimeDyldELF > createRuntimeDyldELF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver, bool ProcessAllSections, RuntimeDyld::NotifyStubEmittedFunction NotifyStubEmitted)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
static bool isZeroInit(const SectionRef Section)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
static uint64_t computeAllocationSizeForSections(std::vector< uint64_t > &SectionSizes, Align Alignment)
static bool isRequiredForExecution(const SectionRef Section)
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
An allocated TLS section.
support::ulittle32_t VirtualSize
support::ulittle32_t Characteristics
support::ulittle32_t SizeOfRawData