32 #define DEBUG_TYPE "dyld" 37 GenericRTDyldError = 1
45 const char *
name()
const noexcept
override {
return "runtimedyld"; }
47 std::string message(
int Condition)
const override {
48 switch (static_cast<RuntimeDyldErrorCode>(Condition)) {
49 case GenericRTDyldError:
return "Generic RuntimeDyld error";
66 return std::error_code(GenericRTDyldError, *RTDyldErrorCategory);
80 MemMgr.deregisterEHFrames();
85 dbgs() <<
"----- Contents of section " << S.
getName() <<
" " << State
89 dbgs() <<
"\n <section not emitted>\n";
93 const unsigned ColsPerRow = 16;
98 unsigned StartPadding = LoadAddr & (ColsPerRow - 1);
99 unsigned BytesRemaining = S.
getSize();
103 LoadAddr & ~(uint64_t)(ColsPerRow - 1)) <<
":";
104 while (StartPadding--)
108 while (BytesRemaining > 0) {
109 if ((LoadAddr & (ColsPerRow - 1)) == 0)
110 dbgs() <<
"\n" <<
format(
"0x%016" PRIx64, LoadAddr) <<
":";
128 LLVM_DEBUG(
for (
int i = 0, e = Sections.size(); i != e; ++i)
132 if (
auto Err = resolveExternalSymbols()) {
134 ErrorStr =
toString(std::move(Err));
137 resolveLocalRelocations();
140 LLVM_DEBUG(
for (
int i = 0, e = Sections.size(); i != e; ++i)
146 for (
auto it = Relocations.begin(), e = Relocations.end(); it != e; ++it) {
151 uint64_t Addr = Sections[Idx].getLoadAddress();
152 LLVM_DEBUG(
dbgs() <<
"Resolving relocations Section #" << Idx <<
"\t" 153 <<
format(
"%p", (uintptr_t)Addr) <<
"\n");
154 resolveRelocationList(it->second, Addr);
160 uint64_t TargetAddress) {
162 for (
unsigned i = 0, e = Sections.size(); i != e; ++i) {
163 if (Sections[i].getAddress() == LocalAddress) {
164 reassignSectionAddress(i, TargetAddress);
191 if (MemMgr.needsToReserveAllocationSpace()) {
192 uint64_t CodeSize = 0, RODataSize = 0, RWDataSize = 0;
193 uint32_t CodeAlign = 1, RODataAlign = 1, RWDataAlign = 1;
194 if (
auto Err = computeTotalAllocSize(Obj,
196 RODataSize, RODataAlign,
197 RWDataSize, RWDataAlign))
198 return std::move(Err);
199 MemMgr.reserveAllocationSpace(CodeSize, CodeAlign, RODataSize, RODataAlign,
200 RWDataSize, RWDataAlign);
209 uint64_t CommonSize = 0;
217 for (
auto &Sym : Obj.
symbols()) {
221 if (
auto NameOrErr = Sym.getName())
222 Symbols.insert(*NameOrErr);
224 return NameOrErr.takeError();
228 if (
auto ResultOrErr =
Resolver.getResponsibilitySet(Symbols))
229 ResponsibilitySet = std::move(*ResultOrErr);
231 return ResultOrErr.takeError();
246 if (
auto SymTypeOrErr =
I->getType())
247 SymType = *SymTypeOrErr;
249 return SymTypeOrErr.takeError();
253 if (
auto NameOrErr =
I->getName())
256 return NameOrErr.takeError();
259 auto JITSymFlags = getJITSymbolFlags(*
I);
261 return JITSymFlags.takeError();
267 if (JITSymFlags->isWeak() || JITSymFlags->isCommon()) {
269 if (GlobalSymbolTable.count(Name))
273 if (!ResponsibilitySet.count(Name))
278 if (JITSymFlags->isWeak())
280 if (JITSymFlags->isCommon()) {
283 uint64_t
Size =
I->getCommonSize();
287 CommonSymbolsToAllocate.push_back(*
I);
294 if (
auto AddrOrErr =
I->getAddress())
297 return AddrOrErr.takeError();
299 unsigned SectionID = AbsoluteSymbolSection;
301 LLVM_DEBUG(
dbgs() <<
"\tType: " << SymType <<
" (absolute) Name: " << Name
302 <<
" SID: " << SectionID
303 <<
" Offset: " <<
format(
"%p", (uintptr_t)Addr)
304 <<
" flags: " << Flags <<
"\n");
312 if (
auto SIOrErr =
I->getSection())
315 return SIOrErr.takeError();
322 if (
auto Err =
getOffset(*
I, *SI, SectOffset))
323 return std::move(Err);
325 bool IsCode = SI->isText();
327 if (
auto SectionIDOrErr =
328 findOrEmitSection(Obj, *SI, IsCode, LocalSections))
329 SectionID = *SectionIDOrErr;
331 return SectionIDOrErr.takeError();
334 <<
" SID: " << SectionID
335 <<
" Offset: " <<
format(
"%p", (uintptr_t)SectOffset)
336 <<
" flags: " << Flags <<
"\n");
337 GlobalSymbolTable[
Name] =
343 if (
auto Err = emitCommonSymbols(Obj, CommonSymbolsToAllocate, CommonSize,
345 return std::move(Err);
354 if (RelocatedSection == SE)
360 if (I == E && !ProcessAllSections)
363 bool IsCode = RelocatedSection->isText();
364 unsigned SectionID = 0;
365 if (
auto SectionIDOrErr = findOrEmitSection(Obj, *RelocatedSection, IsCode,
367 SectionID = *SectionIDOrErr;
369 return SectionIDOrErr.takeError();
374 if (
auto IOrErr = processRelocationRef(SectionID, I, Obj, LocalSections, Stubs))
377 return IOrErr.takeError();
382 Checker->registerStubMap(Obj.
getFileName(), SectionID, Stubs);
386 if (
auto Err = finalizeLoad(Obj, LocalSections))
387 return std::move(Err);
392 return LocalSections;
400 uint64_t Alignment) {
401 uint64_t TotalSize = 0;
402 for (
size_t Idx = 0, Cnt = SectionSizes.size(); Idx < Cnt; Idx++) {
403 uint64_t AlignedSize =
404 (SectionSizes[Idx] + Alignment - 1) / Alignment * Alignment;
405 TotalSize += AlignedSize;
412 if (isa<object::ELFObjectFileBase>(Obj))
414 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj)) {
415 const coff_section *CoffSection = COFFObj->getCOFFSection(Section);
426 return HasContent && !IsDiscardable;
429 assert(isa<MachOObjectFile>(Obj));
435 if (isa<object::ELFObjectFileBase>(Obj))
438 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj))
439 return ((COFFObj->getCOFFSection(Section)->Characteristics &
447 assert(isa<MachOObjectFile>(Obj));
453 if (isa<object::ELFObjectFileBase>(Obj))
455 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj))
456 return COFFObj->getCOFFSection(Section)->Characteristics &
459 auto *MachO = cast<MachOObjectFile>(Obj);
460 unsigned SectionType = MachO->getSectionType(Section);
470 uint64_t &RODataSize,
472 uint64_t &RWDataSize,
475 std::vector<uint64_t> CodeSectionSizes;
476 std::vector<uint64_t> ROSectionSizes;
477 std::vector<uint64_t> RWSectionSizes;
489 uint64_t DataSize = Section.
getSize();
491 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
492 bool IsCode = Section.
isText();
496 if (
auto EC = Section.
getName(Name))
499 uint64_t StubBufSize = computeSectionStubBufSize(Obj, Section);
507 if (Name ==
".eh_frame")
514 CodeAlign =
std::max(CodeAlign, Alignment);
515 CodeSectionSizes.push_back(SectionSize);
516 }
else if (IsReadOnly) {
517 RODataAlign =
std::max(RODataAlign, Alignment);
518 ROSectionSizes.push_back(SectionSize);
520 RWDataAlign =
std::max(RWDataAlign, Alignment);
521 RWSectionSizes.push_back(SectionSize);
529 if (
unsigned GotSize = computeGOTSize(Obj)) {
530 RWSectionSizes.push_back(GotSize);
531 RWDataAlign = std::max<uint32_t>(RWDataAlign, getGOTEntrySize());
535 uint64_t CommonSize = 0;
542 uint64_t
Size =
I->getCommonSize();
551 if (CommonSize != 0) {
552 RWSectionSizes.push_back(CommonSize);
553 RWDataAlign =
std::max(RWDataAlign, CommonAlign);
570 size_t GotEntrySize = getGOTEntrySize();
579 if (relocationNeedsGot(Reloc))
580 GotSize += GotEntrySize;
589 unsigned StubSize = getMaxStubSize();
596 unsigned StubBufSize = 0;
600 if (!(RelSecI == Section))
604 if (relocationNeedsStub(Reloc))
605 StubBufSize += StubSize;
609 uint64_t DataSize = Section.
getSize();
613 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
614 unsigned StubAlignment = getStubAlignment();
615 unsigned EndAlignment = (DataSize | Alignment) & -(DataSize | Alignment);
616 if (StubAlignment > EndAlignment)
617 StubBufSize += StubAlignment - EndAlignment;
622 unsigned Size)
const {
624 if (IsTargetLittleEndian) {
627 Result = (Result << 8) | *Src--;
630 Result = (Result << 8) | *Src++;
636 unsigned Size)
const {
637 if (IsTargetLittleEndian) {
639 *Dst++ = Value & 0xFF;
645 *Dst-- = Value & 0xFF;
660 if (SymbolsToAllocate.empty())
664 unsigned SectionID = Sections.size();
665 uint8_t *Addr = MemMgr.allocateDataSection(CommonSize, CommonAlign, SectionID,
666 "<common symbols>",
false);
671 SectionEntry(
"<common symbols>", Addr, CommonSize, CommonSize, 0));
672 memset(Addr, 0, CommonSize);
675 <<
" new addr: " <<
format(
"%p", Addr)
676 <<
" DataSize: " << CommonSize <<
"\n");
679 for (
auto &Sym : SymbolsToAllocate) {
681 uint64_t
Size = Sym.getCommonSize();
683 if (
auto NameOrErr = Sym.getName())
686 return NameOrErr.takeError();
691 Offset += AlignOffset;
693 auto JITSymFlags = getJITSymbolFlags(Sym);
696 return JITSymFlags.takeError();
698 LLVM_DEBUG(
dbgs() <<
"Allocating common symbol " << Name <<
" address " 699 <<
format(
"%p", Addr) <<
"\n");
700 GlobalSymbolTable[
Name] =
707 Checker->registerSection(Obj.
getFileName(), SectionID);
719 unsigned Alignment = (
unsigned)Alignment64 & 0xffffffffL;
720 unsigned PaddingSize = 0;
721 unsigned StubBufSize = 0;
726 uint64_t DataSize = Section.
getSize();
729 if (
auto EC = Section.
getName(Name))
732 StubBufSize = computeSectionStubBufSize(Obj, Section);
737 if (Name ==
".eh_frame")
741 unsigned SectionID = Sections.size();
743 const char *pData =
nullptr;
747 if (!IsVirtual && !IsZeroInit) {
759 Alignment =
std::max(Alignment, getStubAlignment());
761 PaddingSize += getStubAlignment() - 1;
766 if (IsRequired || ProcessAllSections) {
767 Allocate = DataSize + PaddingSize + StubBufSize;
770 Addr = IsCode ? MemMgr.allocateCodeSection(Allocate, Alignment, SectionID,
772 : MemMgr.allocateDataSection(Allocate, Alignment, SectionID,
778 if (IsZeroInit || IsVirtual)
779 memset(Addr, 0, DataSize);
781 memcpy(Addr, pData, DataSize);
784 if (PaddingSize != 0) {
785 memset(Addr + DataSize, 0, PaddingSize);
787 DataSize += PaddingSize;
792 DataSize &= ~(getStubAlignment() - 1);
795 LLVM_DEBUG(
dbgs() <<
"emitSection SectionID: " << SectionID <<
" Name: " 796 << Name <<
" obj addr: " <<
format(
"%p", pData)
797 <<
" new addr: " <<
format(
"%p", Addr) <<
" DataSize: " 798 << DataSize <<
" StubBufSize: " << StubBufSize
799 <<
" Allocate: " << Allocate <<
"\n");
807 dbgs() <<
"emitSection SectionID: " << SectionID <<
" Name: " << Name
808 <<
" obj addr: " <<
format(
"%p", data.
data()) <<
" new addr: 0" 809 <<
" DataSize: " << DataSize <<
" StubBufSize: " << StubBufSize
810 <<
" Allocate: " << Allocate <<
"\n");
814 SectionEntry(Name, Addr, DataSize, Allocate, (uintptr_t)pData));
818 Sections.back().setLoadAddress(0);
821 Checker->registerSection(Obj.
getFileName(), SectionID);
832 unsigned SectionID = 0;
833 ObjSectionToIDMap::iterator i = LocalSections.find(Section);
834 if (i != LocalSections.end())
835 SectionID = i->second;
837 if (
auto SectionIDOrErr = emitSection(Obj, Section, IsCode))
838 SectionID = *SectionIDOrErr;
840 return SectionIDOrErr.takeError();
841 LocalSections[
Section] = SectionID;
847 unsigned SectionID) {
848 Relocations[SectionID].push_back(RE);
857 if (Loc == GlobalSymbolTable.end()) {
858 ExternalSymbolRelocations[
SymbolName].push_back(RE);
862 const auto &
SymInfo = Loc->second;
864 Relocations[
SymInfo.getSectionID()].push_back(RECopy);
869 unsigned AbiVariant) {
875 writeBytesUnaligned(0xd2e00010, Addr, 4);
876 writeBytesUnaligned(0xf2c00010, Addr+4, 4);
877 writeBytesUnaligned(0xf2a00010, Addr+8, 4);
878 writeBytesUnaligned(0xf2800010, Addr+12, 4);
879 writeBytesUnaligned(0xd61f0200, Addr+16, 4);
885 writeBytesUnaligned(0xe51ff004, Addr, 4);
887 }
else if (IsMipsO32ABI || IsMipsN32ABI) {
892 const unsigned LuiT9Instr = 0x3c190000, AdduiT9Instr = 0x27390000;
893 const unsigned NopInstr = 0x0;
894 unsigned JrT9Instr = 0x03200008;
897 JrT9Instr = 0x03200009;
899 writeBytesUnaligned(LuiT9Instr, Addr, 4);
900 writeBytesUnaligned(AdduiT9Instr, Addr + 4, 4);
901 writeBytesUnaligned(JrT9Instr, Addr + 8, 4);
902 writeBytesUnaligned(NopInstr, Addr + 12, 4);
904 }
else if (IsMipsN64ABI) {
913 const unsigned LuiT9Instr = 0x3c190000, DaddiuT9Instr = 0x67390000,
914 DsllT9Instr = 0x19CC38;
915 const unsigned NopInstr = 0x0;
916 unsigned JrT9Instr = 0x03200008;
918 JrT9Instr = 0x03200009;
920 writeBytesUnaligned(LuiT9Instr, Addr, 4);
921 writeBytesUnaligned(DaddiuT9Instr, Addr + 4, 4);
922 writeBytesUnaligned(DsllT9Instr, Addr + 8, 4);
923 writeBytesUnaligned(DaddiuT9Instr, Addr + 12, 4);
924 writeBytesUnaligned(DsllT9Instr, Addr + 16, 4);
925 writeBytesUnaligned(DaddiuT9Instr, Addr + 20, 4);
926 writeBytesUnaligned(JrT9Instr, Addr + 24, 4);
927 writeBytesUnaligned(NopInstr, Addr + 28, 4);
933 writeInt32BE(Addr, 0x3D800000);
934 writeInt32BE(Addr+4, 0x618C0000);
935 writeInt32BE(Addr+8, 0x798C07C6);
936 writeInt32BE(Addr+12, 0x658C0000);
937 writeInt32BE(Addr+16, 0x618C0000);
938 if (AbiVariant == 2) {
941 writeInt32BE(Addr+20, 0xF8410018);
942 writeInt32BE(Addr+24, 0x7D8903A6);
943 writeInt32BE(Addr+28, 0x4E800420);
948 writeInt32BE(Addr+20, 0xF8410028);
949 writeInt32BE(Addr+24, 0xE96C0000);
950 writeInt32BE(Addr+28, 0xE84C0008);
951 writeInt32BE(Addr+32, 0x7D6903A6);
952 writeInt32BE(Addr+36, 0xE96C0010);
953 writeInt32BE(Addr+40, 0x4E800420);
957 writeInt16BE(Addr, 0xC418);
958 writeInt16BE(Addr+2, 0x0000);
959 writeInt16BE(Addr+4, 0x0004);
960 writeInt16BE(Addr+6, 0x07F1);
988 dbgs() <<
"Reassigning address for section " << SectionID <<
" (" 989 << Sections[SectionID].
getName() <<
"): " 990 <<
format(
"0x%016" PRIx64, Sections[SectionID].getLoadAddress())
991 <<
" -> " <<
format(
"0x%016" PRIx64, Addr) <<
"\n");
992 Sections[SectionID].setLoadAddress(Addr);
997 for (
unsigned i = 0, e = Relocs.
size(); i != e; ++i) {
1000 if (Sections[RE.
SectionID].getAddress() ==
nullptr)
1002 resolveRelocation(RE, Value);
1008 while (!ExternalSymbolRelocations.empty()) {
1013 if (Name.
size() == 0) {
1018 resolveRelocationList(Relocs, 0);
1023 if (Loc == GlobalSymbolTable.end()) {
1024 auto RRI = ExternalSymbolMap.
find(Name);
1025 assert(RRI != ExternalSymbolMap.
end() &&
"No result for symbol");
1026 Addr = RRI->second.getAddress();
1027 Flags = RRI->second.getFlags();
1034 i = ExternalSymbolRelocations.find(Name);
1038 const auto &
SymInfo = Loc->second;
1039 Addr = getSectionLoadAddress(
SymInfo.getSectionID()) +
1047 "' which could not be resolved!");
1056 Addr = modifyAddressBasedOnFlags(Addr, Flags);
1058 LLVM_DEBUG(
dbgs() <<
"Resolving relocations Name: " << Name <<
"\t" 1059 <<
format(
"0x%lx", Addr) <<
"\n");
1063 resolveRelocationList(Relocs, Addr);
1067 ExternalSymbolRelocations.erase(i);
1082 for (
auto &RelocKV : ExternalSymbolRelocations) {
1084 if (!Name.
empty() && !GlobalSymbolTable.count(Name) &&
1085 !ResolvedSymbols.count(Name))
1086 NewSymbols.insert(Name);
1089 if (NewSymbols.empty())
1093 using ExpectedLookupResult =
1099 auto NewSymbolsP = std::make_shared<std::promise<ExpectedLookupResult>>();
1100 auto NewSymbolsF = NewSymbolsP->get_future();
1103 NewSymbolsP->set_value(std::move(Result));
1106 auto NewResolverResults = NewSymbolsF.get();
1108 if (!NewResolverResults)
1109 return NewResolverResults.takeError();
1111 assert(NewResolverResults->size() == NewSymbols.size() &&
1112 "Should have errored on unresolved symbols");
1114 for (
auto &RRKV : *NewResolverResults) {
1115 assert(!ResolvedSymbols.count(RRKV.first) &&
"Redundant resolution?");
1116 ExternalSymbolMap.
insert(RRKV);
1117 ResolvedSymbols.insert(RRKV.first);
1122 applyExternalSymbolRelocations(ExternalSymbolMap);
1129 std::unique_ptr<MemoryBuffer> UnderlyingBuffer) {
1133 auto SharedUnderlyingBuffer =
1134 std::shared_ptr<MemoryBuffer>(std::move(UnderlyingBuffer));
1135 auto SharedThis = std::shared_ptr<RuntimeDyldImpl>(std::move(This));
1136 auto PostResolveContinuation =
1137 [SharedThis, OnEmitted, SharedUnderlyingBuffer](
1140 OnEmitted(Result.takeError());
1146 for (
auto &KV : *Result)
1147 Resolved[KV.first] = KV.second;
1149 SharedThis->applyExternalSymbolRelocations(Resolved);
1150 SharedThis->resolveLocalRelocations();
1151 SharedThis->registerEHFrames();
1153 if (SharedThis->MemMgr.finalizeMemory(&ErrMsg))
1154 OnEmitted(make_error<StringError>(std::move(ErrMsg),
1162 for (
auto &RelocKV : SharedThis->ExternalSymbolRelocations) {
1165 assert(!SharedThis->GlobalSymbolTable.count(Name) &&
1166 "Name already processed. RuntimeDyld instances can not be re-used " 1167 "when finalizing with finalizeAsync.");
1168 Symbols.insert(Name);
1171 if (!Symbols.empty()) {
1172 SharedThis->Resolver.lookup(Symbols, PostResolveContinuation);
1174 PostResolveContinuation(std::map<StringRef, JITEvaluatedSymbol>());
1183 auto I = ObjSecToIDMap.find(Sec);
1184 if (
I != ObjSecToIDMap.end())
1185 return RTDyld.Sections[
I->second].getLoadAddress();
1190 void RuntimeDyld::MemoryManager::anchor() {}
1191 void JITSymbolResolver::anchor() {}
1192 void LegacyJITSymbolResolver::anchor() {}
1196 : MemMgr(MemMgr), Resolver(Resolver) {
1204 ProcessAllSections =
false;
1210 static std::unique_ptr<RuntimeDyldCOFF>
1214 std::unique_ptr<RuntimeDyldCOFF> Dyld =
1216 Dyld->setProcessAllSections(ProcessAllSections);
1217 Dyld->setRuntimeDyldChecker(Checker);
1221 static std::unique_ptr<RuntimeDyldELF>
1225 std::unique_ptr<RuntimeDyldELF> Dyld =
1227 Dyld->setProcessAllSections(ProcessAllSections);
1228 Dyld->setRuntimeDyldChecker(Checker);
1232 static std::unique_ptr<RuntimeDyldMachO>
1235 bool ProcessAllSections,
1237 std::unique_ptr<RuntimeDyldMachO> Dyld =
1239 Dyld->setProcessAllSections(ProcessAllSections);
1240 Dyld->setRuntimeDyldChecker(Checker);
1244 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
1250 MemMgr,
Resolver, ProcessAllSections, Checker);
1254 ProcessAllSections, Checker);
1258 ProcessAllSections, Checker);
1263 if (!Dyld->isCompatibleFile(Obj))
1266 auto LoadedObjInfo = Dyld->loadObject(Obj);
1268 return LoadedObjInfo;
1274 return Dyld->getSymbolLocalAddress(Name);
1280 return Dyld->getSymbol(Name);
1285 return std::map<StringRef, JITEvaluatedSymbol>();
1286 return Dyld->getSymbolTable();
1292 Dyld->reassignSectionAddress(SectionID, Addr);
1296 uint64_t TargetAddress) {
1297 Dyld->mapSectionAddress(LocalAddress, TargetAddress);
1305 bool MemoryFinalizationLocked = MemMgr.FinalizationLocked;
1306 MemMgr.FinalizationLocked =
true;
1309 if (!MemoryFinalizationLocked) {
1311 MemMgr.FinalizationLocked =
false;
1317 Dyld->registerEHFrames();
1322 Dyld->deregisterEHFrames();
1328 std::unique_ptr<MemoryBuffer> UnderlyingBuffer,
1332 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObj,
1333 std::map<StringRef, JITEvaluatedSymbol>)>
1349 OnEmitted(std::move(Err));
1352 std::move(UnderlyingBuffer));
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
friend void jitLinkForORC(object::ObjectFile &Obj, std::unique_ptr< MemoryBuffer > UnderlyingBuffer, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver, bool ProcessAllSections, std::function< Error(std::unique_ptr< LoadedObjectInfo >, std::map< StringRef, JITEvaluatedSymbol >)> OnLoaded, std::function< void(Error)> OnEmitted)
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.
This class represents lattice values for constants.
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.
static Expected< JITSymbolFlags > fromObjectSymbol(const object::SymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
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
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
unsigned SectionID
SectionID - the section this relocation points to.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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)
bool isText() const
Whether this section contains instructions.
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()
virtual Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &Sym)
Generate JITSymbolFlags from a libObject symbol.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
const ObjectFile * getObject() const
void setProcessAllSections(bool ProcessAllSections)
By default, only sections that are "required for execution" are passed to the RTDyldMemoryManager, and other sections are discarded.
Analysis containing CSE Info
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.
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
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
void applyExternalSymbolRelocations(const StringMap< JITEvaluatedSymbol > ExternalSymbolMap)
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)
void resolveLocalRelocations()
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)
static void finalizeAsync(std::unique_ptr< RuntimeDyldImpl > This, std::function< void(Error)> OnEmitted, std::unique_ptr< MemoryBuffer > UnderlyingBuffer)
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.
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)
print Print MemDeps of function
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...
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...