LLVM  13.0.0git
ELFObjectFile.h
Go to the documentation of this file.
1 //===- ELFObjectFile.h - ELF object file implementation ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the ELFObjectFile template class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_OBJECT_ELFOBJECTFILE_H
14 #define LLVM_OBJECT_ELFOBJECTFILE_H
15 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/STLExtras.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"
31 #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 constexpr int NumElfSymbolTypes = 16;
46 
48 
49 class ELFObjectFileBase : public ObjectFile {
50  friend class ELFRelocationRef;
51  friend class ELFSectionRef;
52  friend class ELFSymbolRef;
53 
54  SubtargetFeatures getMIPSFeatures() const;
55  SubtargetFeatures getARMFeatures() const;
56  SubtargetFeatures getRISCVFeatures() const;
57 
58  StringRef getAMDGPUCPUName() const;
59 
60 protected:
62 
63  virtual uint64_t getSymbolSize(DataRefImpl Symb) const = 0;
64  virtual uint8_t getSymbolBinding(DataRefImpl Symb) const = 0;
65  virtual uint8_t getSymbolOther(DataRefImpl Symb) const = 0;
66  virtual uint8_t getSymbolELFType(DataRefImpl Symb) const = 0;
67 
68  virtual uint32_t getSectionType(DataRefImpl Sec) const = 0;
69  virtual uint64_t getSectionFlags(DataRefImpl Sec) const = 0;
70  virtual uint64_t getSectionOffset(DataRefImpl Sec) const = 0;
71 
72  virtual Expected<int64_t> getRelocationAddend(DataRefImpl Rel) const = 0;
73  virtual Error getBuildAttributes(ELFAttributeParser &Attributes) const = 0;
74 
75 public:
77 
79 
80  /// Returns platform-specific object flags, if any.
81  virtual unsigned getPlatformFlags() const = 0;
82 
84 
85  static bool classof(const Binary *v) { return v->isELF(); }
86 
87  SubtargetFeatures getFeatures() const override;
88 
89  Optional<StringRef> tryGetCPUName() const override;
90 
91  void setARMSubArch(Triple &TheTriple) const override;
92 
93  virtual uint16_t getEType() const = 0;
94 
95  virtual uint16_t getEMachine() const = 0;
96 
97  std::vector<std::pair<Optional<DataRefImpl>, uint64_t>>
98  getPltAddresses() const;
99 };
100 
101 class ELFSectionRef : public SectionRef {
102 public:
104  assert(isa<ELFObjectFileBase>(SectionRef::getObject()));
105  }
106 
107  const ELFObjectFileBase *getObject() const {
108  return cast<ELFObjectFileBase>(SectionRef::getObject());
109  }
110 
111  uint32_t getType() const {
113  }
114 
115  uint64_t getFlags() const {
117  }
118 
119  uint64_t getOffset() const {
121  }
122 };
123 
125 public:
127  assert(isa<ELFObjectFileBase>(B->getObject()));
128  }
129 
130  const ELFSectionRef *operator->() const {
131  return static_cast<const ELFSectionRef *>(section_iterator::operator->());
132  }
133 
134  const ELFSectionRef &operator*() const {
135  return static_cast<const ELFSectionRef &>(section_iterator::operator*());
136  }
137 };
138 
139 class ELFSymbolRef : public SymbolRef {
140 public:
142  assert(isa<ELFObjectFileBase>(SymbolRef::getObject()));
143  }
144 
145  const ELFObjectFileBase *getObject() const {
146  return cast<ELFObjectFileBase>(BasicSymbolRef::getObject());
147  }
148 
149  uint64_t getSize() const {
151  }
152 
153  uint8_t getBinding() const {
155  }
156 
157  uint8_t getOther() const {
159  }
160 
161  uint8_t getELFType() const {
163  }
164 
166  uint8_t Type = getELFType();
167  for (auto &EE : ElfSymbolTypes) {
168  if (EE.Value == Type) {
169  return EE.AltName;
170  }
171  }
172  return "";
173  }
174 };
175 
177 public:
179  : symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
181 
182  const ELFSymbolRef *operator->() const {
183  return static_cast<const ELFSymbolRef *>(symbol_iterator::operator->());
184  }
185 
186  const ELFSymbolRef &operator*() const {
187  return static_cast<const ELFSymbolRef &>(symbol_iterator::operator*());
188  }
189 };
190 
192 public:
194  assert(isa<ELFObjectFileBase>(RelocationRef::getObject()));
195  }
196 
197  const ELFObjectFileBase *getObject() const {
198  return cast<ELFObjectFileBase>(RelocationRef::getObject());
199  }
200 
203  }
204 };
205 
207 public:
210  B->getRawDataRefImpl(), cast<ELFObjectFileBase>(B->getObject()))) {}
211 
212  const ELFRelocationRef *operator->() const {
213  return static_cast<const ELFRelocationRef *>(
215  }
216 
217  const ELFRelocationRef &operator*() const {
218  return static_cast<const ELFRelocationRef &>(
220  }
221 };
222 
226 }
227 
228 template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
229  uint16_t getEMachine() const override;
230  uint16_t getEType() const override;
231  uint64_t getSymbolSize(DataRefImpl Sym) const override;
232 
233 public:
235 
236  SectionRef toSectionRef(const Elf_Shdr *Sec) const {
237  return SectionRef(toDRI(Sec), this);
238  }
239 
240  ELFSymbolRef toSymbolRef(const Elf_Shdr *SymTable, unsigned SymbolNum) const {
241  return ELFSymbolRef({toDRI(SymTable, SymbolNum), this});
242  }
243 
244  bool IsContentValid() const { return ContentValid; }
245 
246 private:
248  const Elf_Shdr *DotDynSymSec, const Elf_Shdr *DotSymtabSec,
249  const Elf_Shdr *DotSymtabShndxSec);
250 
251  bool ContentValid = false;
252 
253 protected:
255 
256  const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
257  const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section.
258  const Elf_Shdr *DotSymtabShndxSec = nullptr; // SHT_SYMTAB_SHNDX section.
259 
260  Error initContent() override;
261 
262  void moveSymbolNext(DataRefImpl &Symb) const override;
263  Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
264  Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
265  uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
266  uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
267  uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
268  Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
269  uint8_t getSymbolBinding(DataRefImpl Symb) const override;
270  uint8_t getSymbolOther(DataRefImpl Symb) const override;
271  uint8_t getSymbolELFType(DataRefImpl Symb) const override;
273  Expected<section_iterator> getSymbolSection(const Elf_Sym *Symb,
274  const Elf_Shdr *SymTab) const;
276 
277  void moveSectionNext(DataRefImpl &Sec) const override;
278  Expected<StringRef> getSectionName(DataRefImpl Sec) const override;
279  uint64_t getSectionAddress(DataRefImpl Sec) const override;
280  uint64_t getSectionIndex(DataRefImpl Sec) const override;
281  uint64_t getSectionSize(DataRefImpl Sec) const override;
283  getSectionContents(DataRefImpl Sec) const override;
284  uint64_t getSectionAlignment(DataRefImpl Sec) const override;
285  bool isSectionCompressed(DataRefImpl Sec) const override;
286  bool isSectionText(DataRefImpl Sec) const override;
287  bool isSectionData(DataRefImpl Sec) const override;
288  bool isSectionBSS(DataRefImpl Sec) const override;
289  bool isSectionVirtual(DataRefImpl Sec) const override;
290  bool isBerkeleyText(DataRefImpl Sec) const override;
291  bool isBerkeleyData(DataRefImpl Sec) const override;
292  bool isDebugSection(StringRef SectionName) const override;
294  relocation_iterator section_rel_end(DataRefImpl Sec) const override;
295  std::vector<SectionRef> dynamic_relocation_sections() const override;
297  getRelocatedSection(DataRefImpl Sec) const override;
298 
299  void moveRelocationNext(DataRefImpl &Rel) const override;
300  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
301  symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
302  uint64_t getRelocationType(DataRefImpl Rel) const override;
304  SmallVectorImpl<char> &Result) const override;
305 
306  uint32_t getSectionType(DataRefImpl Sec) const override;
307  uint64_t getSectionFlags(DataRefImpl Sec) const override;
308  uint64_t getSectionOffset(DataRefImpl Sec) const override;
310 
311  DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const {
312  DataRefImpl DRI;
313  if (!SymTable) {
314  DRI.d.a = 0;
315  DRI.d.b = 0;
316  return DRI;
317  }
318  assert(SymTable->sh_type == ELF::SHT_SYMTAB ||
319  SymTable->sh_type == ELF::SHT_DYNSYM);
320 
321  auto SectionsOrErr = EF.sections();
322  if (!SectionsOrErr) {
323  DRI.d.a = 0;
324  DRI.d.b = 0;
325  return DRI;
326  }
327  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
328  unsigned SymTableIndex =
329  (reinterpret_cast<uintptr_t>(SymTable) - SHT) / sizeof(Elf_Shdr);
330 
331  DRI.d.a = SymTableIndex;
332  DRI.d.b = SymbolNum;
333  return DRI;
334  }
335 
336  const Elf_Shdr *toELFShdrIter(DataRefImpl Sec) const {
337  return reinterpret_cast<const Elf_Shdr *>(Sec.p);
338  }
339 
340  DataRefImpl toDRI(const Elf_Shdr *Sec) const {
341  DataRefImpl DRI;
342  DRI.p = reinterpret_cast<uintptr_t>(Sec);
343  return DRI;
344  }
345 
346  DataRefImpl toDRI(const Elf_Dyn *Dyn) const {
347  DataRefImpl DRI;
348  DRI.p = reinterpret_cast<uintptr_t>(Dyn);
349  return DRI;
350  }
351 
352  bool isExportedToOtherDSO(const Elf_Sym *ESym) const {
353  unsigned char Binding = ESym->getBinding();
354  unsigned char Visibility = ESym->getVisibility();
355 
356  // A symbol is exported if its binding is either GLOBAL or WEAK, and its
357  // visibility is either DEFAULT or PROTECTED. All other symbols are not
358  // exported.
359  return (
360  (Binding == ELF::STB_GLOBAL || Binding == ELF::STB_WEAK ||
361  Binding == ELF::STB_GNU_UNIQUE) &&
362  (Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_PROTECTED));
363  }
364 
365  Error getBuildAttributes(ELFAttributeParser &Attributes) const override {
366  auto SectionsOrErr = EF.sections();
367  if (!SectionsOrErr)
368  return SectionsOrErr.takeError();
369 
370  for (const Elf_Shdr &Sec : *SectionsOrErr) {
371  if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES ||
372  Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES) {
373  auto ErrorOrContents = EF.getSectionContents(Sec);
374  if (!ErrorOrContents)
375  return ErrorOrContents.takeError();
376 
377  auto Contents = ErrorOrContents.get();
378  if (Contents[0] != ELFAttrs::Format_Version || Contents.size() == 1)
379  return Error::success();
380 
381  if (Error E = Attributes.parse(Contents, ELFT::TargetEndianness))
382  return E;
383  break;
384  }
385  }
386  return Error::success();
387  }
388 
389  // This flag is used for classof, to distinguish ELFObjectFile from
390  // its subclass. If more subclasses will be created, this flag will
391  // have to become an enum.
393 
394 public:
397  bool InitContent = true);
398 
399  const Elf_Rel *getRel(DataRefImpl Rel) const;
400  const Elf_Rela *getRela(DataRefImpl Rela) const;
401 
403  return EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
404  }
405 
406  /// Get the relocation section that contains \a Rel.
407  const Elf_Shdr *getRelSection(DataRefImpl Rel) const {
408  auto RelSecOrErr = EF.getSection(Rel.d.a);
409  if (!RelSecOrErr)
410  report_fatal_error(errorToErrorCode(RelSecOrErr.takeError()).message());
411  return *RelSecOrErr;
412  }
413 
414  const Elf_Shdr *getSection(DataRefImpl Sec) const {
415  return reinterpret_cast<const Elf_Shdr *>(Sec.p);
416  }
417 
418  basic_symbol_iterator symbol_begin() const override;
419  basic_symbol_iterator symbol_end() const override;
420 
423 
424  section_iterator section_begin() const override;
425  section_iterator section_end() const override;
426 
428 
429  uint8_t getBytesInAddress() const override;
430  StringRef getFileFormatName() const override;
431  Triple::ArchType getArch() const override;
432  Expected<uint64_t> getStartAddress() const override;
433 
434  unsigned getPlatformFlags() const override { return EF.getHeader().e_flags; }
435 
436  const ELFFile<ELFT> &getELFFile() const { return EF; }
437 
438  bool isDyldType() const { return isDyldELFObject; }
439  static bool classof(const Binary *v) {
440  return v->getType() == getELFType(ELFT::TargetEndianness == support::little,
441  ELFT::Is64Bits);
442  }
443 
445 
446  bool isRelocatableObject() const override;
447 };
448 
453 
454 template <class ELFT>
456  ++Sym.d.b;
457 }
458 
459 template <class ELFT> Error ELFObjectFile<ELFT>::initContent() {
460  auto SectionsOrErr = EF.sections();
461  if (!SectionsOrErr)
462  return SectionsOrErr.takeError();
463 
464  for (const Elf_Shdr &Sec : *SectionsOrErr) {
465  switch (Sec.sh_type) {
466  case ELF::SHT_DYNSYM: {
467  if (!DotDynSymSec)
468  DotDynSymSec = &Sec;
469  break;
470  }
471  case ELF::SHT_SYMTAB: {
472  if (!DotSymtabSec)
473  DotSymtabSec = &Sec;
474  break;
475  }
476  case ELF::SHT_SYMTAB_SHNDX: {
477  if (!DotSymtabShndxSec)
478  DotSymtabShndxSec = &Sec;
479  break;
480  }
481  }
482  }
483 
484  ContentValid = true;
485  return Error::success();
486 }
487 
488 template <class ELFT>
490  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
491  if (!SymOrErr)
492  return SymOrErr.takeError();
493  auto SymTabOrErr = EF.getSection(Sym.d.a);
494  if (!SymTabOrErr)
495  return SymTabOrErr.takeError();
496  const Elf_Shdr *SymTableSec = *SymTabOrErr;
497  auto StrTabOrErr = EF.getSection(SymTableSec->sh_link);
498  if (!StrTabOrErr)
499  return StrTabOrErr.takeError();
500  const Elf_Shdr *StringTableSec = *StrTabOrErr;
501  auto SymStrTabOrErr = EF.getStringTable(*StringTableSec);
502  if (!SymStrTabOrErr)
503  return SymStrTabOrErr.takeError();
504  Expected<StringRef> Name = (*SymOrErr)->getName(*SymStrTabOrErr);
505  if (Name && !Name->empty())
506  return Name;
507 
508  // If the symbol name is empty use the section name.
509  if ((*SymOrErr)->getType() == ELF::STT_SECTION) {
510  if (Expected<section_iterator> SecOrErr = getSymbolSection(Sym)) {
511  consumeError(Name.takeError());
512  return (*SecOrErr)->getName();
513  }
514  }
515  return Name;
516 }
517 
518 template <class ELFT>
520  return getSection(Sec)->sh_flags;
521 }
522 
523 template <class ELFT>
525  return getSection(Sec)->sh_type;
526 }
527 
528 template <class ELFT>
530  return getSection(Sec)->sh_offset;
531 }
532 
533 template <class ELFT>
535  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
536  if (!SymOrErr)
537  report_fatal_error(SymOrErr.takeError());
538 
539  uint64_t Ret = (*SymOrErr)->st_value;
540  if ((*SymOrErr)->st_shndx == ELF::SHN_ABS)
541  return Ret;
542 
543  const Elf_Ehdr &Header = EF.getHeader();
544  // Clear the ARM/Thumb or microMIPS indicator flag.
545  if ((Header.e_machine == ELF::EM_ARM || Header.e_machine == ELF::EM_MIPS) &&
546  (*SymOrErr)->getType() == ELF::STT_FUNC)
547  Ret &= ~1;
548 
549  return Ret;
550 }
551 
552 template <class ELFT>
555  Expected<uint64_t> SymbolValueOrErr = getSymbolValue(Symb);
556  if (!SymbolValueOrErr)
557  // TODO: Test this error.
558  return SymbolValueOrErr.takeError();
559 
560  uint64_t Result = *SymbolValueOrErr;
561  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
562  if (!SymOrErr)
563  return SymOrErr.takeError();
564 
565  switch ((*SymOrErr)->st_shndx) {
566  case ELF::SHN_COMMON:
567  case ELF::SHN_UNDEF:
568  case ELF::SHN_ABS:
569  return Result;
570  }
571 
572  auto SymTabOrErr = EF.getSection(Symb.d.a);
573  if (!SymTabOrErr)
574  return SymTabOrErr.takeError();
575 
576  if (EF.getHeader().e_type == ELF::ET_REL) {
577  ArrayRef<Elf_Word> ShndxTable;
578  if (DotSymtabShndxSec) {
579  // TODO: Test this error.
580  if (Expected<ArrayRef<Elf_Word>> ShndxTableOrErr =
581  EF.getSHNDXTable(*DotSymtabShndxSec))
582  ShndxTable = *ShndxTableOrErr;
583  else
584  return ShndxTableOrErr.takeError();
585  }
586 
587  Expected<const Elf_Shdr *> SectionOrErr =
588  EF.getSection(**SymOrErr, *SymTabOrErr, ShndxTable);
589  if (!SectionOrErr)
590  return SectionOrErr.takeError();
591  const Elf_Shdr *Section = *SectionOrErr;
592  if (Section)
593  Result += Section->sh_addr;
594  }
595 
596  return Result;
597 }
598 
599 template <class ELFT>
601  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
602  if (!SymOrErr)
603  report_fatal_error(SymOrErr.takeError());
604  if ((*SymOrErr)->st_shndx == ELF::SHN_COMMON)
605  return (*SymOrErr)->st_value;
606  return 0;
607 }
608 
609 template <class ELFT>
611  return EF.getHeader().e_machine;
612 }
613 
614 template <class ELFT> uint16_t ELFObjectFile<ELFT>::getEType() const {
615  return EF.getHeader().e_type;
616 }
617 
618 template <class ELFT>
619 uint64_t ELFObjectFile<ELFT>::getSymbolSize(DataRefImpl Sym) const {
620  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
621  if (!SymOrErr)
622  report_fatal_error(SymOrErr.takeError());
623  return (*SymOrErr)->st_size;
624 }
625 
626 template <class ELFT>
628  return getSymbolSize(Symb);
629 }
630 
631 template <class ELFT>
633  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
634  if (!SymOrErr)
635  report_fatal_error(SymOrErr.takeError());
636  return (*SymOrErr)->getBinding();
637 }
638 
639 template <class ELFT>
641  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
642  if (!SymOrErr)
643  report_fatal_error(SymOrErr.takeError());
644  return (*SymOrErr)->st_other;
645 }
646 
647 template <class ELFT>
649  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
650  if (!SymOrErr)
651  report_fatal_error(SymOrErr.takeError());
652  return (*SymOrErr)->getType();
653 }
654 
655 template <class ELFT>
658  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
659  if (!SymOrErr)
660  return SymOrErr.takeError();
661 
662  switch ((*SymOrErr)->getType()) {
663  case ELF::STT_NOTYPE:
664  return SymbolRef::ST_Unknown;
665  case ELF::STT_SECTION:
666  return SymbolRef::ST_Debug;
667  case ELF::STT_FILE:
668  return SymbolRef::ST_File;
669  case ELF::STT_FUNC:
670  return SymbolRef::ST_Function;
671  case ELF::STT_OBJECT:
672  case ELF::STT_COMMON:
673  return SymbolRef::ST_Data;
674  case ELF::STT_TLS:
675  default:
676  return SymbolRef::ST_Other;
677  }
678 }
679 
680 template <class ELFT>
682  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
683  if (!SymOrErr)
684  return SymOrErr.takeError();
685 
686  const Elf_Sym *ESym = *SymOrErr;
687  uint32_t Result = SymbolRef::SF_None;
688 
689  if (ESym->getBinding() != ELF::STB_LOCAL)
690  Result |= SymbolRef::SF_Global;
691 
692  if (ESym->getBinding() == ELF::STB_WEAK)
693  Result |= SymbolRef::SF_Weak;
694 
695  if (ESym->st_shndx == ELF::SHN_ABS)
696  Result |= SymbolRef::SF_Absolute;
697 
698  if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION)
700 
701  if (Expected<typename ELFT::SymRange> SymbolsOrErr =
702  EF.symbols(DotSymtabSec)) {
703  // Set the SF_FormatSpecific flag for the 0-index null symbol.
704  if (ESym == SymbolsOrErr->begin())
706  } else
707  // TODO: Test this error.
708  return SymbolsOrErr.takeError();
709 
710  if (Expected<typename ELFT::SymRange> SymbolsOrErr =
711  EF.symbols(DotDynSymSec)) {
712  // Set the SF_FormatSpecific flag for the 0-index null symbol.
713  if (ESym == SymbolsOrErr->begin())
715  } else
716  // TODO: Test this error.
717  return SymbolsOrErr.takeError();
718 
719  if (EF.getHeader().e_machine == ELF::EM_ARM) {
720  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
721  StringRef Name = *NameOrErr;
722  if (Name.startswith("$d") || Name.startswith("$t") ||
723  Name.startswith("$a"))
725  } else {
726  // TODO: Actually report errors helpfully.
727  consumeError(NameOrErr.takeError());
728  }
729  if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
730  Result |= SymbolRef::SF_Thumb;
731  }
732 
733  if (ESym->st_shndx == ELF::SHN_UNDEF)
734  Result |= SymbolRef::SF_Undefined;
735 
736  if (ESym->getType() == ELF::STT_COMMON || ESym->st_shndx == ELF::SHN_COMMON)
737  Result |= SymbolRef::SF_Common;
738 
739  if (isExportedToOtherDSO(ESym))
740  Result |= SymbolRef::SF_Exported;
741 
742  if (ESym->getVisibility() == ELF::STV_HIDDEN)
743  Result |= SymbolRef::SF_Hidden;
744 
745  return Result;
746 }
747 
748 template <class ELFT>
751  const Elf_Shdr *SymTab) const {
752  ArrayRef<Elf_Word> ShndxTable;
753  if (DotSymtabShndxSec) {
754  // TODO: Test this error.
755  Expected<ArrayRef<Elf_Word>> ShndxTableOrErr =
756  EF.getSHNDXTable(*DotSymtabShndxSec);
757  if (!ShndxTableOrErr)
758  return ShndxTableOrErr.takeError();
759  ShndxTable = *ShndxTableOrErr;
760  }
761 
762  auto ESecOrErr = EF.getSection(*ESym, SymTab, ShndxTable);
763  if (!ESecOrErr)
764  return ESecOrErr.takeError();
765 
766  const Elf_Shdr *ESec = *ESecOrErr;
767  if (!ESec)
768  return section_end();
769 
770  DataRefImpl Sec;
771  Sec.p = reinterpret_cast<intptr_t>(ESec);
772  return section_iterator(SectionRef(Sec, this));
773 }
774 
775 template <class ELFT>
778  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
779  if (!SymOrErr)
780  return SymOrErr.takeError();
781 
782  auto SymTabOrErr = EF.getSection(Symb.d.a);
783  if (!SymTabOrErr)
784  return SymTabOrErr.takeError();
785  return getSymbolSection(*SymOrErr, *SymTabOrErr);
786 }
787 
788 template <class ELFT>
790  const Elf_Shdr *ESec = getSection(Sec);
791  Sec = toDRI(++ESec);
792 }
793 
794 template <class ELFT>
796  return EF.getSectionName(*getSection(Sec));
797 }
798 
799 template <class ELFT>
801  return getSection(Sec)->sh_addr;
802 }
803 
804 template <class ELFT>
806  auto SectionsOrErr = EF.sections();
807  handleAllErrors(std::move(SectionsOrErr.takeError()),
808  [](const ErrorInfoBase &) {
809  llvm_unreachable("unable to get section index");
810  });
811  const Elf_Shdr *First = SectionsOrErr->begin();
812  return getSection(Sec) - First;
813 }
814 
815 template <class ELFT>
817  return getSection(Sec)->sh_size;
818 }
819 
820 template <class ELFT>
823  const Elf_Shdr *EShdr = getSection(Sec);
824  if (EShdr->sh_type == ELF::SHT_NOBITS)
825  return makeArrayRef((const uint8_t *)base(), 0);
826  if (Error E =
827  checkOffset(getMemoryBufferRef(),
828  (uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))
829  return std::move(E);
830  return makeArrayRef((const uint8_t *)base() + EShdr->sh_offset,
831  EShdr->sh_size);
832 }
833 
834 template <class ELFT>
836  return getSection(Sec)->sh_addralign;
837 }
838 
839 template <class ELFT>
841  return getSection(Sec)->sh_flags & ELF::SHF_COMPRESSED;
842 }
843 
844 template <class ELFT>
846  return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR;
847 }
848 
849 template <class ELFT>
851  const Elf_Shdr *EShdr = getSection(Sec);
852  return EShdr->sh_type == ELF::SHT_PROGBITS &&
853  EShdr->sh_flags & ELF::SHF_ALLOC &&
854  !(EShdr->sh_flags & ELF::SHF_EXECINSTR);
855 }
856 
857 template <class ELFT>
859  const Elf_Shdr *EShdr = getSection(Sec);
860  return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
861  EShdr->sh_type == ELF::SHT_NOBITS;
862 }
863 
864 template <class ELFT>
865 std::vector<SectionRef>
867  std::vector<SectionRef> Res;
868  std::vector<uintptr_t> Offsets;
869 
870  auto SectionsOrErr = EF.sections();
871  if (!SectionsOrErr)
872  return Res;
873 
874  for (const Elf_Shdr &Sec : *SectionsOrErr) {
875  if (Sec.sh_type != ELF::SHT_DYNAMIC)
876  continue;
877  Elf_Dyn *Dynamic =
878  reinterpret_cast<Elf_Dyn *>((uintptr_t)base() + Sec.sh_offset);
879  for (; Dynamic->d_tag != ELF::DT_NULL; Dynamic++) {
880  if (Dynamic->d_tag == ELF::DT_REL || Dynamic->d_tag == ELF::DT_RELA ||
881  Dynamic->d_tag == ELF::DT_JMPREL) {
882  Offsets.push_back(Dynamic->d_un.d_val);
883  }
884  }
885  }
886  for (const Elf_Shdr &Sec : *SectionsOrErr) {
887  if (is_contained(Offsets, Sec.sh_addr))
888  Res.emplace_back(toDRI(&Sec), this);
889  }
890  return Res;
891 }
892 
893 template <class ELFT>
895  return getSection(Sec)->sh_type == ELF::SHT_NOBITS;
896 }
897 
898 template <class ELFT>
900  return getSection(Sec)->sh_flags & ELF::SHF_ALLOC &&
901  (getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR ||
902  !(getSection(Sec)->sh_flags & ELF::SHF_WRITE));
903 }
904 
905 template <class ELFT>
907  const Elf_Shdr *EShdr = getSection(Sec);
908  return !isBerkeleyText(Sec) && EShdr->sh_type != ELF::SHT_NOBITS &&
909  EShdr->sh_flags & ELF::SHF_ALLOC;
910 }
911 
912 template <class ELFT>
914  return SectionName.startswith(".debug") ||
915  SectionName.startswith(".zdebug") || SectionName == ".gdb_index";
916 }
917 
918 template <class ELFT>
921  DataRefImpl RelData;
922  auto SectionsOrErr = EF.sections();
923  if (!SectionsOrErr)
925  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
926  RelData.d.a = (Sec.p - SHT) / EF.getHeader().e_shentsize;
927  RelData.d.b = 0;
928  return relocation_iterator(RelocationRef(RelData, this));
929 }
930 
931 template <class ELFT>
934  const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p);
935  relocation_iterator Begin = section_rel_begin(Sec);
936  if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
937  return Begin;
938  DataRefImpl RelData = Begin->getRawDataRefImpl();
939  const Elf_Shdr *RelSec = getRelSection(RelData);
940 
941  // Error check sh_link here so that getRelocationSymbol can just use it.
942  auto SymSecOrErr = EF.getSection(RelSec->sh_link);
943  if (!SymSecOrErr)
944  report_fatal_error(errorToErrorCode(SymSecOrErr.takeError()).message());
945 
946  RelData.d.b += S->sh_size / S->sh_entsize;
947  return relocation_iterator(RelocationRef(RelData, this));
948 }
949 
950 template <class ELFT>
953  if (EF.getHeader().e_type != ELF::ET_REL)
954  return section_end();
955 
956  const Elf_Shdr *EShdr = getSection(Sec);
957  uintX_t Type = EShdr->sh_type;
958  if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA)
959  return section_end();
960 
961  Expected<const Elf_Shdr *> SecOrErr = EF.getSection(EShdr->sh_info);
962  if (!SecOrErr)
963  return SecOrErr.takeError();
964  return section_iterator(SectionRef(toDRI(*SecOrErr), this));
965 }
966 
967 // Relocations
968 template <class ELFT>
970  ++Rel.d.b;
971 }
972 
973 template <class ELFT>
976  uint32_t symbolIdx;
977  const Elf_Shdr *sec = getRelSection(Rel);
978  if (sec->sh_type == ELF::SHT_REL)
979  symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL());
980  else
981  symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL());
982  if (!symbolIdx)
983  return symbol_end();
984 
985  // FIXME: error check symbolIdx
986  DataRefImpl SymbolData;
987  SymbolData.d.a = sec->sh_link;
988  SymbolData.d.b = symbolIdx;
989  return symbol_iterator(SymbolRef(SymbolData, this));
990 }
991 
992 template <class ELFT>
994  const Elf_Shdr *sec = getRelSection(Rel);
995  if (sec->sh_type == ELF::SHT_REL)
996  return getRel(Rel)->r_offset;
997 
998  return getRela(Rel)->r_offset;
999 }
1000 
1001 template <class ELFT>
1003  const Elf_Shdr *sec = getRelSection(Rel);
1004  if (sec->sh_type == ELF::SHT_REL)
1005  return getRel(Rel)->getType(EF.isMips64EL());
1006  else
1007  return getRela(Rel)->getType(EF.isMips64EL());
1008 }
1009 
1010 template <class ELFT>
1012  return getELFRelocationTypeName(EF.getHeader().e_machine, Type);
1013 }
1014 
1015 template <class ELFT>
1017  DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
1018  uint32_t type = getRelocationType(Rel);
1019  EF.getRelocationTypeName(type, Result);
1020 }
1021 
1022 template <class ELFT>
1025  if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
1026  return createError("Section is not SHT_RELA");
1027  return (int64_t)getRela(Rel)->r_addend;
1028 }
1029 
1030 template <class ELFT>
1031 const typename ELFObjectFile<ELFT>::Elf_Rel *
1033  assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
1034  auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
1035  if (!Ret)
1036  report_fatal_error(errorToErrorCode(Ret.takeError()).message());
1037  return *Ret;
1038 }
1039 
1040 template <class ELFT>
1041 const typename ELFObjectFile<ELFT>::Elf_Rela *
1043  assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
1044  auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
1045  if (!Ret)
1046  report_fatal_error(errorToErrorCode(Ret.takeError()).message());
1047  return *Ret;
1048 }
1049 
1050 template <class ELFT>
1053  auto EFOrErr = ELFFile<ELFT>::create(Object.getBuffer());
1054  if (Error E = EFOrErr.takeError())
1055  return std::move(E);
1056 
1057  ELFObjectFile<ELFT> Obj = {Object, std::move(*EFOrErr), nullptr, nullptr,
1058  nullptr};
1059  if (InitContent)
1060  if (Error E = Obj.initContent())
1061  return std::move(E);
1062  return std::move(Obj);
1063 }
1064 
1065 template <class ELFT>
1067  const Elf_Shdr *DotDynSymSec,
1068  const Elf_Shdr *DotSymtabSec,
1069  const Elf_Shdr *DotSymtabShndx)
1071  getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits),
1072  Object),
1073  EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec),
1074  DotSymtabShndxSec(DotSymtabShndx) {}
1075 
1076 template <class ELFT>
1078  : ELFObjectFile(Other.Data, Other.EF, Other.DotDynSymSec,
1079  Other.DotSymtabSec, Other.DotSymtabShndxSec) {}
1080 
1081 template <class ELFT>
1083  DataRefImpl Sym =
1084  toDRI(DotSymtabSec,
1085  DotSymtabSec && DotSymtabSec->sh_size >= sizeof(Elf_Sym) ? 1 : 0);
1086  return basic_symbol_iterator(SymbolRef(Sym, this));
1087 }
1088 
1089 template <class ELFT>
1091  const Elf_Shdr *SymTab = DotSymtabSec;
1092  if (!SymTab)
1093  return symbol_begin();
1094  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
1095  return basic_symbol_iterator(SymbolRef(Sym, this));
1096 }
1097 
1098 template <class ELFT>
1100  if (!DotDynSymSec || DotDynSymSec->sh_size < sizeof(Elf_Sym))
1101  // Ignore errors here where the dynsym is empty or sh_size less than the
1102  // size of one symbol. These should be handled elsewhere.
1103  return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 0), this));
1104  // Skip 0-index NULL symbol.
1105  return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 1), this));
1106 }
1107 
1108 template <class ELFT>
1110  const Elf_Shdr *SymTab = DotDynSymSec;
1111  if (!SymTab)
1112  return dynamic_symbol_begin();
1113  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
1114  return basic_symbol_iterator(SymbolRef(Sym, this));
1115 }
1116 
1117 template <class ELFT>
1119  auto SectionsOrErr = EF.sections();
1120  if (!SectionsOrErr)
1121  return section_iterator(SectionRef());
1122  return section_iterator(SectionRef(toDRI((*SectionsOrErr).begin()), this));
1123 }
1124 
1125 template <class ELFT>
1127  auto SectionsOrErr = EF.sections();
1128  if (!SectionsOrErr)
1129  return section_iterator(SectionRef());
1130  return section_iterator(SectionRef(toDRI((*SectionsOrErr).end()), this));
1131 }
1132 
1133 template <class ELFT>
1135  return ELFT::Is64Bits ? 8 : 4;
1136 }
1137 
1138 template <class ELFT>
1140  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1141  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1142  case ELF::ELFCLASS32:
1143  switch (EF.getHeader().e_machine) {
1144  case ELF::EM_386:
1145  return "elf32-i386";
1146  case ELF::EM_IAMCU:
1147  return "elf32-iamcu";
1148  case ELF::EM_X86_64:
1149  return "elf32-x86-64";
1150  case ELF::EM_ARM:
1151  return (IsLittleEndian ? "elf32-littlearm" : "elf32-bigarm");
1152  case ELF::EM_AVR:
1153  return "elf32-avr";
1154  case ELF::EM_HEXAGON:
1155  return "elf32-hexagon";
1156  case ELF::EM_LANAI:
1157  return "elf32-lanai";
1158  case ELF::EM_MIPS:
1159  return "elf32-mips";
1160  case ELF::EM_MSP430:
1161  return "elf32-msp430";
1162  case ELF::EM_PPC:
1163  return (IsLittleEndian ? "elf32-powerpcle" : "elf32-powerpc");
1164  case ELF::EM_RISCV:
1165  return "elf32-littleriscv";
1166  case ELF::EM_CSKY:
1167  return "elf32-csky";
1168  case ELF::EM_SPARC:
1169  case ELF::EM_SPARC32PLUS:
1170  return "elf32-sparc";
1171  case ELF::EM_AMDGPU:
1172  return "elf32-amdgpu";
1173  default:
1174  return "elf32-unknown";
1175  }
1176  case ELF::ELFCLASS64:
1177  switch (EF.getHeader().e_machine) {
1178  case ELF::EM_386:
1179  return "elf64-i386";
1180  case ELF::EM_X86_64:
1181  return "elf64-x86-64";
1182  case ELF::EM_AARCH64:
1183  return (IsLittleEndian ? "elf64-littleaarch64" : "elf64-bigaarch64");
1184  case ELF::EM_PPC64:
1185  return (IsLittleEndian ? "elf64-powerpcle" : "elf64-powerpc");
1186  case ELF::EM_RISCV:
1187  return "elf64-littleriscv";
1188  case ELF::EM_S390:
1189  return "elf64-s390";
1190  case ELF::EM_SPARCV9:
1191  return "elf64-sparc";
1192  case ELF::EM_MIPS:
1193  return "elf64-mips";
1194  case ELF::EM_AMDGPU:
1195  return "elf64-amdgpu";
1196  case ELF::EM_BPF:
1197  return "elf64-bpf";
1198  case ELF::EM_VE:
1199  return "elf64-ve";
1200  default:
1201  return "elf64-unknown";
1202  }
1203  default:
1204  // FIXME: Proper error handling.
1205  report_fatal_error("Invalid ELFCLASS!");
1206  }
1207 }
1208 
1209 template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
1210  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1211  switch (EF.getHeader().e_machine) {
1212  case ELF::EM_386:
1213  case ELF::EM_IAMCU:
1214  return Triple::x86;
1215  case ELF::EM_X86_64:
1216  return Triple::x86_64;
1217  case ELF::EM_AARCH64:
1218  return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be;
1219  case ELF::EM_ARM:
1220  return Triple::arm;
1221  case ELF::EM_AVR:
1222  return Triple::avr;
1223  case ELF::EM_HEXAGON:
1224  return Triple::hexagon;
1225  case ELF::EM_LANAI:
1226  return Triple::lanai;
1227  case ELF::EM_MIPS:
1228  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1229  case ELF::ELFCLASS32:
1230  return IsLittleEndian ? Triple::mipsel : Triple::mips;
1231  case ELF::ELFCLASS64:
1232  return IsLittleEndian ? Triple::mips64el : Triple::mips64;
1233  default:
1234  report_fatal_error("Invalid ELFCLASS!");
1235  }
1236  case ELF::EM_MSP430:
1237  return Triple::msp430;
1238  case ELF::EM_PPC:
1239  return IsLittleEndian ? Triple::ppcle : Triple::ppc;
1240  case ELF::EM_PPC64:
1241  return IsLittleEndian ? Triple::ppc64le : Triple::ppc64;
1242  case ELF::EM_RISCV:
1243  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1244  case ELF::ELFCLASS32:
1245  return Triple::riscv32;
1246  case ELF::ELFCLASS64:
1247  return Triple::riscv64;
1248  default:
1249  report_fatal_error("Invalid ELFCLASS!");
1250  }
1251  case ELF::EM_S390:
1252  return Triple::systemz;
1253 
1254  case ELF::EM_SPARC:
1255  case ELF::EM_SPARC32PLUS:
1256  return IsLittleEndian ? Triple::sparcel : Triple::sparc;
1257  case ELF::EM_SPARCV9:
1258  return Triple::sparcv9;
1259 
1260  case ELF::EM_AMDGPU: {
1261  if (!IsLittleEndian)
1262  return Triple::UnknownArch;
1263 
1264  unsigned MACH = EF.getHeader().e_flags & ELF::EF_AMDGPU_MACH;
1265  if (MACH >= ELF::EF_AMDGPU_MACH_R600_FIRST &&
1267  return Triple::r600;
1268  if (MACH >= ELF::EF_AMDGPU_MACH_AMDGCN_FIRST &&
1270  return Triple::amdgcn;
1271 
1272  return Triple::UnknownArch;
1273  }
1274 
1275  case ELF::EM_BPF:
1276  return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
1277 
1278  case ELF::EM_VE:
1279  return Triple::ve;
1280  case ELF::EM_CSKY:
1281  return Triple::csky;
1282  default:
1283  return Triple::UnknownArch;
1284  }
1285 }
1286 
1287 template <class ELFT>
1289  return EF.getHeader().e_entry;
1290 }
1291 
1292 template <class ELFT>
1295  return make_range(dynamic_symbol_begin(), dynamic_symbol_end());
1296 }
1297 
1298 template <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const {
1299  return EF.getHeader().e_type == ELF::ET_REL;
1300 }
1301 
1302 } // end namespace object
1303 } // end namespace llvm
1304 
1305 #endif // LLVM_OBJECT_ELFOBJECTFILE_H
MemoryBuffer.h
llvm::Triple::riscv64
@ riscv64
Definition: Triple.h:73
llvm::object::elf_section_iterator::elf_section_iterator
elf_section_iterator(const section_iterator &B)
Definition: ELFObjectFile.h:126
llvm::object::ELFSectionRef::getObject
const ELFObjectFileBase * getObject() const
Definition: ELFObjectFile.h:107
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:849
llvm::cast
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition: Casting.h:254
llvm::object::ELFObjectFile::DotDynSymSec
const Elf_Shdr * DotDynSymSec
Definition: ELFObjectFile.h:256
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
llvm::object::ELFObjectFile::getSectionName
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:795
llvm::ELF::STT_SECTION
@ STT_SECTION
Definition: ELF.h:1092
llvm::object::ELFObjectFile::toSymbolRef
ELFSymbolRef toSymbolRef(const Elf_Shdr *SymTable, unsigned SymbolNum) const
Definition: ELFObjectFile.h:240
llvm::ELF::ELFCLASS64
@ ELFCLASS64
Definition: ELF.h:326
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::Triple::bpfeb
@ bpfeb
Definition: Triple.h:58
llvm::object::ELFObjectFile::getRelocationAddend
Expected< int64_t > getRelocationAddend(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1024
llvm::object::DataRefImpl::a
uint32_t a
Definition: SymbolicFile.h:37
llvm::Triple::UnknownArch
@ UnknownArch
Definition: Triple.h:48
llvm::object::ELFObjectFile::getSymbolELFType
uint8_t getSymbolELFType(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:648
intptr_t
llvm::ELF::EM_ARM
@ EM_ARM
Definition: ELF.h:155
llvm::object::ELFObjectFile::getRelSection
const Elf_Shdr * getRelSection(DataRefImpl Rel) const
Get the relocation section that contains Rel.
Definition: ELFObjectFile.h:407
llvm::object::ELFSymbolRef::getELFTypeName
StringRef getELFTypeName() const
Definition: ELFObjectFile.h:165
llvm::object::ELFSectionRef::getType
uint32_t getType() const
Definition: ELFObjectFile.h:111
llvm::ELF::EM_VE
@ EM_VE
Definition: ELF.h:318
llvm::ELF::EM_SPARC
@ EM_SPARC
Definition: ELF.h:134
llvm::object::ELFObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition: ELFObjectFile.h:1082
llvm::object::ELFObjectFile::isSectionText
bool isSectionText(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:845
StringRef.h
llvm::object::BasicSymbolRef::SF_Common
@ SF_Common
Definition: SymbolicFile.h:108
llvm::ELF::EM_SPARC32PLUS
@ EM_SPARC32PLUS
Definition: ELF.h:145
llvm::Triple::x86
@ x86
Definition: Triple.h:82
llvm::object::ELFObjectFileBase::getPltAddresses
std::vector< std::pair< Optional< DataRefImpl >, uint64_t > > getPltAddresses() const
Definition: ELFObjectFile.cpp:571
llvm::ELF::EM_HEXAGON
@ EM_HEXAGON
Definition: ELF.h:256
llvm::object::ELFObjectFile::getRelocationTypeName
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
Definition: ELFObjectFile.h:1016
llvm::ELF::SHT_RELA
@ SHT_RELA
Definition: ELF.h:852
llvm::ELF::EF_AMDGPU_MACH_R600_FIRST
@ EF_AMDGPU_MACH_R600_FIRST
Definition: ELF.h:700
llvm::Triple::amdgcn
@ amdgcn
Definition: Triple.h:71
llvm::object::ELFObjectFile::DotSymtabSec
const Elf_Shdr * DotSymtabSec
Definition: ELFObjectFile.h:257
llvm::object::ELFObjectFileBase::getBuildAttributes
virtual Error getBuildAttributes(ELFAttributeParser &Attributes) const =0
llvm::object::SectionRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:523
ErrorHandling.h
llvm::object::DataRefImpl::d
struct llvm::object::DataRefImpl::@311 d
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
llvm::object::ELFObjectFile::EF
ELFFile< ELFT > EF
Definition: ELFObjectFile.h:254
llvm::object::ELFObjectFileBase::getEMachine
virtual uint16_t getEMachine() const =0
llvm::object::createError
static Error createError(const Twine &Err)
Definition: ELF.h:84
Error.h
llvm::object::ELFObjectFile::getBuildAttributes
Error getBuildAttributes(ELFAttributeParser &Attributes) const override
Definition: ELFObjectFile.h:365
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:927
llvm::ELF::SHN_COMMON
@ SHN_COMMON
Definition: ELF.h:841
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::object::ELFObjectFileBase::classof
static bool classof(const Binary *v)
Definition: ELFObjectFile.h:85
llvm::object::elf_section_iterator::operator*
const ELFSectionRef & operator*() const
Definition: ELFObjectFile.h:134
llvm::ELF::EM_MIPS
@ EM_MIPS
Definition: ELF.h:140
llvm::object::BasicSymbolRef::SF_Exported
@ SF_Exported
Definition: SymbolicFile.h:110
llvm::object::relocation_iterator
content_iterator< RelocationRef > relocation_iterator
Definition: ObjectFile.h:76
llvm::ELF::EM_RISCV
@ EM_RISCV
Definition: ELF.h:315
llvm::object::getSection
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: ELF.h:404
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::object::NumElfSymbolTypes
constexpr int NumElfSymbolTypes
Definition: ELFObjectFile.h:44
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:83
llvm::object::symbol_iterator::operator->
const SymbolRef * operator->() const
Definition: ObjectFile.h:211
llvm::object::ELFObjectFile::DotSymtabShndxSec
const Elf_Shdr * DotSymtabShndxSec
Definition: ELFObjectFile.h:258
llvm::object::SymbolRef::ST_Unknown
@ ST_Unknown
Definition: ObjectFile.h:169
llvm::object::getObject
static Expected< const T * > getObject(MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
Definition: XCOFFObjectFile.cpp:32
llvm::Triple::ppc
@ ppc
Definition: Triple.h:66
llvm::object::elf_symbol_iterator::operator*
const ELFSymbolRef & operator*() const
Definition: ELFObjectFile.h:186
llvm::Optional
Definition: APInt.h:33
llvm::object::ELFObjectFileBase::ELFSymbolRef
friend class ELFSymbolRef
Definition: ELFObjectFile.h:52
llvm::Triple::hexagon
@ hexagon
Definition: Triple.h:60
llvm::object::elf_relocation_iterator::operator->
const ELFRelocationRef * operator->() const
Definition: ELFObjectFile.h:212
llvm::object::ELFSectionRef
Definition: ELFObjectFile.h:101
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::object::SymbolRef::ST_Data
@ ST_Data
Definition: ObjectFile.h:170
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::object::ELFObjectFile::isBerkeleyData
bool isBerkeleyData(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:906
STLExtras.h
llvm::object::SymbolRef::ST_File
@ ST_File
Definition: ObjectFile.h:172
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition: SymbolicFile.h:106
SymbolicFile.h
llvm::Triple::avr
@ avr
Definition: Triple.h:56
llvm::object::ELFObjectFile::dynamic_symbol_begin
elf_symbol_iterator dynamic_symbol_begin() const
Definition: ELFObjectFile.h:1099
llvm::Triple::mips64
@ mips64
Definition: Triple.h:63
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1006
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::object::ELFObjectFile::getDynamicSymbolIterators
elf_symbol_iterator_range getDynamicSymbolIterators() const override
Definition: ELFObjectFile.h:1294
llvm::ELF::STT_TLS
@ STT_TLS
Definition: ELF.h:1095
llvm::EnumEntry
Definition: ScopedPrinter.h:24
llvm::object::ELFObjectFile::toDRI
DataRefImpl toDRI(const Elf_Dyn *Dyn) const
Definition: ELFObjectFile.h:346
llvm::ELF::EM_AMDGPU
@ EM_AMDGPU
Definition: ELF.h:314
llvm::ELF::SHN_UNDEF
@ SHN_UNDEF
Definition: ELF.h:834
llvm::object::ELFSymbolRef::getSize
uint64_t getSize() const
Definition: ELFObjectFile.h:149
llvm::ELF::STT_FILE
@ STT_FILE
Definition: ELF.h:1093
llvm::object::ELFObjectFile::getRela
const Elf_Rela * getRela(DataRefImpl Rela) const
Definition: ELFObjectFile.h:1042
llvm::object::ELFObjectFileBase
Definition: ELFObjectFile.h:49
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::object::SymbolicFile::symbol_end
virtual basic_symbol_iterator symbol_end() const =0
llvm::ELF::STV_HIDDEN
@ STV_HIDDEN
Definition: ELF.h:1109
ARMAttributeParser.h
llvm::object::ELFObjectFileBase::getPlatformFlags
virtual unsigned getPlatformFlags() const =0
Returns platform-specific object flags, if any.
llvm::Triple::sparc
@ sparc
Definition: Triple.h:74
llvm::object::ELFSymbolRef::getOther
uint8_t getOther() const
Definition: ELFObjectFile.h:157
llvm::object::ELFRelocationRef
Definition: ELFObjectFile.h:191
Error.h
llvm::ELF::STV_PROTECTED
@ STV_PROTECTED
Definition: ELF.h:1110
llvm::Triple::sparcv9
@ sparcv9
Definition: Triple.h:75
SubtargetFeature.h
llvm::Triple::sparcel
@ sparcel
Definition: Triple.h:76
ELF.h
llvm::ELF::SHT_RISCV_ATTRIBUTES
@ SHT_RISCV_ATTRIBUTES
Definition: ELF.h:914
llvm::object::symbol_iterator::operator*
const SymbolRef & operator*() const
Definition: ObjectFile.h:216
llvm::Triple::ArchType
ArchType
Definition: Triple.h:47
llvm::ELF::EI_CLASS
@ EI_CLASS
Definition: ELF.h:51
llvm::object::ELFObjectFile::initContent
Error initContent() override
Definition: ELFObjectFile.h:459
llvm::ELF::EM_PPC
@ EM_PPC
Definition: ELF.h:147
llvm::object::ELFSymbolRef::getObject
const ELFObjectFileBase * getObject() const
Definition: ELFObjectFile.h:145
llvm::object::BasicSymbolRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition: SymbolicFile.h:202
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::object::ELFObjectFileBase::getSectionFlags
virtual uint64_t getSectionFlags(DataRefImpl Sec) const =0
llvm::support::little
@ little
Definition: Endian.h:27
llvm::object::ELFObjectFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition: ELFObjectFile.h:455
llvm::ELF::STB_LOCAL
@ STB_LOCAL
Definition: ELF.h:1077
llvm::Triple::mips64el
@ mips64el
Definition: Triple.h:64
llvm::object::ELFObjectFile::getSectionAlignment
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:835
llvm::object::ELFObjectFile::getELFFile
const ELFFile< ELFT > & getELFFile() const
Definition: ELFObjectFile.h:436
llvm::ELF::STT_NOTYPE
@ STT_NOTYPE
Definition: ELF.h:1089
llvm::ELF::EM_IAMCU
@ EM_IAMCU
Definition: ELF.h:138
llvm::SubtargetFeatures
Manages the enabling and disabling of subtarget specific features.
Definition: SubtargetFeature.h:183
llvm::object::elf_section_iterator
Definition: ELFObjectFile.h:124
llvm::object::ELFSectionRef::getFlags
uint64_t getFlags() const
Definition: ELFObjectFile.h:115
llvm::object::content_iterator::operator*
const content_type & operator*() const
Definition: SymbolicFile.h:77
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
First
into llvm powi allowing the code generator to produce balanced multiplication trees First
Definition: README.txt:54
llvm::Triple::ppc64
@ ppc64
Definition: Triple.h:68
llvm::object::ELFObjectFile::section_rel_begin
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:920
llvm::object::ELFObjectFile::isDyldELFObject
bool isDyldELFObject
Definition: ELFObjectFile.h:392
llvm::Triple::r600
@ r600
Definition: Triple.h:70
llvm::report_fatal_error
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:140
llvm::object::ELFObjectFile::getSymbolAlignment
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:600
llvm::object::ELFObjectFileBase::getRelocationAddend
virtual Expected< int64_t > getRelocationAddend(DataRefImpl Rel) const =0
llvm::object::DataRefImpl::p
uintptr_t p
Definition: SymbolicFile.h:39
llvm::object::Binary::getELFType
static unsigned int getELFType(bool isLE, bool is64Bits)
Definition: Binary.h:75
llvm::ELF::EF_AMDGPU_MACH_R600_LAST
@ EF_AMDGPU_MACH_R600_LAST
Definition: ELF.h:701
llvm::object::ELFObjectFile::isBerkeleyText
bool isBerkeleyText(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:899
llvm::Triple::lanai
@ lanai
Definition: Triple.h:97
llvm::ELF::STV_DEFAULT
@ STV_DEFAULT
Definition: ELF.h:1107
llvm::object::ELFObjectFile::create
static Expected< ELFObjectFile< ELFT > > create(MemoryBufferRef Object, bool InitContent=true)
Definition: ELFObjectFile.h:1052
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition: ELF.h:924
llvm::object::SymbolRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:414
llvm::object::ELFObjectFile::getSymbolValueImpl
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:534
llvm::Triple::csky
@ csky
Definition: Triple.h:59
llvm::ErrorInfoBase
Base class for error info classes.
Definition: Error.h:48
llvm::object::ELFObjectFile::getSymbolBinding
uint8_t getSymbolBinding(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:632
llvm::ELFAttrs::Format_Version
@ Format_Version
Definition: ELFAttributes.h:33
llvm::object::ELFObjectFileBase::getDynamicSymbolIterators
virtual elf_symbol_iterator_range getDynamicSymbolIterators() const =0
llvm::object::ELFObjectFileBase::getSectionOffset
virtual uint64_t getSectionOffset(DataRefImpl Sec) const =0
llvm::object::RelocationRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:561
ELFAttributes.h
llvm::ELF::EM_S390
@ EM_S390
Definition: ELF.h:149
llvm::ELF::EM_AARCH64
@ EM_AARCH64
Definition: ELF.h:279
llvm::object::BasicSymbolRef::getObject
const SymbolicFile * getObject() const
Definition: SymbolicFile.h:206
llvm::OutputFileType::Object
@ Object
llvm::object::SectionRef
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:80
llvm::object::ELFObjectFile::getSectionContents
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:822
llvm::object::ELFSectionRef::getOffset
uint64_t getOffset() const
Definition: ELFObjectFile.h:119
llvm::Triple::ppc64le
@ ppc64le
Definition: Triple.h:69
llvm::ELF::SHT_REL
@ SHT_REL
Definition: ELF.h:857
llvm::object::ElfSymbolTypes
const llvm::EnumEntry< unsigned > ElfSymbolTypes[NumElfSymbolTypes]
Definition: ELFObjectFile.cpp:40
llvm::object::ELFObjectFile::section_rel_end
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:933
llvm::object::getELFRelocationTypeName
StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
Definition: ELF.cpp:22
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::object::BasicSymbolRef::SF_FormatSpecific
@ SF_FormatSpecific
Definition: SymbolicFile.h:111
type
AMD64 Optimization Manual has some nice information about optimizing integer multiplication by a constant How much of it applies to Intel s X86 implementation There are definite trade offs to xmm0 cvttss2siq rdx jb L3 subss xmm0 rax cvttss2siq rdx xorq rdx rax ret instead of xmm1 cvttss2siq rcx movaps xmm2 subss xmm2 cvttss2siq rax rdx xorq rax ucomiss xmm0 cmovb rax ret Seems like the jb branch has high likelihood of being taken It would have saved a few instructions It s not possible to reference and DH registers in an instruction requiring REX prefix divb and mulb both produce results in AH If isel emits a CopyFromReg which gets turned into a movb and that can be allocated a r8b r15b To get around isel emits a CopyFromReg from AX and then right shift it down by and truncate it It s not pretty but it works We need some register allocation magic to make the hack go which would often require a callee saved register Callees usually need to keep this value live for most of their body so it doesn t add a significant burden on them We currently implement this in however this is suboptimal because it means that it would be quite awkward to implement the optimization for callers A better implementation would be to relax the LLVM IR rules for sret arguments to allow a function with an sret argument to have a non void return type
Definition: README-X86-64.txt:70
llvm::ELF::EM_AVR
@ EM_AVR
Definition: ELF.h:198
llvm::object::ELFObjectFile::section_begin
section_iterator section_begin() const override
Definition: ELFObjectFile.h:1118
llvm::object::Binary::getType
unsigned int getType() const
Definition: Binary.h:101
llvm::object::ELFObjectFile::getSectionIndex
uint64_t getSectionIndex(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:805
llvm::object::symbol_iterator
Definition: ObjectFile.h:204
ELF.h
llvm::object::ELFObjectFileBase::getFeatures
SubtargetFeatures getFeatures() const override
Definition: ELFObjectFile.cpp:346
llvm::object::ELFObjectFile::getSection
const Elf_Shdr * getSection(DataRefImpl Sec) const
Definition: ELFObjectFile.h:414
llvm::object::SymbolRef::ST_Function
@ ST_Function
Definition: ObjectFile.h:173
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::object::ELFRelocationRef::ELFRelocationRef
ELFRelocationRef(const RelocationRef &B)
Definition: ELFObjectFile.h:193
llvm::object::ELFObjectFile::getFileFormatName
StringRef getFileFormatName() const override
Definition: ELFObjectFile.h:1139
llvm::object::elf_symbol_iterator::operator->
const ELFSymbolRef * operator->() const
Definition: ELFObjectFile.h:182
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::object::BasicSymbolRef::SF_None
@ SF_None
Definition: SymbolicFile.h:103
llvm::object::ObjectFile::SectionRef
friend class SectionRef
Definition: ObjectFile.h:257
llvm::object::ELFObjectFile::classof
static bool classof(const Binary *v)
Definition: ELFObjectFile.h:439
llvm::object::ELFRelocationRef::getObject
const ELFObjectFileBase * getObject() const
Definition: ELFObjectFile.h:197
llvm::object::BasicSymbolRef::SF_Undefined
@ SF_Undefined
Definition: SymbolicFile.h:104
llvm::object::ELFObjectFile::getSectionAddress
uint64_t getSectionAddress(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:800
llvm::object::ELFObjectFile::isDebugSection
bool isDebugSection(StringRef SectionName) const override
Definition: ELFObjectFile.h:913
llvm::ELF::SHT_ARM_ATTRIBUTES
@ SHT_ARM_ATTRIBUTES
Definition: ELF.h:900
llvm::is_contained
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:1563
ArrayRef.h
llvm::object::ELFObjectFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:681
llvm::object::BasicSymbolRef::SF_Thumb
@ SF_Thumb
Definition: SymbolicFile.h:113
llvm::ELF::SHT_SYMTAB
@ SHT_SYMTAB
Definition: ELF.h:850
llvm::object::ELFSymbolRef
Definition: ELFObjectFile.h:139
llvm::object::SymbolRef::ST_Debug
@ ST_Debug
Definition: ObjectFile.h:171
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::ELF::STB_GLOBAL
@ STB_GLOBAL
Definition: ELF.h:1078
ObjectFile.h
llvm::object::ELFObjectFileBase::elf_symbol_iterator_range
iterator_range< elf_symbol_iterator > elf_symbol_iterator_range
Definition: ELFObjectFile.h:76
llvm::object::Binary::isELF
bool isELF() const
Definition: Binary.h:120
llvm::ELF::STT_COMMON
@ STT_COMMON
Definition: ELF.h:1094
base
therefore end up llgh r3 lr r0 br r14 but truncating the load would lh r3 br r14 Functions ret i64 and ought to be implemented ngr r0 br r14 but two address optimizations reverse the order of the AND and ngr r2 lgr r0 br r14 CodeGen SystemZ and ll has several examples of this Out of range displacements are usually handled by loading the full address into a register In many cases it would be better to create an anchor point instead E g i64 base
Definition: README.txt:125
llvm::object::content_iterator
Definition: SymbolicFile.h:68
llvm::object::ELFSymbolRef::getBinding
uint8_t getBinding() const
Definition: ELFObjectFile.h:153
llvm::Triple::bpfel
@ bpfel
Definition: Triple.h:57
llvm::object::content_iterator::operator->
const content_type * operator->() const
Definition: SymbolicFile.h:75
ELFTypes.h
iterator_range.h
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:856
llvm::object::ELFObjectFileBase::getSymbolSize
virtual uint64_t getSymbolSize(DataRefImpl Symb) const =0
llvm::object::ELFObjectFile::dynamic_symbol_end
elf_symbol_iterator dynamic_symbol_end() const
Definition: ELFObjectFile.h:1109
llvm::object::ELFObjectFile::getRelocatedSection
Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:952
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition: ELF.h:930
llvm::object::elf_relocation_iterator
Definition: ELFObjectFile.h:206
llvm::ELF::ELFCLASS32
@ ELFCLASS32
Definition: ELF.h:325
Triple.h
llvm::ELFAttributeParser
Definition: ELFAttributeParser.h:23
llvm::object::ELFObjectFile::getSymbolSection
Expected< section_iterator > getSymbolSection(const Elf_Sym *Symb, const Elf_Shdr *SymTab) const
Definition: ELFObjectFile.h:750
llvm::object::ELFObjectFile::getSymbolOther
uint8_t getSymbolOther(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:640
llvm::Sched::Source
@ Source
Definition: TargetLowering.h:98
llvm::ELFAttributeParser::parse
Error parse(ArrayRef< uint8_t > section, support::endianness endian)
Definition: ELFAttributeParser.cpp:189
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::ELF::EF_AMDGPU_MACH_AMDGCN_LAST
@ EF_AMDGPU_MACH_AMDGCN_LAST
Definition: ELF.h:739
llvm::Triple::arm
@ arm
Definition: Triple.h:50
llvm::ELF::EF_AMDGPU_MACH
@ EF_AMDGPU_MACH
Definition: ELF.h:667
llvm::object::section_iterator
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:47
llvm::object::ELFObjectFile::isRelocatableObject
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
Definition: ELFObjectFile.h:1298
llvm::object::ELFObjectFile::IsContentValid
bool IsContentValid() const
Definition: ELFObjectFile.h:244
llvm::object::ELFObjectFileBase::symbols
elf_symbol_iterator_range symbols() const
Definition: ELFObjectFile.h:224
llvm::object::elf_symbol_iterator::elf_symbol_iterator
elf_symbol_iterator(const basic_symbol_iterator &B)
Definition: ELFObjectFile.h:178
llvm::Triple::aarch64_be
@ aarch64_be
Definition: Triple.h:53
llvm::Triple::msp430
@ msp430
Definition: Triple.h:65
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition: ObjectFile.h:225
llvm::object::Binary
Definition: Binary.h:32
llvm::ELF::EM_PPC64
@ EM_PPC64
Definition: ELF.h:148
llvm::Triple::ppcle
@ ppcle
Definition: Triple.h:67
llvm::RoundingMode::Dynamic
@ Dynamic
Denotes mode unknown at compile time.
uint32_t
llvm::object::RelocationRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:565
llvm::object::ELFObjectFileBase::getSectionType
virtual uint32_t getSectionType(DataRefImpl Sec) const =0
llvm::object::ELFObjectFile::getPlatformFlags
unsigned getPlatformFlags() const override
Returns platform-specific object flags, if any.
Definition: ELFObjectFile.h:434
llvm::object::ELFObjectFile::getBytesInAddress
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
Definition: ELFObjectFile.h:1134
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::object::SymbolicFile::symbol_begin
virtual basic_symbol_iterator symbol_begin() const =0
llvm::object::DataRefImpl
Definition: SymbolicFile.h:33
llvm::ELF::STB_WEAK
@ STB_WEAK
Definition: ELF.h:1079
llvm::object::ELFObjectFile::getCommonSymbolSizeImpl
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:627
llvm::ELF::EF_AMDGPU_MACH_AMDGCN_FIRST
@ EF_AMDGPU_MACH_AMDGCN_FIRST
Definition: ELF.h:738
llvm::Triple::ve
@ ve
Definition: Triple.h:102
llvm::object::ELFObjectFile::dynamic_relocation_sections
std::vector< SectionRef > dynamic_relocation_sections() const override
Definition: ELFObjectFile.h:866
LLVM_ELF_IMPORT_TYPES_ELFT
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Definition: ELFTypes.h:103
llvm::ELF::EM_SPARCV9
@ EM_SPARCV9
Definition: ELF.h:158
llvm::object::ELFObjectFile::getSymbolType
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:657
llvm::object::ELFObjectFile::toELFShdrIter
const Elf_Shdr * toELFShdrIter(DataRefImpl Sec) const
Definition: ELFObjectFile.h:336
llvm::ELF::SHN_ABS
@ SHN_ABS
Definition: ELF.h:840
llvm::object::ELFObjectFile::getRel
const Elf_Rel * getRel(DataRefImpl Rel) const
Definition: ELFObjectFile.h:1032
llvm::object::ELFObjectFile::getRelocationSymbol
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:975
llvm::object::ELFObjectFile::isExportedToOtherDSO
bool isExportedToOtherDSO(const Elf_Sym *ESym) const
Definition: ELFObjectFile.h:352
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::object::SymbolRef::Type
Type
Definition: ObjectFile.h:168
llvm::object::ELFObjectFile::getRelocationType
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1002
llvm::ELF::SHF_COMPRESSED
@ SHF_COMPRESSED
Definition: ELF.h:955
uint16_t
llvm::object::ELFObjectFile::toDRI
DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const
Definition: ELFObjectFile.h:311
llvm::ELF::EM_X86_64
@ EM_X86_64
Definition: ELF.h:177
llvm::object::ELFObjectFileBase::setARMSubArch
void setARMSubArch(Triple &TheTriple) const override
Definition: ELFObjectFile.cpp:486
llvm::object::ELFObjectFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition: ELFObjectFile.h:1090
llvm::SectionName
Definition: DWARFSection.h:20
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::ELF::SHT_DYNSYM
@ SHT_DYNSYM
Definition: ELF.h:859
llvm::ELF::EM_386
@ EM_386
Definition: ELF.h:135
llvm::ELF::ET_REL
@ ET_REL
Definition: ELF.h:115
llvm::Triple::riscv32
@ riscv32
Definition: Triple.h:72
Casting.h
llvm::ELF::EM_MSP430
@ EM_MSP430
Definition: ELF.h:221
llvm::Triple::mipsel
@ mipsel
Definition: Triple.h:62
llvm::object::BasicSymbolRef::SF_Absolute
@ SF_Absolute
Definition: SymbolicFile.h:107
llvm::object::ELFObjectFileBase::getEType
virtual uint16_t getEType() const =0
llvm::object::ELFObjectFile::isSectionCompressed
bool isSectionCompressed(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:840
llvm::object::ELFFile::create
static Expected< ELFFile > create(StringRef Object)
Definition: ELF.h:755
llvm::Triple::systemz
@ systemz
Definition: Triple.h:77
llvm::object::SymbolRef::ST_Other
@ ST_Other
Definition: ObjectFile.h:174
llvm::object::ELFObjectFile::isSectionData
bool isSectionData(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:850
llvm::object::ELFObjectFile::section_end
section_iterator section_end() const override
Definition: ELFObjectFile.h:1126
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:474
llvm::errorToErrorCode
std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
Definition: Error.cpp:93
llvm::object::ELFObjectFile::toDRI
DataRefImpl toDRI(const Elf_Shdr *Sec) const
Definition: ELFObjectFile.h:340
llvm::object::ELFObjectFile::toSectionRef
SectionRef toSectionRef(const Elf_Shdr *Sec) const
Definition: ELFObjectFile.h:236
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:557
llvm::object::ELFObjectFile::getRelocationOffset
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:993
llvm::object::ELFObjectFileBase::getSymbolBinding
virtual uint8_t getSymbolBinding(DataRefImpl Symb) const =0
Binary.h
llvm::ELF::STT_OBJECT
@ STT_OBJECT
Definition: ELF.h:1090
llvm::object::ELFObjectFile::getSectionOffset
uint64_t getSectionOffset(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:529
SmallVector.h
llvm::object::ELFObjectFile::getSectionType
uint32_t getSectionType(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:524
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition: SymbolicFile.h:105
llvm::object::BasicSymbolRef::SF_Hidden
@ SF_Hidden
Definition: SymbolicFile.h:114
llvm::object::ELFSymbolRef::ELFSymbolRef
ELFSymbolRef(const SymbolRef &B)
Definition: ELFObjectFile.h:141
support
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
Definition: README.txt:10
llvm::ELF::SHT_SYMTAB_SHNDX
@ SHT_SYMTAB_SHNDX
Definition: ELF.h:864
llvm::object::ELFObjectFile::getSymbolName
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:489
llvm::object::ELFSymbolRef::getELFType
uint8_t getELFType() const
Definition: ELFObjectFile.h:161
getSymbolValue
static uint64_t getSymbolValue(const MCSymbol &Symbol, const MCAsmLayout &Layout)
Definition: WinCOFFObjectWriter.cpp:334
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::object::elf_symbol_iterator
Definition: ELFObjectFile.h:176
llvm::ELF::EM_CSKY
@ EM_CSKY
Definition: ELF.h:319
llvm::SmallVectorImpl< char >
llvm::object::SymbolRef
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition: ObjectFile.h:164
llvm::object::ELFObjectFile::moveRelocationNext
void moveRelocationNext(DataRefImpl &Rel) const override
Definition: ELFObjectFile.h:969
llvm::object::elf_relocation_iterator::elf_relocation_iterator
elf_relocation_iterator(const relocation_iterator &B)
Definition: ELFObjectFile.h:208
llvm::object::ELFObjectFile::isDyldType
bool isDyldType() const
Definition: ELFObjectFile.h:438
llvm::object::DataRefImpl::b
uint32_t b
Definition: SymbolicFile.h:37
llvm::ELF::STB_GNU_UNIQUE
@ STB_GNU_UNIQUE
Definition: ELF.h:1080
llvm::object::RelocationRef
This is a value type class that represents a single relocation in the list of relocations in the obje...
Definition: ObjectFile.h:51
llvm::object::ELFObjectFile::isSectionBSS
bool isSectionBSS(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:858
llvm::object::ELFObjectFile::isSectionVirtual
bool isSectionVirtual(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:894
llvm::object::ELFRelocationRef::getAddend
Expected< int64_t > getAddend() const
Definition: ELFObjectFile.h:201
llvm::object::ELFObjectFileBase::getSymbolOther
virtual uint8_t getSymbolOther(DataRefImpl Symb) const =0
llvm::ELF::EM_BPF
@ EM_BPF
Definition: ELF.h:317
llvm::SI::KernelInputOffsets::Offsets
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:1224
llvm::object::ELFSectionRef::ELFSectionRef
ELFSectionRef(const SectionRef &B)
Definition: ELFObjectFile.h:103
llvm::object::ELFObjectFile::moveSectionNext
void moveSectionNext(DataRefImpl &Sec) const override
Definition: ELFObjectFile.h:789
getSymbolName
static StringRef getSymbolName(SymbolKind SymKind)
Definition: CodeViewDebug.cpp:2980
llvm::object::ELFObjectFileBase::getSymbolELFType
virtual uint8_t getSymbolELFType(DataRefImpl Symb) const =0
llvm::object::ELFObjectFileBase::tryGetCPUName
Optional< StringRef > tryGetCPUName() const override
Definition: ELFObjectFile.cpp:359
llvm::ELF::STT_FUNC
@ STT_FUNC
Definition: ELF.h:1091
Endian.h
llvm::object::ELFObjectFile::getSectionFlags
uint64_t getSectionFlags(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:519
llvm::object::ELFObjectFile
Definition: ELFObjectFile.h:228
llvm::object::SectionRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:527
llvm::ELF::SHT_DYNAMIC
@ SHT_DYNAMIC
Definition: ELF.h:854
llvm::object::ELFObjectFile::getArch
Triple::ArchType getArch() const override
Definition: ELFObjectFile.h:1209
llvm::object::ELFObjectFile::getSymbol
Expected< const Elf_Sym * > getSymbol(DataRefImpl Sym) const
Definition: ELFObjectFile.h:402
llvm::object::ELFObjectFile::getStartAddress
Expected< uint64_t > getStartAddress() const override
Definition: ELFObjectFile.h:1288
llvm::handleAllErrors
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:929
llvm::object::basic_symbol_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
Definition: SymbolicFile.h:137
llvm::object::ELFFile
Definition: ELF.h:98
llvm::ELF::EM_LANAI
@ EM_LANAI
Definition: ELF.h:316
llvm::Triple::mips
@ mips
Definition: Triple.h:61
llvm::object::elf_relocation_iterator::operator*
const ELFRelocationRef & operator*() const
Definition: ELFObjectFile.h:217
llvm::object::elf_section_iterator::operator->
const ELFSectionRef * operator->() const
Definition: ELFObjectFile.h:130
llvm::object::ELFObjectFileBase::ELFObjectFileBase
ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
Definition: ELFObjectFile.cpp:59
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:52
llvm::object::ELFObjectFile::getSymbolAddress
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:554
llvm::object::ELFObjectFile::getSectionSize
uint64_t getSectionSize(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:816
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1131