LLVM  15.0.0git
ELF.cpp
Go to the documentation of this file.
1 //===- ELF.cpp - ELF object file implementation ---------------------------===//
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 #include "llvm/Object/ELF.h"
10 #include "llvm/BinaryFormat/ELF.h"
12 
13 using namespace llvm;
14 using namespace object;
15 
16 #define STRINGIFY_ENUM_CASE(ns, name) \
17  case ns::name: \
18  return #name;
19 
20 #define ELF_RELOC(name, value) STRINGIFY_ENUM_CASE(ELF, name)
21 
23  uint32_t Type) {
24  switch (Machine) {
25  case ELF::EM_68K:
26  switch (Type) {
27 #include "llvm/BinaryFormat/ELFRelocs/M68k.def"
28  default:
29  break;
30  }
31  break;
32  case ELF::EM_X86_64:
33  switch (Type) {
34 #include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
35  default:
36  break;
37  }
38  break;
39  case ELF::EM_386:
40  case ELF::EM_IAMCU:
41  switch (Type) {
42 #include "llvm/BinaryFormat/ELFRelocs/i386.def"
43  default:
44  break;
45  }
46  break;
47  case ELF::EM_MIPS:
48  switch (Type) {
49 #include "llvm/BinaryFormat/ELFRelocs/Mips.def"
50  default:
51  break;
52  }
53  break;
54  case ELF::EM_AARCH64:
55  switch (Type) {
56 #include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
57  default:
58  break;
59  }
60  break;
61  case ELF::EM_ARM:
62  switch (Type) {
63 #include "llvm/BinaryFormat/ELFRelocs/ARM.def"
64  default:
65  break;
66  }
67  break;
70  switch (Type) {
71 #include "llvm/BinaryFormat/ELFRelocs/ARC.def"
72  default:
73  break;
74  }
75  break;
76  case ELF::EM_AVR:
77  switch (Type) {
78 #include "llvm/BinaryFormat/ELFRelocs/AVR.def"
79  default:
80  break;
81  }
82  break;
83  case ELF::EM_HEXAGON:
84  switch (Type) {
85 #include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
86  default:
87  break;
88  }
89  break;
90  case ELF::EM_LANAI:
91  switch (Type) {
92 #include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
93  default:
94  break;
95  }
96  break;
97  case ELF::EM_PPC:
98  switch (Type) {
99 #include "llvm/BinaryFormat/ELFRelocs/PowerPC.def"
100  default:
101  break;
102  }
103  break;
104  case ELF::EM_PPC64:
105  switch (Type) {
106 #include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
107  default:
108  break;
109  }
110  break;
111  case ELF::EM_RISCV:
112  switch (Type) {
113 #include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
114  default:
115  break;
116  }
117  break;
118  case ELF::EM_S390:
119  switch (Type) {
120 #include "llvm/BinaryFormat/ELFRelocs/SystemZ.def"
121  default:
122  break;
123  }
124  break;
125  case ELF::EM_SPARC:
126  case ELF::EM_SPARC32PLUS:
127  case ELF::EM_SPARCV9:
128  switch (Type) {
129 #include "llvm/BinaryFormat/ELFRelocs/Sparc.def"
130  default:
131  break;
132  }
133  break;
134  case ELF::EM_AMDGPU:
135  switch (Type) {
136 #include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
137  default:
138  break;
139  }
140  break;
141  case ELF::EM_BPF:
142  switch (Type) {
143 #include "llvm/BinaryFormat/ELFRelocs/BPF.def"
144  default:
145  break;
146  }
147  break;
148  case ELF::EM_MSP430:
149  switch (Type) {
150 #include "llvm/BinaryFormat/ELFRelocs/MSP430.def"
151  default:
152  break;
153  }
154  break;
155  case ELF::EM_VE:
156  switch (Type) {
157 #include "llvm/BinaryFormat/ELFRelocs/VE.def"
158  default:
159  break;
160  }
161  break;
162  case ELF::EM_CSKY:
163  switch (Type) {
164 #include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
165  default:
166  break;
167  }
168  break;
169  case ELF::EM_LOONGARCH:
170  switch (Type) {
171 #include "llvm/BinaryFormat/ELFRelocs/LoongArch.def"
172  default:
173  break;
174  }
175  break;
176  default:
177  break;
178  }
179  return "Unknown";
180 }
181 
182 #undef ELF_RELOC
183 
185  switch (Machine) {
186  case ELF::EM_X86_64:
187  return ELF::R_X86_64_RELATIVE;
188  case ELF::EM_386:
189  case ELF::EM_IAMCU:
190  return ELF::R_386_RELATIVE;
191  case ELF::EM_MIPS:
192  break;
193  case ELF::EM_AARCH64:
194  return ELF::R_AARCH64_RELATIVE;
195  case ELF::EM_ARM:
196  return ELF::R_ARM_RELATIVE;
197  case ELF::EM_ARC_COMPACT:
199  return ELF::R_ARC_RELATIVE;
200  case ELF::EM_AVR:
201  break;
202  case ELF::EM_HEXAGON:
203  return ELF::R_HEX_RELATIVE;
204  case ELF::EM_LANAI:
205  break;
206  case ELF::EM_PPC:
207  break;
208  case ELF::EM_PPC64:
209  return ELF::R_PPC64_RELATIVE;
210  case ELF::EM_RISCV:
211  return ELF::R_RISCV_RELATIVE;
212  case ELF::EM_S390:
213  return ELF::R_390_RELATIVE;
214  case ELF::EM_SPARC:
215  case ELF::EM_SPARC32PLUS:
216  case ELF::EM_SPARCV9:
217  return ELF::R_SPARC_RELATIVE;
218  case ELF::EM_CSKY:
219  return ELF::R_CKCORE_RELATIVE;
220  case ELF::EM_VE:
221  return ELF::R_VE_RELATIVE;
222  case ELF::EM_AMDGPU:
223  break;
224  case ELF::EM_BPF:
225  break;
226  default:
227  break;
228  }
229  return 0;
230 }
231 
233  switch (Machine) {
234  case ELF::EM_ARM:
235  switch (Type) {
241  }
242  break;
243  case ELF::EM_HEXAGON:
244  switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED); }
245  break;
246  case ELF::EM_X86_64:
247  switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_X86_64_UNWIND); }
248  break;
249  case ELF::EM_MIPS:
250  case ELF::EM_MIPS_RS3_LE:
251  switch (Type) {
256  }
257  break;
258  case ELF::EM_MSP430:
260  break;
261  case ELF::EM_RISCV:
262  switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_RISCV_ATTRIBUTES); }
263  break;
264  default:
265  break;
266  }
267 
268  switch (Type) {
304  default:
305  return "Unknown";
306  }
307 }
308 
309 template <class ELFT>
310 std::vector<typename ELFT::Rel>
311 ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
312  // This function decodes the contents of an SHT_RELR packed relocation
313  // section.
314  //
315  // Proposal for adding SHT_RELR sections to generic-abi is here:
316  // https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg
317  //
318  // The encoded sequence of Elf64_Relr entries in a SHT_RELR section looks
319  // like [ AAAAAAAA BBBBBBB1 BBBBBBB1 ... AAAAAAAA BBBBBB1 ... ]
320  //
321  // i.e. start with an address, followed by any number of bitmaps. The address
322  // entry encodes 1 relocation. The subsequent bitmap entries encode up to 63
323  // relocations each, at subsequent offsets following the last address entry.
324  //
325  // The bitmap entries must have 1 in the least significant bit. The assumption
326  // here is that an address cannot have 1 in lsb. Odd addresses are not
327  // supported.
328  //
329  // Excluding the least significant bit in the bitmap, each non-zero bit in
330  // the bitmap represents a relocation to be applied to a corresponding machine
331  // word that follows the base address word. The second least significant bit
332  // represents the machine word immediately following the initial address, and
333  // each bit that follows represents the next word, in linear order. As such,
334  // a single bitmap can encode up to 31 relocations in a 32-bit object, and
335  // 63 relocations in a 64-bit object.
336  //
337  // This encoding has a couple of interesting properties:
338  // 1. Looking at any entry, it is clear whether it's an address or a bitmap:
339  // even means address, odd means bitmap.
340  // 2. Just a simple list of addresses is a valid encoding.
341 
342  Elf_Rel Rel;
343  Rel.r_info = 0;
344  Rel.setType(getRelativeRelocationType(), false);
345  std::vector<Elf_Rel> Relocs;
346 
347  // Word type: uint32_t for Elf32, and uint64_t for Elf64.
348  using Addr = typename ELFT::uint;
349 
350  Addr Base = 0;
351  for (Elf_Relr R : relrs) {
352  typename ELFT::uint Entry = R;
353  if ((Entry & 1) == 0) {
354  // Even entry: encodes the offset for next relocation.
355  Rel.r_offset = Entry;
356  Relocs.push_back(Rel);
357  // Set base offset for subsequent bitmap entries.
358  Base = Entry + sizeof(Addr);
359  } else {
360  // Odd entry: encodes bitmap for relocations starting at base.
361  for (Addr Offset = Base; (Entry >>= 1) != 0; Offset += sizeof(Addr))
362  if ((Entry & 1) != 0) {
363  Rel.r_offset = Offset;
364  Relocs.push_back(Rel);
365  }
366  Base += (CHAR_BIT * sizeof(Entry) - 1) * sizeof(Addr);
367  }
368  }
369 
370  return Relocs;
371 }
372 
373 template <class ELFT>
375 ELFFile<ELFT>::android_relas(const Elf_Shdr &Sec) const {
376  // This function reads relocations in Android's packed relocation format,
377  // which is based on SLEB128 and delta encoding.
378  Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
379  if (!ContentsOrErr)
380  return ContentsOrErr.takeError();
381  ArrayRef<uint8_t> Content = *ContentsOrErr;
382  if (Content.size() < 4 || Content[0] != 'A' || Content[1] != 'P' ||
383  Content[2] != 'S' || Content[3] != '2')
384  return createError("invalid packed relocation header");
385  DataExtractor Data(Content, isLE(), ELFT::Is64Bits ? 8 : 4);
386  DataExtractor::Cursor Cur(/*Offset=*/4);
387 
388  uint64_t NumRelocs = Data.getSLEB128(Cur);
389  uint64_t Offset = Data.getSLEB128(Cur);
390  uint64_t Addend = 0;
391 
392  if (!Cur)
393  return std::move(Cur.takeError());
394 
395  std::vector<Elf_Rela> Relocs;
396  Relocs.reserve(NumRelocs);
397  while (NumRelocs) {
398  uint64_t NumRelocsInGroup = Data.getSLEB128(Cur);
399  if (!Cur)
400  return std::move(Cur.takeError());
401  if (NumRelocsInGroup > NumRelocs)
402  return createError("relocation group unexpectedly large");
403  NumRelocs -= NumRelocsInGroup;
404 
405  uint64_t GroupFlags = Data.getSLEB128(Cur);
406  bool GroupedByInfo = GroupFlags & ELF::RELOCATION_GROUPED_BY_INFO_FLAG;
407  bool GroupedByOffsetDelta = GroupFlags & ELF::RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG;
408  bool GroupedByAddend = GroupFlags & ELF::RELOCATION_GROUPED_BY_ADDEND_FLAG;
409  bool GroupHasAddend = GroupFlags & ELF::RELOCATION_GROUP_HAS_ADDEND_FLAG;
410 
411  uint64_t GroupOffsetDelta;
412  if (GroupedByOffsetDelta)
413  GroupOffsetDelta = Data.getSLEB128(Cur);
414 
415  uint64_t GroupRInfo;
416  if (GroupedByInfo)
417  GroupRInfo = Data.getSLEB128(Cur);
418 
419  if (GroupedByAddend && GroupHasAddend)
420  Addend += Data.getSLEB128(Cur);
421 
422  if (!GroupHasAddend)
423  Addend = 0;
424 
425  for (uint64_t I = 0; Cur && I != NumRelocsInGroup; ++I) {
426  Elf_Rela R;
427  Offset += GroupedByOffsetDelta ? GroupOffsetDelta : Data.getSLEB128(Cur);
428  R.r_offset = Offset;
429  R.r_info = GroupedByInfo ? GroupRInfo : Data.getSLEB128(Cur);
430  if (GroupHasAddend && !GroupedByAddend)
431  Addend += Data.getSLEB128(Cur);
432  R.r_addend = Addend;
433  Relocs.push_back(R);
434  }
435  if (!Cur)
436  return std::move(Cur.takeError());
437  }
438 
439  return Relocs;
440 }
441 
442 template <class ELFT>
443 std::string ELFFile<ELFT>::getDynamicTagAsString(unsigned Arch,
444  uint64_t Type) const {
445 #define DYNAMIC_STRINGIFY_ENUM(tag, value) \
446  case value: \
447  return #tag;
448 
449 #define DYNAMIC_TAG(n, v)
450  switch (Arch) {
451  case ELF::EM_AARCH64:
452  switch (Type) {
453 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
454 #include "llvm/BinaryFormat/DynamicTags.def"
455 #undef AARCH64_DYNAMIC_TAG
456  }
457  break;
458 
459  case ELF::EM_HEXAGON:
460  switch (Type) {
461 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
462 #include "llvm/BinaryFormat/DynamicTags.def"
463 #undef HEXAGON_DYNAMIC_TAG
464  }
465  break;
466 
467  case ELF::EM_MIPS:
468  switch (Type) {
469 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
470 #include "llvm/BinaryFormat/DynamicTags.def"
471 #undef MIPS_DYNAMIC_TAG
472  }
473  break;
474 
475  case ELF::EM_PPC:
476  switch (Type) {
477 #define PPC_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
478 #include "llvm/BinaryFormat/DynamicTags.def"
479 #undef PPC_DYNAMIC_TAG
480  }
481  break;
482 
483  case ELF::EM_PPC64:
484  switch (Type) {
485 #define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
486 #include "llvm/BinaryFormat/DynamicTags.def"
487 #undef PPC64_DYNAMIC_TAG
488  }
489  break;
490 
491  case ELF::EM_RISCV:
492  switch (Type) {
493 #define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
494 #include "llvm/BinaryFormat/DynamicTags.def"
495 #undef RISCV_DYNAMIC_TAG
496  }
497  break;
498  }
499 #undef DYNAMIC_TAG
500  switch (Type) {
501 // Now handle all dynamic tags except the architecture specific ones
502 #define AARCH64_DYNAMIC_TAG(name, value)
503 #define MIPS_DYNAMIC_TAG(name, value)
504 #define HEXAGON_DYNAMIC_TAG(name, value)
505 #define PPC_DYNAMIC_TAG(name, value)
506 #define PPC64_DYNAMIC_TAG(name, value)
507 #define RISCV_DYNAMIC_TAG(name, value)
508 // Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
509 #define DYNAMIC_TAG_MARKER(name, value)
510 #define DYNAMIC_TAG(name, value) case value: return #name;
511 #include "llvm/BinaryFormat/DynamicTags.def"
512 #undef DYNAMIC_TAG
513 #undef AARCH64_DYNAMIC_TAG
514 #undef MIPS_DYNAMIC_TAG
515 #undef HEXAGON_DYNAMIC_TAG
516 #undef PPC_DYNAMIC_TAG
517 #undef PPC64_DYNAMIC_TAG
518 #undef RISCV_DYNAMIC_TAG
519 #undef DYNAMIC_TAG_MARKER
520 #undef DYNAMIC_STRINGIFY_ENUM
521  default:
522  return "<unknown:>0x" + utohexstr(Type, true);
523  }
524 }
525 
526 template <class ELFT>
528  return getDynamicTagAsString(getHeader().e_machine, Type);
529 }
530 
531 template <class ELFT>
533  ArrayRef<Elf_Dyn> Dyn;
534 
535  auto ProgramHeadersOrError = program_headers();
536  if (!ProgramHeadersOrError)
537  return ProgramHeadersOrError.takeError();
538 
539  for (const Elf_Phdr &Phdr : *ProgramHeadersOrError) {
540  if (Phdr.p_type == ELF::PT_DYNAMIC) {
541  Dyn = makeArrayRef(
542  reinterpret_cast<const Elf_Dyn *>(base() + Phdr.p_offset),
543  Phdr.p_filesz / sizeof(Elf_Dyn));
544  break;
545  }
546  }
547 
548  // If we can't find the dynamic section in the program headers, we just fall
549  // back on the sections.
550  if (Dyn.empty()) {
551  auto SectionsOrError = sections();
552  if (!SectionsOrError)
553  return SectionsOrError.takeError();
554 
555  for (const Elf_Shdr &Sec : *SectionsOrError) {
556  if (Sec.sh_type == ELF::SHT_DYNAMIC) {
557  Expected<ArrayRef<Elf_Dyn>> DynOrError =
558  getSectionContentsAsArray<Elf_Dyn>(Sec);
559  if (!DynOrError)
560  return DynOrError.takeError();
561  Dyn = *DynOrError;
562  break;
563  }
564  }
565 
566  if (!Dyn.data())
567  return ArrayRef<Elf_Dyn>();
568  }
569 
570  if (Dyn.empty())
571  return createError("invalid empty dynamic section");
572 
573  if (Dyn.back().d_tag != ELF::DT_NULL)
574  return createError("dynamic sections must be DT_NULL terminated");
575 
576  return Dyn;
577 }
578 
579 template <class ELFT>
582  auto ProgramHeadersOrError = program_headers();
583  if (!ProgramHeadersOrError)
584  return ProgramHeadersOrError.takeError();
585 
587 
588  for (const Elf_Phdr &Phdr : *ProgramHeadersOrError)
589  if (Phdr.p_type == ELF::PT_LOAD)
590  LoadSegments.push_back(const_cast<Elf_Phdr *>(&Phdr));
591 
592  auto SortPred = [](const Elf_Phdr_Impl<ELFT> *A,
593  const Elf_Phdr_Impl<ELFT> *B) {
594  return A->p_vaddr < B->p_vaddr;
595  };
596  if (!llvm::is_sorted(LoadSegments, SortPred)) {
597  if (Error E =
598  WarnHandler("loadable segments are unsorted by virtual address"))
599  return std::move(E);
600  llvm::stable_sort(LoadSegments, SortPred);
601  }
602 
603  const Elf_Phdr *const *I = llvm::upper_bound(
604  LoadSegments, VAddr, [](uint64_t VAddr, const Elf_Phdr_Impl<ELFT> *Phdr) {
605  return VAddr < Phdr->p_vaddr;
606  });
607 
608  if (I == LoadSegments.begin())
609  return createError("virtual address is not in any segment: 0x" +
610  Twine::utohexstr(VAddr));
611  --I;
612  const Elf_Phdr &Phdr = **I;
613  uint64_t Delta = VAddr - Phdr.p_vaddr;
614  if (Delta >= Phdr.p_filesz)
615  return createError("virtual address is not in any segment: 0x" +
616  Twine::utohexstr(VAddr));
617 
618  uint64_t Offset = Phdr.p_offset + Delta;
619  if (Offset >= getBufSize())
620  return createError("can't map virtual address 0x" +
621  Twine::utohexstr(VAddr) + " to the segment with index " +
622  Twine(&Phdr - (*ProgramHeadersOrError).data() + 1) +
623  ": the segment ends at 0x" +
624  Twine::utohexstr(Phdr.p_offset + Phdr.p_filesz) +
625  ", which is greater than the file size (0x" +
626  Twine::utohexstr(getBufSize()) + ")");
627 
628  return base() + Offset;
629 }
630 
631 template <class ELFT>
633 ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec) const {
634  Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
635  if (!ContentsOrErr)
636  return ContentsOrErr.takeError();
637  ArrayRef<uint8_t> Content = *ContentsOrErr;
638  DataExtractor Data(Content, isLE(), ELFT::Is64Bits ? 8 : 4);
639  std::vector<BBAddrMap> FunctionEntries;
640 
641  DataExtractor::Cursor Cur(0);
642  Error ULEBSizeErr = Error::success();
643 
644  // Helper to extract and decode the next ULEB128 value as uint32_t.
645  // Returns zero and sets ULEBSizeErr if the ULEB128 value exceeds the uint32_t
646  // limit.
647  // Also returns zero if ULEBSizeErr is already in an error state.
648  auto ReadULEB128AsUInt32 = [&Data, &Cur, &ULEBSizeErr]() -> uint32_t {
649  // Bail out and do not extract data if ULEBSizeErr is already set.
650  if (ULEBSizeErr)
651  return 0;
652  uint64_t Offset = Cur.tell();
653  uint64_t Value = Data.getULEB128(Cur);
654  if (Value > UINT32_MAX) {
655  ULEBSizeErr = createError(
656  "ULEB128 value at offset 0x" + Twine::utohexstr(Offset) +
657  " exceeds UINT32_MAX (0x" + Twine::utohexstr(Value) + ")");
658  return 0;
659  }
660  return static_cast<uint32_t>(Value);
661  };
662 
663  while (!ULEBSizeErr && Cur && Cur.tell() < Content.size()) {
664  uintX_t Address = static_cast<uintX_t>(Data.getAddress(Cur));
665  uint32_t NumBlocks = ReadULEB128AsUInt32();
666  std::vector<BBAddrMap::BBEntry> BBEntries;
667  for (uint32_t BlockID = 0; !ULEBSizeErr && Cur && (BlockID < NumBlocks);
668  ++BlockID) {
669  uint32_t Offset = ReadULEB128AsUInt32();
670  uint32_t Size = ReadULEB128AsUInt32();
671  uint32_t Metadata = ReadULEB128AsUInt32();
672  BBEntries.push_back({Offset, Size, Metadata});
673  }
674  FunctionEntries.push_back({Address, BBEntries});
675  }
676  // Either Cur is in the error state, or ULEBSizeError is set (not both), but
677  // we join the two errors here to be safe.
678  if (!Cur || ULEBSizeErr)
679  return joinErrors(Cur.takeError(), std::move(ULEBSizeErr));
680  return FunctionEntries;
681 }
682 
683 template class llvm::object::ELFFile<ELF32LE>;
684 template class llvm::object::ELFFile<ELF32BE>;
685 template class llvm::object::ELFFile<ELF64LE>;
686 template class llvm::object::ELFFile<ELF64BE>;
llvm::ELF::SHT_HEX_ORDERED
@ SHT_HEX_ORDERED
Definition: ELF.h:1009
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::ELF::SHT_ANDROID_REL
@ SHT_ANDROID_REL
Definition: ELF.h:977
llvm::upper_bound
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1749
llvm::ELF::SHT_GNU_ATTRIBUTES
@ SHT_GNU_ATTRIBUTES
Definition: ELF.h:993
llvm::ELF::SHT_ARM_DEBUGOVERLAY
@ SHT_ARM_DEBUGOVERLAY
Definition: ELF.h:1007
llvm::ELF::SHT_PREINIT_ARRAY
@ SHT_PREINIT_ARRAY
Definition: ELF.h:968
llvm::object::ELFFile::android_relas
Expected< std::vector< Elf_Rela > > android_relas(const Elf_Shdr &Sec) const
Definition: ELF.cpp:375
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
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::ELF::EM_LOONGARCH
@ EM_LOONGARCH
Definition: ELF.h:322
Content
T Content
Definition: ELFObjHandler.cpp:88
llvm::ELF::SHT_GNU_versym
@ SHT_GNU_versym
Definition: ELF.h:997
llvm::ELF::EM_LANAI
@ EM_LANAI
Definition: ELF.h:318
llvm::ELF::SHT_SYMTAB_SHNDX
@ SHT_SYMTAB_SHNDX
Definition: ELF.h:970
llvm::ELF::SHT_STRTAB
@ SHT_STRTAB
Definition: ELF.h:957
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::ELF::SHT_MIPS_DWARF
@ SHT_MIPS_DWARF
Definition: ELF.h:1015
llvm::ELF::EM_SPARCV9
@ EM_SPARCV9
Definition: ELF.h:159
STRINGIFY_ENUM_CASE
#define STRINGIFY_ENUM_CASE(ns, name)
Definition: ELF.cpp:16
llvm::ELF::EM_AVR
@ EM_AVR
Definition: ELF.h:199
llvm::ELF::RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG
@ RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG
Definition: ELF.h:1735
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::ELF::SHT_FINI_ARRAY
@ SHT_FINI_ARRAY
Definition: ELF.h:967
llvm::ELF::SHT_LLVM_DEPENDENT_LIBRARIES
@ SHT_LLVM_DEPENDENT_LIBRARIES
Definition: ELF.h:983
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:159
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:161
uint
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint
Definition: README.txt:239
llvm::ELF::RELOCATION_GROUPED_BY_ADDEND_FLAG
@ RELOCATION_GROUPED_BY_ADDEND_FLAG
Definition: ELF.h:1736
llvm::ELF::SHT_ANDROID_RELR
@ SHT_ANDROID_RELR
Definition: ELF.h:992
llvm::DataExtractor::Cursor::takeError
Error takeError()
Return error contained inside this Cursor, if any.
Definition: DataExtractor.h:78
llvm::ELF::SHT_LLVM_PART_EHDR
@ SHT_LLVM_PART_EHDR
Definition: ELF.h:986
llvm::ArrayRef::back
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:173
llvm::ELF::EM_68K
@ EM_68K
Definition: ELF.h:137
ELF.h
llvm::ELF::EM_ARM
@ EM_ARM
Definition: ELF.h:156
llvm::ELF::SHT_LLVM_CALL_GRAPH_PROFILE
@ SHT_LLVM_CALL_GRAPH_PROFILE
Definition: ELF.h:989
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::ELF::SHT_HASH
@ SHT_HASH
Definition: ELF.h:959
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::object::ELFFile::decodeBBAddrMap
Expected< std::vector< BBAddrMap > > decodeBBAddrMap(const Elf_Shdr &Sec) const
Definition: ELF.cpp:633
llvm::ELF::SHT_ANDROID_RELA
@ SHT_ANDROID_RELA
Definition: ELF.h:978
llvm::ELF::SHT_SHLIB
@ SHT_SHLIB
Definition: ELF.h:964
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::ELF::EM_RISCV
@ EM_RISCV
Definition: ELF.h:317
llvm::ELF::EM_IAMCU
@ EM_IAMCU
Definition: ELF.h:139
llvm::ELF::SHT_LLVM_ODRTAB
@ SHT_LLVM_ODRTAB
Definition: ELF.h:979
llvm::ELF::SHT_MIPS_ABIFLAGS
@ SHT_MIPS_ABIFLAGS
Definition: ELF.h:1016
llvm::ELF::SHT_NOBITS
@ SHT_NOBITS
Definition: ELF.h:962
llvm::ELF::PT_LOAD
@ PT_LOAD
Definition: ELF.h:1334
llvm::ELF::EM_BPF
@ EM_BPF
Definition: ELF.h:319
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::ELF::SHT_DYNAMIC
@ SHT_DYNAMIC
Definition: ELF.h:960
llvm::ELF::EM_MIPS_RS3_LE
@ EM_MIPS_RS3_LE
Definition: ELF.h:143
llvm::ELF::SHT_LLVM_SYMPART
@ SHT_LLVM_SYMPART
Definition: ELF.h:985
llvm::ELF::SHT_MSP430_ATTRIBUTES
@ SHT_MSP430_ATTRIBUTES
Definition: ELF.h:1018
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::Elf_Phdr_Impl
Definition: ELFTypes.h:33
llvm::Twine::utohexstr
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:408
llvm::ELF::EM_CSKY
@ EM_CSKY
Definition: ELF.h:321
llvm::ELF::SHT_NULL
@ SHT_NULL
Definition: ELF.h:954
llvm::ELF::PT_DYNAMIC
@ PT_DYNAMIC
Definition: ELF.h:1335
uint64_t
ELF.h
llvm::ELF::SHT_SYMTAB
@ SHT_SYMTAB
Definition: ELF.h:956
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::ELF::SHT_ARM_EXIDX
@ SHT_ARM_EXIDX
Definition: ELF.h:1002
llvm::ELF::EM_PPC64
@ EM_PPC64
Definition: ELF.h:149
llvm::ELF::EM_SPARC32PLUS
@ EM_SPARC32PLUS
Definition: ELF.h:146
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::EM_MIPS
@ EM_MIPS
Definition: ELF.h:141
llvm::ELF::EM_ARC_COMPACT2
@ EM_ARC_COMPACT2
Definition: ELF.h:291
llvm::object::ELFFile::toMappedAddr
Expected< const uint8_t * > toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition: ELF.cpp:581
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::ELF::SHT_LLVM_ADDRSIG
@ SHT_LLVM_ADDRSIG
Definition: ELF.h:981
llvm::joinErrors
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:426
llvm::object::getELFSectionTypeName
StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type)
llvm::ELF::SHT_LLVM_BB_ADDR_MAP
@ SHT_LLVM_BB_ADDR_MAP
Definition: ELF.h:988
llvm::object::ELFFile::dynamicEntries
Expected< Elf_Dyn_Range > dynamicEntries() const
Definition: ELF.cpp:532
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::ELF::SHT_MIPS_OPTIONS
@ SHT_MIPS_OPTIONS
Definition: ELF.h:1014
llvm::ELF::SHT_RELR
@ SHT_RELR
Definition: ELF.h:973
llvm::DataExtractor::Cursor
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:54
llvm::ELF::SHT_RELA
@ SHT_RELA
Definition: ELF.h:958
llvm::ELF::EM_AMDGPU
@ EM_AMDGPU
Definition: ELF.h:316
llvm::ELF::SHT_X86_64_UNWIND
@ SHT_X86_64_UNWIND
Definition: ELF.h:1011
llvm::ArrayRef< uint8_t >
llvm::ELF::RELOCATION_GROUPED_BY_INFO_FLAG
@ RELOCATION_GROUPED_BY_INFO_FLAG
Definition: ELF.h:1734
llvm::ELF::SHT_NOTE
@ SHT_NOTE
Definition: ELF.h:961
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::ELF::SHT_ARM_OVERLAYSECTION
@ SHT_ARM_OVERLAYSECTION
Definition: ELF.h:1008
uint32_t
llvm::object::ELFFile::getDynamicTagAsString
std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const
Definition: ELF.cpp:443
llvm::ELF::SHT_GROUP
@ SHT_GROUP
Definition: ELF.h:969
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::stable_sort
void stable_sort(R &&Range)
Definition: STLExtras.h:1761
llvm::ELF::SHT_GNU_verdef
@ SHT_GNU_verdef
Definition: ELF.h:995
llvm::ELF::SHT_ARM_PREEMPTMAP
@ SHT_ARM_PREEMPTMAP
Definition: ELF.h:1004
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::ELF::EM_S390
@ EM_S390
Definition: ELF.h:150
llvm::ELF::SHT_GNU_verneed
@ SHT_GNU_verneed
Definition: ELF.h:996
DataExtractor.h
llvm::ELF::SHT_REL
@ SHT_REL
Definition: ELF.h:963
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::is_sorted
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition: STLExtras.h:1697
llvm::ELF::SHT_INIT_ARRAY
@ SHT_INIT_ARRAY
Definition: ELF.h:966
llvm::object::getELFRelativeRelocationType
uint32_t getELFRelativeRelocationType(uint32_t Machine)
Definition: ELF.cpp:184
llvm::ELF::EM_SPARC
@ EM_SPARC
Definition: ELF.h:135
llvm::ELF::SHT_GNU_HASH
@ SHT_GNU_HASH
Definition: ELF.h:994
llvm::ELF::SHT_LLVM_LINKER_OPTIONS
@ SHT_LLVM_LINKER_OPTIONS
Definition: ELF.h:980
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::ELF::SHT_DYNSYM
@ SHT_DYNSYM
Definition: ELF.h:965
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:597
llvm::DataExtractor
Definition: DataExtractor.h:41
Machine
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:369
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::ELF::EM_X86_64
@ EM_X86_64
Definition: ELF.h:178
llvm::object::ELFFile::decode_relrs
std::vector< Elf_Rel > decode_relrs(Elf_Relr_Range relrs) const
Definition: ELF.cpp:311
llvm::ELF::EM_MSP430
@ EM_MSP430
Definition: ELF.h:222
llvm::ELF::SHT_LLVM_PART_PHDR
@ SHT_LLVM_PART_PHDR
Definition: ELF.h:987
llvm::object::createError
Error createError(const Twine &Err)
Definition: Error.h:84
llvm::ELF::RELOCATION_GROUP_HAS_ADDEND_FLAG
@ RELOCATION_GROUP_HAS_ADDEND_FLAG
Definition: ELF.h:1737
llvm::ELF::SHT_MIPS_REGINFO
@ SHT_MIPS_REGINFO
Definition: ELF.h:1013
llvm::ELF::EM_VE
@ EM_VE
Definition: ELF.h:320
llvm::ELF::EM_AARCH64
@ EM_AARCH64
Definition: ELF.h:280
llvm::ELF::EM_ARC_COMPACT
@ EM_ARC_COMPACT
Definition: ELF.h:209
llvm::ELF::EM_386
@ EM_386
Definition: ELF.h:136
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::object::ELFFile
Definition: ELF.h:94
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::ELF::SHT_ARM_ATTRIBUTES
@ SHT_ARM_ATTRIBUTES
Definition: ELF.h:1006