29#define DEBUG_TYPE "dyld"
34 or32le(L, (Imm & 0xFFF) << 10);
37template <
class T>
static void write(
bool isBE,
void *
P,
T V) {
38 isBE ? write<T, support::big>(
P, V) : write<T, support::little>(
P, V);
43 uint32_t ImmHi = (Imm & 0x1FFFFC) << 3;
44 uint64_t Mask = (0x3 << 29) | (0x1FFFFC << 3);
52 return (Val >> Start) & Mask;
57template <
class ELFT>
class DyldELFObject :
public ELFObjectFile<ELFT> {
60 typedef typename ELFT::uint addr_type;
78 return v->isDyldType();
90 this->isDyldELFObject =
true;
97 if (
auto E = Obj.takeError())
99 std::unique_ptr<DyldELFObject<ELFT>>
Ret(
100 new DyldELFObject<ELFT>(std::move(*Obj)));
101 return std::move(Ret);
105void DyldELFObject<ELFT>::updateSectionAddress(
const SectionRef &Sec,
109 const_cast<Elf_Shdr *
>(
reinterpret_cast<const Elf_Shdr *
>(ShdrRef.
p));
113 shdr->sh_addr =
static_cast<addr_type
>(
Addr);
117void DyldELFObject<ELFT>::updateSymbolAddress(
const SymbolRef &SymRef,
120 Elf_Sym *sym =
const_cast<Elf_Sym *
>(
125 sym->st_value =
static_cast<addr_type
>(
Addr);
128class LoadedELFObjectInfo final
130 RuntimeDyld::LoadedObjectInfo> {
132 LoadedELFObjectInfo(
RuntimeDyldImpl &RTDyld, ObjSectionToIDMap ObjSecToIDMap)
136 getObjectForDebug(
const ObjectFile &Obj)
const override;
139template <
typename ELFT>
142 const LoadedELFObjectInfo &L) {
143 typedef typename ELFT::Shdr Elf_Shdr;
144 typedef typename ELFT::uint addr_type;
147 DyldELFObject<ELFT>::create(Buffer);
151 std::unique_ptr<DyldELFObject<ELFT>> Obj = std::move(*ObjOrErr);
155 for (
const auto &Sec : Obj->sections()) {
162 if (*NameOrErr !=
"") {
164 Elf_Shdr *shdr =
const_cast<Elf_Shdr *
>(
165 reinterpret_cast<const Elf_Shdr *
>(ShdrRef.
p));
167 if (
uint64_t SecLoadAddr =
L.getSectionLoadAddress(*SI)) {
170 shdr->sh_addr =
static_cast<addr_type
>(SecLoadAddr);
176 return std::move(Obj);
180createELFDebugObject(
const ObjectFile &Obj,
const LoadedELFObjectInfo &L) {
183 std::unique_ptr<MemoryBuffer> Buffer =
190 createRTDyldELFObject<ELF32LE>(Buffer->getMemBufferRef(), Obj, L);
193 createRTDyldELFObject<ELF32BE>(Buffer->getMemBufferRef(), Obj, L);
196 createRTDyldELFObject<ELF64BE>(Buffer->getMemBufferRef(), Obj, L);
199 createRTDyldELFObject<ELF64LE>(Buffer->getMemBufferRef(), Obj, L);
208LoadedELFObjectInfo::getObjectForDebug(
const ObjectFile &Obj)
const {
209 return createELFDebugObject(Obj, *
this);
222 for (
int i = 0, e = UnregisteredEHFrameSections.
size(); i != e; ++i) {
223 SID EHFrameSID = UnregisteredEHFrameSections[i];
224 uint8_t *EHFrameAddr =
Sections[EHFrameSID].getAddress();
226 size_t EHFrameSize =
Sections[EHFrameSID].getSize();
229 UnregisteredEHFrameSections.
clear();
232std::unique_ptr<RuntimeDyldELF>
247std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
250 return std::make_unique<LoadedELFObjectInfo>(*
this, *ObjSectionToIDOrErr);
259void RuntimeDyldELF::resolveX86_64Relocation(
const SectionEntry &Section,
267 case ELF::R_X86_64_NONE:
269 case ELF::R_X86_64_8: {
272 uint8_t TruncatedAddr = (
Value & 0xFF);
273 *Section.getAddressWithOffset(
Offset) = TruncatedAddr;
275 <<
format(
"%p\n", Section.getAddressWithOffset(
Offset)));
278 case ELF::R_X86_64_16: {
285 <<
format(
"%p\n", Section.getAddressWithOffset(
Offset)));
288 case ELF::R_X86_64_64: {
295 case ELF::R_X86_64_32:
296 case ELF::R_X86_64_32S: {
299 (
Type == ELF::R_X86_64_32S &&
300 ((int64_t)
Value <= INT32_MAX && (int64_t)
Value >= INT32_MIN)));
308 case ELF::R_X86_64_PC8: {
310 int64_t RealOffset =
Value + Addend - FinalAddress;
311 assert(isInt<8>(RealOffset));
312 int8_t TruncOffset = (RealOffset & 0xFF);
316 case ELF::R_X86_64_PC32: {
318 int64_t RealOffset =
Value + Addend - FinalAddress;
319 assert(isInt<32>(RealOffset));
320 int32_t TruncOffset = (RealOffset & 0xFFFFFFFF);
325 case ELF::R_X86_64_PC64: {
327 int64_t RealOffset =
Value + Addend - FinalAddress;
331 <<
format(
"%p\n", FinalAddress));
334 case ELF::R_X86_64_GOTOFF64: {
337 for (
const auto &Section :
Sections) {
338 if (
Section.getName() ==
".got") {
339 GOTBase =
Section.getLoadAddressWithOffset(0);
343 assert(GOTBase != 0 &&
"missing GOT");
344 int64_t GOTOffset =
Value - GOTBase + Addend;
348 case ELF::R_X86_64_DTPMOD64: {
353 case ELF::R_X86_64_DTPOFF64:
354 case ELF::R_X86_64_TPOFF64: {
363 case ELF::R_X86_64_DTPOFF32:
364 case ELF::R_X86_64_TPOFF32: {
367 int64_t RealValue =
Value + Addend;
368 assert(RealValue >= INT32_MIN && RealValue <= INT32_MAX);
369 int32_t TruncValue = RealValue;
377void RuntimeDyldELF::resolveX86Relocation(
const SectionEntry &Section,
381 case ELF::R_386_32: {
388 case ELF::R_386_PLT32:
389 case ELF::R_386_PC32: {
405void RuntimeDyldELF::resolveAArch64Relocation(
const SectionEntry &Section,
416 <<
" FinalAddress: 0x" <<
format(
"%llx", FinalAddress)
417 <<
" Value: 0x" <<
format(
"%llx",
Value) <<
" Type: 0x"
419 <<
format(
"%llx", Addend) <<
"\n");
425 case ELF::R_AARCH64_NONE:
427 case ELF::R_AARCH64_ABS16: {
429 assert(
static_cast<int64_t
>(Result) >= INT16_MIN && Result < UINT16_MAX);
430 write(isBE, TargetPtr,
static_cast<uint16_t>(Result & 0xffffU));
433 case ELF::R_AARCH64_ABS32: {
435 assert(
static_cast<int64_t
>(Result) >= INT32_MIN && Result < UINT32_MAX);
436 write(isBE, TargetPtr,
static_cast<uint32_t>(Result & 0xffffffffU));
439 case ELF::R_AARCH64_ABS64:
442 case ELF::R_AARCH64_PLT32: {
444 assert(
static_cast<int64_t
>(Result) >= INT32_MIN &&
445 static_cast<int64_t
>(Result) <= INT32_MAX);
449 case ELF::R_AARCH64_PREL16: {
451 assert(
static_cast<int64_t
>(Result) >= INT16_MIN &&
452 static_cast<int64_t
>(Result) <= UINT16_MAX);
453 write(isBE, TargetPtr,
static_cast<uint16_t>(Result & 0xffffU));
456 case ELF::R_AARCH64_PREL32: {
458 assert(
static_cast<int64_t
>(Result) >= INT32_MIN &&
459 static_cast<int64_t
>(Result) <= UINT32_MAX);
460 write(isBE, TargetPtr,
static_cast<uint32_t>(Result & 0xffffffffU));
463 case ELF::R_AARCH64_PREL64:
464 write(isBE, TargetPtr,
Value + Addend - FinalAddress);
466 case ELF::R_AARCH64_CONDBR19: {
469 assert(isInt<21>(BranchImm));
470 *TargetPtr &= 0xff00001fU;
472 or32le(TargetPtr, (BranchImm & 0x001FFFFC) << 3);
475 case ELF::R_AARCH64_TSTBR14: {
478 assert(isInt<16>(BranchImm));
480 *TargetPtr &= 0xfff8001fU;
482 or32le(TargetPtr, (BranchImm & 0x0000FFFC) << 3);
485 case ELF::R_AARCH64_CALL26:
486 case ELF::R_AARCH64_JUMP26: {
492 assert(isInt<28>(BranchImm));
493 or32le(TargetPtr, (BranchImm & 0x0FFFFFFC) >> 2);
496 case ELF::R_AARCH64_MOVW_UABS_G3:
497 or32le(TargetPtr, ((
Value + Addend) & 0xFFFF000000000000) >> 43);
499 case ELF::R_AARCH64_MOVW_UABS_G2_NC:
500 or32le(TargetPtr, ((
Value + Addend) & 0xFFFF00000000) >> 27);
502 case ELF::R_AARCH64_MOVW_UABS_G1_NC:
503 or32le(TargetPtr, ((
Value + Addend) & 0xFFFF0000) >> 11);
505 case ELF::R_AARCH64_MOVW_UABS_G0_NC:
506 or32le(TargetPtr, ((
Value + Addend) & 0xFFFF) << 5);
508 case ELF::R_AARCH64_ADR_PREL_PG_HI21: {
511 ((
Value + Addend) & ~0xfffULL) - (FinalAddress & ~0xfffULL);
514 assert(isInt<33>(Result) &&
"overflow check failed for relocation");
521 case ELF::R_AARCH64_ADD_ABS_LO12_NC:
527 case ELF::R_AARCH64_LDST8_ABS_LO12_NC:
533 case ELF::R_AARCH64_LDST16_ABS_LO12_NC:
539 case ELF::R_AARCH64_LDST32_ABS_LO12_NC:
545 case ELF::R_AARCH64_LDST64_ABS_LO12_NC:
551 case ELF::R_AARCH64_LDST128_ABS_LO12_NC:
557 case ELF::R_AARCH64_LD_PREL_LO19: {
562 assert(isInt<21>(Result));
564 *TargetPtr &= 0xff00001fU;
567 *TargetPtr |= ((
Result & 0xffc) << (5 - 2));
570 case ELF::R_AARCH64_ADR_PREL_LO21: {
575 assert(isInt<21>(Result));
577 *TargetPtr &= 0x9f00001fU;
580 *TargetPtr |= ((
Result & 0xffc) << (5 - 2));
581 *TargetPtr |= (
Result & 0x3) << 29;
587void RuntimeDyldELF::resolveARMRelocation(
const SectionEntry &Section,
598 <<
" FinalAddress: " <<
format(
"%p", FinalAddress)
601 <<
" Addend: " <<
format(
"%x", Addend) <<
"\n");
607 case ELF::R_ARM_NONE:
610 case ELF::R_ARM_PREL31:
613 ((
Value - FinalAddress) & ~0x80000000);
615 case ELF::R_ARM_TARGET1:
616 case ELF::R_ARM_ABS32:
621 case ELF::R_ARM_MOVW_ABS_NC:
622 case ELF::R_ARM_MOVT_ABS:
623 if (
Type == ELF::R_ARM_MOVW_ABS_NC)
625 else if (
Type == ELF::R_ARM_MOVT_ABS)
629 (((
Value >> 12) & 0xF) << 16);
632 case ELF::R_ARM_PC24:
633 case ELF::R_ARM_CALL:
634 case ELF::R_ARM_JUMP24:
635 int32_t RelValue =
static_cast<int32_t
>(
Value - FinalAddress - 8);
636 RelValue = (RelValue & 0x03FFFFFC) >> 2;
644void RuntimeDyldELF::setMipsABI(
const ObjectFile &Obj) {
652 if (
auto *
E = dyn_cast<ELFObjectFileBase>(&Obj)) {
653 unsigned AbiVariant =
E->getPlatformFlags();
662 ObjSectionToIDMap &LocalSections,
674 for (
auto &Section : Obj.
sections()) {
684 if (
auto SectionIDOrErr =
688 return SectionIDOrErr.takeError();
703 ObjSectionToIDMap &LocalSections,
723 if (RelSectionName !=
".opd")
727 e = si->relocation_end();
732 if (TypeFunc != ELF::R_PPC64_ADDR64) {
737 uint64_t TargetSymbolOffset = i->getOffset();
740 if (
auto AddendOrErr = i->getAddend())
741 Addend = *AddendOrErr;
743 return AddendOrErr.takeError();
751 if (TypeTOC != ELF::R_PPC64_TOC)
757 if (Rel.
Addend != (int64_t)TargetSymbolOffset)
761 if (
auto TSIOrErr = TargetSymbol->
getSection())
764 return TSIOrErr.takeError();
767 bool IsCode = TSI->isText();
772 return SectionIDOrErr.takeError();
773 Rel.
Addend = (intptr_t)Addend;
788 return (
value >> 16) & 0xffff;
792 return ((
value + 0x8000) >> 16) & 0xffff;
796 return (
value >> 32) & 0xffff;
800 return ((
value + 0x8000) >> 32) & 0xffff;
804 return (
value >> 48) & 0xffff;
808 return ((
value + 0x8000) >> 48) & 0xffff;
811void RuntimeDyldELF::resolvePPC32Relocation(
const SectionEntry &Section,
814 uint8_t *LocalAddress = Section.getAddressWithOffset(
Offset);
819 case ELF::R_PPC_ADDR16_LO:
822 case ELF::R_PPC_ADDR16_HI:
825 case ELF::R_PPC_ADDR16_HA:
831void RuntimeDyldELF::resolvePPC64Relocation(
const SectionEntry &Section,
834 uint8_t *LocalAddress =
Section.getAddressWithOffset(
Offset);
839 case ELF::R_PPC64_ADDR16:
842 case ELF::R_PPC64_ADDR16_DS:
845 case ELF::R_PPC64_ADDR16_LO:
848 case ELF::R_PPC64_ADDR16_LO_DS:
851 case ELF::R_PPC64_ADDR16_HI:
852 case ELF::R_PPC64_ADDR16_HIGH:
855 case ELF::R_PPC64_ADDR16_HA:
856 case ELF::R_PPC64_ADDR16_HIGHA:
859 case ELF::R_PPC64_ADDR16_HIGHER:
862 case ELF::R_PPC64_ADDR16_HIGHERA:
865 case ELF::R_PPC64_ADDR16_HIGHEST:
868 case ELF::R_PPC64_ADDR16_HIGHESTA:
871 case ELF::R_PPC64_ADDR14: {
874 uint8_t aalk = *(LocalAddress + 3);
877 case ELF::R_PPC64_REL16_LO: {
882 case ELF::R_PPC64_REL16_HI: {
887 case ELF::R_PPC64_REL16_HA: {
892 case ELF::R_PPC64_ADDR32: {
893 int64_t
Result =
static_cast<int64_t
>(
Value + Addend);
894 if (SignExtend64<32>(Result) !=
Result)
898 case ELF::R_PPC64_REL24: {
900 int64_t delta =
static_cast<int64_t
>(
Value - FinalAddress + Addend);
901 if (SignExtend64<26>(delta) != delta)
905 writeInt32BE(LocalAddress, (Inst & 0xFC000003) | (delta & 0x03FFFFFC));
907 case ELF::R_PPC64_REL32: {
909 int64_t delta =
static_cast<int64_t
>(
Value - FinalAddress + Addend);
910 if (SignExtend64<32>(delta) != delta)
914 case ELF::R_PPC64_REL64: {
919 case ELF::R_PPC64_ADDR64:
925void RuntimeDyldELF::resolveSystemZRelocation(
const SectionEntry &Section,
928 uint8_t *LocalAddress =
Section.getAddressWithOffset(
Offset);
933 case ELF::R_390_PC16DBL:
934 case ELF::R_390_PLT16DBL: {
936 assert(int16_t(Delta / 2) * 2 == Delta &&
"R_390_PC16DBL overflow");
940 case ELF::R_390_PC32DBL:
941 case ELF::R_390_PLT32DBL: {
943 assert(int32_t(Delta / 2) * 2 == Delta &&
"R_390_PC32DBL overflow");
947 case ELF::R_390_PC16: {
949 assert(int16_t(Delta) == Delta &&
"R_390_PC16 overflow");
953 case ELF::R_390_PC32: {
955 assert(int32_t(Delta) == Delta &&
"R_390_PC32 overflow");
959 case ELF::R_390_PC64: {
965 *LocalAddress = (uint8_t)(
Value + Addend);
979void RuntimeDyldELF::resolveBPFRelocation(
const SectionEntry &Section,
988 case ELF::R_BPF_NONE:
989 case ELF::R_BPF_64_64:
990 case ELF::R_BPF_64_32:
991 case ELF::R_BPF_64_NODYLD32:
993 case ELF::R_BPF_64_ABS64: {
999 case ELF::R_BPF_64_ABS32: {
1037void RuntimeDyldELF::resolveRelocation(
const SectionEntry &Section,
1040 uint64_t SymOffset, SID SectionID) {
1043 resolveX86_64Relocation(Section,
Offset,
Value,
Type, Addend, SymOffset);
1080void *RuntimeDyldELF::computePlaceholderAddress(
unsigned SectionID,
uint64_t Offset)
const {
1086 if (
Value.SymbolName)
1093 bool IsLocal)
const {
1095 case ELF::R_MICROMIPS_GOT16:
1097 return ELF::R_MICROMIPS_LO16;
1099 case ELF::R_MICROMIPS_HI16:
1100 return ELF::R_MICROMIPS_LO16;
1101 case ELF::R_MIPS_GOT16:
1103 return ELF::R_MIPS_LO16;
1105 case ELF::R_MIPS_HI16:
1106 return ELF::R_MIPS_LO16;
1107 case ELF::R_MIPS_PCHI16:
1108 return ELF::R_MIPS_PCLO16;
1112 return ELF::R_MIPS_NONE;
1124bool RuntimeDyldELF::resolveAArch64ShortBranch(
1128 if (
Value.SymbolName) {
1135 const auto &
SymInfo = Loc->second;
1148 if (!isInt<28>(
Address +
Value.Addend - SourceAddress))
1157void RuntimeDyldELF::resolveAArch64Branch(
unsigned SectionID,
1162 LLVM_DEBUG(
dbgs() <<
"\t\tThis is an AArch64 branch relocation.");
1166 unsigned RelType = RelI->getType();
1168 StubMap::const_iterator i = Stubs.find(
Value);
1169 if (i != Stubs.end()) {
1170 resolveRelocation(Section,
Offset,
1174 }
else if (!resolveAArch64ShortBranch(SectionID, RelI,
Value)) {
1182 ELF::R_AARCH64_MOVW_UABS_G3,
Value.Addend);
1184 StubTargetAddr -
Section.getAddress() + 4,
1185 ELF::R_AARCH64_MOVW_UABS_G2_NC,
Value.Addend);
1187 StubTargetAddr -
Section.getAddress() + 8,
1188 ELF::R_AARCH64_MOVW_UABS_G1_NC,
Value.Addend);
1190 StubTargetAddr -
Section.getAddress() + 12,
1191 ELF::R_AARCH64_MOVW_UABS_G0_NC,
Value.Addend);
1193 if (
Value.SymbolName) {
1204 resolveRelocation(Section,
Offset,
1208 Section.advanceStubOffset(getMaxStubSize());
1216 const auto &Obj = cast<ELFObjectFileBase>(O);
1217 uint64_t RelType = RelI->getType();
1220 Addend = *AddendOrErr;
1228 if (
auto TargetNameOrErr = Symbol->getName())
1229 TargetName = *TargetNameOrErr;
1231 return TargetNameOrErr.takeError();
1233 LLVM_DEBUG(
dbgs() <<
"\t\tRelType: " << RelType <<
" Addend: " << Addend
1234 <<
" TargetName: " << TargetName <<
"\n");
1244 if (!SymTypeOrErr) {
1250 SymType = *SymTypeOrErr;
1253 const auto &
SymInfo = gsi->second;
1263 auto SectionOrErr = Symbol->getSection();
1264 if (!SectionOrErr) {
1274 bool isCode = si->isText();
1277 Value.SectionID = *SectionIDOrErr;
1279 return SectionIDOrErr.takeError();
1280 Value.Addend = Addend;
1288 Value.Addend = Addend;
1294 if (!
Value.SymbolName)
1295 Value.SymbolName =
"";
1309 if ((RelType == ELF::R_AARCH64_CALL26 ||
1310 RelType == ELF::R_AARCH64_JUMP26) &&
1312 resolveAArch64Branch(SectionID,
Value, RelI, Stubs);
1313 }
else if (RelType == ELF::R_AARCH64_ADR_GOT_PAGE) {
1316 uint64_t GOTOffset = findOrAllocGOTEntry(
Value, ELF::R_AARCH64_ABS64);
1317 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
1318 ELF::R_AARCH64_ADR_PREL_PG_HI21);
1320 }
else if (RelType == ELF::R_AARCH64_LD64_GOT_LO12_NC) {
1321 uint64_t GOTOffset = findOrAllocGOTEntry(
Value, ELF::R_AARCH64_ABS64);
1322 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
1323 ELF::R_AARCH64_LDST64_ABS_LO12_NC);
1325 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1328 if (RelType == ELF::R_ARM_PC24 || RelType == ELF::R_ARM_CALL ||
1329 RelType == ELF::R_ARM_JUMP24) {
1335 StubMap::const_iterator i = Stubs.find(
Value);
1336 if (i != Stubs.end()) {
1339 reinterpret_cast<uint64_t>(Section.getAddressWithOffset(i->second)),
1345 Stubs[
Value] = Section.getStubOffset();
1347 Section.getAddressWithOffset(Section.getStubOffset()));
1349 ELF::R_ARM_ABS32,
Value.Addend);
1350 if (
Value.SymbolName)
1356 Section.getAddressWithOffset(
1357 Section.getStubOffset())),
1359 Section.advanceStubOffset(getMaxStubSize());
1363 reinterpret_cast<uint32_t*
>(computePlaceholderAddress(SectionID,
Offset));
1364 if (RelType == ELF::R_ARM_PREL31 || RelType == ELF::R_ARM_TARGET1 ||
1365 RelType == ELF::R_ARM_ABS32) {
1366 Value.Addend += *Placeholder;
1367 }
else if (RelType == ELF::R_ARM_MOVW_ABS_NC || RelType == ELF::R_ARM_MOVT_ABS) {
1369 Value.Addend += (int16_t)((*Placeholder & 0xFFF) | (((*Placeholder >> 16) & 0xF) << 12));
1371 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1374 uint8_t *Placeholder =
reinterpret_cast<uint8_t *
>(
1375 computePlaceholderAddress(SectionID,
Offset));
1377 if (RelType == ELF::R_MIPS_26) {
1385 uint32_t Addend = (Opcode & 0x03ffffff) << 2;
1387 Value.Addend += Addend;
1390 StubMap::const_iterator i = Stubs.find(
Value);
1391 if (i != Stubs.end()) {
1398 Stubs[
Value] = Section.getStubOffset();
1403 Section.getAddressWithOffset(Section.getStubOffset()), AbiVariant);
1406 RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(),
1407 ELF::R_MIPS_HI16,
Value.Addend);
1409 StubTargetAddr - Section.getAddress() + 4,
1410 ELF::R_MIPS_LO16,
Value.Addend);
1412 if (
Value.SymbolName) {
1422 Section.advanceStubOffset(getMaxStubSize());
1424 }
else if (RelType == ELF::R_MIPS_HI16 || RelType == ELF::R_MIPS_PCHI16) {
1425 int64_t Addend = (Opcode & 0x0000ffff) << 16;
1427 PendingRelocs.push_back(std::make_pair(
Value, RE));
1428 }
else if (RelType == ELF::R_MIPS_LO16 || RelType == ELF::R_MIPS_PCLO16) {
1429 int64_t Addend =
Value.Addend + SignExtend32<16>(Opcode & 0x0000ffff);
1430 for (
auto I = PendingRelocs.begin();
I != PendingRelocs.end();) {
1433 if (MatchingValue ==
Value &&
1434 RelType == getMatchingLoRelocation(Reloc.
RelType) &&
1437 if (
Value.SymbolName)
1441 I = PendingRelocs.erase(
I);
1446 if (
Value.SymbolName)
1451 if (RelType == ELF::R_MIPS_32)
1452 Value.Addend += Opcode;
1453 else if (RelType == ELF::R_MIPS_PC16)
1454 Value.Addend += SignExtend32<18>((Opcode & 0x0000ffff) << 2);
1455 else if (RelType == ELF::R_MIPS_PC19_S2)
1456 Value.Addend += SignExtend32<21>((Opcode & 0x0007ffff) << 2);
1457 else if (RelType == ELF::R_MIPS_PC21_S2)
1458 Value.Addend += SignExtend32<23>((Opcode & 0x001fffff) << 2);
1459 else if (RelType == ELF::R_MIPS_PC26_S2)
1460 Value.Addend += SignExtend32<28>((Opcode & 0x03ffffff) << 2);
1461 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1466 if (r_type == ELF::R_MIPS_CALL16 || r_type == ELF::R_MIPS_GOT_PAGE
1467 || r_type == ELF::R_MIPS_GOT_DISP) {
1469 if (i != GOTSymbolOffsets.
end())
1473 GOTSymbolOffsets[TargetName] = RE.
SymOffset;
1475 if (
Value.SymbolName)
1479 }
else if (RelType == ELF::R_MIPS_26) {
1485 StubMap::const_iterator i = Stubs.find(
Value);
1486 if (i != Stubs.end()) {
1493 Stubs[
Value] = Section.getStubOffset();
1498 Section.getAddressWithOffset(Section.getStubOffset()), AbiVariant);
1502 RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(),
1503 ELF::R_MIPS_HI16,
Value.Addend);
1505 StubTargetAddr - Section.getAddress() + 4,
1506 ELF::R_MIPS_LO16,
Value.Addend);
1507 if (
Value.SymbolName) {
1518 StubTargetAddr - Section.getAddress(),
1519 ELF::R_MIPS_HIGHEST,
Value.Addend);
1521 StubTargetAddr - Section.getAddress() + 4,
1522 ELF::R_MIPS_HIGHER,
Value.Addend);
1524 StubTargetAddr - Section.getAddress() + 12,
1525 ELF::R_MIPS_HI16,
Value.Addend);
1527 StubTargetAddr - Section.getAddress() + 20,
1528 ELF::R_MIPS_LO16,
Value.Addend);
1529 if (
Value.SymbolName) {
1543 Section.advanceStubOffset(getMaxStubSize());
1546 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1550 if (RelType == ELF::R_PPC64_REL24) {
1559 uint8_t *
Target = Section.getAddressWithOffset(
Offset);
1560 bool RangeOverflow =
false;
1563 if (AbiVariant != 2) {
1567 if (
auto Err = findOPDEntrySection(Obj, ObjSectionToID,
Value))
1568 return std::move(Err);
1572 if (
Value.SectionID == SectionID){
1573 uint8_t SymOther = Symbol->getOther();
1577 uint8_t *RelocTarget =
1579 int64_t delta =
static_cast<int64_t
>(
Target - RelocTarget);
1581 if (SignExtend64<26>(delta) != delta) {
1582 RangeOverflow =
true;
1583 }
else if ((AbiVariant != 2) ||
1584 (AbiVariant == 2 &&
Value.SectionID == SectionID)) {
1589 if (IsExtern || (AbiVariant == 2 &&
Value.SectionID != SectionID) ||
1593 StubMap::const_iterator i = Stubs.find(
Value);
1594 if (i != Stubs.end()) {
1596 resolveRelocation(Section,
Offset,
1598 Section.getAddressWithOffset(i->second)),
1604 Stubs[
Value] = Section.getStubOffset();
1606 Section.getAddressWithOffset(Section.getStubOffset()),
1609 ELF::R_PPC64_ADDR64,
Value.Addend);
1615 uint64_t StubRelocOffset = StubTargetAddr - Section.getAddress();
1617 StubRelocOffset += 2;
1620 ELF::R_PPC64_ADDR16_HIGHEST,
Value.Addend);
1622 ELF::R_PPC64_ADDR16_HIGHER,
Value.Addend);
1624 ELF::R_PPC64_ADDR16_HI,
Value.Addend);
1626 ELF::R_PPC64_ADDR16_LO,
Value.Addend);
1628 if (
Value.SymbolName) {
1641 Section.getAddressWithOffset(
1642 Section.getStubOffset())),
1644 Section.advanceStubOffset(getMaxStubSize());
1646 if (IsExtern || (AbiVariant == 2 &&
Value.SectionID != SectionID)) {
1648 if (AbiVariant == 2)
1654 }
else if (RelType == ELF::R_PPC64_TOC16 ||
1655 RelType == ELF::R_PPC64_TOC16_DS ||
1656 RelType == ELF::R_PPC64_TOC16_LO ||
1657 RelType == ELF::R_PPC64_TOC16_LO_DS ||
1658 RelType == ELF::R_PPC64_TOC16_HI ||
1659 RelType == ELF::R_PPC64_TOC16_HA) {
1671 case ELF::R_PPC64_TOC16: RelType = ELF::R_PPC64_ADDR16;
break;
1672 case ELF::R_PPC64_TOC16_DS: RelType = ELF::R_PPC64_ADDR16_DS;
break;
1673 case ELF::R_PPC64_TOC16_LO: RelType = ELF::R_PPC64_ADDR16_LO;
break;
1674 case ELF::R_PPC64_TOC16_LO_DS: RelType = ELF::R_PPC64_ADDR16_LO_DS;
break;
1675 case ELF::R_PPC64_TOC16_HI: RelType = ELF::R_PPC64_ADDR16_HI;
break;
1676 case ELF::R_PPC64_TOC16_HA: RelType = ELF::R_PPC64_ADDR16_HA;
break;
1681 if (
auto Err = findPPC64TOCSection(Obj, ObjSectionToID, TOCValue))
1682 return std::move(Err);
1692 if (RelType == ELF::R_PPC64_TOC) {
1693 RelType = ELF::R_PPC64_ADDR64;
1694 if (
auto Err = findPPC64TOCSection(Obj, ObjSectionToID,
Value))
1695 return std::move(Err);
1696 }
else if (TargetName ==
".TOC.") {
1697 if (
auto Err = findPPC64TOCSection(Obj, ObjSectionToID,
Value))
1698 return std::move(Err);
1699 Value.Addend += Addend;
1704 if (
Value.SymbolName)
1710 (RelType == ELF::R_390_PLT32DBL || RelType == ELF::R_390_GOTENT)) {
1720 LLVM_DEBUG(
dbgs() <<
"\t\tThis is a SystemZ indirect relocation.");
1724 StubMap::const_iterator i = Stubs.find(
Value);
1725 uintptr_t StubAddress;
1726 if (i != Stubs.end()) {
1727 StubAddress = uintptr_t(Section.getAddressWithOffset(i->second));
1733 uintptr_t BaseAddress = uintptr_t(Section.getAddress());
1735 alignTo(BaseAddress + Section.getStubOffset(), getStubAlignment());
1736 unsigned StubOffset = StubAddress - BaseAddress;
1738 Stubs[
Value] = StubOffset;
1742 if (
Value.SymbolName)
1746 Section.advanceStubOffset(getMaxStubSize());
1749 if (RelType == ELF::R_390_GOTENT)
1750 resolveRelocation(Section,
Offset, StubAddress + 8, ELF::R_390_PC32DBL,
1753 resolveRelocation(Section,
Offset, StubAddress, RelType, Addend);
1755 if (RelType == ELF::R_X86_64_PLT32) {
1776 StubMap::const_iterator i = Stubs.find(
Value);
1777 uintptr_t StubAddress;
1778 if (i != Stubs.end()) {
1779 StubAddress = uintptr_t(Section->getAddress()) + i->second;
1785 uintptr_t BaseAddress = uintptr_t(Section->getAddress());
1786 StubAddress =
alignTo(BaseAddress + Section->getStubOffset(),
1787 getStubAlignment());
1788 unsigned StubOffset = StubAddress - BaseAddress;
1789 Stubs[
Value] = StubOffset;
1793 Section->advanceStubOffset(getMaxStubSize());
1796 uint64_t GOTOffset = allocateGOTEntries(1);
1802 resolveGOTOffsetRelocation(SectionID, StubOffset + 2, GOTOffset - 4,
1803 ELF::R_X86_64_PC32);
1807 computeGOTOffsetRE(GOTOffset, 0, ELF::R_X86_64_64),
1812 resolveRelocation(*Section,
Offset, StubAddress, ELF::R_X86_64_PC32,
1816 computePlaceholderAddress(SectionID,
Offset));
1817 processSimpleRelocation(SectionID,
Offset, ELF::R_X86_64_PC32,
Value);
1819 }
else if (RelType == ELF::R_X86_64_GOTPCREL ||
1820 RelType == ELF::R_X86_64_GOTPCRELX ||
1821 RelType == ELF::R_X86_64_REX_GOTPCRELX) {
1822 uint64_t GOTOffset = allocateGOTEntries(1);
1823 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
1824 ELF::R_X86_64_PC32);
1828 computeGOTOffsetRE(GOTOffset,
Value.Offset, ELF::R_X86_64_64);
1829 if (
Value.SymbolName)
1833 }
else if (RelType == ELF::R_X86_64_GOT64) {
1835 uint64_t GOTOffset = allocateGOTEntries(1);
1837 ELF::R_X86_64_64, 0);
1841 computeGOTOffsetRE(GOTOffset,
Value.Offset, ELF::R_X86_64_64);
1842 if (
Value.SymbolName)
1846 }
else if (RelType == ELF::R_X86_64_GOTPC32) {
1850 (void)allocateGOTEntries(0);
1851 resolveGOTOffsetRelocation(SectionID,
Offset, Addend, ELF::R_X86_64_PC32);
1852 }
else if (RelType == ELF::R_X86_64_GOTPC64) {
1853 (void)allocateGOTEntries(0);
1854 resolveGOTOffsetRelocation(SectionID,
Offset, Addend, ELF::R_X86_64_PC64);
1855 }
else if (RelType == ELF::R_X86_64_GOTOFF64) {
1857 (void)allocateGOTEntries(0);
1858 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1859 }
else if (RelType == ELF::R_X86_64_PC32) {
1861 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1862 }
else if (RelType == ELF::R_X86_64_PC64) {
1864 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1865 }
else if (RelType == ELF::R_X86_64_GOTTPOFF) {
1866 processX86_64GOTTPOFFRelocation(SectionID,
Offset,
Value, Addend);
1867 }
else if (RelType == ELF::R_X86_64_TLSGD ||
1868 RelType == ELF::R_X86_64_TLSLD) {
1871 auto &GetAddrRelocation = *RelI;
1872 processX86_64TLSRelocation(SectionID,
Offset, RelType,
Value, Addend,
1875 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1881 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1886void RuntimeDyldELF::processX86_64GOTTPOFFRelocation(
unsigned SectionID,
1897 struct CodeSequence {
1909 std::array<CodeSequence, 2> CodeSequences;
1913 static const std::initializer_list<uint8_t> ExpectedCodeSequenceList = {
1914 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00,
1916 0x48, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00
1919 CodeSequences[0].ExpectedCodeSequence =
1921 CodeSequences[0].TLSSequenceOffset = 12;
1923 static const std::initializer_list<uint8_t> NewCodeSequenceList = {
1924 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00,
1925 0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00
1928 CodeSequences[0].TpoffRelocationOffset = 12;
1933 static const std::initializer_list<uint8_t> ExpectedCodeSequenceList = {
1934 0x48, 0x8b, 0x05, 0x00, 0x00, 0x00, 0x00,
1935 0x64, 0x48, 0x8b, 0x00, 0x00, 0x00, 0x00
1937 CodeSequences[1].ExpectedCodeSequence =
1939 CodeSequences[1].TLSSequenceOffset = 3;
1941 static const std::initializer_list<uint8_t> NewCodeSequenceList = {
1942 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00,
1943 0x64, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00,
1946 CodeSequences[1].TpoffRelocationOffset = 10;
1951 for (
const auto &
C : CodeSequences) {
1952 assert(
C.ExpectedCodeSequence.size() ==
C.NewCodeSequence.size() &&
1953 "Old and new code sequences must have the same size");
1955 if (
Offset <
C.TLSSequenceOffset ||
1956 (
Offset -
C.TLSSequenceOffset +
C.NewCodeSequence.size()) >
1963 auto TLSSequenceStartOffset =
Offset -
C.TLSSequenceOffset;
1964 auto *TLSSequence =
Section.getAddressWithOffset(TLSSequenceStartOffset);
1966 C.ExpectedCodeSequence) {
1970 memcpy(TLSSequence,
C.NewCodeSequence.data(),
C.NewCodeSequence.size());
1977 TLSSequenceStartOffset +
C.TpoffRelocationOffset,
1978 ELF::R_X86_64_TPOFF32,
Value.Addend - Addend);
1980 if (
Value.SymbolName)
1993 uint64_t GOTOffset = allocateGOTEntries(1);
1994 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
1995 ELF::R_X86_64_PC32);
1997 computeGOTOffsetRE(GOTOffset,
Value.Offset, ELF::R_X86_64_TPOFF64);
1998 if (
Value.SymbolName)
2005void RuntimeDyldELF::processX86_64TLSRelocation(
2018 bool IsSmallCodeModel;
2020 bool IsGOTPCRel =
false;
2022 switch (GetAddrRelocation.
getType()) {
2023 case ELF::R_X86_64_GOTPCREL:
2024 case ELF::R_X86_64_REX_GOTPCRELX:
2025 case ELF::R_X86_64_GOTPCRELX:
2028 case ELF::R_X86_64_PLT32:
2029 IsSmallCodeModel =
true;
2031 case ELF::R_X86_64_PLTOFF64:
2032 IsSmallCodeModel =
false;
2036 "invalid TLS relocations for General/Local Dynamic TLS Model: "
2037 "expected PLT or GOT relocation for __tls_get_addr function");
2048 if (RelType == ELF::R_X86_64_TLSGD) {
2053 if (IsSmallCodeModel) {
2055 static const std::initializer_list<uint8_t> CodeSequence = {
2057 0x48, 0x8d, 0x3d, 0x00, 0x00,
2061 0xe8, 0x00, 0x00, 0x00, 0x00
2064 TLSSequenceOffset = 4;
2068 static const std::initializer_list<uint8_t> CodeSequence = {
2070 0x48, 0x8d, 0x3d, 0x00, 0x00,
2074 0xff, 0x15, 0x00, 0x00, 0x00,
2078 TLSSequenceOffset = 4;
2083 static const std::initializer_list<uint8_t> SmallSequence = {
2084 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00,
2086 0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00
2090 TpoffRelocOffset = 12;
2092 static const std::initializer_list<uint8_t> CodeSequence = {
2093 0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
2095 0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2101 TLSSequenceOffset = 3;
2104 static const std::initializer_list<uint8_t> LargeSequence = {
2105 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00,
2107 0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00,
2109 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00
2112 TpoffRelocOffset = 12;
2119 ELF::R_X86_64_TPOFF32,
Value.Addend - Addend);
2120 if (
Value.SymbolName)
2124 }
else if (RelType == ELF::R_X86_64_TLSLD) {
2125 if (IsSmallCodeModel) {
2127 static const std::initializer_list<uint8_t> CodeSequence = {
2128 0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00,
2129 0x00, 0xe8, 0x00, 0x00, 0x00, 0x00
2132 TLSSequenceOffset = 3;
2135 static const std::initializer_list<uint8_t> SmallSequence = {
2137 0x64, 0x48, 0x8b, 0x04, 0x25,
2138 0x00, 0x00, 0x00, 0x00
2144 static const std::initializer_list<uint8_t> CodeSequence = {
2145 0x48, 0x8d, 0x3d, 0x00,
2147 0xff, 0x15, 0x00, 0x00,
2152 TLSSequenceOffset = 3;
2156 static const std::initializer_list<uint8_t> SmallSequence = {
2157 0x0f, 0x1f, 0x40, 0x00,
2158 0x64, 0x48, 0x8b, 0x04, 0x25,
2159 0x00, 0x00, 0x00, 0x00
2166 static const std::initializer_list<uint8_t> CodeSequence = {
2167 0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
2169 0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2175 TLSSequenceOffset = 3;
2178 static const std::initializer_list<uint8_t> LargeSequence = {
2180 0x66, 0x66, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00,
2182 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00
2191 "Old and new code sequences must have the same size");
2194 if (
Offset < TLSSequenceOffset ||
2195 (
Offset - TLSSequenceOffset + NewCodeSequence.
size()) >
2200 auto *TLSSequence =
Section.getAddressWithOffset(
Offset - TLSSequenceOffset);
2202 ExpectedCodeSequence) {
2204 "invalid TLS sequence for Global/Local Dynamic TLS Model");
2207 memcpy(TLSSequence, NewCodeSequence.
data(), NewCodeSequence.
size());
2245uint64_t RuntimeDyldELF::allocateGOTEntries(
unsigned no) {
2246 if (GOTSectionID == 0) {
2253 CurrentGOTIndex += no;
2258 unsigned GOTRelType) {
2259 auto E = GOTOffsetMap.insert({
Value, 0});
2261 uint64_t GOTOffset = allocateGOTEntries(1);
2265 computeGOTOffsetRE(GOTOffset,
Value.Offset, GOTRelType);
2266 if (
Value.SymbolName)
2271 E.first->second = GOTOffset;
2274 return E.first->second;
2277void RuntimeDyldELF::resolveGOTOffsetRelocation(
unsigned SectionID,
2297 if (ObjSymbolFlags & SymbolRef::SF_Indirect) {
2298 if (IFuncStubSectionID == 0) {
2301 IFuncStubSectionID =
Sections.size();
2303 SectionEntry(
".text.__llvm_IFuncStubs",
nullptr, 0, 0, 0));
2305 IFuncStubOffset = 64;
2313 IFuncStubOffset += getMaxIFuncStubSize();
2320 if (!PendingRelocs.empty())
2321 return make_error<RuntimeDyldError>(
"Can't find matching LO16 reloc");
2325 if (IFuncStubSectionID != 0) {
2327 IFuncStubOffset, 1, IFuncStubSectionID,
".text.__llvm_IFuncStubs");
2328 if (!IFuncStubsAddr)
2329 return make_error<RuntimeDyldError>(
2330 "Unable to allocate memory for IFunc stubs!");
2332 SectionEntry(
".text.__llvm_IFuncStubs", IFuncStubsAddr, IFuncStubOffset,
2333 IFuncStubOffset, 0);
2335 createIFuncResolver(IFuncStubsAddr);
2338 << IFuncStubSectionID <<
" Addr: "
2339 <<
Sections[IFuncStubSectionID].getAddress() <<
'\n');
2340 for (
auto &IFuncStub : IFuncStubs) {
2341 auto &Symbol = IFuncStub.OriginalSymbol;
2343 <<
" Offset: " <<
format(
"%p", Symbol.getOffset())
2344 <<
" IFuncStubOffset: "
2345 <<
format(
"%p\n", IFuncStub.StubOffset));
2346 createIFuncStub(IFuncStubSectionID, 0, IFuncStub.StubOffset,
2347 Symbol.getSectionID(), Symbol.getOffset());
2350 IFuncStubSectionID = 0;
2351 IFuncStubOffset = 0;
2356 if (GOTSectionID != 0) {
2360 GOTSectionID,
".got",
false);
2362 return make_error<RuntimeDyldError>(
"Unable to allocate memory for GOT!");
2369 memset(
Addr, 0, TotalSize);
2375 if (
SI->relocation_begin() !=
SI->relocation_end()) {
2378 return make_error<RuntimeDyldError>(
2382 ObjSectionToIDMap::iterator i = SectionMap.find(*RelocatedSection);
2383 assert(i != SectionMap.end());
2387 GOTSymbolOffsets.
clear();
2392 ObjSectionToIDMap::iterator i, e;
2393 for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) {
2403 if (
Name ==
".eh_frame") {
2404 UnregisteredEHFrameSections.
push_back(i->second);
2410 CurrentGOTIndex = 0;
2419void RuntimeDyldELF::createIFuncResolver(uint8_t *
Addr)
const {
2431 const uint8_t StubCode[] = {
2439 0x41, 0xff, 0x53, 0x08,
2451 static_assert(
sizeof(StubCode) <= 64,
2452 "maximum size of the IFunc resolver is 64B");
2453 memcpy(
Addr, StubCode,
sizeof(StubCode));
2456 "IFunc resolver is not supported for target architecture");
2460void RuntimeDyldELF::createIFuncStub(
unsigned IFuncStubSectionID,
2463 unsigned IFuncSectionID,
2465 auto &IFuncStubSection =
Sections[IFuncStubSectionID];
2466 auto *
Addr = IFuncStubSection.getAddressWithOffset(IFuncStubOffset);
2490 uint64_t GOT1 = allocateGOTEntries(2);
2494 IFuncResolverOffset, {});
2496 RelocationEntry RE2(GOTSectionID, GOT2, ELF::R_X86_64_64, IFuncOffset, {});
2499 const uint8_t StubCode[] = {
2500 0x4c, 0x8d, 0x1d, 0x00, 0x00, 0x00, 0x00,
2503 assert(
sizeof(StubCode) <= getMaxIFuncStubSize() &&
2504 "IFunc stub size must not exceed getMaxIFuncStubSize()");
2505 memcpy(
Addr, StubCode,
sizeof(StubCode));
2509 resolveGOTOffsetRelocation(IFuncStubSectionID, IFuncStubOffset + 3,
2510 GOT1 - 4, ELF::R_X86_64_PC32);
2516unsigned RuntimeDyldELF::getMaxIFuncStubSize()
const {
2523bool RuntimeDyldELF::relocationNeedsGot(
const RelocationRef &R)
const {
2524 unsigned RelTy =
R.getType();
2526 return RelTy == ELF::R_AARCH64_ADR_GOT_PAGE ||
2527 RelTy == ELF::R_AARCH64_LD64_GOT_LO12_NC;
2530 return RelTy == ELF::R_X86_64_GOTPCREL ||
2531 RelTy == ELF::R_X86_64_GOTPCRELX ||
2532 RelTy == ELF::R_X86_64_GOT64 ||
2533 RelTy == ELF::R_X86_64_REX_GOTPCRELX;
2537bool RuntimeDyldELF::relocationNeedsStub(
const RelocationRef &R)
const {
2541 switch (
R.getType()) {
2546 case ELF::R_X86_64_GOTPCREL:
2547 case ELF::R_X86_64_GOTPCRELX:
2548 case ELF::R_X86_64_REX_GOTPCRELX:
2549 case ELF::R_X86_64_GOTPC64:
2550 case ELF::R_X86_64_GOT64:
2551 case ELF::R_X86_64_GOTOFF64:
2552 case ELF::R_X86_64_PC32:
2553 case ELF::R_X86_64_PC64:
2554 case ELF::R_X86_64_64:
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Given that RA is a live value
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
static void or32le(void *P, int32_t V)
static void or32AArch64Imm(void *L, uint64_t Imm)
static void write(bool isBE, void *P, T V)
static uint64_t getBits(uint64_t Val, int Start, int End)
static void write32AArch64Addr(void *L, uint64_t Imm)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
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.
Symbol resolution interface.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
RelocationEntry - used to represent relocations internally in the dynamic linker.
uint32_t RelType
RelType - relocation type.
uint64_t Offset
Offset - offset into the section.
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
unsigned SectionID
SectionID - the section this relocation points to.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
void registerEHFrames() override
size_t getGOTEntrySize() override
~RuntimeDyldELF() override
static std::unique_ptr< RuntimeDyldELF > create(Triple::ArchType Arch, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
Error finalizeLoad(const ObjectFile &Obj, ObjSectionToIDMap &SectionMap) override
DenseMap< SID, SID > SectionToGOTMap
bool isCompatibleFile(const object::ObjectFile &Obj) const override
std::unique_ptr< RuntimeDyld::LoadedObjectInfo > loadObject(const object::ObjectFile &O) override
RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
Expected< relocation_iterator > processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
std::map< SectionRef, unsigned > ObjSectionToIDMap
void writeInt32BE(uint8_t *Addr, uint32_t Value)
void writeInt64BE(uint8_t *Addr, uint64_t Value)
std::map< RelocationValueRef, uintptr_t > StubMap
void writeInt16BE(uint8_t *Addr, uint16_t Value)
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
bool IsTargetLittleEndian
RuntimeDyld::MemoryManager & MemMgr
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
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.
RTDyldSymbolTable GlobalSymbolTable
Expected< ObjSectionToIDMap > loadObjectImpl(const object::ObjectFile &Obj)
virtual uint8_t * allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, bool IsReadOnly)=0
Allocate a memory block of (at least) the given size suitable for data.
virtual uint8_t * allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName)=0
Allocate a memory block of (at least) the given size suitable for executable code.
virtual void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size)=0
Register the EH frames with the runtime so that c++ exceptions work.
virtual bool allowStubAllocation() const
Override to return false to tell LLVM no stub space will be needed.
SectionEntry - represents a section emitted into memory by the dynamic linker.
void push_back(const T &Elt)
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Symbol info for RuntimeDyld.
Target - Wrapper for Target specific information.
static StringRef getArchTypePrefix(ArchType Kind)
Get the "prefix" canonical name for the Kind architecture.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
Expected< uint32_t > getFlags() const
Get symbol flags (bitwise OR of SymbolRef::Flags)
DataRefImpl getRawDataRefImpl() const
StringRef getData() const
bool isLittleEndian() const
StringRef getFileName() const
virtual unsigned getPlatformFlags() const =0
Returns platform-specific object flags, if any.
static bool classof(const Binary *v)
Expected< const Elf_Sym * > getSymbol(DataRefImpl Sym) const
static Expected< ELFObjectFile< ELFT > > create(MemoryBufferRef Object, bool InitContent=true)
Expected< int64_t > getAddend() const
This class is the base class for all object file types.
virtual section_iterator section_end() const =0
virtual uint8_t getBytesInAddress() const =0
The number of bytes used to represent an address in this object file format.
section_iterator_range sections() const
virtual StringRef getFileFormatName() 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...
DataRefImpl getRawDataRefImpl() const
Expected< StringRef > getName() const
This is a value type class that represents a single symbol in the list of symbols in the object file.
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
virtual basic_symbol_iterator symbol_end() const =0
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
static int64_t decodePPC64LocalEntryOffset(unsigned Other)
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
@ Resolved
Queried, materialization begun.
void write32le(void *P, uint32_t V)
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs)
static uint16_t applyPPChighera(uint64_t value)
static uint16_t applyPPChi(uint64_t value)
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
static uint16_t applyPPChighesta(uint64_t value)
static uint16_t applyPPChighest(uint64_t value)
static uint16_t applyPPCha(uint64_t value)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
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...
static uint16_t applyPPClo(uint64_t value)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
static uint16_t applyPPChigher(uint64_t value)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
static void or32le(void *P, int32_t V)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void consumeError(Error Err)
Consume a Error without doing anything.
static void write32AArch64Addr(void *T, uint64_t s, uint64_t p, int shift)
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...