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