13#ifndef LLVM_OBJECT_ELF_H
14#define LLVM_OBJECT_ELF_H
81inline std::pair<unsigned char, unsigned char>
100template <
class ELFT>
class ELFFile;
117 "the index is greater than or equal to the number of entries (" +
121 if (EntryStart +
sizeof(
T) >
BufEnd)
122 return createError(
"can't read past the end of the file");
134 const typename ELFT::Shdr &Sec) {
135 auto TableOrErr = Obj.sections();
137 return "[index " + std::to_string(&Sec - &TableOrErr->front()) +
"]";
143 return "[unknown index]";
148 unsigned SecNdx = &Sec - &
cantFail(Obj.sections()).front();
151 " section with index " +
Twine(SecNdx))
157 const typename ELFT::Phdr &Phdr) {
158 auto Headers = Obj.program_headers();
160 return (
"[index " +
Twine(&Phdr - &Headers->front()) +
"]").str();
163 return "[unknown index]";
172 const typename ELFT::Shdr &Sec) {
177 if (Sec.sh_offset < Phdr.p_offset)
181 if (Sec.sh_size == 0)
182 return (Sec.sh_offset + 1 <= Phdr.p_offset + Phdr.p_filesz);
183 return Sec.sh_offset + Sec.sh_size <= Phdr.p_offset + Phdr.p_filesz;
190 const typename ELFT::Shdr &Sec) {
194 if (Sec.sh_addr < Phdr.p_vaddr)
200 bool IsTbssInNonTLS = IsTbss && Phdr.p_type !=
ELF::PT_TLS;
202 if (Sec.sh_size == 0 || IsTbssInNonTLS)
203 return Sec.sh_addr + 1 <= Phdr.p_vaddr + Phdr.p_memsz;
204 return Sec.sh_addr + Sec.sh_size <= Phdr.p_vaddr + Phdr.p_memsz;
209 const typename ELFT::Shdr &Sec) {
225 size_t Count = Hdr / 8;
229 uint
Offset = 0, Addend = 0;
239 Offset += (
Data.getULEB128(Cur) << (7 - FlagBits)) - (0x80 >> FlagBits);
242 SymIdx +=
Data.getSLEB128(Cur);
246 Addend +=
Data.getSLEB128(Cur);
281 std::vector<Elf_Shdr> FakeSections;
286 std::optional<uint32_t> RealPhNum;
289 std::optional<uint64_t> RealShNum;
293 std::optional<uint32_t> RealShStrNdx;
297 Error readShdrZero();
338 return *RealShStrNdx;
343 return *RealShStrNdx;
347 return *
reinterpret_cast<const Elf_Ehdr *
>(
base());
350 template <
typename T>
352 template <
typename T>
361 uint32_t SymbolVersionIndex,
bool &IsDefault,
362 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
363 std::optional<bool> IsSymHidden)
const;
370 Elf_Shdr_Range Sections)
const;
375 Elf_Shdr_Range Sections)
const;
389 const Elf_Shdr *SymTab)
const;
436 using RelsOrRelas = std::pair<std::vector<Elf_Rel>, std::vector<Elf_Rela>>;
448 return PhNumOrErr.takeError();
449 if (NumPh &&
getHeader().e_phentsize !=
sizeof(Elf_Phdr))
455 if (PhOff + HeadersSize < PhOff || PhOff + HeadersSize >
getBufSize())
456 return createError(
"program headers are longer than binary of size " +
459 ", e_phnum = " +
Twine(NumPh) +
462 auto *Begin =
reinterpret_cast<const Elf_Phdr *
>(
base() + PhOff);
463 return ArrayRef(Begin, Begin + NumPh);
476 if (Phdr.p_offset + Phdr.p_filesz >
getBufSize() ||
477 Phdr.p_offset + Phdr.p_filesz < Phdr.p_offset) {
481 return Elf_Note_Iterator(Err);
485 if (Phdr.p_align != 0 && Phdr.p_align != 1 && Phdr.p_align != 4 &&
489 return Elf_Note_Iterator(Err);
491 return Elf_Note_Iterator(
base() + Phdr.p_offset, Phdr.p_filesz,
492 std::max<size_t>(Phdr.p_align, 4), Err);
505 if (Shdr.sh_offset + Shdr.sh_size >
getBufSize() ||
506 Shdr.sh_offset + Shdr.sh_size < Shdr.sh_offset) {
510 return Elf_Note_Iterator(Err);
513 if (Shdr.sh_addralign != 0 && Shdr.sh_addralign != 1 &&
514 Shdr.sh_addralign != 4 && Shdr.sh_addralign != 8) {
517 return Elf_Note_Iterator(Err);
519 return Elf_Note_Iterator(
base() + Shdr.sh_offset, Shdr.sh_size,
520 std::max<size_t>(Shdr.sh_addralign, 4), Err);
525 return Elf_Note_Iterator();
553 Elf_Shdr_Range Sections,
558 const Elf_Shdr *SymTab,
561 Elf_Sym_Range Symtab,
573 template <
typename T>
587 std::vector<PGOAnalysisMap> *PGOAnalyses =
nullptr)
const;
608 if (Index >= Sections.size())
610 return &Sections[Index];
618 if (!ShndxTable.
First)
620 "found an extended symbol index (" +
Twine(SymIndex) +
621 "), but unable to locate the extended symbol index table");
625 return createError(
"unable to read an extended symbol table at index " +
626 Twine(SymIndex) +
": " +
641 return *ErrorOrIndex;
652 auto SymsOrErr =
symbols(SymTab);
654 return SymsOrErr.takeError();
655 return getSection(Sym, *SymsOrErr, ShndxTable);
664 return IndexOrErr.takeError();
676 return SymsOrErr.takeError();
678 Elf_Sym_Range Symbols = *SymsOrErr;
679 if (Index >= Symbols.size())
680 return createError(
"unable to get symbol from section " +
682 ": invalid symbol index (" +
Twine(Index) +
")");
683 return &Symbols[Index];
690 if (Sec.sh_entsize !=
sizeof(
T) &&
sizeof(
T) != 1)
692 " has invalid sh_entsize: expected " +
Twine(
sizeof(
T)) +
693 ", but got " +
Twine(Sec.sh_entsize));
695 uintX_t
Offset = Sec.sh_offset;
696 uintX_t
Size = Sec.sh_size;
698 if (
Size %
sizeof(
T))
700 " has an invalid sh_size (" +
Twine(
Size) +
701 ") which is not a multiple of its sh_entsize (" +
702 Twine(Sec.sh_entsize) +
")");
703 if (std::numeric_limits<uintX_t>::max() -
Offset <
Size)
707 ") that cannot be represented");
712 ") that is greater than the file size (0x" +
719 const T *Start =
reinterpret_cast<const T *
>(
base() +
Offset);
726 uintX_t
Offset = Phdr.p_offset;
727 uintX_t
Size = Phdr.p_filesz;
729 if (std::numeric_limits<uintX_t>::max() -
Offset <
Size)
733 ") that cannot be represented");
738 ") that is greater than the file size (0x" +
759 Result.append(Name.begin(), Name.end());
773 Result.append(Name.begin(), Name.end());
776 Result.append(1,
'/');
777 Result.append(Name.begin(), Name.end());
780 Result.append(1,
'/');
781 Result.append(Name.begin(), Name.end());
793 const Elf_Shdr *VerDefSec)
const {
802 if (
N >= VersionMap.
size())
804 VersionMap[
N] = {std::string(
Version), IsVerdef};
811 for (
const VerDef &Def : *Defs)
819 for (
const VerNeed &Dep : *Deps)
820 for (
const VernAux &Aux : Dep.AuxV)
830 const Elf_Shdr *SymTab)
const {
844 "e_shstrndx == SHN_XINDEX, but cannot read section header 0: " +
851 return FakeSectionStrings;
853 if (Index >= Sections.size())
865 const void *BufEnd) {
866 using Elf_Word =
typename ELFT::Word;
867 if (Table.nbuckets == 0)
868 return Table.symndx + 1;
871 for (Elf_Word Val : Table.buckets())
872 LastSymIdx = std::max(LastSymIdx, (
uint64_t)Val);
874 reinterpret_cast<const Elf_Word *
>(Table.values(LastSymIdx).end());
876 while (It < BufEnd && (*It & 1) == 0) {
883 "no terminator found for GNU hash section before buffer end");
885 return LastSymIdx + 1;
895 if (!SectionsOrError)
897 for (
const Elf_Shdr &Sec : *SectionsOrError) {
899 if (Sec.sh_size % Sec.sh_entsize != 0) {
901 "SHT_DYNSYM section has sh_size (" +
902 Twine(Sec.sh_size) +
") % sh_entsize (" +
903 Twine(Sec.sh_entsize) +
") that is not 0");
905 return Sec.sh_size / Sec.sh_entsize;
909 if (!SectionsOrError->empty()) {
920 std::optional<uint64_t> ElfHash;
921 std::optional<uint64_t> ElfGnuHash;
922 for (
const Elf_Dyn &Entry : *DynTable) {
923 switch (Entry.d_tag) {
925 ElfHash = Entry.d_un.d_ptr;
927 case ELF::DT_GNU_HASH:
928 ElfGnuHash = Entry.d_un.d_ptr;
936 const Elf_GnuHash *Table =
937 reinterpret_cast<const Elf_GnuHash *
>(TablePtr.
get());
946 const Elf_Hash *Table =
reinterpret_cast<const Elf_Hash *
>(TablePtr.
get());
947 return Table->nchain;
954template <
class ELFT>
Error ELFFile<ELFT>::readShdrZero() {
955 const Elf_Ehdr &Header = getHeader();
967 (Header.e_shnum == 0 && Header.e_shoff != 0) ||
974 if (Header.e_shnum != 0)
975 RealShNum = Header.e_shnum;
977 RealShNum = std::nullopt;
979 RealPhNum = Header.e_phnum;
981 RealShStrNdx = Header.e_shstrndx;
982 return SecOrErr.takeError();
986 Header.e_phnum ==
ELF::PN_XNUM ? (*SecOrErr)->sh_info : Header.e_phnum;
987 RealShNum = Header.e_shnum == 0 ? (*SecOrErr)->sh_size : Header.e_shnum;
988 RealShStrNdx = Header.e_shstrndx ==
ELF::SHN_XINDEX ? (*SecOrErr)->sh_link
991 RealPhNum = Header.e_phnum;
992 RealShNum = Header.e_shnum;
993 RealShStrNdx = Header.e_shstrndx;
1001 if (
sizeof(Elf_Ehdr) > Object.size())
1003 ") is smaller than an ELF header (" +
1004 Twine(
sizeof(Elf_Ehdr)) +
")");
1012 if (!FakeSections.empty())
1018 FakeSectionStrings +=
'\0';
1022 Elf_Shdr FakeShdr = {};
1025 FakeShdr.sh_addr = Phdr.p_vaddr;
1026 FakeShdr.sh_size = Phdr.p_memsz;
1027 FakeShdr.sh_offset = Phdr.p_offset;
1029 FakeShdr.sh_name = FakeSectionStrings.size();
1030 FakeSectionStrings += (
"PT_LOAD#" +
Twine(Idx)).str();
1031 FakeSectionStrings +=
'\0';
1032 FakeSections.push_back(FakeShdr);
1036template <
class ELFT>
1038 const uintX_t SectionTableOffset =
getHeader().e_shoff;
1039 if (SectionTableOffset == 0) {
1040 if (!FakeSections.empty())
1045 if (
getHeader().e_shentsize !=
sizeof(Elf_Shdr))
1046 return createError(
"invalid e_shentsize in ELF header: " +
1049 const uint64_t FileSize = Buf.size();
1050 if (SectionTableOffset +
sizeof(Elf_Shdr) > FileSize ||
1051 SectionTableOffset + (uintX_t)
sizeof(Elf_Shdr) < SectionTableOffset)
1053 "section header table goes past the end of the file: e_shoff = 0x" +
1057 if (SectionTableOffset & (
alignof(Elf_Shdr) - 1))
1059 return createError(
"invalid alignment of section headers");
1061 const Elf_Shdr *
First =
1062 reinterpret_cast<const Elf_Shdr *
>(
base() + SectionTableOffset);
1064 uintX_t NumSections = 0;
1066 NumSections = *ShNumOrErr;
1068 return ShNumOrErr.takeError();
1070 if (NumSections >
UINT64_MAX /
sizeof(Elf_Shdr))
1071 return createError(
"invalid number of sections specified in the NULL "
1072 "section's sh_size field (" +
1073 Twine(NumSections) +
")");
1075 const uint64_t SectionTableSize = NumSections *
sizeof(Elf_Shdr);
1076 if (SectionTableOffset + SectionTableSize < SectionTableOffset)
1078 "invalid section header table offset (e_shoff = 0x" +
1080 ") or invalid number of sections specified in the first section "
1081 "header's sh_size field (0x" +
1085 if (SectionTableOffset + SectionTableSize > FileSize)
1086 return createError(
"section table goes past the end of file");
1090template <
class ELFT>
1091template <
typename T>
1096 return SecOrErr.takeError();
1100template <
class ELFT>
1101template <
typename T>
1109 if (Entry >= Arr.
size())
1111 "can't read an entry at 0x" +
1113 ": it goes past the end of the section (0x" +
1118template <
typename ELFT>
1120 uint32_t SymbolVersionIndex,
bool &IsDefault,
1121 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
1122 std::optional<bool> IsSymHidden)
const {
1133 if (VersionIndex >= VersionMap.size() || !VersionMap[VersionIndex])
1134 return createError(
"SHT_GNU_versym section refers to a version index " +
1135 Twine(VersionIndex) +
" which is missing");
1139 if (!Entry.IsVerDef || IsSymHidden.value_or(
false))
1143 return Entry.Name.c_str();
1146template <
class ELFT>
1158 const uint8_t *Start = ContentsOrErr->data();
1159 const uint8_t *End = Start + ContentsOrErr->size();
1161 auto ExtractNextAux = [&](
const uint8_t *&VerdauxBuf,
1163 if (VerdauxBuf +
sizeof(Elf_Verdaux) > End)
1165 ": version definition " +
Twine(VerDefNdx) +
1166 " refers to an auxiliary entry that goes past the end "
1169 auto *Verdaux =
reinterpret_cast<const Elf_Verdaux *
>(VerdauxBuf);
1170 VerdauxBuf += Verdaux->vda_next;
1173 Aux.
Offset = VerdauxBuf - Start;
1174 if (Verdaux->vda_name < StrTabOrErr->size())
1175 Aux.
Name = std::string(StrTabOrErr->drop_front(Verdaux->vda_name).data());
1177 Aux.
Name = (
"<invalid vda_name: " +
Twine(Verdaux->vda_name) +
">").str();
1181 std::vector<VerDef> Ret;
1182 const uint8_t *VerdefBuf = Start;
1183 for (
unsigned I = 1;
I <= Sec.sh_info; ++
I) {
1184 if (VerdefBuf +
sizeof(Elf_Verdef) > End)
1186 ": version definition " +
Twine(
I) +
1187 " goes past the end of the section");
1191 "invalid " +
describe(*
this, Sec) +
1192 ": found a misaligned version definition entry at offset 0x" +
1195 unsigned Version = *
reinterpret_cast<const Elf_Half *
>(VerdefBuf);
1199 " is not yet supported");
1201 const Elf_Verdef *
D =
reinterpret_cast<const Elf_Verdef *
>(VerdefBuf);
1202 VerDef &VD = *Ret.emplace(Ret.end());
1203 VD.
Offset = VerdefBuf - Start;
1208 VD.
Hash =
D->vd_hash;
1210 const uint8_t *VerdauxBuf = VerdefBuf +
D->vd_aux;
1211 for (
unsigned J = 0; J <
D->vd_cnt; ++J) {
1214 ": found a misaligned auxiliary entry at offset 0x" +
1222 VD.
Name = AuxOrErr->Name;
1224 VD.
AuxV.push_back(*AuxOrErr);
1227 VerdefBuf +=
D->vd_next;
1233template <
class ELFT>
1241 return std::move(
E);
1243 StrTab = *StrTabOrErr;
1251 const uint8_t *Start = ContentsOrErr->data();
1252 const uint8_t *End = Start + ContentsOrErr->size();
1253 const uint8_t *VerneedBuf = Start;
1255 std::vector<VerNeed> Ret;
1256 for (
unsigned I = 1;
I <= Sec.sh_info; ++
I) {
1257 if (VerneedBuf +
sizeof(Elf_Verdef) > End)
1259 ": version dependency " +
Twine(
I) +
1260 " goes past the end of the section");
1264 "invalid " +
describe(*
this, Sec) +
1265 ": found a misaligned version dependency entry at offset 0x" +
1268 unsigned Version = *
reinterpret_cast<const Elf_Half *
>(VerneedBuf);
1272 " is not yet supported");
1274 const Elf_Verneed *Verneed =
1275 reinterpret_cast<const Elf_Verneed *
>(VerneedBuf);
1277 VerNeed &VN = *Ret.emplace(Ret.end());
1278 VN.
Version = Verneed->vn_version;
1279 VN.
Cnt = Verneed->vn_cnt;
1280 VN.
Offset = VerneedBuf - Start;
1282 if (Verneed->vn_file < StrTab.
size())
1283 VN.
File = std::string(StrTab.
data() + Verneed->vn_file);
1285 VN.
File = (
"<corrupt vn_file: " +
Twine(Verneed->vn_file) +
">").str();
1287 const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux;
1288 for (
unsigned J = 0; J < Verneed->vn_cnt; ++J) {
1291 ": found a misaligned auxiliary entry at offset 0x" +
1294 if (VernauxBuf +
sizeof(Elf_Vernaux) > End)
1296 "invalid " +
describe(*
this, Sec) +
": version dependency " +
1298 " refers to an auxiliary entry that goes past the end "
1301 const Elf_Vernaux *Vernaux =
1302 reinterpret_cast<const Elf_Vernaux *
>(VernauxBuf);
1305 Aux.
Hash = Vernaux->vna_hash;
1306 Aux.
Flags = Vernaux->vna_flags;
1307 Aux.
Other = Vernaux->vna_other;
1308 Aux.
Offset = VernauxBuf - Start;
1309 if (StrTab.
size() <= Vernaux->vna_name)
1310 Aux.
Name =
"<corrupt>";
1314 VernauxBuf += Vernaux->vna_next;
1316 VerneedBuf += Verneed->vn_next;
1321template <
class ELFT>
1326 return TableOrErr.takeError();
1330template <
class ELFT>
1335 if (
Error E = WarnHandler(
"invalid sh_type for string table section " +
1337 ": expected SHT_STRTAB, but got " +
1339 getHeader().e_machine, Section.sh_type)))
1340 return std::move(
E);
1344 return V.takeError();
1347 return createError(
"SHT_STRTAB string table section " +
1349 if (
Data.back() !=
'\0')
1350 return createError(
"SHT_STRTAB string table section " +
1352 " is non-null terminated");
1356template <
class ELFT>
1361 return SectionsOrErr.takeError();
1365template <
class ELFT>
1368 Elf_Shdr_Range Sections)
const {
1372 return VOrErr.takeError();
1376 return SymTableOrErr.takeError();
1377 const Elf_Shdr &SymTable = **SymTableOrErr;
1381 "SHT_SYMTAB_SHNDX section is linked with " +
1383 " section (expected SHT_SYMTAB/SHT_DYNSYM)");
1385 uint64_t Syms = SymTable.sh_size /
sizeof(Elf_Sym);
1386 if (V.size() != Syms)
1388 " entries, but the symbol table associated has " +
1394template <
class ELFT>
1399 return SectionsOrErr.takeError();
1403template <
class ELFT>
1406 Elf_Shdr_Range Sections)
const {
1410 "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
1418template <
class ELFT>
1423 if (!StrTabSecOrErr)
1429 return createError(
"invalid string table linked to " +
1432 return *StrTabOrErr;
1435template <
class ELFT>
1441 return SectionsOrErr.takeError();
1444 return Table.takeError();
1448template <
class ELFT>
1456 " has an invalid sh_name (0x" +
1458 ") offset which goes past the end of the "
1459 "section name string table");
1470 H ^= (
H >> 24) & 0xf0;
1472 return H & 0x0fffffff;
1481 H = (
H << 5) +
H +
C;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_TEMPLATE_ABI
static bool isMips64EL(const ELFYAML::Object &Obj)
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
This file implements a map that provides insertion order iteration.
Function const char TargetMachine * Machine
This file defines the SmallString class.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Helper for Errors used as out-parameters.
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.
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.
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
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Twine utohexstr(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.
ELFFile(const ELFFile &)=default
llvm::function_ref< Error(const Twine &Msg)> WarningHandler
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_Shdr * > getSection(uint32_t Index) const
Expected< StringRef > getSectionName(const Elf_Shdr &Section, StringRef DotShstrtab) const
Expected< ArrayRef< Elf_Word > > getSHNDXTable(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const
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< const Elf_Shdr * > getSection(const Elf_Sym &Sym, Elf_Sym_Range Symtab, DataRegion< Elf_Word > ShndxTable) const
Expected< Elf_Sym_Range > symbols(const Elf_Shdr *Sec) const
Expected< uint64_t > getShNum() 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< uint32_t > getShStrNdx() const
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
void getRelocationTypeName(uint32_t Type, SmallVectorImpl< char > &Result) 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< const T * > getEntry(const Elf_Shdr &Section, uint32_t Entry) const
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 ...
std::string getDynamicTagAsString(uint64_t Type) const
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< uint32_t > getPhNum() const
Expected< StringRef > getStringTableForSymtab(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const
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
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
std::pair< std::vector< Elf_Rel >, std::vector< Elf_Rela > > RelsOrRelas
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)
Error decodeCrel(ArrayRef< uint8_t > Content, function_ref< void(uint64_t, bool)> HdrHandler, function_ref< void(Elf_Crel_Impl< Is64 >)> EntryHandler)
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Error createError(const Twine &Err)
LLVM_ABI StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
bool checkSectionOffsets(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
LLVM_ABI uint32_t getELFRelativeRelocationType(uint32_t Machine)
LLVM_ABI StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type)
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.
LLVM_ABI StringRef getRISCVVendorRelocationTypeName(uint32_t Type, StringRef Vendor)
@ 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)
ELFFile< ELF32LE > ELF32LEFile
bool checkSectionVMA(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
ELFFile< ELF64BE > ELF64BEFile
ELFFile< ELF32BE > ELF32BEFile
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...
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.
std::string describe(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
ELFFile< ELF64LE > ELF64LEFile
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
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