LLVM 22.0.0git
ELF.h
Go to the documentation of this file.
1//===- ELF.h - ELF object file implementation -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the ELFFile template class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_OBJECT_ELF_H
14#define LLVM_OBJECT_ELF_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/MapVector.h"
20#include "llvm/ADT/StringRef.h"
23#include "llvm/Object/Error.h"
26#include "llvm/Support/Error.h"
27#include <cassert>
28#include <cstddef>
29#include <cstdint>
30#include <limits>
31#include <type_traits>
32#include <utility>
33
34namespace llvm {
35namespace object {
36
37struct VerdAux {
38 unsigned Offset;
39 std::string Name;
40};
41
42struct VerDef {
43 unsigned Offset;
48 unsigned Hash;
49 std::string Name;
50 std::vector<VerdAux> AuxV;
51};
52
53struct VernAux {
54 unsigned Hash;
55 unsigned Flags;
56 unsigned Other;
57 unsigned Offset;
58 std::string Name;
59};
60
61struct VerNeed {
62 unsigned Version;
63 unsigned Cnt;
64 unsigned Offset;
65 std::string File;
66 std::vector<VernAux> AuxV;
67};
68
70 std::string Name;
72};
73
77
78// Subclasses of ELFFile may need this for template instantiation
79inline std::pair<unsigned char, unsigned char>
81 if (Object.size() < ELF::EI_NIDENT)
82 return std::make_pair((uint8_t)ELF::ELFCLASSNONE,
84 return std::make_pair((uint8_t)Object[ELF::EI_CLASS],
85 (uint8_t)Object[ELF::EI_DATA]);
86}
87
89 PADDI_R12_NO_DISP = 0x0610000039800000,
93 PLD_R12_NO_DISP = 0x04100000E5800000,
94 MTCTR_R12 = 0x7D8903A6,
95 BCTR = 0x4E800420,
96};
97
98template <class ELFT> class ELFFile;
99
100template <class T> struct DataRegion {
101 // This constructor is used when we know the start and the size of a data
102 // region. We assume that Arr does not go past the end of the file.
103 DataRegion(ArrayRef<T> Arr) : First(Arr.data()), Size(Arr.size()) {}
104
105 // Sometimes we only know the start of a data region. We still don't want to
106 // read past the end of the file, so we provide the end of a buffer.
107 DataRegion(const T *Data, const uint8_t *BufferEnd)
108 : First(Data), BufEnd(BufferEnd) {}
109
111 assert(Size || BufEnd);
112 if (Size) {
113 if (N >= *Size)
114 return createError(
115 "the index is greater than or equal to the number of entries (" +
116 Twine(*Size) + ")");
117 } else {
118 const uint8_t *EntryStart = (const uint8_t *)First + N * sizeof(T);
119 if (EntryStart + sizeof(T) > BufEnd)
120 return createError("can't read past the end of the file");
121 }
122 return *(First + N);
123 }
124
125 const T *First;
126 std::optional<uint64_t> Size;
127 const uint8_t *BufEnd = nullptr;
128};
129
130template <class ELFT>
131static std::string getSecIndexForError(const ELFFile<ELFT> &Obj,
132 const typename ELFT::Shdr &Sec) {
133 auto TableOrErr = Obj.sections();
134 if (TableOrErr)
135 return "[index " + std::to_string(&Sec - &TableOrErr->front()) + "]";
136 // To make this helper be more convenient for error reporting purposes we
137 // drop the error. But really it should never be triggered. Before this point,
138 // our code should have called 'sections()' and reported a proper error on
139 // failure.
140 llvm::consumeError(TableOrErr.takeError());
141 return "[unknown index]";
142}
143
144template <class ELFT>
145static std::string describe(const ELFFile<ELFT> &Obj,
146 const typename ELFT::Shdr &Sec) {
147 unsigned SecNdx = &Sec - &cantFail(Obj.sections()).front();
148 return (object::getELFSectionTypeName(Obj.getHeader().e_machine,
149 Sec.sh_type) +
150 " section with index " + Twine(SecNdx))
151 .str();
152}
153
154template <class ELFT>
155static std::string getPhdrIndexForError(const ELFFile<ELFT> &Obj,
156 const typename ELFT::Phdr &Phdr) {
157 auto Headers = Obj.program_headers();
158 if (Headers)
159 return ("[index " + Twine(&Phdr - &Headers->front()) + "]").str();
160 // See comment in the getSecIndexForError() above.
161 llvm::consumeError(Headers.takeError());
162 return "[unknown index]";
163}
164
165static inline Error defaultWarningHandler(const Twine &Msg) {
166 return createError(Msg);
167}
168
169template <class ELFT>
170static bool checkSectionOffsets(const typename ELFT::Phdr &Phdr,
171 const typename ELFT::Shdr &Sec) {
172 // SHT_NOBITS sections don't need to have an offset inside the segment.
173 if (Sec.sh_type == ELF::SHT_NOBITS)
174 return true;
175
176 if (Sec.sh_offset < Phdr.p_offset)
177 return false;
178
179 // Only non-empty sections can be at the end of a segment.
180 if (Sec.sh_size == 0)
181 return (Sec.sh_offset + 1 <= Phdr.p_offset + Phdr.p_filesz);
182 return Sec.sh_offset + Sec.sh_size <= Phdr.p_offset + Phdr.p_filesz;
183}
184
185// Check that an allocatable section belongs to a virtual address
186// space of a segment.
187template <class ELFT>
188static bool checkSectionVMA(const typename ELFT::Phdr &Phdr,
189 const typename ELFT::Shdr &Sec) {
190 if (!(Sec.sh_flags & ELF::SHF_ALLOC))
191 return true;
192
193 if (Sec.sh_addr < Phdr.p_vaddr)
194 return false;
195
196 bool IsTbss =
197 (Sec.sh_type == ELF::SHT_NOBITS) && ((Sec.sh_flags & ELF::SHF_TLS) != 0);
198 // .tbss is special, it only has memory in PT_TLS and has NOBITS properties.
199 bool IsTbssInNonTLS = IsTbss && Phdr.p_type != ELF::PT_TLS;
200 // Only non-empty sections can be at the end of a segment.
201 if (Sec.sh_size == 0 || IsTbssInNonTLS)
202 return Sec.sh_addr + 1 <= Phdr.p_vaddr + Phdr.p_memsz;
203 return Sec.sh_addr + Sec.sh_size <= Phdr.p_vaddr + Phdr.p_memsz;
204}
205
206template <class ELFT>
207static bool isSectionInSegment(const typename ELFT::Phdr &Phdr,
208 const typename ELFT::Shdr &Sec) {
209 return checkSectionOffsets<ELFT>(Phdr, Sec) &&
210 checkSectionVMA<ELFT>(Phdr, Sec);
211}
212
213// HdrHandler is called once with the number of relocations and whether the
214// relocations have addends. EntryHandler is called once per decoded relocation.
215template <bool Is64>
217 ArrayRef<uint8_t> Content,
218 function_ref<void(uint64_t /*relocation count*/, bool /*explicit addends*/)>
219 HdrHandler,
220 function_ref<void(Elf_Crel_Impl<Is64>)> EntryHandler) {
221 DataExtractor Data(Content, true, 8); // endian and address size are unused
223 const uint64_t Hdr = Data.getULEB128(Cur);
224 size_t Count = Hdr / 8;
225 const size_t FlagBits = Hdr & ELF::CREL_HDR_ADDEND ? 3 : 2;
226 const size_t Shift = Hdr % ELF::CREL_HDR_ADDEND;
227 using uint = typename Elf_Crel_Impl<Is64>::uint;
228 uint Offset = 0, Addend = 0;
229 HdrHandler(Count, Hdr & ELF::CREL_HDR_ADDEND);
230 uint32_t SymIdx = 0, Type = 0;
231 for (; Count; --Count) {
232 // The delta offset and flags member may be larger than uint64_t. Special
233 // case the first byte (2 or 3 flag bits; the rest are offset bits). Other
234 // ULEB128 bytes encode the remaining delta offset bits.
235 const uint8_t B = Data.getU8(Cur);
236 Offset += B >> FlagBits;
237 if (B >= 0x80)
238 Offset += (Data.getULEB128(Cur) << (7 - FlagBits)) - (0x80 >> FlagBits);
239 // Delta symidx/type/addend members (SLEB128).
240 if (B & 1)
241 SymIdx += Data.getSLEB128(Cur);
242 if (B & 2)
243 Type += Data.getSLEB128(Cur);
244 if (B & 4 & Hdr)
245 Addend += Data.getSLEB128(Cur);
246 if (!Cur)
247 break;
248 EntryHandler(
250 }
251 return Cur.takeError();
252}
253
254template <class ELFT>
255class ELFFile {
256public:
258
259 // Default ctor and copy assignment operator required to instantiate the
260 // template for DLL export.
261 ELFFile(const ELFFile &) = default;
262 ELFFile &operator=(const ELFFile &) = default;
263
264 // This is a callback that can be passed to a number of functions.
265 // It can be used to ignore non-critical errors (warnings), which is
266 // useful for dumpers, like llvm-readobj.
267 // It accepts a warning message string and returns a success
268 // when the warning should be ignored or an error otherwise.
270
271 const uint8_t *base() const { return Buf.bytes_begin(); }
272 const uint8_t *end() const { return base() + getBufSize(); }
273
274 size_t getBufSize() const { return Buf.size(); }
275
276private:
277 StringRef Buf;
278 std::vector<Elf_Shdr> FakeSections;
279 SmallString<0> FakeSectionStrings;
280
281 // When the number of program headers is >= PN_XNUM, the actual number is
282 // contained in the sh_info field of the section header at index 0.
283 std::optional<uint32_t> RealPhNum;
284 // When the number of section headers is >= SHN_LORESERVE, the actual number
285 // is contained in the sh_size field of the section header at index 0.
286 std::optional<uint64_t> RealShNum;
287 // When the section index of the section name table is >= SHN_LORESERVE, the
288 // actual number is contained in the sh_link field of the section header at
289 // index 0.
290 std::optional<uint32_t> RealShStrNdx;
291
292 ELFFile(StringRef Object);
293
294 Error readShdrZero();
295
296public:
298 if (!RealPhNum) {
299 if (Error E = const_cast<ELFFile<ELFT> *>(this)->readShdrZero())
300 return std::move(E);
301 }
302 return *RealPhNum;
303 }
304
306 if (!RealShNum) {
307 if (Error E = const_cast<ELFFile<ELFT> *>(this)->readShdrZero())
308 return std::move(E);
309 }
310 return *RealShNum;
311 }
312
314 if (!RealShStrNdx) {
315 if (Error E = const_cast<ELFFile<ELFT> *>(this)->readShdrZero())
316 return std::move(E);
317 }
318 return *RealShStrNdx;
319 }
320
321 const Elf_Ehdr &getHeader() const {
322 return *reinterpret_cast<const Elf_Ehdr *>(base());
323 }
324
325 template <typename T>
327 template <typename T>
328 Expected<const T *> getEntry(const Elf_Shdr &Section, uint32_t Entry) const;
329
331 getVersionDefinitions(const Elf_Shdr &Sec) const;
333 const Elf_Shdr &Sec,
334 WarningHandler WarnHandler = &defaultWarningHandler) const;
336 uint32_t SymbolVersionIndex, bool &IsDefault,
337 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
338 std::optional<bool> IsSymHidden) const;
339
341 getStringTable(const Elf_Shdr &Section,
342 WarningHandler WarnHandler = &defaultWarningHandler) const;
343 Expected<StringRef> getStringTableForSymtab(const Elf_Shdr &Section) const;
345 Elf_Shdr_Range Sections) const;
346 Expected<StringRef> getLinkAsStrtab(const typename ELFT::Shdr &Sec) const;
347
348 Expected<ArrayRef<Elf_Word>> getSHNDXTable(const Elf_Shdr &Section) const;
350 Elf_Shdr_Range Sections) const;
351
353
356 SmallVectorImpl<char> &Result) const;
358
359 std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const;
361
362 /// Get the symbol for a given relocation.
364 const Elf_Shdr *SymTab) const;
365
367 loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const;
368
370
371 bool isLE() const {
372 return getHeader().getDataEncoding() == ELF::ELFDATA2LSB;
373 }
374
375 bool isMipsELF64() const {
376 return getHeader().e_machine == ELF::EM_MIPS &&
377 getHeader().getFileClass() == ELF::ELFCLASS64;
378 }
379
380 bool isMips64EL() const { return isMipsELF64() && isLE(); }
381
383
385
388 WarningHandler WarnHandler = &defaultWarningHandler) const;
389
390 Expected<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const {
391 if (!Sec)
392 return ArrayRef<Elf_Sym>(nullptr, nullptr);
394 }
395
396 Expected<Elf_Rela_Range> relas(const Elf_Shdr &Sec) const {
398 }
399
400 Expected<Elf_Rel_Range> rels(const Elf_Shdr &Sec) const {
402 }
403
404 Expected<Elf_Relr_Range> relrs(const Elf_Shdr &Sec) const {
406 }
407
408 std::vector<Elf_Rel> decode_relrs(Elf_Relr_Range relrs) const;
409
411 using RelsOrRelas = std::pair<std::vector<Elf_Rel>, std::vector<Elf_Rela>>;
413 Expected<RelsOrRelas> crels(const Elf_Shdr &Sec) const;
414
416
417 /// Iterate over program header table.
419 uint32_t NumPh;
420 if (Expected<uint32_t> PhNumOrErr = getPhNum())
421 NumPh = *PhNumOrErr;
422 else
423 return PhNumOrErr.takeError();
424 if (NumPh && getHeader().e_phentsize != sizeof(Elf_Phdr))
425 return createError("invalid e_phentsize: " +
426 Twine(getHeader().e_phentsize));
427
428 uint64_t HeadersSize = (uint64_t)NumPh * getHeader().e_phentsize;
429 uint64_t PhOff = getHeader().e_phoff;
430 if (PhOff + HeadersSize < PhOff || PhOff + HeadersSize > getBufSize())
431 return createError("program headers are longer than binary of size " +
432 Twine(getBufSize()) + ": e_phoff = 0x" +
433 Twine::utohexstr(getHeader().e_phoff) +
434 ", e_phnum = " + Twine(NumPh) +
435 ", e_phentsize = " + Twine(getHeader().e_phentsize));
436
437 auto *Begin = reinterpret_cast<const Elf_Phdr *>(base() + PhOff);
438 return ArrayRef(Begin, Begin + NumPh);
439 }
440
441 /// Get an iterator over notes in a program header.
442 ///
443 /// The program header must be of type \c PT_NOTE.
444 ///
445 /// \param Phdr the program header to iterate over.
446 /// \param Err [out] an error to support fallible iteration, which should
447 /// be checked after iteration ends.
448 Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const {
449 assert(Phdr.p_type == ELF::PT_NOTE && "Phdr is not of type PT_NOTE");
450 ErrorAsOutParameter ErrAsOutParam(Err);
451 if (Phdr.p_offset + Phdr.p_filesz > getBufSize() ||
452 Phdr.p_offset + Phdr.p_filesz < Phdr.p_offset) {
453 Err =
454 createError("invalid offset (0x" + Twine::utohexstr(Phdr.p_offset) +
455 ") or size (0x" + Twine::utohexstr(Phdr.p_filesz) + ")");
456 return Elf_Note_Iterator(Err);
457 }
458 // Allow 4, 8, and (for Linux core dumps) 0.
459 // TODO: Disallow 1 after all tests are fixed.
460 if (Phdr.p_align != 0 && Phdr.p_align != 1 && Phdr.p_align != 4 &&
461 Phdr.p_align != 8) {
462 Err =
463 createError("alignment (" + Twine(Phdr.p_align) + ") is not 4 or 8");
464 return Elf_Note_Iterator(Err);
465 }
466 return Elf_Note_Iterator(base() + Phdr.p_offset, Phdr.p_filesz,
467 std::max<size_t>(Phdr.p_align, 4), Err);
468 }
469
470 /// Get an iterator over notes in a section.
471 ///
472 /// The section must be of type \c SHT_NOTE.
473 ///
474 /// \param Shdr the section to iterate over.
475 /// \param Err [out] an error to support fallible iteration, which should
476 /// be checked after iteration ends.
477 Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const {
478 assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE");
479 ErrorAsOutParameter ErrAsOutParam(Err);
480 if (Shdr.sh_offset + Shdr.sh_size > getBufSize() ||
481 Shdr.sh_offset + Shdr.sh_size < Shdr.sh_offset) {
482 Err =
483 createError("invalid offset (0x" + Twine::utohexstr(Shdr.sh_offset) +
484 ") or size (0x" + Twine::utohexstr(Shdr.sh_size) + ")");
485 return Elf_Note_Iterator(Err);
486 }
487 // TODO: Allow just 4 and 8 after all tests are fixed.
488 if (Shdr.sh_addralign != 0 && Shdr.sh_addralign != 1 &&
489 Shdr.sh_addralign != 4 && Shdr.sh_addralign != 8) {
490 Err = createError("alignment (" + Twine(Shdr.sh_addralign) +
491 ") is not 4 or 8");
492 return Elf_Note_Iterator(Err);
493 }
494 return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size,
495 std::max<size_t>(Shdr.sh_addralign, 4), Err);
496 }
497
498 /// Get the end iterator for notes.
499 Elf_Note_Iterator notes_end() const {
500 return Elf_Note_Iterator();
501 }
502
503 /// Get an iterator range over notes of a program header.
504 ///
505 /// The program header must be of type \c PT_NOTE.
506 ///
507 /// \param Phdr the program header to iterate over.
508 /// \param Err [out] an error to support fallible iteration, which should
509 /// be checked after iteration ends.
511 Error &Err) const {
512 return make_range(notes_begin(Phdr, Err), notes_end());
513 }
514
515 /// Get an iterator range over notes of a section.
516 ///
517 /// The section must be of type \c SHT_NOTE.
518 ///
519 /// \param Shdr the section to iterate over.
520 /// \param Err [out] an error to support fallible iteration, which should
521 /// be checked after iteration ends.
523 Error &Err) const {
524 return make_range(notes_begin(Shdr, Err), notes_end());
525 }
526
528 Elf_Shdr_Range Sections,
529 WarningHandler WarnHandler = &defaultWarningHandler) const;
530 Expected<uint32_t> getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms,
531 DataRegion<Elf_Word> ShndxTable) const;
533 const Elf_Shdr *SymTab,
534 DataRegion<Elf_Word> ShndxTable) const;
536 Elf_Sym_Range Symtab,
537 DataRegion<Elf_Word> ShndxTable) const;
539
541 uint32_t Index) const;
542
544 getSectionName(const Elf_Shdr &Section,
545 WarningHandler WarnHandler = &defaultWarningHandler) const;
546 Expected<StringRef> getSectionName(const Elf_Shdr &Section,
547 StringRef DotShstrtab) const;
548 template <typename T>
551 Expected<ArrayRef<uint8_t>> getSegmentContents(const Elf_Phdr &Phdr) const;
552
553 /// Returns a vector of BBAddrMap structs corresponding to each function
554 /// within the text section that the SHT_LLVM_BB_ADDR_MAP section \p Sec
555 /// is associated with. If the current ELFFile is relocatable, a corresponding
556 /// \p RelaSec must be passed in as an argument.
557 /// Optional out variable to collect all PGO Analyses. New elements are only
558 /// added if no error occurs. If not provided, the PGO Analyses are decoded
559 /// then ignored.
561 decodeBBAddrMap(const Elf_Shdr &Sec, const Elf_Shdr *RelaSec = nullptr,
562 std::vector<PGOAnalysisMap> *PGOAnalyses = nullptr) const;
563
564 /// Returns a map from every section matching \p IsMatch to its relocation
565 /// section, or \p nullptr if it has no relocation section. This function
566 /// returns an error if any of the \p IsMatch calls fail or if it fails to
567 /// retrieve the content section of any relocation section.
570 std::function<Expected<bool>(const Elf_Shdr &)> IsMatch) const;
571
573};
574
579
580template <class ELFT>
582getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
583 if (Index >= Sections.size())
584 return createError("invalid section index: " + Twine(Index));
585 return &Sections[Index];
586}
587
588template <class ELFT>
590getExtendedSymbolTableIndex(const typename ELFT::Sym &Sym, unsigned SymIndex,
592 assert(Sym.st_shndx == ELF::SHN_XINDEX);
593 if (!ShndxTable.First)
594 return createError(
595 "found an extended symbol index (" + Twine(SymIndex) +
596 "), but unable to locate the extended symbol index table");
597
598 Expected<typename ELFT::Word> TableOrErr = ShndxTable[SymIndex];
599 if (!TableOrErr)
600 return createError("unable to read an extended symbol table at index " +
601 Twine(SymIndex) + ": " +
602 toString(TableOrErr.takeError()));
603 return *TableOrErr;
604}
605
606template <class ELFT>
608ELFFile<ELFT>::getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms,
609 DataRegion<Elf_Word> ShndxTable) const {
610 uint32_t Index = Sym.st_shndx;
611 if (Index == ELF::SHN_XINDEX) {
612 Expected<uint32_t> ErrorOrIndex =
613 getExtendedSymbolTableIndex<ELFT>(Sym, &Sym - Syms.begin(), ShndxTable);
614 if (!ErrorOrIndex)
615 return ErrorOrIndex.takeError();
616 return *ErrorOrIndex;
617 }
618 if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE)
619 return 0;
620 return Index;
621}
622
623template <class ELFT>
625ELFFile<ELFT>::getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab,
626 DataRegion<Elf_Word> ShndxTable) const {
627 auto SymsOrErr = symbols(SymTab);
628 if (!SymsOrErr)
629 return SymsOrErr.takeError();
630 return getSection(Sym, *SymsOrErr, ShndxTable);
631}
632
633template <class ELFT>
635ELFFile<ELFT>::getSection(const Elf_Sym &Sym, Elf_Sym_Range Symbols,
636 DataRegion<Elf_Word> ShndxTable) const {
637 auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
638 if (!IndexOrErr)
639 return IndexOrErr.takeError();
640 uint32_t Index = *IndexOrErr;
641 if (Index == 0)
642 return nullptr;
643 return getSection(Index);
644}
645
646template <class ELFT>
648ELFFile<ELFT>::getSymbol(const Elf_Shdr *Sec, uint32_t Index) const {
649 auto SymsOrErr = symbols(Sec);
650 if (!SymsOrErr)
651 return SymsOrErr.takeError();
652
653 Elf_Sym_Range Symbols = *SymsOrErr;
654 if (Index >= Symbols.size())
655 return createError("unable to get symbol from section " +
656 getSecIndexForError(*this, *Sec) +
657 ": invalid symbol index (" + Twine(Index) + ")");
658 return &Symbols[Index];
659}
660
661template <class ELFT>
662template <typename T>
665 if (Sec.sh_entsize != sizeof(T) && sizeof(T) != 1)
666 return createError("section " + getSecIndexForError(*this, Sec) +
667 " has invalid sh_entsize: expected " + Twine(sizeof(T)) +
668 ", but got " + Twine(Sec.sh_entsize));
669
670 uintX_t Offset = Sec.sh_offset;
671 uintX_t Size = Sec.sh_size;
672
673 if (Size % sizeof(T))
674 return createError("section " + getSecIndexForError(*this, Sec) +
675 " has an invalid sh_size (" + Twine(Size) +
676 ") which is not a multiple of its sh_entsize (" +
677 Twine(Sec.sh_entsize) + ")");
678 if (std::numeric_limits<uintX_t>::max() - Offset < Size)
679 return createError("section " + getSecIndexForError(*this, Sec) +
680 " has a sh_offset (0x" + Twine::utohexstr(Offset) +
681 ") + sh_size (0x" + Twine::utohexstr(Size) +
682 ") that cannot be represented");
683 if (Offset + Size > Buf.size())
684 return createError("section " + getSecIndexForError(*this, Sec) +
685 " has a sh_offset (0x" + Twine::utohexstr(Offset) +
686 ") + sh_size (0x" + Twine::utohexstr(Size) +
687 ") that is greater than the file size (0x" +
688 Twine::utohexstr(Buf.size()) + ")");
689
690 if (Offset % alignof(T))
691 // TODO: this error is untested.
692 return createError("unaligned data");
693
694 const T *Start = reinterpret_cast<const T *>(base() + Offset);
695 return ArrayRef(Start, Size / sizeof(T));
696}
697
698template <class ELFT>
700ELFFile<ELFT>::getSegmentContents(const Elf_Phdr &Phdr) const {
701 uintX_t Offset = Phdr.p_offset;
702 uintX_t Size = Phdr.p_filesz;
703
704 if (std::numeric_limits<uintX_t>::max() - Offset < Size)
705 return createError("program header " + getPhdrIndexForError(*this, Phdr) +
706 " has a p_offset (0x" + Twine::utohexstr(Offset) +
707 ") + p_filesz (0x" + Twine::utohexstr(Size) +
708 ") that cannot be represented");
709 if (Offset + Size > Buf.size())
710 return createError("program header " + getPhdrIndexForError(*this, Phdr) +
711 " has a p_offset (0x" + Twine::utohexstr(Offset) +
712 ") + p_filesz (0x" + Twine::utohexstr(Size) +
713 ") that is greater than the file size (0x" +
714 Twine::utohexstr(Buf.size()) + ")");
715 return ArrayRef(base() + Offset, Size);
716}
717
718template <class ELFT>
720ELFFile<ELFT>::getSectionContents(const Elf_Shdr &Sec) const {
722}
723
724template <class ELFT>
728
729template <class ELFT>
731 SmallVectorImpl<char> &Result) const {
732 if (!isMipsELF64()) {
734 Result.append(Name.begin(), Name.end());
735 } else {
736 // The Mips N64 ABI allows up to three operations to be specified per
737 // relocation record. Unfortunately there's no easy way to test for the
738 // presence of N64 ELFs as they have no special flag that identifies them
739 // as being N64. We can safely assume at the moment that all Mips
740 // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
741 // information to disambiguate between old vs new ABIs.
742 uint8_t Type1 = (Type >> 0) & 0xFF;
743 uint8_t Type2 = (Type >> 8) & 0xFF;
744 uint8_t Type3 = (Type >> 16) & 0xFF;
745
746 // Concat all three relocation type names.
747 StringRef Name = getRelocationTypeName(Type1);
748 Result.append(Name.begin(), Name.end());
749
750 Name = getRelocationTypeName(Type2);
751 Result.append(1, '/');
752 Result.append(Name.begin(), Name.end());
753
754 Name = getRelocationTypeName(Type3);
755 Result.append(1, '/');
756 Result.append(Name.begin(), Name.end());
757 }
758}
759
760template <class ELFT>
764
765template <class ELFT>
767ELFFile<ELFT>::loadVersionMap(const Elf_Shdr *VerNeedSec,
768 const Elf_Shdr *VerDefSec) const {
770
771 // The first two version indexes are reserved.
772 // Index 0 is VER_NDX_LOCAL, index 1 is VER_NDX_GLOBAL.
773 VersionMap.push_back(VersionEntry());
774 VersionMap.push_back(VersionEntry());
775
776 auto InsertEntry = [&](unsigned N, StringRef Version, bool IsVerdef) {
777 if (N >= VersionMap.size())
778 VersionMap.resize(N + 1);
779 VersionMap[N] = {std::string(Version), IsVerdef};
780 };
781
782 if (VerDefSec) {
784 if (!Defs)
785 return Defs.takeError();
786 for (const VerDef &Def : *Defs)
787 InsertEntry(Def.Ndx & ELF::VERSYM_VERSION, Def.Name, true);
788 }
789
790 if (VerNeedSec) {
792 if (!Deps)
793 return Deps.takeError();
794 for (const VerNeed &Dep : *Deps)
795 for (const VernAux &Aux : Dep.AuxV)
796 InsertEntry(Aux.Other & ELF::VERSYM_VERSION, Aux.Name, false);
797 }
798
799 return VersionMap;
800}
801
802template <class ELFT>
805 const Elf_Shdr *SymTab) const {
806 uint32_t Index = Rel.getSymbol(isMips64EL());
807 if (Index == 0)
808 return nullptr;
809 return getEntry<Elf_Sym>(*SymTab, Index);
810}
811
812template <class ELFT>
815 WarningHandler WarnHandler) const {
816 Expected<uint32_t> ShStrNdxOrErr = getShStrNdx();
817 if (!ShStrNdxOrErr)
818 return ShStrNdxOrErr.takeError();
819
820 if (*ShStrNdxOrErr == ELF::SHN_XINDEX && Sections.empty())
821 return createError(
822 "e_shstrndx == SHN_XINDEX, but the section header table is empty");
823
824 uint32_t Index = *ShStrNdxOrErr;
825 // There is no section name string table. Return FakeSectionStrings which
826 // is non-empty if we have created fake sections.
827 if (!Index)
828 return FakeSectionStrings;
829
830 if (Index >= Sections.size())
831 return createError("section header string table index " + Twine(Index) +
832 " does not exist");
833 return getStringTable(Sections[Index], WarnHandler);
834}
835
836/// This function finds the number of dynamic symbols using a GNU hash table.
837///
838/// @param Table The GNU hash table for .dynsym.
839template <class ELFT>
841getDynSymtabSizeFromGnuHash(const typename ELFT::GnuHash &Table,
842 const void *BufEnd) {
843 using Elf_Word = typename ELFT::Word;
844 if (Table.nbuckets == 0)
845 return Table.symndx + 1;
846 uint64_t LastSymIdx = 0;
847 // Find the index of the first symbol in the last chain.
848 for (Elf_Word Val : Table.buckets())
849 LastSymIdx = std::max(LastSymIdx, (uint64_t)Val);
850 const Elf_Word *It =
851 reinterpret_cast<const Elf_Word *>(Table.values(LastSymIdx).end());
852 // Locate the end of the chain to find the last symbol index.
853 while (It < BufEnd && (*It & 1) == 0) {
854 ++LastSymIdx;
855 ++It;
856 }
857 if (It >= BufEnd) {
858 return createStringError(
860 "no terminator found for GNU hash section before buffer end");
861 }
862 return LastSymIdx + 1;
863}
864
865/// This function determines the number of dynamic symbols. It reads section
866/// headers first. If section headers are not available, the number of
867/// symbols will be inferred by parsing dynamic hash tables.
868template <class ELFT>
870 // Read .dynsym section header first if available.
871 Expected<Elf_Shdr_Range> SectionsOrError = sections();
872 if (!SectionsOrError)
873 return SectionsOrError.takeError();
874 for (const Elf_Shdr &Sec : *SectionsOrError) {
875 if (Sec.sh_type == ELF::SHT_DYNSYM) {
876 if (Sec.sh_size % Sec.sh_entsize != 0) {
878 "SHT_DYNSYM section has sh_size (" +
879 Twine(Sec.sh_size) + ") % sh_entsize (" +
880 Twine(Sec.sh_entsize) + ") that is not 0");
881 }
882 return Sec.sh_size / Sec.sh_entsize;
883 }
884 }
885
886 if (!SectionsOrError->empty()) {
887 // Section headers are available but .dynsym header is not found.
888 // Return 0 as .dynsym does not exist.
889 return 0;
890 }
891
892 // Section headers do not exist. Falling back to infer
893 // upper bound of .dynsym from .gnu.hash and .hash.
895 if (!DynTable)
896 return DynTable.takeError();
897 std::optional<uint64_t> ElfHash;
898 std::optional<uint64_t> ElfGnuHash;
899 for (const Elf_Dyn &Entry : *DynTable) {
900 switch (Entry.d_tag) {
901 case ELF::DT_HASH:
902 ElfHash = Entry.d_un.d_ptr;
903 break;
904 case ELF::DT_GNU_HASH:
905 ElfGnuHash = Entry.d_un.d_ptr;
906 break;
907 }
908 }
909 if (ElfGnuHash) {
910 Expected<const uint8_t *> TablePtr = toMappedAddr(*ElfGnuHash);
911 if (!TablePtr)
912 return TablePtr.takeError();
913 const Elf_GnuHash *Table =
914 reinterpret_cast<const Elf_GnuHash *>(TablePtr.get());
915 return getDynSymtabSizeFromGnuHash<ELFT>(*Table, this->Buf.bytes_end());
916 }
917
918 // Search SYSV hash table to try to find the upper bound of dynsym.
919 if (ElfHash) {
920 Expected<const uint8_t *> TablePtr = toMappedAddr(*ElfHash);
921 if (!TablePtr)
922 return TablePtr.takeError();
923 const Elf_Hash *Table = reinterpret_cast<const Elf_Hash *>(TablePtr.get());
924 return Table->nchain;
925 }
926 return 0;
927}
928
929template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
930
931template <class ELFT> Error ELFFile<ELFT>::readShdrZero() {
932 const Elf_Ehdr &Header = getHeader();
933
934 if ((Header.e_phnum == ELF::PN_XNUM || Header.e_shnum == 0 ||
935 Header.e_shstrndx == ELF::SHN_XINDEX) &&
936 Header.e_shoff != 0) {
937 // Pretend we have section 0 or sections() would call getShNum and thus
938 // become an infinite recursion.
939 RealShNum = 1;
940 auto SecOrErr = getSection(0);
941 if (!SecOrErr) {
942 RealShNum = std::nullopt;
943 return SecOrErr.takeError();
944 }
945
946 RealPhNum =
947 Header.e_phnum == ELF::PN_XNUM ? (*SecOrErr)->sh_info : Header.e_phnum;
948 RealShNum = Header.e_shnum == 0 ? (*SecOrErr)->sh_size : Header.e_shnum;
949 RealShStrNdx = Header.e_shstrndx == ELF::SHN_XINDEX ? (*SecOrErr)->sh_link
950 : Header.e_shstrndx;
951 } else {
952 RealPhNum = Header.e_phnum;
953 RealShNum = Header.e_shnum;
954 RealShStrNdx = Header.e_shstrndx;
955 }
956
957 return Error::success();
958}
959
960template <class ELFT>
962 if (sizeof(Elf_Ehdr) > Object.size())
963 return createError("invalid buffer: the size (" + Twine(Object.size()) +
964 ") is smaller than an ELF header (" +
965 Twine(sizeof(Elf_Ehdr)) + ")");
966 return ELFFile(Object);
967}
968
969/// Used by llvm-objdump -d (which needs sections for disassembly) to
970/// disassemble objects without a section header table (e.g. ET_CORE objects
971/// analyzed by linux perf or ET_EXEC with llvm-strip --strip-sections).
972template <class ELFT> void ELFFile<ELFT>::createFakeSections() {
973 if (!FakeSections.empty())
974 return;
975 auto PhdrsOrErr = program_headers();
976 if (!PhdrsOrErr)
977 return;
978
979 FakeSectionStrings += '\0';
980 for (auto [Idx, Phdr] : llvm::enumerate(*PhdrsOrErr)) {
981 if (Phdr.p_type != ELF::PT_LOAD || !(Phdr.p_flags & ELF::PF_X))
982 continue;
983 Elf_Shdr FakeShdr = {};
984 FakeShdr.sh_type = ELF::SHT_PROGBITS;
985 FakeShdr.sh_flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
986 FakeShdr.sh_addr = Phdr.p_vaddr;
987 FakeShdr.sh_size = Phdr.p_memsz;
988 FakeShdr.sh_offset = Phdr.p_offset;
989 // Create a section name based on the p_type and index.
990 FakeShdr.sh_name = FakeSectionStrings.size();
991 FakeSectionStrings += ("PT_LOAD#" + Twine(Idx)).str();
992 FakeSectionStrings += '\0';
993 FakeSections.push_back(FakeShdr);
994 }
995}
996
997template <class ELFT>
999 const uintX_t SectionTableOffset = getHeader().e_shoff;
1000 if (SectionTableOffset == 0) {
1001 if (!FakeSections.empty())
1002 return ArrayRef(FakeSections);
1003 return ArrayRef<Elf_Shdr>();
1004 }
1005
1006 if (getHeader().e_shentsize != sizeof(Elf_Shdr))
1007 return createError("invalid e_shentsize in ELF header: " +
1008 Twine(getHeader().e_shentsize));
1009
1010 const uint64_t FileSize = Buf.size();
1011 if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize ||
1012 SectionTableOffset + (uintX_t)sizeof(Elf_Shdr) < SectionTableOffset)
1013 return createError(
1014 "section header table goes past the end of the file: e_shoff = 0x" +
1015 Twine::utohexstr(SectionTableOffset));
1016
1017 // Invalid address alignment of section headers
1018 if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
1019 // TODO: this error is untested.
1020 return createError("invalid alignment of section headers");
1021
1022 const Elf_Shdr *First =
1023 reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
1024
1025 uintX_t NumSections = 0;
1026 if (Expected<uint64_t> ShNumOrErr = getShNum())
1027 NumSections = *ShNumOrErr;
1028 else
1029 return ShNumOrErr.takeError();
1030
1031 if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
1032 return createError("invalid number of sections specified in the NULL "
1033 "section's sh_size field (" +
1034 Twine(NumSections) + ")");
1035
1036 const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
1037 if (SectionTableOffset + SectionTableSize < SectionTableOffset)
1038 return createError(
1039 "invalid section header table offset (e_shoff = 0x" +
1040 Twine::utohexstr(SectionTableOffset) +
1041 ") or invalid number of sections specified in the first section "
1042 "header's sh_size field (0x" +
1043 Twine::utohexstr(NumSections) + ")");
1044
1045 // Section table goes past end of file!
1046 if (SectionTableOffset + SectionTableSize > FileSize)
1047 return createError("section table goes past the end of file");
1048 return ArrayRef(First, NumSections);
1049}
1050
1051template <class ELFT>
1052template <typename T>
1054 uint32_t Entry) const {
1055 auto SecOrErr = getSection(Section);
1056 if (!SecOrErr)
1057 return SecOrErr.takeError();
1058 return getEntry<T>(**SecOrErr, Entry);
1059}
1060
1061template <class ELFT>
1062template <typename T>
1064 uint32_t Entry) const {
1065 Expected<ArrayRef<T>> EntriesOrErr = getSectionContentsAsArray<T>(Section);
1066 if (!EntriesOrErr)
1067 return EntriesOrErr.takeError();
1068
1069 ArrayRef<T> Arr = *EntriesOrErr;
1070 if (Entry >= Arr.size())
1071 return createError(
1072 "can't read an entry at 0x" +
1073 Twine::utohexstr(Entry * static_cast<uint64_t>(sizeof(T))) +
1074 ": it goes past the end of the section (0x" +
1075 Twine::utohexstr(Section.sh_size) + ")");
1076 return &Arr[Entry];
1077}
1078
1079template <typename ELFT>
1081 uint32_t SymbolVersionIndex, bool &IsDefault,
1082 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
1083 std::optional<bool> IsSymHidden) const {
1084 size_t VersionIndex = SymbolVersionIndex & llvm::ELF::VERSYM_VERSION;
1085
1086 // Special markers for unversioned symbols.
1087 if (VersionIndex == llvm::ELF::VER_NDX_LOCAL ||
1088 VersionIndex == llvm::ELF::VER_NDX_GLOBAL) {
1089 IsDefault = false;
1090 return "";
1091 }
1092
1093 // Lookup this symbol in the version table.
1094 if (VersionIndex >= VersionMap.size() || !VersionMap[VersionIndex])
1095 return createError("SHT_GNU_versym section refers to a version index " +
1096 Twine(VersionIndex) + " which is missing");
1097
1098 const VersionEntry &Entry = *VersionMap[VersionIndex];
1099 // A default version (@@) is only available for defined symbols.
1100 if (!Entry.IsVerDef || IsSymHidden.value_or(false))
1101 IsDefault = false;
1102 else
1103 IsDefault = !(SymbolVersionIndex & llvm::ELF::VERSYM_HIDDEN);
1104 return Entry.Name.c_str();
1105}
1106
1107template <class ELFT>
1109ELFFile<ELFT>::getVersionDefinitions(const Elf_Shdr &Sec) const {
1110 Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Sec);
1111 if (!StrTabOrErr)
1112 return StrTabOrErr.takeError();
1113
1114 Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
1115 if (!ContentsOrErr)
1116 return createError("cannot read content of " + describe(*this, Sec) + ": " +
1117 toString(ContentsOrErr.takeError()));
1118
1119 const uint8_t *Start = ContentsOrErr->data();
1120 const uint8_t *End = Start + ContentsOrErr->size();
1121
1122 auto ExtractNextAux = [&](const uint8_t *&VerdauxBuf,
1123 unsigned VerDefNdx) -> Expected<VerdAux> {
1124 if (VerdauxBuf + sizeof(Elf_Verdaux) > End)
1125 return createError("invalid " + describe(*this, Sec) +
1126 ": version definition " + Twine(VerDefNdx) +
1127 " refers to an auxiliary entry that goes past the end "
1128 "of the section");
1129
1130 auto *Verdaux = reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf);
1131 VerdauxBuf += Verdaux->vda_next;
1132
1133 VerdAux Aux;
1134 Aux.Offset = VerdauxBuf - Start;
1135 if (Verdaux->vda_name < StrTabOrErr->size())
1136 Aux.Name = std::string(StrTabOrErr->drop_front(Verdaux->vda_name).data());
1137 else
1138 Aux.Name = ("<invalid vda_name: " + Twine(Verdaux->vda_name) + ">").str();
1139 return Aux;
1140 };
1141
1142 std::vector<VerDef> Ret;
1143 const uint8_t *VerdefBuf = Start;
1144 for (unsigned I = 1; I <= /*VerDefsNum=*/Sec.sh_info; ++I) {
1145 if (VerdefBuf + sizeof(Elf_Verdef) > End)
1146 return createError("invalid " + describe(*this, Sec) +
1147 ": version definition " + Twine(I) +
1148 " goes past the end of the section");
1149
1150 if (reinterpret_cast<uintptr_t>(VerdefBuf) % sizeof(uint32_t) != 0)
1151 return createError(
1152 "invalid " + describe(*this, Sec) +
1153 ": found a misaligned version definition entry at offset 0x" +
1154 Twine::utohexstr(VerdefBuf - Start));
1155
1156 unsigned Version = *reinterpret_cast<const Elf_Half *>(VerdefBuf);
1157 if (Version != 1)
1158 return createError("unable to dump " + describe(*this, Sec) +
1159 ": version " + Twine(Version) +
1160 " is not yet supported");
1161
1162 const Elf_Verdef *D = reinterpret_cast<const Elf_Verdef *>(VerdefBuf);
1163 VerDef &VD = *Ret.emplace(Ret.end());
1164 VD.Offset = VerdefBuf - Start;
1165 VD.Version = D->vd_version;
1166 VD.Flags = D->vd_flags;
1167 VD.Ndx = D->vd_ndx;
1168 VD.Cnt = D->vd_cnt;
1169 VD.Hash = D->vd_hash;
1170
1171 const uint8_t *VerdauxBuf = VerdefBuf + D->vd_aux;
1172 for (unsigned J = 0; J < D->vd_cnt; ++J) {
1173 if (reinterpret_cast<uintptr_t>(VerdauxBuf) % sizeof(uint32_t) != 0)
1174 return createError("invalid " + describe(*this, Sec) +
1175 ": found a misaligned auxiliary entry at offset 0x" +
1176 Twine::utohexstr(VerdauxBuf - Start));
1177
1178 Expected<VerdAux> AuxOrErr = ExtractNextAux(VerdauxBuf, I);
1179 if (!AuxOrErr)
1180 return AuxOrErr.takeError();
1181
1182 if (J == 0)
1183 VD.Name = AuxOrErr->Name;
1184 else
1185 VD.AuxV.push_back(*AuxOrErr);
1186 }
1187
1188 VerdefBuf += D->vd_next;
1189 }
1190
1191 return Ret;
1192}
1193
1194template <class ELFT>
1197 WarningHandler WarnHandler) const {
1198 StringRef StrTab;
1199 Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Sec);
1200 if (!StrTabOrErr) {
1201 if (Error E = WarnHandler(toString(StrTabOrErr.takeError())))
1202 return std::move(E);
1203 } else {
1204 StrTab = *StrTabOrErr;
1205 }
1206
1207 Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
1208 if (!ContentsOrErr)
1209 return createError("cannot read content of " + describe(*this, Sec) + ": " +
1210 toString(ContentsOrErr.takeError()));
1211
1212 const uint8_t *Start = ContentsOrErr->data();
1213 const uint8_t *End = Start + ContentsOrErr->size();
1214 const uint8_t *VerneedBuf = Start;
1215
1216 std::vector<VerNeed> Ret;
1217 for (unsigned I = 1; I <= /*VerneedNum=*/Sec.sh_info; ++I) {
1218 if (VerneedBuf + sizeof(Elf_Verdef) > End)
1219 return createError("invalid " + describe(*this, Sec) +
1220 ": version dependency " + Twine(I) +
1221 " goes past the end of the section");
1222
1223 if (reinterpret_cast<uintptr_t>(VerneedBuf) % sizeof(uint32_t) != 0)
1224 return createError(
1225 "invalid " + describe(*this, Sec) +
1226 ": found a misaligned version dependency entry at offset 0x" +
1227 Twine::utohexstr(VerneedBuf - Start));
1228
1229 unsigned Version = *reinterpret_cast<const Elf_Half *>(VerneedBuf);
1230 if (Version != 1)
1231 return createError("unable to dump " + describe(*this, Sec) +
1232 ": version " + Twine(Version) +
1233 " is not yet supported");
1234
1235 const Elf_Verneed *Verneed =
1236 reinterpret_cast<const Elf_Verneed *>(VerneedBuf);
1237
1238 VerNeed &VN = *Ret.emplace(Ret.end());
1239 VN.Version = Verneed->vn_version;
1240 VN.Cnt = Verneed->vn_cnt;
1241 VN.Offset = VerneedBuf - Start;
1242
1243 if (Verneed->vn_file < StrTab.size())
1244 VN.File = std::string(StrTab.data() + Verneed->vn_file);
1245 else
1246 VN.File = ("<corrupt vn_file: " + Twine(Verneed->vn_file) + ">").str();
1247
1248 const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux;
1249 for (unsigned J = 0; J < Verneed->vn_cnt; ++J) {
1250 if (reinterpret_cast<uintptr_t>(VernauxBuf) % sizeof(uint32_t) != 0)
1251 return createError("invalid " + describe(*this, Sec) +
1252 ": found a misaligned auxiliary entry at offset 0x" +
1253 Twine::utohexstr(VernauxBuf - Start));
1254
1255 if (VernauxBuf + sizeof(Elf_Vernaux) > End)
1256 return createError(
1257 "invalid " + describe(*this, Sec) + ": version dependency " +
1258 Twine(I) +
1259 " refers to an auxiliary entry that goes past the end "
1260 "of the section");
1261
1262 const Elf_Vernaux *Vernaux =
1263 reinterpret_cast<const Elf_Vernaux *>(VernauxBuf);
1264
1265 VernAux &Aux = *VN.AuxV.emplace(VN.AuxV.end());
1266 Aux.Hash = Vernaux->vna_hash;
1267 Aux.Flags = Vernaux->vna_flags;
1268 Aux.Other = Vernaux->vna_other;
1269 Aux.Offset = VernauxBuf - Start;
1270 if (StrTab.size() <= Vernaux->vna_name)
1271 Aux.Name = "<corrupt>";
1272 else
1273 Aux.Name = std::string(StrTab.drop_front(Vernaux->vna_name));
1274
1275 VernauxBuf += Vernaux->vna_next;
1276 }
1277 VerneedBuf += Verneed->vn_next;
1278 }
1279 return Ret;
1280}
1281
1282template <class ELFT>
1285 auto TableOrErr = sections();
1286 if (!TableOrErr)
1287 return TableOrErr.takeError();
1288 return object::getSection<ELFT>(*TableOrErr, Index);
1289}
1290
1291template <class ELFT>
1293ELFFile<ELFT>::getStringTable(const Elf_Shdr &Section,
1294 WarningHandler WarnHandler) const {
1295 if (Section.sh_type != ELF::SHT_STRTAB)
1296 if (Error E = WarnHandler("invalid sh_type for string table section " +
1297 getSecIndexForError(*this, Section) +
1298 ": expected SHT_STRTAB, but got " +
1300 getHeader().e_machine, Section.sh_type)))
1301 return std::move(E);
1302
1303 auto V = getSectionContentsAsArray<char>(Section);
1304 if (!V)
1305 return V.takeError();
1306 ArrayRef<char> Data = *V;
1307 if (Data.empty())
1308 return createError("SHT_STRTAB string table section " +
1309 getSecIndexForError(*this, Section) + " is empty");
1310 if (Data.back() != '\0')
1311 return createError("SHT_STRTAB string table section " +
1312 getSecIndexForError(*this, Section) +
1313 " is non-null terminated");
1314 return StringRef(Data.begin(), Data.size());
1315}
1316
1317template <class ELFT>
1319ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section) const {
1320 auto SectionsOrErr = sections();
1321 if (!SectionsOrErr)
1322 return SectionsOrErr.takeError();
1323 return getSHNDXTable(Section, *SectionsOrErr);
1324}
1325
1326template <class ELFT>
1328ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section,
1329 Elf_Shdr_Range Sections) const {
1330 assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
1331 auto VOrErr = getSectionContentsAsArray<Elf_Word>(Section);
1332 if (!VOrErr)
1333 return VOrErr.takeError();
1334 ArrayRef<Elf_Word> V = *VOrErr;
1335 auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
1336 if (!SymTableOrErr)
1337 return SymTableOrErr.takeError();
1338 const Elf_Shdr &SymTable = **SymTableOrErr;
1339 if (SymTable.sh_type != ELF::SHT_SYMTAB &&
1340 SymTable.sh_type != ELF::SHT_DYNSYM)
1341 return createError(
1342 "SHT_SYMTAB_SHNDX section is linked with " +
1343 object::getELFSectionTypeName(getHeader().e_machine, SymTable.sh_type) +
1344 " section (expected SHT_SYMTAB/SHT_DYNSYM)");
1345
1346 uint64_t Syms = SymTable.sh_size / sizeof(Elf_Sym);
1347 if (V.size() != Syms)
1348 return createError("SHT_SYMTAB_SHNDX has " + Twine(V.size()) +
1349 " entries, but the symbol table associated has " +
1350 Twine(Syms));
1351
1352 return V;
1353}
1354
1355template <class ELFT>
1357ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec) const {
1358 auto SectionsOrErr = sections();
1359 if (!SectionsOrErr)
1360 return SectionsOrErr.takeError();
1361 return getStringTableForSymtab(Sec, *SectionsOrErr);
1362}
1363
1364template <class ELFT>
1367 Elf_Shdr_Range Sections) const {
1368
1369 if (Sec.sh_type != ELF::SHT_SYMTAB && Sec.sh_type != ELF::SHT_DYNSYM)
1370 return createError(
1371 "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
1372 Expected<const Elf_Shdr *> SectionOrErr =
1373 object::getSection<ELFT>(Sections, Sec.sh_link);
1374 if (!SectionOrErr)
1375 return SectionOrErr.takeError();
1376 return getStringTable(**SectionOrErr);
1377}
1378
1379template <class ELFT>
1381ELFFile<ELFT>::getLinkAsStrtab(const typename ELFT::Shdr &Sec) const {
1383 getSection(Sec.sh_link);
1384 if (!StrTabSecOrErr)
1385 return createError("invalid section linked to " + describe(*this, Sec) +
1386 ": " + toString(StrTabSecOrErr.takeError()));
1387
1388 Expected<StringRef> StrTabOrErr = getStringTable(**StrTabSecOrErr);
1389 if (!StrTabOrErr)
1390 return createError("invalid string table linked to " +
1391 describe(*this, Sec) + ": " +
1392 toString(StrTabOrErr.takeError()));
1393 return *StrTabOrErr;
1394}
1395
1396template <class ELFT>
1398ELFFile<ELFT>::getSectionName(const Elf_Shdr &Section,
1399 WarningHandler WarnHandler) const {
1400 auto SectionsOrErr = sections();
1401 if (!SectionsOrErr)
1402 return SectionsOrErr.takeError();
1403 auto Table = getSectionStringTable(*SectionsOrErr, WarnHandler);
1404 if (!Table)
1405 return Table.takeError();
1406 return getSectionName(Section, *Table);
1407}
1408
1409template <class ELFT>
1411 StringRef DotShstrtab) const {
1412 uint32_t Offset = Section.sh_name;
1413 if (Offset == 0)
1414 return StringRef();
1415 if (Offset >= DotShstrtab.size())
1416 return createError("a section " + getSecIndexForError(*this, Section) +
1417 " has an invalid sh_name (0x" +
1419 ") offset which goes past the end of the "
1420 "section name string table");
1421 return StringRef(DotShstrtab.data() + Offset);
1422}
1423
1424/// This function returns the hash value for a symbol in the .dynsym section
1425/// Name of the API remains consistent as specified in the libelf
1426/// REF : http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash
1427inline uint32_t hashSysV(StringRef SymbolName) {
1428 uint32_t H = 0;
1429 for (uint8_t C : SymbolName) {
1430 H = (H << 4) + C;
1431 H ^= (H >> 24) & 0xf0;
1432 }
1433 return H & 0x0fffffff;
1434}
1435
1436/// This function returns the hash value for a symbol in the .dynsym section
1437/// for the GNU hash table. The implementation is defined in the GNU hash ABI.
1438/// REF : https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf.c#l222
1440 uint32_t H = 5381;
1441 for (uint8_t C : Name)
1442 H = (H << 5) + H + C;
1443 return H;
1444}
1445
1450
1451} // end namespace object
1452} // end namespace llvm
1453
1454#endif // LLVM_OBJECT_ELF_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
bbsections Prepares for basic block sections
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_TEMPLATE_ABI
Definition Compiler.h:214
static bool isMips64EL(const ELFYAML::Object &Obj)
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Definition ELFTypes.h:107
#define I(x, y, z)
Definition MD5.cpp:58
#define H(x, y, z)
Definition MD5.cpp:57
This file implements a map that provides insertion order iteration.
#define T
Function const char TargetMachine * Machine
This file defines the SmallString class.
This file defines the SmallVector class.
static Split data
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition ArrayRef.h:147
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Error takeError()
Return error contained inside this Cursor, if any.
Helper for Errors used as out-parameters.
Definition Error.h:1144
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
reference get()
Returns a reference to the stored T value.
Definition Error.h:582
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void resize(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
const unsigned char * bytes_end() const
Definition StringRef.h:127
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:611
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:146
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:140
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static Twine utohexstr(uint64_t Val)
Definition Twine.h:385
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
ELFFile(const ELFFile &)=default
llvm::function_ref< Error(const Twine &Msg)> WarningHandler
Definition ELF.h:269
const Elf_Ehdr & getHeader() const
Definition ELF.h:321
Expected< std::vector< Elf_Rela > > android_relas(const Elf_Shdr &Sec) const
Definition ELF.cpp:455
Expected< StringRef > getLinkAsStrtab(const typename ELFT::Shdr &Sec) const
Definition ELF.h:1381
static Expected< ELFFile > create(StringRef Object)
Definition ELF.h:961
Expected< const Elf_Shdr * > getSection(uint32_t Index) const
Definition ELF.h:1284
Expected< StringRef > getSectionName(const Elf_Shdr &Section, StringRef DotShstrtab) const
Definition ELF.h:1410
Expected< ArrayRef< Elf_Word > > getSHNDXTable(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const
Definition ELF.h:1328
Expected< const Elf_Sym * > getSymbol(const Elf_Shdr *Sec, uint32_t Index) const
Definition ELF.h:648
Expected< std::vector< VerDef > > getVersionDefinitions(const Elf_Shdr &Sec) const
Definition ELF.h:1109
std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const
Definition ELF.cpp:523
Expected< ArrayRef< Elf_Word > > getSHNDXTable(const Elf_Shdr &Section) const
Definition ELF.h:1319
Expected< const Elf_Shdr * > getSection(const Elf_Sym &Sym, Elf_Sym_Range Symtab, DataRegion< Elf_Word > ShndxTable) const
Definition ELF.h:635
Expected< Elf_Sym_Range > symbols(const Elf_Shdr *Sec) const
Definition ELF.h:390
Expected< uint64_t > getShNum() const
Definition ELF.h:305
Expected< ArrayRef< uint8_t > > getSegmentContents(const Elf_Phdr &Phdr) const
Definition ELF.h:700
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:998
Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const
Get an iterator over notes in a section.
Definition ELF.h:477
uint32_t getRelativeRelocationType() const
Definition ELF.h:761
iterator_range< Elf_Note_Iterator > notes(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator range over notes of a program header.
Definition ELF.h:510
Expected< StringRef > getSymbolVersionByIndex(uint32_t SymbolVersionIndex, bool &IsDefault, SmallVector< std::optional< VersionEntry >, 0 > &VersionMap, std::optional< bool > IsSymHidden) const
Definition ELF.h:1080
Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator over notes in a program header.
Definition ELF.h:448
Expected< ArrayRef< uint8_t > > getSectionContents(const Elf_Shdr &Sec) const
Definition ELF.h:720
Expected< Elf_Rela_Range > relas(const Elf_Shdr &Sec) const
Definition ELF.h:396
Expected< Elf_Phdr_Range > program_headers() const
Iterate over program header table.
Definition ELF.h:418
Expected< uint32_t > getShStrNdx() const
Definition ELF.h:313
Expected< StringRef > getStringTableForSymtab(const Elf_Shdr &Section) const
Definition ELF.h:1357
Expected< std::vector< VerNeed > > getVersionDependencies(const Elf_Shdr &Sec, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.h:1196
size_t getBufSize() const
Definition ELF.h:274
Expected< const T * > getEntry(uint32_t Section, uint32_t Entry) const
Definition ELF.h:1053
void getRelocationTypeName(uint32_t Type, SmallVectorImpl< char > &Result) const
Definition ELF.h:730
Expected< const Elf_Sym * > getRelocationSymbol(const Elf_Rel &Rel, const Elf_Shdr *SymTab) const
Get the symbol for a given relocation.
Definition ELF.h:804
Expected< RelsOrRelas > decodeCrel(ArrayRef< uint8_t > Content) const
Definition ELF.cpp:415
const uint8_t * end() const
Definition ELF.h:272
Expected< StringRef > getSectionStringTable(Elf_Shdr_Range Sections, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.h:814
Expected< uint64_t > getDynSymtabSize() const
This function determines the number of dynamic symbols.
Definition ELF.h:869
Expected< const T * > getEntry(const Elf_Shdr &Section, uint32_t Entry) const
Definition ELF.h:1063
Expected< uint64_t > getCrelHeader(ArrayRef< uint8_t > Content) const
Definition ELF.cpp:403
Expected< Elf_Dyn_Range > dynamicEntries() const
Definition ELF.cpp:612
void createFakeSections()
Used by llvm-objdump -d (which needs sections for disassembly) to disassemble objects without a secti...
Definition ELF.h:972
ELFFile(const ELFFile &)=default
Expected< Elf_Shdr_Range > sections() const
Definition ELF.h:998
iterator_range< Elf_Note_Iterator > notes(const Elf_Shdr &Shdr, Error &Err) const
Get an iterator range over notes of a section.
Definition ELF.h:522
const uint8_t * base() const
Definition ELF.h:271
bool isMipsELF64() const
Definition ELF.h:375
Expected< const uint8_t * > toMappedAddr(uint64_t VAddr, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.cpp:664
Expected< Elf_Relr_Range > relrs(const Elf_Shdr &Sec) const
Definition ELF.h:404
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:1011
std::string getDynamicTagAsString(uint64_t Type) const
Definition ELF.cpp:607
bool isLE() const
Definition ELF.h:371
bool isMips64EL() const
Definition ELF.h:380
Elf_Note_Iterator notes_end() const
Get the end iterator for notes.
Definition ELF.h:499
Expected< StringRef > getSectionName(const Elf_Shdr &Section, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.h:1398
StringRef getRelocationTypeName(uint32_t Type) const
Definition ELF.h:725
Expected< StringRef > getStringTable(const Elf_Shdr &Section, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.h:1293
llvm::function_ref< Error(const Twine &Msg)> WarningHandler
Definition ELF.h:269
Expected< uint32_t > getPhNum() const
Definition ELF.h:297
Expected< StringRef > getStringTableForSymtab(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const
Definition ELF.h:1366
Expected< ArrayRef< T > > getSectionContentsAsArray(const Elf_Shdr &Sec) const
Definition ELF.h:664
Expected< RelsOrRelas > crels(const Elf_Shdr &Sec) const
Definition ELF.cpp:446
Expected< SmallVector< std::optional< VersionEntry >, 0 > > loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const
Definition ELF.h:767
Expected< Elf_Rel_Range > rels(const Elf_Shdr &Sec) const
Definition ELF.h:400
Expected< const Elf_Shdr * > getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, DataRegion< Elf_Word > ShndxTable) const
Definition ELF.h:625
std::vector< Elf_Rel > decode_relrs(Elf_Relr_Range relrs) const
Definition ELF.cpp:339
std::pair< std::vector< Elf_Rel >, std::vector< Elf_Rela > > RelsOrRelas
Definition ELF.h:411
Expected< uint32_t > getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, DataRegion< Elf_Word > ShndxTable) const
Definition ELF.h:608
#define UINT64_MAX
Definition DataTypes.h:77
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ SHN_XINDEX
Definition ELF.h:1140
@ SHN_UNDEF
Definition ELF.h:1132
@ SHN_LORESERVE
Definition ELF.h:1133
@ PF_X
Definition ELF.h:1608
@ SHF_ALLOC
Definition ELF.h:1248
@ SHF_TLS
Definition ELF.h:1273
@ SHF_EXECINSTR
Definition ELF.h:1251
@ EI_DATA
Definition ELF.h:56
@ EI_NIDENT
Definition ELF.h:61
@ EI_CLASS
Definition ELF.h:55
@ EM_MIPS
Definition ELF.h:146
@ SHT_STRTAB
Definition ELF.h:1149
@ SHT_PROGBITS
Definition ELF.h:1147
@ SHT_NOBITS
Definition ELF.h:1154
@ SHT_SYMTAB
Definition ELF.h:1148
@ SHT_SYMTAB_SHNDX
Definition ELF.h:1162
@ SHT_NOTE
Definition ELF.h:1153
@ SHT_DYNSYM
Definition ELF.h:1157
constexpr unsigned CREL_HDR_ADDEND
Definition ELF.h:2053
@ ELFDATANONE
Definition ELF.h:339
@ ELFDATA2LSB
Definition ELF.h:340
@ PT_LOAD
Definition ELF.h:1558
@ PT_TLS
Definition ELF.h:1564
@ PT_NOTE
Definition ELF.h:1561
@ ELFCLASS64
Definition ELF.h:334
@ ELFCLASSNONE
Definition ELF.h:332
@ VER_NDX_GLOBAL
Definition ELF.h:1714
@ VERSYM_VERSION
Definition ELF.h:1715
@ VER_NDX_LOCAL
Definition ELF.h:1713
@ VERSYM_HIDDEN
Definition ELF.h:1716
@ PN_XNUM
Definition ELF.h:1128
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
Expected< uint32_t > getExtendedSymbolTableIndex(const typename ELFT::Sym &Sym, unsigned SymIndex, DataRegion< typename ELFT::Word > ShndxTable)
Definition ELF.h:590
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition ELF.h:582
static bool isSectionInSegment(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
Definition ELF.h:207
Error createError(const Twine &Err)
Definition Error.h:86
LLVM_ABI StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type)
Definition ELF.cpp:25
static Expected< uint64_t > getDynSymtabSizeFromGnuHash(const typename ELFT::GnuHash &Table, const void *BufEnd)
This function finds the number of dynamic symbols using a GNU hash table.
Definition ELF.h:841
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
uint32_t hashGnu(StringRef Name)
This function returns the hash value for a symbol in the .dynsym section for the GNU hash table.
Definition ELF.h:1439
static bool checkSectionOffsets(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
Definition ELF.h:170
static std::string getPhdrIndexForError(const ELFFile< ELFT > &Obj, const typename ELFT::Phdr &Phdr)
Definition ELF.h:155
static bool checkSectionVMA(const typename ELFT::Phdr &Phdr, const typename ELFT::Shdr &Sec)
Definition ELF.h:188
PPCInstrMasks
Definition ELF.h:88
@ PLD_R12_NO_DISP
Definition ELF.h:93
@ ADDIS_R12_TO_R2_NO_DISP
Definition ELF.h:90
@ ADDI_R12_TO_R12_NO_DISP
Definition ELF.h:92
@ ADDI_R12_TO_R2_NO_DISP
Definition ELF.h:91
@ PADDI_R12_NO_DISP
Definition ELF.h:89
@ MTCTR_R12
Definition ELF.h:94
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
Definition ELF.h:80
static Error defaultWarningHandler(const Twine &Msg)
Definition ELF.h:165
ELFFile< ELF32LE > ELF32LEFile
Definition ELF.h:575
ELFFile< ELF64BE > ELF64BEFile
Definition ELF.h:578
ELFFile< ELF32BE > ELF32BEFile
Definition ELF.h:577
uint32_t hashSysV(StringRef SymbolName)
This function returns the hash value for a symbol in the .dynsym section Name of the API remains cons...
Definition ELF.h:1427
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
static std::string getSecIndexForError(const ELFFile< ELFT > &Obj, const typename ELFT::Shdr &Sec)
Definition ELF.h:131
ELFFile< ELF64LE > ELF64LEFile
Definition ELF.h:576
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1655
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2472
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:302
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:71
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1083
#define N
Expected< T > operator[](uint64_t N)
Definition ELF.h:110
DataRegion(const T *Data, const uint8_t *BufferEnd)
Definition ELF.h:107
DataRegion(ArrayRef< T > Arr)
Definition ELF.h:103
const uint8_t * BufEnd
Definition ELF.h:127
std::optional< uint64_t > Size
Definition ELF.h:126
std::conditional_t< Is64, uint64_t, uint32_t > uint
Definition ELFTypes.h:490
std::string Name
Definition ELF.h:49
uint16_t Version
Definition ELF.h:44
uint16_t Flags
Definition ELF.h:45
uint16_t Ndx
Definition ELF.h:46
uint16_t Cnt
Definition ELF.h:47
unsigned Hash
Definition ELF.h:48
std::vector< VerdAux > AuxV
Definition ELF.h:50
unsigned Offset
Definition ELF.h:43
unsigned Cnt
Definition ELF.h:63
std::string File
Definition ELF.h:65
std::vector< VernAux > AuxV
Definition ELF.h:66
unsigned Offset
Definition ELF.h:64
unsigned Version
Definition ELF.h:62
unsigned Offset
Definition ELF.h:38
std::string Name
Definition ELF.h:39
unsigned Hash
Definition ELF.h:54
unsigned Offset
Definition ELF.h:57
unsigned Flags
Definition ELF.h:55
std::string Name
Definition ELF.h:58
unsigned Other
Definition ELF.h:56
std::string Name
Definition ELF.h:70