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