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