27 using namespace llvm::object;
29 #define DEBUG_TYPE "dyld"
34 GenericRTDyldError = 1
42 const char *
name()
const noexcept
override {
return "runtimedyld"; }
44 std::string message(
int Condition)
const override {
45 switch (static_cast<RuntimeDyldErrorCode>(Condition)) {
46 case GenericRTDyldError:
return "Generic RuntimeDyld error";
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) <<
":";
126 for (
int i = 0, e = Sections.size(); i != e; ++i)
131 if (
auto Err = resolveExternalSymbols()) {
133 ErrorStr =
toString(std::move(Err));
137 for (
auto it = Relocations.begin(), e = Relocations.end(); it != e; ++it) {
142 uint64_t Addr = Sections[Idx].getLoadAddress();
143 DEBUG(
dbgs() <<
"Resolving relocations Section #" << Idx <<
"\t"
144 <<
format(
"%p", (uintptr_t)Addr) <<
"\n");
145 resolveRelocationList(it->second, Addr);
151 for (
int i = 0, e = Sections.size(); i != e; ++i)
158 uint64_t TargetAddress) {
160 for (
unsigned i = 0, e = Sections.size(); i != e; ++i) {
161 if (Sections[i].getAddress() == LocalAddress) {
162 reassignSectionAddress(i, TargetAddress);
189 if (MemMgr.needsToReserveAllocationSpace()) {
190 uint64_t CodeSize = 0, RODataSize = 0, RWDataSize = 0;
191 uint32_t CodeAlign = 1, RODataAlign = 1, RWDataAlign = 1;
192 if (
auto Err = computeTotalAllocSize(Obj,
194 RODataSize, RODataAlign,
195 RWDataSize, RWDataAlign))
196 return std::move(Err);
197 MemMgr.reserveAllocationSpace(CodeSize, CodeAlign, RODataSize, RODataAlign,
198 RWDataSize, RWDataAlign);
218 CommonSymbols.push_back(*
I);
223 if (
auto SymTypeOrErr =
I->getType())
224 SymType = *SymTypeOrErr;
226 return SymTypeOrErr.takeError();
230 if (
auto NameOrErr =
I->getName())
233 return NameOrErr.takeError();
242 if (JITSymFlags.
isWeak()) {
245 if (GlobalSymbolTable.count(Name))
249 if (
auto Sym = Resolver.findSymbolInLogicalDylib(Name)) {
250 if (Sym.getFlags().isStrongDefinition())
252 }
else if (
auto Err = Sym.takeError())
253 return std::move(Err);
261 if (
auto AddrOrErr =
I->getAddress())
264 return AddrOrErr.takeError();
266 unsigned SectionID = AbsoluteSymbolSection;
268 DEBUG(
dbgs() <<
"\tType: " << SymType <<
" (absolute) Name: " << Name
269 <<
" SID: " << SectionID <<
" Offset: "
270 <<
format(
"%p", (uintptr_t)Addr)
271 <<
" flags: " << Flags <<
"\n");
272 GlobalSymbolTable[
Name] =
280 if (
auto SIOrErr =
I->getSection())
283 return SIOrErr.takeError();
290 if (
auto Err =
getOffset(*
I, *SI, SectOffset))
291 return std::move(Err);
293 bool IsCode = SI->isText();
295 if (
auto SectionIDOrErr = findOrEmitSection(Obj, *SI, IsCode,
297 SectionID = *SectionIDOrErr;
299 return SectionIDOrErr.takeError();
301 DEBUG(
dbgs() <<
"\tType: " << SymType <<
" Name: " << Name
302 <<
" SID: " << SectionID <<
" Offset: "
303 <<
format(
"%p", (uintptr_t)SectOffset)
304 <<
" flags: " << Flags <<
"\n");
305 GlobalSymbolTable[
Name] =
312 if (
auto Err = emitCommonSymbols(Obj, CommonSymbols))
313 return std::move(Err);
322 if (RelocatedSection == SE)
328 if (I == E && !ProcessAllSections)
331 bool IsCode = RelocatedSection->isText();
332 unsigned SectionID = 0;
333 if (
auto SectionIDOrErr = findOrEmitSection(Obj, *RelocatedSection, IsCode,
335 SectionID = *SectionIDOrErr;
337 return SectionIDOrErr.takeError();
339 DEBUG(
dbgs() <<
"\tSectionID: " << SectionID <<
"\n");
342 if (
auto IOrErr = processRelocationRef(SectionID, I, Obj, LocalSections, Stubs))
345 return IOrErr.takeError();
350 Checker->registerStubMap(Obj.
getFileName(), SectionID, Stubs);
354 if (
auto Err = finalizeLoad(Obj, LocalSections))
355 return std::move(Err);
360 return LocalSections;
368 uint64_t Alignment) {
369 uint64_t TotalSize = 0;
370 for (
size_t Idx = 0, Cnt = SectionSizes.size(); Idx < Cnt; Idx++) {
371 uint64_t AlignedSize =
372 (SectionSizes[Idx] + Alignment - 1) / Alignment * Alignment;
373 TotalSize += AlignedSize;
380 if (isa<object::ELFObjectFileBase>(Obj))
382 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj)) {
383 const coff_section *CoffSection = COFFObj->getCOFFSection(Section);
394 return HasContent && !IsDiscardable;
397 assert(isa<MachOObjectFile>(Obj));
403 if (isa<object::ELFObjectFileBase>(Obj))
406 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj))
407 return ((COFFObj->getCOFFSection(Section)->Characteristics &
415 assert(isa<MachOObjectFile>(Obj));
421 if (isa<object::ELFObjectFileBase>(Obj))
423 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj))
424 return COFFObj->getCOFFSection(Section)->Characteristics &
427 auto *MachO = cast<MachOObjectFile>(Obj);
428 unsigned SectionType = MachO->getSectionType(Section);
438 uint64_t &RODataSize,
440 uint64_t &RWDataSize,
443 std::vector<uint64_t> CodeSectionSizes;
444 std::vector<uint64_t> ROSectionSizes;
445 std::vector<uint64_t> RWSectionSizes;
457 uint64_t DataSize = Section.
getSize();
459 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
460 bool IsCode = Section.
isText();
464 if (
auto EC = Section.
getName(Name))
467 uint64_t StubBufSize = computeSectionStubBufSize(Obj, Section);
475 if (Name ==
".eh_frame")
482 CodeAlign =
std::max(CodeAlign, Alignment);
483 CodeSectionSizes.push_back(SectionSize);
484 }
else if (IsReadOnly) {
485 RODataAlign =
std::max(RODataAlign, Alignment);
486 ROSectionSizes.push_back(SectionSize);
488 RWDataAlign =
std::max(RWDataAlign, Alignment);
489 RWSectionSizes.push_back(SectionSize);
497 if (
unsigned GotSize = computeGOTSize(Obj)) {
498 RWSectionSizes.push_back(GotSize);
499 RWDataAlign = std::max<uint32_t>(RWDataAlign, getGOTEntrySize());
503 uint64_t CommonSize = 0;
510 uint64_t
Size =
I->getCommonSize();
519 if (CommonSize != 0) {
520 RWSectionSizes.push_back(CommonSize);
521 RWDataAlign =
std::max(RWDataAlign, CommonAlign);
538 size_t GotEntrySize = getGOTEntrySize();
547 if (relocationNeedsGot(Reloc))
548 GotSize += GotEntrySize;
557 unsigned StubSize = getMaxStubSize();
564 unsigned StubBufSize = 0;
568 if (!(RelSecI == Section))
572 if (relocationNeedsStub(Reloc))
573 StubBufSize += StubSize;
577 uint64_t DataSize = Section.
getSize();
581 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
582 unsigned StubAlignment = getStubAlignment();
583 unsigned EndAlignment = (DataSize | Alignment) & -(DataSize | Alignment);
584 if (StubAlignment > EndAlignment)
585 StubBufSize += StubAlignment - EndAlignment;
590 unsigned Size)
const {
592 if (IsTargetLittleEndian) {
595 Result = (Result << 8) | *Src--;
598 Result = (Result << 8) | *Src++;
604 unsigned Size)
const {
605 if (IsTargetLittleEndian) {
607 *Dst++ = Value & 0xFF;
613 *Dst-- = Value & 0xFF;
621 if (CommonSymbols.empty())
624 uint64_t CommonSize = 0;
625 uint32_t CommonAlign = CommonSymbols.begin()->getAlignment();
628 DEBUG(
dbgs() <<
"Processing common symbols...\n");
630 for (
const auto &Sym : CommonSymbols) {
632 if (
auto NameOrErr = Sym.getName())
635 return NameOrErr.takeError();
638 if (GlobalSymbolTable.count(Name)) {
639 DEBUG(
dbgs() <<
"\tSkipping already emitted common symbol '" << Name
644 if (
auto Sym = Resolver.findSymbolInLogicalDylib(Name)) {
645 if (!Sym.getFlags().isCommon()) {
646 DEBUG(
dbgs() <<
"\tSkipping common symbol '" << Name
647 <<
"' in favor of stronger definition.\n");
652 uint64_t
Size = Sym.getCommonSize();
656 SymbolsToAllocate.push_back(Sym);
660 unsigned SectionID = Sections.size();
661 uint8_t *Addr = MemMgr.allocateDataSection(CommonSize, CommonAlign, SectionID,
662 "<common symbols>",
false);
667 SectionEntry(
"<common symbols>", Addr, CommonSize, CommonSize, 0));
668 memset(Addr, 0, CommonSize);
670 DEBUG(
dbgs() <<
"emitCommonSection SectionID: " << SectionID <<
" new addr: "
671 <<
format(
"%p", Addr) <<
" DataSize: " << CommonSize <<
"\n");
674 for (
auto &Sym : SymbolsToAllocate) {
676 uint64_t
Size = Sym.getCommonSize();
678 if (
auto NameOrErr = Sym.getName())
681 return NameOrErr.takeError();
686 Offset += AlignOffset;
689 DEBUG(
dbgs() <<
"Allocating common symbol " << Name <<
" address "
690 <<
format(
"%p", Addr) <<
"\n");
691 GlobalSymbolTable[
Name] =
698 Checker->registerSection(Obj.
getFileName(), SectionID);
710 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
711 unsigned PaddingSize = 0;
712 unsigned StubBufSize = 0;
717 uint64_t DataSize = Section.
getSize();
720 if (
auto EC = Section.
getName(Name))
723 StubBufSize = computeSectionStubBufSize(Obj, Section);
728 if (Name ==
".eh_frame")
732 unsigned SectionID = Sections.size();
734 const char *pData =
nullptr;
738 if (!IsVirtual && !IsZeroInit) {
750 Alignment =
std::max(Alignment, getStubAlignment());
754 if (IsRequired || ProcessAllSections) {
755 Allocate = DataSize + PaddingSize + StubBufSize;
758 Addr = IsCode ? MemMgr.allocateCodeSection(Allocate, Alignment, SectionID,
760 : MemMgr.allocateDataSection(Allocate, Alignment, SectionID,
766 if (IsZeroInit || IsVirtual)
767 memset(Addr, 0, DataSize);
769 memcpy(Addr, pData, DataSize);
772 if (PaddingSize != 0) {
773 memset(Addr + DataSize, 0, PaddingSize);
775 DataSize += PaddingSize;
778 DEBUG(
dbgs() <<
"emitSection SectionID: " << SectionID <<
" Name: " << Name
779 <<
" obj addr: " <<
format(
"%p", pData)
780 <<
" new addr: " <<
format(
"%p", Addr)
781 <<
" DataSize: " << DataSize <<
" StubBufSize: " << StubBufSize
782 <<
" Allocate: " << Allocate <<
"\n");
789 DEBUG(
dbgs() <<
"emitSection SectionID: " << SectionID <<
" Name: " << Name
790 <<
" obj addr: " <<
format(
"%p", data.
data()) <<
" new addr: 0"
791 <<
" DataSize: " << DataSize <<
" StubBufSize: " << StubBufSize
792 <<
" Allocate: " << Allocate <<
"\n");
796 SectionEntry(Name, Addr, DataSize, Allocate, (uintptr_t)pData));
800 Sections.back().setLoadAddress(0);
803 Checker->registerSection(Obj.
getFileName(), SectionID);
814 unsigned SectionID = 0;
815 ObjSectionToIDMap::iterator i = LocalSections.find(Section);
816 if (i != LocalSections.end())
817 SectionID = i->second;
819 if (
auto SectionIDOrErr = emitSection(Obj, Section, IsCode))
820 SectionID = *SectionIDOrErr;
822 return SectionIDOrErr.takeError();
823 LocalSections[
Section] = SectionID;
829 unsigned SectionID) {
830 Relocations[SectionID].push_back(RE);
839 if (Loc == GlobalSymbolTable.end()) {
840 ExternalSymbolRelocations[SymbolName].push_back(RE);
844 const auto &
SymInfo = Loc->second;
846 Relocations[
SymInfo.getSectionID()].push_back(RECopy);
851 unsigned AbiVariant) {
857 writeBytesUnaligned(0xd2e00010, Addr, 4);
858 writeBytesUnaligned(0xf2c00010, Addr+4, 4);
859 writeBytesUnaligned(0xf2a00010, Addr+8, 4);
860 writeBytesUnaligned(0xf2800010, Addr+12, 4);
861 writeBytesUnaligned(0xd61f0200, Addr+16, 4);
867 writeBytesUnaligned(0xe51ff004, Addr, 4);
869 }
else if (IsMipsO32ABI) {
874 const unsigned LuiT9Instr = 0x3c190000, AdduiT9Instr = 0x27390000;
875 const unsigned NopInstr = 0x0;
876 unsigned JrT9Instr = 0x03200008;
878 JrT9Instr = 0x03200009;
880 writeBytesUnaligned(LuiT9Instr, Addr, 4);
881 writeBytesUnaligned(AdduiT9Instr, Addr+4, 4);
882 writeBytesUnaligned(JrT9Instr, Addr+8, 4);
883 writeBytesUnaligned(NopInstr, Addr+12, 4);
889 writeInt32BE(Addr, 0x3D800000);
890 writeInt32BE(Addr+4, 0x618C0000);
891 writeInt32BE(Addr+8, 0x798C07C6);
892 writeInt32BE(Addr+12, 0x658C0000);
893 writeInt32BE(Addr+16, 0x618C0000);
894 if (AbiVariant == 2) {
897 writeInt32BE(Addr+20, 0xF8410018);
898 writeInt32BE(Addr+24, 0x7D8903A6);
899 writeInt32BE(Addr+28, 0x4E800420);
904 writeInt32BE(Addr+20, 0xF8410028);
905 writeInt32BE(Addr+24, 0xE96C0000);
906 writeInt32BE(Addr+28, 0xE84C0008);
907 writeInt32BE(Addr+32, 0x7D6903A6);
908 writeInt32BE(Addr+36, 0xE96C0010);
909 writeInt32BE(Addr+40, 0x4E800420);
913 writeInt16BE(Addr, 0xC418);
914 writeInt16BE(Addr+2, 0x0000);
915 writeInt16BE(Addr+4, 0x0004);
916 writeInt16BE(Addr+6, 0x07F1);
943 DEBUG(
dbgs() <<
"Reassigning address for section " << SectionID <<
" ("
944 << Sections[SectionID].
getName() <<
"): "
945 <<
format(
"0x%016" PRIx64, Sections[SectionID].getLoadAddress())
946 <<
" -> " <<
format(
"0x%016" PRIx64, Addr) <<
"\n");
947 Sections[SectionID].setLoadAddress(Addr);
952 for (
unsigned i = 0, e = Relocs.
size(); i != e; ++i) {
955 if (Sections[RE.
SectionID].getAddress() ==
nullptr)
957 resolveRelocation(RE, Value);
962 while (!ExternalSymbolRelocations.empty()) {
966 if (Name.
size() == 0) {
968 DEBUG(
dbgs() <<
"Resolving absolute relocations."
971 resolveRelocationList(Relocs, 0);
975 if (Loc == GlobalSymbolTable.end()) {
979 if (
auto Sym = Resolver.findSymbolInLogicalDylib(Name.
data())) {
980 if (
auto AddrOrErr = Sym.getAddress())
983 return AddrOrErr.takeError();
984 }
else if (
auto Err = Sym.takeError())
989 if (
auto Sym = Resolver.findSymbol(Name.
data())) {
990 if (
auto AddrOrErr = Sym.getAddress())
993 return AddrOrErr.takeError();
994 }
else if (
auto Err = Sym.takeError())
1003 i = ExternalSymbolRelocations.find(Name);
1007 const auto &
SymInfo = Loc->second;
1008 Addr = getSectionLoadAddress(
SymInfo.getSectionID()) +
1015 "' which could not be resolved!");
1019 if (Addr != UINT64_MAX) {
1020 DEBUG(
dbgs() <<
"Resolving relocations Name: " << Name <<
"\t"
1021 <<
format(
"0x%lx", Addr) <<
"\n");
1025 resolveRelocationList(Relocs, Addr);
1029 ExternalSymbolRelocations.erase(i);
1041 auto I = ObjSecToIDMap.find(Sec);
1042 if (
I != ObjSecToIDMap.end())
1043 return RTDyld.Sections[
I->second].getLoadAddress();
1048 void RuntimeDyld::MemoryManager::anchor() {}
1049 void JITSymbolResolver::anchor() {}
1053 : MemMgr(MemMgr), Resolver(Resolver) {
1061 ProcessAllSections =
false;
1067 static std::unique_ptr<RuntimeDyldCOFF>
1071 std::unique_ptr<RuntimeDyldCOFF> Dyld =
1073 Dyld->setProcessAllSections(ProcessAllSections);
1074 Dyld->setRuntimeDyldChecker(Checker);
1078 static std::unique_ptr<RuntimeDyldELF>
1082 std::unique_ptr<RuntimeDyldELF> Dyld =
1084 Dyld->setProcessAllSections(ProcessAllSections);
1085 Dyld->setRuntimeDyldChecker(Checker);
1089 static std::unique_ptr<RuntimeDyldMachO>
1092 bool ProcessAllSections,
1094 std::unique_ptr<RuntimeDyldMachO> Dyld =
1096 Dyld->setProcessAllSections(ProcessAllSections);
1097 Dyld->setRuntimeDyldChecker(Checker);
1101 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
1107 MemMgr, Resolver, ProcessAllSections, Checker);
1110 static_cast<Triple::ArchType>(Obj.
getArch()), MemMgr, Resolver,
1111 ProcessAllSections, Checker);
1114 static_cast<Triple::ArchType>(Obj.
getArch()), MemMgr, Resolver,
1115 ProcessAllSections, Checker);
1120 if (!Dyld->isCompatibleFile(Obj))
1123 auto LoadedObjInfo = Dyld->loadObject(Obj);
1125 return LoadedObjInfo;
1131 return Dyld->getSymbolLocalAddress(Name);
1137 return Dyld->getSymbol(Name);
1143 Dyld->reassignSectionAddress(SectionID, Addr);
1147 uint64_t TargetAddress) {
1148 Dyld->mapSectionAddress(LocalAddress, TargetAddress);
1156 bool MemoryFinalizationLocked = MemMgr.FinalizationLocked;
1157 MemMgr.FinalizationLocked =
true;
1160 if (!MemoryFinalizationLocked) {
1162 MemMgr.FinalizationLocked =
false;
1168 Dyld->registerEHFrames();
1173 Dyld->deregisterEHFrames();
Error emitCommonSymbols(const ObjectFile &Obj, CommonSymbolList &CommonSymbols)
Given the common symbols discovered in the object file, emit a new section for them and update the sy...
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
std::unique_ptr< LoadedObjectInfo > loadObject(const object::ObjectFile &O)
Add the referenced object file to the list of objects to be loaded and relocated. ...
void registerEHFrames()
Register any EH frame sections that have been loaded but not previously registered with the memory ma...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
StringRef getErrorString()
unsigned computeGOTSize(const ObjectFile &Obj)
static bool isReadOnlyData(const SectionRef Section)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
uint8_t * getAddress() const
This class is the base class for all object file types.
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Error takeError()
Take ownership of the stored error.
uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const override
Obtain the Load Address of a section by SectionRef.
void deregisterEHFrames()
virtual unsigned getArch() const =0
static std::unique_ptr< RuntimeDyldELF > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
virtual basic_symbol_iterator symbol_begin() const =0
unsigned SectionID
SectionID - the section this relocation points to.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
void resolveRelocationList(const RelocationList &Relocs, uint64_t Value)
Resolves relocations from Relocs list with address from Value.
This is a value type class that represents a single relocation in the list of relocations in the obje...
static StringRef getName(Value *V)
static bool isRequiredForExecution(const SectionRef Section)
std::map< RelocationValueRef, uintptr_t > StubMap
Tagged union holding either a T or a Error.
void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress)
virtual void registerEHFrames()
static std::unique_ptr< RuntimeDyldMachO > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
Create a RuntimeDyldMachO instance for the given target architecture.
support::ulittle32_t VirtualSize
static uint64_t computeAllocationSizeForSections(std::vector< uint64_t > &SectionSizes, uint64_t Alignment)
std::error_code getName(StringRef &Result) const
virtual ~RuntimeDyldImpl()
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
JITEvaluatedSymbol getSymbol(StringRef Name) const
Get the target address and flags for the named symbol.
void * getSymbolLocalAddress(StringRef Name) const
Get the address of our local copy of the symbol.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
RuntimeDyld(MemoryManager &MemMgr, JITSymbolResolver &Resolver)
Construct a RuntimeDyld instance.
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
uint64_t getAlignment() const
Get the alignment of this section as the actual value (not log 2).
Instances of this class acquire a given Mutex Lock when constructed and hold that lock until destruct...
support::ulittle32_t Characteristics
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
virtual bool finalizeMemory(std::string *ErrMsg=nullptr)=0
This method is called when object loading is complete and section page permissions can be applied...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 gigabytes).
virtual void notifyObjectLoaded(RuntimeDyld &RTDyld, const object::ObjectFile &Obj)
This method is called after an object has been loaded into memory but before relocations are applied ...
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
static ManagedStatic< _object_error_category > error_category
Error computeTotalAllocSize(const ObjectFile &Obj, uint64_t &CodeSize, uint32_t &CodeAlign, uint64_t &RODataSize, uint32_t &RODataAlign, uint64_t &RWDataSize, uint32_t &RWDataAlign)
Flags for symbols in the JIT.
static JITSymbolFlags fromObjectSymbol(const object::BasicSymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
std::vector< SymbolRef > CommonSymbolList
virtual basic_symbol_iterator symbol_end() const =0
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
support::ulittle32_t SizeOfRawData
uint64_t getAddress() const
StringRef getFileName() const
const ObjectFile * getObject() const
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
static void dumpSectionMemory(const SectionEntry &S, StringRef State)
static ErrorSuccess success()
Create a success value.
unsigned computeSectionStubBufSize(const ObjectFile &Obj, const SectionRef &Section)
virtual section_iterator section_begin() const =0
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Symbol info for RuntimeDyld.
static std::unique_ptr< RuntimeDyldCOFF > createRuntimeDyldCOFF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver, bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker)
void reassignSectionAddress(unsigned SectionID, uint64_t Addr)
Represents a symbol that has been evaluated to an address already.
std::error_code getContents(StringRef &Result) const
This is a value type class that represents a single symbol in the list of symbols in the object file...
static std::unique_ptr< RuntimeDyldELF > createRuntimeDyldELF(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver, bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker)
static bool isZeroInit(const SectionRef Section)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
virtual section_iterator section_end() const =0
std::map< SectionRef, unsigned > ObjSectionToIDMap
void resolveRelocations()
void finalizeWithMemoryManagerLocking()
Perform all actions needed to make the code owned by this RuntimeDyld instance executable: ...
static std::unique_ptr< RuntimeDyldCOFF > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Expected< unsigned > emitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode)
Emits section data from the object file to the MemoryManager.
bool isLittleEndian() const
static std::unique_ptr< RuntimeDyldMachO > createRuntimeDyldMachO(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver, bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker)
uint64_t getLoadAddress() const
void resolveRelocations()
Resolve the relocations for all symbols we currently know about.
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
SectionEntry - represents a section emitted into memory by the dynamic linker.
void deregisterEHFrames()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
bool isWeak() const
Returns true is the Weak flag is set.
Lightweight error class with error context and mandatory checking.
uint64_t OffsetToAlignment(uint64_t Value, uint64_t Align)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
void reassignSectionAddress(unsigned SectionID, uint64_t Addr)
StringRef - Represent a constant reference to a string, i.e.
Expected< ObjSectionToIDMap > loadObjectImpl(const object::ObjectFile &Obj)
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
S_ZEROFILL - Zero fill on demand section.
Error resolveExternalSymbols()
Resolve relocations to external symbols.
void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress)
Map a section to its target address space value.
StringRef getName() const
SectionType
These are the section type and attributes fields.
This is a value type class that represents a single section in the list of sections in the object fil...
uint64_t getFlags() const