LLVM  15.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 (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 
466 
467 template <class ELFT>
469  ++Sym.d.b;
470 }
471 
472 template <class ELFT> Error ELFObjectFile<ELFT>::initContent() {
473  auto SectionsOrErr = EF.sections();
474  if (!SectionsOrErr)
475  return SectionsOrErr.takeError();
476 
477  for (const Elf_Shdr &Sec : *SectionsOrErr) {
478  switch (Sec.sh_type) {
479  case ELF::SHT_DYNSYM: {
480  if (!DotDynSymSec)
481  DotDynSymSec = &Sec;
482  break;
483  }
484  case ELF::SHT_SYMTAB: {
485  if (!DotSymtabSec)
486  DotSymtabSec = &Sec;
487  break;
488  }
489  case ELF::SHT_SYMTAB_SHNDX: {
490  if (!DotSymtabShndxSec)
491  DotSymtabShndxSec = &Sec;
492  break;
493  }
494  }
495  }
496 
497  ContentValid = true;
498  return Error::success();
499 }
500 
501 template <class ELFT>
503  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
504  if (!SymOrErr)
505  return SymOrErr.takeError();
506  auto SymTabOrErr = EF.getSection(Sym.d.a);
507  if (!SymTabOrErr)
508  return SymTabOrErr.takeError();
509  const Elf_Shdr *SymTableSec = *SymTabOrErr;
510  auto StrTabOrErr = EF.getSection(SymTableSec->sh_link);
511  if (!StrTabOrErr)
512  return StrTabOrErr.takeError();
513  const Elf_Shdr *StringTableSec = *StrTabOrErr;
514  auto SymStrTabOrErr = EF.getStringTable(*StringTableSec);
515  if (!SymStrTabOrErr)
516  return SymStrTabOrErr.takeError();
517  Expected<StringRef> Name = (*SymOrErr)->getName(*SymStrTabOrErr);
518  if (Name && !Name->empty())
519  return Name;
520 
521  // If the symbol name is empty use the section name.
522  if ((*SymOrErr)->getType() == ELF::STT_SECTION) {
523  if (Expected<section_iterator> SecOrErr = getSymbolSection(Sym)) {
524  consumeError(Name.takeError());
525  return (*SecOrErr)->getName();
526  }
527  }
528  return Name;
529 }
530 
531 template <class ELFT>
533  return getSection(Sec)->sh_flags;
534 }
535 
536 template <class ELFT>
538  return getSection(Sec)->sh_type;
539 }
540 
541 template <class ELFT>
543  return getSection(Sec)->sh_offset;
544 }
545 
546 template <class ELFT>
548  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
549  if (!SymOrErr)
550  report_fatal_error(SymOrErr.takeError());
551 
552  uint64_t Ret = (*SymOrErr)->st_value;
553  if ((*SymOrErr)->st_shndx == ELF::SHN_ABS)
554  return Ret;
555 
556  const Elf_Ehdr &Header = EF.getHeader();
557  // Clear the ARM/Thumb or microMIPS indicator flag.
558  if ((Header.e_machine == ELF::EM_ARM || Header.e_machine == ELF::EM_MIPS) &&
559  (*SymOrErr)->getType() == ELF::STT_FUNC)
560  Ret &= ~1;
561 
562  return Ret;
563 }
564 
565 template <class ELFT>
568  Expected<uint64_t> SymbolValueOrErr = getSymbolValue(Symb);
569  if (!SymbolValueOrErr)
570  // TODO: Test this error.
571  return SymbolValueOrErr.takeError();
572 
573  uint64_t Result = *SymbolValueOrErr;
574  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
575  if (!SymOrErr)
576  return SymOrErr.takeError();
577 
578  switch ((*SymOrErr)->st_shndx) {
579  case ELF::SHN_COMMON:
580  case ELF::SHN_UNDEF:
581  case ELF::SHN_ABS:
582  return Result;
583  }
584 
585  auto SymTabOrErr = EF.getSection(Symb.d.a);
586  if (!SymTabOrErr)
587  return SymTabOrErr.takeError();
588 
589  if (EF.getHeader().e_type == ELF::ET_REL) {
590  ArrayRef<Elf_Word> ShndxTable;
591  if (DotSymtabShndxSec) {
592  // TODO: Test this error.
593  if (Expected<ArrayRef<Elf_Word>> ShndxTableOrErr =
594  EF.getSHNDXTable(*DotSymtabShndxSec))
595  ShndxTable = *ShndxTableOrErr;
596  else
597  return ShndxTableOrErr.takeError();
598  }
599 
600  Expected<const Elf_Shdr *> SectionOrErr =
601  EF.getSection(**SymOrErr, *SymTabOrErr, ShndxTable);
602  if (!SectionOrErr)
603  return SectionOrErr.takeError();
604  const Elf_Shdr *Section = *SectionOrErr;
605  if (Section)
606  Result += Section->sh_addr;
607  }
608 
609  return Result;
610 }
611 
612 template <class ELFT>
614  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
615  if (!SymOrErr)
616  report_fatal_error(SymOrErr.takeError());
617  if ((*SymOrErr)->st_shndx == ELF::SHN_COMMON)
618  return (*SymOrErr)->st_value;
619  return 0;
620 }
621 
622 template <class ELFT>
624  return EF.getHeader().e_machine;
625 }
626 
627 template <class ELFT> uint16_t ELFObjectFile<ELFT>::getEType() const {
628  return EF.getHeader().e_type;
629 }
630 
631 template <class ELFT>
632 uint64_t ELFObjectFile<ELFT>::getSymbolSize(DataRefImpl Sym) const {
633  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
634  if (!SymOrErr)
635  report_fatal_error(SymOrErr.takeError());
636  return (*SymOrErr)->st_size;
637 }
638 
639 template <class ELFT>
641  return getSymbolSize(Symb);
642 }
643 
644 template <class ELFT>
646  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
647  if (!SymOrErr)
648  report_fatal_error(SymOrErr.takeError());
649  return (*SymOrErr)->getBinding();
650 }
651 
652 template <class ELFT>
654  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
655  if (!SymOrErr)
656  report_fatal_error(SymOrErr.takeError());
657  return (*SymOrErr)->st_other;
658 }
659 
660 template <class ELFT>
662  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
663  if (!SymOrErr)
664  report_fatal_error(SymOrErr.takeError());
665  return (*SymOrErr)->getType();
666 }
667 
668 template <class ELFT>
671  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
672  if (!SymOrErr)
673  return SymOrErr.takeError();
674 
675  switch ((*SymOrErr)->getType()) {
676  case ELF::STT_NOTYPE:
677  return SymbolRef::ST_Unknown;
678  case ELF::STT_SECTION:
679  return SymbolRef::ST_Debug;
680  case ELF::STT_FILE:
681  return SymbolRef::ST_File;
682  case ELF::STT_FUNC:
683  return SymbolRef::ST_Function;
684  case ELF::STT_OBJECT:
685  case ELF::STT_COMMON:
686  return SymbolRef::ST_Data;
687  case ELF::STT_TLS:
688  default:
689  return SymbolRef::ST_Other;
690  }
691 }
692 
693 template <class ELFT>
695  Expected<const Elf_Sym *> SymOrErr = getSymbol(Sym);
696  if (!SymOrErr)
697  return SymOrErr.takeError();
698 
699  const Elf_Sym *ESym = *SymOrErr;
700  uint32_t Result = SymbolRef::SF_None;
701 
702  if (ESym->getBinding() != ELF::STB_LOCAL)
703  Result |= SymbolRef::SF_Global;
704 
705  if (ESym->getBinding() == ELF::STB_WEAK)
706  Result |= SymbolRef::SF_Weak;
707 
708  if (ESym->st_shndx == ELF::SHN_ABS)
709  Result |= SymbolRef::SF_Absolute;
710 
711  if (ESym->getType() == ELF::STT_FILE || ESym->getType() == ELF::STT_SECTION)
713 
714  if (Expected<typename ELFT::SymRange> SymbolsOrErr =
715  EF.symbols(DotSymtabSec)) {
716  // Set the SF_FormatSpecific flag for the 0-index null symbol.
717  if (ESym == SymbolsOrErr->begin())
719  } else
720  // TODO: Test this error.
721  return SymbolsOrErr.takeError();
722 
723  if (Expected<typename ELFT::SymRange> SymbolsOrErr =
724  EF.symbols(DotDynSymSec)) {
725  // Set the SF_FormatSpecific flag for the 0-index null symbol.
726  if (ESym == SymbolsOrErr->begin())
728  } else
729  // TODO: Test this error.
730  return SymbolsOrErr.takeError();
731 
732  if (EF.getHeader().e_machine == ELF::EM_AARCH64) {
733  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
734  StringRef Name = *NameOrErr;
735  if (Name.startswith("$d") || Name.startswith("$x"))
737  } else {
738  // TODO: Actually report errors helpfully.
739  consumeError(NameOrErr.takeError());
740  }
741  } else if (EF.getHeader().e_machine == ELF::EM_ARM) {
742  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
743  StringRef Name = *NameOrErr;
744  // TODO Investigate why empty name symbols need to be marked.
745  if (Name.empty() || Name.startswith("$d") || Name.startswith("$t") ||
746  Name.startswith("$a"))
748  } else {
749  // TODO: Actually report errors helpfully.
750  consumeError(NameOrErr.takeError());
751  }
752  if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
753  Result |= SymbolRef::SF_Thumb;
754  } else if (EF.getHeader().e_machine == ELF::EM_RISCV) {
755  if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
756  // Mark empty name symbols used for label differences.
757  if (NameOrErr->empty())
759  } else {
760  // TODO: Actually report errors helpfully.
761  consumeError(NameOrErr.takeError());
762  }
763  }
764 
765  if (ESym->st_shndx == ELF::SHN_UNDEF)
766  Result |= SymbolRef::SF_Undefined;
767 
768  if (ESym->getType() == ELF::STT_COMMON || ESym->st_shndx == ELF::SHN_COMMON)
769  Result |= SymbolRef::SF_Common;
770 
771  if (isExportedToOtherDSO(ESym))
772  Result |= SymbolRef::SF_Exported;
773 
774  if (ESym->getVisibility() == ELF::STV_HIDDEN)
775  Result |= SymbolRef::SF_Hidden;
776 
777  return Result;
778 }
779 
780 template <class ELFT>
783  const Elf_Shdr *SymTab) const {
784  ArrayRef<Elf_Word> ShndxTable;
785  if (DotSymtabShndxSec) {
786  // TODO: Test this error.
787  Expected<ArrayRef<Elf_Word>> ShndxTableOrErr =
788  EF.getSHNDXTable(*DotSymtabShndxSec);
789  if (!ShndxTableOrErr)
790  return ShndxTableOrErr.takeError();
791  ShndxTable = *ShndxTableOrErr;
792  }
793 
794  auto ESecOrErr = EF.getSection(*ESym, SymTab, ShndxTable);
795  if (!ESecOrErr)
796  return ESecOrErr.takeError();
797 
798  const Elf_Shdr *ESec = *ESecOrErr;
799  if (!ESec)
800  return section_end();
801 
802  DataRefImpl Sec;
803  Sec.p = reinterpret_cast<intptr_t>(ESec);
804  return section_iterator(SectionRef(Sec, this));
805 }
806 
807 template <class ELFT>
810  Expected<const Elf_Sym *> SymOrErr = getSymbol(Symb);
811  if (!SymOrErr)
812  return SymOrErr.takeError();
813 
814  auto SymTabOrErr = EF.getSection(Symb.d.a);
815  if (!SymTabOrErr)
816  return SymTabOrErr.takeError();
817  return getSymbolSection(*SymOrErr, *SymTabOrErr);
818 }
819 
820 template <class ELFT>
822  const Elf_Shdr *ESec = getSection(Sec);
823  Sec = toDRI(++ESec);
824 }
825 
826 template <class ELFT>
828  return EF.getSectionName(*getSection(Sec));
829 }
830 
831 template <class ELFT>
833  return getSection(Sec)->sh_addr;
834 }
835 
836 template <class ELFT>
838  auto SectionsOrErr = EF.sections();
839  handleAllErrors(std::move(SectionsOrErr.takeError()),
840  [](const ErrorInfoBase &) {
841  llvm_unreachable("unable to get section index");
842  });
843  const Elf_Shdr *First = SectionsOrErr->begin();
844  return getSection(Sec) - First;
845 }
846 
847 template <class ELFT>
849  return getSection(Sec)->sh_size;
850 }
851 
852 template <class ELFT>
855  const Elf_Shdr *EShdr = getSection(Sec);
856  if (EShdr->sh_type == ELF::SHT_NOBITS)
857  return makeArrayRef((const uint8_t *)base(), 0);
858  if (Error E =
859  checkOffset(getMemoryBufferRef(),
860  (uintptr_t)base() + EShdr->sh_offset, EShdr->sh_size))
861  return std::move(E);
862  return makeArrayRef((const uint8_t *)base() + EShdr->sh_offset,
863  EShdr->sh_size);
864 }
865 
866 template <class ELFT>
868  return getSection(Sec)->sh_addralign;
869 }
870 
871 template <class ELFT>
873  return getSection(Sec)->sh_flags & ELF::SHF_COMPRESSED;
874 }
875 
876 template <class ELFT>
878  return getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR;
879 }
880 
881 template <class ELFT>
883  const Elf_Shdr *EShdr = getSection(Sec);
884  return EShdr->sh_type == ELF::SHT_PROGBITS &&
885  EShdr->sh_flags & ELF::SHF_ALLOC &&
886  !(EShdr->sh_flags & ELF::SHF_EXECINSTR);
887 }
888 
889 template <class ELFT>
891  const Elf_Shdr *EShdr = getSection(Sec);
892  return EShdr->sh_flags & (ELF::SHF_ALLOC | ELF::SHF_WRITE) &&
893  EShdr->sh_type == ELF::SHT_NOBITS;
894 }
895 
896 template <class ELFT>
897 std::vector<SectionRef>
899  std::vector<SectionRef> Res;
900  std::vector<uintptr_t> Offsets;
901 
902  auto SectionsOrErr = EF.sections();
903  if (!SectionsOrErr)
904  return Res;
905 
906  for (const Elf_Shdr &Sec : *SectionsOrErr) {
907  if (Sec.sh_type != ELF::SHT_DYNAMIC)
908  continue;
909  Elf_Dyn *Dynamic =
910  reinterpret_cast<Elf_Dyn *>((uintptr_t)base() + Sec.sh_offset);
911  for (; Dynamic->d_tag != ELF::DT_NULL; Dynamic++) {
912  if (Dynamic->d_tag == ELF::DT_REL || Dynamic->d_tag == ELF::DT_RELA ||
913  Dynamic->d_tag == ELF::DT_JMPREL) {
914  Offsets.push_back(Dynamic->d_un.d_val);
915  }
916  }
917  }
918  for (const Elf_Shdr &Sec : *SectionsOrErr) {
919  if (is_contained(Offsets, Sec.sh_addr))
920  Res.emplace_back(toDRI(&Sec), this);
921  }
922  return Res;
923 }
924 
925 template <class ELFT>
927  return getSection(Sec)->sh_type == ELF::SHT_NOBITS;
928 }
929 
930 template <class ELFT>
932  return getSection(Sec)->sh_flags & ELF::SHF_ALLOC &&
933  (getSection(Sec)->sh_flags & ELF::SHF_EXECINSTR ||
934  !(getSection(Sec)->sh_flags & ELF::SHF_WRITE));
935 }
936 
937 template <class ELFT>
939  const Elf_Shdr *EShdr = getSection(Sec);
940  return !isBerkeleyText(Sec) && EShdr->sh_type != ELF::SHT_NOBITS &&
941  EShdr->sh_flags & ELF::SHF_ALLOC;
942 }
943 
944 template <class ELFT>
946  Expected<StringRef> SectionNameOrErr = getSectionName(Sec);
947  if (!SectionNameOrErr) {
948  // TODO: Report the error message properly.
949  consumeError(SectionNameOrErr.takeError());
950  return false;
951  }
952  StringRef SectionName = SectionNameOrErr.get();
953  return SectionName.startswith(".debug") ||
954  SectionName.startswith(".zdebug") || SectionName == ".gdb_index";
955 }
956 
957 template <class ELFT>
960  DataRefImpl RelData;
961  auto SectionsOrErr = EF.sections();
962  if (!SectionsOrErr)
964  uintptr_t SHT = reinterpret_cast<uintptr_t>((*SectionsOrErr).begin());
965  RelData.d.a = (Sec.p - SHT) / EF.getHeader().e_shentsize;
966  RelData.d.b = 0;
967  return relocation_iterator(RelocationRef(RelData, this));
968 }
969 
970 template <class ELFT>
973  const Elf_Shdr *S = reinterpret_cast<const Elf_Shdr *>(Sec.p);
974  relocation_iterator Begin = section_rel_begin(Sec);
975  if (S->sh_type != ELF::SHT_RELA && S->sh_type != ELF::SHT_REL)
976  return Begin;
977  DataRefImpl RelData = Begin->getRawDataRefImpl();
978  const Elf_Shdr *RelSec = getRelSection(RelData);
979 
980  // Error check sh_link here so that getRelocationSymbol can just use it.
981  auto SymSecOrErr = EF.getSection(RelSec->sh_link);
982  if (!SymSecOrErr)
984  Twine(errorToErrorCode(SymSecOrErr.takeError()).message()));
985 
986  RelData.d.b += S->sh_size / S->sh_entsize;
987  return relocation_iterator(RelocationRef(RelData, this));
988 }
989 
990 template <class ELFT>
993  const Elf_Shdr *EShdr = getSection(Sec);
994  uintX_t Type = EShdr->sh_type;
995  if (Type != ELF::SHT_REL && Type != ELF::SHT_RELA)
996  return section_end();
997 
998  Expected<const Elf_Shdr *> SecOrErr = EF.getSection(EShdr->sh_info);
999  if (!SecOrErr)
1000  return SecOrErr.takeError();
1001  return section_iterator(SectionRef(toDRI(*SecOrErr), this));
1002 }
1003 
1004 // Relocations
1005 template <class ELFT>
1007  ++Rel.d.b;
1008 }
1009 
1010 template <class ELFT>
1013  uint32_t symbolIdx;
1014  const Elf_Shdr *sec = getRelSection(Rel);
1015  if (sec->sh_type == ELF::SHT_REL)
1016  symbolIdx = getRel(Rel)->getSymbol(EF.isMips64EL());
1017  else
1018  symbolIdx = getRela(Rel)->getSymbol(EF.isMips64EL());
1019  if (!symbolIdx)
1020  return symbol_end();
1021 
1022  // FIXME: error check symbolIdx
1023  DataRefImpl SymbolData;
1024  SymbolData.d.a = sec->sh_link;
1025  SymbolData.d.b = symbolIdx;
1026  return symbol_iterator(SymbolRef(SymbolData, this));
1027 }
1028 
1029 template <class ELFT>
1031  const Elf_Shdr *sec = getRelSection(Rel);
1032  if (sec->sh_type == ELF::SHT_REL)
1033  return getRel(Rel)->r_offset;
1034 
1035  return getRela(Rel)->r_offset;
1036 }
1037 
1038 template <class ELFT>
1040  const Elf_Shdr *sec = getRelSection(Rel);
1041  if (sec->sh_type == ELF::SHT_REL)
1042  return getRel(Rel)->getType(EF.isMips64EL());
1043  else
1044  return getRela(Rel)->getType(EF.isMips64EL());
1045 }
1046 
1047 template <class ELFT>
1049  return getELFRelocationTypeName(EF.getHeader().e_machine, Type);
1050 }
1051 
1052 template <class ELFT>
1054  DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
1055  uint32_t type = getRelocationType(Rel);
1056  EF.getRelocationTypeName(type, Result);
1057 }
1058 
1059 template <class ELFT>
1062  if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
1063  return createError("Section is not SHT_RELA");
1064  return (int64_t)getRela(Rel)->r_addend;
1065 }
1066 
1067 template <class ELFT>
1068 const typename ELFObjectFile<ELFT>::Elf_Rel *
1070  assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
1071  auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
1072  if (!Ret)
1073  report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
1074  return *Ret;
1075 }
1076 
1077 template <class ELFT>
1078 const typename ELFObjectFile<ELFT>::Elf_Rela *
1080  assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
1081  auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
1082  if (!Ret)
1083  report_fatal_error(Twine(errorToErrorCode(Ret.takeError()).message()));
1084  return *Ret;
1085 }
1086 
1087 template <class ELFT>
1090  auto EFOrErr = ELFFile<ELFT>::create(Object.getBuffer());
1091  if (Error E = EFOrErr.takeError())
1092  return std::move(E);
1093 
1094  ELFObjectFile<ELFT> Obj = {Object, std::move(*EFOrErr), nullptr, nullptr,
1095  nullptr};
1096  if (InitContent)
1097  if (Error E = Obj.initContent())
1098  return std::move(E);
1099  return std::move(Obj);
1100 }
1101 
1102 template <class ELFT>
1104  const Elf_Shdr *DotDynSymSec,
1105  const Elf_Shdr *DotSymtabSec,
1106  const Elf_Shdr *DotSymtabShndx)
1108  getELFType(ELFT::TargetEndianness == support::little, ELFT::Is64Bits),
1109  Object),
1110  EF(EF), DotDynSymSec(DotDynSymSec), DotSymtabSec(DotSymtabSec),
1111  DotSymtabShndxSec(DotSymtabShndx) {}
1112 
1113 template <class ELFT>
1115  : ELFObjectFile(Other.Data, Other.EF, Other.DotDynSymSec,
1116  Other.DotSymtabSec, Other.DotSymtabShndxSec) {}
1117 
1118 template <class ELFT>
1120  DataRefImpl Sym =
1121  toDRI(DotSymtabSec,
1122  DotSymtabSec && DotSymtabSec->sh_size >= sizeof(Elf_Sym) ? 1 : 0);
1123  return basic_symbol_iterator(SymbolRef(Sym, this));
1124 }
1125 
1126 template <class ELFT>
1128  const Elf_Shdr *SymTab = DotSymtabSec;
1129  if (!SymTab)
1130  return symbol_begin();
1131  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
1132  return basic_symbol_iterator(SymbolRef(Sym, this));
1133 }
1134 
1135 template <class ELFT>
1137  if (!DotDynSymSec || DotDynSymSec->sh_size < sizeof(Elf_Sym))
1138  // Ignore errors here where the dynsym is empty or sh_size less than the
1139  // size of one symbol. These should be handled elsewhere.
1140  return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 0), this));
1141  // Skip 0-index NULL symbol.
1142  return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 1), this));
1143 }
1144 
1145 template <class ELFT>
1147  const Elf_Shdr *SymTab = DotDynSymSec;
1148  if (!SymTab)
1149  return dynamic_symbol_begin();
1150  DataRefImpl Sym = toDRI(SymTab, SymTab->sh_size / sizeof(Elf_Sym));
1151  return basic_symbol_iterator(SymbolRef(Sym, this));
1152 }
1153 
1154 template <class ELFT>
1156  auto SectionsOrErr = EF.sections();
1157  if (!SectionsOrErr)
1158  return section_iterator(SectionRef());
1159  return section_iterator(SectionRef(toDRI((*SectionsOrErr).begin()), this));
1160 }
1161 
1162 template <class ELFT>
1164  auto SectionsOrErr = EF.sections();
1165  if (!SectionsOrErr)
1166  return section_iterator(SectionRef());
1167  return section_iterator(SectionRef(toDRI((*SectionsOrErr).end()), this));
1168 }
1169 
1170 template <class ELFT>
1172  return ELFT::Is64Bits ? 8 : 4;
1173 }
1174 
1175 template <class ELFT>
1177  constexpr bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1178  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1179  case ELF::ELFCLASS32:
1180  switch (EF.getHeader().e_machine) {
1181  case ELF::EM_68K:
1182  return "elf32-m68k";
1183  case ELF::EM_386:
1184  return "elf32-i386";
1185  case ELF::EM_IAMCU:
1186  return "elf32-iamcu";
1187  case ELF::EM_X86_64:
1188  return "elf32-x86-64";
1189  case ELF::EM_ARM:
1190  return (IsLittleEndian ? "elf32-littlearm" : "elf32-bigarm");
1191  case ELF::EM_AVR:
1192  return "elf32-avr";
1193  case ELF::EM_HEXAGON:
1194  return "elf32-hexagon";
1195  case ELF::EM_LANAI:
1196  return "elf32-lanai";
1197  case ELF::EM_MIPS:
1198  return "elf32-mips";
1199  case ELF::EM_MSP430:
1200  return "elf32-msp430";
1201  case ELF::EM_PPC:
1202  return (IsLittleEndian ? "elf32-powerpcle" : "elf32-powerpc");
1203  case ELF::EM_RISCV:
1204  return "elf32-littleriscv";
1205  case ELF::EM_CSKY:
1206  return "elf32-csky";
1207  case ELF::EM_SPARC:
1208  case ELF::EM_SPARC32PLUS:
1209  return "elf32-sparc";
1210  case ELF::EM_AMDGPU:
1211  return "elf32-amdgpu";
1212  case ELF::EM_LOONGARCH:
1213  return "elf32-loongarch";
1214  default:
1215  return "elf32-unknown";
1216  }
1217  case ELF::ELFCLASS64:
1218  switch (EF.getHeader().e_machine) {
1219  case ELF::EM_386:
1220  return "elf64-i386";
1221  case ELF::EM_X86_64:
1222  return "elf64-x86-64";
1223  case ELF::EM_AARCH64:
1224  return (IsLittleEndian ? "elf64-littleaarch64" : "elf64-bigaarch64");
1225  case ELF::EM_PPC64:
1226  return (IsLittleEndian ? "elf64-powerpcle" : "elf64-powerpc");
1227  case ELF::EM_RISCV:
1228  return "elf64-littleriscv";
1229  case ELF::EM_S390:
1230  return "elf64-s390";
1231  case ELF::EM_SPARCV9:
1232  return "elf64-sparc";
1233  case ELF::EM_MIPS:
1234  return "elf64-mips";
1235  case ELF::EM_AMDGPU:
1236  return "elf64-amdgpu";
1237  case ELF::EM_BPF:
1238  return "elf64-bpf";
1239  case ELF::EM_VE:
1240  return "elf64-ve";
1241  case ELF::EM_LOONGARCH:
1242  return "elf64-loongarch";
1243  default:
1244  return "elf64-unknown";
1245  }
1246  default:
1247  // FIXME: Proper error handling.
1248  report_fatal_error("Invalid ELFCLASS!");
1249  }
1250 }
1251 
1252 template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
1253  bool IsLittleEndian = ELFT::TargetEndianness == support::little;
1254  switch (EF.getHeader().e_machine) {
1255  case ELF::EM_68K:
1256  return Triple::m68k;
1257  case ELF::EM_386:
1258  case ELF::EM_IAMCU:
1259  return Triple::x86;
1260  case ELF::EM_X86_64:
1261  return Triple::x86_64;
1262  case ELF::EM_AARCH64:
1263  return IsLittleEndian ? Triple::aarch64 : Triple::aarch64_be;
1264  case ELF::EM_ARM:
1265  return Triple::arm;
1266  case ELF::EM_AVR:
1267  return Triple::avr;
1268  case ELF::EM_HEXAGON:
1269  return Triple::hexagon;
1270  case ELF::EM_LANAI:
1271  return Triple::lanai;
1272  case ELF::EM_MIPS:
1273  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1274  case ELF::ELFCLASS32:
1275  return IsLittleEndian ? Triple::mipsel : Triple::mips;
1276  case ELF::ELFCLASS64:
1277  return IsLittleEndian ? Triple::mips64el : Triple::mips64;
1278  default:
1279  report_fatal_error("Invalid ELFCLASS!");
1280  }
1281  case ELF::EM_MSP430:
1282  return Triple::msp430;
1283  case ELF::EM_PPC:
1284  return IsLittleEndian ? Triple::ppcle : Triple::ppc;
1285  case ELF::EM_PPC64:
1286  return IsLittleEndian ? Triple::ppc64le : Triple::ppc64;
1287  case ELF::EM_RISCV:
1288  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1289  case ELF::ELFCLASS32:
1290  return Triple::riscv32;
1291  case ELF::ELFCLASS64:
1292  return Triple::riscv64;
1293  default:
1294  report_fatal_error("Invalid ELFCLASS!");
1295  }
1296  case ELF::EM_S390:
1297  return Triple::systemz;
1298 
1299  case ELF::EM_SPARC:
1300  case ELF::EM_SPARC32PLUS:
1301  return IsLittleEndian ? Triple::sparcel : Triple::sparc;
1302  case ELF::EM_SPARCV9:
1303  return Triple::sparcv9;
1304 
1305  case ELF::EM_AMDGPU: {
1306  if (!IsLittleEndian)
1307  return Triple::UnknownArch;
1308 
1309  unsigned MACH = EF.getHeader().e_flags & ELF::EF_AMDGPU_MACH;
1310  if (MACH >= ELF::EF_AMDGPU_MACH_R600_FIRST &&
1312  return Triple::r600;
1313  if (MACH >= ELF::EF_AMDGPU_MACH_AMDGCN_FIRST &&
1315  return Triple::amdgcn;
1316 
1317  return Triple::UnknownArch;
1318  }
1319 
1320  case ELF::EM_BPF:
1321  return IsLittleEndian ? Triple::bpfel : Triple::bpfeb;
1322 
1323  case ELF::EM_VE:
1324  return Triple::ve;
1325  case ELF::EM_CSKY:
1326  return Triple::csky;
1327 
1328  case ELF::EM_LOONGARCH:
1329  switch (EF.getHeader().e_ident[ELF::EI_CLASS]) {
1330  case ELF::ELFCLASS32:
1331  return Triple::loongarch32;
1332  case ELF::ELFCLASS64:
1333  return Triple::loongarch64;
1334  default:
1335  report_fatal_error("Invalid ELFCLASS!");
1336  }
1337 
1338  default:
1339  return Triple::UnknownArch;
1340  }
1341 }
1342 
1343 template <class ELFT>
1345  return EF.getHeader().e_entry;
1346 }
1347 
1348 template <class ELFT>
1351  return make_range(dynamic_symbol_begin(), dynamic_symbol_end());
1352 }
1353 
1354 template <class ELFT> bool ELFObjectFile<ELFT>::isRelocatableObject() const {
1355  return EF.getHeader().e_type == ELF::ET_REL;
1356 }
1357 
1358 } // end namespace object
1359 } // end namespace llvm
1360 
1361 #endif // LLVM_OBJECT_ELFOBJECTFILE_H
llvm::ELF::EF_AMDGPU_MACH
@ EF_AMDGPU_MACH
Definition: ELF.h:697
llvm::Triple::riscv64
@ riscv64
Definition: Triple.h:76
llvm::ELF::STT_FUNC
@ STT_FUNC
Definition: ELF.h:1202
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:17
llvm::object::ELFObjectFile::getSectionName
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:827
llvm::object::ELFObjectFile::isDebugSection
bool isDebugSection(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:945
llvm::object::ELFObjectFile::toSymbolRef
ELFSymbolRef toSymbolRef(const Elf_Shdr *SymTable, unsigned SymbolNum) const
Definition: ELFObjectFile.h:252
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:1061
llvm::object::DataRefImpl::a
uint32_t a
Definition: SymbolicFile.h:39
llvm::ELF::SHF_WRITE
@ SHF_WRITE
Definition: ELF.h:1032
llvm::Triple::UnknownArch
@ UnknownArch
Definition: Triple.h:47
llvm::object::ELFObjectFile::getSymbolELFType
uint8_t getSymbolELFType(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:661
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::ELFObjectFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition: ELFObjectFile.h:1119
llvm::object::ELFObjectFile::isSectionText
bool isSectionText(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:877
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:599
llvm::object::ELFObjectFile::getRelocationTypeName
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
Definition: ELFObjectFile.h:1053
llvm::object::ELFObjectFileBase::readDynsymVersions
Expected< std::vector< VersionEntry > > readDynsymVersions() const
Returns a vector containing a symbol version for each dynamic symbol.
Definition: ELFObjectFile.cpp:759
llvm::Triple::amdgcn
@ amdgcn
Definition: Triple.h:74
llvm::cast
decltype(auto) LLVM_NODISCARD cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition: Casting.h:565
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:536
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::EM_LANAI
@ EM_LANAI
Definition: ELF.h:318
llvm::ELF::SHT_SYMTAB_SHNDX
@ SHT_SYMTAB_SHNDX
Definition: ELF.h:970
llvm::object::BasicSymbolRef::SF_Exported
@ SF_Exported
Definition: SymbolicFile.h:116
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:401
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::Triple::x86_64
@ x86_64
Definition: Triple.h:86
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::object::DataRefImpl::d
struct llvm::object::DataRefImpl::@332 d
llvm::ELF::SHF_ALLOC
@ SHF_ALLOC
Definition: ELF.h:1035
llvm::object::ELFSectionRef
Definition: ELFObjectFile.h:113
llvm::ELF::EM_AVR
@ EM_AVR
Definition: ELF.h:199
llvm::ELF::STT_TLS
@ STT_TLS
Definition: ELF.h:1206
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:938
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:1136
llvm::Triple::mips64
@ mips64
Definition: Triple.h:66
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1043
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::ELF::SHN_COMMON
@ SHN_COMMON
Definition: ELF.h:947
llvm::object::ELFObjectFile::getDynamicSymbolIterators
elf_symbol_iterator_range getDynamicSymbolIterators() const override
Definition: ELFObjectFile.h:1350
llvm::EnumEntry
Definition: EnumTables.h:18
llvm::object::ELFObjectFile::toDRI
DataRefImpl toDRI(const Elf_Dyn *Dyn) const
Definition: ELFObjectFile.h:358
llvm::ELF::SHF_COMPRESSED
@ SHF_COMPRESSED
Definition: ELF.h:1063
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:1079
llvm::object::ELFObjectFileBase
Definition: ELFObjectFile.h:51
llvm::object::SymbolicFile::symbol_end
virtual basic_symbol_iterator symbol_end() const =0
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:472
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::ELF::STB_GLOBAL
@ STB_GLOBAL
Definition: ELF.h:1189
llvm::object::ELFObjectFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition: ELFObjectFile.h:468
llvm::ELF::EF_AMDGPU_MACH_AMDGCN_LAST
@ EF_AMDGPU_MACH_AMDGCN_LAST
Definition: ELF.h:777
llvm::Triple::mips64el
@ mips64el
Definition: Triple.h:67
llvm::object::ELFObjectFile::getSectionAlignment
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:867
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:183
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:959
llvm::ELF::EF_AMDGPU_MACH_R600_LAST
@ EF_AMDGPU_MACH_R600_LAST
Definition: ELF.h:731
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:143
llvm::object::ELFObjectFile::getSymbolAlignment
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:613
llvm::ELF::SHN_ABS
@ SHN_ABS
Definition: ELF.h:946
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::ELF::STV_DEFAULT
@ STV_DEFAULT
Definition: ELF.h:1218
llvm::object::ELFObjectFile::isBerkeleyText
bool isBerkeleyText(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:931
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:1089
llvm::object::SymbolRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:427
llvm::ELF::EM_RISCV
@ EM_RISCV
Definition: ELF.h:317
llvm::ELF::STT_SECTION
@ STT_SECTION
Definition: ELF.h:1203
llvm::ELF::EM_IAMCU
@ EM_IAMCU
Definition: ELF.h:139
llvm::object::ELFObjectFile::getSymbolValueImpl
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:547
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:645
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:574
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:962
ELFAttributes.h
llvm::ELF::STV_HIDDEN
@ STV_HIDDEN
Definition: ELF.h:1220
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:854
llvm::ELF::SHT_DYNAMIC
@ SHT_DYNAMIC
Definition: ELF.h:960
llvm::object::ELFSectionRef::getOffset
uint64_t getOffset() const
Definition: ELFObjectFile.h:131
llvm::Triple::ppc64le
@ ppc64le
Definition: Triple.h:72
llvm::object::ElfSymbolTypes
const llvm::EnumEntry< unsigned > ElfSymbolTypes[NumElfSymbolTypes]
Definition: ELFObjectFile.cpp:38
llvm::object::ELFObjectFile::section_rel_end
relocation_iterator section_rel_end(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:972
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:1155
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:837
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:344
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
llvm::ELF::SHT_SYMTAB
@ SHT_SYMTAB
Definition: ELF.h:956
llvm::ELF::STT_NOTYPE
@ STT_NOTYPE
Definition: ELF.h:1200
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::ELF::STB_LOCAL
@ STB_LOCAL
Definition: ELF.h:1188
llvm::object::ELFRelocationRef::ELFRelocationRef
ELFRelocationRef(const RelocationRef &B)
Definition: ELFObjectFile.h:205
llvm::object::ELFObjectFile::getFileFormatName
StringRef getFileFormatName() const override
Definition: ELFObjectFile.h:1176
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:772
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:832
Attributes
AMDGPU Kernel Attributes
Definition: AMDGPULowerKernelAttributes.cpp:244
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:1682
ArrayRef.h
llvm::object::ELFObjectFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:694
llvm::object::BasicSymbolRef::SF_Thumb
@ SF_Thumb
Definition: SymbolicFile.h:119
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::ELF::SHT_RELA
@ SHT_RELA
Definition: ELF.h:958
llvm::object::ELFObjectFile::dynamic_symbol_end
elf_symbol_iterator dynamic_symbol_end() const
Definition: ELFObjectFile.h:1146
llvm::object::ELFObjectFile::getRelocatedSection
Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:992
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:782
llvm::object::ELFObjectFile::getSymbolOther
uint8_t getSymbolOther(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:653
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:1354
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: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:70
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:567
llvm::RoundingMode::Dynamic
@ Dynamic
Denotes mode unknown at compile time.
uint32_t
llvm::object::RelocationRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:578
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:1171
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:640
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:898
LLVM_ELF_IMPORT_TYPES_ELFT
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Definition: ELFTypes.h:104
llvm::ELF::STB_GNU_UNIQUE
@ STB_GNU_UNIQUE
Definition: ELF.h:1191
llvm::object::ELFObjectFile::getSymbolType
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:670
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:1069
llvm::ELF::STV_PROTECTED
@ STV_PROTECTED
Definition: ELF.h:1221
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::object::ELFObjectFile::getRelocationSymbol
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1012
llvm::object::ELFObjectFile::isExportedToOtherDSO
bool isExportedToOtherDSO(const Elf_Sym *ESym) const
Definition: ELFObjectFile.h:364
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::object::SymbolRef::Type
Type
Definition: ObjectFile.h:171
llvm::object::ELFObjectFile::getRelocationType
uint64_t getRelocationType(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1039
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:504
llvm::object::ELFObjectFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition: ELFObjectFile.h:1127
llvm::SectionName
Definition: DWARFSection.h:21
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::ELF::STT_OBJECT
@ STT_OBJECT
Definition: ELF.h:1201
llvm::ELF::EM_S390
@ EM_S390
Definition: ELF.h:150
llvm::Triple::riscv32
@ riscv32
Definition: Triple.h:75
Casting.h
llvm::ELF::SHT_REL
@ SHT_REL
Definition: ELF.h:963
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:872
llvm::Triple::loongarch64
@ loongarch64
Definition: Triple.h:62
llvm::object::ELFFile::create
static Expected< ELFFile > create(StringRef Object)
Definition: ELF.h:752
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:882
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:730
llvm::object::ELFObjectFile::section_end
section_iterator section_end() const override
Definition: ELFObjectFile.h:1163
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:96
llvm::ELF::SHT_DYNSYM
@ SHT_DYNSYM
Definition: ELF.h:965
llvm::ELF::EF_AMDGPU_MACH_AMDGCN_FIRST
@ EF_AMDGPU_MACH_AMDGCN_FIRST
Definition: ELF.h:776
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:597
llvm::object::ELFObjectFile::getRelocationOffset
uint64_t getRelocationOffset(DataRefImpl Rel) const override
Definition: ELFObjectFile.h:1030
llvm::object::ELFObjectFileBase::getSymbolBinding
virtual uint8_t getSymbolBinding(DataRefImpl Symb) const =0
Binary.h
llvm::ELF::SHN_UNDEF
@ SHN_UNDEF
Definition: ELF.h:940
llvm::object::ELFObjectFile::getSectionOffset
uint64_t getSectionOffset(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:542
llvm::ELF::EM_PPC
@ EM_PPC
Definition: ELF.h:148
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:955
llvm::ELF::SHT_RISCV_ATTRIBUTES
@ SHT_RISCV_ATTRIBUTES
Definition: ELF.h:1020
llvm::object::ELFObjectFile::getSectionType
uint32_t getSectionType(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:537
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::EM_MSP430
@ EM_MSP430
Definition: ELF.h:222
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:502
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:351
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::object::elf_symbol_iterator
Definition: ELFObjectFile.h:188
llvm::ELF::STT_FILE
@ STT_FILE
Definition: ELF.h:1204
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:1006
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::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:890
llvm::ELF::EM_AARCH64
@ EM_AARCH64
Definition: ELF.h:280
llvm::object::ELFObjectFile::isSectionVirtual
bool isSectionVirtual(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:926
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:1312
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:821
getSymbolName
static StringRef getSymbolName(SymbolKind SymKind)
Definition: CodeViewDebug.cpp:3104
llvm::object::ELFObjectFileBase::getSymbolELFType
virtual uint8_t getSymbolELFType(DataRefImpl Symb) const =0
llvm::object::ELFObjectFileBase::tryGetCPUName
Optional< StringRef > tryGetCPUName() const override
Definition: ELFObjectFile.cpp:357
Endian.h
llvm::object::ELFObjectFile::getSectionFlags
uint64_t getSectionFlags(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:532
llvm::object::ELFObjectFile
Definition: ELFObjectFile.h:240
llvm::object::SectionRef::getObject
const ObjectFile * getObject() const
Definition: ObjectFile.h:540
llvm::object::ELFObjectFile::getArch
Triple::ArchType getArch() const override
Definition: ELFObjectFile.h:1252
llvm::object::ELFObjectFile::getSymbol
Expected< const Elf_Sym * > getSymbol(DataRefImpl Sym) const
Definition: ELFObjectFile.h:414
llvm::object::ELFObjectFile::getStartAddress
Expected< uint64_t > getStartAddress() const override
Definition: ELFObjectFile.h:1344
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:966
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::STT_COMMON
@ STT_COMMON
Definition: ELF.h:1205
llvm::object::ELFFile
Definition: ELF.h:94
llvm::ELF::SHF_EXECINSTR
@ SHF_EXECINSTR
Definition: ELF.h:1038
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:57
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:51
llvm::object::ELFObjectFile::getSymbolAddress
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
Definition: ELFObjectFile.h:567
llvm::ELF::STB_WEAK
@ STB_WEAK
Definition: ELF.h:1190
llvm::object::ELFObjectFile::getSectionSize
uint64_t getSectionSize(DataRefImpl Sec) const override
Definition: ELFObjectFile.h:848
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1236
llvm::ELF::SHT_ARM_ATTRIBUTES
@ SHT_ARM_ATTRIBUTES
Definition: ELF.h:1006
ScopedPrinter.h