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