13#ifndef LLVM_OBJECT_ELF_H
14#define LLVM_OBJECT_ELF_H
79inline std::pair<unsigned char, unsigned char>
98template <
class ELFT>
class ELFFile;
115 "the index is greater than or equal to the number of entries (" +
119 if (EntryStart +
sizeof(
T) >
BufEnd)
120 return createError(
"can't read past the end of the file");
132 const typename ELFT::Shdr &Sec) {
135 return "[index " + std::to_string(&Sec - &TableOrErr->front()) +
"]";
141 return "[unknown index]";
146 const typename ELFT::Shdr &Sec) {
150 " section with index " +
Twine(SecNdx))
156 const typename ELFT::Phdr &Phdr) {
159 return (
"[index " +
Twine(&Phdr - &Headers->front()) +
"]").str();
162 return "[unknown index]";
171 const typename ELFT::Shdr &Sec) {
176 if (Sec.sh_offset < Phdr.p_offset)
180 if (Sec.sh_size == 0)
181 return (Sec.sh_offset + 1 <= Phdr.p_offset + Phdr.p_filesz);
182 return Sec.sh_offset + Sec.sh_size <= Phdr.p_offset + Phdr.p_filesz;
189 const typename ELFT::Shdr &Sec) {
193 if (Sec.sh_addr < Phdr.p_vaddr)
199 bool IsTbssInNonTLS = IsTbss && Phdr.p_type !=
ELF::PT_TLS;
201 if (Sec.sh_size == 0 || IsTbssInNonTLS)
202 return Sec.sh_addr + 1 <= Phdr.p_vaddr + Phdr.p_memsz;
203 return Sec.sh_addr + Sec.sh_size <= Phdr.p_vaddr + Phdr.p_memsz;
208 const typename ELFT::Shdr &Sec) {
209 return checkSectionOffsets<ELFT>(Phdr, Sec) &&
210 checkSectionVMA<ELFT>(Phdr, Sec);
224 size_t Count = Hdr / 8;
228 uint
Offset = 0, Addend = 0;
231 for (; Count; --Count) {
238 Offset += (
Data.getULEB128(Cur) << (7 - FlagBits)) - (0x80 >> FlagBits);
241 SymIdx +=
Data.getSLEB128(Cur);
245 Addend +=
Data.getSLEB128(Cur);
249 {Offset << Shift, SymIdx, Type, std::make_signed_t<uint>(Addend)});
278 std::vector<Elf_Shdr> FakeSections;
285 return *
reinterpret_cast<const Elf_Ehdr *
>(
base());
288 template <
typename T>
290 template <
typename T>
299 uint32_t SymbolVersionIndex,
bool &IsDefault,
300 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
301 std::optional<bool> IsSymHidden)
const;
308 Elf_Shdr_Range Sections)
const;
313 Elf_Shdr_Range Sections)
const;
327 const Elf_Shdr *SymTab)
const;
330 loadVersionMap(
const Elf_Shdr *VerNeedSec,
const Elf_Shdr *VerDefSec)
const;
356 return getSectionContentsAsArray<Elf_Sym>(*Sec);
360 return getSectionContentsAsArray<Elf_Rela>(Sec);
364 return getSectionContentsAsArray<Elf_Rel>(Sec);
368 return getSectionContentsAsArray<Elf_Relr>(Sec);
374 using RelsOrRelas = std::pair<std::vector<Elf_Rel>, std::vector<Elf_Rela>>;
389 if (PhOff + HeadersSize < PhOff || PhOff + HeadersSize >
getBufSize())
390 return createError(
"program headers are longer than binary of size " +
396 auto *Begin =
reinterpret_cast<const Elf_Phdr *
>(
base() + PhOff);
410 if (Phdr.p_offset + Phdr.p_filesz >
getBufSize()) {
414 return Elf_Note_Iterator(Err);
418 if (Phdr.p_align != 0 && Phdr.p_align != 1 && Phdr.p_align != 4 &&
422 return Elf_Note_Iterator(Err);
424 return Elf_Note_Iterator(
base() + Phdr.p_offset, Phdr.p_filesz,
425 std::max<size_t>(Phdr.p_align, 4), Err);
442 return Elf_Note_Iterator(Err);
445 if (
Shdr.sh_addralign != 0 &&
Shdr.sh_addralign != 1 &&
446 Shdr.sh_addralign != 4 &&
Shdr.sh_addralign != 8) {
449 return Elf_Note_Iterator(Err);
451 return Elf_Note_Iterator(
base() +
Shdr.sh_offset,
Shdr.sh_size,
452 std::max<size_t>(
Shdr.sh_addralign, 4), Err);
457 return Elf_Note_Iterator();
485 Elf_Shdr_Range Sections,
490 const Elf_Shdr *SymTab,
493 Elf_Sym_Range Symtab,
505 template <
typename T>
518 decodeBBAddrMap(
const Elf_Shdr &Sec,
const Elf_Shdr *RelaSec =
nullptr,
519 std::vector<PGOAnalysisMap> *PGOAnalyses =
nullptr)
const;
540 if (
Index >= Sections.size())
542 return &Sections[
Index];
550 if (!ShndxTable.
First)
552 "found an extended symbol index (" +
Twine(SymIndex) +
553 "), but unable to locate the extended symbol index table");
557 return createError(
"unable to read an extended symbol table at index " +
558 Twine(SymIndex) +
": " +
570 getExtendedSymbolTableIndex<ELFT>(
Sym, &
Sym - Syms.begin(), ShndxTable);
573 return *ErrorOrIndex;
584 auto SymsOrErr = symbols(SymTab);
586 return SymsOrErr.takeError();
594 auto IndexOrErr = getSectionIndex(
Sym, Symbols, ShndxTable);
596 return IndexOrErr.takeError();
606 auto SymsOrErr = symbols(Sec);
608 return SymsOrErr.takeError();
610 Elf_Sym_Range Symbols = *SymsOrErr;
611 if (
Index >= Symbols.size())
612 return createError(
"unable to get symbol from section " +
614 ": invalid symbol index (" +
Twine(
Index) +
")");
615 return &Symbols[
Index];
622 if (Sec.sh_entsize !=
sizeof(
T) &&
sizeof(
T) != 1)
624 " has invalid sh_entsize: expected " +
Twine(
sizeof(
T)) +
625 ", but got " +
Twine(Sec.sh_entsize));
627 uintX_t
Offset = Sec.sh_offset;
628 uintX_t
Size = Sec.sh_size;
630 if (
Size %
sizeof(
T))
632 " has an invalid sh_size (" +
Twine(
Size) +
633 ") which is not a multiple of its sh_entsize (" +
634 Twine(Sec.sh_entsize) +
")");
635 if (std::numeric_limits<uintX_t>::max() -
Offset <
Size)
639 ") that cannot be represented");
644 ") that is greater than the file size (0x" +
651 const T *Start =
reinterpret_cast<const T *
>(base() +
Offset);
658 uintX_t
Offset = Phdr.p_offset;
659 uintX_t
Size = Phdr.p_filesz;
661 if (std::numeric_limits<uintX_t>::max() -
Offset <
Size)
665 ") that cannot be represented");
670 ") that is greater than the file size (0x" +
678 return getSectionContentsAsArray<uint8_t>(Sec);
689 if (!isMipsELF64()) {
691 Result.append(
Name.begin(),
Name.end());
705 Result.append(
Name.begin(),
Name.end());
708 Result.append(1,
'/');
709 Result.append(
Name.begin(),
Name.end());
712 Result.append(1,
'/');
713 Result.append(
Name.begin(),
Name.end());
725 const Elf_Shdr *VerDefSec)
const {
734 if (
N >= VersionMap.
size())
736 VersionMap[
N] = {std::string(
Version), IsVerdef};
743 for (
const VerDef &Def : *Defs)
751 for (
const VerNeed &Dep : *Deps)
752 for (
const VernAux &Aux : Dep.AuxV)
762 const Elf_Shdr *SymTab)
const {
766 return getEntry<Elf_Sym>(*SymTab,
Index);
779 if (Sections.empty())
781 "e_shstrndx == SHN_XINDEX, but the section header table is empty");
783 Index = Sections[0].sh_link;
789 return FakeSectionStrings;
791 if (
Index >= Sections.size())
794 return getStringTable(Sections[
Index], WarnHandler);
803 const void *BufEnd) {
804 using Elf_Word =
typename ELFT::Word;
805 if (Table.nbuckets == 0)
806 return Table.symndx + 1;
809 for (Elf_Word Val : Table.buckets())
810 LastSymIdx = std::max(LastSymIdx, (
uint64_t)Val);
812 reinterpret_cast<const Elf_Word *
>(Table.values(LastSymIdx).end());
814 while (It < BufEnd && (*It & 1) == 0) {
821 "no terminator found for GNU hash section before buffer end");
823 return LastSymIdx + 1;
833 if (!SectionsOrError)
835 for (
const Elf_Shdr &Sec : *SectionsOrError) {
837 if (Sec.sh_size % Sec.sh_entsize != 0) {
839 "SHT_DYNSYM section has sh_size (" +
840 Twine(Sec.sh_size) +
") % sh_entsize (" +
841 Twine(Sec.sh_entsize) +
") that is not 0");
843 return Sec.sh_size / Sec.sh_entsize;
847 if (!SectionsOrError->empty()) {
858 std::optional<uint64_t> ElfHash;
859 std::optional<uint64_t> ElfGnuHash;
860 for (
const Elf_Dyn &Entry : *DynTable) {
861 switch (Entry.d_tag) {
863 ElfHash = Entry.d_un.d_ptr;
865 case ELF::DT_GNU_HASH:
866 ElfGnuHash = Entry.d_un.d_ptr;
874 const Elf_GnuHash *Table =
875 reinterpret_cast<const Elf_GnuHash *
>(TablePtr.
get());
876 return getDynSymtabSizeFromGnuHash<ELFT>(*Table, this->Buf.
bytes_end());
884 const Elf_Hash *Table =
reinterpret_cast<const Elf_Hash *
>(TablePtr.
get());
885 return Table->nchain;
894 if (
sizeof(Elf_Ehdr) > Object.size())
896 ") is smaller than an ELF header (" +
897 Twine(
sizeof(Elf_Ehdr)) +
")");
905 if (!FakeSections.empty())
907 auto PhdrsOrErr = program_headers();
911 FakeSectionStrings +=
'\0';
915 Elf_Shdr FakeShdr = {};
918 FakeShdr.sh_addr = Phdr.p_vaddr;
919 FakeShdr.sh_size = Phdr.p_memsz;
920 FakeShdr.sh_offset = Phdr.p_offset;
922 FakeShdr.sh_name = FakeSectionStrings.
size();
923 FakeSectionStrings += (
"PT_LOAD#" +
Twine(
Idx)).str();
924 FakeSectionStrings +=
'\0';
931 const uintX_t SectionTableOffset = getHeader().e_shoff;
932 if (SectionTableOffset == 0) {
933 if (!FakeSections.empty())
938 if (getHeader().e_shentsize !=
sizeof(Elf_Shdr))
939 return createError(
"invalid e_shentsize in ELF header: " +
940 Twine(getHeader().e_shentsize));
943 if (SectionTableOffset +
sizeof(Elf_Shdr) > FileSize ||
944 SectionTableOffset + (uintX_t)
sizeof(Elf_Shdr) < SectionTableOffset)
946 "section header table goes past the end of the file: e_shoff = 0x" +
950 if (SectionTableOffset & (
alignof(Elf_Shdr) - 1))
952 return createError(
"invalid alignment of section headers");
954 const Elf_Shdr *
First =
955 reinterpret_cast<const Elf_Shdr *
>(base() + SectionTableOffset);
957 uintX_t NumSections = getHeader().e_shnum;
958 if (NumSections == 0)
959 NumSections =
First->sh_size;
961 if (NumSections >
UINT64_MAX /
sizeof(Elf_Shdr))
962 return createError(
"invalid number of sections specified in the NULL "
963 "section's sh_size field (" +
964 Twine(NumSections) +
")");
966 const uint64_t SectionTableSize = NumSections *
sizeof(Elf_Shdr);
967 if (SectionTableOffset + SectionTableSize < SectionTableOffset)
969 "invalid section header table offset (e_shoff = 0x" +
971 ") or invalid number of sections specified in the first section "
972 "header's sh_size field (0x" +
976 if (SectionTableOffset + SectionTableSize > FileSize)
977 return createError(
"section table goes past the end of file");
987 return SecOrErr.takeError();
988 return getEntry<T>(**SecOrErr, Entry);
1000 if (Entry >= Arr.
size())
1002 "can't read an entry at 0x" +
1004 ": it goes past the end of the section (0x" +
1009template <
typename ELFT>
1011 uint32_t SymbolVersionIndex,
bool &IsDefault,
1012 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
1013 std::optional<bool> IsSymHidden)
const {
1024 if (VersionIndex >= VersionMap.size() || !VersionMap[VersionIndex])
1025 return createError(
"SHT_GNU_versym section refers to a version index " +
1026 Twine(VersionIndex) +
" which is missing");
1030 if (!Entry.IsVerDef || IsSymHidden.value_or(
false))
1034 return Entry.Name.c_str();
1037template <
class ELFT>
1049 const uint8_t *Start = ContentsOrErr->data();
1050 const uint8_t *
End = Start + ContentsOrErr->size();
1052 auto ExtractNextAux = [&](
const uint8_t *&VerdauxBuf,
1054 if (VerdauxBuf +
sizeof(Elf_Verdaux) >
End)
1056 ": version definition " +
Twine(VerDefNdx) +
1057 " refers to an auxiliary entry that goes past the end "
1060 auto *Verdaux =
reinterpret_cast<const Elf_Verdaux *
>(VerdauxBuf);
1061 VerdauxBuf += Verdaux->vda_next;
1064 Aux.
Offset = VerdauxBuf - Start;
1065 if (Verdaux->vda_name < StrTabOrErr->size())
1066 Aux.
Name = std::string(StrTabOrErr->drop_front(Verdaux->vda_name).data());
1068 Aux.
Name = (
"<invalid vda_name: " +
Twine(Verdaux->vda_name) +
">").str();
1072 std::vector<VerDef> Ret;
1073 const uint8_t *VerdefBuf = Start;
1074 for (
unsigned I = 1;
I <= Sec.sh_info; ++
I) {
1075 if (VerdefBuf +
sizeof(Elf_Verdef) >
End)
1077 ": version definition " +
Twine(
I) +
1078 " goes past the end of the section");
1080 if (
reinterpret_cast<uintptr_t
>(VerdefBuf) %
sizeof(
uint32_t) != 0)
1082 "invalid " +
describe(*
this, Sec) +
1083 ": found a misaligned version definition entry at offset 0x" +
1086 unsigned Version = *
reinterpret_cast<const Elf_Half *
>(VerdefBuf);
1090 " is not yet supported");
1092 const Elf_Verdef *
D =
reinterpret_cast<const Elf_Verdef *
>(VerdefBuf);
1093 VerDef &VD = *Ret.emplace(Ret.end());
1094 VD.
Offset = VerdefBuf - Start;
1099 VD.
Hash =
D->vd_hash;
1101 const uint8_t *VerdauxBuf = VerdefBuf +
D->vd_aux;
1102 for (
unsigned J = 0; J <
D->vd_cnt; ++J) {
1103 if (
reinterpret_cast<uintptr_t
>(VerdauxBuf) %
sizeof(
uint32_t) != 0)
1105 ": found a misaligned auxiliary entry at offset 0x" +
1113 VD.
Name = AuxOrErr->Name;
1115 VD.
AuxV.push_back(*AuxOrErr);
1118 VerdefBuf +=
D->vd_next;
1124template <
class ELFT>
1132 return std::move(
E);
1134 StrTab = *StrTabOrErr;
1142 const uint8_t *Start = ContentsOrErr->data();
1143 const uint8_t *
End = Start + ContentsOrErr->size();
1144 const uint8_t *VerneedBuf = Start;
1146 std::vector<VerNeed> Ret;
1147 for (
unsigned I = 1;
I <= Sec.sh_info; ++
I) {
1148 if (VerneedBuf +
sizeof(Elf_Verdef) >
End)
1150 ": version dependency " +
Twine(
I) +
1151 " goes past the end of the section");
1153 if (
reinterpret_cast<uintptr_t
>(VerneedBuf) %
sizeof(
uint32_t) != 0)
1155 "invalid " +
describe(*
this, Sec) +
1156 ": found a misaligned version dependency entry at offset 0x" +
1159 unsigned Version = *
reinterpret_cast<const Elf_Half *
>(VerneedBuf);
1163 " is not yet supported");
1165 const Elf_Verneed *Verneed =
1166 reinterpret_cast<const Elf_Verneed *
>(VerneedBuf);
1168 VerNeed &VN = *Ret.emplace(Ret.end());
1169 VN.
Version = Verneed->vn_version;
1170 VN.
Cnt = Verneed->vn_cnt;
1171 VN.
Offset = VerneedBuf - Start;
1173 if (Verneed->vn_file < StrTab.
size())
1174 VN.
File = std::string(StrTab.
data() + Verneed->vn_file);
1176 VN.
File = (
"<corrupt vn_file: " +
Twine(Verneed->vn_file) +
">").str();
1178 const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux;
1179 for (
unsigned J = 0; J < Verneed->vn_cnt; ++J) {
1180 if (
reinterpret_cast<uintptr_t
>(VernauxBuf) %
sizeof(
uint32_t) != 0)
1182 ": found a misaligned auxiliary entry at offset 0x" +
1185 if (VernauxBuf +
sizeof(Elf_Vernaux) >
End)
1187 "invalid " +
describe(*
this, Sec) +
": version dependency " +
1189 " refers to an auxiliary entry that goes past the end "
1192 const Elf_Vernaux *Vernaux =
1193 reinterpret_cast<const Elf_Vernaux *
>(VernauxBuf);
1196 Aux.
Hash = Vernaux->vna_hash;
1197 Aux.
Flags = Vernaux->vna_flags;
1198 Aux.
Other = Vernaux->vna_other;
1199 Aux.
Offset = VernauxBuf - Start;
1200 if (StrTab.
size() <= Vernaux->vna_name)
1201 Aux.
Name =
"<corrupt>";
1205 VernauxBuf += Vernaux->vna_next;
1207 VerneedBuf += Verneed->vn_next;
1212template <
class ELFT>
1217 return TableOrErr.takeError();
1218 return object::getSection<ELFT>(*TableOrErr,
Index);
1221template <
class ELFT>
1226 if (
Error E = WarnHandler(
"invalid sh_type for string table section " +
1228 ": expected SHT_STRTAB, but got " +
1230 getHeader().e_machine, Section.sh_type)))
1231 return std::move(
E);
1233 auto V = getSectionContentsAsArray<char>(Section);
1235 return V.takeError();
1238 return createError(
"SHT_STRTAB string table section " +
1240 if (
Data.back() !=
'\0')
1241 return createError(
"SHT_STRTAB string table section " +
1243 " is non-null terminated");
1247template <
class ELFT>
1252 return SectionsOrErr.takeError();
1253 return getSHNDXTable(Section, *SectionsOrErr);
1256template <
class ELFT>
1259 Elf_Shdr_Range Sections)
const {
1261 auto VOrErr = getSectionContentsAsArray<Elf_Word>(Section);
1263 return VOrErr.takeError();
1265 auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
1267 return SymTableOrErr.takeError();
1268 const Elf_Shdr &SymTable = **SymTableOrErr;
1272 "SHT_SYMTAB_SHNDX section is linked with " +
1274 " section (expected SHT_SYMTAB/SHT_DYNSYM)");
1276 uint64_t Syms = SymTable.sh_size /
sizeof(Elf_Sym);
1277 if (V.size() != Syms)
1279 " entries, but the symbol table associated has " +
1285template <
class ELFT>
1290 return SectionsOrErr.takeError();
1291 return getStringTableForSymtab(Sec, *SectionsOrErr);
1294template <
class ELFT>
1297 Elf_Shdr_Range Sections)
const {
1301 "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
1303 object::getSection<ELFT>(Sections, Sec.sh_link);
1306 return getStringTable(**SectionOrErr);
1309template <
class ELFT>
1314 if (!StrTabSecOrErr)
1320 return createError(
"invalid string table linked to " +
1323 return *StrTabOrErr;
1326template <
class ELFT>
1332 return SectionsOrErr.takeError();
1333 auto Table = getSectionStringTable(*SectionsOrErr, WarnHandler);
1335 return Table.takeError();
1339template <
class ELFT>
1347 " has an invalid sh_name (0x" +
1349 ") offset which goes past the end of the "
1350 "section name string table");
1361 H ^= (
H >> 24) & 0xf0;
1363 return H & 0x0fffffff;
1372 H = (
H << 5) +
H +
C;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
bbsections Prepares for basic block sections
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
COFF::MachineTypes Machine
#define LLVM_TEMPLATE_ABI
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.
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.
Expected< RelsOrRelas > decodeCrel(ArrayRef< uint8_t > Content) const
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< uint64_t > getCrelHeader(ArrayRef< uint8_t > Content) const
Expected< Elf_Dyn_Range > dynamicEntries() const
void createFakeSections()
Used by llvm-objdump -d (which needs sections for disassembly) to disassemble objects without a secti...
ELFFile(const ELFFile &)=default
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< RelsOrRelas > crels(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
std::pair< std::vector< Elf_Rel >, std::vector< Elf_Rela > > RelsOrRelas
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.
constexpr unsigned CREL_HDR_ADDEND
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
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)
static bool isSectionInSegment(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
Error createError(const Twine &Err)
LLVM_ABI 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.
LLVM_ABI uint32_t getELFRelativeRelocationType(uint32_t Machine)
LLVM_ABI StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type)
static std::string describe(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
uint32_t hashGnu(StringRef Name)
This function returns the hash value for a symbol in the .dynsym section for the GNU hash table.
static bool checkSectionOffsets(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
static std::string getPhdrIndexForError(const ELFFile< ELFT > &Obj, const typename ELFT::Phdr &Phdr)
static bool checkSectionVMA(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
@ 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)
uint32_t hashSysV(StringRef SymbolName)
This function returns the hash value for a symbol in the .dynsym section Name of the API remains cons...
static Error decodeCrel(ArrayRef< uint8_t > Content, function_ref< void(uint64_t, bool)> HdrHandler, function_ref< void(Elf_Crel_Impl< Is64 >)> EntryHandler)
static std::string getSecIndexForError(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
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 tuples (A, B,...
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.
const char * toString(DWARFSectionKind Kind)
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::conditional_t< Is64, uint64_t, uint32_t > uint
std::vector< VerdAux > AuxV
std::vector< VernAux > AuxV