LLVM 22.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"
15
16using namespace llvm;
17using namespace object;
18
19#define STRINGIFY_ENUM_CASE(ns, name) \
20 case ns::name: \
21 return #name;
22
23#define ELF_RELOC(name, value) STRINGIFY_ENUM_CASE(ELF, name)
24
26 uint32_t Type) {
27 switch (Machine) {
28 case ELF::EM_68K:
29 switch (Type) {
30#include "llvm/BinaryFormat/ELFRelocs/M68k.def"
31 default:
32 break;
33 }
34 break;
35 case ELF::EM_X86_64:
36 switch (Type) {
37#include "llvm/BinaryFormat/ELFRelocs/x86_64.def"
38 default:
39 break;
40 }
41 break;
42 case ELF::EM_386:
43 case ELF::EM_IAMCU:
44 switch (Type) {
45#include "llvm/BinaryFormat/ELFRelocs/i386.def"
46 default:
47 break;
48 }
49 break;
50 case ELF::EM_MIPS:
51 switch (Type) {
52#include "llvm/BinaryFormat/ELFRelocs/Mips.def"
53 default:
54 break;
55 }
56 break;
57 case ELF::EM_AARCH64:
58 switch (Type) {
59#include "llvm/BinaryFormat/ELFRelocs/AArch64.def"
60 default:
61 break;
62 }
63 break;
64 case ELF::EM_ARM:
65 switch (Type) {
66#include "llvm/BinaryFormat/ELFRelocs/ARM.def"
67 default:
68 break;
69 }
70 break;
73 switch (Type) {
74#include "llvm/BinaryFormat/ELFRelocs/ARC.def"
75 default:
76 break;
77 }
78 break;
79 case ELF::EM_AVR:
80 switch (Type) {
81#include "llvm/BinaryFormat/ELFRelocs/AVR.def"
82 default:
83 break;
84 }
85 break;
86 case ELF::EM_HEXAGON:
87 switch (Type) {
88#include "llvm/BinaryFormat/ELFRelocs/Hexagon.def"
89 default:
90 break;
91 }
92 break;
93 case ELF::EM_LANAI:
94 switch (Type) {
95#include "llvm/BinaryFormat/ELFRelocs/Lanai.def"
96 default:
97 break;
98 }
99 break;
100 case ELF::EM_PPC:
101 switch (Type) {
102#include "llvm/BinaryFormat/ELFRelocs/PowerPC.def"
103 default:
104 break;
105 }
106 break;
107 case ELF::EM_PPC64:
108 switch (Type) {
109#include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
110 default:
111 break;
112 }
113 break;
114 case ELF::EM_RISCV:
115 switch (Type) {
116#include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
117 default:
118 break;
119 }
120 break;
121 case ELF::EM_S390:
122 switch (Type) {
123#include "llvm/BinaryFormat/ELFRelocs/SystemZ.def"
124 default:
125 break;
126 }
127 break;
128 case ELF::EM_SPARC:
130 case ELF::EM_SPARCV9:
131 switch (Type) {
132#include "llvm/BinaryFormat/ELFRelocs/Sparc.def"
133 default:
134 break;
135 }
136 break;
137 case ELF::EM_AMDGPU:
138 switch (Type) {
139#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
140 default:
141 break;
142 }
143 break;
144 case ELF::EM_BPF:
145 switch (Type) {
146#include "llvm/BinaryFormat/ELFRelocs/BPF.def"
147 default:
148 break;
149 }
150 break;
151 case ELF::EM_MSP430:
152 switch (Type) {
153#include "llvm/BinaryFormat/ELFRelocs/MSP430.def"
154 default:
155 break;
156 }
157 break;
158 case ELF::EM_VE:
159 switch (Type) {
160#include "llvm/BinaryFormat/ELFRelocs/VE.def"
161 default:
162 break;
163 }
164 break;
165 case ELF::EM_CSKY:
166 switch (Type) {
167#include "llvm/BinaryFormat/ELFRelocs/CSKY.def"
168 default:
169 break;
170 }
171 break;
173 switch (Type) {
174#include "llvm/BinaryFormat/ELFRelocs/LoongArch.def"
175 default:
176 break;
177 }
178 break;
179 case ELF::EM_XTENSA:
180 switch (Type) {
181#include "llvm/BinaryFormat/ELFRelocs/Xtensa.def"
182 default:
183 break;
184 }
185 break;
186 default:
187 break;
188 }
189 return "Unknown";
190}
191
192#undef ELF_RELOC
193
195 switch (Machine) {
196 case ELF::EM_X86_64:
197 return ELF::R_X86_64_RELATIVE;
198 case ELF::EM_386:
199 case ELF::EM_IAMCU:
200 return ELF::R_386_RELATIVE;
201 case ELF::EM_MIPS:
202 break;
203 case ELF::EM_AARCH64:
204 return ELF::R_AARCH64_RELATIVE;
205 case ELF::EM_ARM:
206 return ELF::R_ARM_RELATIVE;
209 return ELF::R_ARC_RELATIVE;
210 case ELF::EM_AVR:
211 break;
212 case ELF::EM_HEXAGON:
213 return ELF::R_HEX_RELATIVE;
214 case ELF::EM_LANAI:
215 break;
216 case ELF::EM_PPC:
217 break;
218 case ELF::EM_PPC64:
219 return ELF::R_PPC64_RELATIVE;
220 case ELF::EM_RISCV:
221 return ELF::R_RISCV_RELATIVE;
222 case ELF::EM_S390:
223 return ELF::R_390_RELATIVE;
224 case ELF::EM_SPARC:
226 case ELF::EM_SPARCV9:
227 return ELF::R_SPARC_RELATIVE;
228 case ELF::EM_CSKY:
229 return ELF::R_CKCORE_RELATIVE;
230 case ELF::EM_VE:
231 return ELF::R_VE_RELATIVE;
232 case ELF::EM_AMDGPU:
233 break;
234 case ELF::EM_BPF:
235 break;
237 return ELF::R_LARCH_RELATIVE;
238 default:
239 break;
240 }
241 return 0;
242}
243
245 switch (Machine) {
246 case ELF::EM_ARM:
247 switch (Type) {
248 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_EXIDX);
249 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_PREEMPTMAP);
250 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_ATTRIBUTES);
251 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_DEBUGOVERLAY);
252 STRINGIFY_ENUM_CASE(ELF, SHT_ARM_OVERLAYSECTION);
253 }
254 break;
255 case ELF::EM_HEXAGON:
256 switch (Type) {
257 STRINGIFY_ENUM_CASE(ELF, SHT_HEX_ORDERED);
258 STRINGIFY_ENUM_CASE(ELF, SHT_HEXAGON_ATTRIBUTES);
259 }
260 break;
261 case ELF::EM_X86_64:
262 switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_X86_64_UNWIND); }
263 break;
264 case ELF::EM_MIPS:
266 switch (Type) {
267 STRINGIFY_ENUM_CASE(ELF, SHT_MIPS_REGINFO);
268 STRINGIFY_ENUM_CASE(ELF, SHT_MIPS_OPTIONS);
269 STRINGIFY_ENUM_CASE(ELF, SHT_MIPS_DWARF);
270 STRINGIFY_ENUM_CASE(ELF, SHT_MIPS_ABIFLAGS);
271 }
272 break;
273 case ELF::EM_MSP430:
274 switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_MSP430_ATTRIBUTES); }
275 break;
276 case ELF::EM_RISCV:
277 switch (Type) { STRINGIFY_ENUM_CASE(ELF, SHT_RISCV_ATTRIBUTES); }
278 break;
279 case ELF::EM_AARCH64:
280 switch (Type) {
281 STRINGIFY_ENUM_CASE(ELF, SHT_AARCH64_AUTH_RELR);
282 STRINGIFY_ENUM_CASE(ELF, SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC);
283 STRINGIFY_ENUM_CASE(ELF, SHT_AARCH64_MEMTAG_GLOBALS_STATIC);
284 }
285 default:
286 break;
287 }
288
289 switch (Type) {
290 STRINGIFY_ENUM_CASE(ELF, SHT_NULL);
291 STRINGIFY_ENUM_CASE(ELF, SHT_PROGBITS);
292 STRINGIFY_ENUM_CASE(ELF, SHT_SYMTAB);
293 STRINGIFY_ENUM_CASE(ELF, SHT_STRTAB);
294 STRINGIFY_ENUM_CASE(ELF, SHT_RELA);
295 STRINGIFY_ENUM_CASE(ELF, SHT_HASH);
296 STRINGIFY_ENUM_CASE(ELF, SHT_DYNAMIC);
297 STRINGIFY_ENUM_CASE(ELF, SHT_NOTE);
298 STRINGIFY_ENUM_CASE(ELF, SHT_NOBITS);
299 STRINGIFY_ENUM_CASE(ELF, SHT_REL);
300 STRINGIFY_ENUM_CASE(ELF, SHT_SHLIB);
301 STRINGIFY_ENUM_CASE(ELF, SHT_DYNSYM);
302 STRINGIFY_ENUM_CASE(ELF, SHT_INIT_ARRAY);
303 STRINGIFY_ENUM_CASE(ELF, SHT_FINI_ARRAY);
304 STRINGIFY_ENUM_CASE(ELF, SHT_PREINIT_ARRAY);
305 STRINGIFY_ENUM_CASE(ELF, SHT_GROUP);
306 STRINGIFY_ENUM_CASE(ELF, SHT_SYMTAB_SHNDX);
307 STRINGIFY_ENUM_CASE(ELF, SHT_RELR);
308 STRINGIFY_ENUM_CASE(ELF, SHT_CREL);
309 STRINGIFY_ENUM_CASE(ELF, SHT_ANDROID_REL);
310 STRINGIFY_ENUM_CASE(ELF, SHT_ANDROID_RELA);
311 STRINGIFY_ENUM_CASE(ELF, SHT_ANDROID_RELR);
312 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_ODRTAB);
313 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_LINKER_OPTIONS);
314 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_CALL_GRAPH_PROFILE);
315 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_ADDRSIG);
316 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_DEPENDENT_LIBRARIES);
317 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_SYMPART);
318 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_PART_EHDR);
319 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_PART_PHDR);
320 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_BB_ADDR_MAP);
321 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_OFFLOADING);
322 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_LTO);
323 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_JT_SIZES)
324 STRINGIFY_ENUM_CASE(ELF, SHT_LLVM_CFI_JUMP_TABLE)
325 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_SFRAME);
326 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_ATTRIBUTES);
327 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_HASH);
328 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verdef);
329 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_verneed);
330 STRINGIFY_ENUM_CASE(ELF, SHT_GNU_versym);
331 default:
332 return "Unknown";
333 }
334}
335
336template <class ELFT>
337std::vector<typename ELFT::Rel>
338ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
339 // This function decodes the contents of an SHT_RELR packed relocation
340 // section.
341 //
342 // Proposal for adding SHT_RELR sections to generic-abi is here:
343 // https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg
344 //
345 // The encoded sequence of Elf64_Relr entries in a SHT_RELR section looks
346 // like [ AAAAAAAA BBBBBBB1 BBBBBBB1 ... AAAAAAAA BBBBBB1 ... ]
347 //
348 // i.e. start with an address, followed by any number of bitmaps. The address
349 // entry encodes 1 relocation. The subsequent bitmap entries encode up to 63
350 // relocations each, at subsequent offsets following the last address entry.
351 //
352 // The bitmap entries must have 1 in the least significant bit. The assumption
353 // here is that an address cannot have 1 in lsb. Odd addresses are not
354 // supported.
355 //
356 // Excluding the least significant bit in the bitmap, each non-zero bit in
357 // the bitmap represents a relocation to be applied to a corresponding machine
358 // word that follows the base address word. The second least significant bit
359 // represents the machine word immediately following the initial address, and
360 // each bit that follows represents the next word, in linear order. As such,
361 // a single bitmap can encode up to 31 relocations in a 32-bit object, and
362 // 63 relocations in a 64-bit object.
363 //
364 // This encoding has a couple of interesting properties:
365 // 1. Looking at any entry, it is clear whether it's an address or a bitmap:
366 // even means address, odd means bitmap.
367 // 2. Just a simple list of addresses is a valid encoding.
368
369 Elf_Rel Rel;
370 Rel.r_info = 0;
371 Rel.setType(getRelativeRelocationType(), false);
372 std::vector<Elf_Rel> Relocs;
373
374 // Word type: uint32_t for Elf32, and uint64_t for Elf64.
375 using Addr = typename ELFT::uint;
376
377 Addr Base = 0;
378 for (Elf_Relr R : relrs) {
379 typename ELFT::uint Entry = R;
380 if ((Entry & 1) == 0) {
381 // Even entry: encodes the offset for next relocation.
382 Rel.r_offset = Entry;
383 Relocs.push_back(Rel);
384 // Set base offset for subsequent bitmap entries.
385 Base = Entry + sizeof(Addr);
386 } else {
387 // Odd entry: encodes bitmap for relocations starting at base.
388 for (Addr Offset = Base; (Entry >>= 1) != 0; Offset += sizeof(Addr))
389 if ((Entry & 1) != 0) {
390 Rel.r_offset = Offset;
391 Relocs.push_back(Rel);
392 }
393 Base += (CHAR_BIT * sizeof(Entry) - 1) * sizeof(Addr);
394 }
395 }
396
397 return Relocs;
398}
399
400template <class ELFT>
403 DataExtractor Data(Content, isLE(), sizeof(typename ELFT::Addr));
404 Error Err = Error::success();
405 uint64_t Hdr = 0;
406 Hdr = Data.getULEB128(&Hdr, &Err);
407 if (Err)
408 return Err;
409 return Hdr;
410}
411
412template <class ELFT>
415 std::vector<Elf_Rel> Rels;
416 std::vector<Elf_Rela> Relas;
417 size_t I = 0;
418 bool HasAddend;
419 Error Err = object::decodeCrel<ELFT::Is64Bits>(
420 Content,
421 [&](uint64_t Count, bool HasA) {
422 HasAddend = HasA;
423 if (HasAddend)
424 Relas.resize(Count);
425 else
426 Rels.resize(Count);
427 },
428 [&](Elf_Crel Crel) {
429 if (HasAddend) {
430 Relas[I].r_offset = Crel.r_offset;
431 Relas[I].setSymbolAndType(Crel.r_symidx, Crel.r_type, false);
432 Relas[I++].r_addend = Crel.r_addend;
433 } else {
434 Rels[I].r_offset = Crel.r_offset;
435 Rels[I++].setSymbolAndType(Crel.r_symidx, Crel.r_type, false);
436 }
437 });
438 if (Err)
439 return std::move(Err);
440 return std::make_pair(std::move(Rels), std::move(Relas));
441}
442
443template <class ELFT>
445ELFFile<ELFT>::crels(const Elf_Shdr &Sec) const {
446 Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
447 if (!ContentsOrErr)
448 return ContentsOrErr.takeError();
449 return decodeCrel(*ContentsOrErr);
450}
451
452template <class ELFT>
454ELFFile<ELFT>::android_relas(const Elf_Shdr &Sec) const {
455 // This function reads relocations in Android's packed relocation format,
456 // which is based on SLEB128 and delta encoding.
457 Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
458 if (!ContentsOrErr)
459 return ContentsOrErr.takeError();
460 ArrayRef<uint8_t> Content = *ContentsOrErr;
461 if (Content.size() < 4 || Content[0] != 'A' || Content[1] != 'P' ||
462 Content[2] != 'S' || Content[3] != '2')
463 return createError("invalid packed relocation header");
464 DataExtractor Data(Content, isLE(), ELFT::Is64Bits ? 8 : 4);
465 DataExtractor::Cursor Cur(/*Offset=*/4);
466
467 uint64_t NumRelocs = Data.getSLEB128(Cur);
468 uint64_t Offset = Data.getSLEB128(Cur);
469 uint64_t Addend = 0;
470
471 if (!Cur)
472 return std::move(Cur.takeError());
473
474 std::vector<Elf_Rela> Relocs;
475 Relocs.reserve(NumRelocs);
476 while (NumRelocs) {
477 uint64_t NumRelocsInGroup = Data.getSLEB128(Cur);
478 if (!Cur)
479 return std::move(Cur.takeError());
480 if (NumRelocsInGroup > NumRelocs)
481 return createError("relocation group unexpectedly large");
482 NumRelocs -= NumRelocsInGroup;
483
484 uint64_t GroupFlags = Data.getSLEB128(Cur);
485 bool GroupedByInfo = GroupFlags & ELF::RELOCATION_GROUPED_BY_INFO_FLAG;
486 bool GroupedByOffsetDelta = GroupFlags & ELF::RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG;
487 bool GroupedByAddend = GroupFlags & ELF::RELOCATION_GROUPED_BY_ADDEND_FLAG;
488 bool GroupHasAddend = GroupFlags & ELF::RELOCATION_GROUP_HAS_ADDEND_FLAG;
489
490 uint64_t GroupOffsetDelta;
491 if (GroupedByOffsetDelta)
492 GroupOffsetDelta = Data.getSLEB128(Cur);
493
494 uint64_t GroupRInfo;
495 if (GroupedByInfo)
496 GroupRInfo = Data.getSLEB128(Cur);
497
498 if (GroupedByAddend && GroupHasAddend)
499 Addend += Data.getSLEB128(Cur);
500
501 if (!GroupHasAddend)
502 Addend = 0;
503
504 for (uint64_t I = 0; Cur && I != NumRelocsInGroup; ++I) {
505 Elf_Rela R;
506 Offset += GroupedByOffsetDelta ? GroupOffsetDelta : Data.getSLEB128(Cur);
507 R.r_offset = Offset;
508 R.r_info = GroupedByInfo ? GroupRInfo : Data.getSLEB128(Cur);
509 if (GroupHasAddend && !GroupedByAddend)
510 Addend += Data.getSLEB128(Cur);
511 R.r_addend = Addend;
512 Relocs.push_back(R);
513 }
514 if (!Cur)
515 return std::move(Cur.takeError());
516 }
517
518 return Relocs;
519}
520
521template <class ELFT>
522std::string ELFFile<ELFT>::getDynamicTagAsString(unsigned Arch,
523 uint64_t Type) const {
524#define DYNAMIC_STRINGIFY_ENUM(tag, value) \
525 case value: \
526 return #tag;
527
528#define DYNAMIC_TAG(n, v)
529 switch (Arch) {
530 case ELF::EM_AARCH64:
531 switch (Type) {
532#define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
533#include "llvm/BinaryFormat/DynamicTags.def"
534#undef AARCH64_DYNAMIC_TAG
535 }
536 break;
537
538 case ELF::EM_HEXAGON:
539 switch (Type) {
540#define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
541#include "llvm/BinaryFormat/DynamicTags.def"
542#undef HEXAGON_DYNAMIC_TAG
543 }
544 break;
545
546 case ELF::EM_MIPS:
547 switch (Type) {
548#define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
549#include "llvm/BinaryFormat/DynamicTags.def"
550#undef MIPS_DYNAMIC_TAG
551 }
552 break;
553
554 case ELF::EM_PPC:
555 switch (Type) {
556#define PPC_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
557#include "llvm/BinaryFormat/DynamicTags.def"
558#undef PPC_DYNAMIC_TAG
559 }
560 break;
561
562 case ELF::EM_PPC64:
563 switch (Type) {
564#define PPC64_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
565#include "llvm/BinaryFormat/DynamicTags.def"
566#undef PPC64_DYNAMIC_TAG
567 }
568 break;
569
570 case ELF::EM_RISCV:
571 switch (Type) {
572#define RISCV_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
573#include "llvm/BinaryFormat/DynamicTags.def"
574#undef RISCV_DYNAMIC_TAG
575 }
576 break;
577 }
578#undef DYNAMIC_TAG
579 switch (Type) {
580// Now handle all dynamic tags except the architecture specific ones
581#define AARCH64_DYNAMIC_TAG(name, value)
582#define MIPS_DYNAMIC_TAG(name, value)
583#define HEXAGON_DYNAMIC_TAG(name, value)
584#define PPC_DYNAMIC_TAG(name, value)
585#define PPC64_DYNAMIC_TAG(name, value)
586#define RISCV_DYNAMIC_TAG(name, value)
587// Also ignore marker tags such as DT_HIOS (maps to DT_VERNEEDNUM), etc.
588#define DYNAMIC_TAG_MARKER(name, value)
589#define DYNAMIC_TAG(name, value) case value: return #name;
590#include "llvm/BinaryFormat/DynamicTags.def"
591#undef DYNAMIC_TAG
592#undef AARCH64_DYNAMIC_TAG
593#undef MIPS_DYNAMIC_TAG
594#undef HEXAGON_DYNAMIC_TAG
595#undef PPC_DYNAMIC_TAG
596#undef PPC64_DYNAMIC_TAG
597#undef RISCV_DYNAMIC_TAG
598#undef DYNAMIC_TAG_MARKER
599#undef DYNAMIC_STRINGIFY_ENUM
600 default:
601 return "<unknown:>0x" + utohexstr(Type, true);
602 }
603}
604
605template <class ELFT>
607 return getDynamicTagAsString(getHeader().e_machine, Type);
608}
609
610template <class ELFT>
613
614 auto ProgramHeadersOrError = program_headers();
615 if (!ProgramHeadersOrError)
616 return ProgramHeadersOrError.takeError();
617
618 for (const Elf_Phdr &Phdr : *ProgramHeadersOrError) {
619 if (Phdr.p_type == ELF::PT_DYNAMIC) {
620 const uint8_t *DynOffset = base() + Phdr.p_offset;
621 if (DynOffset > end())
622 return createError(
623 "dynamic section offset past file size: corrupted ELF");
624 Dyn = ArrayRef(reinterpret_cast<const Elf_Dyn *>(DynOffset),
625 Phdr.p_filesz / sizeof(Elf_Dyn));
626 break;
627 }
628 }
629
630 // If we can't find the dynamic section in the program headers, we just fall
631 // back on the sections.
632 if (Dyn.empty()) {
633 auto SectionsOrError = sections();
634 if (!SectionsOrError)
635 return SectionsOrError.takeError();
636
637 for (const Elf_Shdr &Sec : *SectionsOrError) {
638 if (Sec.sh_type == ELF::SHT_DYNAMIC) {
639 Expected<ArrayRef<Elf_Dyn>> DynOrError =
640 getSectionContentsAsArray<Elf_Dyn>(Sec);
641 if (!DynOrError)
642 return DynOrError.takeError();
643 Dyn = *DynOrError;
644 break;
645 }
646 }
647
648 if (!Dyn.data())
649 return ArrayRef<Elf_Dyn>();
650 }
651
652 if (Dyn.empty())
653 return createError("invalid empty dynamic section");
654
655 if (Dyn.back().d_tag != ELF::DT_NULL)
656 return createError("dynamic sections must be DT_NULL terminated");
657
658 return Dyn;
659}
660
661template <class ELFT>
664 auto ProgramHeadersOrError = program_headers();
665 if (!ProgramHeadersOrError)
666 return ProgramHeadersOrError.takeError();
667
669
670 for (const Elf_Phdr &Phdr : *ProgramHeadersOrError)
671 if (Phdr.p_type == ELF::PT_LOAD)
672 LoadSegments.push_back(const_cast<Elf_Phdr *>(&Phdr));
673
674 auto SortPred = [](const Elf_Phdr_Impl<ELFT> *A,
675 const Elf_Phdr_Impl<ELFT> *B) {
676 return A->p_vaddr < B->p_vaddr;
677 };
678 if (!llvm::is_sorted(LoadSegments, SortPred)) {
679 if (Error E =
680 WarnHandler("loadable segments are unsorted by virtual address"))
681 return std::move(E);
682 llvm::stable_sort(LoadSegments, SortPred);
683 }
684
685 const Elf_Phdr *const *I = llvm::upper_bound(
686 LoadSegments, VAddr, [](uint64_t VAddr, const Elf_Phdr_Impl<ELFT> *Phdr) {
687 return VAddr < Phdr->p_vaddr;
688 });
689
690 if (I == LoadSegments.begin())
691 return createError("virtual address is not in any segment: 0x" +
692 Twine::utohexstr(VAddr));
693 --I;
694 const Elf_Phdr &Phdr = **I;
695 uint64_t Delta = VAddr - Phdr.p_vaddr;
696 if (Delta >= Phdr.p_filesz)
697 return createError("virtual address is not in any segment: 0x" +
698 Twine::utohexstr(VAddr));
699
700 uint64_t Offset = Phdr.p_offset + Delta;
701 if (Offset >= getBufSize())
702 return createError("can't map virtual address 0x" +
703 Twine::utohexstr(VAddr) + " to the segment with index " +
704 Twine(&Phdr - (*ProgramHeadersOrError).data() + 1) +
705 ": the segment ends at 0x" +
706 Twine::utohexstr(Phdr.p_offset + Phdr.p_filesz) +
707 ", which is greater than the file size (0x" +
708 Twine::utohexstr(getBufSize()) + ")");
709
710 return base() + Offset;
711}
712
713// Helper to extract and decode the next ULEB128 value as unsigned int.
714// Returns zero and sets ULEBSizeErr if the ULEB128 value exceeds the unsigned
715// int limit.
716// Also returns zero if ULEBSizeErr is already in an error state.
717// ULEBSizeErr is an out variable if an error occurs.
718template <typename IntTy, std::enable_if_t<std::is_unsigned_v<IntTy>, int> = 0>
720 Error &ULEBSizeErr) {
721 // Bail out and do not extract data if ULEBSizeErr is already set.
722 if (ULEBSizeErr)
723 return 0;
724 uint64_t Offset = Cur.tell();
725 uint64_t Value = Data.getULEB128(Cur);
726 if (Value > std::numeric_limits<IntTy>::max()) {
727 ULEBSizeErr = createError("ULEB128 value at offset 0x" +
728 Twine::utohexstr(Offset) + " exceeds UINT" +
729 Twine(std::numeric_limits<IntTy>::digits) +
730 "_MAX (0x" + Twine::utohexstr(Value) + ")");
731 return 0;
732 }
733 return static_cast<IntTy>(Value);
734}
735
736template <typename ELFT>
739 const typename ELFFile<ELFT>::Elf_Shdr &Sec,
740 const typename ELFFile<ELFT>::Elf_Shdr *RelaSec,
741 std::vector<PGOAnalysisMap> *PGOAnalyses) {
742 bool IsRelocatable = EF.getHeader().e_type == ELF::ET_REL;
743
744 // This DenseMap maps the offset of each function (the location of the
745 // reference to the function in the SHT_LLVM_BB_ADDR_MAP section) to the
746 // addend (the location of the function in the text section).
747 llvm::DenseMap<uint64_t, uint64_t> FunctionOffsetTranslations;
748 if (IsRelocatable && RelaSec) {
749 assert(RelaSec &&
750 "Can't read a SHT_LLVM_BB_ADDR_MAP section in a relocatable "
751 "object file without providing a relocation section.");
752 if (RelaSec->sh_type == ELF::SHT_CREL) {
754 if (!Relas)
755 return createError("unable to read CREL relocations for section " +
756 describe(EF, Sec) + ": " +
757 toString(Relas.takeError()));
758 for (typename ELFFile<ELFT>::Elf_Rela Rela : std::get<1>(*Relas)) {
759 FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend;
760 }
761 } else {
763 EF.relas(*RelaSec);
764 if (!Relas)
765 return createError("unable to read relocations for section " +
766 describe(EF, Sec) + ": " +
767 toString(Relas.takeError()));
768 for (typename ELFFile<ELFT>::Elf_Rela Rela : *Relas)
769 FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend;
770 }
771 }
772 auto GetAddressForRelocation =
773 [&](unsigned RelocationOffsetInSection) -> Expected<unsigned> {
774 auto FOTIterator =
775 FunctionOffsetTranslations.find(RelocationOffsetInSection);
776 if (FOTIterator == FunctionOffsetTranslations.end()) {
777 return createError("failed to get relocation data for offset: " +
778 Twine::utohexstr(RelocationOffsetInSection) +
779 " in section " + describe(EF, Sec));
780 }
781 return FOTIterator->second;
782 };
783 Expected<ArrayRef<uint8_t>> ContentsOrErr = EF.getSectionContents(Sec);
784 if (!ContentsOrErr)
785 return ContentsOrErr.takeError();
786 ArrayRef<uint8_t> Content = *ContentsOrErr;
787
788 // Decompress the section if needed.
789 std::unique_ptr<uint8_t[]> DecompressedContent;
790 if (Sec.sh_flags & llvm::ELF::SHF_COMPRESSED) {
791 Expected<StringRef> SectionNameOrErr = EF.getSectionName(Sec);
792 if (!SectionNameOrErr)
793 return SectionNameOrErr.takeError();
794 auto DecompressorOrErr =
795 Decompressor::create(*SectionNameOrErr, toStringRef(*ContentsOrErr),
796 EF.isLE(), ELFT::Is64Bits);
797 if (!DecompressorOrErr)
798 return DecompressorOrErr.takeError();
799 size_t DecompressedSize = DecompressorOrErr->getDecompressedSize();
800 DecompressedContent = std::make_unique<uint8_t[]>(DecompressedSize);
801 MutableArrayRef<uint8_t> DecompressedContentRef(DecompressedContent.get(),
802 DecompressedSize);
803 if (Error Err = DecompressorOrErr->decompress(DecompressedContentRef))
804 return std::move(Err);
805 Content = DecompressedContentRef;
806 }
807
808 DataExtractor Data(Content, EF.isLE(), ELFT::Is64Bits ? 8 : 4);
809 std::vector<BBAddrMap> FunctionEntries;
810
812 Error ULEBSizeErr = Error::success();
813 Error MetadataDecodeErr = Error::success();
814
815 // Helper lampda to extract the (possiblly relocatable) address stored at Cur.
816 auto ExtractAddress = [&]() -> Expected<typename ELFFile<ELFT>::uintX_t> {
817 uint64_t RelocationOffsetInSection = Cur.tell();
818 auto Address =
819 static_cast<typename ELFFile<ELFT>::uintX_t>(Data.getAddress(Cur));
820 if (!Cur)
821 return Cur.takeError();
822 if (!IsRelocatable)
823 return Address;
824 assert(Address == 0);
825 Expected<unsigned> AddressOrErr =
826 GetAddressForRelocation(RelocationOffsetInSection);
827 if (!AddressOrErr)
828 return AddressOrErr.takeError();
829 return *AddressOrErr;
830 };
831
832 uint8_t Version = 0;
833 uint8_t Feature = 0;
834 BBAddrMap::Features FeatEnable{};
835 while (!ULEBSizeErr && !MetadataDecodeErr && Cur &&
836 Cur.tell() < Content.size()) {
837 Version = Data.getU8(Cur);
838 if (!Cur)
839 break;
840 if (Version < 2 || Version > 3)
841 return createError("unsupported SHT_LLVM_BB_ADDR_MAP version: " +
842 Twine(static_cast<int>(Version)));
843 Feature = Data.getU8(Cur); // Feature byte
844 if (!Cur)
845 break;
846 auto FeatEnableOrErr = BBAddrMap::Features::decode(Feature);
847 if (!FeatEnableOrErr)
848 return FeatEnableOrErr.takeError();
849 FeatEnable = *FeatEnableOrErr;
850 if (FeatEnable.CallsiteEndOffsets && Version < 3)
851 return createError("version should be >= 3 for SHT_LLVM_BB_ADDR_MAP when "
852 "callsite offsets feature is enabled: version = " +
853 Twine(static_cast<int>(Version)) +
854 " feature = " + Twine(static_cast<int>(Feature)));
855 uint32_t NumBlocksInBBRange = 0;
856 uint32_t NumBBRanges = 1;
857 typename ELFFile<ELFT>::uintX_t RangeBaseAddress = 0;
858 if (FeatEnable.MultiBBRange) {
859 NumBBRanges = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
860 if (!Cur || ULEBSizeErr)
861 break;
862 if (!NumBBRanges)
863 return createError("invalid zero number of BB ranges at offset " +
864 Twine::utohexstr(Cur.tell()) + " in " +
865 describe(EF, Sec));
866 } else {
867 auto AddressOrErr = ExtractAddress();
868 if (!AddressOrErr)
869 return AddressOrErr.takeError();
870 RangeBaseAddress = *AddressOrErr;
871 NumBlocksInBBRange = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
872 }
873 std::vector<BBAddrMap::BBRangeEntry> BBRangeEntries;
874 uint32_t TotalNumBlocks = 0;
875 for (uint32_t BBRangeIndex = 0; BBRangeIndex < NumBBRanges;
876 ++BBRangeIndex) {
877 uint32_t PrevBBEndOffset = 0;
878 if (FeatEnable.MultiBBRange) {
879 auto AddressOrErr = ExtractAddress();
880 if (!AddressOrErr)
881 return AddressOrErr.takeError();
882 RangeBaseAddress = *AddressOrErr;
883 NumBlocksInBBRange = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
884 }
885 std::vector<BBAddrMap::BBEntry> BBEntries;
886 if (!FeatEnable.OmitBBEntries) {
887 for (uint32_t BlockIndex = 0; !MetadataDecodeErr && !ULEBSizeErr &&
888 Cur && (BlockIndex < NumBlocksInBBRange);
889 ++BlockIndex) {
890 uint32_t ID = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
891 uint32_t Offset = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
892 // Read the callsite offsets.
893 uint32_t LastCallsiteEndOffset = 0;
894 SmallVector<uint32_t, 1> CallsiteEndOffsets;
895 if (FeatEnable.CallsiteEndOffsets) {
896 uint32_t NumCallsites =
897 readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
898 CallsiteEndOffsets.reserve(NumCallsites);
899 for (uint32_t CallsiteIndex = 0;
900 !ULEBSizeErr && Cur && (CallsiteIndex < NumCallsites);
901 ++CallsiteIndex) {
902 LastCallsiteEndOffset +=
903 readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
904 CallsiteEndOffsets.push_back(LastCallsiteEndOffset);
905 }
906 }
907 uint32_t Size = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr) +
908 LastCallsiteEndOffset;
909 uint32_t MD = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
912 if (!MetadataOrErr) {
913 MetadataDecodeErr = MetadataOrErr.takeError();
914 break;
915 }
916 BBEntries.push_back({ID, Offset + PrevBBEndOffset, Size,
917 *MetadataOrErr, CallsiteEndOffsets});
918 PrevBBEndOffset += Offset + Size;
919 }
920 TotalNumBlocks += BBEntries.size();
921 }
922 BBRangeEntries.push_back({RangeBaseAddress, std::move(BBEntries)});
923 }
924 FunctionEntries.push_back({std::move(BBRangeEntries)});
925
926 if (PGOAnalyses || FeatEnable.hasPGOAnalysis()) {
927 // Function entry count
929 FeatEnable.FuncEntryCount
930 ? readULEB128As<uint64_t>(Data, Cur, ULEBSizeErr)
931 : 0;
932
933 std::vector<PGOAnalysisMap::PGOBBEntry> PGOBBEntries;
934 for (uint32_t BlockIndex = 0;
935 FeatEnable.hasPGOAnalysisBBData() && !MetadataDecodeErr &&
936 !ULEBSizeErr && Cur && (BlockIndex < TotalNumBlocks);
937 ++BlockIndex) {
938 // Block frequency
939 uint64_t BBF = FeatEnable.BBFreq
940 ? readULEB128As<uint64_t>(Data, Cur, ULEBSizeErr)
941 : 0;
942
943 // Branch probability
945 Successors;
946 if (FeatEnable.BrProb) {
947 auto SuccCount = readULEB128As<uint64_t>(Data, Cur, ULEBSizeErr);
948 for (uint64_t I = 0; I < SuccCount; ++I) {
949 uint32_t BBID = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
950 uint32_t BrProb = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
951 if (PGOAnalyses)
952 Successors.push_back({BBID, BranchProbability::getRaw(BrProb)});
953 }
954 }
955
956 if (PGOAnalyses)
957 PGOBBEntries.push_back({BlockFrequency(BBF), std::move(Successors)});
958 }
959
960 if (PGOAnalyses)
961 PGOAnalyses->push_back(
962 {FuncEntryCount, std::move(PGOBBEntries), FeatEnable});
963 }
964 }
965 // Either Cur is in the error state, or we have an error in ULEBSizeErr or
966 // MetadataDecodeErr (but not both), but we join all errors here to be safe.
967 if (!Cur || ULEBSizeErr || MetadataDecodeErr)
968 return joinErrors(joinErrors(Cur.takeError(), std::move(ULEBSizeErr)),
969 std::move(MetadataDecodeErr));
970 return FunctionEntries;
971}
972
973template <class ELFT>
975ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec, const Elf_Shdr *RelaSec,
976 std::vector<PGOAnalysisMap> *PGOAnalyses) const {
977 size_t OriginalPGOSize = PGOAnalyses ? PGOAnalyses->size() : 0;
978 auto AddrMapsOrErr = decodeBBAddrMapImpl(*this, Sec, RelaSec, PGOAnalyses);
979 // remove new analyses when an error occurs
980 if (!AddrMapsOrErr && PGOAnalyses)
981 PGOAnalyses->resize(OriginalPGOSize);
982 return std::move(AddrMapsOrErr);
983}
984
985template <class ELFT>
989 std::function<Expected<bool>(const Elf_Shdr &)> IsMatch) const {
991 Error Errors = Error::success();
992 for (const Elf_Shdr &Sec : cantFail(this->sections())) {
993 Expected<bool> DoesSectionMatch = IsMatch(Sec);
994 if (!DoesSectionMatch) {
995 Errors = joinErrors(std::move(Errors), DoesSectionMatch.takeError());
996 continue;
997 }
998 if (*DoesSectionMatch) {
999 if (SecToRelocMap.try_emplace(&Sec).second)
1000 continue;
1001 }
1002
1003 if (Sec.sh_type != ELF::SHT_RELA && Sec.sh_type != ELF::SHT_REL &&
1004 Sec.sh_type != ELF::SHT_CREL)
1005 continue;
1006
1007 Expected<const Elf_Shdr *> RelSecOrErr = this->getSection(Sec.sh_info);
1008 if (!RelSecOrErr) {
1009 Errors = joinErrors(std::move(Errors),
1010 createError(describe(*this, Sec) +
1011 ": failed to get a relocated section: " +
1012 toString(RelSecOrErr.takeError())));
1013 continue;
1014 }
1015 const Elf_Shdr *ContentsSec = *RelSecOrErr;
1016 Expected<bool> DoesRelTargetMatch = IsMatch(*ContentsSec);
1017 if (!DoesRelTargetMatch) {
1018 Errors = joinErrors(std::move(Errors), DoesRelTargetMatch.takeError());
1019 continue;
1020 }
1021 if (*DoesRelTargetMatch)
1022 SecToRelocMap[ContentsSec] = &Sec;
1023 }
1024 if(Errors)
1025 return std::move(Errors);
1026 return SecToRelocMap;
1027}
1028
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
bbsections Prepares for basic block sections
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:390
#define LLVM_EXPORT_TEMPLATE
Definition: Compiler.h:215
T Content
uint64_t Addr
uint64_t Size
#define I(x, y, z)
Definition: MD5.cpp:58
static IntTy readULEB128As(DataExtractor &Data, DataExtractor::Cursor &Cur, Error &ULEBSizeErr)
Definition: ELF.cpp:719
#define STRINGIFY_ENUM_CASE(ns, name)
Definition: ELF.cpp:19
static Expected< std::vector< BBAddrMap > > decodeBBAddrMapImpl(const ELFFile< ELFT > &EF, const typename ELFFile< ELFT >::Elf_Shdr &Sec, const typename ELFFile< ELFT >::Elf_Shdr *RelaSec, std::vector< PGOAnalysisMap > *PGOAnalyses)
Definition: ELF.cpp:738
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
const T & back() const
back - Get the last element.
Definition: ArrayRef.h:156
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:142
const T * data() const
Definition: ArrayRef.h:144
static BranchProbability getRaw(uint32_t N)
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:55
uint64_t tell() const
Return the current position of this Cursor.
Definition: DataExtractor.h:72
Error takeError()
Return error contained inside this Cursor, if any.
Definition: DataExtractor.h:79
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:177
iterator end()
Definition: DenseMap.h:87
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
Tagged union holding either a T or a Error.
Definition: Error.h:485
Error takeError()
Take ownership of the stored error.
Definition: Error.h:612
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
Definition: MapVector.h:107
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
void reserve(size_type N)
Definition: SmallVector.h:664
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:418
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:75
An efficient, type-erasing, non-owning reference to a callable.
static LLVM_ABI Expected< Decompressor > create(StringRef Name, StringRef Data, bool IsLE, bool Is64Bit)
Create decompressor object.
const Elf_Ehdr & getHeader() const
Definition: ELF.h:284
Expected< std::vector< Elf_Rela > > android_relas(const Elf_Shdr &Sec) const
Definition: ELF.cpp:454
std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const
Definition: ELF.cpp:522
Expected< std::vector< BBAddrMap > > decodeBBAddrMap(const Elf_Shdr &Sec, const Elf_Shdr *RelaSec=nullptr, std::vector< PGOAnalysisMap > *PGOAnalyses=nullptr) const
Returns a vector of BBAddrMap structs corresponding to each function within the text section that the...
Definition: ELF.cpp:975
Expected< ArrayRef< uint8_t > > getSectionContents(const Elf_Shdr &Sec) const
Definition: ELF.h:677
Expected< Elf_Rela_Range > relas(const Elf_Shdr &Sec) const
Definition: ELF.h:359
Expected< RelsOrRelas > decodeCrel(ArrayRef< uint8_t > Content) const
Definition: ELF.cpp:414
Expected< uint64_t > getCrelHeader(ArrayRef< uint8_t > Content) const
Definition: ELF.cpp:402
Expected< Elf_Dyn_Range > dynamicEntries() const
Definition: ELF.cpp:611
Expected< const uint8_t * > toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition: ELF.cpp:663
Expected< MapVector< const Elf_Shdr *, const Elf_Shdr * > > getSectionAndRelocations(std::function< Expected< bool >(const Elf_Shdr &)> IsMatch) const
Returns a map from every section matching IsMatch to its relocation section, or nullptr if it has no ...
Definition: ELF.cpp:988
bool isLE() const
Definition: ELF.h:334
Expected< StringRef > getSectionName(const Elf_Shdr &Section, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition: ELF.h:1328
Expected< RelsOrRelas > crels(const Elf_Shdr &Sec) const
Definition: ELF.cpp:445
std::vector< Elf_Rel > decode_relrs(Elf_Relr_Range relrs) const
Definition: ELF.cpp:338
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG
Definition: ELF.h:2001
@ RELOCATION_GROUPED_BY_INFO_FLAG
Definition: ELF.h:2000
@ RELOCATION_GROUPED_BY_ADDEND_FLAG
Definition: ELF.h:2002
@ RELOCATION_GROUP_HAS_ADDEND_FLAG
Definition: ELF.h:2003
@ EM_MSP430
Definition: ELF.h:227
@ EM_S390
Definition: ELF.h:155
@ EM_PPC64
Definition: ELF.h:154
@ EM_SPARC
Definition: ELF.h:140
@ EM_CSKY
Definition: ELF.h:326
@ EM_SPARC32PLUS
Definition: ELF.h:151
@ EM_MIPS_RS3_LE
Definition: ELF.h:148
@ EM_68K
Definition: ELF.h:142
@ EM_386
Definition: ELF.h:141
@ EM_LOONGARCH
Definition: ELF.h:327
@ EM_BPF
Definition: ELF.h:324
@ EM_PPC
Definition: ELF.h:153
@ EM_X86_64
Definition: ELF.h:183
@ EM_HEXAGON
Definition: ELF.h:262
@ EM_LANAI
Definition: ELF.h:323
@ EM_MIPS
Definition: ELF.h:146
@ EM_SPARCV9
Definition: ELF.h:164
@ EM_AARCH64
Definition: ELF.h:285
@ EM_XTENSA
Definition: ELF.h:216
@ EM_ARC_COMPACT2
Definition: ELF.h:296
@ EM_RISCV
Definition: ELF.h:322
@ EM_ARC_COMPACT
Definition: ELF.h:214
@ EM_ARM
Definition: ELF.h:161
@ EM_VE
Definition: ELF.h:325
@ EM_IAMCU
Definition: ELF.h:144
@ EM_AMDGPU
Definition: ELF.h:321
@ EM_AVR
Definition: ELF.h:204
@ SHT_REL
Definition: ELF.h:1148
@ SHT_CREL
Definition: ELF.h:1161
@ SHT_DYNAMIC
Definition: ELF.h:1145
@ SHT_RELA
Definition: ELF.h:1143
@ ET_REL
Definition: ELF.h:119
@ SHF_COMPRESSED
Definition: ELF.h:1268
@ PT_LOAD
Definition: ELF.h:1550
@ PT_DYNAMIC
Definition: ELF.h:1551
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition: ELF.h:539
Error createError(const Twine &Err)
Definition: Error.h:86
LLVM_ABI StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
Definition: ELF.cpp:25
LLVM_ABI uint32_t getELFRelativeRelocationType(uint32_t Machine)
Definition: ELF.cpp:194
LLVM_ABI StringRef getELFSectionTypeName(uint32_t Machine, uint32_t Type)
static std::string describe(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
Definition: ELF.h:145
static Error decodeCrel(ArrayRef< uint8_t > Content, function_ref< void(uint64_t, bool)> HdrHandler, function_ref< void(Elf_Crel_Impl< Is64 >)> EntryHandler)
Definition: ELF.h:216
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
void stable_sort(R &&Range)
Definition: STLExtras.h:2077
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:2026
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:442
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:1939
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:769
const char * toString(DWARFSectionKind Kind)
@ CallsiteIndex
static Expected< Metadata > decode(uint32_t V)
Definition: ELFTypes.h:902
static Expected< Features > decode(uint8_t Val)
Definition: ELFTypes.h:853