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