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) <<
":";
125 LLVM_DEBUG(
for (
int i = 0, e = Sections.size(); i != e; ++i)
129 if (
auto Err = resolveExternalSymbols()) {
131 ErrorStr =
toString(std::move(Err));
135 for (
auto it = Relocations.begin(), e = Relocations.end(); it != e; ++it) {
140 uint64_t Addr = Sections[Idx].getLoadAddress();
141 LLVM_DEBUG(
dbgs() <<
"Resolving relocations Section #" << Idx <<
"\t" 142 <<
format(
"%p", (uintptr_t)Addr) <<
"\n");
143 resolveRelocationList(it->second, Addr);
148 LLVM_DEBUG(
for (
int i = 0, e = Sections.size(); i != e; ++i)
153 uint64_t TargetAddress) {
155 for (
unsigned i = 0, e = Sections.size(); i != e; ++i) {
156 if (Sections[i].getAddress() == LocalAddress) {
157 reassignSectionAddress(i, TargetAddress);
184 if (MemMgr.needsToReserveAllocationSpace()) {
185 uint64_t CodeSize = 0, RODataSize = 0, RWDataSize = 0;
186 uint32_t CodeAlign = 1, RODataAlign = 1, RWDataAlign = 1;
187 if (
auto Err = computeTotalAllocSize(Obj,
189 RODataSize, RODataAlign,
190 RWDataSize, RWDataAlign))
191 return std::move(Err);
192 MemMgr.reserveAllocationSpace(CodeSize, CodeAlign, RODataSize, RODataAlign,
193 RWDataSize, RWDataAlign);
202 uint64_t CommonSize = 0;
210 for (
auto &Sym : Obj.
symbols()) {
214 if (
auto NameOrErr = Sym.getName())
215 Symbols.insert(*NameOrErr);
217 return NameOrErr.takeError();
221 if (
auto FlagsResultOrErr =
Resolver.lookupFlags(Symbols))
222 SymbolFlags = std::move(*FlagsResultOrErr);
224 return FlagsResultOrErr.takeError();
239 if (
auto SymTypeOrErr =
I->getType())
240 SymType = *SymTypeOrErr;
242 return SymTypeOrErr.takeError();
246 if (
auto NameOrErr =
I->getName())
249 return NameOrErr.takeError();
261 if (GlobalSymbolTable.count(Name))
266 auto FlagsI = SymbolFlags.find(Name);
267 if (FlagsI == SymbolFlags.end() ||
268 (JITSymFlags.
isWeak() && !FlagsI->second.isStrong()) ||
269 (JITSymFlags.
isCommon() && FlagsI->second.isCommon())) {
275 uint64_t
Size =
I->getCommonSize();
279 CommonSymbolsToAllocate.push_back(*
I);
288 if (
auto AddrOrErr =
I->getAddress())
291 return AddrOrErr.takeError();
293 unsigned SectionID = AbsoluteSymbolSection;
295 LLVM_DEBUG(
dbgs() <<
"\tType: " << SymType <<
" (absolute) Name: " << Name
296 <<
" SID: " << SectionID
297 <<
" Offset: " <<
format(
"%p", (uintptr_t)Addr)
298 <<
" flags: " << Flags <<
"\n");
306 if (
auto SIOrErr =
I->getSection())
309 return SIOrErr.takeError();
316 if (
auto Err =
getOffset(*
I, *SI, SectOffset))
317 return std::move(Err);
319 bool IsCode = SI->isText();
321 if (
auto SectionIDOrErr =
322 findOrEmitSection(Obj, *SI, IsCode, LocalSections))
323 SectionID = *SectionIDOrErr;
325 return SectionIDOrErr.takeError();
328 <<
" SID: " << SectionID
329 <<
" Offset: " <<
format(
"%p", (uintptr_t)SectOffset)
330 <<
" flags: " << Flags <<
"\n");
331 GlobalSymbolTable[
Name] =
337 if (
auto Err = emitCommonSymbols(Obj, CommonSymbolsToAllocate, CommonSize,
339 return std::move(Err);
348 if (RelocatedSection == SE)
354 if (I == E && !ProcessAllSections)
357 bool IsCode = RelocatedSection->isText();
358 unsigned SectionID = 0;
359 if (
auto SectionIDOrErr = findOrEmitSection(Obj, *RelocatedSection, IsCode,
361 SectionID = *SectionIDOrErr;
363 return SectionIDOrErr.takeError();
368 if (
auto IOrErr = processRelocationRef(SectionID, I, Obj, LocalSections, Stubs))
371 return IOrErr.takeError();
376 Checker->registerStubMap(Obj.
getFileName(), SectionID, Stubs);
380 if (
auto Err = finalizeLoad(Obj, LocalSections))
381 return std::move(Err);
386 return LocalSections;
394 uint64_t Alignment) {
395 uint64_t TotalSize = 0;
396 for (
size_t Idx = 0, Cnt = SectionSizes.size(); Idx < Cnt; Idx++) {
397 uint64_t AlignedSize =
398 (SectionSizes[Idx] + Alignment - 1) / Alignment * Alignment;
399 TotalSize += AlignedSize;
406 if (isa<object::ELFObjectFileBase>(Obj))
408 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj)) {
409 const coff_section *CoffSection = COFFObj->getCOFFSection(Section);
420 return HasContent && !IsDiscardable;
423 assert(isa<MachOObjectFile>(Obj));
429 if (isa<object::ELFObjectFileBase>(Obj))
432 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj))
433 return ((COFFObj->getCOFFSection(Section)->Characteristics &
441 assert(isa<MachOObjectFile>(Obj));
447 if (isa<object::ELFObjectFileBase>(Obj))
449 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj))
450 return COFFObj->getCOFFSection(Section)->Characteristics &
453 auto *MachO = cast<MachOObjectFile>(Obj);
454 unsigned SectionType = MachO->getSectionType(Section);
464 uint64_t &RODataSize,
466 uint64_t &RWDataSize,
469 std::vector<uint64_t> CodeSectionSizes;
470 std::vector<uint64_t> ROSectionSizes;
471 std::vector<uint64_t> RWSectionSizes;
483 uint64_t DataSize = Section.
getSize();
485 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
486 bool IsCode = Section.
isText();
490 if (
auto EC = Section.
getName(Name))
493 uint64_t StubBufSize = computeSectionStubBufSize(Obj, Section);
501 if (Name ==
".eh_frame")
508 CodeAlign =
std::max(CodeAlign, Alignment);
509 CodeSectionSizes.push_back(SectionSize);
510 }
else if (IsReadOnly) {
511 RODataAlign =
std::max(RODataAlign, Alignment);
512 ROSectionSizes.push_back(SectionSize);
514 RWDataAlign =
std::max(RWDataAlign, Alignment);
515 RWSectionSizes.push_back(SectionSize);
523 if (
unsigned GotSize = computeGOTSize(Obj)) {
524 RWSectionSizes.push_back(GotSize);
525 RWDataAlign = std::max<uint32_t>(RWDataAlign, getGOTEntrySize());
529 uint64_t CommonSize = 0;
536 uint64_t
Size =
I->getCommonSize();
545 if (CommonSize != 0) {
546 RWSectionSizes.push_back(CommonSize);
547 RWDataAlign =
std::max(RWDataAlign, CommonAlign);
564 size_t GotEntrySize = getGOTEntrySize();
573 if (relocationNeedsGot(Reloc))
574 GotSize += GotEntrySize;
583 unsigned StubSize = getMaxStubSize();
590 unsigned StubBufSize = 0;
594 if (!(RelSecI == Section))
598 if (relocationNeedsStub(Reloc))
599 StubBufSize += StubSize;
603 uint64_t DataSize = Section.
getSize();
607 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
608 unsigned StubAlignment = getStubAlignment();
609 unsigned EndAlignment = (DataSize | Alignment) & -(DataSize | Alignment);
610 if (StubAlignment > EndAlignment)
611 StubBufSize += StubAlignment - EndAlignment;
616 unsigned Size)
const {
618 if (IsTargetLittleEndian) {
621 Result = (Result << 8) | *Src--;
624 Result = (Result << 8) | *Src++;
630 unsigned Size)
const {
631 if (IsTargetLittleEndian) {
633 *Dst++ = Value & 0xFF;
639 *Dst-- = Value & 0xFF;
653 if (SymbolsToAllocate.empty())
657 unsigned SectionID = Sections.size();
658 uint8_t *Addr = MemMgr.allocateDataSection(CommonSize, CommonAlign, SectionID,
659 "<common symbols>",
false);
664 SectionEntry(
"<common symbols>", Addr, CommonSize, CommonSize, 0));
665 memset(Addr, 0, CommonSize);
668 <<
" new addr: " <<
format(
"%p", Addr)
669 <<
" DataSize: " << CommonSize <<
"\n");
672 for (
auto &Sym : SymbolsToAllocate) {
674 uint64_t
Size = Sym.getCommonSize();
676 if (
auto NameOrErr = Sym.getName())
679 return NameOrErr.takeError();
684 Offset += AlignOffset;
687 LLVM_DEBUG(
dbgs() <<
"Allocating common symbol " << Name <<
" address " 688 <<
format(
"%p", Addr) <<
"\n");
689 GlobalSymbolTable[
Name] =
696 Checker->registerSection(Obj.
getFileName(), SectionID);
708 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
709 unsigned PaddingSize = 0;
710 unsigned StubBufSize = 0;
715 uint64_t DataSize = Section.
getSize();
718 if (
auto EC = Section.
getName(Name))
721 StubBufSize = computeSectionStubBufSize(Obj, Section);
726 if (Name ==
".eh_frame")
730 unsigned SectionID = Sections.size();
732 const char *pData =
nullptr;
736 if (!IsVirtual && !IsZeroInit) {
748 Alignment =
std::max(Alignment, getStubAlignment());
750 PaddingSize += getStubAlignment() - 1;
755 if (IsRequired || ProcessAllSections) {
756 Allocate = DataSize + PaddingSize + StubBufSize;
759 Addr = IsCode ? MemMgr.allocateCodeSection(Allocate, Alignment, SectionID,
761 : MemMgr.allocateDataSection(Allocate, Alignment, SectionID,
767 if (IsZeroInit || IsVirtual)
768 memset(Addr, 0, DataSize);
770 memcpy(Addr, pData, DataSize);
773 if (PaddingSize != 0) {
774 memset(Addr + DataSize, 0, PaddingSize);
776 DataSize += PaddingSize;
781 DataSize &= ~(getStubAlignment() - 1);
784 LLVM_DEBUG(
dbgs() <<
"emitSection SectionID: " << SectionID <<
" Name: " 785 << Name <<
" obj addr: " <<
format(
"%p", pData)
786 <<
" new addr: " <<
format(
"%p", Addr) <<
" DataSize: " 787 << DataSize <<
" StubBufSize: " << StubBufSize
788 <<
" Allocate: " << Allocate <<
"\n");
796 dbgs() <<
"emitSection SectionID: " << SectionID <<
" Name: " << Name
797 <<
" obj addr: " <<
format(
"%p", data.
data()) <<
" new addr: 0" 798 <<
" DataSize: " << DataSize <<
" StubBufSize: " << StubBufSize
799 <<
" Allocate: " << Allocate <<
"\n");
803 SectionEntry(Name, Addr, DataSize, Allocate, (uintptr_t)pData));
807 Sections.back().setLoadAddress(0);
810 Checker->registerSection(Obj.
getFileName(), SectionID);
821 unsigned SectionID = 0;
822 ObjSectionToIDMap::iterator i = LocalSections.find(Section);
823 if (i != LocalSections.end())
824 SectionID = i->second;
826 if (
auto SectionIDOrErr = emitSection(Obj, Section, IsCode))
827 SectionID = *SectionIDOrErr;
829 return SectionIDOrErr.takeError();
830 LocalSections[
Section] = SectionID;
836 unsigned SectionID) {
837 Relocations[SectionID].push_back(RE);
846 if (Loc == GlobalSymbolTable.end()) {
847 ExternalSymbolRelocations[
SymbolName].push_back(RE);
851 const auto &
SymInfo = Loc->second;
853 Relocations[
SymInfo.getSectionID()].push_back(RECopy);
858 unsigned AbiVariant) {
864 writeBytesUnaligned(0xd2e00010, Addr, 4);
865 writeBytesUnaligned(0xf2c00010, Addr+4, 4);
866 writeBytesUnaligned(0xf2a00010, Addr+8, 4);
867 writeBytesUnaligned(0xf2800010, Addr+12, 4);
868 writeBytesUnaligned(0xd61f0200, Addr+16, 4);
874 writeBytesUnaligned(0xe51ff004, Addr, 4);
876 }
else if (IsMipsO32ABI || IsMipsN32ABI) {
881 const unsigned LuiT9Instr = 0x3c190000, AdduiT9Instr = 0x27390000;
882 const unsigned NopInstr = 0x0;
883 unsigned JrT9Instr = 0x03200008;
886 JrT9Instr = 0x03200009;
888 writeBytesUnaligned(LuiT9Instr, Addr, 4);
889 writeBytesUnaligned(AdduiT9Instr, Addr + 4, 4);
890 writeBytesUnaligned(JrT9Instr, Addr + 8, 4);
891 writeBytesUnaligned(NopInstr, Addr + 12, 4);
893 }
else if (IsMipsN64ABI) {
902 const unsigned LuiT9Instr = 0x3c190000, DaddiuT9Instr = 0x67390000,
903 DsllT9Instr = 0x19CC38;
904 const unsigned NopInstr = 0x0;
905 unsigned JrT9Instr = 0x03200008;
907 JrT9Instr = 0x03200009;
909 writeBytesUnaligned(LuiT9Instr, Addr, 4);
910 writeBytesUnaligned(DaddiuT9Instr, Addr + 4, 4);
911 writeBytesUnaligned(DsllT9Instr, Addr + 8, 4);
912 writeBytesUnaligned(DaddiuT9Instr, Addr + 12, 4);
913 writeBytesUnaligned(DsllT9Instr, Addr + 16, 4);
914 writeBytesUnaligned(DaddiuT9Instr, Addr + 20, 4);
915 writeBytesUnaligned(JrT9Instr, Addr + 24, 4);
916 writeBytesUnaligned(NopInstr, Addr + 28, 4);
922 writeInt32BE(Addr, 0x3D800000);
923 writeInt32BE(Addr+4, 0x618C0000);
924 writeInt32BE(Addr+8, 0x798C07C6);
925 writeInt32BE(Addr+12, 0x658C0000);
926 writeInt32BE(Addr+16, 0x618C0000);
927 if (AbiVariant == 2) {
930 writeInt32BE(Addr+20, 0xF8410018);
931 writeInt32BE(Addr+24, 0x7D8903A6);
932 writeInt32BE(Addr+28, 0x4E800420);
937 writeInt32BE(Addr+20, 0xF8410028);
938 writeInt32BE(Addr+24, 0xE96C0000);
939 writeInt32BE(Addr+28, 0xE84C0008);
940 writeInt32BE(Addr+32, 0x7D6903A6);
941 writeInt32BE(Addr+36, 0xE96C0010);
942 writeInt32BE(Addr+40, 0x4E800420);
946 writeInt16BE(Addr, 0xC418);
947 writeInt16BE(Addr+2, 0x0000);
948 writeInt16BE(Addr+4, 0x0004);
949 writeInt16BE(Addr+6, 0x07F1);
977 dbgs() <<
"Reassigning address for section " << SectionID <<
" (" 978 << Sections[SectionID].
getName() <<
"): " 979 <<
format(
"0x%016" PRIx64, Sections[SectionID].getLoadAddress())
980 <<
" -> " <<
format(
"0x%016" PRIx64, Addr) <<
"\n");
981 Sections[SectionID].setLoadAddress(Addr);
986 for (
unsigned i = 0, e = Relocs.
size(); i != e; ++i) {
989 if (Sections[RE.
SectionID].getAddress() ==
nullptr)
991 resolveRelocation(RE, Value);
1006 for (
auto &RelocKV : ExternalSymbolRelocations) {
1008 if (!Name.
empty() && !GlobalSymbolTable.count(Name) &&
1009 !ResolvedSymbols.count(Name))
1010 NewSymbols.insert(Name);
1013 if (NewSymbols.empty())
1016 auto NewResolverResults =
Resolver.lookup(NewSymbols);
1017 if (!NewResolverResults)
1018 return NewResolverResults.takeError();
1020 assert(NewResolverResults->size() == NewSymbols.size() &&
1021 "Should have errored on unresolved symbols");
1023 for (
auto &RRKV : *NewResolverResults) {
1024 assert(!ResolvedSymbols.count(RRKV.first) &&
"Redundant resolution?");
1025 ExternalSymbolMap.
insert(RRKV);
1026 ResolvedSymbols.insert(RRKV.first);
1031 while (!ExternalSymbolRelocations.empty()) {
1036 if (Name.
size() == 0) {
1041 resolveRelocationList(Relocs, 0);
1046 if (Loc == GlobalSymbolTable.end()) {
1047 auto RRI = ExternalSymbolMap.
find(Name);
1048 assert(RRI != ExternalSymbolMap.
end() &&
"No result for symbol");
1049 Addr = RRI->second.getAddress();
1050 Flags = RRI->second.getFlags();
1057 i = ExternalSymbolRelocations.find(Name);
1061 const auto &
SymInfo = Loc->second;
1062 Addr = getSectionLoadAddress(
SymInfo.getSectionID()) +
1070 "' which could not be resolved!");
1079 Addr = modifyAddressBasedOnFlags(Addr, Flags);
1081 LLVM_DEBUG(
dbgs() <<
"Resolving relocations Name: " << Name <<
"\t" 1082 <<
format(
"0x%lx", Addr) <<
"\n");
1086 resolveRelocationList(Relocs, Addr);
1090 ExternalSymbolRelocations.erase(i);
1102 auto I = ObjSecToIDMap.find(Sec);
1103 if (
I != ObjSecToIDMap.end())
1104 return RTDyld.Sections[
I->second].getLoadAddress();
1109 void RuntimeDyld::MemoryManager::anchor() {}
1110 void JITSymbolResolver::anchor() {}
1111 void LegacyJITSymbolResolver::anchor() {}
1115 : MemMgr(MemMgr), Resolver(Resolver) {
1123 ProcessAllSections =
false;
1129 static std::unique_ptr<RuntimeDyldCOFF>
1133 std::unique_ptr<RuntimeDyldCOFF> Dyld =
1135 Dyld->setProcessAllSections(ProcessAllSections);
1136 Dyld->setRuntimeDyldChecker(Checker);
1140 static std::unique_ptr<RuntimeDyldELF>
1144 std::unique_ptr<RuntimeDyldELF> Dyld =
1146 Dyld->setProcessAllSections(ProcessAllSections);
1147 Dyld->setRuntimeDyldChecker(Checker);
1151 static std::unique_ptr<RuntimeDyldMachO>
1154 bool ProcessAllSections,
1156 std::unique_ptr<RuntimeDyldMachO> Dyld =
1158 Dyld->setProcessAllSections(ProcessAllSections);
1159 Dyld->setRuntimeDyldChecker(Checker);
1163 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
1169 MemMgr,
Resolver, ProcessAllSections, Checker);
1173 ProcessAllSections, Checker);
1177 ProcessAllSections, Checker);
1182 if (!Dyld->isCompatibleFile(Obj))
1185 auto LoadedObjInfo = Dyld->loadObject(Obj);
1187 return LoadedObjInfo;
1193 return Dyld->getSymbolLocalAddress(Name);
1199 return Dyld->getSymbol(Name);
1204 return std::map<StringRef, JITEvaluatedSymbol>();
1205 return Dyld->getSymbolTable();
1211 Dyld->reassignSectionAddress(SectionID, Addr);
1215 uint64_t TargetAddress) {
1216 Dyld->mapSectionAddress(LocalAddress, TargetAddress);
1224 bool MemoryFinalizationLocked = MemMgr.FinalizationLocked;
1225 MemMgr.FinalizationLocked =
true;
1228 if (!MemoryFinalizationLocked) {
1230 MemMgr.FinalizationLocked =
false;
1236 Dyld->registerEHFrames();
1241 Dyld->deregisterEHFrames();
std::map< StringRef, JITSymbolFlags > LookupFlagsResult
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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.
bool isCommon() const
Returns true if the Common flag is set.
Compute iterated dominance frontiers using a linear time algorithm.
StringRef getFileName() const
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
StringRef getErrorString()
unsigned computeGOTSize(const ObjectFile &Obj)
static bool isReadOnlyData(const SectionRef Section)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
iterator find(StringRef Key)
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...
uint8_t * getAddress() const
Error takeError()
Take ownership of the stored error.
std::set< StringRef > LookupSet
JITEvaluatedSymbol getSymbol(StringRef Name) const
Get the target address and flags for the named symbol.
uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const override
Obtain the Load Address of a section by SectionRef.
void deregisterEHFrames()
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).
static std::unique_ptr< RuntimeDyldELF > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
virtual basic_symbol_iterator symbol_begin() const =0
bool isWeak() const
Returns true if the Weak flag is set.
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
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.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
uint64_t getAddress() const
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)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
virtual ~RuntimeDyldImpl()
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
const ObjectFile * getObject() const
RuntimeDyld(MemoryManager &MemMgr, JITSymbolResolver &Resolver)
Construct a RuntimeDyld instance.
Instances of this class acquire a given Mutex Lock when constructed and hold that lock until destruct...
support::ulittle32_t Characteristics
uint64_t getFlags() const
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...
void * getSymbolLocalAddress(StringRef Name) const
Get the address of our local copy of the symbol.
* 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 ...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
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.
Symbol resolution interface.
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
virtual JITSymbolFlags getJITSymbolFlags(const BasicSymbolRef &Sym)
Generate JITSymbolFlags from a libObject symbol.
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
Expected< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isLittleEndian() const
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.
std::error_code getName(StringRef &Result) const
virtual Triple::ArchType getArch() const =0
std::error_code getContents(StringRef &Result) const
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Symbol info for RuntimeDyld.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
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.
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)
std::map< StringRef, JITEvaluatedSymbol > getSymbolTable() const
Returns a copy of the symbol table.
symbol_iterator_range symbols() const
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)
This is a value type class that represents a single symbol in the list of symbols in the object file...
uint64_t getLoadAddress() const
Expected< unsigned > emitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode)
Emits section data from the object file to the MemoryManager.
uint64_t getAlignment() const
Get the alignment of this section as the actual value (not log 2).
static std::unique_ptr< RuntimeDyldMachO > createRuntimeDyldMachO(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver, bool ProcessAllSections, RuntimeDyldCheckerImpl *Checker)
void resolveRelocations()
Resolve the relocations for all symbols we currently know about.
StringRef getName() const
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.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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...
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.
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...