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  if (Name.startswith("$d") || Name.startswith("$t") ||
737  Name.startswith("$a"))
739  } else {
740  // TODO: Actually report errors helpfully.
741  consumeError(NameOrErr.takeError());
742  }
743  if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
744  Result |= SymbolRef::SF_Thumb;
745  } else if (EF.getHeader().e_machine == ELF::EM_RISCV) {
746  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
747  // Mark empty name symbols used for label differences.
748  if (NameOrErr->empty())
750  } else {
751  // TODO: Actually report errors helpfully.
752  consumeError(NameOrErr.takeError());
753  }
754  }
755 
756  if (ESym->st_shndx == ELF::SHN_UNDEF)
757  Result |= SymbolRef::SF_Undefined;
758 
759  if (ESym->getType() == ELF::STT_COMMON || ESym->st_shndx == ELF::SHN_COMMON)
760  Result |= SymbolRef::SF_Common;
761 
762  if (isExportedToOtherDSO(ESym))
763  Result |= SymbolRef::SF_Exported;
764 
765  if (ESym->getVisibility() == ELF::STV_HIDDEN)
766  Result |= SymbolRef::SF_Hidden;
767 
768  return Result;
769 }
770 
771 template <class ELFT>
774  const Elf_Shdr *SymTab) const {
775  ArrayRef<Elf_Word> ShndxTable;
776  if (DotSymtabShndxSec) {
777  // TODO: Test this error.
778  Expected<ArrayRef<Elf_Word>> ShndxTableOrErr =
779  EF.getSHNDXTable(*DotSymtabShndxSec);
780  if (!ShndxTableOrErr)
781  return ShndxTableOrErr.takeError();
782  ShndxTable = *ShndxTableOrErr;
783  }
784 
785  auto ESecOrErr = EF.getSection(*ESym, SymTab, ShndxTable);
786  if (!ESecOrErr)
787  return ESecOrErr.takeError();
788 
789  const Elf_Shdr *ESec = *ESecOrErr;
790  if (!ESec)
791  return section_end();
792 
793  DataRefImpl Sec;
794  Sec.p = reinterpret_cast<intptr_t>(ESec);
795  return section_iterator(SectionRef(Sec, this));
796 }
797 
798 template <class ELFT>
801  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
802  if (!SymOrErr)
803  return SymOrErr.takeError();
804 
805  auto SymTabOrErr = EF.getSection(Symb.d.a);
806  if (!SymTabOrErr)
807  return SymTabOrErr.takeError();
808  return getSymbolSection(*SymOrErr, *SymTabOrErr);
809 }
810 
811 template <class ELFT>
813  const Elf_Shdr *ESec = getSection(Sec);
814  Sec = toDRI(++ESec);
815 }
816 
817 template <class ELFT>
819  return EF.getSectionName(*getSection(Sec));
820 }
821 
822 template <class ELFT>
824  return getSection(Sec)->sh_addr;
825 }
826 
827 template <class ELFT>
829  auto SectionsOrErr = EF.sections();
830  handleAllErrors(std::move(SectionsOrErr.takeError()),
831  [](const ErrorInfoBase &) {
832  llvm_unreachable("unable to get section index");
833  });
834  const Elf_Shdr *First = SectionsOrErr->begin();
835  return getSection(Sec) - First;
836 }
837 
838 template <class ELFT>
840  return getSection(Sec)->sh_size;
841 }
842 
843 template <class ELFT>
846  const Elf_Shdr *EShdr = getSection(Sec);
847  if (EShdr->sh_type == ELF::SHT_NOBITS)
848  return makeArrayRef((const uint8_t *)base(), 0);
849  if (Error E =
850  checkOffset(getMemoryBufferRef(),
851  (uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))
852  return std::move(E);
853  return makeArrayRef((const uint8_t *)base() + EShdr->sh_offset,
854  EShdr->sh_size);
855 }
856 
857 template <class ELFT>
859  return getSection(Sec)->sh_addralign;
860 }
861 
862 template <class ELFT>
864  return getSection(Sec)->sh_flags & ELF::SHF_COMPRESSED;
865 }
866 
867 template <class ELFT>
869  return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR;
870 }
871 
872 template <class ELFT>
874  const Elf_Shdr *EShdr = getSection(Sec);
875  return EShdr->sh_type == ELF::SHT_PROGBITS &&
876  EShdr->sh_flags & ELF::SHF_ALLOC &&
877  !(EShdr->sh_flags & ELF::SHF_EXECINSTR);
878 }
879 
880 template <class ELFT>
882  const Elf_Shdr *EShdr = getSection(Sec);
883  return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
884  EShdr->sh_type == ELF::SHT_NOBITS;
885 }
886 
887 template <class ELFT>
888 std::vector<SectionRef>
890  std::vector<SectionRef> Res;
891  std::vector<uintptr_t> Offsets;
892 
893  auto SectionsOrErr = EF.sections();
894  if (!SectionsOrErr)
895  return Res;
896 
897  for (const Elf_Shdr &Sec : *SectionsOrErr) {
898  if (Sec.sh_type != ELF::SHT_DYNAMIC)
899  continue;
900  Elf_Dyn *Dynamic =
901  reinterpret_cast<Elf_Dyn *>((uintptr_t)base() + Sec.sh_offset);
902  for (; Dynamic->d_tag != ELF::DT_NULL; Dynamic++) {
903  if (Dynamic->d_tag == ELF::DT_REL || Dynamic->d_tag == ELF::DT_RELA ||
904  Dynamic->d_tag == ELF::DT_JMPREL) {
905  Offsets.push_back(Dynamic->d_un.d_val);
906  }
907  }
908  }
909  for (const Elf_Shdr &Sec : *SectionsOrErr) {
910  if (is_contained(Offsets, Sec.sh_addr))
911  Res.emplace_back(toDRI(&Sec), this);
912  }
913  return Res;
914 }
915 
916 template <class ELFT>
918  return getSection(Sec)->sh_type == ELF::SHT_NOBITS;
919 }
920 
921 template <class ELFT>
923  return getSection(Sec)->sh_flags & ELF::SHF_ALLOC &&
924  (getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR ||
925  !(getSection(Sec)->sh_flags & ELF::SHF_WRITE));
926 }
927 
928 template <class ELFT>
930  const Elf_Shdr *EShdr = getSection(Sec);
931  return !isBerkeleyText(Sec) && EShdr->sh_type != ELF::SHT_NOBITS &&
932  EShdr->sh_flags & ELF::SHF_ALLOC;
933 }
934 
935 template <class ELFT>
937  Expected<StringRef> SectionNameOrErr = getSectionName(Sec);
938  if (!SectionNameOrErr) {
939  // TODO: Report the error message properly.
940  consumeError(SectionNameOrErr.takeError());
941  return false;
942  }
943  StringRef SectionName = SectionNameOrErr.get();
944  return SectionName.startswith(".debug") ||
945  SectionName.startswith(".zdebug") || SectionName == ".gdb_index";
946 }
947 
948 template <class ELFT>
951  DataRefImpl RelData;
952  auto SectionsOrErr = EF.sections();
953  if (!SectionsOrErr)
955  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
956  RelData.d.a = (Sec.p - SHT) / EF.getHeader().e_shentsize;
957  RelData.d.b = 0;
958  return relocation_iterator(RelocationRef(RelData, this));
959 }
960 
961 template <class ELFT>
964  const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p);
965  relocation_iterator Begin = section_rel_begin(Sec);
966  if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
967  return Begin;
968  DataRefImpl RelData = Begin->getRawDataRefImpl();
969  const Elf_Shdr *RelSec = getRelSection(RelData);
970 
971  // Error check sh_link here so that getRelocationSymbol can just use it.
972  auto SymSecOrErr = EF.getSection(RelSec->sh_link);
973  if (!SymSecOrErr)
975  Twine(errorToErrorCode(SymSecOrErr.takeError()).message()));
976 
977  RelData.d.b += S->sh_size / S->sh_entsize;
978  return relocation_iterator(RelocationRef(RelData, this));
979 }
980 
981 template <class ELFT>
984  const Elf_Shdr *EShdr = getSection(Sec);
985  uintX_t Type = EShdr->sh_type;
986  if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA)
987  return section_end();
988 
989  Expected<const Elf_Shdr *> SecOrErr = EF.getSection(EShdr->sh_info);
990  if (!SecOrErr)
991  return SecOrErr.takeError();
992  return section_iterator(SectionRef(toDRI(*SecOrErr), this));
993 }
994 
995 // Relocations
996 template <class ELFT>
998  ++Rel.d.b;
999 }
1000 
1001 template <class ELFT>
1004  uint32_t symbolIdx;
1005  const Elf_Shdr *sec = getRelSection(Rel);
1006  if (sec->sh_type == ELF::SHT_REL)
1007  symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL());
1008  else
1009  symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL());
1010  if (!symbolIdx)
1011  return symbol_end();
1012 
1013  // FIXME: error check symbolIdx
1014  DataRefImpl SymbolData;
1015  SymbolData.d.a = sec->sh_link;
1016  SymbolData.d.b = symbolIdx;
1017  return symbol_iterator(SymbolRef(SymbolData, this));
1018 }
1019 
1020 template <class ELFT>
1022  const Elf_Shdr *sec = getRelSection(Rel);
1023  if (sec->sh_type == ELF::SHT_REL)
1024  return getRel(Rel)->r_offset;
1025 
1026  return getRela(Rel)->r_offset;
1027 }
1028 
1029 template <class ELFT>
1031  const Elf_Shdr *sec = getRelSection(Rel);
1032  if (sec->sh_type == ELF::SHT_REL)
1033  return getRel(Rel)->getType(EF.isMips64EL());
1034  else
1035  return getRela(Rel)->getType(EF.isMips64EL());
1036 }
1037 
1038 template <class ELFT>
1040  return getELFRelocationTypeName(EF.getHeader().e_machine, Type);
1041 }
1042 
1043 template <class ELFT>
1045  DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
1046  uint32_t type = getRelocationType(Rel);
1047  EF.getRelocationTypeName(type, Result);
1048 }
1049 
1050 template <class ELFT>
1053  if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
1054  return createError("Section is not SHT_RELA");
1055  return (int64_t)getRela(Rel)->r_addend;
1056 }
1057 
1058 template <class ELFT>
1059 const typename ELFObjectFile<ELFT>::Elf_Rel *
1061  assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
1062  auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
1063  if (!Ret)
1064  report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
1065  return *Ret;
1066 }
1067 
1068 template <class ELFT>
1069 const typename ELFObjectFile<ELFT>::Elf_Rela *
1071  assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
1072  auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
1073  if (!Ret)
1074  report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
1075  return *Ret;
1076 }
1077 
1078 template <class ELFT>
1081  auto EFOrErr = ELFFile<ELFT>::create(Object.getBuffer());
1082  if (Error E = EFOrErr.takeError())
1083  return std::move(E);
1084 
1085  ELFObjectFile<ELFT> Obj = {Object, std::move(*EFOrErr), nullptr, nullptr,
1086  nullptr};
1087  if (InitContent)
1088  if (Error E = Obj.initContent())
1089  return std::move(E);
1090  return std::move(Obj);
1091 }
1092 
1093 template <class ELFT>
1095  const Elf_Shdr *DotDynSymSec,
1096  const Elf_Shdr *DotSymtabSec,
1097  const Elf_Shdr *DotSymtabShndx)
1099  getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits),
1100  Object),
1101  EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec),
1102  DotSymtabShndxSec(DotSymtabShndx) {}
1103 
1104 template <class ELFT>
1106  : ELFObjectFile(Other.Data, Other.EF, Other.DotDynSymSec,
1107  Other.DotSymtabSec, Other.DotSymtabShndxSec) {}
1108 
1109 template <class ELFT>
1111  DataRefImpl Sym =
1112  toDRI(DotSymtabSec,
1113  DotSymtabSec && DotSymtabSec->sh_size >= sizeof(Elf_Sym) ? 1 : 0);
1114  return basic_symbol_iterator(SymbolRef(Sym, this));
1115 }
1116 
1117 template <class ELFT>
1119  const Elf_Shdr *SymTab = DotSymtabSec;
1120  if (!SymTab)
1121  return symbol_begin();
1122  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
1123  return basic_symbol_iterator(SymbolRef(Sym, this));
1124 }
1125 
1126 template <class ELFT>
1128  if (!DotDynSymSec || DotDynSymSec->sh_size < sizeof(Elf_Sym))
1129  // Ignore errors here where the dynsym is empty or sh_size less than the
1130  // size of one symbol. These should be handled elsewhere.
1131  return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 0), this));
1132  // Skip 0-index NULL symbol.
1133  return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 1), this));
1134 }
1135 
1136 template <class ELFT>
1138  const Elf_Shdr *SymTab = DotDynSymSec;
1139  if (!SymTab)
1140  return dynamic_symbol_begin();
1141  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
1142  return basic_symbol_iterator(SymbolRef(Sym, this));
1143 }
1144 
1145 template <class ELFT>
1147  auto SectionsOrErr = EF.sections();
1148  if (!SectionsOrErr)
1149  return section_iterator(SectionRef());
1150  return section_iterator(SectionRef(toDRI((*SectionsOrErr).begin()), this));
1151 }
1152 
1153 template <class ELFT>
1155  auto SectionsOrErr = EF.sections();
1156  if (!SectionsOrErr)
1157  return section_iterator(SectionRef());
1158  return section_iterator(SectionRef(toDRI((*SectionsOrErr).end()), this));
1159 }
1160 
1161 template <class ELFT>
1163  return ELFT::Is64Bits ? 8 : 4;
1164 }
1165 
1166 template <class ELFT>
1168  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1169  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1170  case ELF::ELFCLASS32:
1171  switch (EF.getHeader().e_machine) {
1172  case ELF::EM_68K:
1173  return "elf32-m68k";
1174  case ELF::EM_386:
1175  return "elf32-i386";
1176  case ELF::EM_IAMCU:
1177  return "elf32-iamcu";
1178  case ELF::EM_X86_64:
1179  return "elf32-x86-64";
1180  case ELF::EM_ARM:
1181  return (IsLittleEndian ? "elf32-littlearm" : "elf32-bigarm");
1182  case ELF::EM_AVR:
1183  return "elf32-avr";
1184  case ELF::EM_HEXAGON:
1185  return "elf32-hexagon";
1186  case ELF::EM_LANAI:
1187  return "elf32-lanai";
1188  case ELF::EM_MIPS:
1189  return "elf32-mips";
1190  case ELF::EM_MSP430:
1191  return "elf32-msp430";
1192  case ELF::EM_PPC:
1193  return (IsLittleEndian ? "elf32-powerpcle" : "elf32-powerpc");
1194  case ELF::EM_RISCV:
1195  return "elf32-littleriscv";
1196  case ELF::EM_CSKY:
1197  return "elf32-csky";
1198  case ELF::EM_SPARC:
1199  case ELF::EM_SPARC32PLUS:
1200  return "elf32-sparc";
1201  case ELF::EM_AMDGPU:
1202  return "elf32-amdgpu";
1203  default:
1204  return "elf32-unknown";
1205  }
1206  case ELF::ELFCLASS64:
1207  switch (EF.getHeader().e_machine) {
1208  case ELF::EM_386:
1209  return "elf64-i386";
1210  case ELF::EM_X86_64:
1211  return "elf64-x86-64";
1212  case ELF::EM_AARCH64:
1213  return (IsLittleEndian ? "elf64-littleaarch64" : "elf64-bigaarch64");
1214  case ELF::EM_PPC64:
1215  return (IsLittleEndian ? "elf64-powerpcle" : "elf64-powerpc");
1216  case ELF::EM_RISCV:
1217  return "elf64-littleriscv";
1218  case ELF::EM_S390:
1219  return "elf64-s390";
1220  case ELF::EM_SPARCV9:
1221  return "elf64-sparc";
1222  case ELF::EM_MIPS:
1223  return "elf64-mips";
1224  case ELF::EM_AMDGPU:
1225  return "elf64-amdgpu";
1226  case ELF::EM_BPF:
1227  return "elf64-bpf";
1228  case ELF::EM_VE:
1229  return "elf64-ve";
1230  default:
1231  return "elf64-unknown";
1232  }
1233  default:
1234  // FIXME: Proper error handling.
1235  report_fatal_error("Invalid ELFCLASS!");
1236  }
1237 }
1238 
1239 template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
1240  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1241  switch (EF.getHeader().e_machine) {
1242  case ELF::EM_68K:
1243  return Triple::m68k;
1244  case ELF::EM_386:
1245  case ELF::EM_IAMCU:
1246  return Triple::x86;
1247  case ELF::EM_X86_64:
1248  return Triple::x86_64;
1249  case ELF::EM_AARCH64:
1250  return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be;
1251  case ELF::EM_ARM:
1252  return Triple::arm;
1253  case ELF::EM_AVR:
1254  return Triple::avr;
1255  case ELF::EM_HEXAGON:
1256  return Triple::hexagon;
1257  case ELF::EM_LANAI:
1258  return Triple::lanai;
1259  case ELF::EM_MIPS:
1260  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1261  case ELF::ELFCLASS32:
1262  return IsLittleEndian ? Triple::mipsel : Triple::mips;
1263  case ELF::ELFCLASS64:
1264  return IsLittleEndian ? Triple::mips64el : Triple::mips64;
1265  default:
1266  report_fatal_error("Invalid ELFCLASS!");
1267  }
1268  case ELF::EM_MSP430:
1269  return Triple::msp430;
1270  case ELF::EM_PPC:
1271  return IsLittleEndian ? Triple::ppcle : Triple::ppc;
1272  case ELF::EM_PPC64:
1273  return IsLittleEndian ? Triple::ppc64le : Triple::ppc64;
1274  case ELF::EM_RISCV:
1275  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1276  case ELF::ELFCLASS32:
1277  return Triple::riscv32;
1278  case ELF::ELFCLASS64:
1279  return Triple::riscv64;
1280  default:
1281  report_fatal_error("Invalid ELFCLASS!");
1282  }
1283  case ELF::EM_S390:
1284  return Triple::systemz;
1285 
1286  case ELF::EM_SPARC:
1287  case ELF::EM_SPARC32PLUS:
1288  return IsLittleEndian ? Triple::sparcel : Triple::sparc;
1289  case ELF::EM_SPARCV9:
1290  return Triple::sparcv9;
1291 
1292  case ELF::EM_AMDGPU: {
1293  if (!IsLittleEndian)
1294  return Triple::UnknownArch;
1295 
1296  unsigned MACH = EF.getHeader().e_flags & ELF::EF_AMDGPU_MACH;
1297  if (MACH >= ELF::EF_AMDGPU_MACH_R600_FIRST &&
1299  return Triple::r600;
1300  if (MACH >= ELF::EF_AMDGPU_MACH_AMDGCN_FIRST &&
1302  return Triple::amdgcn;
1303 
1304  return Triple::UnknownArch;
1305  }
1306 
1307  case ELF::EM_BPF:
1308  return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
1309 
1310  case ELF::EM_VE:
1311  return Triple::ve;
1312  case ELF::EM_CSKY:
1313  return Triple::csky;
1314  default:
1315  return Triple::UnknownArch;
1316  }
1317 }
1318 
1319 template <class ELFT>
1321  return EF.getHeader().e_entry;
1322 }
1323 
1324 template <class ELFT>
1327  return make_range(dynamic_symbol_begin(), dynamic_symbol_end());
1328 }
1329 
1330 template <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const {
1331  return EF.getHeader().e_type == ELF::ET_REL;
1332 }
1333 
1334 } // end namespace object
1335 } // end namespace llvm
1336 
1337 #endif // LLVM_OBJECT_ELFOBJECTFILE_H
llvm::ELF::EM_S390
@ EM_S390
Definition: ELF.h:151
MemoryBuffer.h
llvm::Triple::riscv64
@ riscv64
Definition: Triple.h:74
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:919
llvm::object::ELFObjectFile::DotDynSymSec
const Elf_Shdr * DotDynSymSec
Definition: ELFObjectFile.h:260
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::object::ELFObjectFile::getSectionName
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:818
llvm::object::ELFObjectFile::isDebugSection
bool isDebugSection(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:936
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:58
llvm::object::ELFObjectFile::getRelocationAddend
Expected< int64_t > getRelocationAddend(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1052
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: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:1147
llvm::ELF::EF_AMDGPU_MACH_R600_LAST
@ EF_AMDGPU_MACH_R600_LAST
Definition: ELF.h:716
llvm::ELF::ELFCLASS32
@ ELFCLASS32
Definition: ELF.h:328
llvm::object::ELFObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition: ELFObjectFile.h:1110
llvm::object::ELFObjectFile::isSectionText
bool isSectionText(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:868
StringRef.h
llvm::object::BasicSymbolRef::SF_Common
@ SF_Common
Definition: SymbolicFile.h:112
llvm::Triple::x86
@ x86
Definition: Triple.h:83
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:1044
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:72
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:526
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: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:138
llvm::object::BasicSymbolRef::SF_Exported
@ SF_Exported
Definition: SymbolicFile.h:114
llvm::object::relocation_iterator
content_iterator< RelocationRef > relocation_iterator
Definition: ObjectFile.h:76
llvm::object::getSection
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: ELF.h:402
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:84
llvm::object::symbol_iterator::operator->
const SymbolRef * operator->() const
Definition: ObjectFile.h:214
llvm::object::ELFObjectFile::DotSymtabShndxSec
const Elf_Shdr * DotSymtabShndxSec
Definition: ELFObjectFile.h:262
llvm::object::SymbolRef::ST_Unknown
@ ST_Unknown
Definition: ObjectFile.h:172
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:67
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:60
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:715
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:173
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:929
STLExtras.h
llvm::object::SymbolRef::ST_File
@ ST_File
Definition: ObjectFile.h:175
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition: SymbolicFile.h:110
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:1127
llvm::Triple::mips64
@ mips64
Definition: Triple.h:64
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:997
llvm::object::ELFObjectFile::getDynamicSymbolIterators
elf_symbol_iterator_range getDynamicSymbolIterators() const override
Definition: ELFObjectFile.h:1326
llvm::ELF::STT_TLS
@ STT_TLS
Definition: ELF.h:1162
llvm::EnumEntry
Definition: ScopedPrinter.h:24
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:1070
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::SHT_SYMTAB
@ SHT_SYMTAB
Definition: ELF.h:917
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:75
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:76
SubtargetFeature.h
llvm::Triple::sparcel
@ sparcel
Definition: Triple.h:77
ELF.h
llvm::object::symbol_iterator::operator*
const SymbolRef & operator*() const
Definition: ObjectFile.h:219
llvm::Triple::ArchType
ArchType
Definition: Triple.h:47
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:926
llvm::Triple::mips64el
@ mips64el
Definition: Triple.h:65
llvm::object::ELFObjectFile::getSectionAlignment
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:858
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:1146
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:931
llvm::ELF::STV_DEFAULT
@ STV_DEFAULT
Definition: ELF.h:1174
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:69
llvm::object::ELFObjectFile::section_rel_begin
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:950
llvm::ELF::STT_FILE
@ STT_FILE
Definition: ELF.h:1160
llvm::object::ELFObjectFile::isDyldELFObject
bool isDyldELFObject
Definition: ELFObjectFile.h:396
llvm::Triple::r600
@ r600
Definition: Triple.h:71
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:140
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:759
llvm::object::ELFObjectFileBase::getRelocationAddend
virtual Expected< int64_t > getRelocationAddend(DataRefImpl Rel) const =0
llvm::Triple::m68k
@ m68k
Definition: Triple.h:61
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:922
llvm::Triple::lanai
@ lanai
Definition: Triple.h:98
llvm::object::ELFObjectFile::create
static Expected< ELFObjectFile< ELFT > > create(MemoryBufferRef Object, bool InitContent=true)
Definition: ELFObjectFile.h:1080
llvm::ELF::STB_GLOBAL
@ STB_GLOBAL
Definition: ELF.h:1145
llvm::object::SymbolRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:417
llvm::object::ELFObjectFile::getSymbolValueImpl
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:539
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: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:564
llvm::ELF::STT_FUNC
@ STT_FUNC
Definition: ELF.h:1158
llvm::ELF::SHT_DYNAMIC
@ SHT_DYNAMIC
Definition: ELF.h:921
llvm::ELF::STB_LOCAL
@ STB_LOCAL
Definition: ELF.h:1144
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:80
llvm::object::ELFObjectFile::getSectionContents
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:845
llvm::object::ELFSectionRef::getOffset
uint64_t getOffset() const
Definition: ELFObjectFile.h:123
llvm::Triple::ppc64le
@ ppc64le
Definition: Triple.h:70
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:963
llvm::object::DataRefImpl::d
struct llvm::object::DataRefImpl::@321 d
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:1146
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:828
llvm::ELF::SHT_ARM_ATTRIBUTES
@ SHT_ARM_ATTRIBUTES
Definition: ELF.h:967
llvm::object::symbol_iterator
Definition: ObjectFile.h:207
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:176
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:916
llvm::ELF::SHT_REL
@ SHT_REL
Definition: ELF.h:924
llvm::ELF::SHT_RISCV_ATTRIBUTES
@ SHT_RISCV_ATTRIBUTES
Definition: ELF.h:981
llvm::object::ELFRelocationRef::ELFRelocationRef
ELFRelocationRef(const RelocationRef &B)
Definition: ELFObjectFile.h:197
llvm::object::ELFObjectFile::getFileFormatName
StringRef getFileFormatName() const override
Definition: ELFObjectFile.h:1167
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:1161
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:994
llvm::object::ObjectFile::SectionRef
friend class SectionRef
Definition: ObjectFile.h:260
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:1177
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:823
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:1616
llvm::ELF::SHN_UNDEF
@ SHN_UNDEF
Definition: ELF.h:901
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:174
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:57
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:1137
llvm::object::ELFObjectFile::getRelocatedSection
Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:983
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:773
llvm::object::ELFObjectFile::getSymbolOther
uint8_t getSymbolOther(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:645
llvm::Sched::Source
@ Source
Definition: TargetLowering.h:100
llvm::ELF::STT_OBJECT
@ STT_OBJECT
Definition: ELF.h:1157
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:50
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:1330
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:53
llvm::Triple::msp430
@ msp430
Definition: Triple.h:66
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::ObjectFile
This class is the base class for all object file types.
Definition: ObjectFile.h:228
llvm::object::Binary
Definition: Binary.h:32
llvm::Triple::ppcle
@ ppcle
Definition: Triple.h:68
llvm::ELF::SHN_ABS
@ SHN_ABS
Definition: ELF.h:907
llvm::ELF::STV_HIDDEN
@ STV_HIDDEN
Definition: ELF.h:1176
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:568
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:1162
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:103
llvm::object::ELFObjectFile::dynamic_relocation_sections
std::vector< SectionRef > dynamic_relocation_sections() const override
Definition: ELFObjectFile.h:889
LLVM_ELF_IMPORT_TYPES_ELFT
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Definition: ELFTypes.h:106
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:1060
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:1003
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:171
llvm::object::ELFObjectFile::getRelocationType
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1030
llvm::ELF::EF_AMDGPU_MACH
@ EF_AMDGPU_MACH
Definition: ELF.h:682
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:1118
llvm::SectionName
Definition: DWARFSection.h:21
llvm::ELF::EF_AMDGPU_MACH_AMDGCN_LAST
@ EF_AMDGPU_MACH_AMDGCN_LAST
Definition: ELF.h:760
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::Triple::riscv32
@ riscv32
Definition: Triple.h:73
Casting.h
llvm::Triple::mipsel
@ mipsel
Definition: Triple.h:63
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:863
llvm::object::ELFFile::create
static Expected< ELFFile > create(StringRef Object)
Definition: ELF.h:753
llvm::Triple::systemz
@ systemz
Definition: Triple.h:78
llvm::object::SymbolRef::ST_Other
@ ST_Other
Definition: ObjectFile.h:177
llvm::ELF::STT_SECTION
@ STT_SECTION
Definition: ELF.h:1159
llvm::object::ELFObjectFile::isSectionData
bool isSectionData(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:873
llvm::object::ELFObjectFile::section_end
section_iterator section_end() const override
Definition: ELFObjectFile.h:1154
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
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: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:1021
llvm::ELF::SHN_COMMON
@ SHN_COMMON
Definition: ELF.h:908
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:334
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:167
llvm::object::ELFObjectFile::moveRelocationNext
void moveRelocationNext(DataRefImpl &Rel) const override
Definition: ELFObjectFile.h:997
llvm::object::createError
Error createError(const Twine &Err)
Definition: Error.h:85
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:991
llvm::object::ELFObjectFile::isDyldType
bool isDyldType() const
Definition: ELFObjectFile.h:443
llvm::ELF::SHF_COMPRESSED
@ SHF_COMPRESSED
Definition: ELF.h:1022
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:51
llvm::object::ELFObjectFile::isSectionBSS
bool isSectionBSS(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:881
llvm::object::ELFObjectFile::isSectionVirtual
bool isSectionVirtual(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:917
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:1263
llvm::object::ELFSectionRef::ELFSectionRef
ELFSectionRef(const SectionRef &B)
Definition: ELFObjectFile.h:107
llvm::ELF::STT_NOTYPE
@ STT_NOTYPE
Definition: ELF.h:1156
llvm::object::ELFObjectFile::moveSectionNext
void moveSectionNext(DataRefImpl &Sec) const override
Definition: ELFObjectFile.h:812
getSymbolName
static StringRef getSymbolName(SymbolKind SymKind)
Definition: CodeViewDebug.cpp:3000
llvm::object::ELFObjectFileBase::getSymbolELFType
virtual uint8_t getSymbolELFType(DataRefImpl Symb) const =0
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:923
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:530
llvm::object::ELFObjectFile::getArch
Triple::ArchType getArch() const override
Definition: ELFObjectFile.h:1239
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:1320
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:62
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:52
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:839
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1184