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