LLVM  14.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;
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  /// Returns a vector containing a symbol version for each dynamic symbol.
101  /// Returns an empty vector if version sections do not exist.
103 };
104 
105 class ELFSectionRef : public SectionRef {
106 public:
108  assert(isa<ELFObjectFileBase>(SectionRef::getObject()));
109  }
110 
111  const ELFObjectFileBase *getObject() const {
112  return cast<ELFObjectFileBase>(SectionRef::getObject());
113  }
114 
115  uint32_t getType() const {
117  }
118 
119  uint64_t getFlags() const {
121  }
122 
123  uint64_t getOffset() const {
125  }
126 };
127 
129 public:
131  assert(isa<ELFObjectFileBase>(B->getObject()));
132  }
133 
134  const ELFSectionRef *operator->() const {
135  return static_cast<const ELFSectionRef *>(section_iterator::operator->());
136  }
137 
138  const ELFSectionRef &operator*() const {
139  return static_cast<const ELFSectionRef &>(section_iterator::operator*());
140  }
141 };
142 
143 class ELFSymbolRef : public SymbolRef {
144 public:
146  assert(isa<ELFObjectFileBase>(SymbolRef::getObject()));
147  }
148 
149  const ELFObjectFileBase *getObject() const {
150  return cast<ELFObjectFileBase>(BasicSymbolRef::getObject());
151  }
152 
153  uint64_t getSize() const {
155  }
156 
157  uint8_t getBinding() const {
159  }
160 
161  uint8_t getOther() const {
163  }
164 
165  uint8_t getELFType() const {
167  }
168 
170  uint8_t Type = getELFType();
171  for (auto &EE : ElfSymbolTypes) {
172  if (EE.Value == Type) {
173  return EE.AltName;
174  }
175  }
176  return "";
177  }
178 };
179 
181 public:
183  : symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
185 
186  const ELFSymbolRef *operator->() const {
187  return static_cast<const ELFSymbolRef *>(symbol_iterator::operator->());
188  }
189 
190  const ELFSymbolRef &operator*() const {
191  return static_cast<const ELFSymbolRef &>(symbol_iterator::operator*());
192  }
193 };
194 
196 public:
198  assert(isa<ELFObjectFileBase>(RelocationRef::getObject()));
199  }
200 
201  const ELFObjectFileBase *getObject() const {
202  return cast<ELFObjectFileBase>(RelocationRef::getObject());
203  }
204 
207  }
208 };
209 
211 public:
214  B->getRawDataRefImpl(), cast<ELFObjectFileBase>(B->getObject()))) {}
215 
216  const ELFRelocationRef *operator->() const {
217  return static_cast<const ELFRelocationRef *>(
219  }
220 
221  const ELFRelocationRef &operator*() const {
222  return static_cast<const ELFRelocationRef &>(
224  }
225 };
226 
230 }
231 
232 template <class ELFT> class ELFObjectFile : public ELFObjectFileBase {
233  uint16_t getEMachine() const override;
234  uint16_t getEType() const override;
235  uint64_t getSymbolSize(DataRefImpl Sym) const override;
236 
237 public:
239 
240  SectionRef toSectionRef(const Elf_Shdr *Sec) const {
241  return SectionRef(toDRI(Sec), this);
242  }
243 
244  ELFSymbolRef toSymbolRef(const Elf_Shdr *SymTable, unsigned SymbolNum) const {
245  return ELFSymbolRef({toDRI(SymTable, SymbolNum), this});
246  }
247 
248  bool IsContentValid() const { return ContentValid; }
249 
250 private:
252  const Elf_Shdr *DotDynSymSec, const Elf_Shdr *DotSymtabSec,
253  const Elf_Shdr *DotSymtabShndxSec);
254 
255  bool ContentValid = false;
256 
257 protected:
259 
260  const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
261  const Elf_Shdr *DotSymtabSec = nullptr; // Symbol table section.
262  const Elf_Shdr *DotSymtabShndxSec = nullptr; // SHT_SYMTAB_SHNDX section.
263 
264  Error initContent() override;
265 
266  void moveSymbolNext(DataRefImpl &Symb) const override;
267  Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
268  Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
269  uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
270  uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
271  uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
272  Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
273  uint8_t getSymbolBinding(DataRefImpl Symb) const override;
274  uint8_t getSymbolOther(DataRefImpl Symb) const override;
275  uint8_t getSymbolELFType(DataRefImpl Symb) const override;
277  Expected<section_iterator> getSymbolSection(const Elf_Sym *Symb,
278  const Elf_Shdr *SymTab) const;
280 
281  void moveSectionNext(DataRefImpl &Sec) const override;
282  Expected<StringRef> getSectionName(DataRefImpl Sec) const override;
283  uint64_t getSectionAddress(DataRefImpl Sec) const override;
284  uint64_t getSectionIndex(DataRefImpl Sec) const override;
285  uint64_t getSectionSize(DataRefImpl Sec) const override;
287  getSectionContents(DataRefImpl Sec) const override;
288  uint64_t getSectionAlignment(DataRefImpl Sec) const override;
289  bool isSectionCompressed(DataRefImpl Sec) const override;
290  bool isSectionText(DataRefImpl Sec) const override;
291  bool isSectionData(DataRefImpl Sec) const override;
292  bool isSectionBSS(DataRefImpl Sec) const override;
293  bool isSectionVirtual(DataRefImpl Sec) const override;
294  bool isBerkeleyText(DataRefImpl Sec) const override;
295  bool isBerkeleyData(DataRefImpl Sec) const override;
296  bool isDebugSection(DataRefImpl Sec) const override;
298  relocation_iterator section_rel_end(DataRefImpl Sec) const override;
299  std::vector<SectionRef> dynamic_relocation_sections() const override;
301  getRelocatedSection(DataRefImpl Sec) const override;
302 
303  void moveRelocationNext(DataRefImpl &Rel) const override;
304  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
305  symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
306  uint64_t getRelocationType(DataRefImpl Rel) const override;
308  SmallVectorImpl<char> &Result) const override;
309 
310  uint32_t getSectionType(DataRefImpl Sec) const override;
311  uint64_t getSectionFlags(DataRefImpl Sec) const override;
312  uint64_t getSectionOffset(DataRefImpl Sec) const override;
314 
315  DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const {
316  DataRefImpl DRI;
317  if (!SymTable) {
318  DRI.d.a = 0;
319  DRI.d.b = 0;
320  return DRI;
321  }
322  assert(SymTable->sh_type == ELF::SHT_SYMTAB ||
323  SymTable->sh_type == ELF::SHT_DYNSYM);
324 
325  auto SectionsOrErr = EF.sections();
326  if (!SectionsOrErr) {
327  DRI.d.a = 0;
328  DRI.d.b = 0;
329  return DRI;
330  }
331  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
332  unsigned SymTableIndex =
333  (reinterpret_cast<uintptr_t>(SymTable) - SHT) / sizeof(Elf_Shdr);
334 
335  DRI.d.a = SymTableIndex;
336  DRI.d.b = SymbolNum;
337  return DRI;
338  }
339 
340  const Elf_Shdr *toELFShdrIter(DataRefImpl Sec) const {
341  return reinterpret_cast<const Elf_Shdr *>(Sec.p);
342  }
343 
344  DataRefImpl toDRI(const Elf_Shdr *Sec) const {
345  DataRefImpl DRI;
346  DRI.p = reinterpret_cast<uintptr_t>(Sec);
347  return DRI;
348  }
349 
350  DataRefImpl toDRI(const Elf_Dyn *Dyn) const {
351  DataRefImpl DRI;
352  DRI.p = reinterpret_cast<uintptr_t>(Dyn);
353  return DRI;
354  }
355 
356  bool isExportedToOtherDSO(const Elf_Sym *ESym) const {
357  unsigned char Binding = ESym->getBinding();
358  unsigned char Visibility = ESym->getVisibility();
359 
360  // A symbol is exported if its binding is either GLOBAL or WEAK, and its
361  // visibility is either DEFAULT or PROTECTED. All other symbols are not
362  // exported.
363  return (
364  (Binding == ELF::STB_GLOBAL || Binding == ELF::STB_WEAK ||
365  Binding == ELF::STB_GNU_UNIQUE) &&
366  (Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_PROTECTED));
367  }
368 
370  auto SectionsOrErr = EF.sections();
371  if (!SectionsOrErr)
372  return SectionsOrErr.takeError();
373 
374  for (const Elf_Shdr &Sec : *SectionsOrErr) {
375  if (Sec.sh_type == ELF::SHT_ARM_ATTRIBUTES ||
376  Sec.sh_type == ELF::SHT_RISCV_ATTRIBUTES) {
377  auto ErrorOrContents = EF.getSectionContents(Sec);
378  if (!ErrorOrContents)
379  return ErrorOrContents.takeError();
380 
381  auto Contents = ErrorOrContents.get();
382  if (Contents[0] != ELFAttrs::Format_Version || Contents.size() == 1)
383  return Error::success();
384 
385  if (Error E = Attributes.parse(Contents, ELFT::TargetEndianness))
386  return E;
387  break;
388  }
389  }
390  return Error::success();
391  }
392 
393  // This flag is used for classof, to distinguish ELFObjectFile from
394  // its subclass. If more subclasses will be created, this flag will
395  // have to become an enum.
397 
398 public:
401  bool InitContent = true);
402 
403  const Elf_Rel *getRel(DataRefImpl Rel) const;
404  const Elf_Rela *getRela(DataRefImpl Rela) const;
405 
407  return EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
408  }
409 
410  /// Get the relocation section that contains \a Rel.
411  const Elf_Shdr *getRelSection(DataRefImpl Rel) const {
412  auto RelSecOrErr = EF.getSection(Rel.d.a);
413  if (!RelSecOrErr)
415  Twine(errorToErrorCode(RelSecOrErr.takeError()).message()));
416  return *RelSecOrErr;
417  }
418 
419  const Elf_Shdr *getSection(DataRefImpl Sec) const {
420  return reinterpret_cast<const Elf_Shdr *>(Sec.p);
421  }
422 
423  basic_symbol_iterator symbol_begin() const override;
424  basic_symbol_iterator symbol_end() const override;
425 
428 
429  section_iterator section_begin() const override;
430  section_iterator section_end() const override;
431 
433 
434  uint8_t getBytesInAddress() const override;
435  StringRef getFileFormatName() const override;
436  Triple::ArchType getArch() const override;
437  Expected<uint64_t> getStartAddress() const override;
438 
439  unsigned getPlatformFlags() const override { return EF.getHeader().e_flags; }
440 
441  const ELFFile<ELFT> &getELFFile() const { return EF; }
442 
443  bool isDyldType() const { return isDyldELFObject; }
444  static bool classof(const Binary *v) {
445  return v->getType() == getELFType(ELFT::TargetEndianness == support::little,
446  ELFT::Is64Bits);
447  }
448 
450 
451  bool isRelocatableObject() const override;
452 };
453 
458 
459 template <class ELFT>
461  ++Sym.d.b;
462 }
463 
464 template <class ELFT> Error ELFObjectFile<ELFT>::initContent() {
465  auto SectionsOrErr = EF.sections();
466  if (!SectionsOrErr)
467  return SectionsOrErr.takeError();
468 
469  for (const Elf_Shdr &Sec : *SectionsOrErr) {
470  switch (Sec.sh_type) {
471  case ELF::SHT_DYNSYM: {
472  if (!DotDynSymSec)
473  DotDynSymSec = &Sec;
474  break;
475  }
476  case ELF::SHT_SYMTAB: {
477  if (!DotSymtabSec)
478  DotSymtabSec = &Sec;
479  break;
480  }
481  case ELF::SHT_SYMTAB_SHNDX: {
482  if (!DotSymtabShndxSec)
483  DotSymtabShndxSec = &Sec;
484  break;
485  }
486  }
487  }
488 
489  ContentValid = true;
490  return Error::success();
491 }
492 
493 template <class ELFT>
495  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
496  if (!SymOrErr)
497  return SymOrErr.takeError();
498  auto SymTabOrErr = EF.getSection(Sym.d.a);
499  if (!SymTabOrErr)
500  return SymTabOrErr.takeError();
501  const Elf_Shdr *SymTableSec = *SymTabOrErr;
502  auto StrTabOrErr = EF.getSection(SymTableSec->sh_link);
503  if (!StrTabOrErr)
504  return StrTabOrErr.takeError();
505  const Elf_Shdr *StringTableSec = *StrTabOrErr;
506  auto SymStrTabOrErr = EF.getStringTable(*StringTableSec);
507  if (!SymStrTabOrErr)
508  return SymStrTabOrErr.takeError();
509  Expected<StringRef> Name = (*SymOrErr)->getName(*SymStrTabOrErr);
510  if (Name && !Name->empty())
511  return Name;
512 
513  // If the symbol name is empty use the section name.
514  if ((*SymOrErr)->getType() == ELF::STT_SECTION) {
515  if (Expected<section_iterator> SecOrErr = getSymbolSection(Sym)) {
516  consumeError(Name.takeError());
517  return (*SecOrErr)->getName();
518  }
519  }
520  return Name;
521 }
522 
523 template <class ELFT>
525  return getSection(Sec)->sh_flags;
526 }
527 
528 template <class ELFT>
530  return getSection(Sec)->sh_type;
531 }
532 
533 template <class ELFT>
535  return getSection(Sec)->sh_offset;
536 }
537 
538 template <class ELFT>
540  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
541  if (!SymOrErr)
542  report_fatal_error(SymOrErr.takeError());
543 
544  uint64_t Ret = (*SymOrErr)->st_value;
545  if ((*SymOrErr)->st_shndx == ELF::SHN_ABS)
546  return Ret;
547 
548  const Elf_Ehdr &Header = EF.getHeader();
549  // Clear the ARM/Thumb or microMIPS indicator flag.
550  if ((Header.e_machine == ELF::EM_ARM || Header.e_machine == ELF::EM_MIPS) &&
551  (*SymOrErr)->getType() == ELF::STT_FUNC)
552  Ret &= ~1;
553 
554  return Ret;
555 }
556 
557 template <class ELFT>
560  Expected<uint64_t> SymbolValueOrErr = getSymbolValue(Symb);
561  if (!SymbolValueOrErr)
562  // TODO: Test this error.
563  return SymbolValueOrErr.takeError();
564 
565  uint64_t Result = *SymbolValueOrErr;
566  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
567  if (!SymOrErr)
568  return SymOrErr.takeError();
569 
570  switch ((*SymOrErr)->st_shndx) {
571  case ELF::SHN_COMMON:
572  case ELF::SHN_UNDEF:
573  case ELF::SHN_ABS:
574  return Result;
575  }
576 
577  auto SymTabOrErr = EF.getSection(Symb.d.a);
578  if (!SymTabOrErr)
579  return SymTabOrErr.takeError();
580 
581  if (EF.getHeader().e_type == ELF::ET_REL) {
582  ArrayRef<Elf_Word> ShndxTable;
583  if (DotSymtabShndxSec) {
584  // TODO: Test this error.
585  if (Expected<ArrayRef<Elf_Word>> ShndxTableOrErr =
586  EF.getSHNDXTable(*DotSymtabShndxSec))
587  ShndxTable = *ShndxTableOrErr;
588  else
589  return ShndxTableOrErr.takeError();
590  }
591 
592  Expected<const Elf_Shdr *> SectionOrErr =
593  EF.getSection(**SymOrErr, *SymTabOrErr, ShndxTable);
594  if (!SectionOrErr)
595  return SectionOrErr.takeError();
596  const Elf_Shdr *Section = *SectionOrErr;
597  if (Section)
598  Result += Section->sh_addr;
599  }
600 
601  return Result;
602 }
603 
604 template <class ELFT>
606  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
607  if (!SymOrErr)
608  report_fatal_error(SymOrErr.takeError());
609  if ((*SymOrErr)->st_shndx == ELF::SHN_COMMON)
610  return (*SymOrErr)->st_value;
611  return 0;
612 }
613 
614 template <class ELFT>
616  return EF.getHeader().e_machine;
617 }
618 
619 template <class ELFT> uint16_t ELFObjectFile<ELFT>::getEType() const {
620  return EF.getHeader().e_type;
621 }
622 
623 template <class ELFT>
624 uint64_t ELFObjectFile<ELFT>::getSymbolSize(DataRefImpl Sym) const {
625  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
626  if (!SymOrErr)
627  report_fatal_error(SymOrErr.takeError());
628  return (*SymOrErr)->st_size;
629 }
630 
631 template <class ELFT>
633  return getSymbolSize(Symb);
634 }
635 
636 template <class ELFT>
638  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
639  if (!SymOrErr)
640  report_fatal_error(SymOrErr.takeError());
641  return (*SymOrErr)->getBinding();
642 }
643 
644 template <class ELFT>
646  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
647  if (!SymOrErr)
648  report_fatal_error(SymOrErr.takeError());
649  return (*SymOrErr)->st_other;
650 }
651 
652 template <class ELFT>
654  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
655  if (!SymOrErr)
656  report_fatal_error(SymOrErr.takeError());
657  return (*SymOrErr)->getType();
658 }
659 
660 template <class ELFT>
663  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
664  if (!SymOrErr)
665  return SymOrErr.takeError();
666 
667  switch ((*SymOrErr)->getType()) {
668  case ELF::STT_NOTYPE:
669  return SymbolRef::ST_Unknown;
670  case ELF::STT_SECTION:
671  return SymbolRef::ST_Debug;
672  case ELF::STT_FILE:
673  return SymbolRef::ST_File;
674  case ELF::STT_FUNC:
675  return SymbolRef::ST_Function;
676  case ELF::STT_OBJECT:
677  case ELF::STT_COMMON:
678  return SymbolRef::ST_Data;
679  case ELF::STT_TLS:
680  default:
681  return SymbolRef::ST_Other;
682  }
683 }
684 
685 template <class ELFT>
687  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
688  if (!SymOrErr)
689  return SymOrErr.takeError();
690 
691  const Elf_Sym *ESym = *SymOrErr;
692  uint32_t Result = SymbolRef::SF_None;
693 
694  if (ESym->getBinding() != ELF::STB_LOCAL)
695  Result |= SymbolRef::SF_Global;
696 
697  if (ESym->getBinding() == ELF::STB_WEAK)
698  Result |= SymbolRef::SF_Weak;
699 
700  if (ESym->st_shndx == ELF::SHN_ABS)
701  Result |= SymbolRef::SF_Absolute;
702 
703  if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION)
705 
706  if (Expected<typename ELFT::SymRange> SymbolsOrErr =
707  EF.symbols(DotSymtabSec)) {
708  // Set the SF_FormatSpecific flag for the 0-index null symbol.
709  if (ESym == SymbolsOrErr->begin())
711  } else
712  // TODO: Test this error.
713  return SymbolsOrErr.takeError();
714 
715  if (Expected<typename ELFT::SymRange> SymbolsOrErr =
716  EF.symbols(DotDynSymSec)) {
717  // Set the SF_FormatSpecific flag for the 0-index null symbol.
718  if (ESym == SymbolsOrErr->begin())
720  } else
721  // TODO: Test this error.
722  return SymbolsOrErr.takeError();
723 
724  if (EF.getHeader().e_machine == ELF::EM_AARCH64) {
725  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
726  StringRef Name = *NameOrErr;
727  if (Name.startswith("$d") || Name.startswith("$x"))
729  } else {
730  // TODO: Actually report errors helpfully.
731  consumeError(NameOrErr.takeError());
732  }
733  } else if (EF.getHeader().e_machine == ELF::EM_ARM) {
734  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
735  StringRef Name = *NameOrErr;
736  // TODO Investigate why empty name symbols need to be marked.
737  if (Name.empty() || Name.startswith("$d") || Name.startswith("$t") ||
738  Name.startswith("$a"))
740  } else {
741  // TODO: Actually report errors helpfully.
742  consumeError(NameOrErr.takeError());
743  }
744  if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
745  Result |= SymbolRef::SF_Thumb;
746  } else if (EF.getHeader().e_machine == ELF::EM_RISCV) {
747  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
748  // Mark empty name symbols used for label differences.
749  if (NameOrErr->empty())
751  } else {
752  // TODO: Actually report errors helpfully.
753  consumeError(NameOrErr.takeError());
754  }
755  }
756 
757  if (ESym->st_shndx == ELF::SHN_UNDEF)
758  Result |= SymbolRef::SF_Undefined;
759 
760  if (ESym->getType() == ELF::STT_COMMON || ESym->st_shndx == ELF::SHN_COMMON)
761  Result |= SymbolRef::SF_Common;
762 
763  if (isExportedToOtherDSO(ESym))
764  Result |= SymbolRef::SF_Exported;
765 
766  if (ESym->getVisibility() == ELF::STV_HIDDEN)
767  Result |= SymbolRef::SF_Hidden;
768 
769  return Result;
770 }
771 
772 template <class ELFT>
775  const Elf_Shdr *SymTab) const {
776  ArrayRef<Elf_Word> ShndxTable;
777  if (DotSymtabShndxSec) {
778  // TODO: Test this error.
779  Expected<ArrayRef<Elf_Word>> ShndxTableOrErr =
780  EF.getSHNDXTable(*DotSymtabShndxSec);
781  if (!ShndxTableOrErr)
782  return ShndxTableOrErr.takeError();
783  ShndxTable = *ShndxTableOrErr;
784  }
785 
786  auto ESecOrErr = EF.getSection(*ESym, SymTab, ShndxTable);
787  if (!ESecOrErr)
788  return ESecOrErr.takeError();
789 
790  const Elf_Shdr *ESec = *ESecOrErr;
791  if (!ESec)
792  return section_end();
793 
794  DataRefImpl Sec;
795  Sec.p = reinterpret_cast<intptr_t>(ESec);
796  return section_iterator(SectionRef(Sec, this));
797 }
798 
799 template <class ELFT>
802  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
803  if (!SymOrErr)
804  return SymOrErr.takeError();
805 
806  auto SymTabOrErr = EF.getSection(Symb.d.a);
807  if (!SymTabOrErr)
808  return SymTabOrErr.takeError();
809  return getSymbolSection(*SymOrErr, *SymTabOrErr);
810 }
811 
812 template <class ELFT>
814  const Elf_Shdr *ESec = getSection(Sec);
815  Sec = toDRI(++ESec);
816 }
817 
818 template <class ELFT>
820  return EF.getSectionName(*getSection(Sec));
821 }
822 
823 template <class ELFT>
825  return getSection(Sec)->sh_addr;
826 }
827 
828 template <class ELFT>
830  auto SectionsOrErr = EF.sections();
831  handleAllErrors(std::move(SectionsOrErr.takeError()),
832  [](const ErrorInfoBase &) {
833  llvm_unreachable("unable to get section index");
834  });
835  const Elf_Shdr *First = SectionsOrErr->begin();
836  return getSection(Sec) - First;
837 }
838 
839 template <class ELFT>
841  return getSection(Sec)->sh_size;
842 }
843 
844 template <class ELFT>
847  const Elf_Shdr *EShdr = getSection(Sec);
848  if (EShdr->sh_type == ELF::SHT_NOBITS)
849  return makeArrayRef((const uint8_t *)base(), 0);
850  if (Error E =
851  checkOffset(getMemoryBufferRef(),
852  (uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))
853  return std::move(E);
854  return makeArrayRef((const uint8_t *)base() + EShdr->sh_offset,
855  EShdr->sh_size);
856 }
857 
858 template <class ELFT>
860  return getSection(Sec)->sh_addralign;
861 }
862 
863 template <class ELFT>
865  return getSection(Sec)->sh_flags & ELF::SHF_COMPRESSED;
866 }
867 
868 template <class ELFT>
870  return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR;
871 }
872 
873 template <class ELFT>
875  const Elf_Shdr *EShdr = getSection(Sec);
876  return EShdr->sh_type == ELF::SHT_PROGBITS &&
877  EShdr->sh_flags & ELF::SHF_ALLOC &&
878  !(EShdr->sh_flags & ELF::SHF_EXECINSTR);
879 }
880 
881 template <class ELFT>
883  const Elf_Shdr *EShdr = getSection(Sec);
884  return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
885  EShdr->sh_type == ELF::SHT_NOBITS;
886 }
887 
888 template <class ELFT>
889 std::vector<SectionRef>
891  std::vector<SectionRef> Res;
892  std::vector<uintptr_t> Offsets;
893 
894  auto SectionsOrErr = EF.sections();
895  if (!SectionsOrErr)
896  return Res;
897 
898  for (const Elf_Shdr &Sec : *SectionsOrErr) {
899  if (Sec.sh_type != ELF::SHT_DYNAMIC)
900  continue;
901  Elf_Dyn *Dynamic =
902  reinterpret_cast<Elf_Dyn *>((uintptr_t)base() + Sec.sh_offset);
903  for (; Dynamic->d_tag != ELF::DT_NULL; Dynamic++) {
904  if (Dynamic->d_tag == ELF::DT_REL || Dynamic->d_tag == ELF::DT_RELA ||
905  Dynamic->d_tag == ELF::DT_JMPREL) {
906  Offsets.push_back(Dynamic->d_un.d_val);
907  }
908  }
909  }
910  for (const Elf_Shdr &Sec : *SectionsOrErr) {
911  if (is_contained(Offsets, Sec.sh_addr))
912  Res.emplace_back(toDRI(&Sec), this);
913  }
914  return Res;
915 }
916 
917 template <class ELFT>
919  return getSection(Sec)->sh_type == ELF::SHT_NOBITS;
920 }
921 
922 template <class ELFT>
924  return getSection(Sec)->sh_flags & ELF::SHF_ALLOC &&
925  (getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR ||
926  !(getSection(Sec)->sh_flags & ELF::SHF_WRITE));
927 }
928 
929 template <class ELFT>
931  const Elf_Shdr *EShdr = getSection(Sec);
932  return !isBerkeleyText(Sec) && EShdr->sh_type != ELF::SHT_NOBITS &&
933  EShdr->sh_flags & ELF::SHF_ALLOC;
934 }
935 
936 template <class ELFT>
938  Expected<StringRef> SectionNameOrErr = getSectionName(Sec);
939  if (!SectionNameOrErr) {
940  // TODO: Report the error message properly.
941  consumeError(SectionNameOrErr.takeError());
942  return false;
943  }
944  StringRef SectionName = SectionNameOrErr.get();
945  return SectionName.startswith(".debug") ||
946  SectionName.startswith(".zdebug") || SectionName == ".gdb_index";
947 }
948 
949 template <class ELFT>
952  DataRefImpl RelData;
953  auto SectionsOrErr = EF.sections();
954  if (!SectionsOrErr)
956  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
957  RelData.d.a = (Sec.p - SHT) / EF.getHeader().e_shentsize;
958  RelData.d.b = 0;
959  return relocation_iterator(RelocationRef(RelData, this));
960 }
961 
962 template <class ELFT>
965  const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p);
966  relocation_iterator Begin = section_rel_begin(Sec);
967  if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
968  return Begin;
969  DataRefImpl RelData = Begin->getRawDataRefImpl();
970  const Elf_Shdr *RelSec = getRelSection(RelData);
971 
972  // Error check sh_link here so that getRelocationSymbol can just use it.
973  auto SymSecOrErr = EF.getSection(RelSec->sh_link);
974  if (!SymSecOrErr)
976  Twine(errorToErrorCode(SymSecOrErr.takeError()).message()));
977 
978  RelData.d.b += S->sh_size / S->sh_entsize;
979  return relocation_iterator(RelocationRef(RelData, this));
980 }
981 
982 template <class ELFT>
985  const Elf_Shdr *EShdr = getSection(Sec);
986  uintX_t Type = EShdr->sh_type;
987  if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA)
988  return section_end();
989 
990  Expected<const Elf_Shdr *> SecOrErr = EF.getSection(EShdr->sh_info);
991  if (!SecOrErr)
992  return SecOrErr.takeError();
993  return section_iterator(SectionRef(toDRI(*SecOrErr), this));
994 }
995 
996 // Relocations
997 template <class ELFT>
999  ++Rel.d.b;
1000 }
1001 
1002 template <class ELFT>
1005  uint32_t symbolIdx;
1006  const Elf_Shdr *sec = getRelSection(Rel);
1007  if (sec->sh_type == ELF::SHT_REL)
1008  symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL());
1009  else
1010  symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL());
1011  if (!symbolIdx)
1012  return symbol_end();
1013 
1014  // FIXME: error check symbolIdx
1015  DataRefImpl SymbolData;
1016  SymbolData.d.a = sec->sh_link;
1017  SymbolData.d.b = symbolIdx;
1018  return symbol_iterator(SymbolRef(SymbolData, this));
1019 }
1020 
1021 template <class ELFT>
1023  const Elf_Shdr *sec = getRelSection(Rel);
1024  if (sec->sh_type == ELF::SHT_REL)
1025  return getRel(Rel)->r_offset;
1026 
1027  return getRela(Rel)->r_offset;
1028 }
1029 
1030 template <class ELFT>
1032  const Elf_Shdr *sec = getRelSection(Rel);
1033  if (sec->sh_type == ELF::SHT_REL)
1034  return getRel(Rel)->getType(EF.isMips64EL());
1035  else
1036  return getRela(Rel)->getType(EF.isMips64EL());
1037 }
1038 
1039 template <class ELFT>
1041  return getELFRelocationTypeName(EF.getHeader().e_machine, Type);
1042 }
1043 
1044 template <class ELFT>
1046  DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
1047  uint32_t type = getRelocationType(Rel);
1048  EF.getRelocationTypeName(type, Result);
1049 }
1050 
1051 template <class ELFT>
1054  if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
1055  return createError("Section is not SHT_RELA");
1056  return (int64_t)getRela(Rel)->r_addend;
1057 }
1058 
1059 template <class ELFT>
1060 const typename ELFObjectFile<ELFT>::Elf_Rel *
1062  assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
1063  auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
1064  if (!Ret)
1065  report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
1066  return *Ret;
1067 }
1068 
1069 template <class ELFT>
1070 const typename ELFObjectFile<ELFT>::Elf_Rela *
1072  assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
1073  auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
1074  if (!Ret)
1075  report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
1076  return *Ret;
1077 }
1078 
1079 template <class ELFT>
1082  auto EFOrErr = ELFFile<ELFT>::create(Object.getBuffer());
1083  if (Error E = EFOrErr.takeError())
1084  return std::move(E);
1085 
1086  ELFObjectFile<ELFT> Obj = {Object, std::move(*EFOrErr), nullptr, nullptr,
1087  nullptr};
1088  if (InitContent)
1089  if (Error E = Obj.initContent())
1090  return std::move(E);
1091  return std::move(Obj);
1092 }
1093 
1094 template <class ELFT>
1096  const Elf_Shdr *DotDynSymSec,
1097  const Elf_Shdr *DotSymtabSec,
1098  const Elf_Shdr *DotSymtabShndx)
1100  getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits),
1101  Object),
1102  EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec),
1103  DotSymtabShndxSec(DotSymtabShndx) {}
1104 
1105 template <class ELFT>
1107  : ELFObjectFile(Other.Data, Other.EF, Other.DotDynSymSec,
1108  Other.DotSymtabSec, Other.DotSymtabShndxSec) {}
1109 
1110 template <class ELFT>
1112  DataRefImpl Sym =
1113  toDRI(DotSymtabSec,
1114  DotSymtabSec && DotSymtabSec->sh_size >= sizeof(Elf_Sym) ? 1 : 0);
1115  return basic_symbol_iterator(SymbolRef(Sym, this));
1116 }
1117 
1118 template <class ELFT>
1120  const Elf_Shdr *SymTab = DotSymtabSec;
1121  if (!SymTab)
1122  return symbol_begin();
1123  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
1124  return basic_symbol_iterator(SymbolRef(Sym, this));
1125 }
1126 
1127 template <class ELFT>
1129  if (!DotDynSymSec || DotDynSymSec->sh_size < sizeof(Elf_Sym))
1130  // Ignore errors here where the dynsym is empty or sh_size less than the
1131  // size of one symbol. These should be handled elsewhere.
1132  return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 0), this));
1133  // Skip 0-index NULL symbol.
1134  return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 1), this));
1135 }
1136 
1137 template <class ELFT>
1139  const Elf_Shdr *SymTab = DotDynSymSec;
1140  if (!SymTab)
1141  return dynamic_symbol_begin();
1142  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
1143  return basic_symbol_iterator(SymbolRef(Sym, this));
1144 }
1145 
1146 template <class ELFT>
1148  auto SectionsOrErr = EF.sections();
1149  if (!SectionsOrErr)
1150  return section_iterator(SectionRef());
1151  return section_iterator(SectionRef(toDRI((*SectionsOrErr).begin()), this));
1152 }
1153 
1154 template <class ELFT>
1156  auto SectionsOrErr = EF.sections();
1157  if (!SectionsOrErr)
1158  return section_iterator(SectionRef());
1159  return section_iterator(SectionRef(toDRI((*SectionsOrErr).end()), this));
1160 }
1161 
1162 template <class ELFT>
1164  return ELFT::Is64Bits ? 8 : 4;
1165 }
1166 
1167 template <class ELFT>
1169  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1170  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1171  case ELF::ELFCLASS32:
1172  switch (EF.getHeader().e_machine) {
1173  case ELF::EM_68K:
1174  return "elf32-m68k";
1175  case ELF::EM_386:
1176  return "elf32-i386";
1177  case ELF::EM_IAMCU:
1178  return "elf32-iamcu";
1179  case ELF::EM_X86_64:
1180  return "elf32-x86-64";
1181  case ELF::EM_ARM:
1182  return (IsLittleEndian ? "elf32-littlearm" : "elf32-bigarm");
1183  case ELF::EM_AVR:
1184  return "elf32-avr";
1185  case ELF::EM_HEXAGON:
1186  return "elf32-hexagon";
1187  case ELF::EM_LANAI:
1188  return "elf32-lanai";
1189  case ELF::EM_MIPS:
1190  return "elf32-mips";
1191  case ELF::EM_MSP430:
1192  return "elf32-msp430";
1193  case ELF::EM_PPC:
1194  return (IsLittleEndian ? "elf32-powerpcle" : "elf32-powerpc");
1195  case ELF::EM_RISCV:
1196  return "elf32-littleriscv";
1197  case ELF::EM_CSKY:
1198  return "elf32-csky";
1199  case ELF::EM_SPARC:
1200  case ELF::EM_SPARC32PLUS:
1201  return "elf32-sparc";
1202  case ELF::EM_AMDGPU:
1203  return "elf32-amdgpu";
1204  default:
1205  return "elf32-unknown";
1206  }
1207  case ELF::ELFCLASS64:
1208  switch (EF.getHeader().e_machine) {
1209  case ELF::EM_386:
1210  return "elf64-i386";
1211  case ELF::EM_X86_64:
1212  return "elf64-x86-64";
1213  case ELF::EM_AARCH64:
1214  return (IsLittleEndian ? "elf64-littleaarch64" : "elf64-bigaarch64");
1215  case ELF::EM_PPC64:
1216  return (IsLittleEndian ? "elf64-powerpcle" : "elf64-powerpc");
1217  case ELF::EM_RISCV:
1218  return "elf64-littleriscv";
1219  case ELF::EM_S390:
1220  return "elf64-s390";
1221  case ELF::EM_SPARCV9:
1222  return "elf64-sparc";
1223  case ELF::EM_MIPS:
1224  return "elf64-mips";
1225  case ELF::EM_AMDGPU:
1226  return "elf64-amdgpu";
1227  case ELF::EM_BPF:
1228  return "elf64-bpf";
1229  case ELF::EM_VE:
1230  return "elf64-ve";
1231  default:
1232  return "elf64-unknown";
1233  }
1234  default:
1235  // FIXME: Proper error handling.
1236  report_fatal_error("Invalid ELFCLASS!");
1237  }
1238 }
1239 
1240 template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
1241  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1242  switch (EF.getHeader().e_machine) {
1243  case ELF::EM_68K:
1244  return Triple::m68k;
1245  case ELF::EM_386:
1246  case ELF::EM_IAMCU:
1247  return Triple::x86;
1248  case ELF::EM_X86_64:
1249  return Triple::x86_64;
1250  case ELF::EM_AARCH64:
1251  return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be;
1252  case ELF::EM_ARM:
1253  return Triple::arm;
1254  case ELF::EM_AVR:
1255  return Triple::avr;
1256  case ELF::EM_HEXAGON:
1257  return Triple::hexagon;
1258  case ELF::EM_LANAI:
1259  return Triple::lanai;
1260  case ELF::EM_MIPS:
1261  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1262  case ELF::ELFCLASS32:
1263  return IsLittleEndian ? Triple::mipsel : Triple::mips;
1264  case ELF::ELFCLASS64:
1265  return IsLittleEndian ? Triple::mips64el : Triple::mips64;
1266  default:
1267  report_fatal_error("Invalid ELFCLASS!");
1268  }
1269  case ELF::EM_MSP430:
1270  return Triple::msp430;
1271  case ELF::EM_PPC:
1272  return IsLittleEndian ? Triple::ppcle : Triple::ppc;
1273  case ELF::EM_PPC64:
1274  return IsLittleEndian ? Triple::ppc64le : Triple::ppc64;
1275  case ELF::EM_RISCV:
1276  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1277  case ELF::ELFCLASS32:
1278  return Triple::riscv32;
1279  case ELF::ELFCLASS64:
1280  return Triple::riscv64;
1281  default:
1282  report_fatal_error("Invalid ELFCLASS!");
1283  }
1284  case ELF::EM_S390:
1285  return Triple::systemz;
1286 
1287  case ELF::EM_SPARC:
1288  case ELF::EM_SPARC32PLUS:
1289  return IsLittleEndian ? Triple::sparcel : Triple::sparc;
1290  case ELF::EM_SPARCV9:
1291  return Triple::sparcv9;
1292 
1293  case ELF::EM_AMDGPU: {
1294  if (!IsLittleEndian)
1295  return Triple::UnknownArch;
1296 
1297  unsigned MACH = EF.getHeader().e_flags & ELF::EF_AMDGPU_MACH;
1298  if (MACH >= ELF::EF_AMDGPU_MACH_R600_FIRST &&
1300  return Triple::r600;
1301  if (MACH >= ELF::EF_AMDGPU_MACH_AMDGCN_FIRST &&
1303  return Triple::amdgcn;
1304 
1305  return Triple::UnknownArch;
1306  }
1307 
1308  case ELF::EM_BPF:
1309  return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
1310 
1311  case ELF::EM_VE:
1312  return Triple::ve;
1313  case ELF::EM_CSKY:
1314  return Triple::csky;
1315  default:
1316  return Triple::UnknownArch;
1317  }
1318 }
1319 
1320 template <class ELFT>
1322  return EF.getHeader().e_entry;
1323 }
1324 
1325 template <class ELFT>
1328  return make_range(dynamic_symbol_begin(), dynamic_symbol_end());
1329 }
1330 
1331 template <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const {
1332  return EF.getHeader().e_type == ELF::ET_REL;
1333 }
1334 
1335 } // end namespace object
1336 } // end namespace llvm
1337 
1338 #endif // LLVM_OBJECT_ELFOBJECTFILE_H
llvm::ELF::EM_S390
@ EM_S390
Definition: ELF.h:151
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:130
llvm::object::ELFSectionRef::getObject
const ELFObjectFileBase * getObject() const
Definition: ELFObjectFile.h:111
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::ELF::EM_SPARC
@ EM_SPARC
Definition: ELF.h:136
llvm::ELF::SHT_RELA
@ SHT_RELA
Definition: ELF.h:924
llvm::object::ELFObjectFile::DotDynSymSec
const Elf_Shdr * DotDynSymSec
Definition: ELFObjectFile.h:260
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::object::ELFObjectFile::getSectionName
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:819
llvm::object::ELFObjectFile::isDebugSection
bool isDebugSection(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:937
llvm::object::ELFObjectFile::toSymbolRef
ELFSymbolRef toSymbolRef(const Elf_Shdr *SymTable, unsigned SymbolNum) const
Definition: ELFObjectFile.h:244
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:57
llvm::object::ELFObjectFile::getRelocationAddend
Expected< int64_t > getRelocationAddend(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1053
llvm::object::DataRefImpl::a
uint32_t a
Definition: SymbolicFile.h:37
llvm::Triple::UnknownArch
@ UnknownArch
Definition: Triple.h:47
llvm::object::ELFObjectFile::getSymbolELFType
uint8_t getSymbolELFType(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:653
intptr_t
llvm::object::ELFObjectFile::getRelSection
const Elf_Shdr * getRelSection(DataRefImpl Rel) const
Get the relocation section that contains Rel.
Definition: ELFObjectFile.h:411
llvm::object::ELFSymbolRef::getELFTypeName
StringRef getELFTypeName() const
Definition: ELFObjectFile.h:169
llvm::object::ELFSectionRef::getType
uint32_t getType() const
Definition: ELFObjectFile.h:115
llvm::ELF::EM_ARM
@ EM_ARM
Definition: ELF.h:157
llvm::ELF::STB_GNU_UNIQUE
@ STB_GNU_UNIQUE
Definition: ELF.h:1152
llvm::ELF::EF_AMDGPU_MACH_R600_LAST
@ EF_AMDGPU_MACH_R600_LAST
Definition: ELF.h:721
llvm::ELF::ELFCLASS32
@ ELFCLASS32
Definition: ELF.h:328
llvm::object::ELFObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition: ELFObjectFile.h:1111
llvm::object::ELFObjectFile::isSectionText
bool isSectionText(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:869
StringRef.h
llvm::object::BasicSymbolRef::SF_Common
@ SF_Common
Definition: SymbolicFile.h:112
llvm::Triple::x86
@ x86
Definition: Triple.h:82
llvm::ELF::EM_AARCH64
@ EM_AARCH64
Definition: ELF.h:281
llvm::object::ELFObjectFileBase::getPltAddresses
std::vector< std::pair< Optional< DataRefImpl >, uint64_t > > getPltAddresses() const
Definition: ELFObjectFile.cpp:584
llvm::object::ELFObjectFile::getRelocationTypeName
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
Definition: ELFObjectFile.h:1045
llvm::object::ELFObjectFileBase::readDynsymVersions
Expected< std::vector< VersionEntry > > readDynsymVersions() const
Returns a vector containing a symbol version for each dynamic symbol.
Definition: ELFObjectFile.cpp:715
llvm::Triple::amdgcn
@ amdgcn
Definition: Triple.h:71
llvm::ELF::EM_RISCV
@ EM_RISCV
Definition: ELF.h:318
llvm::ELF::EM_PPC64
@ EM_PPC64
Definition: ELF.h:150
llvm::object::ELFObjectFile::DotSymtabSec
const Elf_Shdr * DotSymtabSec
Definition: ELFObjectFile.h:261
llvm::object::ELFObjectFileBase::getBuildAttributes
virtual Error getBuildAttributes(ELFAttributeParser &Attributes) const =0
llvm::object::SectionRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition: ObjectFile.h:525
ErrorHandling.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::object::ELFObjectFile::EF
ELFFile< ELFT > EF
Definition: ELFObjectFile.h:258
llvm::object::ELFObjectFileBase::getEMachine
virtual uint16_t getEMachine() const =0
Error.h
llvm::object::ELFObjectFile::getBuildAttributes
Error getBuildAttributes(ELFAttributeParser &Attributes) const override
Definition: ELFObjectFile.h:369
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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:138
llvm::object::BasicSymbolRef::SF_Exported
@ SF_Exported
Definition: SymbolicFile.h:114
llvm::object::relocation_iterator
content_iterator< RelocationRef > relocation_iterator
Definition: ObjectFile.h:75
llvm::object::getSection
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: ELF.h:401
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
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:213
llvm::object::ELFObjectFile::DotSymtabShndxSec
const Elf_Shdr * DotSymtabShndxSec
Definition: ELFObjectFile.h:262
llvm::object::SymbolRef::ST_Unknown
@ ST_Unknown
Definition: ObjectFile.h:171
llvm::object::getObject
static Expected< const T * > getObject(MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
Definition: XCOFFObjectFile.cpp:33
llvm::Triple::ppc
@ ppc
Definition: Triple.h:66
llvm::object::elf_symbol_iterator::operator*
const ELFSymbolRef & operator*() const
Definition: ELFObjectFile.h:190
llvm::Optional
Definition: APInt.h:33
llvm::object::ELFObjectFileBase::ELFSymbolRef
friend class ELFSymbolRef
Definition: ELFObjectFile.h:52
llvm::Triple::hexagon
@ hexagon
Definition: Triple.h:59
llvm::object::elf_relocation_iterator::operator->
const ELFRelocationRef * operator->() const
Definition: ELFObjectFile.h:216
llvm::object::ELFSectionRef
Definition: ELFObjectFile.h:105
llvm::ELF::EF_AMDGPU_MACH_R600_FIRST
@ EF_AMDGPU_MACH_R600_FIRST
Definition: ELF.h:720
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::ELF::EM_CSKY
@ EM_CSKY
Definition: ELF.h:322
llvm::object::SymbolRef::ST_Data
@ ST_Data
Definition: ObjectFile.h:172
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:930
STLExtras.h
llvm::object::SymbolRef::ST_File
@ ST_File
Definition: ObjectFile.h:174
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition: SymbolicFile.h:110
SymbolicFile.h
llvm::Triple::avr
@ avr
Definition: Triple.h:55
llvm::object::ELFObjectFile::dynamic_symbol_begin
elf_symbol_iterator dynamic_symbol_begin() const
Definition: ELFObjectFile.h:1128
llvm::Triple::mips64
@ mips64
Definition: Triple.h:63
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1045
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition: ELF.h:1002
llvm::object::ELFObjectFile::getDynamicSymbolIterators
elf_symbol_iterator_range getDynamicSymbolIterators() const override
Definition: ELFObjectFile.h:1327
llvm::ELF::STT_TLS
@ STT_TLS
Definition: ELF.h:1167
llvm::EnumEntry
Definition: ScopedPrinter.h:25
llvm::ELF::EM_HEXAGON
@ EM_HEXAGON
Definition: ELF.h:258
llvm::object::ELFObjectFile::toDRI
DataRefImpl toDRI(const Elf_Dyn *Dyn) const
Definition: ELFObjectFile.h:350
llvm::object::ELFSymbolRef::getSize
uint64_t getSize() const
Definition: ELFObjectFile.h:153
llvm::object::ELFObjectFile::getRela
const Elf_Rela * getRela(DataRefImpl Rela) const
Definition: ELFObjectFile.h:1071
llvm::object::ELFObjectFileBase
Definition: ELFObjectFile.h:49
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
llvm::object::SymbolicFile::symbol_end
virtual basic_symbol_iterator symbol_end() const =0
llvm::ELF::SHT_SYMTAB
@ SHT_SYMTAB
Definition: ELF.h:922
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:161
llvm::object::ELFRelocationRef
Definition: ELFObjectFile.h:195
Error.h
llvm::Triple::sparcv9
@ sparcv9
Definition: Triple.h:75
SubtargetFeature.h
llvm::Triple::sparcel
@ sparcel
Definition: Triple.h:76
ELF.h
llvm::object::symbol_iterator::operator*
const SymbolRef & operator*() const
Definition: ObjectFile.h:218
llvm::Triple::ArchType
ArchType
Definition: Triple.h:46
llvm::object::ELFObjectFile::initContent
Error initContent() override
Definition: ELFObjectFile.h:464
llvm::object::ELFSymbolRef::getObject
const ELFObjectFileBase * getObject() const
Definition: ELFObjectFile.h:149
llvm::object::BasicSymbolRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition: SymbolicFile.h:206
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:460
llvm::ELF::SHT_DYNSYM
@ SHT_DYNSYM
Definition: ELF.h:931
llvm::Triple::mips64el
@ mips64el
Definition: Triple.h:64
llvm::object::ELFObjectFile::getSectionAlignment
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:859
llvm::object::ELFObjectFile::getELFFile
const ELFFile< ELFT > & getELFFile() const
Definition: ELFObjectFile.h:441
llvm::ELF::EM_MIPS
@ EM_MIPS
Definition: ELF.h:142
llvm::ELF::STB_WEAK
@ STB_WEAK
Definition: ELF.h:1151
llvm::SubtargetFeatures
Manages the enabling and disabling of subtarget specific features.
Definition: SubtargetFeature.h:183
llvm::ELF::SHT_SYMTAB_SHNDX
@ SHT_SYMTAB_SHNDX
Definition: ELF.h:936
llvm::ELF::STV_DEFAULT
@ STV_DEFAULT
Definition: ELF.h:1179
llvm::object::elf_section_iterator
Definition: ELFObjectFile.h:128
llvm::object::ELFSectionRef::getFlags
uint64_t getFlags() const
Definition: ELFObjectFile.h:119
llvm::object::content_iterator::operator*
const content_type & operator*() const
Definition: SymbolicFile.h:81
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:951
llvm::ELF::STT_FILE
@ STT_FILE
Definition: ELF.h:1165
llvm::object::ELFObjectFile::isDyldELFObject
bool isDyldELFObject
Definition: ELFObjectFile.h:396
llvm::Triple::r600
@ r600
Definition: Triple.h:70
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
llvm::object::ELFObjectFile::getSymbolAlignment
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:605
llvm::ELF::EF_AMDGPU_MACH_AMDGCN_FIRST
@ EF_AMDGPU_MACH_AMDGCN_FIRST
Definition: ELF.h:764
llvm::object::ELFObjectFileBase::getRelocationAddend
virtual Expected< int64_t > getRelocationAddend(DataRefImpl Rel) const =0
llvm::Triple::m68k
@ m68k
Definition: Triple.h:60
llvm::ELF::EM_VE
@ EM_VE
Definition: ELF.h:321
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::EM_68K
@ EM_68K
Definition: ELF.h:138
llvm::object::ELFObjectFile::isBerkeleyText
bool isBerkeleyText(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:923
llvm::Triple::lanai
@ lanai
Definition: Triple.h:99
llvm::object::ELFObjectFile::create
static Expected< ELFObjectFile< ELFT > > create(MemoryBufferRef Object, bool InitContent=true)
Definition: ELFObjectFile.h:1081
llvm::ELF::STB_GLOBAL
@ STB_GLOBAL
Definition: ELF.h:1150
llvm::object::SymbolRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:416
llvm::object::ELFObjectFile::getSymbolValueImpl
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:539
llvm::Triple::csky
@ csky
Definition: Triple.h:58
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:637
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:563
llvm::ELF::STT_FUNC
@ STT_FUNC
Definition: ELF.h:1163
llvm::ELF::SHT_DYNAMIC
@ SHT_DYNAMIC
Definition: ELF.h:926
llvm::ELF::STB_LOCAL
@ STB_LOCAL
Definition: ELF.h:1149
ELFAttributes.h
llvm::object::BasicSymbolRef::getObject
const SymbolicFile * getObject() const
Definition: SymbolicFile.h:210
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:79
llvm::object::ELFObjectFile::getSectionContents
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:846
llvm::object::ELFSectionRef::getOffset
uint64_t getOffset() const
Definition: ELFObjectFile.h:123
llvm::Triple::ppc64le
@ ppc64le
Definition: Triple.h:69
llvm::object::ElfSymbolTypes
const llvm::EnumEntry< unsigned > ElfSymbolTypes[NumElfSymbolTypes]
Definition: ELFObjectFile.cpp:40
llvm::ELF::EM_PPC
@ EM_PPC
Definition: ELF.h:149
llvm::object::ELFObjectFile::section_rel_end
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:964
llvm::ELF::EM_SPARC32PLUS
@ EM_SPARC32PLUS
Definition: ELF.h:147
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:115
llvm::ELF::ELFCLASS64
@ ELFCLASS64
Definition: ELF.h:329
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::object::ELFObjectFile::section_begin
section_iterator section_begin() const override
Definition: ELFObjectFile.h:1147
uint64_t
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:829
llvm::ELF::SHT_ARM_ATTRIBUTES
@ SHT_ARM_ATTRIBUTES
Definition: ELF.h:972
llvm::object::symbol_iterator
Definition: ObjectFile.h:206
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:419
llvm::object::SymbolRef::ST_Function
@ ST_Function
Definition: ObjectFile.h:175
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:921
llvm::ELF::SHT_REL
@ SHT_REL
Definition: ELF.h:929
llvm::ELF::SHT_RISCV_ATTRIBUTES
@ SHT_RISCV_ATTRIBUTES
Definition: ELF.h:986
llvm::object::ELFRelocationRef::ELFRelocationRef
ELFRelocationRef(const RelocationRef &B)
Definition: ELFObjectFile.h:197
llvm::object::ELFObjectFile::getFileFormatName
StringRef getFileFormatName() const override
Definition: ELFObjectFile.h:1168
llvm::object::elf_symbol_iterator::operator->
const ELFSymbolRef * operator->() const
Definition: ELFObjectFile.h:186
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::ELF::EI_CLASS
@ EI_CLASS
Definition: ELF.h:53
llvm::object::BasicSymbolRef::SF_None
@ SF_None
Definition: SymbolicFile.h:107
llvm::ELF::STT_COMMON
@ STT_COMMON
Definition: ELF.h:1166
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:999
llvm::object::ObjectFile::SectionRef
friend class SectionRef
Definition: ObjectFile.h:259
llvm::object::ELFObjectFile::classof
static bool classof(const Binary *v)
Definition: ELFObjectFile.h:444
llvm::object::ELFRelocationRef::getObject
const ELFObjectFileBase * getObject() const
Definition: ELFObjectFile.h:201
llvm::ELF::STV_PROTECTED
@ STV_PROTECTED
Definition: ELF.h:1182
llvm::object::BasicSymbolRef::SF_Undefined
@ SF_Undefined
Definition: SymbolicFile.h:108
llvm::object::ELFObjectFile::getSectionAddress
uint64_t getSectionAddress(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:824
Attributes
AMDGPU Kernel Attributes
Definition: AMDGPULowerKernelAttributes.cpp:254
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:1714
llvm::ELF::SHN_UNDEF
@ SHN_UNDEF
Definition: ELF.h:906
ArrayRef.h
llvm::object::ELFObjectFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:686
llvm::object::BasicSymbolRef::SF_Thumb
@ SF_Thumb
Definition: SymbolicFile.h:117
llvm::ELF::EM_LANAI
@ EM_LANAI
Definition: ELF.h:319
llvm::object::ELFSymbolRef
Definition: ELFObjectFile.h:143
llvm::object::SymbolRef::ST_Debug
@ ST_Debug
Definition: ObjectFile.h:173
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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::EM_BPF
@ EM_BPF
Definition: ELF.h:320
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:67
llvm::object::ELFSymbolRef::getBinding
uint8_t getBinding() const
Definition: ELFObjectFile.h:157
llvm::Triple::bpfel
@ bpfel
Definition: Triple.h:56
llvm::object::content_iterator::operator->
const content_type * operator->() const
Definition: SymbolicFile.h:79
ELFTypes.h
iterator_range.h
llvm::ELF::EM_AMDGPU
@ EM_AMDGPU
Definition: ELF.h:317
llvm::object::ELFObjectFileBase::getSymbolSize
virtual uint64_t getSymbolSize(DataRefImpl Symb) const =0
llvm::ELF::EM_MSP430
@ EM_MSP430
Definition: ELF.h:223
llvm::object::ELFObjectFile::dynamic_symbol_end
elf_symbol_iterator dynamic_symbol_end() const
Definition: ELFObjectFile.h:1138
llvm::object::ELFObjectFile::getRelocatedSection
Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:984
llvm::object::elf_relocation_iterator
Definition: ELFObjectFile.h:210
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:774
llvm::object::ELFObjectFile::getSymbolOther
uint8_t getSymbolOther(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:645
llvm::Sched::Source
@ Source
Definition: TargetLowering.h:99
llvm::ELF::STT_OBJECT
@ STT_OBJECT
Definition: ELF.h:1162
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::Triple::arm
@ arm
Definition: Triple.h:49
llvm::object::section_iterator
content_iterator< SectionRef > section_iterator
Definition: ObjectFile.h:46
llvm::object::ELFObjectFile::isRelocatableObject
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
Definition: ELFObjectFile.h:1331
llvm::object::ELFObjectFile::IsContentValid
bool IsContentValid() const
Definition: ELFObjectFile.h:248
llvm::object::ELFObjectFileBase::symbols
elf_symbol_iterator_range symbols() const
Definition: ELFObjectFile.h:228
llvm::object::elf_symbol_iterator::elf_symbol_iterator
elf_symbol_iterator(const basic_symbol_iterator &B)
Definition: ELFObjectFile.h:182
llvm::Triple::aarch64_be
@ aarch64_be
Definition: Triple.h:52
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:227
llvm::object::Binary
Definition: Binary.h:32
llvm::Triple::ppcle
@ ppcle
Definition: Triple.h:67
llvm::ELF::SHN_ABS
@ SHN_ABS
Definition: ELF.h:912
llvm::ELF::STV_HIDDEN
@ STV_HIDDEN
Definition: ELF.h:1181
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:569
llvm::RoundingMode::Dynamic
@ Dynamic
Denotes mode unknown at compile time.
uint32_t
llvm::object::RelocationRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:567
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:439
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:1163
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::object::ELFObjectFile::getCommonSymbolSizeImpl
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:632
llvm::Triple::ve
@ ve
Definition: Triple.h:104
llvm::object::ELFObjectFile::dynamic_relocation_sections
std::vector< SectionRef > dynamic_relocation_sections() const override
Definition: ELFObjectFile.h:890
LLVM_ELF_IMPORT_TYPES_ELFT
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Definition: ELFTypes.h:104
llvm::object::ELFObjectFile::getSymbolType
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:662
llvm::object::ELFObjectFile::toELFShdrIter
const Elf_Shdr * toELFShdrIter(DataRefImpl Sec) const
Definition: ELFObjectFile.h:340
llvm::object::ELFObjectFile::getRel
const Elf_Rel * getRel(DataRefImpl Rel) const
Definition: ELFObjectFile.h:1061
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::object::ELFObjectFile::getRelocationSymbol
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1004
llvm::object::ELFObjectFile::isExportedToOtherDSO
bool isExportedToOtherDSO(const Elf_Sym *ESym) const
Definition: ELFObjectFile.h:356
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::object::SymbolRef::Type
Type
Definition: ObjectFile.h:170
llvm::object::ELFObjectFile::getRelocationType
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1031
llvm::ELF::EF_AMDGPU_MACH
@ EF_AMDGPU_MACH
Definition: ELF.h:687
uint16_t
llvm::object::ELFObjectFile::toDRI
DataRefImpl toDRI(const Elf_Shdr *SymTable, unsigned SymbolNum) const
Definition: ELFObjectFile.h:315
llvm::object::ELFObjectFileBase::setARMSubArch
void setARMSubArch(Triple &TheTriple) const override
Definition: ELFObjectFile.cpp:492
llvm::object::ELFObjectFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition: ELFObjectFile.h:1119
llvm::SectionName
Definition: DWARFSection.h:21
llvm::ELF::EF_AMDGPU_MACH_AMDGCN_LAST
@ EF_AMDGPU_MACH_AMDGCN_LAST
Definition: ELF.h:765
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::Triple::riscv32
@ riscv32
Definition: Triple.h:72
Casting.h
llvm::Triple::mipsel
@ mipsel
Definition: Triple.h:62
llvm::object::BasicSymbolRef::SF_Absolute
@ SF_Absolute
Definition: SymbolicFile.h:111
llvm::object::ELFObjectFileBase::getEType
virtual uint16_t getEType() const =0
llvm::object::ELFObjectFile::isSectionCompressed
bool isSectionCompressed(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:864
llvm::object::ELFFile::create
static Expected< ELFFile > create(StringRef Object)
Definition: ELF.h:752
llvm::Triple::systemz
@ systemz
Definition: Triple.h:77
llvm::object::SymbolRef::ST_Other
@ ST_Other
Definition: ObjectFile.h:176
llvm::ELF::STT_SECTION
@ STT_SECTION
Definition: ELF.h:1164
llvm::object::ELFObjectFile::isSectionData
bool isSectionData(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:874
llvm::object::ELFObjectFile::section_end
section_iterator section_end() const override
Definition: ELFObjectFile.h:1155
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:96
llvm::object::ELFObjectFile::toDRI
DataRefImpl toDRI(const Elf_Shdr *Sec) const
Definition: ELFObjectFile.h:344
llvm::object::ELFObjectFile::toSectionRef
SectionRef toSectionRef(const Elf_Shdr *Sec) const
Definition: ELFObjectFile.h:240
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:599
llvm::object::ELFObjectFile::getRelocationOffset
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1022
llvm::ELF::SHN_COMMON
@ SHN_COMMON
Definition: ELF.h:913
llvm::object::ELFObjectFileBase::getSymbolBinding
virtual uint8_t getSymbolBinding(DataRefImpl Symb) const =0
Binary.h
llvm::object::ELFObjectFile::getSectionOffset
uint64_t getSectionOffset(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:534
SmallVector.h
llvm::object::ELFObjectFile::getSectionType
uint32_t getSectionType(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:529
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition: SymbolicFile.h:109
llvm::object::BasicSymbolRef::SF_Hidden
@ SF_Hidden
Definition: SymbolicFile.h:118
llvm::object::ELFSymbolRef::ELFSymbolRef
ELFSymbolRef(const SymbolRef &B)
Definition: ELFObjectFile.h:145
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::object::ELFObjectFile::getSymbolName
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:494
llvm::object::ELFSymbolRef::getELFType
uint8_t getELFType() const
Definition: ELFObjectFile.h:165
getSymbolValue
static uint64_t getSymbolValue(const MCSymbol &Symbol, const MCAsmLayout &Layout)
Definition: WinCOFFObjectWriter.cpp:359
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::ELF::EM_X86_64
@ EM_X86_64
Definition: ELF.h:179
llvm::object::elf_symbol_iterator
Definition: ELFObjectFile.h:180
llvm::ELF::EM_AVR
@ EM_AVR
Definition: ELF.h:200
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:166
llvm::object::ELFObjectFile::moveRelocationNext
void moveRelocationNext(DataRefImpl &Rel) const override
Definition: ELFObjectFile.h:998
llvm::object::DataRefImpl::d
struct llvm::object::DataRefImpl::@326 d
llvm::object::createError
Error createError(const Twine &Err)
Definition: Error.h:83
llvm::object::elf_relocation_iterator::elf_relocation_iterator
elf_relocation_iterator(const relocation_iterator &B)
Definition: ELFObjectFile.h:212
llvm::ELF::EM_IAMCU
@ EM_IAMCU
Definition: ELF.h:140
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition: ELF.h:996
llvm::object::ELFObjectFile::isDyldType
bool isDyldType() const
Definition: ELFObjectFile.h:443
llvm::ELF::SHF_COMPRESSED
@ SHF_COMPRESSED
Definition: ELF.h:1027
llvm::object::DataRefImpl::b
uint32_t b
Definition: SymbolicFile.h:37
llvm::ELF::ET_REL
@ ET_REL
Definition: ELF.h:117
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:50
llvm::object::ELFObjectFile::isSectionBSS
bool isSectionBSS(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:882
llvm::object::ELFObjectFile::isSectionVirtual
bool isSectionVirtual(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:918
llvm::object::ELFRelocationRef::getAddend
Expected< int64_t > getAddend() const
Definition: ELFObjectFile.h:205
llvm::object::ELFObjectFileBase::getSymbolOther
virtual uint8_t getSymbolOther(DataRefImpl Symb) const =0
llvm::SI::KernelInputOffsets::Offsets
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:1260
llvm::object::ELFSectionRef::ELFSectionRef
ELFSectionRef(const SectionRef &B)
Definition: ELFObjectFile.h:107
llvm::ELF::STT_NOTYPE
@ STT_NOTYPE
Definition: ELF.h:1161
llvm::object::ELFObjectFile::moveSectionNext
void moveSectionNext(DataRefImpl &Sec) const override
Definition: ELFObjectFile.h:813
getSymbolName
static StringRef getSymbolName(SymbolKind SymKind)
Definition: CodeViewDebug.cpp:3114
llvm::object::ELFObjectFileBase::getSymbolELFType
virtual uint8_t getSymbolELFType(DataRefImpl Symb) const =0
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:928
llvm::object::ELFObjectFileBase::tryGetCPUName
Optional< StringRef > tryGetCPUName() const override
Definition: ELFObjectFile.cpp:359
Endian.h
llvm::object::ELFObjectFile::getSectionFlags
uint64_t getSectionFlags(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:524
llvm::ELF::EM_386
@ EM_386
Definition: ELF.h:137
llvm::ELF::EM_SPARCV9
@ EM_SPARCV9
Definition: ELF.h:160
llvm::object::ELFObjectFile
Definition: ELFObjectFile.h:232
llvm::object::SectionRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:529
llvm::object::ELFObjectFile::getArch
Triple::ArchType getArch() const override
Definition: ELFObjectFile.h:1240
llvm::object::ELFObjectFile::getSymbol
Expected< const Elf_Sym * > getSymbol(DataRefImpl Sym) const
Definition: ELFObjectFile.h:406
llvm::object::ELFObjectFile::getStartAddress
Expected< uint64_t > getStartAddress() const override
Definition: ELFObjectFile.h:1321
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:968
llvm::object::basic_symbol_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
Definition: SymbolicFile.h:141
llvm::object::ELFFile
Definition: ELF.h:94
llvm::Triple::mips
@ mips
Definition: Triple.h:61
llvm::object::elf_relocation_iterator::operator*
const ELFRelocationRef & operator*() const
Definition: ELFObjectFile.h:221
llvm::object::elf_section_iterator::operator->
const ELFSectionRef * operator->() const
Definition: ELFObjectFile.h:134
llvm::object::ELFObjectFileBase::ELFObjectFileBase
ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
Definition: ELFObjectFile.cpp:59
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:51
llvm::object::ELFObjectFile::getSymbolAddress
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:559
llvm::object::ELFObjectFile::getSectionSize
uint64_t getSectionSize(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:840
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1198