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