13#ifndef LLVM_OBJECT_ELF_H
14#define LLVM_OBJECT_ELF_H
76inline std::pair<unsigned char, unsigned char>
95template <
class ELFT>
class ELFFile;
112 "the index is greater than or equal to the number of entries (" +
115 const uint8_t *EntryStart = (
const uint8_t *)
First +
N *
sizeof(
T);
116 if (EntryStart +
sizeof(
T) >
BufEnd)
117 return createError(
"can't read past the end of the file");
129 const typename ELFT::Shdr &Sec) {
132 return "[index " + std::to_string(&Sec - &TableOrErr->front()) +
"]";
138 return "[unknown index]";
143 const typename ELFT::Shdr &Sec) {
147 " section with index " +
Twine(SecNdx))
153 const typename ELFT::Phdr &Phdr) {
156 return (
"[index " +
Twine(&Phdr - &Headers->front()) +
"]").str();
159 return "[unknown index]";
168 const typename ELFT::Shdr &Sec) {
173 if (Sec.sh_offset < Phdr.p_offset)
177 if (Sec.sh_size == 0)
178 return (Sec.sh_offset + 1 <= Phdr.p_offset + Phdr.p_filesz);
179 return Sec.sh_offset + Sec.sh_size <= Phdr.p_offset + Phdr.p_filesz;
186 const typename ELFT::Shdr &Sec) {
190 if (Sec.sh_addr < Phdr.p_vaddr)
196 bool IsTbssInNonTLS = IsTbss && Phdr.p_type !=
ELF::PT_TLS;
198 if (Sec.sh_size == 0 || IsTbssInNonTLS)
199 return Sec.sh_addr + 1 <= Phdr.p_vaddr + Phdr.p_memsz;
200 return Sec.sh_addr + Sec.sh_size <= Phdr.p_vaddr + Phdr.p_memsz;
205 const typename ELFT::Shdr &Sec) {
206 return checkSectionOffsets<ELFT>(Phdr, Sec) &&
207 checkSectionVMA<ELFT>(Phdr, Sec);
229 std::vector<Elf_Shdr> FakeSections;
236 return *
reinterpret_cast<const Elf_Ehdr *
>(
base());
239 template <
typename T>
241 template <
typename T>
250 uint32_t SymbolVersionIndex,
bool &IsDefault,
251 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
252 std::optional<bool> IsSymHidden)
const;
259 Elf_Shdr_Range Sections)
const;
264 Elf_Shdr_Range Sections)
const;
278 const Elf_Shdr *SymTab)
const;
281 loadVersionMap(
const Elf_Shdr *VerNeedSec,
const Elf_Shdr *VerDefSec)
const;
307 return getSectionContentsAsArray<Elf_Sym>(*Sec);
311 return getSectionContentsAsArray<Elf_Rela>(Sec);
315 return getSectionContentsAsArray<Elf_Rel>(Sec);
319 return getSectionContentsAsArray<Elf_Relr>(Sec);
335 if (PhOff + HeadersSize < PhOff || PhOff + HeadersSize >
getBufSize())
336 return createError(
"program headers are longer than binary of size " +
342 auto *Begin =
reinterpret_cast<const Elf_Phdr *
>(
base() + PhOff);
356 if (Phdr.p_offset + Phdr.p_filesz >
getBufSize()) {
360 return Elf_Note_Iterator(Err);
364 if (Phdr.p_align != 0 && Phdr.p_align != 1 && Phdr.p_align != 4 &&
368 return Elf_Note_Iterator(Err);
370 return Elf_Note_Iterator(
base() + Phdr.p_offset, Phdr.p_filesz,
371 std::max<size_t>(Phdr.p_align, 4), Err);
388 return Elf_Note_Iterator(Err);
391 if (
Shdr.sh_addralign != 0 &&
Shdr.sh_addralign != 1 &&
392 Shdr.sh_addralign != 4 &&
Shdr.sh_addralign != 8) {
395 return Elf_Note_Iterator(Err);
397 return Elf_Note_Iterator(
base() +
Shdr.sh_offset,
Shdr.sh_size,
398 std::max<size_t>(
Shdr.sh_addralign, 4), Err);
403 return Elf_Note_Iterator();
431 Elf_Shdr_Range Sections,
436 const Elf_Shdr *SymTab,
439 Elf_Sym_Range Symtab,
451 template <
typename T>
464 decodeBBAddrMap(
const Elf_Shdr &Sec,
const Elf_Shdr *RelaSec =
nullptr,
465 std::vector<PGOAnalysisMap> *PGOAnalyses =
nullptr)
const;
486 if (
Index >= Sections.size())
488 return &Sections[
Index];
496 if (!ShndxTable.
First)
498 "found an extended symbol index (" +
Twine(SymIndex) +
499 "), but unable to locate the extended symbol index table");
503 return createError(
"unable to read an extended symbol table at index " +
504 Twine(SymIndex) +
": " +
516 getExtendedSymbolTableIndex<ELFT>(
Sym, &
Sym - Syms.begin(), ShndxTable);
519 return *ErrorOrIndex;
530 auto SymsOrErr = symbols(SymTab);
532 return SymsOrErr.takeError();
540 auto IndexOrErr = getSectionIndex(
Sym, Symbols, ShndxTable);
542 return IndexOrErr.takeError();
552 auto SymsOrErr = symbols(Sec);
554 return SymsOrErr.takeError();
556 Elf_Sym_Range Symbols = *SymsOrErr;
557 if (
Index >= Symbols.size())
558 return createError(
"unable to get symbol from section " +
560 ": invalid symbol index (" +
Twine(
Index) +
")");
561 return &Symbols[
Index];
568 if (Sec.sh_entsize !=
sizeof(
T) &&
sizeof(
T) != 1)
570 " has invalid sh_entsize: expected " +
Twine(
sizeof(
T)) +
571 ", but got " +
Twine(Sec.sh_entsize));
573 uintX_t
Offset = Sec.sh_offset;
574 uintX_t
Size = Sec.sh_size;
576 if (
Size %
sizeof(
T))
578 " has an invalid sh_size (" +
Twine(
Size) +
579 ") which is not a multiple of its sh_entsize (" +
580 Twine(Sec.sh_entsize) +
")");
581 if (std::numeric_limits<uintX_t>::max() -
Offset <
Size)
585 ") that cannot be represented");
590 ") that is greater than the file size (0x" +
597 const T *Start =
reinterpret_cast<const T *
>(base() +
Offset);
604 uintX_t
Offset = Phdr.p_offset;
605 uintX_t
Size = Phdr.p_filesz;
607 if (std::numeric_limits<uintX_t>::max() -
Offset <
Size)
611 ") that cannot be represented");
616 ") that is greater than the file size (0x" +
624 return getSectionContentsAsArray<uint8_t>(Sec);
635 if (!isMipsELF64()) {
637 Result.append(
Name.begin(),
Name.end());
645 uint8_t Type1 = (
Type >> 0) & 0xFF;
651 Result.append(
Name.begin(),
Name.end());
654 Result.append(1,
'/');
655 Result.append(
Name.begin(),
Name.end());
658 Result.append(1,
'/');
659 Result.append(
Name.begin(),
Name.end());
671 const Elf_Shdr *VerDefSec)
const {
679 auto InsertEntry = [&](
unsigned N,
StringRef Version,
bool IsVerdef) {
680 if (
N >= VersionMap.
size())
682 VersionMap[
N] = {std::string(Version), IsVerdef};
689 for (
const VerDef &Def : *Defs)
697 for (
const VerNeed &Dep : *Deps)
698 for (
const VernAux &Aux : Dep.AuxV)
708 const Elf_Shdr *SymTab)
const {
712 return getEntry<Elf_Sym>(*SymTab,
Index);
725 if (Sections.empty())
727 "e_shstrndx == SHN_XINDEX, but the section header table is empty");
729 Index = Sections[0].sh_link;
735 return FakeSectionStrings;
737 if (
Index >= Sections.size())
740 return getStringTable(Sections[
Index], WarnHandler);
749 const void *BufEnd) {
750 using Elf_Word =
typename ELFT::Word;
751 if (Table.nbuckets == 0)
752 return Table.symndx + 1;
755 for (Elf_Word Val : Table.buckets())
756 LastSymIdx = std::max(LastSymIdx, (
uint64_t)Val);
758 reinterpret_cast<const Elf_Word *
>(Table.values(LastSymIdx).end());
760 while (It < BufEnd && (*It & 1) == 0) {
767 "no terminator found for GNU hash section before buffer end");
769 return LastSymIdx + 1;
779 if (!SectionsOrError)
781 for (
const Elf_Shdr &Sec : *SectionsOrError) {
783 if (Sec.sh_size % Sec.sh_entsize != 0) {
785 "SHT_DYNSYM section has sh_size (" +
786 Twine(Sec.sh_size) +
") % sh_entsize (" +
787 Twine(Sec.sh_entsize) +
") that is not 0");
789 return Sec.sh_size / Sec.sh_entsize;
793 if (!SectionsOrError->empty()) {
804 std::optional<uint64_t> ElfHash;
805 std::optional<uint64_t> ElfGnuHash;
806 for (
const Elf_Dyn &Entry : *DynTable) {
807 switch (Entry.d_tag) {
809 ElfHash = Entry.d_un.d_ptr;
811 case ELF::DT_GNU_HASH:
812 ElfGnuHash = Entry.d_un.d_ptr;
820 const Elf_GnuHash *Table =
821 reinterpret_cast<const Elf_GnuHash *
>(TablePtr.
get());
822 return getDynSymtabSizeFromGnuHash<ELFT>(*Table, this->Buf.
bytes_end());
830 const Elf_Hash *Table =
reinterpret_cast<const Elf_Hash *
>(TablePtr.
get());
831 return Table->nchain;
840 if (
sizeof(Elf_Ehdr) > Object.size())
842 ") is smaller than an ELF header (" +
843 Twine(
sizeof(Elf_Ehdr)) +
")");
851 if (!FakeSections.empty())
853 auto PhdrsOrErr = program_headers();
857 FakeSectionStrings +=
'\0';
861 Elf_Shdr FakeShdr = {};
864 FakeShdr.sh_addr = Phdr.p_vaddr;
865 FakeShdr.sh_size = Phdr.p_memsz;
866 FakeShdr.sh_offset = Phdr.p_offset;
868 FakeShdr.sh_name = FakeSectionStrings.
size();
869 FakeSectionStrings += (
"PT_LOAD#" +
Twine(
Idx)).str();
870 FakeSectionStrings +=
'\0';
877 const uintX_t SectionTableOffset = getHeader().e_shoff;
878 if (SectionTableOffset == 0) {
879 if (!FakeSections.empty())
880 return ArrayRef(FakeSections.data(), FakeSections.size());
884 if (getHeader().e_shentsize !=
sizeof(Elf_Shdr))
885 return createError(
"invalid e_shentsize in ELF header: " +
886 Twine(getHeader().e_shentsize));
889 if (SectionTableOffset +
sizeof(Elf_Shdr) > FileSize ||
890 SectionTableOffset + (uintX_t)
sizeof(Elf_Shdr) < SectionTableOffset)
892 "section header table goes past the end of the file: e_shoff = 0x" +
896 if (SectionTableOffset & (
alignof(Elf_Shdr) - 1))
898 return createError(
"invalid alignment of section headers");
900 const Elf_Shdr *
First =
901 reinterpret_cast<const Elf_Shdr *
>(base() + SectionTableOffset);
903 uintX_t NumSections = getHeader().e_shnum;
904 if (NumSections == 0)
905 NumSections =
First->sh_size;
907 if (NumSections >
UINT64_MAX /
sizeof(Elf_Shdr))
908 return createError(
"invalid number of sections specified in the NULL "
909 "section's sh_size field (" +
910 Twine(NumSections) +
")");
912 const uint64_t SectionTableSize = NumSections *
sizeof(Elf_Shdr);
913 if (SectionTableOffset + SectionTableSize < SectionTableOffset)
915 "invalid section header table offset (e_shoff = 0x" +
917 ") or invalid number of sections specified in the first section "
918 "header's sh_size field (0x" +
922 if (SectionTableOffset + SectionTableSize > FileSize)
923 return createError(
"section table goes past the end of file");
933 return SecOrErr.takeError();
934 return getEntry<T>(**SecOrErr, Entry);
946 if (Entry >= Arr.
size())
948 "can't read an entry at 0x" +
950 ": it goes past the end of the section (0x" +
955template <
typename ELFT>
957 uint32_t SymbolVersionIndex,
bool &IsDefault,
958 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
959 std::optional<bool> IsSymHidden)
const {
970 if (VersionIndex >= VersionMap.size() || !VersionMap[VersionIndex])
971 return createError(
"SHT_GNU_versym section refers to a version index " +
972 Twine(VersionIndex) +
" which is missing");
976 if (!Entry.IsVerDef || IsSymHidden.value_or(
false))
980 return Entry.Name.c_str();
995 const uint8_t *Start = ContentsOrErr->data();
996 const uint8_t *
End = Start + ContentsOrErr->size();
998 auto ExtractNextAux = [&](
const uint8_t *&VerdauxBuf,
1000 if (VerdauxBuf +
sizeof(Elf_Verdaux) >
End)
1002 ": version definition " +
Twine(VerDefNdx) +
1003 " refers to an auxiliary entry that goes past the end "
1006 auto *Verdaux =
reinterpret_cast<const Elf_Verdaux *
>(VerdauxBuf);
1007 VerdauxBuf += Verdaux->vda_next;
1010 Aux.
Offset = VerdauxBuf - Start;
1011 if (Verdaux->vda_name <= StrTabOrErr->size())
1012 Aux.
Name = std::string(StrTabOrErr->drop_front(Verdaux->vda_name));
1014 Aux.
Name = (
"<invalid vda_name: " +
Twine(Verdaux->vda_name) +
">").str();
1018 std::vector<VerDef> Ret;
1019 const uint8_t *VerdefBuf = Start;
1020 for (
unsigned I = 1;
I <= Sec.sh_info; ++
I) {
1021 if (VerdefBuf +
sizeof(Elf_Verdef) >
End)
1023 ": version definition " +
Twine(
I) +
1024 " goes past the end of the section");
1026 if (
reinterpret_cast<uintptr_t
>(VerdefBuf) %
sizeof(
uint32_t) != 0)
1028 "invalid " +
describe(*
this, Sec) +
1029 ": found a misaligned version definition entry at offset 0x" +
1032 unsigned Version = *
reinterpret_cast<const Elf_Half *
>(VerdefBuf);
1035 ": version " +
Twine(Version) +
1036 " is not yet supported");
1038 const Elf_Verdef *
D =
reinterpret_cast<const Elf_Verdef *
>(VerdefBuf);
1039 VerDef &VD = *Ret.emplace(Ret.end());
1040 VD.
Offset = VerdefBuf - Start;
1045 VD.
Hash =
D->vd_hash;
1047 const uint8_t *VerdauxBuf = VerdefBuf +
D->vd_aux;
1048 for (
unsigned J = 0; J <
D->vd_cnt; ++J) {
1049 if (
reinterpret_cast<uintptr_t
>(VerdauxBuf) %
sizeof(
uint32_t) != 0)
1051 ": found a misaligned auxiliary entry at offset 0x" +
1059 VD.
Name = AuxOrErr->Name;
1061 VD.
AuxV.push_back(*AuxOrErr);
1064 VerdefBuf +=
D->vd_next;
1070template <
class ELFT>
1078 return std::move(
E);
1080 StrTab = *StrTabOrErr;
1088 const uint8_t *Start = ContentsOrErr->data();
1089 const uint8_t *
End = Start + ContentsOrErr->size();
1090 const uint8_t *VerneedBuf = Start;
1092 std::vector<VerNeed> Ret;
1093 for (
unsigned I = 1;
I <= Sec.sh_info; ++
I) {
1094 if (VerneedBuf +
sizeof(Elf_Verdef) >
End)
1096 ": version dependency " +
Twine(
I) +
1097 " goes past the end of the section");
1099 if (
reinterpret_cast<uintptr_t
>(VerneedBuf) %
sizeof(
uint32_t) != 0)
1101 "invalid " +
describe(*
this, Sec) +
1102 ": found a misaligned version dependency entry at offset 0x" +
1105 unsigned Version = *
reinterpret_cast<const Elf_Half *
>(VerneedBuf);
1108 ": version " +
Twine(Version) +
1109 " is not yet supported");
1111 const Elf_Verneed *Verneed =
1112 reinterpret_cast<const Elf_Verneed *
>(VerneedBuf);
1114 VerNeed &VN = *Ret.emplace(Ret.end());
1115 VN.
Version = Verneed->vn_version;
1116 VN.
Cnt = Verneed->vn_cnt;
1117 VN.
Offset = VerneedBuf - Start;
1119 if (Verneed->vn_file < StrTab.
size())
1120 VN.
File = std::string(StrTab.
data() + Verneed->vn_file);
1122 VN.
File = (
"<corrupt vn_file: " +
Twine(Verneed->vn_file) +
">").str();
1124 const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux;
1125 for (
unsigned J = 0; J < Verneed->vn_cnt; ++J) {
1126 if (
reinterpret_cast<uintptr_t
>(VernauxBuf) %
sizeof(
uint32_t) != 0)
1128 ": found a misaligned auxiliary entry at offset 0x" +
1131 if (VernauxBuf +
sizeof(Elf_Vernaux) >
End)
1133 "invalid " +
describe(*
this, Sec) +
": version dependency " +
1135 " refers to an auxiliary entry that goes past the end "
1138 const Elf_Vernaux *Vernaux =
1139 reinterpret_cast<const Elf_Vernaux *
>(VernauxBuf);
1142 Aux.
Hash = Vernaux->vna_hash;
1143 Aux.
Flags = Vernaux->vna_flags;
1144 Aux.
Other = Vernaux->vna_other;
1145 Aux.
Offset = VernauxBuf - Start;
1146 if (StrTab.
size() <= Vernaux->vna_name)
1147 Aux.
Name =
"<corrupt>";
1151 VernauxBuf += Vernaux->vna_next;
1153 VerneedBuf += Verneed->vn_next;
1158template <
class ELFT>
1163 return TableOrErr.takeError();
1164 return object::getSection<ELFT>(*TableOrErr,
Index);
1167template <
class ELFT>
1172 if (
Error E = WarnHandler(
"invalid sh_type for string table section " +
1174 ": expected SHT_STRTAB, but got " +
1176 getHeader().e_machine, Section.sh_type)))
1177 return std::move(
E);
1179 auto V = getSectionContentsAsArray<char>(Section);
1181 return V.takeError();
1184 return createError(
"SHT_STRTAB string table section " +
1186 if (
Data.back() !=
'\0')
1187 return createError(
"SHT_STRTAB string table section " +
1189 " is non-null terminated");
1193template <
class ELFT>
1198 return SectionsOrErr.takeError();
1199 return getSHNDXTable(Section, *SectionsOrErr);
1202template <
class ELFT>
1205 Elf_Shdr_Range Sections)
const {
1207 auto VOrErr = getSectionContentsAsArray<Elf_Word>(Section);
1209 return VOrErr.takeError();
1211 auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
1213 return SymTableOrErr.takeError();
1214 const Elf_Shdr &SymTable = **SymTableOrErr;
1218 "SHT_SYMTAB_SHNDX section is linked with " +
1220 " section (expected SHT_SYMTAB/SHT_DYNSYM)");
1222 uint64_t Syms = SymTable.sh_size /
sizeof(Elf_Sym);
1223 if (V.size() != Syms)
1225 " entries, but the symbol table associated has " +
1231template <
class ELFT>
1236 return SectionsOrErr.takeError();
1237 return getStringTableForSymtab(Sec, *SectionsOrErr);
1240template <
class ELFT>
1243 Elf_Shdr_Range Sections)
const {
1247 "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
1249 object::getSection<ELFT>(Sections, Sec.sh_link);
1252 return getStringTable(**SectionOrErr);
1255template <
class ELFT>
1260 if (!StrTabSecOrErr)
1266 return createError(
"invalid string table linked to " +
1269 return *StrTabOrErr;
1272template <
class ELFT>
1278 return SectionsOrErr.takeError();
1279 auto Table = getSectionStringTable(*SectionsOrErr, WarnHandler);
1281 return Table.takeError();
1285template <
class ELFT>
1293 " has an invalid sh_name (0x" +
1295 ") offset which goes past the end of the "
1296 "section name string table");
1305 for (uint8_t
C : SymbolName) {
1307 H ^= (
H >> 24) & 0xf0;
1309 return H & 0x0fffffff;
1317 for (uint8_t
C :
Name)
1318 H = (
H << 5) +
H +
C;
bbsections Prepares for basic block sections
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
COFF::MachineTypes Machine
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static bool isMips64EL(const ELFYAML::Object &Obj)
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
This file implements a map that provides insertion order iteration.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
const unsigned char * bytes_end() const
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
const unsigned char * bytes_begin() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Twine utohexstr(const uint64_t &Val)
The instances of the Type class are immutable: once they are created, they are never changed.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
const Elf_Ehdr & getHeader() const
Expected< std::vector< Elf_Rela > > android_relas(const Elf_Shdr &Sec) const
Expected< StringRef > getLinkAsStrtab(const typename ELFT::Shdr &Sec) const
static Expected< ELFFile > create(StringRef Object)
Expected< const Elf_Sym * > getSymbol(const Elf_Shdr *Sec, uint32_t Index) const
Expected< std::vector< VerDef > > getVersionDefinitions(const Elf_Shdr &Sec) const
std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const
Expected< ArrayRef< Elf_Word > > getSHNDXTable(const Elf_Shdr &Section) const
Expected< Elf_Sym_Range > symbols(const Elf_Shdr *Sec) const
Expected< ArrayRef< uint8_t > > getSegmentContents(const Elf_Phdr &Phdr) const
Expected< std::vector< BBAddrMap > > decodeBBAddrMap(const Elf_Shdr &Sec, const Elf_Shdr *RelaSec=nullptr, std::vector< PGOAnalysisMap > *PGOAnalyses=nullptr) const
Returns a vector of BBAddrMap structs corresponding to each function within the text section that the...
Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const
Get an iterator over notes in a section.
uint32_t getRelativeRelocationType() const
iterator_range< Elf_Note_Iterator > notes(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator range over notes of a program header.
Expected< StringRef > getSymbolVersionByIndex(uint32_t SymbolVersionIndex, bool &IsDefault, SmallVector< std::optional< VersionEntry >, 0 > &VersionMap, std::optional< bool > IsSymHidden) const
Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator over notes in a program header.
Expected< ArrayRef< uint8_t > > getSectionContents(const Elf_Shdr &Sec) const
Expected< Elf_Rela_Range > relas(const Elf_Shdr &Sec) const
Expected< Elf_Phdr_Range > program_headers() const
Iterate over program header table.
Expected< StringRef > getStringTableForSymtab(const Elf_Shdr &Section) const
Expected< std::vector< VerNeed > > getVersionDependencies(const Elf_Shdr &Sec, WarningHandler WarnHandler=&defaultWarningHandler) const
size_t getBufSize() const
Expected< const T * > getEntry(uint32_t Section, uint32_t Entry) const
Expected< const Elf_Sym * > getRelocationSymbol(const Elf_Rel &Rel, const Elf_Shdr *SymTab) const
Get the symbol for a given relocation.
const uint8_t * end() const
Expected< StringRef > getSectionStringTable(Elf_Shdr_Range Sections, WarningHandler WarnHandler=&defaultWarningHandler) const
Expected< uint64_t > getDynSymtabSize() const
This function determines the number of dynamic symbols.
Expected< Elf_Dyn_Range > dynamicEntries() const
void createFakeSections()
Used by llvm-objdump -d (which needs sections for disassembly) to disassemble objects without a secti...
Expected< Elf_Shdr_Range > sections() const
iterator_range< Elf_Note_Iterator > notes(const Elf_Shdr &Shdr, Error &Err) const
Get an iterator range over notes of a section.
const uint8_t * base() const
Expected< const uint8_t * > toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler=&defaultWarningHandler) const
Expected< Elf_Relr_Range > relrs(const Elf_Shdr &Sec) const
Expected< MapVector< const Elf_Shdr *, const Elf_Shdr * > > getSectionAndRelocations(std::function< Expected< bool >(const Elf_Shdr &)> IsMatch) const
Returns a map from every section matching IsMatch to its relocation section, or nullptr if it has no ...
Elf_Note_Iterator notes_end() const
Get the end iterator for notes.
Expected< StringRef > getSectionName(const Elf_Shdr &Section, WarningHandler WarnHandler=&defaultWarningHandler) const
StringRef getRelocationTypeName(uint32_t Type) const
Expected< StringRef > getStringTable(const Elf_Shdr &Section, WarningHandler WarnHandler=&defaultWarningHandler) const
llvm::function_ref< Error(const Twine &Msg)> WarningHandler
Expected< ArrayRef< T > > getSectionContentsAsArray(const Elf_Shdr &Sec) const
Expected< SmallVector< std::optional< VersionEntry >, 0 > > loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const
Expected< Elf_Rel_Range > rels(const Elf_Shdr &Sec) const
Expected< const Elf_Shdr * > getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, DataRegion< Elf_Word > ShndxTable) const
std::vector< Elf_Rel > decode_relrs(Elf_Relr_Range relrs) const
Expected< uint32_t > getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, DataRegion< Elf_Word > ShndxTable) const
@ C
The default llvm calling convention, compatible with C.
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Expected< uint32_t > getExtendedSymbolTableIndex(const typename ELFT::Sym &Sym, unsigned SymIndex, DataRegion< typename ELFT::Word > ShndxTable)
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Error createError(const Twine &Err)
StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
static Expected< uint64_t > getDynSymtabSizeFromGnuHash(const typename ELFT::GnuHash &Table, const void *BufEnd)
This function finds the number of dynamic symbols using a GNU hash table.
bool checkSectionOffsets(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
uint32_t getELFRelativeRelocationType(uint32_t Machine)
static std::string describe(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
std::string getPhdrIndexForError(const ELFFile< ELFT > &Obj, const typename ELFT::Phdr &Phdr)
uint32_t hashGnu(StringRef Name)
This function returns the hash value for a symbol in the .dynsym section for the GNU hash table.
StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type)
@ ADDIS_R12_TO_R2_NO_DISP
@ ADDI_R12_TO_R12_NO_DISP
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
static Error defaultWarningHandler(const Twine &Msg)
bool isSectionInSegment(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
bool checkSectionVMA(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
std::string getSecIndexForError(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
uint32_t hashSysV(StringRef SymbolName)
This function returns the hash value for a symbol in the .dynsym section Name of the API remains cons...
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
void consumeError(Error Err)
Consume a Error without doing anything.
Expected< T > operator[](uint64_t N)
DataRegion(const T *Data, const uint8_t *BufferEnd)
DataRegion(ArrayRef< T > Arr)
std::optional< uint64_t > Size
std::vector< VerdAux > AuxV
std::vector< VernAux > AuxV