28#define DEBUG_TYPE "dyld"
36template <
class T>
static void write(
bool isBE,
void *
P,
T V) {
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;
62 DyldELFObject(ELFObjectFile<ELFT> &&Obj);
65 static Expected<std::unique_ptr<DyldELFObject>>
66 create(MemoryBufferRef
Wrapper);
68 void updateSectionAddress(
const SectionRef &Sec,
uint64_t Addr);
70 void updateSymbolAddress(
const SymbolRef &SymRef,
uint64_t Addr);
73 static bool classof(
const Binary *v) {
74 return (
isa<ELFObjectFile<ELFT>>(v) &&
75 classof(
cast<ELFObjectFile<ELFT>>(v)));
77 static bool classof(
const ELFObjectFile<ELFT> *v) {
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)
133 : LoadedObjectInfoHelper(RTDyld, std::
move(ObjSecToIDMap)) {}
135 OwningBinary<ObjectFile>
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) {
181 assert(
Obj.isELF() &&
"Not an ELF object file.");
183 std::unique_ptr<MemoryBuffer> Buffer =
188 if (
Obj.getBytesInAddress() == 4 &&
Obj.isLittleEndian())
190 createRTDyldELFObject<ELF32LE>(Buffer->getMemBufferRef(), Obj, L);
191 else if (
Obj.getBytesInAddress() == 4 && !
Obj.isLittleEndian())
193 createRTDyldELFObject<ELF32BE>(Buffer->getMemBufferRef(), Obj, L);
194 else if (
Obj.getBytesInAddress() == 8 && !
Obj.isLittleEndian())
196 createRTDyldELFObject<ELF64BE>(Buffer->getMemBufferRef(), Obj, L);
197 else if (
Obj.getBytesInAddress() == 8 &&
Obj.isLittleEndian())
199 createRTDyldELFObject<ELF64LE>(Buffer->getMemBufferRef(), Obj, L);
208LoadedELFObjectInfo::getObjectForDebug(
const ObjectFile &Obj)
const {
209 return createELFDebugObject(Obj, *
this);
222 for (
SID EHFrameSID : UnregisteredEHFrameSections) {
224 uint64_t EHFrameLoadAddr =
Sections[EHFrameSID].getLoadAddress();
225 size_t EHFrameSize =
Sections[EHFrameSID].getSize();
226 MemMgr.registerEHFrames(EHFrameAddr, EHFrameLoadAddr, EHFrameSize);
228 UnregisteredEHFrameSections.clear();
231std::unique_ptr<RuntimeDyldELF>
246std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
249 return std::make_unique<LoadedELFObjectInfo>(*
this, *ObjSectionToIDOrErr);
258void RuntimeDyldELF::resolveX86_64Relocation(
const SectionEntry &Section,
261 uint64_t SymOffset) {
266 case ELF::R_X86_64_NONE:
268 case ELF::R_X86_64_8: {
272 *Section.getAddressWithOffset(
Offset) = TruncatedAddr;
274 <<
format(
"%p\n", Section.getAddressWithOffset(
Offset)));
277 case ELF::R_X86_64_16: {
281 support::ulittle16_t::ref(Section.getAddressWithOffset(
Offset)) =
284 <<
format(
"%p\n", Section.getAddressWithOffset(
Offset)));
287 case ELF::R_X86_64_64: {
288 support::ulittle64_t::ref(
Section.getAddressWithOffset(
Offset)) =
294 case ELF::R_X86_64_32:
295 case ELF::R_X86_64_32S: {
298 (
Type == ELF::R_X86_64_32S &&
299 ((int64_t)
Value <= INT32_MAX && (int64_t)
Value >= INT32_MIN)));
300 uint32_t TruncatedAddr = (
Value & 0xFFFFFFFF);
301 support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset)) =
307 case ELF::R_X86_64_PC8: {
309 int64_t RealOffset =
Value + Addend - FinalAddress;
311 int8_t TruncOffset = (RealOffset & 0xFF);
315 case ELF::R_X86_64_PC32: {
317 int64_t RealOffset =
Value + Addend - FinalAddress;
319 int32_t TruncOffset = (RealOffset & 0xFFFFFFFF);
320 support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset)) =
324 case ELF::R_X86_64_PC64: {
326 int64_t RealOffset =
Value + Addend - FinalAddress;
327 support::ulittle64_t::ref(
Section.getAddressWithOffset(
Offset)) =
330 <<
format(
"%p\n", FinalAddress));
333 case ELF::R_X86_64_GOTOFF64: {
336 for (
const auto &Section :
Sections) {
337 if (
Section.getName() ==
".got") {
338 GOTBase =
Section.getLoadAddressWithOffset(0);
342 assert(GOTBase != 0 &&
"missing GOT");
343 int64_t GOTOffset =
Value - GOTBase + Addend;
344 support::ulittle64_t::ref(
Section.getAddressWithOffset(
Offset)) = GOTOffset;
347 case ELF::R_X86_64_DTPMOD64: {
349 support::ulittle64_t::ref(
Section.getAddressWithOffset(
Offset)) = 1;
352 case ELF::R_X86_64_DTPOFF64:
353 case ELF::R_X86_64_TPOFF64: {
358 support::ulittle64_t::ref(
Section.getAddressWithOffset(
Offset)) =
362 case ELF::R_X86_64_DTPOFF32:
363 case ELF::R_X86_64_TPOFF32: {
366 int64_t RealValue =
Value + Addend;
367 assert(RealValue >= INT32_MIN && RealValue <= INT32_MAX);
368 int32_t TruncValue = RealValue;
369 support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset)) =
376void RuntimeDyldELF::resolveX86Relocation(
const SectionEntry &Section,
378 uint32_t
Type, int32_t Addend) {
380 case ELF::R_386_32: {
381 support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset)) =
387 case ELF::R_386_PLT32:
388 case ELF::R_386_PC32: {
389 uint32_t FinalAddress =
391 uint32_t RealOffset =
Value + Addend - FinalAddress;
392 support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset)) =
404void RuntimeDyldELF::resolveAArch64Relocation(
const SectionEntry &Section,
406 uint32_t
Type, int64_t Addend) {
407 uint32_t *TargetPtr =
408 reinterpret_cast<uint32_t *
>(
Section.getAddressWithOffset(
Offset));
415 <<
" FinalAddress: 0x" <<
format(
"%llx", FinalAddress)
416 <<
" Value: 0x" <<
format(
"%llx",
Value) <<
" Type: 0x"
418 <<
format(
"%llx", Addend) <<
"\n");
424 case ELF::R_AARCH64_NONE:
426 case ELF::R_AARCH64_ABS16: {
429 (Result >> 16) == 0);
430 write(isBE, TargetPtr,
static_cast<uint16_t
>(Result & 0xffffU));
433 case ELF::R_AARCH64_ABS32: {
436 (Result >> 32) == 0);
437 write(isBE, TargetPtr,
static_cast<uint32_t
>(Result & 0xffffffffU));
440 case ELF::R_AARCH64_ABS64:
443 case ELF::R_AARCH64_PLT32: {
445 assert(
static_cast<int64_t
>(Result) >= INT32_MIN &&
446 static_cast<int64_t
>(Result) <= INT32_MAX);
447 write(isBE, TargetPtr,
static_cast<uint32_t
>(Result));
450 case ELF::R_AARCH64_PREL16: {
452 assert(
static_cast<int64_t
>(Result) >= INT16_MIN &&
453 static_cast<int64_t
>(Result) <= UINT16_MAX);
454 write(isBE, TargetPtr,
static_cast<uint16_t
>(Result & 0xffffU));
457 case ELF::R_AARCH64_PREL32: {
459 assert(
static_cast<int64_t
>(Result) >= INT32_MIN &&
460 static_cast<int64_t
>(Result) <= UINT32_MAX);
461 write(isBE, TargetPtr,
static_cast<uint32_t
>(Result & 0xffffffffU));
464 case ELF::R_AARCH64_PREL64:
465 write(isBE, TargetPtr,
Value + Addend - FinalAddress);
467 case ELF::R_AARCH64_CONDBR19: {
471 *TargetPtr &= 0xff00001fU;
473 or32le(TargetPtr, (BranchImm & 0x001FFFFC) << 3);
476 case ELF::R_AARCH64_TSTBR14: {
485 or32le(TargetPtr, (BranchImm & 0x0000FFFC) << 3);
488 case ELF::R_AARCH64_CALL26:
489 case ELF::R_AARCH64_JUMP26: {
496 or32le(TargetPtr, (BranchImm & 0x0FFFFFFC) >> 2);
499 case ELF::R_AARCH64_MOVW_UABS_G3:
500 or32le(TargetPtr, ((
Value + Addend) & 0xFFFF000000000000) >> 43);
502 case ELF::R_AARCH64_MOVW_UABS_G2_NC:
503 or32le(TargetPtr, ((
Value + Addend) & 0xFFFF00000000) >> 27);
505 case ELF::R_AARCH64_MOVW_UABS_G1_NC:
506 or32le(TargetPtr, ((
Value + Addend) & 0xFFFF0000) >> 11);
508 case ELF::R_AARCH64_MOVW_UABS_G0_NC:
509 or32le(TargetPtr, ((
Value + Addend) & 0xFFFF) << 5);
511 case ELF::R_AARCH64_ADR_PREL_PG_HI21: {
514 ((
Value + Addend) & ~0xfffULL) - (FinalAddress & ~0xfffULL);
524 case ELF::R_AARCH64_ADD_ABS_LO12_NC:
530 case ELF::R_AARCH64_LDST8_ABS_LO12_NC:
536 case ELF::R_AARCH64_LDST16_ABS_LO12_NC:
542 case ELF::R_AARCH64_LDST32_ABS_LO12_NC:
548 case ELF::R_AARCH64_LDST64_ABS_LO12_NC:
554 case ELF::R_AARCH64_LDST128_ABS_LO12_NC:
560 case ELF::R_AARCH64_LD_PREL_LO19: {
567 *TargetPtr &= 0xff00001fU;
570 *TargetPtr |= ((
Result & 0xffc) << (5 - 2));
573 case ELF::R_AARCH64_ADR_PREL_LO21: {
580 *TargetPtr &= 0x9f00001fU;
583 *TargetPtr |= ((
Result & 0xffc) << (5 - 2));
584 *TargetPtr |= (
Result & 0x3) << 29;
590void RuntimeDyldELF::resolveARMRelocation(
const SectionEntry &Section,
592 uint32_t
Type, int32_t Addend) {
594 uint32_t *TargetPtr =
595 reinterpret_cast<uint32_t *
>(
Section.getAddressWithOffset(
Offset));
596 uint32_t FinalAddress =
Section.getLoadAddressWithOffset(
Offset) & 0xFFFFFFFF;
601 <<
" FinalAddress: " <<
format(
"%p", FinalAddress)
604 <<
" Addend: " <<
format(
"%x", Addend) <<
"\n");
610 case ELF::R_ARM_NONE:
613 case ELF::R_ARM_PREL31:
614 support::ulittle32_t::ref{TargetPtr} =
615 (support::ulittle32_t::ref{TargetPtr} & 0x80000000) |
616 ((
Value - FinalAddress) & ~0x80000000);
618 case ELF::R_ARM_TARGET1:
619 case ELF::R_ARM_ABS32:
620 support::ulittle32_t::ref{TargetPtr} =
Value;
624 case ELF::R_ARM_MOVW_ABS_NC:
625 case ELF::R_ARM_MOVT_ABS:
626 if (
Type == ELF::R_ARM_MOVW_ABS_NC)
628 else if (
Type == ELF::R_ARM_MOVT_ABS)
630 support::ulittle32_t::ref{TargetPtr} =
631 (support::ulittle32_t::ref{TargetPtr} & ~0x000F0FFF) | (
Value & 0xFFF) |
632 (((
Value >> 12) & 0xF) << 16);
635 case ELF::R_ARM_PC24:
636 case ELF::R_ARM_CALL:
637 case ELF::R_ARM_JUMP24:
638 int32_t RelValue =
static_cast<int32_t
>(
Value - FinalAddress - 8);
639 RelValue = (RelValue & 0x03FFFFFC) >> 2;
640 assert((support::ulittle32_t::ref{TargetPtr} & 0xFFFFFF) == 0xFFFFFE);
641 support::ulittle32_t::ref{TargetPtr} =
642 (support::ulittle32_t::ref{TargetPtr} & 0xFF000000) | RelValue;
647bool RuntimeDyldELF::resolveLoongArch64ShortBranch(
651 if (
Value.SymbolName) {
656 const auto &SymInfo = Loc->second;
658 SymInfo.getOffset());
666 if (RelI->
getType() == ELF::R_LARCH_B26) {
682void RuntimeDyldELF::resolveLoongArch64Branch(
unsigned SectionID,
686 LLVM_DEBUG(
dbgs() <<
"\t\tThis is an LoongArch64 branch relocation.\n");
688 if (resolveLoongArch64ShortBranch(SectionID, RelI,
Value))
693 unsigned RelType = RelI->
getType();
697 resolveRelocation(Section,
Offset,
705 It->second =
Section.getStubOffset();
706 uint8_t *StubTargetAddr =
708 RelocationEntry LU12I_W(SectionID, StubTargetAddr -
Section.getAddress(),
709 ELF::R_LARCH_ABS_HI20,
Value.Addend);
710 RelocationEntry ORI(SectionID, StubTargetAddr -
Section.getAddress() + 4,
711 ELF::R_LARCH_ABS_LO12,
Value.Addend);
712 RelocationEntry LU32I_D(SectionID, StubTargetAddr -
Section.getAddress() + 8,
713 ELF::R_LARCH_ABS64_LO20,
Value.Addend);
714 RelocationEntry LU52I_D(SectionID, StubTargetAddr -
Section.getAddress() + 12,
715 ELF::R_LARCH_ABS64_HI12,
Value.Addend);
716 if (
Value.SymbolName) {
728 resolveRelocation(Section,
Offset,
737 return Hi == 63 ? Val >>
Lo : (Val & (((1ULL << (
Hi + 1)) - 1))) >>
Lo;
744 uint64_t pcalau12i_pc;
746 case ELF::R_LARCH_PCALA64_LO20:
747 case ELF::R_LARCH_GOT64_PC_LO20:
748 pcalau12i_pc = pc - 8;
750 case ELF::R_LARCH_PCALA64_HI12:
751 case ELF::R_LARCH_GOT64_PC_HI12:
752 pcalau12i_pc = pc - 12;
758 uint64_t result = (dest & ~0xfffULL) - (pcalau12i_pc & ~0xfffULL);
760 result += 0x1000 - 0x1'0000'0000;
761 if (result & 0x8000'0000)
762 result += 0x1'0000'0000;
766void RuntimeDyldELF::resolveLoongArch64Relocation(
const SectionEntry &Section,
770 auto *TargetPtr = Section.getAddressWithOffset(
Offset);
773 LLVM_DEBUG(
dbgs() <<
"resolveLoongArch64Relocation, LocalAddress: 0x"
775 <<
" FinalAddress: 0x" <<
format(
"%llx", FinalAddress)
776 <<
" Value: 0x" <<
format(
"%llx",
Value) <<
" Type: 0x"
778 <<
format(
"%llx", Addend) <<
"\n");
784 case ELF::R_LARCH_MARK_LA:
787 case ELF::R_LARCH_32:
788 support::ulittle32_t::ref{TargetPtr} =
789 static_cast<uint32_t
>(
Value + Addend);
791 case ELF::R_LARCH_64:
792 support::ulittle64_t::ref{TargetPtr} =
Value + Addend;
794 case ELF::R_LARCH_32_PCREL:
795 support::ulittle32_t::ref{TargetPtr} =
796 static_cast<uint32_t
>(
Value + Addend - FinalAddress);
798 case ELF::R_LARCH_B26: {
800 auto Instr = support::ulittle32_t::ref(TargetPtr);
803 Instr = (
Instr & 0xfc000000) | Imm15_0 | Imm25_16;
806 case ELF::R_LARCH_CALL36: {
808 auto Pcaddu18i = support::ulittle32_t::ref(TargetPtr);
811 Pcaddu18i = (Pcaddu18i & 0xfe00001f) | Imm35_16;
812 auto Jirl = support::ulittle32_t::ref(TargetPtr + 4);
813 uint32_t Imm15_0 =
extractBits(Call36, 15, 0) << 10;
814 Jirl = (Jirl & 0xfc0003ff) | Imm15_0;
817 case ELF::R_LARCH_GOT_PC_HI20:
818 case ELF::R_LARCH_PCALA_HI20: {
821 auto Instr = support::ulittle32_t::ref(TargetPtr);
822 uint32_t Imm31_12 =
extractBits(PageDelta, 31, 12) << 5;
826 case ELF::R_LARCH_GOT_PC_LO12:
827 case ELF::R_LARCH_PCALA_LO12: {
829 auto Instr = support::ulittle32_t::ref(TargetPtr);
830 uint32_t Imm11_0 = TargetOffset << 10;
834 case ELF::R_LARCH_GOT64_PC_LO20:
835 case ELF::R_LARCH_PCALA64_LO20: {
838 auto Instr = support::ulittle32_t::ref(TargetPtr);
839 uint32_t Imm51_32 =
extractBits(PageDelta, 51, 32) << 5;
843 case ELF::R_LARCH_GOT64_PC_HI12:
844 case ELF::R_LARCH_PCALA64_HI12: {
847 auto Instr = support::ulittle32_t::ref(TargetPtr);
848 uint32_t Imm63_52 =
extractBits(PageDelta, 63, 52) << 10;
852 case ELF::R_LARCH_ABS_HI20: {
854 auto Instr = support::ulittle32_t::ref(TargetPtr);
855 uint32_t Imm31_12 =
extractBits(Target, 31, 12) << 5;
859 case ELF::R_LARCH_ABS_LO12: {
861 auto Instr = support::ulittle32_t::ref(TargetPtr);
862 uint32_t Imm11_0 =
extractBits(Target, 11, 0) << 10;
866 case ELF::R_LARCH_ABS64_LO20: {
868 auto Instr = support::ulittle32_t::ref(TargetPtr);
869 uint32_t Imm51_32 =
extractBits(Target, 51, 32) << 5;
873 case ELF::R_LARCH_ABS64_HI12: {
875 auto Instr = support::ulittle32_t::ref(TargetPtr);
876 uint32_t Imm63_52 =
extractBits(Target, 63, 52) << 10;
880 case ELF::R_LARCH_ADD32:
881 support::ulittle32_t::ref{TargetPtr} =
882 (support::ulittle32_t::ref{TargetPtr} +
883 static_cast<uint32_t
>(
Value + Addend));
885 case ELF::R_LARCH_SUB32:
886 support::ulittle32_t::ref{TargetPtr} =
887 (support::ulittle32_t::ref{TargetPtr} -
888 static_cast<uint32_t
>(
Value + Addend));
890 case ELF::R_LARCH_ADD64:
891 support::ulittle64_t::ref{TargetPtr} =
892 (support::ulittle64_t::ref{TargetPtr} +
Value + Addend);
894 case ELF::R_LARCH_SUB64:
895 support::ulittle64_t::ref{TargetPtr} =
896 (support::ulittle64_t::ref{TargetPtr} -
Value - Addend);
901void RuntimeDyldELF::setMipsABI(
const ObjectFile &Obj) {
910 unsigned AbiVariant =
E->getPlatformFlags();
918Error RuntimeDyldELF::findPPC64TOCSection(
const ELFObjectFileBase &Obj,
919 ObjSectionToIDMap &LocalSections,
931 for (
auto &Section :
Obj.sections()) {
932 Expected<StringRef> NameOrErr =
Section.getName();
937 if (SectionName ==
".got"
938 || SectionName ==
".toc"
939 || SectionName ==
".tocbss"
940 || SectionName ==
".plt") {
941 if (
auto SectionIDOrErr =
945 return SectionIDOrErr.takeError();
959Error RuntimeDyldELF::findOPDEntrySection(
const ELFObjectFileBase &Obj,
960 ObjSectionToIDMap &LocalSections,
967 Expected<section_iterator> RelSecOrErr = si->getRelocatedSection();
972 if (RelSecI ==
Obj.section_end())
975 Expected<StringRef> NameOrErr = RelSecI->
getName();
978 StringRef RelSectionName = *NameOrErr;
980 if (RelSectionName !=
".opd")
983 for (elf_relocation_iterator i = si->relocation_begin(),
984 e = si->relocation_end();
989 if (TypeFunc != ELF::R_PPC64_ADDR64) {
994 uint64_t TargetSymbolOffset = i->getOffset();
995 symbol_iterator TargetSymbol = i->getSymbol();
997 if (
auto AddendOrErr = i->getAddend())
998 Addend = *AddendOrErr;
1000 return AddendOrErr.takeError();
1008 if (TypeTOC != ELF::R_PPC64_TOC)
1014 if (Rel.
Addend != (int64_t)TargetSymbolOffset)
1018 if (
auto TSIOrErr = TargetSymbol->
getSection())
1021 return TSIOrErr.takeError();
1022 assert(TSI !=
Obj.section_end() &&
"TSI should refer to a valid section");
1024 bool IsCode = TSI->
isText();
1029 return SectionIDOrErr.takeError();
1030 Rel.
Addend = (intptr_t)Addend;
1042static inline uint16_t
applyPPClo(uint64_t value) {
return value & 0xffff; }
1045 return (value >> 16) & 0xffff;
1049 return ((value + 0x8000) >> 16) & 0xffff;
1053 return (value >> 32) & 0xffff;
1057 return ((value + 0x8000) >> 32) & 0xffff;
1061 return (value >> 48) & 0xffff;
1065 return ((value + 0x8000) >> 48) & 0xffff;
1068void RuntimeDyldELF::resolvePPC32Relocation(
const SectionEntry &Section,
1071 uint8_t *LocalAddress = Section.getAddressWithOffset(
Offset);
1072 uint32_t FinalAddress = Section.getLoadAddressWithOffset(
Offset);
1077 case ELF::R_PPC_ADDR16_LO:
1080 case ELF::R_PPC_ADDR16_HI:
1083 case ELF::R_PPC_ADDR16_HA:
1086 case ELF::R_PPC_ADDR32:
1089 case ELF::R_PPC_REL16_LO:
1092 case ELF::R_PPC_REL16_HA:
1095 case ELF::R_PPC_REL24: {
1096 int32_t Delta =
static_cast<int32_t
>(
Value - FinalAddress + Addend);
1101 writeInt32BE(LocalAddress, (Inst & 0xFC000003) | (Delta & 0x03FFFFFC));
1103 case ELF::R_PPC_REL32:
1109void RuntimeDyldELF::resolvePPC64Relocation(
const SectionEntry &Section,
1111 uint32_t
Type, int64_t Addend) {
1112 uint8_t *LocalAddress =
Section.getAddressWithOffset(
Offset);
1117 case ELF::R_PPC64_ADDR16:
1120 case ELF::R_PPC64_ADDR16_DS:
1123 case ELF::R_PPC64_ADDR16_LO:
1126 case ELF::R_PPC64_ADDR16_LO_DS:
1129 case ELF::R_PPC64_ADDR16_HI:
1130 case ELF::R_PPC64_ADDR16_HIGH:
1133 case ELF::R_PPC64_ADDR16_HA:
1134 case ELF::R_PPC64_ADDR16_HIGHA:
1137 case ELF::R_PPC64_ADDR16_HIGHER:
1140 case ELF::R_PPC64_ADDR16_HIGHERA:
1143 case ELF::R_PPC64_ADDR16_HIGHEST:
1146 case ELF::R_PPC64_ADDR16_HIGHESTA:
1149 case ELF::R_PPC64_ADDR14: {
1152 uint8_t aalk = *(LocalAddress + 3);
1155 case ELF::R_PPC64_REL16_LO: {
1160 case ELF::R_PPC64_REL16_HI: {
1165 case ELF::R_PPC64_REL16_HA: {
1170 case ELF::R_PPC64_ADDR32: {
1171 int64_t
Result =
static_cast<int64_t
>(
Value + Addend);
1176 case ELF::R_PPC64_REL24: {
1178 int64_t delta =
static_cast<int64_t
>(
Value - FinalAddress + Addend);
1183 writeInt32BE(LocalAddress, (Inst & 0xFC000003) | (delta & 0x03FFFFFC));
1185 case ELF::R_PPC64_REL32: {
1187 int64_t delta =
static_cast<int64_t
>(
Value - FinalAddress + Addend);
1192 case ELF::R_PPC64_REL64: {
1197 case ELF::R_PPC64_ADDR64:
1203void RuntimeDyldELF::resolveSystemZRelocation(
const SectionEntry &Section,
1205 uint32_t
Type, int64_t Addend) {
1206 uint8_t *LocalAddress =
Section.getAddressWithOffset(
Offset);
1211 case ELF::R_390_PC16DBL:
1212 case ELF::R_390_PLT16DBL: {
1214 assert(int16_t(Delta / 2) * 2 == Delta &&
"R_390_PC16DBL overflow");
1218 case ELF::R_390_PC32DBL:
1219 case ELF::R_390_PLT32DBL: {
1221 assert(int32_t(Delta / 2) * 2 == Delta &&
"R_390_PC32DBL overflow");
1225 case ELF::R_390_PC16: {
1227 assert(int16_t(Delta) == Delta &&
"R_390_PC16 overflow");
1231 case ELF::R_390_PC32: {
1233 assert(int32_t(Delta) == Delta &&
"R_390_PC32 overflow");
1237 case ELF::R_390_PC64: {
1243 *LocalAddress = (uint8_t)(
Value + Addend);
1257void RuntimeDyldELF::resolveBPFRelocation(
const SectionEntry &Section,
1259 uint32_t
Type, int64_t Addend) {
1266 case ELF::R_BPF_NONE:
1267 case ELF::R_BPF_64_64:
1268 case ELF::R_BPF_64_32:
1269 case ELF::R_BPF_64_NODYLD32:
1271 case ELF::R_BPF_64_ABS64: {
1277 case ELF::R_BPF_64_ABS32: {
1290 auto Instr = support::ulittle32_t::ref(InstrAddr);
1291 Instr = (Instr & 0xfff) | UpperImm;
1296 auto Instr = support::ulittle32_t::ref(InstrAddr);
1297 Instr = (Instr & 0xfffff) | (LowerImm << 20);
1300void RuntimeDyldELF::resolveRISCVRelocation(
const SectionEntry &Section,
1306 std::string Err =
"Unimplemented reloc type: " + std::to_string(
Type);
1312 case ELF::R_RISCV_CALL:
1313 case ELF::R_RISCV_CALL_PLT: {
1321 case ELF::R_RISCV_HI20: {
1327 case ELF::R_RISCV_LO12_I: {
1333 case ELF::R_RISCV_GOT_HI20:
1334 case ELF::R_RISCV_PCREL_HI20: {
1348 case ELF::R_RISCV_PCREL_LO12_I: {
1349 for (
auto &&PendingReloc : PendingRelocs) {
1350 const RelocationValueRef &MatchingValue = PendingReloc.first;
1351 RelocationEntry &Reloc = PendingReloc.second;
1354 if (
Value + Addend == HIRelocPC) {
1357 auto PCOffset =
Symbol - HIRelocPC;
1364 "R_RISCV_PCREL_LO12_I without matching R_RISCV_PCREL_HI20");
1366 case ELF::R_RISCV_32_PCREL: {
1368 int64_t RealOffset =
Value + Addend - FinalAddress;
1369 int32_t TruncOffset =
Lo_32(RealOffset);
1370 support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset)) =
1374 case ELF::R_RISCV_32: {
1375 auto Ref = support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset));
1379 case ELF::R_RISCV_64: {
1380 auto Ref = support::ulittle64_t::ref(
Section.getAddressWithOffset(
Offset));
1384 case ELF::R_RISCV_ADD8: {
1389 case ELF::R_RISCV_ADD16: {
1390 auto Ref = support::ulittle16_t::ref(
Section.getAddressWithOffset(
Offset));
1394 case ELF::R_RISCV_ADD32: {
1395 auto Ref = support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset));
1399 case ELF::R_RISCV_ADD64: {
1400 auto Ref = support::ulittle64_t::ref(
Section.getAddressWithOffset(
Offset));
1404 case ELF::R_RISCV_SUB8: {
1409 case ELF::R_RISCV_SUB16: {
1410 auto Ref = support::ulittle16_t::ref(
Section.getAddressWithOffset(
Offset));
1414 case ELF::R_RISCV_SUB32: {
1415 auto Ref = support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset));
1419 case ELF::R_RISCV_SUB64: {
1420 auto Ref = support::ulittle64_t::ref(
Section.getAddressWithOffset(
Offset));
1424 case ELF::R_RISCV_SET8: {
1429 case ELF::R_RISCV_SET16: {
1430 auto Ref = support::ulittle16_t::ref(
Section.getAddressWithOffset(
Offset));
1434 case ELF::R_RISCV_SET32: {
1435 auto Ref = support::ulittle32_t::ref(
Section.getAddressWithOffset(
Offset));
1469void RuntimeDyldELF::resolveRelocation(
const SectionEntry &Section,
1472 uint64_t SymOffset,
SID SectionID) {
1475 resolveX86_64Relocation(Section,
Offset,
Value,
Type, Addend, SymOffset);
1512 resolveRISCVRelocation(Section,
Offset,
Value,
Type, Addend, SectionID);
1519void *RuntimeDyldELF::computePlaceholderAddress(
unsigned SectionID,
1525 RelocationEntry RE(SectionID,
Offset, RelType,
Value.Addend,
Value.Offset);
1526 if (
Value.SymbolName)
1532uint32_t RuntimeDyldELF::getMatchingLoRelocation(uint32_t RelType,
1533 bool IsLocal)
const {
1535 case ELF::R_MICROMIPS_GOT16:
1537 return ELF::R_MICROMIPS_LO16;
1539 case ELF::R_MICROMIPS_HI16:
1540 return ELF::R_MICROMIPS_LO16;
1541 case ELF::R_MIPS_GOT16:
1543 return ELF::R_MIPS_LO16;
1545 case ELF::R_MIPS_HI16:
1546 return ELF::R_MIPS_LO16;
1547 case ELF::R_MIPS_PCHI16:
1548 return ELF::R_MIPS_PCLO16;
1552 return ELF::R_MIPS_NONE;
1564bool RuntimeDyldELF::resolveAArch64ShortBranch(
1568 unsigned TargetSectionID;
1569 if (
Value.SymbolName) {
1576 const auto &SymInfo = Loc->second;
1578 TargetSectionID = SymInfo.getSectionID();
1579 TargetOffset = SymInfo.getOffset();
1581 TargetSectionID =
Value.SectionID;
1587 if (TargetSectionID != SectionID)
1598 RelocationEntry RE(SectionID, SourceOffset, RelI->
getType(),
Value.Addend);
1599 if (
Value.SymbolName)
1607void RuntimeDyldELF::resolveAArch64Branch(
unsigned SectionID,
1612 LLVM_DEBUG(
dbgs() <<
"\t\tThis is an AArch64 branch relocation.");
1616 unsigned RelType = RelI->
getType();
1618 StubMap::const_iterator i = Stubs.find(
Value);
1619 if (i != Stubs.end()) {
1620 resolveRelocation(Section,
Offset,
1621 Section.getLoadAddressWithOffset(i->second), RelType, 0);
1623 }
else if (!resolveAArch64ShortBranch(SectionID, RelI,
Value)) {
1630 RelocationEntry REmovz_g3(SectionID, StubTargetAddr -
Section.getAddress(),
1631 ELF::R_AARCH64_MOVW_UABS_G3,
Value.Addend);
1632 RelocationEntry REmovk_g2(SectionID,
1633 StubTargetAddr -
Section.getAddress() + 4,
1634 ELF::R_AARCH64_MOVW_UABS_G2_NC,
Value.Addend);
1635 RelocationEntry REmovk_g1(SectionID,
1636 StubTargetAddr -
Section.getAddress() + 8,
1637 ELF::R_AARCH64_MOVW_UABS_G1_NC,
Value.Addend);
1638 RelocationEntry REmovk_g0(SectionID,
1639 StubTargetAddr -
Section.getAddress() + 12,
1640 ELF::R_AARCH64_MOVW_UABS_G0_NC,
Value.Addend);
1642 if (
Value.SymbolName) {
1653 resolveRelocation(Section,
Offset,
1665 uint64_t RelType = RelI->
getType();
1668 Addend = *AddendOrErr;
1675 if (Symbol != Obj.symbol_end()) {
1676 if (
auto TargetNameOrErr = Symbol->getName())
1677 TargetName = *TargetNameOrErr;
1679 return TargetNameOrErr.takeError();
1681 LLVM_DEBUG(
dbgs() <<
"\t\tRelType: " << RelType <<
" Addend: " << Addend
1682 <<
" TargetName: " << TargetName <<
"\n");
1689 if (Symbol != Obj.symbol_end()) {
1692 if (!SymTypeOrErr) {
1698 SymType = *SymTypeOrErr;
1701 const auto &
SymInfo = gsi->second;
1711 auto SectionOrErr = Symbol->getSection();
1712 if (!SectionOrErr) {
1719 if (si == Obj.section_end())
1722 bool isCode = si->
isText();
1725 Value.SectionID = *SectionIDOrErr;
1727 return SectionIDOrErr.takeError();
1728 Value.Addend = Addend;
1736 Value.Addend = Addend;
1742 if (!
Value.SymbolName)
1743 Value.SymbolName =
"";
1757 if ((RelType == ELF::R_AARCH64_CALL26 ||
1758 RelType == ELF::R_AARCH64_JUMP26) &&
1759 MemMgr.allowStubAllocation()) {
1760 resolveAArch64Branch(SectionID,
Value, RelI, Stubs);
1761 }
else if (RelType == ELF::R_AARCH64_ADR_GOT_PAGE) {
1764 uint64_t GOTOffset = findOrAllocGOTEntry(
Value, ELF::R_AARCH64_ABS64);
1765 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
1766 ELF::R_AARCH64_ADR_PREL_PG_HI21);
1768 }
else if (RelType == ELF::R_AARCH64_LD64_GOT_LO12_NC) {
1769 uint64_t GOTOffset = findOrAllocGOTEntry(
Value, ELF::R_AARCH64_ABS64);
1770 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
1771 ELF::R_AARCH64_LDST64_ABS_LO12_NC);
1773 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1776 if (RelType == ELF::R_ARM_PC24 || RelType == ELF::R_ARM_CALL ||
1777 RelType == ELF::R_ARM_JUMP24) {
1783 auto [It, Inserted] = Stubs.try_emplace(
Value);
1785 resolveRelocation(Section,
Offset,
1786 Section.getLoadAddressWithOffset(It->second), RelType,
1792 It->second = Section.getStubOffset();
1794 Section.getAddressWithOffset(Section.getStubOffset()));
1796 ELF::R_ARM_ABS32,
Value.Addend);
1797 if (
Value.SymbolName)
1804 Section.getLoadAddressWithOffset(Section.getStubOffset()), RelType,
1810 reinterpret_cast<uint32_t*
>(computePlaceholderAddress(SectionID,
Offset));
1811 if (RelType == ELF::R_ARM_PREL31 || RelType == ELF::R_ARM_TARGET1 ||
1812 RelType == ELF::R_ARM_ABS32) {
1813 Value.Addend += *Placeholder;
1814 }
else if (RelType == ELF::R_ARM_MOVW_ABS_NC || RelType == ELF::R_ARM_MOVT_ABS) {
1816 Value.Addend += (int16_t)((*Placeholder & 0xFFF) | (((*Placeholder >> 16) & 0xF) << 12));
1818 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1821 if ((RelType == ELF::R_LARCH_B26 || RelType == ELF::R_LARCH_CALL36) &&
1822 MemMgr.allowStubAllocation()) {
1823 resolveLoongArch64Branch(SectionID,
Value, RelI, Stubs);
1824 }
else if (RelType == ELF::R_LARCH_GOT_PC_HI20 ||
1825 RelType == ELF::R_LARCH_GOT_PC_LO12 ||
1826 RelType == ELF::R_LARCH_GOT64_PC_HI12 ||
1827 RelType == ELF::R_LARCH_GOT64_PC_LO20) {
1828 uint64_t GOTOffset = findOrAllocGOTEntry(
Value, ELF::R_LARCH_64);
1829 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
1832 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1836 computePlaceholderAddress(SectionID,
Offset));
1838 if (RelType == ELF::R_MIPS_26) {
1846 uint32_t Addend = (Opcode & 0x03ffffff) << 2;
1848 Value.Addend += Addend;
1851 auto [It, Inserted] = Stubs.try_emplace(
Value);
1859 It->second = Section.getStubOffset();
1861 unsigned AbiVariant = Obj.getPlatformFlags();
1864 Section.getAddressWithOffset(Section.getStubOffset()), AbiVariant);
1867 RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(),
1868 ELF::R_MIPS_HI16,
Value.Addend);
1870 StubTargetAddr - Section.getAddress() + 4,
1871 ELF::R_MIPS_LO16,
Value.Addend);
1873 if (
Value.SymbolName) {
1885 }
else if (RelType == ELF::R_MIPS_HI16 || RelType == ELF::R_MIPS_PCHI16) {
1886 int64_t Addend = (Opcode & 0x0000ffff) << 16;
1888 PendingRelocs.push_back(std::make_pair(
Value, RE));
1889 }
else if (RelType == ELF::R_MIPS_LO16 || RelType == ELF::R_MIPS_PCLO16) {
1891 for (
auto I = PendingRelocs.begin();
I != PendingRelocs.end();) {
1894 if (MatchingValue ==
Value &&
1895 RelType == getMatchingLoRelocation(
Reloc.RelType) &&
1896 SectionID ==
Reloc.SectionID) {
1897 Reloc.Addend += Addend;
1898 if (
Value.SymbolName)
1902 I = PendingRelocs.erase(
I);
1907 if (
Value.SymbolName)
1912 if (RelType == ELF::R_MIPS_32)
1913 Value.Addend += Opcode;
1914 else if (RelType == ELF::R_MIPS_PC16)
1916 else if (RelType == ELF::R_MIPS_PC19_S2)
1918 else if (RelType == ELF::R_MIPS_PC21_S2)
1920 else if (RelType == ELF::R_MIPS_PC26_S2)
1922 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
1927 if (r_type == ELF::R_MIPS_CALL16 || r_type == ELF::R_MIPS_GOT_PAGE
1928 || r_type == ELF::R_MIPS_GOT_DISP) {
1929 auto [
I, Inserted] = GOTSymbolOffsets.try_emplace(TargetName);
1931 I->second = allocateGOTEntries(1);
1933 if (
Value.SymbolName)
1937 }
else if (RelType == ELF::R_MIPS_26) {
1943 StubMap::const_iterator i = Stubs.find(
Value);
1944 if (i != Stubs.end()) {
1951 Stubs[
Value] = Section.getStubOffset();
1953 unsigned AbiVariant = Obj.getPlatformFlags();
1956 Section.getAddressWithOffset(Section.getStubOffset()), AbiVariant);
1960 RelocationEntry REHi(SectionID, StubTargetAddr - Section.getAddress(),
1961 ELF::R_MIPS_HI16,
Value.Addend);
1963 StubTargetAddr - Section.getAddress() + 4,
1964 ELF::R_MIPS_LO16,
Value.Addend);
1965 if (
Value.SymbolName) {
1976 StubTargetAddr - Section.getAddress(),
1977 ELF::R_MIPS_HIGHEST,
Value.Addend);
1979 StubTargetAddr - Section.getAddress() + 4,
1980 ELF::R_MIPS_HIGHER,
Value.Addend);
1982 StubTargetAddr - Section.getAddress() + 12,
1983 ELF::R_MIPS_HI16,
Value.Addend);
1985 StubTargetAddr - Section.getAddress() + 20,
1986 ELF::R_MIPS_LO16,
Value.Addend);
1987 if (
Value.SymbolName) {
2004 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
2008 if (RelType == ELF::R_PPC_PLTREL24) {
2011 Value.Addend -= Addend;
2012 RelType = ELF::R_PPC_REL24;
2017 bool NeedsStub = RelType == ELF::R_PPC_REL24 &&
2018 (
Value.SymbolName ||
2021 Section.getAddressWithOffset(
Offset)));
2023 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
2025 auto [It, Inserted] = Stubs.try_emplace(
Value, Section.getStubOffset());
2029 processSimpleRelocation(SectionID, It->second + 2, ELF::R_PPC_ADDR16_HI,
2031 processSimpleRelocation(SectionID, It->second + 6, ELF::R_PPC_ADDR16_LO,
2035 resolveRelocation(Section,
Offset,
2036 Section.getLoadAddressWithOffset(It->second), RelType,
2040 if (RelType == ELF::R_PPC64_REL24) {
2042 unsigned AbiVariant = Obj.getPlatformFlags();
2050 bool RangeOverflow =
false;
2053 if (AbiVariant != 2) {
2057 if (
auto Err = findOPDEntrySection(Obj, ObjSectionToID,
Value))
2058 return std::move(Err);
2062 if (
Value.SectionID == SectionID){
2063 uint8_t SymOther = Symbol->getOther();
2069 int64_t delta =
static_cast<int64_t
>(
Target - RelocTarget);
2072 RangeOverflow =
true;
2073 }
else if ((AbiVariant != 2) ||
2074 (AbiVariant == 2 &&
Value.SectionID == SectionID)) {
2079 if (IsExtern || (AbiVariant == 2 &&
Value.SectionID != SectionID) ||
2083 auto [It, Inserted] = Stubs.try_emplace(
Value);
2086 resolveRelocation(Section,
Offset,
2087 Section.getLoadAddressWithOffset(It->second),
2093 It->second = Section.getStubOffset();
2095 Section.getAddressWithOffset(Section.getStubOffset()),
2098 ELF::R_PPC64_ADDR64,
Value.Addend);
2104 uint64_t StubRelocOffset = StubTargetAddr - Section.getAddress();
2106 StubRelocOffset += 2;
2109 ELF::R_PPC64_ADDR16_HIGHEST,
Value.Addend);
2111 ELF::R_PPC64_ADDR16_HIGHER,
Value.Addend);
2113 ELF::R_PPC64_ADDR16_HI,
Value.Addend);
2115 ELF::R_PPC64_ADDR16_LO,
Value.Addend);
2117 if (
Value.SymbolName) {
2131 Section.getLoadAddressWithOffset(Section.getStubOffset()),
2135 if (IsExtern || (AbiVariant == 2 &&
Value.SectionID != SectionID)) {
2137 if (AbiVariant == 2)
2143 }
else if (RelType == ELF::R_PPC64_TOC16 ||
2144 RelType == ELF::R_PPC64_TOC16_DS ||
2145 RelType == ELF::R_PPC64_TOC16_LO ||
2146 RelType == ELF::R_PPC64_TOC16_LO_DS ||
2147 RelType == ELF::R_PPC64_TOC16_HI ||
2148 RelType == ELF::R_PPC64_TOC16_HA) {
2160 case ELF::R_PPC64_TOC16: RelType = ELF::R_PPC64_ADDR16;
break;
2161 case ELF::R_PPC64_TOC16_DS: RelType = ELF::R_PPC64_ADDR16_DS;
break;
2162 case ELF::R_PPC64_TOC16_LO: RelType = ELF::R_PPC64_ADDR16_LO;
break;
2163 case ELF::R_PPC64_TOC16_LO_DS: RelType = ELF::R_PPC64_ADDR16_LO_DS;
break;
2164 case ELF::R_PPC64_TOC16_HI: RelType = ELF::R_PPC64_ADDR16_HI;
break;
2165 case ELF::R_PPC64_TOC16_HA: RelType = ELF::R_PPC64_ADDR16_HA;
break;
2170 if (
auto Err = findPPC64TOCSection(Obj, ObjSectionToID, TOCValue))
2171 return std::move(Err);
2181 if (RelType == ELF::R_PPC64_TOC) {
2182 RelType = ELF::R_PPC64_ADDR64;
2183 if (
auto Err = findPPC64TOCSection(Obj, ObjSectionToID,
Value))
2184 return std::move(Err);
2185 }
else if (TargetName ==
".TOC.") {
2186 if (
auto Err = findPPC64TOCSection(Obj, ObjSectionToID,
Value))
2187 return std::move(Err);
2188 Value.Addend += Addend;
2193 if (
Value.SymbolName)
2199 (RelType == ELF::R_390_PLT32DBL || RelType == ELF::R_390_GOTENT)) {
2209 LLVM_DEBUG(
dbgs() <<
"\t\tThis is a SystemZ indirect relocation.");
2213 StubMap::const_iterator i = Stubs.find(
Value);
2215 if (i != Stubs.end()) {
2216 StubAddress =
uintptr_t(Section.getAddressWithOffset(i->second));
2224 alignTo(BaseAddress + Section.getStubOffset(), getStubAlignment());
2225 unsigned StubOffset = StubAddress - BaseAddress;
2227 Stubs[
Value] = StubOffset;
2231 if (
Value.SymbolName)
2238 if (RelType == ELF::R_390_GOTENT)
2239 resolveRelocation(Section,
Offset, StubAddress + 8, ELF::R_390_PC32DBL,
2242 resolveRelocation(Section,
Offset, StubAddress, RelType, Addend);
2244 if (RelType == ELF::R_X86_64_PLT32) {
2261 if (
Value.SymbolName &&
MemMgr.allowStubAllocation()) {
2265 auto [It, Inserted] = Stubs.try_emplace(
Value);
2268 StubAddress =
uintptr_t(Section->getAddress()) + It->second;
2275 StubAddress =
alignTo(BaseAddress + Section->getStubOffset(),
2276 getStubAlignment());
2277 unsigned StubOffset = StubAddress - BaseAddress;
2278 It->second = StubOffset;
2285 uint64_t GOTOffset = allocateGOTEntries(1);
2291 resolveGOTOffsetRelocation(SectionID, StubOffset + 2, GOTOffset - 4,
2292 ELF::R_X86_64_PC32);
2296 computeGOTOffsetRE(GOTOffset, 0, ELF::R_X86_64_64),
2301 resolveRelocation(*Section,
Offset, StubAddress, ELF::R_X86_64_PC32,
2304 Value.Addend += support::ulittle32_t::ref(
2305 computePlaceholderAddress(SectionID,
Offset));
2306 processSimpleRelocation(SectionID,
Offset, ELF::R_X86_64_PC32,
Value);
2308 }
else if (RelType == ELF::R_X86_64_GOTPCREL ||
2309 RelType == ELF::R_X86_64_GOTPCRELX ||
2310 RelType == ELF::R_X86_64_REX_GOTPCRELX) {
2311 uint64_t GOTOffset = allocateGOTEntries(1);
2312 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
2313 ELF::R_X86_64_PC32);
2317 computeGOTOffsetRE(GOTOffset,
Value.Offset, ELF::R_X86_64_64);
2318 if (
Value.SymbolName)
2322 }
else if (RelType == ELF::R_X86_64_GOT64) {
2324 uint64_t GOTOffset = allocateGOTEntries(1);
2326 ELF::R_X86_64_64, 0);
2330 computeGOTOffsetRE(GOTOffset,
Value.Offset, ELF::R_X86_64_64);
2331 if (
Value.SymbolName)
2335 }
else if (RelType == ELF::R_X86_64_GOTPC32) {
2339 (void)allocateGOTEntries(0);
2340 resolveGOTOffsetRelocation(SectionID,
Offset, Addend, ELF::R_X86_64_PC32);
2341 }
else if (RelType == ELF::R_X86_64_GOTPC64) {
2342 (void)allocateGOTEntries(0);
2343 resolveGOTOffsetRelocation(SectionID,
Offset, Addend, ELF::R_X86_64_PC64);
2344 }
else if (RelType == ELF::R_X86_64_GOTOFF64) {
2346 (void)allocateGOTEntries(0);
2347 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
2348 }
else if (RelType == ELF::R_X86_64_PC32) {
2349 Value.Addend += support::ulittle32_t::ref(computePlaceholderAddress(SectionID,
Offset));
2350 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
2351 }
else if (RelType == ELF::R_X86_64_PC64) {
2352 Value.Addend += support::ulittle64_t::ref(
2353 computePlaceholderAddress(SectionID,
Offset));
2354 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
2355 }
else if (RelType == ELF::R_X86_64_GOTTPOFF) {
2356 processX86_64GOTTPOFFRelocation(SectionID,
Offset,
Value, Addend);
2357 }
else if (RelType == ELF::R_X86_64_TLSGD ||
2358 RelType == ELF::R_X86_64_TLSLD) {
2361 auto &GetAddrRelocation = *RelI;
2362 processX86_64TLSRelocation(SectionID,
Offset, RelType,
Value, Addend,
2365 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
2371 if (RelType == ELF::R_RISCV_GOT_HI20 ||
2372 RelType == ELF::R_RISCV_PCREL_HI20 ||
2373 RelType == ELF::R_RISCV_TPREL_HI20 ||
2374 RelType == ELF::R_RISCV_TLS_GD_HI20 ||
2375 RelType == ELF::R_RISCV_TLS_GOT_HI20) {
2377 PendingRelocs.push_back({
Value, RE});
2379 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
2382 Value.Addend += support::ulittle32_t::ref(
2383 computePlaceholderAddress(SectionID,
Offset));
2385 processSimpleRelocation(SectionID,
Offset, RelType,
Value);
2390void RuntimeDyldELF::processX86_64GOTTPOFFRelocation(
unsigned SectionID,
2401 struct CodeSequence {
2406 uint64_t TLSSequenceOffset;
2410 uint64_t TpoffRelocationOffset;
2413 std::array<CodeSequence, 2> CodeSequences;
2417 static const std::initializer_list<uint8_t> ExpectedCodeSequenceList = {
2418 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00,
2420 0x48, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00
2423 CodeSequences[0].ExpectedCodeSequence =
2424 ArrayRef<uint8_t>(ExpectedCodeSequenceList);
2425 CodeSequences[0].TLSSequenceOffset = 12;
2427 static const std::initializer_list<uint8_t> NewCodeSequenceList = {
2428 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00,
2429 0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00
2431 CodeSequences[0].NewCodeSequence = ArrayRef<uint8_t>(NewCodeSequenceList);
2432 CodeSequences[0].TpoffRelocationOffset = 12;
2437 static const std::initializer_list<uint8_t> ExpectedCodeSequenceList = {
2438 0x48, 0x8b, 0x05, 0x00, 0x00, 0x00, 0x00,
2439 0x64, 0x48, 0x8b, 0x00, 0x00, 0x00, 0x00
2441 CodeSequences[1].ExpectedCodeSequence =
2442 ArrayRef<uint8_t>(ExpectedCodeSequenceList);
2443 CodeSequences[1].TLSSequenceOffset = 3;
2445 static const std::initializer_list<uint8_t> NewCodeSequenceList = {
2446 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00,
2447 0x64, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00,
2449 CodeSequences[1].NewCodeSequence = ArrayRef<uint8_t>(NewCodeSequenceList);
2450 CodeSequences[1].TpoffRelocationOffset = 10;
2455 for (
const auto &
C : CodeSequences) {
2456 assert(
C.ExpectedCodeSequence.size() ==
C.NewCodeSequence.size() &&
2457 "Old and new code sequences must have the same size");
2459 if (
Offset <
C.TLSSequenceOffset ||
2460 (
Offset -
C.TLSSequenceOffset +
C.NewCodeSequence.size()) >
2467 auto TLSSequenceStartOffset =
Offset -
C.TLSSequenceOffset;
2468 auto *TLSSequence =
Section.getAddressWithOffset(TLSSequenceStartOffset);
2469 if (ArrayRef<uint8_t>(TLSSequence,
C.ExpectedCodeSequence.size()) !=
2470 C.ExpectedCodeSequence) {
2474 memcpy(TLSSequence,
C.NewCodeSequence.data(),
C.NewCodeSequence.size());
2480 RelocationEntry RE(SectionID,
2481 TLSSequenceStartOffset +
C.TpoffRelocationOffset,
2482 ELF::R_X86_64_TPOFF32,
Value.Addend - Addend);
2484 if (
Value.SymbolName)
2497 uint64_t GOTOffset = allocateGOTEntries(1);
2498 resolveGOTOffsetRelocation(SectionID,
Offset, GOTOffset + Addend,
2499 ELF::R_X86_64_PC32);
2500 RelocationEntry RE =
2501 computeGOTOffsetRE(GOTOffset,
Value.Offset, ELF::R_X86_64_TPOFF64);
2502 if (
Value.SymbolName)
2509void RuntimeDyldELF::processX86_64TLSRelocation(
2512 const RelocationRef &GetAddrRelocation) {
2522 bool IsSmallCodeModel;
2524 bool IsGOTPCRel =
false;
2526 switch (GetAddrRelocation.
getType()) {
2527 case ELF::R_X86_64_GOTPCREL:
2528 case ELF::R_X86_64_REX_GOTPCRELX:
2529 case ELF::R_X86_64_GOTPCRELX:
2532 case ELF::R_X86_64_PLT32:
2533 IsSmallCodeModel =
true;
2535 case ELF::R_X86_64_PLTOFF64:
2536 IsSmallCodeModel =
false;
2540 "invalid TLS relocations for General/Local Dynamic TLS Model: "
2541 "expected PLT or GOT relocation for __tls_get_addr function");
2548 ArrayRef<uint8_t> ExpectedCodeSequence;
2550 ArrayRef<uint8_t> NewCodeSequence;
2552 if (RelType == ELF::R_X86_64_TLSGD) {
2557 if (IsSmallCodeModel) {
2559 static const std::initializer_list<uint8_t> CodeSequence = {
2561 0x48, 0x8d, 0x3d, 0x00, 0x00,
2565 0xe8, 0x00, 0x00, 0x00, 0x00
2567 ExpectedCodeSequence = ArrayRef<uint8_t>(CodeSequence);
2568 TLSSequenceOffset = 4;
2572 static const std::initializer_list<uint8_t> CodeSequence = {
2574 0x48, 0x8d, 0x3d, 0x00, 0x00,
2578 0xff, 0x15, 0x00, 0x00, 0x00,
2581 ExpectedCodeSequence = ArrayRef<uint8_t>(CodeSequence);
2582 TLSSequenceOffset = 4;
2587 static const std::initializer_list<uint8_t> SmallSequence = {
2588 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00,
2590 0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00
2593 NewCodeSequence = ArrayRef<uint8_t>(SmallSequence);
2594 TpoffRelocOffset = 12;
2596 static const std::initializer_list<uint8_t> CodeSequence = {
2597 0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
2599 0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2604 ExpectedCodeSequence = ArrayRef<uint8_t>(CodeSequence);
2605 TLSSequenceOffset = 3;
2608 static const std::initializer_list<uint8_t> LargeSequence = {
2609 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00,
2611 0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00,
2613 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00
2615 NewCodeSequence = ArrayRef<uint8_t>(LargeSequence);
2616 TpoffRelocOffset = 12;
2622 RelocationEntry RE(SectionID,
Offset - TLSSequenceOffset + TpoffRelocOffset,
2623 ELF::R_X86_64_TPOFF32,
Value.Addend - Addend);
2624 if (
Value.SymbolName)
2628 }
else if (RelType == ELF::R_X86_64_TLSLD) {
2629 if (IsSmallCodeModel) {
2631 static const std::initializer_list<uint8_t> CodeSequence = {
2632 0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00,
2633 0x00, 0xe8, 0x00, 0x00, 0x00, 0x00
2635 ExpectedCodeSequence = ArrayRef<uint8_t>(CodeSequence);
2636 TLSSequenceOffset = 3;
2639 static const std::initializer_list<uint8_t> SmallSequence = {
2641 0x64, 0x48, 0x8b, 0x04, 0x25,
2642 0x00, 0x00, 0x00, 0x00
2644 NewCodeSequence = ArrayRef<uint8_t>(SmallSequence);
2648 static const std::initializer_list<uint8_t> CodeSequence = {
2649 0x48, 0x8d, 0x3d, 0x00,
2651 0xff, 0x15, 0x00, 0x00,
2655 ExpectedCodeSequence = ArrayRef<uint8_t>(CodeSequence);
2656 TLSSequenceOffset = 3;
2660 static const std::initializer_list<uint8_t> SmallSequence = {
2661 0x0f, 0x1f, 0x40, 0x00,
2662 0x64, 0x48, 0x8b, 0x04, 0x25,
2663 0x00, 0x00, 0x00, 0x00
2665 NewCodeSequence = ArrayRef<uint8_t>(SmallSequence);
2670 static const std::initializer_list<uint8_t> CodeSequence = {
2671 0x48, 0x8d, 0x3d, 0x00, 0x00, 0x00, 0x00,
2673 0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2678 ExpectedCodeSequence = ArrayRef<uint8_t>(CodeSequence);
2679 TLSSequenceOffset = 3;
2682 static const std::initializer_list<uint8_t> LargeSequence = {
2684 0x66, 0x66, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00,
2686 0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00
2688 NewCodeSequence = ArrayRef<uint8_t>(LargeSequence);
2695 "Old and new code sequences must have the same size");
2698 if (
Offset < TLSSequenceOffset ||
2699 (
Offset - TLSSequenceOffset + NewCodeSequence.
size()) >
2704 auto *TLSSequence =
Section.getAddressWithOffset(
Offset - TLSSequenceOffset);
2705 if (ArrayRef<uint8_t>(TLSSequence, ExpectedCodeSequence.
size()) !=
2706 ExpectedCodeSequence) {
2708 "invalid TLS sequence for Global/Local Dynamic TLS Model");
2711 memcpy(TLSSequence, NewCodeSequence.
data(), NewCodeSequence.
size());
2726 Result =
sizeof(uint64_t);
2741 Result =
sizeof(uint64_t);
2751uint64_t RuntimeDyldELF::allocateGOTEntries(
unsigned no) {
2752 if (GOTSectionID == 0) {
2759 CurrentGOTIndex += no;
2764 unsigned GOTRelType) {
2765 auto E = GOTOffsetMap.insert({
Value, 0});
2767 uint64_t GOTOffset = allocateGOTEntries(1);
2770 RelocationEntry RE =
2771 computeGOTOffsetRE(GOTOffset,
Value.Offset, GOTRelType);
2772 if (
Value.SymbolName)
2777 E.first->second = GOTOffset;
2780 return E.first->second;
2783void RuntimeDyldELF::resolveGOTOffsetRelocation(
unsigned SectionID,
2788 RelocationEntry GOTRE(SectionID,
Offset,
Type, GOTOffset);
2795 return RelocationEntry(GOTSectionID, GOTOffset,
Type, SymbolOffset);
2798void RuntimeDyldELF::processNewSymbol(
const SymbolRef &ObjSymbol,
SymbolTableEntry& Symbol) {
2803 if (ObjSymbolFlags & SymbolRef::SF_Indirect) {
2804 if (IFuncStubSectionID == 0) {
2807 IFuncStubSectionID =
Sections.size();
2809 SectionEntry(
".text.__llvm_IFuncStubs",
nullptr, 0, 0, 0));
2811 IFuncStubOffset = 64;
2814 IFuncStubs.push_back(IFuncStub{IFuncStubOffset,
Symbol});
2817 Symbol = SymbolTableEntry(IFuncStubSectionID, IFuncStubOffset,
2819 IFuncStubOffset += getMaxIFuncStubSize();
2826 if (!PendingRelocs.empty())
2831 if (IFuncStubSectionID != 0) {
2833 IFuncStubOffset, 1, IFuncStubSectionID,
".text.__llvm_IFuncStubs");
2834 if (!IFuncStubsAddr)
2836 "Unable to allocate memory for IFunc stubs!");
2838 SectionEntry(
".text.__llvm_IFuncStubs", IFuncStubsAddr, IFuncStubOffset,
2839 IFuncStubOffset, 0);
2841 createIFuncResolver(IFuncStubsAddr);
2844 << IFuncStubSectionID <<
" Addr: "
2845 <<
Sections[IFuncStubSectionID].getAddress() <<
'\n');
2846 for (
auto &IFuncStub : IFuncStubs) {
2847 auto &Symbol = IFuncStub.OriginalSymbol;
2849 <<
" Offset: " <<
format(
"%p", Symbol.getOffset())
2850 <<
" IFuncStubOffset: "
2851 <<
format(
"%p\n", IFuncStub.StubOffset));
2852 createIFuncStub(IFuncStubSectionID, 0, IFuncStub.StubOffset,
2853 Symbol.getSectionID(), Symbol.getOffset());
2856 IFuncStubSectionID = 0;
2857 IFuncStubOffset = 0;
2862 if (GOTSectionID != 0) {
2866 GOTSectionID,
".got",
false);
2875 memset(Addr, 0, TotalSize);
2881 if (!
SI->relocations().empty()) {
2888 ObjSectionToIDMap::iterator i = SectionMap.find(*RelocatedSection);
2889 assert(i != SectionMap.end());
2893 GOTSymbolOffsets.clear();
2898 ObjSectionToIDMap::iterator i, e;
2899 for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) {
2909 if (Name ==
".eh_frame") {
2910 UnregisteredEHFrameSections.push_back(i->second);
2915 GOTOffsetMap.clear();
2917 CurrentGOTIndex = 0;
2926void RuntimeDyldELF::createIFuncResolver(
uint8_t *Addr)
const {
2946 0x41, 0xff, 0x53, 0x08,
2958 static_assert(
sizeof(StubCode) <= 64,
2959 "maximum size of the IFunc resolver is 64B");
2960 memcpy(Addr, StubCode,
sizeof(StubCode));
2963 "IFunc resolver is not supported for target architecture");
2967void RuntimeDyldELF::createIFuncStub(
unsigned IFuncStubSectionID,
2970 unsigned IFuncSectionID,
2972 auto &IFuncStubSection =
Sections[IFuncStubSectionID];
2973 auto *Addr = IFuncStubSection.getAddressWithOffset(IFuncStubOffset);
2997 uint64_t GOT1 = allocateGOTEntries(2);
3000 RelocationEntry RE1(GOTSectionID, GOT1, ELF::R_X86_64_64,
3001 IFuncResolverOffset, {});
3003 RelocationEntry RE2(GOTSectionID, GOT2, ELF::R_X86_64_64, IFuncOffset, {});
3006 const uint8_t StubCode[] = {
3007 0x4c, 0x8d, 0x1d, 0x00, 0x00, 0x00, 0x00,
3010 assert(
sizeof(StubCode) <= getMaxIFuncStubSize() &&
3011 "IFunc stub size must not exceed getMaxIFuncStubSize()");
3012 memcpy(Addr, StubCode,
sizeof(StubCode));
3016 resolveGOTOffsetRelocation(IFuncStubSectionID, IFuncStubOffset + 3,
3017 GOT1 - 4, ELF::R_X86_64_PC32);
3023unsigned RuntimeDyldELF::getMaxIFuncStubSize()
const {
3030bool RuntimeDyldELF::relocationNeedsGot(
const RelocationRef &R)
const {
3031 unsigned RelTy =
R.getType();
3033 return RelTy == ELF::R_AARCH64_ADR_GOT_PAGE ||
3034 RelTy == ELF::R_AARCH64_LD64_GOT_LO12_NC;
3037 return RelTy == ELF::R_LARCH_GOT_PC_HI20 ||
3038 RelTy == ELF::R_LARCH_GOT_PC_LO12 ||
3039 RelTy == ELF::R_LARCH_GOT64_PC_HI12 ||
3040 RelTy == ELF::R_LARCH_GOT64_PC_LO20;
3043 return RelTy == ELF::R_X86_64_GOTPCREL ||
3044 RelTy == ELF::R_X86_64_GOTPCRELX ||
3045 RelTy == ELF::R_X86_64_GOT64 ||
3046 RelTy == ELF::R_X86_64_REX_GOTPCRELX;
3050bool RuntimeDyldELF::relocationNeedsStub(
const RelocationRef &R)
const {
3054 switch (
R.getType()) {
3059 case ELF::R_X86_64_GOTPCREL:
3060 case ELF::R_X86_64_GOTPCRELX:
3061 case ELF::R_X86_64_REX_GOTPCRELX:
3062 case ELF::R_X86_64_GOTPC64:
3063 case ELF::R_X86_64_GOT64:
3064 case ELF::R_X86_64_GOTOFF64:
3065 case ELF::R_X86_64_PC32:
3066 case ELF::R_X86_64_PC64:
3067 case ELF::R_X86_64_64:
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
static void or32le(void *P, int32_t V)
static void or32AArch64Imm(void *L, uint64_t Imm)
static uint64_t getBits(uint64_t Val, int Start, int End)
static void write32AArch64Addr(void *L, uint64_t Imm)
Expected< const Elf_Sym * > getSymbol(DataRefImpl Sym) const
static Expected< ELFObjectFile< ELFT > > create(MemoryBufferRef Object, bool InitContent=true)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
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.
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)
RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
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
JITSymbolResolver & Resolver
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.
uint64_t getSectionLoadAddress(unsigned SectionID) const
virtual unsigned getMaxStubSize() const =0
RTDyldSymbolTable GlobalSymbolTable
Expected< ObjSectionToIDMap > loadObjectImpl(const object::ObjectFile &Obj)
SectionEntry - represents a section emitted into memory by the dynamic linker.
StringMapIterBase< SymbolTableEntry, true > const_iterator
Represent a constant reference to a string, i.e.
constexpr const char * data() const
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 LLVM_ABI 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
Expected< int64_t > getAddend() const
This class is the base class for all object file types.
virtual section_iterator section_begin() const =0
uint64_t getOffset() const
symbol_iterator getSymbol() const
This is a value type class that represents a single section in the list of sections in the object fil...
DataRefImpl getRawDataRefImpl() const
bool isText() const
Whether this section contains instructions.
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.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static int64_t decodePPC64LocalEntryOffset(unsigned Other)
content_iterator< SectionRef > section_iterator
content_iterator< RelocationRef > relocation_iterator
@ Resolved
Queried, materialization begun.
NodeAddr< InstrNode * > Instr
void write32le(void *P, uint32_t V)
uint32_t read32le(const void *P)
detail::packed_endian_specific_integral< int32_t, llvm::endianness::little, unaligned > little32_t
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
static uint16_t applyPPChighera(uint64_t value)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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 void applyITypeImmRISCV(uint8_t *InstrAddr, uint32_t Imm)
static uint16_t applyPPChighesta(uint64_t value)
static uint16_t applyPPChighest(uint64_t value)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
static uint16_t applyPPCha(uint64_t value)
static void applyUTypeImmRISCV(uint8_t *InstrAddr, uint32_t Imm)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
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.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
@ Ref
The access may reference the value stored in memory.
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)
static void or32le(void *P, int32_t V)
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
constexpr int32_t SignExtend32(uint32_t X)
Sign-extend the number in the bottom B bits of X to a 32-bit integer.
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.
static uint32_t extractBits(uint64_t Val, uint32_t Hi, uint32_t Lo)
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
static uint64_t getLoongArchPageDelta(uint64_t dest, uint64_t pc, uint32_t type)
@ End
Run the machine verifier once, at the end of the pipeline.
void consumeError(Error Err)
Consume a Error without doing anything.
LLVM_ABI Error write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)
static void write32AArch64Addr(void *T, uint64_t s, uint64_t p, int shift)
Implement std::hash so that hash_code can be used in STL containers.
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...