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) {
 
 
  224  size_t Count = Hdr / 8;
 
  228  uint 
Offset = 0, Addend = 0;
 
  238      Offset += (
Data.getULEB128(Cur) << (7 - FlagBits)) - (0x80 >> FlagBits);
 
  241      SymIdx += 
Data.getSLEB128(Cur);
 
  245      Addend += 
Data.getSLEB128(Cur);
 
 
  278  std::vector<Elf_Shdr> FakeSections;
 
  283  std::optional<uint32_t> RealPhNum;
 
  286  std::optional<uint64_t> RealShNum;
 
  290  std::optional<uint32_t> RealShStrNdx;
 
  294  Error readShdrZero();
 
  318    return *RealShStrNdx;
 
 
  322    return *
reinterpret_cast<const Elf_Ehdr *
>(
base());
 
 
  325  template <
typename T>
 
  327  template <
typename T>
 
  336      uint32_t SymbolVersionIndex, 
bool &IsDefault,
 
  337      SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
 
  338      std::optional<bool> IsSymHidden) 
const;
 
  345                                              Elf_Shdr_Range Sections) 
const;
 
  350                                             Elf_Shdr_Range Sections) 
const;
 
  364                                                const Elf_Shdr *SymTab) 
const;
 
  411  using RelsOrRelas = std::pair<std::vector<Elf_Rel>, std::vector<Elf_Rela>>;
 
  423      return PhNumOrErr.takeError();
 
  424    if (NumPh && 
getHeader().e_phentsize != 
sizeof(Elf_Phdr))
 
  430    if (PhOff + HeadersSize < PhOff || PhOff + HeadersSize > 
getBufSize())
 
  431      return createError(
"program headers are longer than binary of size " +
 
  434                         ", e_phnum = " + 
Twine(NumPh) +
 
  437    auto *Begin = 
reinterpret_cast<const Elf_Phdr *
>(
base() + PhOff);
 
  438    return ArrayRef(Begin, Begin + NumPh);
 
 
  451    if (Phdr.p_offset + Phdr.p_filesz > 
getBufSize() ||
 
  452        Phdr.p_offset + Phdr.p_filesz < Phdr.p_offset) {
 
  456      return Elf_Note_Iterator(Err);
 
  460    if (Phdr.p_align != 0 && Phdr.p_align != 1 && Phdr.p_align != 4 &&
 
  464      return Elf_Note_Iterator(Err);
 
  466    return Elf_Note_Iterator(
base() + Phdr.p_offset, Phdr.p_filesz,
 
  467                             std::max<size_t>(Phdr.p_align, 4), Err);
 
 
  480    if (Shdr.sh_offset + Shdr.sh_size > 
getBufSize() ||
 
  481        Shdr.sh_offset + Shdr.sh_size < Shdr.sh_offset) {
 
  485      return Elf_Note_Iterator(Err);
 
  488    if (Shdr.sh_addralign != 0 && Shdr.sh_addralign != 1 &&
 
  489        Shdr.sh_addralign != 4 && Shdr.sh_addralign != 8) {
 
  492      return Elf_Note_Iterator(Err);
 
  494    return Elf_Note_Iterator(
base() + Shdr.sh_offset, Shdr.sh_size,
 
  495                             std::max<size_t>(Shdr.sh_addralign, 4), Err);
 
 
  500    return Elf_Note_Iterator();
 
 
  528      Elf_Shdr_Range Sections,
 
  533                                        const Elf_Shdr *SymTab,
 
  536                                        Elf_Sym_Range Symtab,
 
  548  template <
typename T>
 
  562                  std::vector<PGOAnalysisMap> *PGOAnalyses = 
nullptr) 
const;
 
 
  583  if (Index >= Sections.size())
 
  585  return &Sections[Index];
 
 
  593  if (!ShndxTable.
First)
 
  595        "found an extended symbol index (" + 
Twine(SymIndex) +
 
  596        "), but unable to locate the extended symbol index table");
 
  600    return createError(
"unable to read an extended symbol table at index " +
 
  601                       Twine(SymIndex) + 
": " +
 
 
  616    return *ErrorOrIndex;
 
 
  627  auto SymsOrErr = 
symbols(SymTab);
 
  629    return SymsOrErr.takeError();
 
  630  return getSection(Sym, *SymsOrErr, ShndxTable);
 
 
  639    return IndexOrErr.takeError();
 
 
  651    return SymsOrErr.takeError();
 
  653  Elf_Sym_Range Symbols = *SymsOrErr;
 
  654  if (Index >= Symbols.size())
 
  655    return createError(
"unable to get symbol from section " +
 
  657                       ": invalid symbol index (" + 
Twine(Index) + 
")");
 
  658  return &Symbols[Index];
 
 
  665  if (Sec.sh_entsize != 
sizeof(
T) && 
sizeof(
T) != 1)
 
  667                       " has invalid sh_entsize: expected " + 
Twine(
sizeof(
T)) +
 
  668                       ", but got " + 
Twine(Sec.sh_entsize));
 
  670  uintX_t 
Offset = Sec.sh_offset;
 
  671  uintX_t 
Size = Sec.sh_size;
 
  673  if (
Size % 
sizeof(
T))
 
  675                       " has an invalid sh_size (" + 
Twine(
Size) +
 
  676                       ") which is not a multiple of its sh_entsize (" +
 
  677                       Twine(Sec.sh_entsize) + 
")");
 
  678  if (std::numeric_limits<uintX_t>::max() - 
Offset < 
Size)
 
  682                       ") that cannot be represented");
 
  687                       ") that is greater than the file size (0x" +
 
  694  const T *Start = 
reinterpret_cast<const T *
>(
base() + 
Offset);
 
 
  701  uintX_t 
Offset = Phdr.p_offset;
 
  702  uintX_t 
Size = Phdr.p_filesz;
 
  704  if (std::numeric_limits<uintX_t>::max() - 
Offset < 
Size)
 
  708                       ") that cannot be represented");
 
  713                       ") that is greater than the file size (0x" +
 
 
  734    Result.append(Name.begin(), Name.end());
 
  748    Result.append(Name.begin(), Name.end());
 
  751    Result.append(1, 
'/');
 
  752    Result.append(Name.begin(), Name.end());
 
  755    Result.append(1, 
'/');
 
  756    Result.append(Name.begin(), Name.end());
 
 
  768                              const Elf_Shdr *VerDefSec)
 const {
 
  777    if (
N >= VersionMap.
size())
 
  779    VersionMap[
N] = {std::string(
Version), IsVerdef};
 
  786    for (
const VerDef &Def : *Defs)
 
  794    for (
const VerNeed &Dep : *Deps)
 
  795      for (
const VernAux &Aux : Dep.AuxV)
 
 
  805                                   const Elf_Shdr *SymTab)
 const {
 
 
  822        "e_shstrndx == SHN_XINDEX, but the section header table is empty");
 
  828    return FakeSectionStrings;
 
  830  if (Index >= Sections.size())
 
 
  842                            const void *BufEnd) {
 
  843  using Elf_Word = 
typename ELFT::Word;
 
  844  if (Table.nbuckets == 0)
 
  845    return Table.symndx + 1;
 
  848  for (Elf_Word Val : Table.buckets())
 
  849    LastSymIdx = std::max(LastSymIdx, (
uint64_t)Val);
 
  851      reinterpret_cast<const Elf_Word *
>(Table.values(LastSymIdx).end());
 
  853  while (It < BufEnd && (*It & 1) == 0) {
 
  860        "no terminator found for GNU hash section before buffer end");
 
  862  return LastSymIdx + 1;
 
 
  872  if (!SectionsOrError)
 
  874  for (
const Elf_Shdr &Sec : *SectionsOrError) {
 
  876      if (Sec.sh_size % Sec.sh_entsize != 0) {
 
  878                                 "SHT_DYNSYM section has sh_size (" +
 
  879                                     Twine(Sec.sh_size) + 
") % sh_entsize (" +
 
  880                                     Twine(Sec.sh_entsize) + 
") that is not 0");
 
  882      return Sec.sh_size / Sec.sh_entsize;
 
  886  if (!SectionsOrError->empty()) {
 
  897  std::optional<uint64_t> ElfHash;
 
  898  std::optional<uint64_t> ElfGnuHash;
 
  899  for (
const Elf_Dyn &Entry : *DynTable) {
 
  900    switch (Entry.d_tag) {
 
  902      ElfHash = Entry.d_un.d_ptr;
 
  904    case ELF::DT_GNU_HASH:
 
  905      ElfGnuHash = Entry.d_un.d_ptr;
 
  913    const Elf_GnuHash *Table =
 
  914        reinterpret_cast<const Elf_GnuHash *
>(TablePtr.
get());
 
  923    const Elf_Hash *Table = 
reinterpret_cast<const Elf_Hash *
>(TablePtr.
get());
 
  924    return Table->nchain;
 
 
  931template <
class ELFT> 
Error ELFFile<ELFT>::readShdrZero() {
 
  932  const Elf_Ehdr &Header = getHeader();
 
  934  if ((Header.e_phnum == 
ELF::PN_XNUM || Header.e_shnum == 0 ||
 
  936      Header.e_shoff != 0) {
 
  942      RealShNum = std::nullopt;
 
  943      return SecOrErr.takeError();
 
  947        Header.e_phnum == 
ELF::PN_XNUM ? (*SecOrErr)->sh_info : Header.e_phnum;
 
  948    RealShNum = Header.e_shnum == 0 ? (*SecOrErr)->sh_size : Header.e_shnum;
 
  949    RealShStrNdx = Header.e_shstrndx == 
ELF::SHN_XINDEX ? (*SecOrErr)->sh_link
 
  952    RealPhNum = Header.e_phnum;
 
  953    RealShNum = Header.e_shnum;
 
  954    RealShStrNdx = Header.e_shstrndx;
 
  962  if (
sizeof(Elf_Ehdr) > Object.size())
 
  964                       ") is smaller than an ELF header (" +
 
  965                       Twine(
sizeof(Elf_Ehdr)) + 
")");
 
 
  973  if (!FakeSections.empty())
 
  979  FakeSectionStrings += 
'\0';
 
  983    Elf_Shdr FakeShdr = {};
 
  986    FakeShdr.sh_addr = Phdr.p_vaddr;
 
  987    FakeShdr.sh_size = Phdr.p_memsz;
 
  988    FakeShdr.sh_offset = Phdr.p_offset;
 
  990    FakeShdr.sh_name = FakeSectionStrings.size();
 
  991    FakeSectionStrings += (
"PT_LOAD#" + 
Twine(Idx)).str();
 
  992    FakeSectionStrings += 
'\0';
 
  993    FakeSections.push_back(FakeShdr);
 
 
  999  const uintX_t SectionTableOffset = 
getHeader().e_shoff;
 
 1000  if (SectionTableOffset == 0) {
 
 1001    if (!FakeSections.empty())
 
 1006  if (
getHeader().e_shentsize != 
sizeof(Elf_Shdr))
 
 1007    return createError(
"invalid e_shentsize in ELF header: " +
 
 1010  const uint64_t FileSize = Buf.size();
 
 1011  if (SectionTableOffset + 
sizeof(Elf_Shdr) > FileSize ||
 
 1012      SectionTableOffset + (uintX_t)
sizeof(Elf_Shdr) < SectionTableOffset)
 
 1014        "section header table goes past the end of the file: e_shoff = 0x" +
 
 1018  if (SectionTableOffset & (
alignof(Elf_Shdr) - 1))
 
 1020    return createError(
"invalid alignment of section headers");
 
 1022  const Elf_Shdr *
First =
 
 1023      reinterpret_cast<const Elf_Shdr *
>(
base() + SectionTableOffset);
 
 1025  uintX_t NumSections = 0;
 
 1027    NumSections = *ShNumOrErr;
 
 1029    return ShNumOrErr.takeError();
 
 1031  if (NumSections > 
UINT64_MAX / 
sizeof(Elf_Shdr))
 
 1032    return createError(
"invalid number of sections specified in the NULL " 
 1033                       "section's sh_size field (" +
 
 1034                       Twine(NumSections) + 
")");
 
 1036  const uint64_t SectionTableSize = NumSections * 
sizeof(Elf_Shdr);
 
 1037  if (SectionTableOffset + SectionTableSize < SectionTableOffset)
 
 1039        "invalid section header table offset (e_shoff = 0x" +
 
 1041        ") or invalid number of sections specified in the first section " 
 1042        "header's sh_size field (0x" +
 
 1046  if (SectionTableOffset + SectionTableSize > FileSize)
 
 1047    return createError(
"section table goes past the end of file");
 
 
 1051template <
class ELFT>
 
 1052template <
typename T>
 
 1057    return SecOrErr.takeError();
 
 
 1061template <
class ELFT>
 
 1062template <
typename T>
 
 1070  if (Entry >= Arr.
size())
 
 1072        "can't read an entry at 0x" +
 
 1074        ": it goes past the end of the section (0x" +
 
 
 1079template <
typename ELFT>
 
 1081    uint32_t SymbolVersionIndex, 
bool &IsDefault,
 
 1082    SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
 
 1083    std::optional<bool> IsSymHidden)
 const {
 
 1094  if (VersionIndex >= VersionMap.size() || !VersionMap[VersionIndex])
 
 1095    return createError(
"SHT_GNU_versym section refers to a version index " +
 
 1096                       Twine(VersionIndex) + 
" which is missing");
 
 1100  if (!Entry.IsVerDef || IsSymHidden.value_or(
false))
 
 1104  return Entry.Name.c_str();
 
 
 1107template <
class ELFT>
 
 1119  const uint8_t *Start = ContentsOrErr->data();
 
 1120  const uint8_t *End = Start + ContentsOrErr->size();
 
 1122  auto ExtractNextAux = [&](
const uint8_t *&VerdauxBuf,
 
 1124    if (VerdauxBuf + 
sizeof(Elf_Verdaux) > End)
 
 1126                         ": version definition " + 
Twine(VerDefNdx) +
 
 1127                         " refers to an auxiliary entry that goes past the end " 
 1130    auto *Verdaux = 
reinterpret_cast<const Elf_Verdaux *
>(VerdauxBuf);
 
 1131    VerdauxBuf += Verdaux->vda_next;
 
 1134    Aux.
Offset = VerdauxBuf - Start;
 
 1135    if (Verdaux->vda_name < StrTabOrErr->size())
 
 1136      Aux.
Name = std::string(StrTabOrErr->drop_front(Verdaux->vda_name).data());
 
 1138      Aux.
Name = (
"<invalid vda_name: " + 
Twine(Verdaux->vda_name) + 
">").str();
 
 1142  std::vector<VerDef> Ret;
 
 1143  const uint8_t *VerdefBuf = Start;
 
 1144  for (
unsigned I = 1; 
I <= Sec.sh_info; ++
I) {
 
 1145    if (VerdefBuf + 
sizeof(Elf_Verdef) > End)
 
 1147                         ": version definition " + 
Twine(
I) +
 
 1148                         " goes past the end of the section");
 
 1150    if (
reinterpret_cast<uintptr_t
>(VerdefBuf) % 
sizeof(
uint32_t) != 0)
 
 1152          "invalid " + 
describe(*
this, Sec) +
 
 1153          ": found a misaligned version definition entry at offset 0x" +
 
 1156    unsigned Version = *
reinterpret_cast<const Elf_Half *
>(VerdefBuf);
 
 1160                         " is not yet supported");
 
 1162    const Elf_Verdef *
D = 
reinterpret_cast<const Elf_Verdef *
>(VerdefBuf);
 
 1163    VerDef &VD = *Ret.emplace(Ret.end());
 
 1164    VD.
Offset = VerdefBuf - Start;
 
 1169    VD.
Hash = 
D->vd_hash;
 
 1171    const uint8_t *VerdauxBuf = VerdefBuf + 
D->vd_aux;
 
 1172    for (
unsigned J = 0; J < 
D->vd_cnt; ++J) {
 
 1173      if (
reinterpret_cast<uintptr_t
>(VerdauxBuf) % 
sizeof(
uint32_t) != 0)
 
 1175                           ": found a misaligned auxiliary entry at offset 0x" +
 
 1183        VD.
Name = AuxOrErr->Name;
 
 1185        VD.
AuxV.push_back(*AuxOrErr);
 
 1188    VerdefBuf += 
D->vd_next;
 
 
 1194template <
class ELFT>
 
 1202      return std::move(
E);
 
 1204    StrTab = *StrTabOrErr;
 
 1212  const uint8_t *Start = ContentsOrErr->data();
 
 1213  const uint8_t *End = Start + ContentsOrErr->size();
 
 1214  const uint8_t *VerneedBuf = Start;
 
 1216  std::vector<VerNeed> Ret;
 
 1217  for (
unsigned I = 1; 
I <= Sec.sh_info; ++
I) {
 
 1218    if (VerneedBuf + 
sizeof(Elf_Verdef) > End)
 
 1220                         ": version dependency " + 
Twine(
I) +
 
 1221                         " goes past the end of the section");
 
 1223    if (
reinterpret_cast<uintptr_t
>(VerneedBuf) % 
sizeof(
uint32_t) != 0)
 
 1225          "invalid " + 
describe(*
this, Sec) +
 
 1226          ": found a misaligned version dependency entry at offset 0x" +
 
 1229    unsigned Version = *
reinterpret_cast<const Elf_Half *
>(VerneedBuf);
 
 1233                         " is not yet supported");
 
 1235    const Elf_Verneed *Verneed =
 
 1236        reinterpret_cast<const Elf_Verneed *
>(VerneedBuf);
 
 1238    VerNeed &VN = *Ret.emplace(Ret.end());
 
 1239    VN.
Version = Verneed->vn_version;
 
 1240    VN.
Cnt = Verneed->vn_cnt;
 
 1241    VN.
Offset = VerneedBuf - Start;
 
 1243    if (Verneed->vn_file < StrTab.
size())
 
 1244      VN.
File = std::string(StrTab.
data() + Verneed->vn_file);
 
 1246      VN.
File = (
"<corrupt vn_file: " + 
Twine(Verneed->vn_file) + 
">").str();
 
 1248    const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux;
 
 1249    for (
unsigned J = 0; J < Verneed->vn_cnt; ++J) {
 
 1250      if (
reinterpret_cast<uintptr_t
>(VernauxBuf) % 
sizeof(
uint32_t) != 0)
 
 1252                           ": found a misaligned auxiliary entry at offset 0x" +
 
 1255      if (VernauxBuf + 
sizeof(Elf_Vernaux) > End)
 
 1257            "invalid " + 
describe(*
this, Sec) + 
": version dependency " +
 
 1259            " refers to an auxiliary entry that goes past the end " 
 1262      const Elf_Vernaux *Vernaux =
 
 1263          reinterpret_cast<const Elf_Vernaux *
>(VernauxBuf);
 
 1266      Aux.
Hash = Vernaux->vna_hash;
 
 1267      Aux.
Flags = Vernaux->vna_flags;
 
 1268      Aux.
Other = Vernaux->vna_other;
 
 1269      Aux.
Offset = VernauxBuf - Start;
 
 1270      if (StrTab.
size() <= Vernaux->vna_name)
 
 1271        Aux.
Name = 
"<corrupt>";
 
 1275      VernauxBuf += Vernaux->vna_next;
 
 1277    VerneedBuf += Verneed->vn_next;
 
 
 1282template <
class ELFT>
 
 1287    return TableOrErr.takeError();
 
 
 1291template <
class ELFT>
 
 1296    if (
Error E = WarnHandler(
"invalid sh_type for string table section " +
 
 1298                              ": expected SHT_STRTAB, but got " +
 
 1300                                  getHeader().e_machine, Section.sh_type)))
 
 1301      return std::move(
E);
 
 1305    return V.takeError();
 
 1308    return createError(
"SHT_STRTAB string table section " +
 
 1310  if (
Data.back() != 
'\0')
 
 1311    return createError(
"SHT_STRTAB string table section " +
 
 1313                       " is non-null terminated");
 
 
 1317template <
class ELFT>
 
 1322    return SectionsOrErr.takeError();
 
 
 1326template <
class ELFT>
 
 1329                             Elf_Shdr_Range Sections)
 const {
 
 1333    return VOrErr.takeError();
 
 1337    return SymTableOrErr.takeError();
 
 1338  const Elf_Shdr &SymTable = **SymTableOrErr;
 
 1342        "SHT_SYMTAB_SHNDX section is linked with " +
 
 1344        " section (expected SHT_SYMTAB/SHT_DYNSYM)");
 
 1346  uint64_t Syms = SymTable.sh_size / 
sizeof(Elf_Sym);
 
 1347  if (V.size() != Syms)
 
 1349                       " entries, but the symbol table associated has " +
 
 
 1355template <
class ELFT>
 
 1360    return SectionsOrErr.takeError();
 
 
 1364template <
class ELFT>
 
 1367                                       Elf_Shdr_Range Sections)
 const {
 
 1371        "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
 
 
 1379template <
class ELFT>
 
 1384  if (!StrTabSecOrErr)
 
 1390    return createError(
"invalid string table linked to " +
 
 1393  return *StrTabOrErr;
 
 
 1396template <
class ELFT>
 
 1402    return SectionsOrErr.takeError();
 
 1405    return Table.takeError();
 
 
 1409template <
class ELFT>
 
 1417                       " has an invalid sh_name (0x" +
 
 1419                       ") offset which goes past the end of the " 
 1420                       "section name string table");
 
 
 1431    H ^= (
H >> 24) & 0xf0;
 
 1433  return H & 0x0fffffff;
 
 
 1442    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.
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.
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.
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).
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)
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)
ELFFile< ELF32LE > ELF32LEFile
ELFFile< ELF64BE > ELF64BEFile
ELFFile< ELF32BE > ELF32BEFile
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)
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.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
FunctionAddr VTableAddr Count
@ 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.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
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