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