LLVM  7.0.0svn
ELF.h
Go to the documentation of this file.
1 //===- ELF.h - ELF object file implementation -------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the ELFFile template class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_OBJECT_ELF_H
15 #define LLVM_OBJECT_ELF_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/BinaryFormat/ELF.h"
21 #include "llvm/Object/ELFTypes.h"
22 #include "llvm/Object/Error.h"
23 #include "llvm/Support/Endian.h"
24 #include "llvm/Support/Error.h"
25 #include <cassert>
26 #include <cstddef>
27 #include <cstdint>
28 #include <limits>
29 #include <utility>
30 
31 namespace llvm {
32 namespace object {
33 
37 
38 // Subclasses of ELFFile may need this for template instantiation
39 inline std::pair<unsigned char, unsigned char>
41  if (Object.size() < ELF::EI_NIDENT)
42  return std::make_pair((uint8_t)ELF::ELFCLASSNONE,
43  (uint8_t)ELF::ELFDATANONE);
44  return std::make_pair((uint8_t)Object[ELF::EI_CLASS],
45  (uint8_t)Object[ELF::EI_DATA]);
46 }
47 
48 static inline Error createError(StringRef Err) {
49  return make_error<StringError>(Err, object_error::parse_failed);
50 }
51 
52 template <class ELFT>
53 class ELFFile {
54 public:
56  using uintX_t = typename ELFT::uint;
57  using Elf_Ehdr = typename ELFT::Ehdr;
58  using Elf_Shdr = typename ELFT::Shdr;
59  using Elf_Sym = typename ELFT::Sym;
60  using Elf_Dyn = typename ELFT::Dyn;
61  using Elf_Phdr = typename ELFT::Phdr;
62  using Elf_Rel = typename ELFT::Rel;
63  using Elf_Rela = typename ELFT::Rela;
64  using Elf_Relr = typename ELFT::Relr;
65  using Elf_Verdef = typename ELFT::Verdef;
66  using Elf_Verdaux = typename ELFT::Verdaux;
67  using Elf_Verneed = typename ELFT::Verneed;
68  using Elf_Vernaux = typename ELFT::Vernaux;
69  using Elf_Versym = typename ELFT::Versym;
70  using Elf_Hash = typename ELFT::Hash;
71  using Elf_GnuHash = typename ELFT::GnuHash;
72  using Elf_Nhdr = typename ELFT::Nhdr;
73  using Elf_Note = typename ELFT::Note;
74  using Elf_Note_Iterator = typename ELFT::NoteIterator;
75  using Elf_Dyn_Range = typename ELFT::DynRange;
76  using Elf_Shdr_Range = typename ELFT::ShdrRange;
77  using Elf_Sym_Range = typename ELFT::SymRange;
78  using Elf_Rel_Range = typename ELFT::RelRange;
79  using Elf_Rela_Range = typename ELFT::RelaRange;
80  using Elf_Relr_Range = typename ELFT::RelrRange;
81  using Elf_Phdr_Range = typename ELFT::PhdrRange;
82 
83  const uint8_t *base() const {
84  return reinterpret_cast<const uint8_t *>(Buf.data());
85  }
86 
87  size_t getBufSize() const { return Buf.size(); }
88 
89 private:
90  StringRef Buf;
91 
92  ELFFile(StringRef Object);
93 
94 public:
95  const Elf_Ehdr *getHeader() const {
96  return reinterpret_cast<const Elf_Ehdr *>(base());
97  }
98 
99  template <typename T>
101  template <typename T>
102  Expected<const T *> getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
103 
104  Expected<StringRef> getStringTable(const Elf_Shdr *Section) const;
107  Elf_Shdr_Range Sections) const;
108 
109  Expected<ArrayRef<Elf_Word>> getSHNDXTable(const Elf_Shdr &Section) const;
111  Elf_Shdr_Range Sections) const;
112 
115  SmallVectorImpl<char> &Result) const;
117 
118  /// Get the symbol for a given relocation.
120  const Elf_Shdr *SymTab) const;
121 
122  static Expected<ELFFile> create(StringRef Object);
123 
124  bool isMipsELF64() const {
125  return getHeader()->e_machine == ELF::EM_MIPS &&
126  getHeader()->getFileClass() == ELF::ELFCLASS64;
127  }
128 
129  bool isMips64EL() const {
130  return isMipsELF64() &&
131  getHeader()->getDataEncoding() == ELF::ELFDATA2LSB;
132  }
133 
135 
137  if (!Sec)
138  return makeArrayRef<Elf_Sym>(nullptr, nullptr);
139  return getSectionContentsAsArray<Elf_Sym>(Sec);
140  }
141 
143  return getSectionContentsAsArray<Elf_Rela>(Sec);
144  }
145 
147  return getSectionContentsAsArray<Elf_Rel>(Sec);
148  }
149 
151  return getSectionContentsAsArray<Elf_Relr>(Sec);
152  }
153 
155 
157 
158  /// Iterate over program header table.
160  if (getHeader()->e_phnum && getHeader()->e_phentsize != sizeof(Elf_Phdr))
161  return createError("invalid e_phentsize");
162  if (getHeader()->e_phoff +
163  (getHeader()->e_phnum * getHeader()->e_phentsize) >
164  getBufSize())
165  return createError("program headers longer than binary");
166  auto *Begin =
167  reinterpret_cast<const Elf_Phdr *>(base() + getHeader()->e_phoff);
168  return makeArrayRef(Begin, Begin + getHeader()->e_phnum);
169  }
170 
171  /// Get an iterator over notes in a program header.
172  ///
173  /// The program header must be of type \c PT_NOTE.
174  ///
175  /// \param Phdr the program header to iterate over.
176  /// \param Err [out] an error to support fallible iteration, which should
177  /// be checked after iteration ends.
178  Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const {
179  if (Phdr.p_type != ELF::PT_NOTE) {
180  Err = createError("attempt to iterate notes of non-note program header");
181  return Elf_Note_Iterator(Err);
182  }
183  if (Phdr.p_offset + Phdr.p_filesz > getBufSize()) {
184  Err = createError("invalid program header offset/size");
185  return Elf_Note_Iterator(Err);
186  }
187  return Elf_Note_Iterator(base() + Phdr.p_offset, Phdr.p_filesz, Err);
188  }
189 
190  /// Get an iterator over notes in a section.
191  ///
192  /// The section must be of type \c SHT_NOTE.
193  ///
194  /// \param Shdr the section to iterate over.
195  /// \param Err [out] an error to support fallible iteration, which should
196  /// be checked after iteration ends.
197  Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const {
198  if (Shdr.sh_type != ELF::SHT_NOTE) {
199  Err = createError("attempt to iterate notes of non-note section");
200  return Elf_Note_Iterator(Err);
201  }
202  if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) {
203  Err = createError("invalid section offset/size");
204  return Elf_Note_Iterator(Err);
205  }
206  return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size, Err);
207  }
208 
209  /// Get the end iterator for notes.
211  return Elf_Note_Iterator();
212  }
213 
214  /// Get an iterator range over notes of a program header.
215  ///
216  /// The program header must be of type \c PT_NOTE.
217  ///
218  /// \param Phdr the program header to iterate over.
219  /// \param Err [out] an error to support fallible iteration, which should
220  /// be checked after iteration ends.
222  Error &Err) const {
223  return make_range(notes_begin(Phdr, Err), notes_end());
224  }
225 
226  /// Get an iterator range over notes of a section.
227  ///
228  /// The section must be of type \c SHT_NOTE.
229  ///
230  /// \param Shdr the section to iterate over.
231  /// \param Err [out] an error to support fallible iteration, which should
232  /// be checked after iteration ends.
234  Error &Err) const {
235  return make_range(notes_begin(Shdr, Err), notes_end());
236  }
237 
240  ArrayRef<Elf_Word> ShndxTable) const;
242  const Elf_Shdr *SymTab,
243  ArrayRef<Elf_Word> ShndxTable) const;
245  Elf_Sym_Range Symtab,
246  ArrayRef<Elf_Word> ShndxTable) const;
249 
251  uint32_t Index) const;
252 
253  Expected<StringRef> getSectionName(const Elf_Shdr *Section) const;
255  StringRef DotShstrtab) const;
256  template <typename T>
259 };
260 
265 
266 template <class ELFT>
268 getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
269  if (Index >= Sections.size())
270  return createError("invalid section index");
271  return &Sections[Index];
272 }
273 
274 template <class ELFT>
275 inline Expected<uint32_t>
276 getExtendedSymbolTableIndex(const typename ELFT::Sym *Sym,
277  const typename ELFT::Sym *FirstSym,
278  ArrayRef<typename ELFT::Word> ShndxTable) {
279  assert(Sym->st_shndx == ELF::SHN_XINDEX);
280  unsigned Index = Sym - FirstSym;
281  if (Index >= ShndxTable.size())
282  return createError("index past the end of the symbol table");
283 
284  // The size of the table was checked in getSHNDXTable.
285  return ShndxTable[Index];
286 }
287 
288 template <class ELFT>
291  ArrayRef<Elf_Word> ShndxTable) const {
292  uint32_t Index = Sym->st_shndx;
293  if (Index == ELF::SHN_XINDEX) {
294  auto ErrorOrIndex = getExtendedSymbolTableIndex<ELFT>(
295  Sym, Syms.begin(), ShndxTable);
296  if (!ErrorOrIndex)
297  return ErrorOrIndex.takeError();
298  return *ErrorOrIndex;
299  }
300  if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE)
301  return 0;
302  return Index;
303 }
304 
305 template <class ELFT>
307 ELFFile<ELFT>::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
308  ArrayRef<Elf_Word> ShndxTable) const {
309  auto SymsOrErr = symbols(SymTab);
310  if (!SymsOrErr)
311  return SymsOrErr.takeError();
312  return getSection(Sym, *SymsOrErr, ShndxTable);
313 }
314 
315 template <class ELFT>
318  ArrayRef<Elf_Word> ShndxTable) const {
319  auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
320  if (!IndexOrErr)
321  return IndexOrErr.takeError();
322  uint32_t Index = *IndexOrErr;
323  if (Index == 0)
324  return nullptr;
325  return getSection(Index);
326 }
327 
328 template <class ELFT>
330 getSymbol(typename ELFT::SymRange Symbols, uint32_t Index) {
331  if (Index >= Symbols.size())
332  return createError("invalid symbol index");
333  return &Symbols[Index];
334 }
335 
336 template <class ELFT>
339  auto SymtabOrErr = symbols(Sec);
340  if (!SymtabOrErr)
341  return SymtabOrErr.takeError();
342  return object::getSymbol<ELFT>(*SymtabOrErr, Index);
343 }
344 
345 template <class ELFT>
346 template <typename T>
349  if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1)
350  return createError("invalid sh_entsize");
351 
352  uintX_t Offset = Sec->sh_offset;
353  uintX_t Size = Sec->sh_size;
354 
355  if (Size % sizeof(T))
356  return createError("size is not a multiple of sh_entsize");
357  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
358  Offset + Size > Buf.size())
359  return createError("invalid section offset");
360 
361  if (Offset % alignof(T))
362  return createError("unaligned data");
363 
364  const T *Start = reinterpret_cast<const T *>(base() + Offset);
365  return makeArrayRef(Start, Size / sizeof(T));
366 }
367 
368 template <class ELFT>
371  return getSectionContentsAsArray<uint8_t>(Sec);
372 }
373 
374 template <class ELFT>
376  return getELFRelocationTypeName(getHeader()->e_machine, Type);
377 }
378 
379 template <class ELFT>
381  SmallVectorImpl<char> &Result) const {
382  if (!isMipsELF64()) {
384  Result.append(Name.begin(), Name.end());
385  } else {
386  // The Mips N64 ABI allows up to three operations to be specified per
387  // relocation record. Unfortunately there's no easy way to test for the
388  // presence of N64 ELFs as they have no special flag that identifies them
389  // as being N64. We can safely assume at the moment that all Mips
390  // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
391  // information to disambiguate between old vs new ABIs.
392  uint8_t Type1 = (Type >> 0) & 0xFF;
393  uint8_t Type2 = (Type >> 8) & 0xFF;
394  uint8_t Type3 = (Type >> 16) & 0xFF;
395 
396  // Concat all three relocation type names.
398  Result.append(Name.begin(), Name.end());
399 
400  Name = getRelocationTypeName(Type2);
401  Result.append(1, '/');
402  Result.append(Name.begin(), Name.end());
403 
404  Name = getRelocationTypeName(Type3);
405  Result.append(1, '/');
406  Result.append(Name.begin(), Name.end());
407  }
408 }
409 
410 template <class ELFT>
412  return getELFRelrRelocationType(getHeader()->e_machine);
413 }
414 
415 template <class ELFT>
418  const Elf_Shdr *SymTab) const {
419  uint32_t Index = Rel->getSymbol(isMips64EL());
420  if (Index == 0)
421  return nullptr;
422  return getEntry<Elf_Sym>(SymTab, Index);
423 }
424 
425 template <class ELFT>
428  uint32_t Index = getHeader()->e_shstrndx;
429  if (Index == ELF::SHN_XINDEX)
430  Index = Sections[0].sh_link;
431 
432  if (!Index) // no section string table.
433  return "";
434  if (Index >= Sections.size())
435  return createError("invalid section index");
436  return getStringTable(&Sections[Index]);
437 }
438 
439 template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
440 
441 template <class ELFT>
443  if (sizeof(Elf_Ehdr) > Object.size())
444  return createError("Invalid buffer");
445  return ELFFile(Object);
446 }
447 
448 template <class ELFT>
450  const uintX_t SectionTableOffset = getHeader()->e_shoff;
451  if (SectionTableOffset == 0)
452  return ArrayRef<Elf_Shdr>();
453 
454  if (getHeader()->e_shentsize != sizeof(Elf_Shdr))
455  return createError(
456  "invalid section header entry size (e_shentsize) in ELF header");
457 
458  const uint64_t FileSize = Buf.size();
459 
460  if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize)
461  return createError("section header table goes past the end of the file");
462 
463  // Invalid address alignment of section headers
464  if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
465  return createError("invalid alignment of section headers");
466 
467  const Elf_Shdr *First =
468  reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
469 
470  uintX_t NumSections = getHeader()->e_shnum;
471  if (NumSections == 0)
472  NumSections = First->sh_size;
473 
474  if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
475  return createError("section table goes past the end of file");
476 
477  const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
478 
479  // Section table goes past end of file!
480  if (SectionTableOffset + SectionTableSize > FileSize)
481  return createError("section table goes past the end of file");
482 
483  return makeArrayRef(First, NumSections);
484 }
485 
486 template <class ELFT>
487 template <typename T>
489  uint32_t Entry) const {
490  auto SecOrErr = getSection(Section);
491  if (!SecOrErr)
492  return SecOrErr.takeError();
493  return getEntry<T>(*SecOrErr, Entry);
494 }
495 
496 template <class ELFT>
497 template <typename T>
499  uint32_t Entry) const {
500  if (sizeof(T) != Section->sh_entsize)
501  return createError("invalid sh_entsize");
502  size_t Pos = Section->sh_offset + Entry * sizeof(T);
503  if (Pos + sizeof(T) > Buf.size())
504  return createError("invalid section offset");
505  return reinterpret_cast<const T *>(base() + Pos);
506 }
507 
508 template <class ELFT>
511  auto TableOrErr = sections();
512  if (!TableOrErr)
513  return TableOrErr.takeError();
514  return object::getSection<ELFT>(*TableOrErr, Index);
515 }
516 
517 template <class ELFT>
520  auto TableOrErr = sections();
521  if (!TableOrErr)
522  return TableOrErr.takeError();
523  for (auto &Sec : *TableOrErr) {
524  auto SecNameOrErr = getSectionName(&Sec);
525  if (!SecNameOrErr)
526  return SecNameOrErr.takeError();
527  if (*SecNameOrErr == SectionName)
528  return &Sec;
529  }
530  return createError("invalid section name");
531 }
532 
533 template <class ELFT>
536  if (Section->sh_type != ELF::SHT_STRTAB)
537  return createError("invalid sh_type for string table, expected SHT_STRTAB");
538  auto V = getSectionContentsAsArray<char>(Section);
539  if (!V)
540  return V.takeError();
541  ArrayRef<char> Data = *V;
542  if (Data.empty())
543  return createError("empty string table");
544  if (Data.back() != '\0')
545  return createError("string table non-null terminated");
546  return StringRef(Data.begin(), Data.size());
547 }
548 
549 template <class ELFT>
552  auto SectionsOrErr = sections();
553  if (!SectionsOrErr)
554  return SectionsOrErr.takeError();
555  return getSHNDXTable(Section, *SectionsOrErr);
556 }
557 
558 template <class ELFT>
561  Elf_Shdr_Range Sections) const {
562  assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
563  auto VOrErr = getSectionContentsAsArray<Elf_Word>(&Section);
564  if (!VOrErr)
565  return VOrErr.takeError();
566  ArrayRef<Elf_Word> V = *VOrErr;
567  auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
568  if (!SymTableOrErr)
569  return SymTableOrErr.takeError();
570  const Elf_Shdr &SymTable = **SymTableOrErr;
571  if (SymTable.sh_type != ELF::SHT_SYMTAB &&
572  SymTable.sh_type != ELF::SHT_DYNSYM)
573  return createError("invalid sh_type");
574  if (V.size() != (SymTable.sh_size / sizeof(Elf_Sym)))
575  return createError("invalid section contents size");
576  return V;
577 }
578 
579 template <class ELFT>
582  auto SectionsOrErr = sections();
583  if (!SectionsOrErr)
584  return SectionsOrErr.takeError();
585  return getStringTableForSymtab(Sec, *SectionsOrErr);
586 }
587 
588 template <class ELFT>
591  Elf_Shdr_Range Sections) const {
592 
593  if (Sec.sh_type != ELF::SHT_SYMTAB && Sec.sh_type != ELF::SHT_DYNSYM)
594  return createError(
595  "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
596  auto SectionOrErr = object::getSection<ELFT>(Sections, Sec.sh_link);
597  if (!SectionOrErr)
598  return SectionOrErr.takeError();
599  return getStringTable(*SectionOrErr);
600 }
601 
602 template <class ELFT>
605  auto SectionsOrErr = sections();
606  if (!SectionsOrErr)
607  return SectionsOrErr.takeError();
608  auto Table = getSectionStringTable(*SectionsOrErr);
609  if (!Table)
610  return Table.takeError();
611  return getSectionName(Section, *Table);
612 }
613 
614 template <class ELFT>
616  StringRef DotShstrtab) const {
617  uint32_t Offset = Section->sh_name;
618  if (Offset == 0)
619  return StringRef();
620  if (Offset >= DotShstrtab.size())
621  return createError("invalid string offset");
622  return StringRef(DotShstrtab.data() + Offset);
623 }
624 
625 /// This function returns the hash value for a symbol in the .dynsym section
626 /// Name of the API remains consistent as specified in the libelf
627 /// REF : http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash
628 inline unsigned hashSysV(StringRef SymbolName) {
629  unsigned h = 0, g;
630  for (char C : SymbolName) {
631  h = (h << 4) + C;
632  g = h & 0xf0000000L;
633  if (g != 0)
634  h ^= g >> 24;
635  h &= ~g;
636  }
637  return h;
638 }
639 
640 } // end namespace object
641 } // end namespace llvm
642 
643 #endif // LLVM_OBJECT_ELF_H
typename ELFT::Dyn Elf_Dyn
Definition: ELF.h:60
uint64_t CallInst * C
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:158
typename ELFT::Rel Elf_Rel
Definition: ELF.h:62
iterator_range< Elf_Note_Iterator > notes(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator range over notes of a program header.
Definition: ELF.h:221
Expected< const T * > getEntry(uint32_t Section, uint32_t Entry) const
Definition: ELF.h:488
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
typename ELFT::Note Elf_Note
Definition: ELF.h:73
static Expected< ELFFile > create(StringRef Object)
Definition: ELF.h:442
iterator begin() const
Definition: ArrayRef.h:137
typename ELFT::Vernaux Elf_Vernaux
Definition: ELF.h:68
StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
StringRef getRelocationTypeName(uint32_t Type) const
Definition: ELF.h:375
uint32_t getELFRelrRelocationType(uint32_t Machine)
Definition: ELF.cpp:150
Expected< StringRef > getSectionStringTable(Elf_Shdr_Range Sections) const
Definition: ELF.h:427
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:936
Expected< StringRef > getStringTable(const Elf_Shdr *Section) const
Definition: ELF.h:535
static Error createError(StringRef Err)
Definition: ELF.h:48
Expected< std::vector< Elf_Rela > > decode_relrs(Elf_Relr_Range relrs) const
Definition: ELF.cpp:261
unsigned hashSysV(StringRef SymbolName)
This function returns the hash value for a symbol in the .dynsym section Name of the API remains cons...
Definition: ELF.h:628
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
typename ELFT::Sym Elf_Sym
Definition: ELF.h:59
Expected< Elf_Phdr_Range > program_headers() const
Iterate over program header table.
Definition: ELF.h:159
uint32_t getRelrRelocationType() const
Definition: ELF.h:411
const uint8_t * base() const
Definition: ELF.h:83
Expected< const Elf_Shdr * > getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, ArrayRef< Elf_Word > ShndxTable) const
Definition: ELF.h:307
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
bool isMips64EL() const
Definition: ELF.h:129
iterator_range< Elf_Note_Iterator > notes(const Elf_Shdr &Shdr, Error &Err) const
Get an iterator range over notes of a section.
Definition: ELF.h:233
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
Expected< Elf_Shdr_Range > sections() const
Definition: ELF.h:449
typename ELFT::PhdrRange Elf_Phdr_Range
Definition: ELF.h:81
typename ELFT::Phdr Elf_Phdr
Definition: ELF.h:61
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
Expected< ArrayRef< uint8_t > > getSectionContents(const Elf_Shdr *Sec) const
Definition: ELF.h:370
#define UINT64_MAX
Definition: DataTypes.h:83
#define T
typename ELFT::Relr Elf_Relr
Definition: ELF.h:64
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
Definition: ELF.h:40
typename ELFT::GnuHash Elf_GnuHash
Definition: ELF.h:71
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:363
typename ELFT::SymRange Elf_Sym_Range
Definition: ELF.h:77
Elf_Note_Iterator notes_end() const
Get the end iterator for notes.
Definition: ELF.h:210
Expected< ArrayRef< T > > getSectionContentsAsArray(const Elf_Shdr *Sec) const
Definition: ELF.h:348
Expected< Elf_Rel_Range > rels(const Elf_Shdr *Sec) const
Definition: ELF.h:146
Expected< ArrayRef< Elf_Word > > getSHNDXTable(const Elf_Shdr &Section) const
Definition: ELF.h:551
bool isMipsELF64() const
Definition: ELF.h:124
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const
Get an iterator over notes in a section.
Definition: ELF.h:197
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
Expected< StringRef > getStringTableForSymtab(const Elf_Shdr &Section) const
Definition: ELF.h:581
Expected< Elf_Rela_Range > relas(const Elf_Shdr *Sec) const
Definition: ELF.h:142
typename ELFT::uint uintX_t
Definition: ELF.h:56
Expected< uint32_t > getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms, ArrayRef< Elf_Word > ShndxTable) const
Definition: ELF.h:290
Expected< Elf_Relr_Range > relrs(const Elf_Shdr *Sec) const
Definition: ELF.h:150
typename ELFT::NoteIterator Elf_Note_Iterator
Definition: ELF.h:74
typename ELFT::Nhdr Elf_Nhdr
Definition: ELF.h:72
typename ELFT::Verdaux Elf_Verdaux
Definition: ELF.h:66
typename ELFT::Ehdr Elf_Ehdr
Definition: ELF.h:57
typename ELFT::RelrRange Elf_Relr_Range
Definition: ELF.h:80
typename ELFT::Rela Elf_Rela
Definition: ELF.h:63
typename ELFT::Verneed Elf_Verneed
Definition: ELF.h:67
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
Definition: ELF.cpp:23
Expected< uint32_t > getExtendedSymbolTableIndex(const typename ELFT::Sym *Sym, const typename ELFT::Sym *FirstSym, ArrayRef< typename ELFT::Word > ShndxTable)
Definition: ELF.h:276
size_t getBufSize() const
Definition: ELF.h:87
Expected< const Elf_Sym * > getRelocationSymbol(const Elf_Rel *Rel, const Elf_Shdr *SymTab) const
Get the symbol for a given relocation.
Definition: ELF.h:417
A range adaptor for a pair of iterators.
iterator begin() const
Definition: StringRef.h:106
Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator over notes in a program header.
Definition: ELF.h:178
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:395
typename ELFT::DynRange Elf_Dyn_Range
Definition: ELF.h:75
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:935
Expected< std::vector< Elf_Rela > > android_relas(const Elf_Shdr *Sec) const
Definition: ELF.cpp:340
Expected< const Elf_Sym * > getSymbol(const Elf_Shdr *Sec, uint32_t Index) const
Definition: ELF.h:338
Expected< Elf_Sym_Range > symbols(const Elf_Shdr *Sec) const
Definition: ELF.h:136
typename ELFT::Verdef Elf_Verdef
Definition: ELF.h:65
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
typename ELFT::RelRange Elf_Rel_Range
Definition: ELF.h:78
aarch64 promote const
typename ELFT::Versym Elf_Versym
Definition: ELF.h:69
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
typename ELFT::RelaRange Elf_Rela_Range
Definition: ELF.h:79
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Definition: ELFTypes.h:104
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
typename ELFT::ShdrRange Elf_Shdr_Range
Definition: ELF.h:76
const Elf_Ehdr * getHeader() const
Definition: ELF.h:95
iterator end() const
Definition: StringRef.h:108
typename ELFT::Shdr Elf_Shdr
Definition: ELF.h:58
Expected< StringRef > getSectionName(const Elf_Shdr *Section) const
Definition: ELF.h:604
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
typename ELFT::Hash Elf_Hash
Definition: ELF.h:70