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(const Twine &Err) {
48  return make_error<StringError>(Err, object_error::parse_failed);
49 }
50 
51 template <class ELFT> class ELFFile;
52 
53 template <class ELFT>
54 std::string getSecIndexForError(const ELFFile<ELFT> *Obj,
55  const typename ELFT::Shdr *Sec) {
56  auto TableOrErr = Obj->sections();
57  if (TableOrErr)
58  return "[index " + std::to_string(Sec - &TableOrErr->front()) + "]";
59  // To make this helper be more convenient for error reporting purposes we
60  // drop the error. But really it should never be triggered. Before this point,
61  // our code should have called 'sections()' and reported a proper error on
62  // failure.
63  llvm::consumeError(TableOrErr.takeError());
64  return "[unknown index]";
65 }
66 
67 template <class ELFT>
68 class ELFFile {
69 public:
71  using uintX_t = typename ELFT::uint;
72  using Elf_Ehdr = typename ELFT::Ehdr;
73  using Elf_Shdr = typename ELFT::Shdr;
74  using Elf_Sym = typename ELFT::Sym;
75  using Elf_Dyn = typename ELFT::Dyn;
76  using Elf_Phdr = typename ELFT::Phdr;
77  using Elf_Rel = typename ELFT::Rel;
78  using Elf_Rela = typename ELFT::Rela;
79  using Elf_Relr = typename ELFT::Relr;
80  using Elf_Verdef = typename ELFT::Verdef;
81  using Elf_Verdaux = typename ELFT::Verdaux;
82  using Elf_Verneed = typename ELFT::Verneed;
83  using Elf_Vernaux = typename ELFT::Vernaux;
84  using Elf_Versym = typename ELFT::Versym;
85  using Elf_Hash = typename ELFT::Hash;
86  using Elf_GnuHash = typename ELFT::GnuHash;
87  using Elf_Nhdr = typename ELFT::Nhdr;
88  using Elf_Note = typename ELFT::Note;
89  using Elf_Note_Iterator = typename ELFT::NoteIterator;
90  using Elf_Dyn_Range = typename ELFT::DynRange;
91  using Elf_Shdr_Range = typename ELFT::ShdrRange;
92  using Elf_Sym_Range = typename ELFT::SymRange;
93  using Elf_Rel_Range = typename ELFT::RelRange;
94  using Elf_Rela_Range = typename ELFT::RelaRange;
95  using Elf_Relr_Range = typename ELFT::RelrRange;
96  using Elf_Phdr_Range = typename ELFT::PhdrRange;
97 
98  const uint8_t *base() const { return Buf.bytes_begin(); }
99 
100  size_t getBufSize() const { return Buf.size(); }
101 
102 private:
103  StringRef Buf;
104 
105  ELFFile(StringRef Object);
106 
107 public:
108  const Elf_Ehdr *getHeader() const {
109  return reinterpret_cast<const Elf_Ehdr *>(base());
110  }
111 
112  template <typename T>
114  template <typename T>
115  Expected<const T *> getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
116 
117  Expected<StringRef> getStringTable(const Elf_Shdr *Section) const;
120  Elf_Shdr_Range Sections) const;
121 
122  Expected<ArrayRef<Elf_Word>> getSHNDXTable(const Elf_Shdr &Section) const;
124  Elf_Shdr_Range Sections) const;
125 
128  SmallVectorImpl<char> &Result) const;
130 
131  std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const;
132  std::string getDynamicTagAsString(uint64_t Type) const;
133 
134  /// Get the symbol for a given relocation.
136  const Elf_Shdr *SymTab) const;
137 
138  static Expected<ELFFile> create(StringRef Object);
139 
140  bool isMipsELF64() const {
141  return getHeader()->e_machine == ELF::EM_MIPS &&
142  getHeader()->getFileClass() == ELF::ELFCLASS64;
143  }
144 
145  bool isMips64EL() const {
146  return isMipsELF64() &&
147  getHeader()->getDataEncoding() == ELF::ELFDATA2LSB;
148  }
149 
151 
153 
154  Expected<const uint8_t *> toMappedAddr(uint64_t VAddr) const;
155 
157  if (!Sec)
158  return makeArrayRef<Elf_Sym>(nullptr, nullptr);
159  return getSectionContentsAsArray<Elf_Sym>(Sec);
160  }
161 
163  return getSectionContentsAsArray<Elf_Rela>(Sec);
164  }
165 
167  return getSectionContentsAsArray<Elf_Rel>(Sec);
168  }
169 
171  return getSectionContentsAsArray<Elf_Relr>(Sec);
172  }
173 
175 
177 
178  /// Iterate over program header table.
180  if (getHeader()->e_phnum && getHeader()->e_phentsize != sizeof(Elf_Phdr))
181  return createError("invalid e_phentsize: " +
182  Twine(getHeader()->e_phentsize));
183  if (getHeader()->e_phoff +
184  (getHeader()->e_phnum * getHeader()->e_phentsize) >
185  getBufSize())
186  return createError("program headers are longer than binary of size " +
187  Twine(getBufSize()) + ": e_phoff = 0x" +
188  Twine::utohexstr(getHeader()->e_phoff) +
189  ", e_phnum = " + Twine(getHeader()->e_phnum) +
190  ", e_phentsize = " + Twine(getHeader()->e_phentsize));
191  auto *Begin =
192  reinterpret_cast<const Elf_Phdr *>(base() + getHeader()->e_phoff);
193  return makeArrayRef(Begin, Begin + getHeader()->e_phnum);
194  }
195 
196  /// Get an iterator over notes in a program header.
197  ///
198  /// The program header must be of type \c PT_NOTE.
199  ///
200  /// \param Phdr the program header 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_Phdr &Phdr, Error &Err) const {
204  assert(Phdr.p_type == ELF::PT_NOTE && "Phdr is not of type PT_NOTE");
205  ErrorAsOutParameter ErrAsOutParam(&Err);
206  if (Phdr.p_offset + Phdr.p_filesz > getBufSize()) {
207  Err = createError("PT_NOTE header has invalid offset (0x" +
208  Twine::utohexstr(Phdr.p_offset) + ") or size (0x" +
209  Twine::utohexstr(Phdr.p_filesz) + ")");
210  return Elf_Note_Iterator(Err);
211  }
212  return Elf_Note_Iterator(base() + Phdr.p_offset, Phdr.p_filesz, Err);
213  }
214 
215  /// Get an iterator over notes in a section.
216  ///
217  /// The section must be of type \c SHT_NOTE.
218  ///
219  /// \param Shdr the section to iterate over.
220  /// \param Err [out] an error to support fallible iteration, which should
221  /// be checked after iteration ends.
222  Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const {
223  assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE");
224  ErrorAsOutParameter ErrAsOutParam(&Err);
225  if (Shdr.sh_offset + Shdr.sh_size > getBufSize()) {
226  Err = createError("SHT_NOTE section " + getSecIndexForError(this, &Shdr) +
227  " has invalid offset (0x" +
228  Twine::utohexstr(Shdr.sh_offset) + ") or size (0x" +
229  Twine::utohexstr(Shdr.sh_size) + ")");
230  return Elf_Note_Iterator(Err);
231  }
232  return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size, Err);
233  }
234 
235  /// Get the end iterator for notes.
237  return Elf_Note_Iterator();
238  }
239 
240  /// Get an iterator range over notes of a program header.
241  ///
242  /// The program header must be of type \c PT_NOTE.
243  ///
244  /// \param Phdr the program header to iterate over.
245  /// \param Err [out] an error to support fallible iteration, which should
246  /// be checked after iteration ends.
248  Error &Err) const {
249  return make_range(notes_begin(Phdr, Err), notes_end());
250  }
251 
252  /// Get an iterator range over notes of a section.
253  ///
254  /// The section must be of type \c SHT_NOTE.
255  ///
256  /// \param Shdr the section to iterate over.
257  /// \param Err [out] an error to support fallible iteration, which should
258  /// be checked after iteration ends.
260  Error &Err) const {
261  return make_range(notes_begin(Shdr, Err), notes_end());
262  }
263 
266  ArrayRef<Elf_Word> ShndxTable) const;
268  const Elf_Shdr *SymTab,
269  ArrayRef<Elf_Word> ShndxTable) const;
271  Elf_Sym_Range Symtab,
272  ArrayRef<Elf_Word> ShndxTable) const;
275 
277  uint32_t Index) const;
278 
279  Expected<StringRef> getSectionName(const Elf_Shdr *Section) const;
281  StringRef DotShstrtab) const;
282  template <typename T>
285 };
286 
291 
292 template <class ELFT>
294 getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
295  if (Index >= Sections.size())
296  return createError("invalid section index: " + Twine(Index));
297  return &Sections[Index];
298 }
299 
300 template <class ELFT>
301 inline Expected<uint32_t>
302 getExtendedSymbolTableIndex(const typename ELFT::Sym *Sym,
303  const typename ELFT::Sym *FirstSym,
304  ArrayRef<typename ELFT::Word> ShndxTable) {
305  assert(Sym->st_shndx == ELF::SHN_XINDEX);
306  unsigned Index = Sym - FirstSym;
307  if (Index >= ShndxTable.size())
308  return createError(
309  "extended symbol index (" + Twine(Index) +
310  ") is past the end of the SHT_SYMTAB_SHNDX section of size " +
311  Twine(ShndxTable.size()));
312 
313  // The size of the table was checked in getSHNDXTable.
314  return ShndxTable[Index];
315 }
316 
317 template <class ELFT>
320  ArrayRef<Elf_Word> ShndxTable) const {
321  uint32_t Index = Sym->st_shndx;
322  if (Index == ELF::SHN_XINDEX) {
323  auto ErrorOrIndex = getExtendedSymbolTableIndex<ELFT>(
324  Sym, Syms.begin(), ShndxTable);
325  if (!ErrorOrIndex)
326  return ErrorOrIndex.takeError();
327  return *ErrorOrIndex;
328  }
329  if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE)
330  return 0;
331  return Index;
332 }
333 
334 template <class ELFT>
336 ELFFile<ELFT>::getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab,
337  ArrayRef<Elf_Word> ShndxTable) const {
338  auto SymsOrErr = symbols(SymTab);
339  if (!SymsOrErr)
340  return SymsOrErr.takeError();
341  return getSection(Sym, *SymsOrErr, ShndxTable);
342 }
343 
344 template <class ELFT>
347  ArrayRef<Elf_Word> ShndxTable) const {
348  auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
349  if (!IndexOrErr)
350  return IndexOrErr.takeError();
351  uint32_t Index = *IndexOrErr;
352  if (Index == 0)
353  return nullptr;
354  return getSection(Index);
355 }
356 
357 template <class ELFT>
359 getSymbol(typename ELFT::SymRange Symbols, uint32_t Index) {
360  if (Index >= Symbols.size())
361  // TODO: this error is untested.
362  return createError("invalid symbol index");
363  return &Symbols[Index];
364 }
365 
366 template <class ELFT>
369  auto SymtabOrErr = symbols(Sec);
370  if (!SymtabOrErr)
371  return SymtabOrErr.takeError();
372  return object::getSymbol<ELFT>(*SymtabOrErr, Index);
373 }
374 
375 template <class ELFT>
376 template <typename T>
379  if (Sec->sh_entsize != sizeof(T) && sizeof(T) != 1)
380  return createError("section " + getSecIndexForError(this, Sec) +
381  " has an invalid sh_entsize: " + Twine(Sec->sh_entsize));
382 
383  uintX_t Offset = Sec->sh_offset;
384  uintX_t Size = Sec->sh_size;
385 
386  if (Size % sizeof(T))
387  return createError("section " + getSecIndexForError(this, Sec) +
388  " has an invalid sh_size (" + Twine(Size) +
389  ") which is not a multiple of its sh_entsize (" +
390  Twine(Sec->sh_entsize) + ")");
391  if ((std::numeric_limits<uintX_t>::max() - Offset < Size) ||
392  Offset + Size > Buf.size())
393  return createError("section " + getSecIndexForError(this, Sec) +
394  " has a sh_offset (0x" + Twine::utohexstr(Offset) +
395  ") + sh_size (0x" + Twine(Size) +
396  ") that cannot be represented");
397 
398  if (Offset % alignof(T))
399  // TODO: this error is untested.
400  return createError("unaligned data");
401 
402  const T *Start = reinterpret_cast<const T *>(base() + Offset);
403  return makeArrayRef(Start, Size / sizeof(T));
404 }
405 
406 template <class ELFT>
409  return getSectionContentsAsArray<uint8_t>(Sec);
410 }
411 
412 template <class ELFT>
414  return getELFRelocationTypeName(getHeader()->e_machine, Type);
415 }
416 
417 template <class ELFT>
419  SmallVectorImpl<char> &Result) const {
420  if (!isMipsELF64()) {
422  Result.append(Name.begin(), Name.end());
423  } else {
424  // The Mips N64 ABI allows up to three operations to be specified per
425  // relocation record. Unfortunately there's no easy way to test for the
426  // presence of N64 ELFs as they have no special flag that identifies them
427  // as being N64. We can safely assume at the moment that all Mips
428  // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
429  // information to disambiguate between old vs new ABIs.
430  uint8_t Type1 = (Type >> 0) & 0xFF;
431  uint8_t Type2 = (Type >> 8) & 0xFF;
432  uint8_t Type3 = (Type >> 16) & 0xFF;
433 
434  // Concat all three relocation type names.
436  Result.append(Name.begin(), Name.end());
437 
438  Name = getRelocationTypeName(Type2);
439  Result.append(1, '/');
440  Result.append(Name.begin(), Name.end());
441 
442  Name = getRelocationTypeName(Type3);
443  Result.append(1, '/');
444  Result.append(Name.begin(), Name.end());
445  }
446 }
447 
448 template <class ELFT>
450  return getELFRelativeRelocationType(getHeader()->e_machine);
451 }
452 
453 template <class ELFT>
456  const Elf_Shdr *SymTab) const {
457  uint32_t Index = Rel->getSymbol(isMips64EL());
458  if (Index == 0)
459  return nullptr;
460  return getEntry<Elf_Sym>(SymTab, Index);
461 }
462 
463 template <class ELFT>
466  uint32_t Index = getHeader()->e_shstrndx;
467  if (Index == ELF::SHN_XINDEX)
468  Index = Sections[0].sh_link;
469 
470  if (!Index) // no section string table.
471  return "";
472  if (Index >= Sections.size())
473  // TODO: this error is untested.
474  return createError("invalid section index");
475  return getStringTable(&Sections[Index]);
476 }
477 
478 template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
479 
480 template <class ELFT>
482  if (sizeof(Elf_Ehdr) > Object.size())
483  return createError("invalid buffer: the size (" + Twine(Object.size()) +
484  ") is smaller than an ELF header (" +
485  Twine(sizeof(Elf_Ehdr)) + ")");
486  return ELFFile(Object);
487 }
488 
489 template <class ELFT>
491  const uintX_t SectionTableOffset = getHeader()->e_shoff;
492  if (SectionTableOffset == 0)
493  return ArrayRef<Elf_Shdr>();
494 
495  if (getHeader()->e_shentsize != sizeof(Elf_Shdr))
496  return createError("invalid e_shentsize in ELF header: " +
497  Twine(getHeader()->e_shentsize));
498 
499  const uint64_t FileSize = Buf.size();
500  if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize)
501  return createError(
502  "section header table goes past the end of the file: e_shoff = 0x" +
503  Twine::utohexstr(SectionTableOffset));
504 
505  // Invalid address alignment of section headers
506  if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
507  // TODO: this error is untested.
508  return createError("invalid alignment of section headers");
509 
510  const Elf_Shdr *First =
511  reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
512 
513  uintX_t NumSections = getHeader()->e_shnum;
514  if (NumSections == 0)
515  NumSections = First->sh_size;
516 
517  if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
518  // TODO: this error is untested.
519  return createError("section table goes past the end of file");
520 
521  const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
522 
523  // Section table goes past end of file!
524  if (SectionTableOffset + SectionTableSize > FileSize)
525  return createError("section table goes past the end of file");
526 
527  return makeArrayRef(First, NumSections);
528 }
529 
530 template <class ELFT>
531 template <typename T>
533  uint32_t Entry) const {
534  auto SecOrErr = getSection(Section);
535  if (!SecOrErr)
536  return SecOrErr.takeError();
537  return getEntry<T>(*SecOrErr, Entry);
538 }
539 
540 template <class ELFT>
541 template <typename T>
543  uint32_t Entry) const {
544  if (sizeof(T) != Section->sh_entsize)
545  // TODO: this error is untested.
546  return createError("invalid sh_entsize");
547  size_t Pos = Section->sh_offset + Entry * sizeof(T);
548  if (Pos + sizeof(T) > Buf.size())
549  return createError("unable to access section " +
550  getSecIndexForError(this, Section) + " data at 0x" +
551  Twine::utohexstr(Pos) +
552  ": offset goes past the end of file");
553  return reinterpret_cast<const T *>(base() + Pos);
554 }
555 
556 template <class ELFT>
559  auto TableOrErr = sections();
560  if (!TableOrErr)
561  return TableOrErr.takeError();
562  return object::getSection<ELFT>(*TableOrErr, Index);
563 }
564 
565 template <class ELFT>
568  auto TableOrErr = sections();
569  if (!TableOrErr)
570  return TableOrErr.takeError();
571  for (auto &Sec : *TableOrErr) {
572  auto SecNameOrErr = getSectionName(&Sec);
573  if (!SecNameOrErr)
574  return SecNameOrErr.takeError();
575  if (*SecNameOrErr == SectionName)
576  return &Sec;
577  }
578  // TODO: this error is untested.
579  return createError("invalid section name");
580 }
581 
582 template <class ELFT>
585  if (Section->sh_type != ELF::SHT_STRTAB)
586  return createError("invalid sh_type for string table section " +
587  getSecIndexForError(this, Section) +
588  ": expected SHT_STRTAB, but got " +
590  Section->sh_type));
591  auto V = getSectionContentsAsArray<char>(Section);
592  if (!V)
593  return V.takeError();
594  ArrayRef<char> Data = *V;
595  if (Data.empty())
596  // TODO: this error is untested.
597  return createError("empty string table");
598  if (Data.back() != '\0')
600  Section->sh_type) +
601  " string table section " +
602  getSecIndexForError(this, Section) +
603  " is non-null terminated");
604  return StringRef(Data.begin(), Data.size());
605 }
606 
607 template <class ELFT>
610  auto SectionsOrErr = sections();
611  if (!SectionsOrErr)
612  return SectionsOrErr.takeError();
613  return getSHNDXTable(Section, *SectionsOrErr);
614 }
615 
616 template <class ELFT>
619  Elf_Shdr_Range Sections) const {
620  assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
621  auto VOrErr = getSectionContentsAsArray<Elf_Word>(&Section);
622  if (!VOrErr)
623  return VOrErr.takeError();
624  ArrayRef<Elf_Word> V = *VOrErr;
625  auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
626  if (!SymTableOrErr)
627  return SymTableOrErr.takeError();
628  const Elf_Shdr &SymTable = **SymTableOrErr;
629  if (SymTable.sh_type != ELF::SHT_SYMTAB &&
630  SymTable.sh_type != ELF::SHT_DYNSYM)
631  // TODO: this error is untested.
632  return createError("invalid sh_type");
633  if (V.size() != (SymTable.sh_size / sizeof(Elf_Sym)))
634  return createError("SHT_SYMTAB_SHNDX section has sh_size (" +
635  Twine(SymTable.sh_size) +
636  ") which is not equal to the number of symbols (" +
637  Twine(V.size()) + ")");
638  return V;
639 }
640 
641 template <class ELFT>
644  auto SectionsOrErr = sections();
645  if (!SectionsOrErr)
646  return SectionsOrErr.takeError();
647  return getStringTableForSymtab(Sec, *SectionsOrErr);
648 }
649 
650 template <class ELFT>
653  Elf_Shdr_Range Sections) const {
654 
655  if (Sec.sh_type != ELF::SHT_SYMTAB && Sec.sh_type != ELF::SHT_DYNSYM)
656  // TODO: this error is untested.
657  return createError(
658  "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
659  auto SectionOrErr = object::getSection<ELFT>(Sections, Sec.sh_link);
660  if (!SectionOrErr)
661  return SectionOrErr.takeError();
662  return getStringTable(*SectionOrErr);
663 }
664 
665 template <class ELFT>
668  auto SectionsOrErr = sections();
669  if (!SectionsOrErr)
670  return SectionsOrErr.takeError();
671  auto Table = getSectionStringTable(*SectionsOrErr);
672  if (!Table)
673  return Table.takeError();
674  return getSectionName(Section, *Table);
675 }
676 
677 template <class ELFT>
679  StringRef DotShstrtab) const {
680  uint32_t Offset = Section->sh_name;
681  if (Offset == 0)
682  return StringRef();
683  if (Offset >= DotShstrtab.size())
684  return createError("a section " + getSecIndexForError(this, Section) +
685  " has an invalid sh_name (0x" +
686  Twine::utohexstr(Offset) +
687  ") offset which goes past the end of the "
688  "section name string table");
689  return StringRef(DotShstrtab.data() + Offset);
690 }
691 
692 /// This function returns the hash value for a symbol in the .dynsym section
693 /// Name of the API remains consistent as specified in the libelf
694 /// REF : http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash
695 inline unsigned hashSysV(StringRef SymbolName) {
696  unsigned h = 0, g;
697  for (char C : SymbolName) {
698  h = (h << 4) + C;
699  g = h & 0xf0000000L;
700  if (g != 0)
701  h ^= g >> 24;
702  h &= ~g;
703  }
704  return h;
705 }
706 
707 } // end namespace object
708 } // end namespace llvm
709 
710 #endif // LLVM_OBJECT_ELF_H
typename ELFT::Dyn Elf_Dyn
Definition: ELF.h:75
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:77
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:247
Expected< const T * > getEntry(uint32_t Section, uint32_t Entry) const
Definition: ELF.h:532
This class represents lattice values for constants.
Definition: AllocatorList.h:23
typename ELFT::Note Elf_Note
Definition: ELF.h:88
static Expected< ELFFile > create(StringRef Object)
Definition: ELF.h:481
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:83
StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type)
StringRef getRelocationTypeName(uint32_t Type) const
Definition: ELF.h:413
Expected< StringRef > getSectionStringTable(Elf_Shdr_Range Sections) const
Definition: ELF.h:465
ELFYAML::ELF_REL Type3
Definition: ELFYAML.cpp:1089
Expected< StringRef > getStringTable(const Elf_Shdr *Section) const
Definition: ELF.h:584
Expected< std::vector< Elf_Rela > > decode_relrs(Elf_Relr_Range relrs) const
Definition: ELF.cpp:270
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:695
typename ELFT::Sym Elf_Sym
Definition: ELF.h:74
Expected< Elf_Phdr_Range > program_headers() const
Iterate over program header table.
Definition: ELF.h:179
Expected< const uint8_t * > toMappedAddr(uint64_t VAddr) const
Definition: ELF.cpp:555
const uint8_t * base() const
Definition: ELF.h:98
Expected< const Elf_Shdr * > getSection(const Elf_Sym *Sym, const Elf_Shdr *SymTab, ArrayRef< Elf_Word > ShndxTable) const
Definition: ELF.h:336
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
bool isMips64EL() const
Definition: ELF.h:145
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:259
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
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:490
typename ELFT::PhdrRange Elf_Phdr_Range
Definition: ELF.h:96
typename ELFT::Phdr Elf_Phdr
Definition: ELF.h:76
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:408
#define UINT64_MAX
Definition: DataTypes.h:83
static Error createError(const Twine &Err)
Definition: ELF.h:47
typename ELFT::Relr Elf_Relr
Definition: ELF.h:79
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:86
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:365
typename ELFT::SymRange Elf_Sym_Range
Definition: ELF.h:92
Elf_Note_Iterator notes_end() const
Get the end iterator for notes.
Definition: ELF.h:236
Expected< ArrayRef< T > > getSectionContentsAsArray(const Elf_Shdr *Sec) const
Definition: ELF.h:378
Expected< Elf_Rel_Range > rels(const Elf_Shdr *Sec) const
Definition: ELF.h:166
Expected< ArrayRef< Elf_Word > > getSHNDXTable(const Elf_Shdr &Section) const
Definition: ELF.h:609
bool isMipsELF64() const
Definition: ELF.h:140
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:222
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
Expected< StringRef > getStringTableForSymtab(const Elf_Shdr &Section) const
Definition: ELF.h:643
Expected< Elf_Rela_Range > relas(const Elf_Shdr *Sec) const
Definition: ELF.h:162
typename ELFT::uint uintX_t
Definition: ELF.h:71
Expected< uint32_t > getSectionIndex(const Elf_Sym *Sym, Elf_Sym_Range Syms, ArrayRef< Elf_Word > ShndxTable) const
Definition: ELF.h:319
Expected< Elf_Relr_Range > relrs(const Elf_Shdr *Sec) const
Definition: ELF.h:170
typename ELFT::NoteIterator Elf_Note_Iterator
Definition: ELF.h:89
std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const
Definition: ELF.cpp:429
typename ELFT::Nhdr Elf_Nhdr
Definition: ELF.h:87
typename ELFT::Verdaux Elf_Verdaux
Definition: ELF.h:81
typename ELFT::Ehdr Elf_Ehdr
Definition: ELF.h:72
typename ELFT::RelrRange Elf_Relr_Range
Definition: ELF.h:95
typename ELFT::Rela Elf_Rela
Definition: ELF.h:78
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:981
typename ELFT::Verneed Elf_Verneed
Definition: ELF.h:82
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:302
size_t getBufSize() const
Definition: ELF.h:100
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:387
Expected< const Elf_Sym * > getRelocationSymbol(const Elf_Rel *Rel, const Elf_Shdr *SymTab) const
Get the symbol for a given relocation.
Definition: ELF.h:455
A range adaptor for a pair of iterators.
Helper for Errors used as out-parameters.
Definition: Error.h:1021
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:203
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:387
typename ELFT::DynRange Elf_Dyn_Range
Definition: ELF.h:90
ELFYAML::ELF_REL Type2
Definition: ELFYAML.cpp:1088
Expected< std::vector< Elf_Rela > > android_relas(const Elf_Shdr *Sec) const
Definition: ELF.cpp:349
uint32_t getRelativeRelocationType() const
Definition: ELF.h:449
const unsigned char * bytes_begin() const
Definition: StringRef.h:105
Expected< const Elf_Sym * > getSymbol(const Elf_Shdr *Sec, uint32_t Index) const
Definition: ELF.h:368
Expected< Elf_Sym_Range > symbols(const Elf_Shdr *Sec) const
Definition: ELF.h:156
uint32_t Size
Definition: Profile.cpp:46
const std::string to_string(const T &Value)
Definition: ScopedPrinter.h:61
typename ELFT::Verdef Elf_Verdef
Definition: ELF.h:80
Expected< Elf_Dyn_Range > dynamicEntries() const
Definition: ELF.cpp:498
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:93
aarch64 promote const
typename ELFT::Versym Elf_Versym
Definition: ELF.h:84
typename ELFT::RelaRange Elf_Rela_Range
Definition: ELF.h:94
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:91
const Elf_Ehdr * getHeader() const
Definition: ELF.h:108
std::string getSecIndexForError(const ELFFile< ELFT > *Obj, const typename ELFT::Shdr *Sec)
Definition: ELF.h:54
iterator end() const
Definition: StringRef.h:103
typename ELFT::Shdr Elf_Shdr
Definition: ELF.h:73
Expected< StringRef > getSectionName(const Elf_Shdr *Section) const
Definition: ELF.h:667
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143
typename ELFT::Hash Elf_Hash
Definition: ELF.h:85