LLVM  7.0.0svn
ELFObjectFile.h
Go to the documentation of this file.
1 //===- ELFObjectFile.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 ELFObjectFile template class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_OBJECT_ELFOBJECTFILE_H
15 #define LLVM_OBJECT_ELFOBJECTFILE_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/Triple.h"
23 #include "llvm/BinaryFormat/ELF.h"
25 #include "llvm/Object/Binary.h"
26 #include "llvm/Object/ELF.h"
27 #include "llvm/Object/ELFTypes.h"
28 #include "llvm/Object/Error.h"
29 #include "llvm/Object/ObjectFile.h"
33 #include "llvm/Support/Casting.h"
34 #include "llvm/Support/Endian.h"
35 #include "llvm/Support/Error.h"
38 #include <cassert>
39 #include <cstdint>
40 #include <system_error>
41 
42 namespace llvm {
43 namespace object {
44 
45 class elf_symbol_iterator;
46 
47 class ELFObjectFileBase : public ObjectFile {
48  friend class ELFRelocationRef;
49  friend class ELFSectionRef;
50  friend class ELFSymbolRef;
51 
52 protected:
54 
55  virtual uint16_t getEMachine() const = 0;
56  virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0;
57  virtual uint8_t getSymbolOther(DataRefImpl Symb) const = 0;
58  virtual uint8_t getSymbolELFType(DataRefImpl Symb) const = 0;
59 
60  virtual uint32_t getSectionType(DataRefImpl Sec) const = 0;
61  virtual uint64_t getSectionFlags(DataRefImpl Sec) const = 0;
62  virtual uint64_t getSectionOffset(DataRefImpl Sec) const = 0;
63 
64  virtual Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
65 
66 public:
68 
70 
71  /// Returns platform-specific object flags, if any.
72  virtual unsigned getPlatformFlags() const = 0;
73 
75 
76  static bool classof(const Binary *v) { return v->isELF(); }
77 
78  SubtargetFeatures getFeatures() const override;
79 
81 
83 
85 
86  void setARMSubArch(Triple &TheTriple) const override;
87 
88  virtual uint16_t getEType() const = 0;
89 };
90 
91 class ELFSectionRef : public SectionRef {
92 public:
94  assert(isa<ELFObjectFileBase>(SectionRef::getObject()));
95  }
96 
97  const ELFObjectFileBase *getObject() const {
98  return cast<ELFObjectFileBase>(SectionRef::getObject());
99  }
100 
101  uint32_t getType() const {
102  return getObject()->getSectionType(getRawDataRefImpl());
103  }
104 
105  uint64_t getFlags() const {
106  return getObject()->getSectionFlags(getRawDataRefImpl());
107  }
108 
109  uint64_t getOffset() const {
110  return getObject()->getSectionOffset(getRawDataRefImpl());
111  }
112 };
113 
115 public:
117  assert(isa<ELFObjectFileBase>(B->getObject()));
118  }
119 
120  const ELFSectionRef *operator->() const {
121  return static_cast<const ELFSectionRef *>(section_iterator::operator->());
122  }
123 
124  const ELFSectionRef &operator*() const {
125  return static_cast<const ELFSectionRef &>(section_iterator::operator*());
126  }
127 };
128 
129 class ELFSymbolRef : public SymbolRef {
130 public:
132  assert(isa<ELFObjectFileBase>(SymbolRef::getObject()));
133  }
134 
135  const ELFObjectFileBase *getObject() const {
136  return cast<ELFObjectFileBase>(BasicSymbolRef::getObject());
137  }
138 
139  uint64_t getSize() const {
140  return getObject()->getSymbolSize(getRawDataRefImpl());
141  }
142 
143  uint8_t getOther() const {
144  return getObject()->getSymbolOther(getRawDataRefImpl());
145  }
146 
147  uint8_t getELFType() const {
148  return getObject()->getSymbolELFType(getRawDataRefImpl());
149  }
150 };
151 
153 public:
155  : symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
156  cast<ELFObjectFileBase>(B->getObject()))) {}
157 
158  const ELFSymbolRef *operator->() const {
159  return static_cast<const ELFSymbolRef *>(symbol_iterator::operator->());
160  }
161 
162  const ELFSymbolRef &operator*() const {
163  return static_cast<const ELFSymbolRef &>(symbol_iterator::operator*());
164  }
165 };
166 
168 public:
170  assert(isa<ELFObjectFileBase>(RelocationRef::getObject()));
171  }
172 
173  const ELFObjectFileBase *getObject() const {
174  return cast<ELFObjectFileBase>(RelocationRef::getObject());
175  }
176 
178  return getObject()->getRelocationAddend(getRawDataRefImpl());
179  }
180 };
181 
183 public:
186  B->getRawDataRefImpl(), cast<ELFObjectFileBase>(B->getObject()))) {}
187 
188  const ELFRelocationRef *operator->() const {
189  return static_cast<const ELFRelocationRef *>(
191  }
192 
193  const ELFRelocationRef &operator*() const {
194  return static_cast<const ELFRelocationRef &>(
196  }
197 };
198 
202 }
203 
204 template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
205  uint16_t getEMachine() const override;
206  uint16_t getEType() const override;
207  uint64_t getSymbolSize(DataRefImpl Sym) const override;
208 
209 public:
211 
212  using uintX_t = typename ELFT::uint;
213 
214  using Elf_Sym = typename ELFT::Sym;
215  using Elf_Shdr = typename ELFT::Shdr;
216  using Elf_Ehdr = typename ELFT::Ehdr;
217  using Elf_Rel = typename ELFT::Rel;
218  using Elf_Rela = typename ELFT::Rela;
219  using Elf_Dyn = typename ELFT::Dyn;
220 
221 private:
222  ELFObjectFile(MemoryBufferRef Object, ELFFile<ELFT> EF,
223  const Elf_Shdr *DotDynSymSec, const Elf_Shdr *DotSymtabSec,
224  ArrayRef<Elf_Word> ShndxTable);
225 
226 protected:
227  ELFFile<ELFT> EF;
228 
229  const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
230  const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section.
231  ArrayRef<Elf_Word> ShndxTable;
232 
233  void moveSymbolNext(DataRefImpl &Symb) const override;
235  Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
236  uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
238  uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
239  uint32_t getSymbolFlags(DataRefImpl Symb) const override;
240  uint8_t getSymbolOther(DataRefImpl Symb) const override;
241  uint8_t getSymbolELFType(DataRefImpl Symb) const override;
244  const Elf_Shdr *SymTab) const;
246 
247  void moveSectionNext(DataRefImpl &Sec) const override;
248  std::error_code getSectionName(DataRefImpl Sec,
249  StringRef &Res) const override;
250  uint64_t getSectionAddress(DataRefImpl Sec) const override;
251  uint64_t getSectionIndex(DataRefImpl Sec) const override;
252  uint64_t getSectionSize(DataRefImpl Sec) const override;
253  std::error_code getSectionContents(DataRefImpl Sec,
254  StringRef &Res) const override;
255  uint64_t getSectionAlignment(DataRefImpl Sec) const override;
256  bool isSectionCompressed(DataRefImpl Sec) const override;
257  bool isSectionText(DataRefImpl Sec) const override;
258  bool isSectionData(DataRefImpl Sec) const override;
259  bool isSectionBSS(DataRefImpl Sec) const override;
260  bool isSectionVirtual(DataRefImpl Sec) const override;
262  relocation_iterator section_rel_end(DataRefImpl Sec) const override;
263  std::vector<SectionRef> dynamic_relocation_sections() const override;
265 
266  void moveRelocationNext(DataRefImpl &Rel) const override;
267  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
268  symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
269  uint64_t getRelocationType(DataRefImpl Rel) const override;
271  SmallVectorImpl<char> &Result) const override;
272 
273  uint32_t getSectionType(DataRefImpl Sec) const override;
274  uint64_t getSectionFlags(DataRefImpl Sec) const override;
275  uint64_t getSectionOffset(DataRefImpl Sec) const override;
277 
278  /// Get the relocation section that contains \a Rel.
279  const Elf_Shdr *getRelSection(DataRefImpl Rel) const {
280  auto RelSecOrErr = EF.getSection(Rel.d.a);
281  if (!RelSecOrErr)
282  report_fatal_error(errorToErrorCode(RelSecOrErr.takeError()).message());
283  return *RelSecOrErr;
284  }
285 
286  DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const {
287  DataRefImpl DRI;
288  if (!SymTable) {
289  DRI.d.a = 0;
290  DRI.d.b = 0;
291  return DRI;
292  }
293  assert(SymTable->sh_type == ELF::SHT_SYMTAB ||
294  SymTable->sh_type == ELF::SHT_DYNSYM);
295 
296  auto SectionsOrErr = EF.sections();
297  if (!SectionsOrErr) {
298  DRI.d.a = 0;
299  DRI.d.b = 0;
300  return DRI;
301  }
302  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
303  unsigned SymTableIndex =
304  (reinterpret_cast<uintptr_t>(SymTable) - SHT) / sizeof(Elf_Shdr);
305 
306  DRI.d.a = SymTableIndex;
307  DRI.d.b = SymbolNum;
308  return DRI;
309  }
310 
311  const Elf_Shdr *toELFShdrIter(DataRefImpl Sec) const {
312  return reinterpret_cast<const Elf_Shdr *>(Sec.p);
313  }
314 
315  DataRefImpl toDRI(const Elf_Shdr *Sec) const {
316  DataRefImpl DRI;
317  DRI.p = reinterpret_cast<uintptr_t>(Sec);
318  return DRI;
319  }
320 
321  DataRefImpl toDRI(const Elf_Dyn *Dyn) const {
322  DataRefImpl DRI;
323  DRI.p = reinterpret_cast<uintptr_t>(Dyn);
324  return DRI;
325  }
326 
327  bool isExportedToOtherDSO(const Elf_Sym *ESym) const {
328  unsigned char Binding = ESym->getBinding();
329  unsigned char Visibility = ESym->getVisibility();
330 
331  // A symbol is exported if its binding is either GLOBAL or WEAK, and its
332  // visibility is either DEFAULT or PROTECTED. All other symbols are not
333  // exported.
334  return ((Binding == ELF::STB_GLOBAL || Binding == ELF::STB_WEAK) &&
335  (Visibility == ELF::STV_DEFAULT ||
336  Visibility == ELF::STV_PROTECTED));
337  }
338 
339  // This flag is used for classof, to distinguish ELFObjectFile from
340  // its subclass. If more subclasses will be created, this flag will
341  // have to become an enum.
343 
344 public:
346  static Expected<ELFObjectFile<ELFT>> create(MemoryBufferRef Object);
347 
348  const Elf_Rel *getRel(DataRefImpl Rel) const;
349  const Elf_Rela *getRela(DataRefImpl Rela) const;
350 
351  const Elf_Sym *getSymbol(DataRefImpl Sym) const {
352  auto Ret = EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
353  if (!Ret)
354  report_fatal_error(errorToErrorCode(Ret.takeError()).message());
355  return *Ret;
356  }
357 
358  const Elf_Shdr *getSection(DataRefImpl Sec) const {
359  return reinterpret_cast<const Elf_Shdr *>(Sec.p);
360  }
361 
362  basic_symbol_iterator symbol_begin() const override;
363  basic_symbol_iterator symbol_end() const override;
364 
365  elf_symbol_iterator dynamic_symbol_begin() const;
366  elf_symbol_iterator dynamic_symbol_end() const;
367 
368  section_iterator section_begin() const override;
369  section_iterator section_end() const override;
370 
372 
373  uint8_t getBytesInAddress() const override;
374  StringRef getFileFormatName() const override;
375  Triple::ArchType getArch() const override;
376 
377  unsigned getPlatformFlags() const override { return EF.getHeader()->e_flags; }
378 
379  std::error_code getBuildAttributes(ARMAttributeParser &Attributes) const override {
380  auto SectionsOrErr = EF.sections();
381  if (!SectionsOrErr)
382  return errorToErrorCode(SectionsOrErr.takeError());
383 
384  for (const Elf_Shdr &Sec : *SectionsOrErr) {
385  if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES) {
386  auto ErrorOrContents = EF.getSectionContents(&Sec);
387  if (!ErrorOrContents)
388  return errorToErrorCode(ErrorOrContents.takeError());
389 
390  auto Contents = ErrorOrContents.get();
391  if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1)
392  return std::error_code();
393 
394  Attributes.Parse(Contents, ELFT::TargetEndianness == support::little);
395  break;
396  }
397  }
398  return std::error_code();
399  }
400 
401  const ELFFile<ELFT> *getELFFile() const { return &EF; }
402 
403  bool isDyldType() const { return isDyldELFObject; }
404  static bool classof(const Binary *v) {
405  return v->getType() == getELFType(ELFT::TargetEndianness == support::little,
406  ELFT::Is64Bits);
407  }
408 
410 
411  bool isRelocatableObject() const override;
412 };
413 
418 
419 template <class ELFT>
421  ++Sym.d.b;
422 }
423 
424 template <class ELFT>
426  const Elf_Sym *ESym = getSymbol(Sym);
427  auto SymTabOrErr = EF.getSection(Sym.d.a);
428  if (!SymTabOrErr)
429  return SymTabOrErr.takeError();
430  const Elf_Shdr *SymTableSec = *SymTabOrErr;
431  auto StrTabOrErr = EF.getSection(SymTableSec->sh_link);
432  if (!StrTabOrErr)
433  return StrTabOrErr.takeError();
434  const Elf_Shdr *StringTableSec = *StrTabOrErr;
435  auto SymStrTabOrErr = EF.getStringTable(StringTableSec);
436  if (!SymStrTabOrErr)
437  return SymStrTabOrErr.takeError();
438  return ESym->getName(*SymStrTabOrErr);
439 }
440 
441 template <class ELFT>
443  return getSection(Sec)->sh_flags;
444 }
445 
446 template <class ELFT>
448  return getSection(Sec)->sh_type;
449 }
450 
451 template <class ELFT>
453  return getSection(Sec)->sh_offset;
454 }
455 
456 template <class ELFT>
458  const Elf_Sym *ESym = getSymbol(Symb);
459  uint64_t Ret = ESym->st_value;
460  if (ESym->st_shndx == ELF::SHN_ABS)
461  return Ret;
462 
463  const Elf_Ehdr *Header = EF.getHeader();
464  // Clear the ARM/Thumb or microMIPS indicator flag.
465  if ((Header->e_machine == ELF::EM_ARM || Header->e_machine == ELF::EM_MIPS) &&
466  ESym->getType() == ELF::STT_FUNC)
467  Ret &= ~1;
468 
469  return Ret;
470 }
471 
472 template <class ELFT>
475  uint64_t Result = getSymbolValue(Symb);
476  const Elf_Sym *ESym = getSymbol(Symb);
477  switch (ESym->st_shndx) {
478  case ELF::SHN_COMMON:
479  case ELF::SHN_UNDEF:
480  case ELF::SHN_ABS:
481  return Result;
482  }
483 
484  const Elf_Ehdr *Header = EF.getHeader();
485  auto SymTabOrErr = EF.getSection(Symb.d.a);
486  if (!SymTabOrErr)
487  return SymTabOrErr.takeError();
488  const Elf_Shdr *SymTab = *SymTabOrErr;
489 
490  if (Header->e_type == ELF::ET_REL) {
491  auto SectionOrErr = EF.getSection(ESym, SymTab, ShndxTable);
492  if (!SectionOrErr)
493  return SectionOrErr.takeError();
494  const Elf_Shdr *Section = *SectionOrErr;
495  if (Section)
496  Result += Section->sh_addr;
497  }
498 
499  return Result;
500 }
501 
502 template <class ELFT>
504  const Elf_Sym *Sym = getSymbol(Symb);
505  if (Sym->st_shndx == ELF::SHN_COMMON)
506  return Sym->st_value;
507  return 0;
508 }
509 
510 template <class ELFT>
511 uint16_t ELFObjectFile<ELFT>::getEMachine() const {
512  return EF.getHeader()->e_machine;
513 }
514 
515 template <class ELFT> uint16_t ELFObjectFile<ELFT>::getEType() const {
516  return EF.getHeader()->e_type;
517 }
518 
519 template <class ELFT>
521  return getSymbol(Sym)->st_size;
522 }
523 
524 template <class ELFT>
526  return getSymbol(Symb)->st_size;
527 }
528 
529 template <class ELFT>
531  return getSymbol(Symb)->st_other;
532 }
533 
534 template <class ELFT>
536  return getSymbol(Symb)->getType();
537 }
538 
539 template <class ELFT>
542  const Elf_Sym *ESym = getSymbol(Symb);
543 
544  switch (ESym->getType()) {
545  case ELF::STT_NOTYPE:
546  return SymbolRef::ST_Unknown;
547  case ELF::STT_SECTION:
548  return SymbolRef::ST_Debug;
549  case ELF::STT_FILE:
550  return SymbolRef::ST_File;
551  case ELF::STT_FUNC:
552  return SymbolRef::ST_Function;
553  case ELF::STT_OBJECT:
554  case ELF::STT_COMMON:
555  case ELF::STT_TLS:
556  return SymbolRef::ST_Data;
557  default:
558  return SymbolRef::ST_Other;
559  }
560 }
561 
562 template <class ELFT>
564  const Elf_Sym *ESym = getSymbol(Sym);
565 
566  uint32_t Result = SymbolRef::SF_None;
567 
568  if (ESym->getBinding() != ELF::STB_LOCAL)
569  Result |= SymbolRef::SF_Global;
570 
571  if (ESym->getBinding() == ELF::STB_WEAK)
572  Result |= SymbolRef::SF_Weak;
573 
574  if (ESym->st_shndx == ELF::SHN_ABS)
575  Result |= SymbolRef::SF_Absolute;
576 
577  if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION)
579 
580  auto DotSymtabSecSyms = EF.symbols(DotSymtabSec);
581  if (DotSymtabSecSyms && ESym == (*DotSymtabSecSyms).begin())
583  auto DotDynSymSecSyms = EF.symbols(DotDynSymSec);
584  if (DotDynSymSecSyms && ESym == (*DotDynSymSecSyms).begin())
586 
587  if (EF.getHeader()->e_machine == ELF::EM_ARM) {
588  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
589  StringRef Name = *NameOrErr;
590  if (Name.startswith("$d") || Name.startswith("$t") ||
591  Name.startswith("$a"))
593  } else {
594  // TODO: Actually report errors helpfully.
595  consumeError(NameOrErr.takeError());
596  }
597  if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
598  Result |= SymbolRef::SF_Thumb;
599  }
600 
601  if (ESym->st_shndx == ELF::SHN_UNDEF)
602  Result |= SymbolRef::SF_Undefined;
603 
604  if (ESym->getType() == ELF::STT_COMMON || ESym->st_shndx == ELF::SHN_COMMON)
605  Result |= SymbolRef::SF_Common;
606 
607  if (isExportedToOtherDSO(ESym))
608  Result |= SymbolRef::SF_Exported;
609 
610  if (ESym->getVisibility() == ELF::STV_HIDDEN)
611  Result |= SymbolRef::SF_Hidden;
612 
613  return Result;
614 }
615 
616 template <class ELFT>
619  const Elf_Shdr *SymTab) const {
620  auto ESecOrErr = EF.getSection(ESym, SymTab, ShndxTable);
621  if (!ESecOrErr)
622  return ESecOrErr.takeError();
623 
624  const Elf_Shdr *ESec = *ESecOrErr;
625  if (!ESec)
626  return section_end();
627 
628  DataRefImpl Sec;
629  Sec.p = reinterpret_cast<intptr_t>(ESec);
630  return section_iterator(SectionRef(Sec, this));
631 }
632 
633 template <class ELFT>
636  const Elf_Sym *Sym = getSymbol(Symb);
637  auto SymTabOrErr = EF.getSection(Symb.d.a);
638  if (!SymTabOrErr)
639  return SymTabOrErr.takeError();
640  const Elf_Shdr *SymTab = *SymTabOrErr;
641  return getSymbolSection(Sym, SymTab);
642 }
643 
644 template <class ELFT>
646  const Elf_Shdr *ESec = getSection(Sec);
647  Sec = toDRI(++ESec);
648 }
649 
650 template <class ELFT>
652  StringRef &Result) const {
653  auto Name = EF.getSectionName(&*getSection(Sec));
654  if (!Name)
655  return errorToErrorCode(Name.takeError());
656  Result = *Name;
657  return std::error_code();
658 }
659 
660 template <class ELFT>
662  return getSection(Sec)->sh_addr;
663 }
664 
665 template <class ELFT>
667  auto SectionsOrErr = EF.sections();
668  handleAllErrors(std::move(SectionsOrErr.takeError()),
669  [](const ErrorInfoBase &) {
670  llvm_unreachable("unable to get section index");
671  });
672  const Elf_Shdr *First = SectionsOrErr->begin();
673  return getSection(Sec) - First;
674 }
675 
676 template <class ELFT>
678  return getSection(Sec)->sh_size;
679 }
680 
681 template <class ELFT>
682 std::error_code
684  StringRef &Result) const {
685  const Elf_Shdr *EShdr = getSection(Sec);
686  if (std::error_code EC =
688  (uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))
689  return EC;
690  Result = StringRef((const char *)base() + EShdr->sh_offset, EShdr->sh_size);
691  return std::error_code();
692 }
693 
694 template <class ELFT>
696  return getSection(Sec)->sh_addralign;
697 }
698 
699 template <class ELFT>
701  return getSection(Sec)->sh_flags & ELF::SHF_COMPRESSED;
702 }
703 
704 template <class ELFT>
706  return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR;
707 }
708 
709 template <class ELFT>
711  const Elf_Shdr *EShdr = getSection(Sec);
712  return EShdr->sh_type == ELF::SHT_PROGBITS &&
713  EShdr->sh_flags & ELF::SHF_ALLOC &&
714  !(EShdr->sh_flags & ELF::SHF_EXECINSTR);
715 }
716 
717 template <class ELFT>
719  const Elf_Shdr *EShdr = getSection(Sec);
720  return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
721  EShdr->sh_type == ELF::SHT_NOBITS;
722 }
723 
724 template <class ELFT>
725 std::vector<SectionRef>
727  std::vector<SectionRef> Res;
728  std::vector<uintptr_t> Offsets;
729 
730  auto SectionsOrErr = EF.sections();
731  if (!SectionsOrErr)
732  return Res;
733 
734  for (const Elf_Shdr &Sec : *SectionsOrErr) {
735  if (Sec.sh_type != ELF::SHT_DYNAMIC)
736  continue;
737  Elf_Dyn *Dynamic =
738  reinterpret_cast<Elf_Dyn *>((uintptr_t)base() + Sec.sh_offset);
739  for (; Dynamic->d_tag != ELF::DT_NULL; Dynamic++) {
740  if (Dynamic->d_tag == ELF::DT_REL || Dynamic->d_tag == ELF::DT_RELA ||
741  Dynamic->d_tag == ELF::DT_JMPREL) {
742  Offsets.push_back(Dynamic->d_un.d_val);
743  }
744  }
745  }
746  for (const Elf_Shdr &Sec : *SectionsOrErr) {
747  if (is_contained(Offsets, Sec.sh_offset))
748  Res.emplace_back(toDRI(&Sec), this);
749  }
750  return Res;
751 }
752 
753 template <class ELFT>
755  return getSection(Sec)->sh_type == ELF::SHT_NOBITS;
756 }
757 
758 template <class ELFT>
761  DataRefImpl RelData;
762  auto SectionsOrErr = EF.sections();
763  if (!SectionsOrErr)
765  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
766  RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize;
767  RelData.d.b = 0;
768  return relocation_iterator(RelocationRef(RelData, this));
769 }
770 
771 template <class ELFT>
774  const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p);
776  if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
777  return Begin;
778  DataRefImpl RelData = Begin->getRawDataRefImpl();
779  const Elf_Shdr *RelSec = getRelSection(RelData);
780 
781  // Error check sh_link here so that getRelocationSymbol can just use it.
782  auto SymSecOrErr = EF.getSection(RelSec->sh_link);
783  if (!SymSecOrErr)
784  report_fatal_error(errorToErrorCode(SymSecOrErr.takeError()).message());
785 
786  RelData.d.b += S->sh_size / S->sh_entsize;
787  return relocation_iterator(RelocationRef(RelData, this));
788 }
789 
790 template <class ELFT>
793  if (EF.getHeader()->e_type != ELF::ET_REL)
794  return section_end();
795 
796  const Elf_Shdr *EShdr = getSection(Sec);
797  uintX_t Type = EShdr->sh_type;
798  if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA)
799  return section_end();
800 
801  auto R = EF.getSection(EShdr->sh_info);
802  if (!R)
803  report_fatal_error(errorToErrorCode(R.takeError()).message());
804  return section_iterator(SectionRef(toDRI(*R), this));
805 }
806 
807 // Relocations
808 template <class ELFT>
810  ++Rel.d.b;
811 }
812 
813 template <class ELFT>
816  uint32_t symbolIdx;
817  const Elf_Shdr *sec = getRelSection(Rel);
818  if (sec->sh_type == ELF::SHT_REL)
819  symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL());
820  else
821  symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL());
822  if (!symbolIdx)
823  return symbol_end();
824 
825  // FIXME: error check symbolIdx
826  DataRefImpl SymbolData;
827  SymbolData.d.a = sec->sh_link;
828  SymbolData.d.b = symbolIdx;
829  return symbol_iterator(SymbolRef(SymbolData, this));
830 }
831 
832 template <class ELFT>
834  const Elf_Shdr *sec = getRelSection(Rel);
835  if (sec->sh_type == ELF::SHT_REL)
836  return getRel(Rel)->r_offset;
837 
838  return getRela(Rel)->r_offset;
839 }
840 
841 template <class ELFT>
843  const Elf_Shdr *sec = getRelSection(Rel);
844  if (sec->sh_type == ELF::SHT_REL)
845  return getRel(Rel)->getType(EF.isMips64EL());
846  else
847  return getRela(Rel)->getType(EF.isMips64EL());
848 }
849 
850 template <class ELFT>
852  return getELFRelocationTypeName(EF.getHeader()->e_machine, Type);
853 }
854 
855 template <class ELFT>
857  DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
858  uint32_t type = getRelocationType(Rel);
859  EF.getRelocationTypeName(type, Result);
860 }
861 
862 template <class ELFT>
865  if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
866  return createError("Section is not SHT_RELA");
867  return (int64_t)getRela(Rel)->r_addend;
868 }
869 
870 template <class ELFT>
871 const typename ELFObjectFile<ELFT>::Elf_Rel *
873  assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
874  auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
875  if (!Ret)
876  report_fatal_error(errorToErrorCode(Ret.takeError()).message());
877  return *Ret;
878 }
879 
880 template <class ELFT>
881 const typename ELFObjectFile<ELFT>::Elf_Rela *
883  assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
884  auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
885  if (!Ret)
886  report_fatal_error(errorToErrorCode(Ret.takeError()).message());
887  return *Ret;
888 }
889 
890 template <class ELFT>
893  auto EFOrErr = ELFFile<ELFT>::create(Object.getBuffer());
894  if (Error E = EFOrErr.takeError())
895  return std::move(E);
896  auto EF = std::move(*EFOrErr);
897 
898  auto SectionsOrErr = EF.sections();
899  if (!SectionsOrErr)
900  return SectionsOrErr.takeError();
901 
902  const Elf_Shdr *DotDynSymSec = nullptr;
903  const Elf_Shdr *DotSymtabSec = nullptr;
904  ArrayRef<Elf_Word> ShndxTable;
905  for (const Elf_Shdr &Sec : *SectionsOrErr) {
906  switch (Sec.sh_type) {
907  case ELF::SHT_DYNSYM: {
908  if (DotDynSymSec)
909  return createError("More than one dynamic symbol table!");
910  DotDynSymSec = &Sec;
911  break;
912  }
913  case ELF::SHT_SYMTAB: {
914  if (DotSymtabSec)
915  return createError("More than one static symbol table!");
916  DotSymtabSec = &Sec;
917  break;
918  }
919  case ELF::SHT_SYMTAB_SHNDX: {
920  auto TableOrErr = EF.getSHNDXTable(Sec);
921  if (!TableOrErr)
922  return TableOrErr.takeError();
923  ShndxTable = *TableOrErr;
924  break;
925  }
926  }
927  }
928  return ELFObjectFile<ELFT>(Object, EF, DotDynSymSec, DotSymtabSec,
929  ShndxTable);
930 }
931 
932 template <class ELFT>
934  const Elf_Shdr *DotDynSymSec,
935  const Elf_Shdr *DotSymtabSec,
936  ArrayRef<Elf_Word> ShndxTable)
938  getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits),
939  Object),
940  EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec),
941  ShndxTable(ShndxTable) {}
942 
943 template <class ELFT>
944 ELFObjectFile<ELFT>::ELFObjectFile(ELFObjectFile<ELFT> &&Other)
945  : ELFObjectFile(Other.Data, Other.EF, Other.DotDynSymSec,
946  Other.DotSymtabSec, Other.ShndxTable) {}
947 
948 template <class ELFT>
950  DataRefImpl Sym = toDRI(DotSymtabSec, 0);
951  return basic_symbol_iterator(SymbolRef(Sym, this));
952 }
953 
954 template <class ELFT>
956  const Elf_Shdr *SymTab = DotSymtabSec;
957  if (!SymTab)
958  return symbol_begin();
959  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
960  return basic_symbol_iterator(SymbolRef(Sym, this));
961 }
962 
963 template <class ELFT>
965  DataRefImpl Sym = toDRI(DotDynSymSec, 0);
966  return symbol_iterator(SymbolRef(Sym, this));
967 }
968 
969 template <class ELFT>
971  const Elf_Shdr *SymTab = DotDynSymSec;
972  if (!SymTab)
973  return dynamic_symbol_begin();
974  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
975  return basic_symbol_iterator(SymbolRef(Sym, this));
976 }
977 
978 template <class ELFT>
980  auto SectionsOrErr = EF.sections();
981  if (!SectionsOrErr)
982  return section_iterator(SectionRef());
983  return section_iterator(SectionRef(toDRI((*SectionsOrErr).begin()), this));
984 }
985 
986 template <class ELFT>
988  auto SectionsOrErr = EF.sections();
989  if (!SectionsOrErr)
990  return section_iterator(SectionRef());
991  return section_iterator(SectionRef(toDRI((*SectionsOrErr).end()), this));
992 }
993 
994 template <class ELFT>
996  return ELFT::Is64Bits ? 8 : 4;
997 }
998 
999 template <class ELFT>
1001  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1002  switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
1003  case ELF::ELFCLASS32:
1004  switch (EF.getHeader()->e_machine) {
1005  case ELF::EM_386:
1006  return "ELF32-i386";
1007  case ELF::EM_IAMCU:
1008  return "ELF32-iamcu";
1009  case ELF::EM_X86_64:
1010  return "ELF32-x86-64";
1011  case ELF::EM_ARM:
1012  return (IsLittleEndian ? "ELF32-arm-little" : "ELF32-arm-big");
1013  case ELF::EM_AVR:
1014  return "ELF32-avr";
1015  case ELF::EM_HEXAGON:
1016  return "ELF32-hexagon";
1017  case ELF::EM_LANAI:
1018  return "ELF32-lanai";
1019  case ELF::EM_MIPS:
1020  return "ELF32-mips";
1021  case ELF::EM_PPC:
1022  return "ELF32-ppc";
1023  case ELF::EM_RISCV:
1024  return "ELF32-riscv";
1025  case ELF::EM_SPARC:
1026  case ELF::EM_SPARC32PLUS:
1027  return "ELF32-sparc";
1028  case ELF::EM_WEBASSEMBLY:
1029  return "ELF32-wasm";
1030  case ELF::EM_AMDGPU:
1031  return "ELF32-amdgpu";
1032  default:
1033  return "ELF32-unknown";
1034  }
1035  case ELF::ELFCLASS64:
1036  switch (EF.getHeader()->e_machine) {
1037  case ELF::EM_386:
1038  return "ELF64-i386";
1039  case ELF::EM_X86_64:
1040  return "ELF64-x86-64";
1041  case ELF::EM_AARCH64:
1042  return (IsLittleEndian ? "ELF64-aarch64-little" : "ELF64-aarch64-big");
1043  case ELF::EM_PPC64:
1044  return "ELF64-ppc64";
1045  case ELF::EM_RISCV:
1046  return "ELF64-riscv";
1047  case ELF::EM_S390:
1048  return "ELF64-s390";
1049  case ELF::EM_SPARCV9:
1050  return "ELF64-sparc";
1051  case ELF::EM_MIPS:
1052  return "ELF64-mips";
1053  case ELF::EM_WEBASSEMBLY:
1054  return "ELF64-wasm";
1055  case ELF::EM_AMDGPU:
1056  return "ELF64-amdgpu";
1057  case ELF::EM_BPF:
1058  return "ELF64-BPF";
1059  default:
1060  return "ELF64-unknown";
1061  }
1062  default:
1063  // FIXME: Proper error handling.
1064  report_fatal_error("Invalid ELFCLASS!");
1065  }
1066 }
1067 
1068 template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
1069  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1070  switch (EF.getHeader()->e_machine) {
1071  case ELF::EM_386:
1072  case ELF::EM_IAMCU:
1073  return Triple::x86;
1074  case ELF::EM_X86_64:
1075  return Triple::x86_64;
1076  case ELF::EM_AARCH64:
1077  return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be;
1078  case ELF::EM_ARM:
1079  return Triple::arm;
1080  case ELF::EM_AVR:
1081  return Triple::avr;
1082  case ELF::EM_HEXAGON:
1083  return Triple::hexagon;
1084  case ELF::EM_LANAI:
1085  return Triple::lanai;
1086  case ELF::EM_MIPS:
1087  switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
1088  case ELF::ELFCLASS32:
1089  return IsLittleEndian ? Triple::mipsel : Triple::mips;
1090  case ELF::ELFCLASS64:
1091  return IsLittleEndian ? Triple::mips64el : Triple::mips64;
1092  default:
1093  report_fatal_error("Invalid ELFCLASS!");
1094  }
1095  case ELF::EM_PPC:
1096  return Triple::ppc;
1097  case ELF::EM_PPC64:
1098  return IsLittleEndian ? Triple::ppc64le : Triple::ppc64;
1099  case ELF::EM_RISCV:
1100  switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
1101  case ELF::ELFCLASS32:
1102  return Triple::riscv32;
1103  case ELF::ELFCLASS64:
1104  return Triple::riscv64;
1105  default:
1106  report_fatal_error("Invalid ELFCLASS!");
1107  }
1108  case ELF::EM_S390:
1109  return Triple::systemz;
1110 
1111  case ELF::EM_SPARC:
1112  case ELF::EM_SPARC32PLUS:
1113  return IsLittleEndian ? Triple::sparcel : Triple::sparc;
1114  case ELF::EM_SPARCV9:
1115  return Triple::sparcv9;
1116  case ELF::EM_WEBASSEMBLY:
1117  switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
1118  case ELF::ELFCLASS32: return Triple::wasm32;
1119  case ELF::ELFCLASS64: return Triple::wasm64;
1120  default: return Triple::UnknownArch;
1121  }
1122 
1123  case ELF::EM_AMDGPU: {
1124  if (!IsLittleEndian)
1125  return Triple::UnknownArch;
1126 
1127  unsigned MACH = EF.getHeader()->e_flags & ELF::EF_AMDGPU_MACH;
1128  if (MACH >= ELF::EF_AMDGPU_MACH_R600_FIRST &&
1130  return Triple::r600;
1131  if (MACH >= ELF::EF_AMDGPU_MACH_AMDGCN_FIRST &&
1133  return Triple::amdgcn;
1134 
1135  return Triple::UnknownArch;
1136  }
1137 
1138  case ELF::EM_BPF:
1139  return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
1140 
1141  default:
1142  return Triple::UnknownArch;
1143  }
1144 }
1145 
1146 template <class ELFT>
1150 }
1151 
1152 template <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const {
1153  return EF.getHeader()->e_type == ELF::ET_REL;
1154 }
1155 
1156 } // end namespace object
1157 } // end namespace llvm
1158 
1159 #endif // LLVM_OBJECT_ELFOBJECTFILE_H
const content_type & operator*() const
Definition: SymbolicFile.h:79
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
uint64_t getSectionSize(DataRefImpl Sec) const override
virtual uint16_t getEMachine() const =0
static bool classof(const Binary *v)
friend class SymbolRef
Definition: ObjectFile.h:208
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:115
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static Expected< ELFFile > create(StringRef Object)
Definition: ELF.h:427
SubtargetFeatures getFeatures() const override
const Elf_Shdr * toELFShdrIter(DataRefImpl Sec) const
std::vector< SectionRef > dynamic_relocation_sections() const override
bool isSectionBSS(DataRefImpl Sec) const override
bool isSectionText(DataRefImpl Sec) const override
friend class SectionRef
Definition: ObjectFile.h:222
elf_relocation_iterator(const relocation_iterator &B)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
const ELFObjectFileBase * getObject() const
static std::error_code getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
void moveSymbolNext(DataRefImpl &Symb) const override
static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr, const uint64_t Size)
Definition: Binary.h:148
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:928
virtual bool isSectionBSS(DataRefImpl Sec) const =0
This class is the base class for all object file types.
Definition: ObjectFile.h:190
elf_symbol_iterator_range symbols() const
typename ELFT::Rel Elf_Rel
virtual uint64_t getRelocationOffset(DataRefImpl Rel) const =0
const uint8_t * base() const
Definition: ObjectFile.h:196
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:769
virtual std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const =0
static Error createError(StringRef Err)
Definition: ELF.h:47
const ObjectFile * getObject() const
Definition: ObjectFile.h:503
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const
Definition: ObjectFile.cpp:69
Base class for error info classes.
Definition: Error.h:47
bool isSectionVirtual(DataRefImpl Sec) const override
virtual Expected< StringRef > getSymbolName(DataRefImpl Symb) const =0
uint32_t getSectionType(DataRefImpl Sec) const override
virtual Expected< int64_t > getRelocationAddend(DataRefImpl Rel) const =0
void moveRelocationNext(DataRefImpl &Rel) const override
virtual relocation_iterator section_rel_end(DataRefImpl Sec) const =0
basic_symbol_iterator symbol_begin() const override
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
virtual basic_symbol_iterator symbol_begin() const =0
Definition: BitVector.h:921
void setARMSubArch(Triple &TheTriple) const override
uint8_t getSymbolOther(DataRefImpl Symb) const override
const Elf_Shdr * DotSymtabSec
uint64_t getSectionAlignment(DataRefImpl Sec) const override
virtual std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const =0
Expected< Elf_Shdr_Range > sections() const
Definition: ELF.h:434
StringRef getBuffer() const
Definition: MemoryBuffer.h:277
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
This is a value type class that represents a single relocation in the list of relocations in the obje...
Definition: ObjectFile.h:52
Expected< section_iterator > getSymbolSection(const Elf_Sym *Symb, const Elf_Shdr *SymTab) const
elf_section_iterator(const section_iterator &B)
typename ELFT::Ehdr Elf_Ehdr
virtual uint64_t getSectionIndex(DataRefImpl Sec) const =0
const ELFObjectFileBase * getObject() const
Definition: ELFObjectFile.h:97
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:770
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: ELF.h:258
virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const =0
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:48
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
const ObjectFile * getObject() const
Definition: ObjectFile.h:370
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const
virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const =0
section_iterator section_begin() const override
std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override
MemoryBufferRef getMemoryBufferRef() const
Definition: Binary.cpp:43
void moveSectionNext(DataRefImpl &Sec) const override
elf_symbol_iterator_range getDynamicSymbolIterators() const override
virtual uint64_t getSectionAlignment(DataRefImpl Sec) const =0
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
DataRefImpl toDRI(const Elf_Dyn *Dyn) const
std::error_code getBuildAttributes(ARMAttributeParser &Attributes) const override
const ObjectFile * getObject() const
Definition: ObjectFile.h:465
virtual uint64_t getSectionOffset(DataRefImpl Sec) const =0
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
Definition: ELF.h:320
std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
Definition: Casting.h:240
elf_symbol_iterator dynamic_symbol_begin() const
relocation_iterator section_rel_end(DataRefImpl Sec) const override
typename ELFT::Shdr Elf_Shdr
Expected< int64_t > getRelocationAddend(DataRefImpl Rel) const override
const content_type * operator->() const
Definition: SymbolicFile.h:77
unsigned getPlatformFlags() const override
Returns platform-specific object flags, if any.
const Elf_Shdr * getSection(DataRefImpl Sec) const
virtual Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const =0
virtual uint32_t getSymbolFlags(DataRefImpl Symb) const =0
const Elf_Sym * getSymbol(DataRefImpl Sym) const
ELFRelocationRef(const RelocationRef &B)
static bool classof(const Binary *v)
Definition: ELFObjectFile.h:76
const ELFObjectFileBase * getObject() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const Elf_Rela * getRela(DataRefImpl Rela) const
virtual uint8_t getBytesInAddress() const =0
The number of bytes used to represent an address in this object file format.
virtual void moveRelocationNext(DataRefImpl &Rel) const =0
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
unsigned int getType() const
Definition: Binary.h:92
uint32_t getSymbolFlags(DataRefImpl Symb) const override
virtual uint64_t getSectionFlags(DataRefImpl Sec) const =0
iterator_range< elf_symbol_iterator > elf_symbol_iterator_range
Definition: ELFObjectFile.h:67
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
typename ELFT::Sym Elf_Sym
const Elf_Shdr * DotDynSymSec
Expected< int64_t > getAddend() const
static unsigned int getELFType(bool isLE, bool is64Bits)
Definition: Binary.h:68
section_iterator getRelocatedSection(DataRefImpl Sec) const override
const Elf_Rel * getRel(DataRefImpl Rel) const
virtual std::vector< SectionRef > dynamic_relocation_sections() const
Definition: ObjectFile.h:265
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
bool isSectionData(DataRefImpl Sec) const override
typename ELFT::Dyn Elf_Dyn
virtual basic_symbol_iterator symbol_end() const =0
static Expected< ELFObjectFile< ELFT > > create(MemoryBufferRef Object)
bool isExportedToOtherDSO(const Elf_Sym *ESym) const
uint8_t getSymbolELFType(DataRefImpl Symb) const override
uint64_t getSectionIndex(DataRefImpl Sec) const override
bool isELF() const
Definition: Binary.h:109
StringRef getFileFormatName() const override
const ELFSymbolRef & operator*() const
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:962
const ELFSectionRef & operator*() const
DataRefImpl toDRI(const Elf_Shdr *Sec) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const ELFSectionRef * operator->() const
ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
uint64_t getSectionAddress(DataRefImpl Sec) const override
std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const override
uint64_t getRelocationOffset(DataRefImpl Rel) const override
struct llvm::object::DataRefImpl::@259 d
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
typename ELFT::Rela Elf_Rela
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:889
virtual Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const =0
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
friend class RelocationRef
Definition: ObjectFile.h:246
const ELFFile< ELFT > * getELFFile() const
virtual section_iterator section_begin() const =0
const SymbolicFile * getObject() const
Definition: SymbolicFile.h:209
const SymbolRef & operator*() const
Definition: ObjectFile.h:181
virtual uint64_t getSectionAddress(DataRefImpl Sec) const =0
virtual Triple::ArchType getArch() const =0
uint64_t getSymbolValue(DataRefImpl Symb) const
Definition: ObjectFile.cpp:51
virtual unsigned getPlatformFlags() const =0
Returns platform-specific object flags, if any.
virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const =0
uint64_t getSectionFlags(DataRefImpl Sec) const override
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Triple::ArchType getArch() const override
content_iterator< BasicSymbolRef > basic_symbol_iterator
Definition: SymbolicFile.h:139
elf_symbol_iterator dynamic_symbol_end() const
A range adaptor for a pair of iterators.
MemoryBufferRef Data
Definition: Binary.h:37
Manages the enabling and disabling of subtarget specific features.
uint64_t getOffset() const
virtual bool isSectionText(DataRefImpl Sec) const =0
virtual uint64_t getSymbolSize(DataRefImpl Symb) const =0
SubtargetFeatures getMIPSFeatures() const
This is a value type class that represents a single symbol in the list of symbols in the object file...
Definition: ObjectFile.h:129
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
uint8_t getELFType() const
virtual void moveSectionNext(DataRefImpl &Sec) const =0
virtual section_iterator section_end() const =0
basic_symbol_iterator symbol_end() const override
virtual uint16_t getEType() const =0
bool isSectionCompressed(DataRefImpl Sec) const override
virtual bool isSectionData(DataRefImpl Sec) const =0
ELFSectionRef(const SectionRef &B)
Definition: ELFObjectFile.h:93
const ELFSymbolRef * operator->() const
uint64_t getSectionOffset(DataRefImpl Sec) const override
virtual section_iterator getRelocatedSection(DataRefImpl Sec) const
Definition: ObjectFile.cpp:80
virtual uint32_t getSectionType(DataRefImpl Sec) const =0
virtual void moveSymbolNext(DataRefImpl &Symb) const =0
virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const =0
virtual bool isRelocatableObject() const =0
True if this is a relocatable object (.o/.obj).
section_iterator section_end() const override
const SymbolRef * operator->() const
Definition: ObjectFile.h:176
virtual bool isSectionCompressed(DataRefImpl Sec) const =0
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const =0
uint64_t getSize() const
aarch64 promote const
virtual elf_symbol_iterator_range getDynamicSymbolIterators() const =0
virtual bool isSectionVirtual(DataRefImpl Sec) const =0
void Parse(ArrayRef< uint8_t > Section, bool isLittle)
virtual uint64_t getSectionSize(DataRefImpl Sec) const =0
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
virtual void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const =0
const ELFRelocationRef & operator*() const
content_iterator< RelocationRef > relocation_iterator
Definition: ObjectFile.h:77
SubtargetFeatures getARMFeatures() const
uint64_t getRelocationType(DataRefImpl Rel) const override
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Definition: ELFTypes.h:102
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
virtual uint8_t getSymbolELFType(DataRefImpl Symb) const =0
SubtargetFeatures getRISCVFeatures() const
const Elf_Ehdr * getHeader() const
Definition: ELF.h:92
virtual uint8_t getSymbolOther(DataRefImpl Symb) const =0
const ELFRelocationRef * operator->() const
elf_symbol_iterator(const basic_symbol_iterator &B)
virtual StringRef getFileFormatName() const =0
virtual uint64_t getRelocationType(DataRefImpl Rel) const =0
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
Definition: Error.cpp:84
typename ELFT::uint uintX_t
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:81
ELFSymbolRef(const SymbolRef &B)
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:967