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/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Triple.h"
22 #include "llvm/BinaryFormat/ELF.h"
24 #include "llvm/Object/Binary.h"
25 #include "llvm/Object/ELF.h"
26 #include "llvm/Object/ELFTypes.h"
27 #include "llvm/Object/Error.h"
28 #include "llvm/Object/ObjectFile.h"
32 #include "llvm/Support/Casting.h"
33 #include "llvm/Support/Endian.h"
34 #include "llvm/Support/Error.h"
37 #include <cassert>
38 #include <cstdint>
39 #include <system_error>
40 
41 namespace llvm {
42 namespace object {
43 
44 class elf_symbol_iterator;
45 
46 class ELFObjectFileBase : public ObjectFile {
47  friend class ELFRelocationRef;
48  friend class ELFSectionRef;
49  friend class ELFSymbolRef;
50 
51 protected:
53 
54  virtual uint16_t getEMachine() const = 0;
55  virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0;
56  virtual uint8_t getSymbolOther(DataRefImpl Symb) const = 0;
57  virtual uint8_t getSymbolELFType(DataRefImpl Symb) const = 0;
58 
59  virtual uint32_t getSectionType(DataRefImpl Sec) const = 0;
60  virtual uint64_t getSectionFlags(DataRefImpl Sec) const = 0;
61  virtual uint64_t getSectionOffset(DataRefImpl Sec) const = 0;
62 
63  virtual Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
64 
65 public:
67 
69 
70  /// Returns platform-specific object flags, if any.
71  virtual unsigned getPlatformFlags() const = 0;
72 
74 
75  static bool classof(const Binary *v) { return v->isELF(); }
76 
77  SubtargetFeatures getFeatures() const override;
78 
80 
82 
84 
85  void setARMSubArch(Triple &TheTriple) const override;
86 };
87 
88 class ELFSectionRef : public SectionRef {
89 public:
91  assert(isa<ELFObjectFileBase>(SectionRef::getObject()));
92  }
93 
94  const ELFObjectFileBase *getObject() const {
95  return cast<ELFObjectFileBase>(SectionRef::getObject());
96  }
97 
98  uint32_t getType() const {
99  return getObject()->getSectionType(getRawDataRefImpl());
100  }
101 
102  uint64_t getFlags() const {
103  return getObject()->getSectionFlags(getRawDataRefImpl());
104  }
105 
106  uint64_t getOffset() const {
107  return getObject()->getSectionOffset(getRawDataRefImpl());
108  }
109 };
110 
112 public:
114  assert(isa<ELFObjectFileBase>(B->getObject()));
115  }
116 
117  const ELFSectionRef *operator->() const {
118  return static_cast<const ELFSectionRef *>(section_iterator::operator->());
119  }
120 
121  const ELFSectionRef &operator*() const {
122  return static_cast<const ELFSectionRef &>(section_iterator::operator*());
123  }
124 };
125 
126 class ELFSymbolRef : public SymbolRef {
127 public:
129  assert(isa<ELFObjectFileBase>(SymbolRef::getObject()));
130  }
131 
132  const ELFObjectFileBase *getObject() const {
133  return cast<ELFObjectFileBase>(BasicSymbolRef::getObject());
134  }
135 
136  uint64_t getSize() const {
137  return getObject()->getSymbolSize(getRawDataRefImpl());
138  }
139 
140  uint8_t getOther() const {
141  return getObject()->getSymbolOther(getRawDataRefImpl());
142  }
143 
144  uint8_t getELFType() const {
145  return getObject()->getSymbolELFType(getRawDataRefImpl());
146  }
147 };
148 
150 public:
152  : symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
153  cast<ELFObjectFileBase>(B->getObject()))) {}
154 
155  const ELFSymbolRef *operator->() const {
156  return static_cast<const ELFSymbolRef *>(symbol_iterator::operator->());
157  }
158 
159  const ELFSymbolRef &operator*() const {
160  return static_cast<const ELFSymbolRef &>(symbol_iterator::operator*());
161  }
162 };
163 
165 public:
167  assert(isa<ELFObjectFileBase>(RelocationRef::getObject()));
168  }
169 
170  const ELFObjectFileBase *getObject() const {
171  return cast<ELFObjectFileBase>(RelocationRef::getObject());
172  }
173 
175  return getObject()->getRelocationAddend(getRawDataRefImpl());
176  }
177 };
178 
180 public:
183  B->getRawDataRefImpl(), cast<ELFObjectFileBase>(B->getObject()))) {}
184 
185  const ELFRelocationRef *operator->() const {
186  return static_cast<const ELFRelocationRef *>(
188  }
189 
190  const ELFRelocationRef &operator*() const {
191  return static_cast<const ELFRelocationRef &>(
193  }
194 };
195 
199 }
200 
201 template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
202  uint16_t getEMachine() const override;
203  uint64_t getSymbolSize(DataRefImpl Sym) const override;
204 
205 public:
207 
208  using uintX_t = typename ELFT::uint;
209 
210  using Elf_Sym = typename ELFT::Sym;
211  using Elf_Shdr = typename ELFT::Shdr;
212  using Elf_Ehdr = typename ELFT::Ehdr;
213  using Elf_Rel = typename ELFT::Rel;
214  using Elf_Rela = typename ELFT::Rela;
215  using Elf_Dyn = typename ELFT::Dyn;
216 
217 private:
218  ELFObjectFile(MemoryBufferRef Object, ELFFile<ELFT> EF,
219  const Elf_Shdr *DotDynSymSec, const Elf_Shdr *DotSymtabSec,
220  ArrayRef<Elf_Word> ShndxTable);
221 
222 protected:
223  ELFFile<ELFT> EF;
224 
225  const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
226  const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section.
227  ArrayRef<Elf_Word> ShndxTable;
228 
229  void moveSymbolNext(DataRefImpl &Symb) const override;
231  Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
232  uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
234  uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
235  uint32_t getSymbolFlags(DataRefImpl Symb) const override;
236  uint8_t getSymbolOther(DataRefImpl Symb) const override;
237  uint8_t getSymbolELFType(DataRefImpl Symb) const override;
240  const Elf_Shdr *SymTab) const;
242 
243  void moveSectionNext(DataRefImpl &Sec) const override;
244  std::error_code getSectionName(DataRefImpl Sec,
245  StringRef &Res) const override;
246  uint64_t getSectionAddress(DataRefImpl Sec) const override;
247  uint64_t getSectionIndex(DataRefImpl Sec) const override;
248  uint64_t getSectionSize(DataRefImpl Sec) const override;
249  std::error_code getSectionContents(DataRefImpl Sec,
250  StringRef &Res) const override;
251  uint64_t getSectionAlignment(DataRefImpl Sec) const override;
252  bool isSectionCompressed(DataRefImpl Sec) const override;
253  bool isSectionText(DataRefImpl Sec) const override;
254  bool isSectionData(DataRefImpl Sec) const override;
255  bool isSectionBSS(DataRefImpl Sec) const override;
256  bool isSectionVirtual(DataRefImpl Sec) const override;
258  relocation_iterator section_rel_end(DataRefImpl Sec) const override;
260 
261  void moveRelocationNext(DataRefImpl &Rel) const override;
262  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
263  symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
264  uint64_t getRelocationType(DataRefImpl Rel) const override;
266  SmallVectorImpl<char> &Result) const override;
267 
268  uint32_t getSectionType(DataRefImpl Sec) const override;
269  uint64_t getSectionFlags(DataRefImpl Sec) const override;
270  uint64_t getSectionOffset(DataRefImpl Sec) const override;
272 
273  /// \brief Get the relocation section that contains \a Rel.
274  const Elf_Shdr *getRelSection(DataRefImpl Rel) const {
275  auto RelSecOrErr = EF.getSection(Rel.d.a);
276  if (!RelSecOrErr)
277  report_fatal_error(errorToErrorCode(RelSecOrErr.takeError()).message());
278  return *RelSecOrErr;
279  }
280 
281  DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const {
282  DataRefImpl DRI;
283  if (!SymTable) {
284  DRI.d.a = 0;
285  DRI.d.b = 0;
286  return DRI;
287  }
288  assert(SymTable->sh_type == ELF::SHT_SYMTAB ||
289  SymTable->sh_type == ELF::SHT_DYNSYM);
290 
291  auto SectionsOrErr = EF.sections();
292  if (!SectionsOrErr) {
293  DRI.d.a = 0;
294  DRI.d.b = 0;
295  return DRI;
296  }
297  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
298  unsigned SymTableIndex =
299  (reinterpret_cast<uintptr_t>(SymTable) - SHT) / sizeof(Elf_Shdr);
300 
301  DRI.d.a = SymTableIndex;
302  DRI.d.b = SymbolNum;
303  return DRI;
304  }
305 
306  const Elf_Shdr *toELFShdrIter(DataRefImpl Sec) const {
307  return reinterpret_cast<const Elf_Shdr *>(Sec.p);
308  }
309 
310  DataRefImpl toDRI(const Elf_Shdr *Sec) const {
311  DataRefImpl DRI;
312  DRI.p = reinterpret_cast<uintptr_t>(Sec);
313  return DRI;
314  }
315 
316  DataRefImpl toDRI(const Elf_Dyn *Dyn) const {
317  DataRefImpl DRI;
318  DRI.p = reinterpret_cast<uintptr_t>(Dyn);
319  return DRI;
320  }
321 
322  bool isExportedToOtherDSO(const Elf_Sym *ESym) const {
323  unsigned char Binding = ESym->getBinding();
324  unsigned char Visibility = ESym->getVisibility();
325 
326  // A symbol is exported if its binding is either GLOBAL or WEAK, and its
327  // visibility is either DEFAULT or PROTECTED. All other symbols are not
328  // exported.
329  return ((Binding == ELF::STB_GLOBAL || Binding == ELF::STB_WEAK) &&
330  (Visibility == ELF::STV_DEFAULT ||
331  Visibility == ELF::STV_PROTECTED));
332  }
333 
334  // This flag is used for classof, to distinguish ELFObjectFile from
335  // its subclass. If more subclasses will be created, this flag will
336  // have to become an enum.
338 
339 public:
341  static Expected<ELFObjectFile<ELFT>> create(MemoryBufferRef Object);
342 
343  const Elf_Rel *getRel(DataRefImpl Rel) const;
344  const Elf_Rela *getRela(DataRefImpl Rela) const;
345 
346  const Elf_Sym *getSymbol(DataRefImpl Sym) const {
347  auto Ret = EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
348  if (!Ret)
349  report_fatal_error(errorToErrorCode(Ret.takeError()).message());
350  return *Ret;
351  }
352 
353  const Elf_Shdr *getSection(DataRefImpl Sec) const {
354  return reinterpret_cast<const Elf_Shdr *>(Sec.p);
355  }
356 
357  basic_symbol_iterator symbol_begin() const override;
358  basic_symbol_iterator symbol_end() const override;
359 
360  elf_symbol_iterator dynamic_symbol_begin() const;
361  elf_symbol_iterator dynamic_symbol_end() const;
362 
363  section_iterator section_begin() const override;
364  section_iterator section_end() const override;
365 
367 
368  uint8_t getBytesInAddress() const override;
369  StringRef getFileFormatName() const override;
370  Triple::ArchType getArch() const override;
371 
372  unsigned getPlatformFlags() const override { return EF.getHeader()->e_flags; }
373 
374  std::error_code getBuildAttributes(ARMAttributeParser &Attributes) const override {
375  auto SectionsOrErr = EF.sections();
376  if (!SectionsOrErr)
377  return errorToErrorCode(SectionsOrErr.takeError());
378 
379  for (const Elf_Shdr &Sec : *SectionsOrErr) {
380  if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES) {
381  auto ErrorOrContents = EF.getSectionContents(&Sec);
382  if (!ErrorOrContents)
383  return errorToErrorCode(ErrorOrContents.takeError());
384 
385  auto Contents = ErrorOrContents.get();
386  if (Contents[0] != ARMBuildAttrs::Format_Version || Contents.size() == 1)
387  return std::error_code();
388 
389  Attributes.Parse(Contents, ELFT::TargetEndianness == support::little);
390  break;
391  }
392  }
393  return std::error_code();
394  }
395 
396  const ELFFile<ELFT> *getELFFile() const { return &EF; }
397 
398  bool isDyldType() const { return isDyldELFObject; }
399  static bool classof(const Binary *v) {
400  return v->getType() == getELFType(ELFT::TargetEndianness == support::little,
401  ELFT::Is64Bits);
402  }
403 
405 
406  bool isRelocatableObject() const override;
407 };
408 
413 
414 template <class ELFT>
416  ++Sym.d.b;
417 }
418 
419 template <class ELFT>
421  const Elf_Sym *ESym = getSymbol(Sym);
422  auto SymTabOrErr = EF.getSection(Sym.d.a);
423  if (!SymTabOrErr)
424  return SymTabOrErr.takeError();
425  const Elf_Shdr *SymTableSec = *SymTabOrErr;
426  auto StrTabOrErr = EF.getSection(SymTableSec->sh_link);
427  if (!StrTabOrErr)
428  return StrTabOrErr.takeError();
429  const Elf_Shdr *StringTableSec = *StrTabOrErr;
430  auto SymStrTabOrErr = EF.getStringTable(StringTableSec);
431  if (!SymStrTabOrErr)
432  return SymStrTabOrErr.takeError();
433  return ESym->getName(*SymStrTabOrErr);
434 }
435 
436 template <class ELFT>
438  return getSection(Sec)->sh_flags;
439 }
440 
441 template <class ELFT>
443  return getSection(Sec)->sh_type;
444 }
445 
446 template <class ELFT>
448  return getSection(Sec)->sh_offset;
449 }
450 
451 template <class ELFT>
453  const Elf_Sym *ESym = getSymbol(Symb);
454  uint64_t Ret = ESym->st_value;
455  if (ESym->st_shndx == ELF::SHN_ABS)
456  return Ret;
457 
458  const Elf_Ehdr *Header = EF.getHeader();
459  // Clear the ARM/Thumb or microMIPS indicator flag.
460  if ((Header->e_machine == ELF::EM_ARM || Header->e_machine == ELF::EM_MIPS) &&
461  ESym->getType() == ELF::STT_FUNC)
462  Ret &= ~1;
463 
464  return Ret;
465 }
466 
467 template <class ELFT>
470  uint64_t Result = getSymbolValue(Symb);
471  const Elf_Sym *ESym = getSymbol(Symb);
472  switch (ESym->st_shndx) {
473  case ELF::SHN_COMMON:
474  case ELF::SHN_UNDEF:
475  case ELF::SHN_ABS:
476  return Result;
477  }
478 
479  const Elf_Ehdr *Header = EF.getHeader();
480  auto SymTabOrErr = EF.getSection(Symb.d.a);
481  if (!SymTabOrErr)
482  return SymTabOrErr.takeError();
483  const Elf_Shdr *SymTab = *SymTabOrErr;
484 
485  if (Header->e_type == ELF::ET_REL) {
486  auto SectionOrErr = EF.getSection(ESym, SymTab, ShndxTable);
487  if (!SectionOrErr)
488  return SectionOrErr.takeError();
489  const Elf_Shdr *Section = *SectionOrErr;
490  if (Section)
491  Result += Section->sh_addr;
492  }
493 
494  return Result;
495 }
496 
497 template <class ELFT>
499  const Elf_Sym *Sym = getSymbol(Symb);
500  if (Sym->st_shndx == ELF::SHN_COMMON)
501  return Sym->st_value;
502  return 0;
503 }
504 
505 template <class ELFT>
506 uint16_t ELFObjectFile<ELFT>::getEMachine() const {
507  return EF.getHeader()->e_machine;
508 }
509 
510 template <class ELFT>
512  return getSymbol(Sym)->st_size;
513 }
514 
515 template <class ELFT>
517  return getSymbol(Symb)->st_size;
518 }
519 
520 template <class ELFT>
522  return getSymbol(Symb)->st_other;
523 }
524 
525 template <class ELFT>
527  return getSymbol(Symb)->getType();
528 }
529 
530 template <class ELFT>
533  const Elf_Sym *ESym = getSymbol(Symb);
534 
535  switch (ESym->getType()) {
536  case ELF::STT_NOTYPE:
537  return SymbolRef::ST_Unknown;
538  case ELF::STT_SECTION:
539  return SymbolRef::ST_Debug;
540  case ELF::STT_FILE:
541  return SymbolRef::ST_File;
542  case ELF::STT_FUNC:
543  return SymbolRef::ST_Function;
544  case ELF::STT_OBJECT:
545  case ELF::STT_COMMON:
546  case ELF::STT_TLS:
547  return SymbolRef::ST_Data;
548  default:
549  return SymbolRef::ST_Other;
550  }
551 }
552 
553 template <class ELFT>
555  const Elf_Sym *ESym = getSymbol(Sym);
556 
557  uint32_t Result = SymbolRef::SF_None;
558 
559  if (ESym->getBinding() != ELF::STB_LOCAL)
560  Result |= SymbolRef::SF_Global;
561 
562  if (ESym->getBinding() == ELF::STB_WEAK)
563  Result |= SymbolRef::SF_Weak;
564 
565  if (ESym->st_shndx == ELF::SHN_ABS)
566  Result |= SymbolRef::SF_Absolute;
567 
568  if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION)
570 
571  auto DotSymtabSecSyms = EF.symbols(DotSymtabSec);
572  if (DotSymtabSecSyms && ESym == (*DotSymtabSecSyms).begin())
574  auto DotDynSymSecSyms = EF.symbols(DotDynSymSec);
575  if (DotDynSymSecSyms && ESym == (*DotDynSymSecSyms).begin())
577 
578  if (EF.getHeader()->e_machine == ELF::EM_ARM) {
579  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
580  StringRef Name = *NameOrErr;
581  if (Name.startswith("$d") || Name.startswith("$t") ||
582  Name.startswith("$a"))
584  } else {
585  // TODO: Actually report errors helpfully.
586  consumeError(NameOrErr.takeError());
587  }
588  if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
589  Result |= SymbolRef::SF_Thumb;
590  }
591 
592  if (ESym->st_shndx == ELF::SHN_UNDEF)
593  Result |= SymbolRef::SF_Undefined;
594 
595  if (ESym->getType() == ELF::STT_COMMON || ESym->st_shndx == ELF::SHN_COMMON)
596  Result |= SymbolRef::SF_Common;
597 
598  if (isExportedToOtherDSO(ESym))
599  Result |= SymbolRef::SF_Exported;
600 
601  if (ESym->getVisibility() == ELF::STV_HIDDEN)
602  Result |= SymbolRef::SF_Hidden;
603 
604  return Result;
605 }
606 
607 template <class ELFT>
610  const Elf_Shdr *SymTab) const {
611  auto ESecOrErr = EF.getSection(ESym, SymTab, ShndxTable);
612  if (!ESecOrErr)
613  return ESecOrErr.takeError();
614 
615  const Elf_Shdr *ESec = *ESecOrErr;
616  if (!ESec)
617  return section_end();
618 
619  DataRefImpl Sec;
620  Sec.p = reinterpret_cast<intptr_t>(ESec);
621  return section_iterator(SectionRef(Sec, this));
622 }
623 
624 template <class ELFT>
627  const Elf_Sym *Sym = getSymbol(Symb);
628  auto SymTabOrErr = EF.getSection(Symb.d.a);
629  if (!SymTabOrErr)
630  return SymTabOrErr.takeError();
631  const Elf_Shdr *SymTab = *SymTabOrErr;
632  return getSymbolSection(Sym, SymTab);
633 }
634 
635 template <class ELFT>
637  const Elf_Shdr *ESec = getSection(Sec);
638  Sec = toDRI(++ESec);
639 }
640 
641 template <class ELFT>
643  StringRef &Result) const {
644  auto Name = EF.getSectionName(&*getSection(Sec));
645  if (!Name)
646  return errorToErrorCode(Name.takeError());
647  Result = *Name;
648  return std::error_code();
649 }
650 
651 template <class ELFT>
653  return getSection(Sec)->sh_addr;
654 }
655 
656 template <class ELFT>
658  auto SectionsOrErr = EF.sections();
659  handleAllErrors(std::move(SectionsOrErr.takeError()),
660  [](const ErrorInfoBase &) {
661  llvm_unreachable("unable to get section index");
662  });
663  const Elf_Shdr *First = SectionsOrErr->begin();
664  return getSection(Sec) - First;
665 }
666 
667 template <class ELFT>
669  return getSection(Sec)->sh_size;
670 }
671 
672 template <class ELFT>
673 std::error_code
675  StringRef &Result) const {
676  const Elf_Shdr *EShdr = getSection(Sec);
677  if (std::error_code EC =
679  (uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))
680  return EC;
681  Result = StringRef((const char *)base() + EShdr->sh_offset, EShdr->sh_size);
682  return std::error_code();
683 }
684 
685 template <class ELFT>
687  return getSection(Sec)->sh_addralign;
688 }
689 
690 template <class ELFT>
692  return getSection(Sec)->sh_flags & ELF::SHF_COMPRESSED;
693 }
694 
695 template <class ELFT>
697  return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR;
698 }
699 
700 template <class ELFT>
702  const Elf_Shdr *EShdr = getSection(Sec);
703  return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
704  EShdr->sh_type == ELF::SHT_PROGBITS;
705 }
706 
707 template <class ELFT>
709  const Elf_Shdr *EShdr = getSection(Sec);
710  return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
711  EShdr->sh_type == ELF::SHT_NOBITS;
712 }
713 
714 template <class ELFT>
716  return getSection(Sec)->sh_type == ELF::SHT_NOBITS;
717 }
718 
719 template <class ELFT>
722  DataRefImpl RelData;
723  auto SectionsOrErr = EF.sections();
724  if (!SectionsOrErr)
726  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
727  RelData.d.a = (Sec.p - SHT) / EF.getHeader()->e_shentsize;
728  RelData.d.b = 0;
729  return relocation_iterator(RelocationRef(RelData, this));
730 }
731 
732 template <class ELFT>
735  const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p);
737  if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
738  return Begin;
739  DataRefImpl RelData = Begin->getRawDataRefImpl();
740  const Elf_Shdr *RelSec = getRelSection(RelData);
741 
742  // Error check sh_link here so that getRelocationSymbol can just use it.
743  auto SymSecOrErr = EF.getSection(RelSec->sh_link);
744  if (!SymSecOrErr)
745  report_fatal_error(errorToErrorCode(SymSecOrErr.takeError()).message());
746 
747  RelData.d.b += S->sh_size / S->sh_entsize;
748  return relocation_iterator(RelocationRef(RelData, this));
749 }
750 
751 template <class ELFT>
754  if (EF.getHeader()->e_type != ELF::ET_REL)
755  return section_end();
756 
757  const Elf_Shdr *EShdr = getSection(Sec);
758  uintX_t Type = EShdr->sh_type;
759  if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA)
760  return section_end();
761 
762  auto R = EF.getSection(EShdr->sh_info);
763  if (!R)
764  report_fatal_error(errorToErrorCode(R.takeError()).message());
765  return section_iterator(SectionRef(toDRI(*R), this));
766 }
767 
768 // Relocations
769 template <class ELFT>
771  ++Rel.d.b;
772 }
773 
774 template <class ELFT>
777  uint32_t symbolIdx;
778  const Elf_Shdr *sec = getRelSection(Rel);
779  if (sec->sh_type == ELF::SHT_REL)
780  symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL());
781  else
782  symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL());
783  if (!symbolIdx)
784  return symbol_end();
785 
786  // FIXME: error check symbolIdx
787  DataRefImpl SymbolData;
788  SymbolData.d.a = sec->sh_link;
789  SymbolData.d.b = symbolIdx;
790  return symbol_iterator(SymbolRef(SymbolData, this));
791 }
792 
793 template <class ELFT>
795  assert(EF.getHeader()->e_type == ELF::ET_REL &&
796  "Only relocatable object files have relocation offsets");
797  const Elf_Shdr *sec = getRelSection(Rel);
798  if (sec->sh_type == ELF::SHT_REL)
799  return getRel(Rel)->r_offset;
800 
801  return getRela(Rel)->r_offset;
802 }
803 
804 template <class ELFT>
806  const Elf_Shdr *sec = getRelSection(Rel);
807  if (sec->sh_type == ELF::SHT_REL)
808  return getRel(Rel)->getType(EF.isMips64EL());
809  else
810  return getRela(Rel)->getType(EF.isMips64EL());
811 }
812 
813 template <class ELFT>
815  return getELFRelocationTypeName(EF.getHeader()->e_machine, Type);
816 }
817 
818 template <class ELFT>
820  DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
821  uint32_t type = getRelocationType(Rel);
822  EF.getRelocationTypeName(type, Result);
823 }
824 
825 template <class ELFT>
828  if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
829  return createError("Section is not SHT_RELA");
830  return (int64_t)getRela(Rel)->r_addend;
831 }
832 
833 template <class ELFT>
834 const typename ELFObjectFile<ELFT>::Elf_Rel *
836  assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
837  auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
838  if (!Ret)
839  report_fatal_error(errorToErrorCode(Ret.takeError()).message());
840  return *Ret;
841 }
842 
843 template <class ELFT>
844 const typename ELFObjectFile<ELFT>::Elf_Rela *
846  assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
847  auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
848  if (!Ret)
849  report_fatal_error(errorToErrorCode(Ret.takeError()).message());
850  return *Ret;
851 }
852 
853 template <class ELFT>
856  auto EFOrErr = ELFFile<ELFT>::create(Object.getBuffer());
857  if (Error E = EFOrErr.takeError())
858  return std::move(E);
859  auto EF = std::move(*EFOrErr);
860 
861  auto SectionsOrErr = EF.sections();
862  if (!SectionsOrErr)
863  return SectionsOrErr.takeError();
864 
865  const Elf_Shdr *DotDynSymSec = nullptr;
866  const Elf_Shdr *DotSymtabSec = nullptr;
867  ArrayRef<Elf_Word> ShndxTable;
868  for (const Elf_Shdr &Sec : *SectionsOrErr) {
869  switch (Sec.sh_type) {
870  case ELF::SHT_DYNSYM: {
871  if (DotDynSymSec)
872  return createError("More than one dynamic symbol table!");
873  DotDynSymSec = &Sec;
874  break;
875  }
876  case ELF::SHT_SYMTAB: {
877  if (DotSymtabSec)
878  return createError("More than one static symbol table!");
879  DotSymtabSec = &Sec;
880  break;
881  }
882  case ELF::SHT_SYMTAB_SHNDX: {
883  auto TableOrErr = EF.getSHNDXTable(Sec);
884  if (!TableOrErr)
885  return TableOrErr.takeError();
886  ShndxTable = *TableOrErr;
887  break;
888  }
889  }
890  }
891  return ELFObjectFile<ELFT>(Object, EF, DotDynSymSec, DotSymtabSec,
892  ShndxTable);
893 }
894 
895 template <class ELFT>
897  const Elf_Shdr *DotDynSymSec,
898  const Elf_Shdr *DotSymtabSec,
899  ArrayRef<Elf_Word> ShndxTable)
901  getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits),
902  Object),
903  EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec),
904  ShndxTable(ShndxTable) {}
905 
906 template <class ELFT>
907 ELFObjectFile<ELFT>::ELFObjectFile(ELFObjectFile<ELFT> &&Other)
908  : ELFObjectFile(Other.Data, Other.EF, Other.DotDynSymSec,
909  Other.DotSymtabSec, Other.ShndxTable) {}
910 
911 template <class ELFT>
913  DataRefImpl Sym = toDRI(DotSymtabSec, 0);
914  return basic_symbol_iterator(SymbolRef(Sym, this));
915 }
916 
917 template <class ELFT>
919  const Elf_Shdr *SymTab = DotSymtabSec;
920  if (!SymTab)
921  return symbol_begin();
922  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
923  return basic_symbol_iterator(SymbolRef(Sym, this));
924 }
925 
926 template <class ELFT>
928  DataRefImpl Sym = toDRI(DotDynSymSec, 0);
929  return symbol_iterator(SymbolRef(Sym, this));
930 }
931 
932 template <class ELFT>
934  const Elf_Shdr *SymTab = DotDynSymSec;
935  if (!SymTab)
936  return dynamic_symbol_begin();
937  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
938  return basic_symbol_iterator(SymbolRef(Sym, this));
939 }
940 
941 template <class ELFT>
943  auto SectionsOrErr = EF.sections();
944  if (!SectionsOrErr)
945  return section_iterator(SectionRef());
946  return section_iterator(SectionRef(toDRI((*SectionsOrErr).begin()), this));
947 }
948 
949 template <class ELFT>
951  auto SectionsOrErr = EF.sections();
952  if (!SectionsOrErr)
953  return section_iterator(SectionRef());
954  return section_iterator(SectionRef(toDRI((*SectionsOrErr).end()), this));
955 }
956 
957 template <class ELFT>
959  return ELFT::Is64Bits ? 8 : 4;
960 }
961 
962 template <class ELFT>
964  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
965  switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
966  case ELF::ELFCLASS32:
967  switch (EF.getHeader()->e_machine) {
968  case ELF::EM_386:
969  return "ELF32-i386";
970  case ELF::EM_IAMCU:
971  return "ELF32-iamcu";
972  case ELF::EM_X86_64:
973  return "ELF32-x86-64";
974  case ELF::EM_ARM:
975  return (IsLittleEndian ? "ELF32-arm-little" : "ELF32-arm-big");
976  case ELF::EM_AVR:
977  return "ELF32-avr";
978  case ELF::EM_HEXAGON:
979  return "ELF32-hexagon";
980  case ELF::EM_LANAI:
981  return "ELF32-lanai";
982  case ELF::EM_MIPS:
983  return "ELF32-mips";
984  case ELF::EM_PPC:
985  return "ELF32-ppc";
986  case ELF::EM_RISCV:
987  return "ELF32-riscv";
988  case ELF::EM_SPARC:
989  case ELF::EM_SPARC32PLUS:
990  return "ELF32-sparc";
991  case ELF::EM_WEBASSEMBLY:
992  return "ELF32-wasm";
993  case ELF::EM_AMDGPU:
994  return "ELF32-amdgpu";
995  default:
996  return "ELF32-unknown";
997  }
998  case ELF::ELFCLASS64:
999  switch (EF.getHeader()->e_machine) {
1000  case ELF::EM_386:
1001  return "ELF64-i386";
1002  case ELF::EM_X86_64:
1003  return "ELF64-x86-64";
1004  case ELF::EM_AARCH64:
1005  return (IsLittleEndian ? "ELF64-aarch64-little" : "ELF64-aarch64-big");
1006  case ELF::EM_PPC64:
1007  return "ELF64-ppc64";
1008  case ELF::EM_RISCV:
1009  return "ELF64-riscv";
1010  case ELF::EM_S390:
1011  return "ELF64-s390";
1012  case ELF::EM_SPARCV9:
1013  return "ELF64-sparc";
1014  case ELF::EM_MIPS:
1015  return "ELF64-mips";
1016  case ELF::EM_WEBASSEMBLY:
1017  return "ELF64-wasm";
1018  case ELF::EM_AMDGPU:
1019  return "ELF64-amdgpu";
1020  case ELF::EM_BPF:
1021  return "ELF64-BPF";
1022  default:
1023  return "ELF64-unknown";
1024  }
1025  default:
1026  // FIXME: Proper error handling.
1027  report_fatal_error("Invalid ELFCLASS!");
1028  }
1029 }
1030 
1031 template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
1032  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1033  switch (EF.getHeader()->e_machine) {
1034  case ELF::EM_386:
1035  case ELF::EM_IAMCU:
1036  return Triple::x86;
1037  case ELF::EM_X86_64:
1038  return Triple::x86_64;
1039  case ELF::EM_AARCH64:
1040  return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be;
1041  case ELF::EM_ARM:
1042  return Triple::arm;
1043  case ELF::EM_AVR:
1044  return Triple::avr;
1045  case ELF::EM_HEXAGON:
1046  return Triple::hexagon;
1047  case ELF::EM_LANAI:
1048  return Triple::lanai;
1049  case ELF::EM_MIPS:
1050  switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
1051  case ELF::ELFCLASS32:
1052  return IsLittleEndian ? Triple::mipsel : Triple::mips;
1053  case ELF::ELFCLASS64:
1054  return IsLittleEndian ? Triple::mips64el : Triple::mips64;
1055  default:
1056  report_fatal_error("Invalid ELFCLASS!");
1057  }
1058  case ELF::EM_PPC:
1059  return Triple::ppc;
1060  case ELF::EM_PPC64:
1061  return IsLittleEndian ? Triple::ppc64le : Triple::ppc64;
1062  case ELF::EM_RISCV:
1063  switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
1064  case ELF::ELFCLASS32:
1065  return Triple::riscv32;
1066  case ELF::ELFCLASS64:
1067  return Triple::riscv64;
1068  default:
1069  report_fatal_error("Invalid ELFCLASS!");
1070  }
1071  case ELF::EM_S390:
1072  return Triple::systemz;
1073 
1074  case ELF::EM_SPARC:
1075  case ELF::EM_SPARC32PLUS:
1076  return IsLittleEndian ? Triple::sparcel : Triple::sparc;
1077  case ELF::EM_SPARCV9:
1078  return Triple::sparcv9;
1079  case ELF::EM_WEBASSEMBLY:
1080  switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) {
1081  case ELF::ELFCLASS32: return Triple::wasm32;
1082  case ELF::ELFCLASS64: return Triple::wasm64;
1083  default: return Triple::UnknownArch;
1084  }
1085 
1086  case ELF::EM_AMDGPU: {
1087  if (!IsLittleEndian)
1088  return Triple::UnknownArch;
1089 
1090  unsigned MACH = EF.getHeader()->e_flags & ELF::EF_AMDGPU_MACH;
1091  if (MACH >= ELF::EF_AMDGPU_MACH_R600_FIRST &&
1093  return Triple::r600;
1094  if (MACH >= ELF::EF_AMDGPU_MACH_AMDGCN_FIRST &&
1096  return Triple::amdgcn;
1097 
1098  return Triple::UnknownArch;
1099  }
1100 
1101  case ELF::EM_BPF:
1102  return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
1103 
1104  default:
1105  return Triple::UnknownArch;
1106  }
1107 }
1108 
1109 template <class ELFT>
1113 }
1114 
1115 template <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const {
1116  return EF.getHeader()->e_type == ELF::ET_REL;
1117 }
1118 
1119 } // end namespace object
1120 } // end namespace llvm
1121 
1122 #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:356
SubtargetFeatures getFeatures() const override
const Elf_Shdr * toELFShdrIter(DataRefImpl Sec) const
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
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:765
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:499
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:363
StringRef getBuffer() const
Definition: MemoryBuffer.h:223
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:94
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:766
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: ELF.h:187
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:366
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
uint32_t getType() const
Definition: ELFObjectFile.h:98
std::error_code getBuildAttributes(ARMAttributeParser &Attributes) const override
const ObjectFile * getObject() const
Definition: ObjectFile.h:461
virtual uint64_t getSectionOffset(DataRefImpl Sec) const =0
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
Definition: ELF.h:249
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:75
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:66
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
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 it requires that all errors 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
bool isSectionCompressed(DataRefImpl Sec) const override
virtual bool isSectionData(DataRefImpl Sec) const =0
ELFSectionRef(const SectionRef &B)
Definition: ELFObjectFile.h:90
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:94
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:89
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)