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 ELFFile(ELFFile &&) = default;
265
266 // This is a callback that can be passed to a number of functions.
267 // It can be used to ignore non-critical errors (warnings), which is
268 // useful for dumpers, like llvm-readobj.
269 // It accepts a warning message string and returns a success
270 // when the warning should be ignored or an error otherwise.
272
273 const uint8_t *base() const { return Buf.bytes_begin(); }
274 const uint8_t *end() const { return base() + getBufSize(); }
275
276 size_t getBufSize() const { return Buf.size(); }
277
278private:
279 StringRef Buf;
280 std::vector<Elf_Shdr> FakeSections;
281 SmallString<0> FakeSectionStrings;
282
283 // When the number of program headers is >= PN_XNUM, the actual number is
284 // contained in the sh_info field of the section header at index 0.
285 std::optional<uint32_t> RealPhNum;
286 // When the number of section headers is >= SHN_LORESERVE, the actual number
287 // is contained in the sh_size field of the section header at index 0.
288 std::optional<uint64_t> RealShNum;
289 // When the section index of the section name table is >= SHN_LORESERVE, the
290 // actual number is contained in the sh_link field of the section header at
291 // index 0.
292 std::optional<uint32_t> RealShStrNdx;
293
294 ELFFile(StringRef Object);
295
296 Error readShdrZero();
297
298public:
300 if (!RealPhNum) {
301 if (Error E = const_cast<ELFFile<ELFT> *>(this)->readShdrZero())
302 return std::move(E);
303 }
304 return *RealPhNum;
305 }
306
308 if (!RealShNum) {
309 if (Error E = const_cast<ELFFile<ELFT> *>(this)->readShdrZero())
310 return std::move(E);
311 }
312 return *RealShNum;
313 }
314
316 if (!RealShStrNdx) {
317 if (Error E = const_cast<ELFFile<ELFT> *>(this)->readShdrZero())
318 return std::move(E);
319 }
320 return *RealShStrNdx;
321 }
322
323 const Elf_Ehdr &getHeader() const {
324 return *reinterpret_cast<const Elf_Ehdr *>(base());
325 }
326
327 template <typename T>
329 template <typename T>
330 Expected<const T *> getEntry(const Elf_Shdr &Section, uint32_t Entry) const;
331
333 getVersionDefinitions(const Elf_Shdr &Sec) const;
335 const Elf_Shdr &Sec,
336 WarningHandler WarnHandler = &defaultWarningHandler) const;
338 uint32_t SymbolVersionIndex, bool &IsDefault,
339 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
340 std::optional<bool> IsSymHidden) const;
341
343 getStringTable(const Elf_Shdr &Section,
344 WarningHandler WarnHandler = &defaultWarningHandler) const;
345 Expected<StringRef> getStringTableForSymtab(const Elf_Shdr &Section) const;
347 Elf_Shdr_Range Sections) const;
348 Expected<StringRef> getLinkAsStrtab(const typename ELFT::Shdr &Sec) const;
349
350 Expected<ArrayRef<Elf_Word>> getSHNDXTable(const Elf_Shdr &Section) const;
352 Elf_Shdr_Range Sections) const;
353
355
358 SmallVectorImpl<char> &Result) const;
360
361 std::string getDynamicTagAsString(unsigned Arch, uint64_t Type) const;
363
364 /// Get the symbol for a given relocation.
366 const Elf_Shdr *SymTab) const;
367
369 loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const;
370
372
373 bool isLE() const {
374 return getHeader().getDataEncoding() == ELF::ELFDATA2LSB;
375 }
376
377 bool isMipsELF64() const {
378 return getHeader().e_machine == ELF::EM_MIPS &&
379 getHeader().getFileClass() == ELF::ELFCLASS64;
380 }
381
382 bool isMips64EL() const { return isMipsELF64() && isLE(); }
383
385
387
390 WarningHandler WarnHandler = &defaultWarningHandler) const;
391
392 Expected<Elf_Sym_Range> symbols(const Elf_Shdr *Sec) const {
393 if (!Sec)
394 return ArrayRef<Elf_Sym>(nullptr, nullptr);
396 }
397
398 Expected<Elf_Rela_Range> relas(const Elf_Shdr &Sec) const {
400 }
401
402 Expected<Elf_Rel_Range> rels(const Elf_Shdr &Sec) const {
404 }
405
406 Expected<Elf_Relr_Range> relrs(const Elf_Shdr &Sec) const {
408 }
409
410 std::vector<Elf_Rel> decode_relrs(Elf_Relr_Range relrs) const;
411
413 using RelsOrRelas = std::pair<std::vector<Elf_Rel>, std::vector<Elf_Rela>>;
415 Expected<RelsOrRelas> crels(const Elf_Shdr &Sec) const;
416
418
419 /// Iterate over program header table.
421 uint32_t NumPh;
422 if (Expected<uint32_t> PhNumOrErr = getPhNum())
423 NumPh = *PhNumOrErr;
424 else
425 return PhNumOrErr.takeError();
426 if (NumPh && getHeader().e_phentsize != sizeof(Elf_Phdr))
427 return createError("invalid e_phentsize: " +
428 Twine(getHeader().e_phentsize));
429
430 uint64_t HeadersSize = (uint64_t)NumPh * getHeader().e_phentsize;
431 uint64_t PhOff = getHeader().e_phoff;
432 if (PhOff + HeadersSize < PhOff || PhOff + HeadersSize > getBufSize())
433 return createError("program headers are longer than binary of size " +
434 Twine(getBufSize()) + ": e_phoff = 0x" +
435 Twine::utohexstr(getHeader().e_phoff) +
436 ", e_phnum = " + Twine(NumPh) +
437 ", e_phentsize = " + Twine(getHeader().e_phentsize));
438
439 auto *Begin = reinterpret_cast<const Elf_Phdr *>(base() + PhOff);
440 return ArrayRef(Begin, Begin + NumPh);
441 }
442
443 /// Get an iterator over notes in a program header.
444 ///
445 /// The program header must be of type \c PT_NOTE.
446 ///
447 /// \param Phdr the program header to iterate over.
448 /// \param Err [out] an error to support fallible iteration, which should
449 /// be checked after iteration ends.
450 Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const {
451 assert(Phdr.p_type == ELF::PT_NOTE && "Phdr is not of type PT_NOTE");
452 ErrorAsOutParameter ErrAsOutParam(Err);
453 if (Phdr.p_offset + Phdr.p_filesz > getBufSize() ||
454 Phdr.p_offset + Phdr.p_filesz < Phdr.p_offset) {
455 Err =
456 createError("invalid offset (0x" + Twine::utohexstr(Phdr.p_offset) +
457 ") or size (0x" + Twine::utohexstr(Phdr.p_filesz) + ")");
458 return Elf_Note_Iterator(Err);
459 }
460 // Allow 4, 8, and (for Linux core dumps) 0.
461 // TODO: Disallow 1 after all tests are fixed.
462 if (Phdr.p_align != 0 && Phdr.p_align != 1 && Phdr.p_align != 4 &&
463 Phdr.p_align != 8) {
464 Err =
465 createError("alignment (" + Twine(Phdr.p_align) + ") is not 4 or 8");
466 return Elf_Note_Iterator(Err);
467 }
468 return Elf_Note_Iterator(base() + Phdr.p_offset, Phdr.p_filesz,
469 std::max<size_t>(Phdr.p_align, 4), Err);
470 }
471
472 /// Get an iterator over notes in a section.
473 ///
474 /// The section must be of type \c SHT_NOTE.
475 ///
476 /// \param Shdr the section to iterate over.
477 /// \param Err [out] an error to support fallible iteration, which should
478 /// be checked after iteration ends.
479 Elf_Note_Iterator notes_begin(const Elf_Shdr &Shdr, Error &Err) const {
480 assert(Shdr.sh_type == ELF::SHT_NOTE && "Shdr is not of type SHT_NOTE");
481 ErrorAsOutParameter ErrAsOutParam(Err);
482 if (Shdr.sh_offset + Shdr.sh_size > getBufSize() ||
483 Shdr.sh_offset + Shdr.sh_size < Shdr.sh_offset) {
484 Err =
485 createError("invalid offset (0x" + Twine::utohexstr(Shdr.sh_offset) +
486 ") or size (0x" + Twine::utohexstr(Shdr.sh_size) + ")");
487 return Elf_Note_Iterator(Err);
488 }
489 // TODO: Allow just 4 and 8 after all tests are fixed.
490 if (Shdr.sh_addralign != 0 && Shdr.sh_addralign != 1 &&
491 Shdr.sh_addralign != 4 && Shdr.sh_addralign != 8) {
492 Err = createError("alignment (" + Twine(Shdr.sh_addralign) +
493 ") is not 4 or 8");
494 return Elf_Note_Iterator(Err);
495 }
496 return Elf_Note_Iterator(base() + Shdr.sh_offset, Shdr.sh_size,
497 std::max<size_t>(Shdr.sh_addralign, 4), Err);
498 }
499
500 /// Get the end iterator for notes.
501 Elf_Note_Iterator notes_end() const {
502 return Elf_Note_Iterator();
503 }
504
505 /// Get an iterator range over notes of a program header.
506 ///
507 /// The program header must be of type \c PT_NOTE.
508 ///
509 /// \param Phdr the program header to iterate over.
510 /// \param Err [out] an error to support fallible iteration, which should
511 /// be checked after iteration ends.
513 Error &Err) const {
514 return make_range(notes_begin(Phdr, Err), notes_end());
515 }
516
517 /// Get an iterator range over notes of a section.
518 ///
519 /// The section must be of type \c SHT_NOTE.
520 ///
521 /// \param Shdr the section to iterate over.
522 /// \param Err [out] an error to support fallible iteration, which should
523 /// be checked after iteration ends.
525 Error &Err) const {
526 return make_range(notes_begin(Shdr, Err), notes_end());
527 }
528
530 Elf_Shdr_Range Sections,
531 WarningHandler WarnHandler = &defaultWarningHandler) const;
532 Expected<uint32_t> getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms,
533 DataRegion<Elf_Word> ShndxTable) const;
535 const Elf_Shdr *SymTab,
536 DataRegion<Elf_Word> ShndxTable) const;
538 Elf_Sym_Range Symtab,
539 DataRegion<Elf_Word> ShndxTable) const;
541
543 uint32_t Index) const;
544
546 getSectionName(const Elf_Shdr &Section,
547 WarningHandler WarnHandler = &defaultWarningHandler) const;
548 Expected<StringRef> getSectionName(const Elf_Shdr &Section,
549 StringRef DotShstrtab) const;
550 template <typename T>
553 Expected<ArrayRef<uint8_t>> getSegmentContents(const Elf_Phdr &Phdr) const;
554
555 /// Returns a vector of BBAddrMap structs corresponding to each function
556 /// within the text section that the SHT_LLVM_BB_ADDR_MAP section \p Sec
557 /// is associated with. If the current ELFFile is relocatable, a corresponding
558 /// \p RelaSec must be passed in as an argument.
559 /// Optional out variable to collect all PGO Analyses. New elements are only
560 /// added if no error occurs. If not provided, the PGO Analyses are decoded
561 /// then ignored.
563 decodeBBAddrMap(const Elf_Shdr &Sec, const Elf_Shdr *RelaSec = nullptr,
564 std::vector<PGOAnalysisMap> *PGOAnalyses = nullptr) const;
565
566 /// Returns a map from every section matching \p IsMatch to its relocation
567 /// section, or \p nullptr if it has no relocation section. This function
568 /// returns an error if any of the \p IsMatch calls fail or if it fails to
569 /// retrieve the content section of any relocation section.
572 std::function<Expected<bool>(const Elf_Shdr &)> IsMatch) const;
573
575};
576
581
582template <class ELFT>
584getSection(typename ELFT::ShdrRange Sections, uint32_t Index) {
585 if (Index >= Sections.size())
586 return createError("invalid section index: " + Twine(Index));
587 return &Sections[Index];
588}
589
590template <class ELFT>
592getExtendedSymbolTableIndex(const typename ELFT::Sym &Sym, unsigned SymIndex,
594 assert(Sym.st_shndx == ELF::SHN_XINDEX);
595 if (!ShndxTable.First)
596 return createError(
597 "found an extended symbol index (" + Twine(SymIndex) +
598 "), but unable to locate the extended symbol index table");
599
600 Expected<typename ELFT::Word> TableOrErr = ShndxTable[SymIndex];
601 if (!TableOrErr)
602 return createError("unable to read an extended symbol table at index " +
603 Twine(SymIndex) + ": " +
604 toString(TableOrErr.takeError()));
605 return *TableOrErr;
606}
607
608template <class ELFT>
610ELFFile<ELFT>::getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms,
611 DataRegion<Elf_Word> ShndxTable) const {
612 uint32_t Index = Sym.st_shndx;
613 if (Index == ELF::SHN_XINDEX) {
614 Expected<uint32_t> ErrorOrIndex =
615 getExtendedSymbolTableIndex<ELFT>(Sym, &Sym - Syms.begin(), ShndxTable);
616 if (!ErrorOrIndex)
617 return ErrorOrIndex.takeError();
618 return *ErrorOrIndex;
619 }
620 if (Index == ELF::SHN_UNDEF || Index >= ELF::SHN_LORESERVE)
621 return 0;
622 return Index;
623}
624
625template <class ELFT>
627ELFFile<ELFT>::getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab,
628 DataRegion<Elf_Word> ShndxTable) const {
629 auto SymsOrErr = symbols(SymTab);
630 if (!SymsOrErr)
631 return SymsOrErr.takeError();
632 return getSection(Sym, *SymsOrErr, ShndxTable);
633}
634
635template <class ELFT>
637ELFFile<ELFT>::getSection(const Elf_Sym &Sym, Elf_Sym_Range Symbols,
638 DataRegion<Elf_Word> ShndxTable) const {
639 auto IndexOrErr = getSectionIndex(Sym, Symbols, ShndxTable);
640 if (!IndexOrErr)
641 return IndexOrErr.takeError();
642 uint32_t Index = *IndexOrErr;
643 if (Index == 0)
644 return nullptr;
645 return getSection(Index);
646}
647
648template <class ELFT>
650ELFFile<ELFT>::getSymbol(const Elf_Shdr *Sec, uint32_t Index) const {
651 auto SymsOrErr = symbols(Sec);
652 if (!SymsOrErr)
653 return SymsOrErr.takeError();
654
655 Elf_Sym_Range Symbols = *SymsOrErr;
656 if (Index >= Symbols.size())
657 return createError("unable to get symbol from section " +
658 getSecIndexForError(*this, *Sec) +
659 ": invalid symbol index (" + Twine(Index) + ")");
660 return &Symbols[Index];
661}
662
663template <class ELFT>
664template <typename T>
667 if (Sec.sh_entsize != sizeof(T) && sizeof(T) != 1)
668 return createError("section " + getSecIndexForError(*this, Sec) +
669 " has invalid sh_entsize: expected " + Twine(sizeof(T)) +
670 ", but got " + Twine(Sec.sh_entsize));
671
672 uintX_t Offset = Sec.sh_offset;
673 uintX_t Size = Sec.sh_size;
674
675 if (Size % sizeof(T))
676 return createError("section " + getSecIndexForError(*this, Sec) +
677 " has an invalid sh_size (" + Twine(Size) +
678 ") which is not a multiple of its sh_entsize (" +
679 Twine(Sec.sh_entsize) + ")");
680 if (std::numeric_limits<uintX_t>::max() - Offset < Size)
681 return createError("section " + getSecIndexForError(*this, Sec) +
682 " has a sh_offset (0x" + Twine::utohexstr(Offset) +
683 ") + sh_size (0x" + Twine::utohexstr(Size) +
684 ") that cannot be represented");
685 if (Offset + Size > Buf.size())
686 return createError("section " + getSecIndexForError(*this, Sec) +
687 " has a sh_offset (0x" + Twine::utohexstr(Offset) +
688 ") + sh_size (0x" + Twine::utohexstr(Size) +
689 ") that is greater than the file size (0x" +
690 Twine::utohexstr(Buf.size()) + ")");
691
692 if (Offset % alignof(T))
693 // TODO: this error is untested.
694 return createError("unaligned data");
695
696 const T *Start = reinterpret_cast<const T *>(base() + Offset);
697 return ArrayRef(Start, Size / sizeof(T));
698}
699
700template <class ELFT>
702ELFFile<ELFT>::getSegmentContents(const Elf_Phdr &Phdr) const {
703 uintX_t Offset = Phdr.p_offset;
704 uintX_t Size = Phdr.p_filesz;
705
706 if (std::numeric_limits<uintX_t>::max() - Offset < Size)
707 return createError("program header " + getPhdrIndexForError(*this, Phdr) +
708 " has a p_offset (0x" + Twine::utohexstr(Offset) +
709 ") + p_filesz (0x" + Twine::utohexstr(Size) +
710 ") that cannot be represented");
711 if (Offset + Size > Buf.size())
712 return createError("program header " + getPhdrIndexForError(*this, Phdr) +
713 " has a p_offset (0x" + Twine::utohexstr(Offset) +
714 ") + p_filesz (0x" + Twine::utohexstr(Size) +
715 ") that is greater than the file size (0x" +
716 Twine::utohexstr(Buf.size()) + ")");
717 return ArrayRef(base() + Offset, Size);
718}
719
720template <class ELFT>
722ELFFile<ELFT>::getSectionContents(const Elf_Shdr &Sec) const {
724}
725
726template <class ELFT>
730
731template <class ELFT>
733 SmallVectorImpl<char> &Result) const {
734 if (!isMipsELF64()) {
736 Result.append(Name.begin(), Name.end());
737 } else {
738 // The Mips N64 ABI allows up to three operations to be specified per
739 // relocation record. Unfortunately there's no easy way to test for the
740 // presence of N64 ELFs as they have no special flag that identifies them
741 // as being N64. We can safely assume at the moment that all Mips
742 // ELFCLASS64 ELFs are N64. New Mips64 ABIs should provide enough
743 // information to disambiguate between old vs new ABIs.
744 uint8_t Type1 = (Type >> 0) & 0xFF;
745 uint8_t Type2 = (Type >> 8) & 0xFF;
746 uint8_t Type3 = (Type >> 16) & 0xFF;
747
748 // Concat all three relocation type names.
749 StringRef Name = getRelocationTypeName(Type1);
750 Result.append(Name.begin(), Name.end());
751
752 Name = getRelocationTypeName(Type2);
753 Result.append(1, '/');
754 Result.append(Name.begin(), Name.end());
755
756 Name = getRelocationTypeName(Type3);
757 Result.append(1, '/');
758 Result.append(Name.begin(), Name.end());
759 }
760}
761
762template <class ELFT>
766
767template <class ELFT>
769ELFFile<ELFT>::loadVersionMap(const Elf_Shdr *VerNeedSec,
770 const Elf_Shdr *VerDefSec) const {
772
773 // The first two version indexes are reserved.
774 // Index 0 is VER_NDX_LOCAL, index 1 is VER_NDX_GLOBAL.
775 VersionMap.push_back(VersionEntry());
776 VersionMap.push_back(VersionEntry());
777
778 auto InsertEntry = [&](unsigned N, StringRef Version, bool IsVerdef) {
779 if (N >= VersionMap.size())
780 VersionMap.resize(N + 1);
781 VersionMap[N] = {std::string(Version), IsVerdef};
782 };
783
784 if (VerDefSec) {
786 if (!Defs)
787 return Defs.takeError();
788 for (const VerDef &Def : *Defs)
789 InsertEntry(Def.Ndx & ELF::VERSYM_VERSION, Def.Name, true);
790 }
791
792 if (VerNeedSec) {
794 if (!Deps)
795 return Deps.takeError();
796 for (const VerNeed &Dep : *Deps)
797 for (const VernAux &Aux : Dep.AuxV)
798 InsertEntry(Aux.Other & ELF::VERSYM_VERSION, Aux.Name, false);
799 }
800
801 return VersionMap;
802}
803
804template <class ELFT>
807 const Elf_Shdr *SymTab) const {
808 uint32_t Index = Rel.getSymbol(isMips64EL());
809 if (Index == 0)
810 return nullptr;
811 return getEntry<Elf_Sym>(*SymTab, Index);
812}
813
814template <class ELFT>
817 WarningHandler WarnHandler) const {
818 Expected<uint32_t> ShStrNdxOrErr = getShStrNdx();
819 if (!ShStrNdxOrErr)
820 return ShStrNdxOrErr.takeError();
821
822 if (*ShStrNdxOrErr == ELF::SHN_XINDEX && Sections.empty())
823 return createError(
824 "e_shstrndx == SHN_XINDEX, but the section header table is empty");
825
826 uint32_t Index = *ShStrNdxOrErr;
827 // There is no section name string table. Return FakeSectionStrings which
828 // is non-empty if we have created fake sections.
829 if (!Index)
830 return FakeSectionStrings;
831
832 if (Index >= Sections.size())
833 return createError("section header string table index " + Twine(Index) +
834 " does not exist");
835 return getStringTable(Sections[Index], WarnHandler);
836}
837
838/// This function finds the number of dynamic symbols using a GNU hash table.
839///
840/// @param Table The GNU hash table for .dynsym.
841template <class ELFT>
843getDynSymtabSizeFromGnuHash(const typename ELFT::GnuHash &Table,
844 const void *BufEnd) {
845 using Elf_Word = typename ELFT::Word;
846 if (Table.nbuckets == 0)
847 return Table.symndx + 1;
848 uint64_t LastSymIdx = 0;
849 // Find the index of the first symbol in the last chain.
850 for (Elf_Word Val : Table.buckets())
851 LastSymIdx = std::max(LastSymIdx, (uint64_t)Val);
852 const Elf_Word *It =
853 reinterpret_cast<const Elf_Word *>(Table.values(LastSymIdx).end());
854 // Locate the end of the chain to find the last symbol index.
855 while (It < BufEnd && (*It & 1) == 0) {
856 ++LastSymIdx;
857 ++It;
858 }
859 if (It >= BufEnd) {
860 return createStringError(
862 "no terminator found for GNU hash section before buffer end");
863 }
864 return LastSymIdx + 1;
865}
866
867/// This function determines the number of dynamic symbols. It reads section
868/// headers first. If section headers are not available, the number of
869/// symbols will be inferred by parsing dynamic hash tables.
870template <class ELFT>
872 // Read .dynsym section header first if available.
873 Expected<Elf_Shdr_Range> SectionsOrError = sections();
874 if (!SectionsOrError)
875 return SectionsOrError.takeError();
876 for (const Elf_Shdr &Sec : *SectionsOrError) {
877 if (Sec.sh_type == ELF::SHT_DYNSYM) {
878 if (Sec.sh_size % Sec.sh_entsize != 0) {
880 "SHT_DYNSYM section has sh_size (" +
881 Twine(Sec.sh_size) + ") % sh_entsize (" +
882 Twine(Sec.sh_entsize) + ") that is not 0");
883 }
884 return Sec.sh_size / Sec.sh_entsize;
885 }
886 }
887
888 if (!SectionsOrError->empty()) {
889 // Section headers are available but .dynsym header is not found.
890 // Return 0 as .dynsym does not exist.
891 return 0;
892 }
893
894 // Section headers do not exist. Falling back to infer
895 // upper bound of .dynsym from .gnu.hash and .hash.
897 if (!DynTable)
898 return DynTable.takeError();
899 std::optional<uint64_t> ElfHash;
900 std::optional<uint64_t> ElfGnuHash;
901 for (const Elf_Dyn &Entry : *DynTable) {
902 switch (Entry.d_tag) {
903 case ELF::DT_HASH:
904 ElfHash = Entry.d_un.d_ptr;
905 break;
906 case ELF::DT_GNU_HASH:
907 ElfGnuHash = Entry.d_un.d_ptr;
908 break;
909 }
910 }
911 if (ElfGnuHash) {
912 Expected<const uint8_t *> TablePtr = toMappedAddr(*ElfGnuHash);
913 if (!TablePtr)
914 return TablePtr.takeError();
915 const Elf_GnuHash *Table =
916 reinterpret_cast<const Elf_GnuHash *>(TablePtr.get());
917 return getDynSymtabSizeFromGnuHash<ELFT>(*Table, this->Buf.bytes_end());
918 }
919
920 // Search SYSV hash table to try to find the upper bound of dynsym.
921 if (ElfHash) {
922 Expected<const uint8_t *> TablePtr = toMappedAddr(*ElfHash);
923 if (!TablePtr)
924 return TablePtr.takeError();
925 const Elf_Hash *Table = reinterpret_cast<const Elf_Hash *>(TablePtr.get());
926 return Table->nchain;
927 }
928 return 0;
929}
930
931template <class ELFT> ELFFile<ELFT>::ELFFile(StringRef Object) : Buf(Object) {}
932
933template <class ELFT> Error ELFFile<ELFT>::readShdrZero() {
934 const Elf_Ehdr &Header = getHeader();
935
936 if ((Header.e_phnum == ELF::PN_XNUM || Header.e_shnum == 0 ||
937 Header.e_shstrndx == ELF::SHN_XINDEX) &&
938 Header.e_shoff != 0) {
939 // Pretend we have section 0 or sections() would call getShNum and thus
940 // become an infinite recursion.
941 RealShNum = 1;
942 auto SecOrErr = getSection(0);
943 if (!SecOrErr) {
944 RealShNum = std::nullopt;
945 return SecOrErr.takeError();
946 }
947
948 RealPhNum =
949 Header.e_phnum == ELF::PN_XNUM ? (*SecOrErr)->sh_info : Header.e_phnum;
950 RealShNum = Header.e_shnum == 0 ? (*SecOrErr)->sh_size : Header.e_shnum;
951 RealShStrNdx = Header.e_shstrndx == ELF::SHN_XINDEX ? (*SecOrErr)->sh_link
952 : Header.e_shstrndx;
953 } else {
954 RealPhNum = Header.e_phnum;
955 RealShNum = Header.e_shnum;
956 RealShStrNdx = Header.e_shstrndx;
957 }
958
959 return Error::success();
960}
961
962template <class ELFT>
964 if (sizeof(Elf_Ehdr) > Object.size())
965 return createError("invalid buffer: the size (" + Twine(Object.size()) +
966 ") is smaller than an ELF header (" +
967 Twine(sizeof(Elf_Ehdr)) + ")");
968 return ELFFile(Object);
969}
970
971/// Used by llvm-objdump -d (which needs sections for disassembly) to
972/// disassemble objects without a section header table (e.g. ET_CORE objects
973/// analyzed by linux perf or ET_EXEC with llvm-strip --strip-sections).
974template <class ELFT> void ELFFile<ELFT>::createFakeSections() {
975 if (!FakeSections.empty())
976 return;
977 auto PhdrsOrErr = program_headers();
978 if (!PhdrsOrErr)
979 return;
980
981 FakeSectionStrings += '\0';
982 for (auto [Idx, Phdr] : llvm::enumerate(*PhdrsOrErr)) {
983 if (Phdr.p_type != ELF::PT_LOAD || !(Phdr.p_flags & ELF::PF_X))
984 continue;
985 Elf_Shdr FakeShdr = {};
986 FakeShdr.sh_type = ELF::SHT_PROGBITS;
987 FakeShdr.sh_flags = ELF::SHF_ALLOC | ELF::SHF_EXECINSTR;
988 FakeShdr.sh_addr = Phdr.p_vaddr;
989 FakeShdr.sh_size = Phdr.p_memsz;
990 FakeShdr.sh_offset = Phdr.p_offset;
991 // Create a section name based on the p_type and index.
992 FakeShdr.sh_name = FakeSectionStrings.size();
993 FakeSectionStrings += ("PT_LOAD#" + Twine(Idx)).str();
994 FakeSectionStrings += '\0';
995 FakeSections.push_back(FakeShdr);
996 }
997}
998
999template <class ELFT>
1001 const uintX_t SectionTableOffset = getHeader().e_shoff;
1002 if (SectionTableOffset == 0) {
1003 if (!FakeSections.empty())
1004 return ArrayRef(FakeSections);
1005 return ArrayRef<Elf_Shdr>();
1006 }
1007
1008 if (getHeader().e_shentsize != sizeof(Elf_Shdr))
1009 return createError("invalid e_shentsize in ELF header: " +
1010 Twine(getHeader().e_shentsize));
1011
1012 const uint64_t FileSize = Buf.size();
1013 if (SectionTableOffset + sizeof(Elf_Shdr) > FileSize ||
1014 SectionTableOffset + (uintX_t)sizeof(Elf_Shdr) < SectionTableOffset)
1015 return createError(
1016 "section header table goes past the end of the file: e_shoff = 0x" +
1017 Twine::utohexstr(SectionTableOffset));
1018
1019 // Invalid address alignment of section headers
1020 if (SectionTableOffset & (alignof(Elf_Shdr) - 1))
1021 // TODO: this error is untested.
1022 return createError("invalid alignment of section headers");
1023
1024 const Elf_Shdr *First =
1025 reinterpret_cast<const Elf_Shdr *>(base() + SectionTableOffset);
1026
1027 uintX_t NumSections = 0;
1028 if (Expected<uint64_t> ShNumOrErr = getShNum())
1029 NumSections = *ShNumOrErr;
1030 else
1031 return ShNumOrErr.takeError();
1032
1033 if (NumSections > UINT64_MAX / sizeof(Elf_Shdr))
1034 return createError("invalid number of sections specified in the NULL "
1035 "section's sh_size field (" +
1036 Twine(NumSections) + ")");
1037
1038 const uint64_t SectionTableSize = NumSections * sizeof(Elf_Shdr);
1039 if (SectionTableOffset + SectionTableSize < SectionTableOffset)
1040 return createError(
1041 "invalid section header table offset (e_shoff = 0x" +
1042 Twine::utohexstr(SectionTableOffset) +
1043 ") or invalid number of sections specified in the first section "
1044 "header's sh_size field (0x" +
1045 Twine::utohexstr(NumSections) + ")");
1046
1047 // Section table goes past end of file!
1048 if (SectionTableOffset + SectionTableSize > FileSize)
1049 return createError("section table goes past the end of file");
1050 return ArrayRef(First, NumSections);
1051}
1052
1053template <class ELFT>
1054template <typename T>
1056 uint32_t Entry) const {
1057 auto SecOrErr = getSection(Section);
1058 if (!SecOrErr)
1059 return SecOrErr.takeError();
1060 return getEntry<T>(**SecOrErr, Entry);
1061}
1062
1063template <class ELFT>
1064template <typename T>
1066 uint32_t Entry) const {
1067 Expected<ArrayRef<T>> EntriesOrErr = getSectionContentsAsArray<T>(Section);
1068 if (!EntriesOrErr)
1069 return EntriesOrErr.takeError();
1070
1071 ArrayRef<T> Arr = *EntriesOrErr;
1072 if (Entry >= Arr.size())
1073 return createError(
1074 "can't read an entry at 0x" +
1075 Twine::utohexstr(Entry * static_cast<uint64_t>(sizeof(T))) +
1076 ": it goes past the end of the section (0x" +
1077 Twine::utohexstr(Section.sh_size) + ")");
1078 return &Arr[Entry];
1079}
1080
1081template <typename ELFT>
1083 uint32_t SymbolVersionIndex, bool &IsDefault,
1084 SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
1085 std::optional<bool> IsSymHidden) const {
1086 size_t VersionIndex = SymbolVersionIndex & llvm::ELF::VERSYM_VERSION;
1087
1088 // Special markers for unversioned symbols.
1089 if (VersionIndex == llvm::ELF::VER_NDX_LOCAL ||
1090 VersionIndex == llvm::ELF::VER_NDX_GLOBAL) {
1091 IsDefault = false;
1092 return "";
1093 }
1094
1095 // Lookup this symbol in the version table.
1096 if (VersionIndex >= VersionMap.size() || !VersionMap[VersionIndex])
1097 return createError("SHT_GNU_versym section refers to a version index " +
1098 Twine(VersionIndex) + " which is missing");
1099
1100 const VersionEntry &Entry = *VersionMap[VersionIndex];
1101 // A default version (@@) is only available for defined symbols.
1102 if (!Entry.IsVerDef || IsSymHidden.value_or(false))
1103 IsDefault = false;
1104 else
1105 IsDefault = !(SymbolVersionIndex & llvm::ELF::VERSYM_HIDDEN);
1106 return Entry.Name.c_str();
1107}
1108
1109template <class ELFT>
1111ELFFile<ELFT>::getVersionDefinitions(const Elf_Shdr &Sec) const {
1112 Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Sec);
1113 if (!StrTabOrErr)
1114 return StrTabOrErr.takeError();
1115
1116 Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
1117 if (!ContentsOrErr)
1118 return createError("cannot read content of " + describe(*this, Sec) + ": " +
1119 toString(ContentsOrErr.takeError()));
1120
1121 const uint8_t *Start = ContentsOrErr->data();
1122 const uint8_t *End = Start + ContentsOrErr->size();
1123
1124 auto ExtractNextAux = [&](const uint8_t *&VerdauxBuf,
1125 unsigned VerDefNdx) -> Expected<VerdAux> {
1126 if (VerdauxBuf + sizeof(Elf_Verdaux) > End)
1127 return createError("invalid " + describe(*this, Sec) +
1128 ": version definition " + Twine(VerDefNdx) +
1129 " refers to an auxiliary entry that goes past the end "
1130 "of the section");
1131
1132 auto *Verdaux = reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf);
1133 VerdauxBuf += Verdaux->vda_next;
1134
1135 VerdAux Aux;
1136 Aux.Offset = VerdauxBuf - Start;
1137 if (Verdaux->vda_name < StrTabOrErr->size())
1138 Aux.Name = std::string(StrTabOrErr->drop_front(Verdaux->vda_name).data());
1139 else
1140 Aux.Name = ("<invalid vda_name: " + Twine(Verdaux->vda_name) + ">").str();
1141 return Aux;
1142 };
1143
1144 std::vector<VerDef> Ret;
1145 const uint8_t *VerdefBuf = Start;
1146 for (unsigned I = 1; I <= /*VerDefsNum=*/Sec.sh_info; ++I) {
1147 if (VerdefBuf + sizeof(Elf_Verdef) > End)
1148 return createError("invalid " + describe(*this, Sec) +
1149 ": version definition " + Twine(I) +
1150 " goes past the end of the section");
1151
1152 if (reinterpret_cast<uintptr_t>(VerdefBuf) % sizeof(uint32_t) != 0)
1153 return createError(
1154 "invalid " + describe(*this, Sec) +
1155 ": found a misaligned version definition entry at offset 0x" +
1156 Twine::utohexstr(VerdefBuf - Start));
1157
1158 unsigned Version = *reinterpret_cast<const Elf_Half *>(VerdefBuf);
1159 if (Version != 1)
1160 return createError("unable to dump " + describe(*this, Sec) +
1161 ": version " + Twine(Version) +
1162 " is not yet supported");
1163
1164 const Elf_Verdef *D = reinterpret_cast<const Elf_Verdef *>(VerdefBuf);
1165 VerDef &VD = *Ret.emplace(Ret.end());
1166 VD.Offset = VerdefBuf - Start;
1167 VD.Version = D->vd_version;
1168 VD.Flags = D->vd_flags;
1169 VD.Ndx = D->vd_ndx;
1170 VD.Cnt = D->vd_cnt;
1171 VD.Hash = D->vd_hash;
1172
1173 const uint8_t *VerdauxBuf = VerdefBuf + D->vd_aux;
1174 for (unsigned J = 0; J < D->vd_cnt; ++J) {
1175 if (reinterpret_cast<uintptr_t>(VerdauxBuf) % sizeof(uint32_t) != 0)
1176 return createError("invalid " + describe(*this, Sec) +
1177 ": found a misaligned auxiliary entry at offset 0x" +
1178 Twine::utohexstr(VerdauxBuf - Start));
1179
1180 Expected<VerdAux> AuxOrErr = ExtractNextAux(VerdauxBuf, I);
1181 if (!AuxOrErr)
1182 return AuxOrErr.takeError();
1183
1184 if (J == 0)
1185 VD.Name = AuxOrErr->Name;
1186 else
1187 VD.AuxV.push_back(*AuxOrErr);
1188 }
1189
1190 VerdefBuf += D->vd_next;
1191 }
1192
1193 return Ret;
1194}
1195
1196template <class ELFT>
1199 WarningHandler WarnHandler) const {
1200 StringRef StrTab;
1201 Expected<StringRef> StrTabOrErr = getLinkAsStrtab(Sec);
1202 if (!StrTabOrErr) {
1203 if (Error E = WarnHandler(toString(StrTabOrErr.takeError())))
1204 return std::move(E);
1205 } else {
1206 StrTab = *StrTabOrErr;
1207 }
1208
1209 Expected<ArrayRef<uint8_t>> ContentsOrErr = getSectionContents(Sec);
1210 if (!ContentsOrErr)
1211 return createError("cannot read content of " + describe(*this, Sec) + ": " +
1212 toString(ContentsOrErr.takeError()));
1213
1214 const uint8_t *Start = ContentsOrErr->data();
1215 const uint8_t *End = Start + ContentsOrErr->size();
1216 const uint8_t *VerneedBuf = Start;
1217
1218 std::vector<VerNeed> Ret;
1219 for (unsigned I = 1; I <= /*VerneedNum=*/Sec.sh_info; ++I) {
1220 if (VerneedBuf + sizeof(Elf_Verdef) > End)
1221 return createError("invalid " + describe(*this, Sec) +
1222 ": version dependency " + Twine(I) +
1223 " goes past the end of the section");
1224
1225 if (reinterpret_cast<uintptr_t>(VerneedBuf) % sizeof(uint32_t) != 0)
1226 return createError(
1227 "invalid " + describe(*this, Sec) +
1228 ": found a misaligned version dependency entry at offset 0x" +
1229 Twine::utohexstr(VerneedBuf - Start));
1230
1231 unsigned Version = *reinterpret_cast<const Elf_Half *>(VerneedBuf);
1232 if (Version != 1)
1233 return createError("unable to dump " + describe(*this, Sec) +
1234 ": version " + Twine(Version) +
1235 " is not yet supported");
1236
1237 const Elf_Verneed *Verneed =
1238 reinterpret_cast<const Elf_Verneed *>(VerneedBuf);
1239
1240 VerNeed &VN = *Ret.emplace(Ret.end());
1241 VN.Version = Verneed->vn_version;
1242 VN.Cnt = Verneed->vn_cnt;
1243 VN.Offset = VerneedBuf - Start;
1244
1245 if (Verneed->vn_file < StrTab.size())
1246 VN.File = std::string(StrTab.data() + Verneed->vn_file);
1247 else
1248 VN.File = ("<corrupt vn_file: " + Twine(Verneed->vn_file) + ">").str();
1249
1250 const uint8_t *VernauxBuf = VerneedBuf + Verneed->vn_aux;
1251 for (unsigned J = 0; J < Verneed->vn_cnt; ++J) {
1252 if (reinterpret_cast<uintptr_t>(VernauxBuf) % sizeof(uint32_t) != 0)
1253 return createError("invalid " + describe(*this, Sec) +
1254 ": found a misaligned auxiliary entry at offset 0x" +
1255 Twine::utohexstr(VernauxBuf - Start));
1256
1257 if (VernauxBuf + sizeof(Elf_Vernaux) > End)
1258 return createError(
1259 "invalid " + describe(*this, Sec) + ": version dependency " +
1260 Twine(I) +
1261 " refers to an auxiliary entry that goes past the end "
1262 "of the section");
1263
1264 const Elf_Vernaux *Vernaux =
1265 reinterpret_cast<const Elf_Vernaux *>(VernauxBuf);
1266
1267 VernAux &Aux = *VN.AuxV.emplace(VN.AuxV.end());
1268 Aux.Hash = Vernaux->vna_hash;
1269 Aux.Flags = Vernaux->vna_flags;
1270 Aux.Other = Vernaux->vna_other;
1271 Aux.Offset = VernauxBuf - Start;
1272 if (StrTab.size() <= Vernaux->vna_name)
1273 Aux.Name = "<corrupt>";
1274 else
1275 Aux.Name = std::string(StrTab.drop_front(Vernaux->vna_name));
1276
1277 VernauxBuf += Vernaux->vna_next;
1278 }
1279 VerneedBuf += Verneed->vn_next;
1280 }
1281 return Ret;
1282}
1283
1284template <class ELFT>
1287 auto TableOrErr = sections();
1288 if (!TableOrErr)
1289 return TableOrErr.takeError();
1290 return object::getSection<ELFT>(*TableOrErr, Index);
1291}
1292
1293template <class ELFT>
1295ELFFile<ELFT>::getStringTable(const Elf_Shdr &Section,
1296 WarningHandler WarnHandler) const {
1297 if (Section.sh_type != ELF::SHT_STRTAB)
1298 if (Error E = WarnHandler("invalid sh_type for string table section " +
1299 getSecIndexForError(*this, Section) +
1300 ": expected SHT_STRTAB, but got " +
1302 getHeader().e_machine, Section.sh_type)))
1303 return std::move(E);
1304
1305 auto V = getSectionContentsAsArray<char>(Section);
1306 if (!V)
1307 return V.takeError();
1308 ArrayRef<char> Data = *V;
1309 if (Data.empty())
1310 return createError("SHT_STRTAB string table section " +
1311 getSecIndexForError(*this, Section) + " is empty");
1312 if (Data.back() != '\0')
1313 return createError("SHT_STRTAB string table section " +
1314 getSecIndexForError(*this, Section) +
1315 " is non-null terminated");
1316 return StringRef(Data.begin(), Data.size());
1317}
1318
1319template <class ELFT>
1321ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section) const {
1322 auto SectionsOrErr = sections();
1323 if (!SectionsOrErr)
1324 return SectionsOrErr.takeError();
1325 return getSHNDXTable(Section, *SectionsOrErr);
1326}
1327
1328template <class ELFT>
1330ELFFile<ELFT>::getSHNDXTable(const Elf_Shdr &Section,
1331 Elf_Shdr_Range Sections) const {
1332 assert(Section.sh_type == ELF::SHT_SYMTAB_SHNDX);
1333 auto VOrErr = getSectionContentsAsArray<Elf_Word>(Section);
1334 if (!VOrErr)
1335 return VOrErr.takeError();
1336 ArrayRef<Elf_Word> V = *VOrErr;
1337 auto SymTableOrErr = object::getSection<ELFT>(Sections, Section.sh_link);
1338 if (!SymTableOrErr)
1339 return SymTableOrErr.takeError();
1340 const Elf_Shdr &SymTable = **SymTableOrErr;
1341 if (SymTable.sh_type != ELF::SHT_SYMTAB &&
1342 SymTable.sh_type != ELF::SHT_DYNSYM)
1343 return createError(
1344 "SHT_SYMTAB_SHNDX section is linked with " +
1345 object::getELFSectionTypeName(getHeader().e_machine, SymTable.sh_type) +
1346 " section (expected SHT_SYMTAB/SHT_DYNSYM)");
1347
1348 uint64_t Syms = SymTable.sh_size / sizeof(Elf_Sym);
1349 if (V.size() != Syms)
1350 return createError("SHT_SYMTAB_SHNDX has " + Twine(V.size()) +
1351 " entries, but the symbol table associated has " +
1352 Twine(Syms));
1353
1354 return V;
1355}
1356
1357template <class ELFT>
1359ELFFile<ELFT>::getStringTableForSymtab(const Elf_Shdr &Sec) const {
1360 auto SectionsOrErr = sections();
1361 if (!SectionsOrErr)
1362 return SectionsOrErr.takeError();
1363 return getStringTableForSymtab(Sec, *SectionsOrErr);
1364}
1365
1366template <class ELFT>
1369 Elf_Shdr_Range Sections) const {
1370
1371 if (Sec.sh_type != ELF::SHT_SYMTAB && Sec.sh_type != ELF::SHT_DYNSYM)
1372 return createError(
1373 "invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM");
1374 Expected<const Elf_Shdr *> SectionOrErr =
1375 object::getSection<ELFT>(Sections, Sec.sh_link);
1376 if (!SectionOrErr)
1377 return SectionOrErr.takeError();
1378 return getStringTable(**SectionOrErr);
1379}
1380
1381template <class ELFT>
1383ELFFile<ELFT>::getLinkAsStrtab(const typename ELFT::Shdr &Sec) const {
1385 getSection(Sec.sh_link);
1386 if (!StrTabSecOrErr)
1387 return createError("invalid section linked to " + describe(*this, Sec) +
1388 ": " + toString(StrTabSecOrErr.takeError()));
1389
1390 Expected<StringRef> StrTabOrErr = getStringTable(**StrTabSecOrErr);
1391 if (!StrTabOrErr)
1392 return createError("invalid string table linked to " +
1393 describe(*this, Sec) + ": " +
1394 toString(StrTabOrErr.takeError()));
1395 return *StrTabOrErr;
1396}
1397
1398template <class ELFT>
1400ELFFile<ELFT>::getSectionName(const Elf_Shdr &Section,
1401 WarningHandler WarnHandler) const {
1402 auto SectionsOrErr = sections();
1403 if (!SectionsOrErr)
1404 return SectionsOrErr.takeError();
1405 auto Table = getSectionStringTable(*SectionsOrErr, WarnHandler);
1406 if (!Table)
1407 return Table.takeError();
1408 return getSectionName(Section, *Table);
1409}
1410
1411template <class ELFT>
1413 StringRef DotShstrtab) const {
1414 uint32_t Offset = Section.sh_name;
1415 if (Offset == 0)
1416 return StringRef();
1417 if (Offset >= DotShstrtab.size())
1418 return createError("a section " + getSecIndexForError(*this, Section) +
1419 " has an invalid sh_name (0x" +
1421 ") offset which goes past the end of the "
1422 "section name string table");
1423 return StringRef(DotShstrtab.data() + Offset);
1424}
1425
1426/// This function returns the hash value for a symbol in the .dynsym section
1427/// Name of the API remains consistent as specified in the libelf
1428/// REF : http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#hash
1429inline uint32_t hashSysV(StringRef SymbolName) {
1430 uint32_t H = 0;
1431 for (uint8_t C : SymbolName) {
1432 H = (H << 4) + C;
1433 H ^= (H >> 24) & 0xf0;
1434 }
1435 return H & 0x0fffffff;
1436}
1437
1438/// This function returns the hash value for a symbol in the .dynsym section
1439/// for the GNU hash table. The implementation is defined in the GNU hash ABI.
1440/// REF : https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf.c#l222
1442 uint32_t H = 5381;
1443 for (uint8_t C : Name)
1444 H = (H << 5) + H + C;
1445 return H;
1446}
1447
1452
1453} // end namespace object
1454} // end namespace llvm
1455
1456#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:143
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:271
const Elf_Ehdr & getHeader() const
Definition ELF.h:323
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:1383
static Expected< ELFFile > create(StringRef Object)
Definition ELF.h:963
Expected< const Elf_Shdr * > getSection(uint32_t Index) const
Definition ELF.h:1286
Expected< StringRef > getSectionName(const Elf_Shdr &Section, StringRef DotShstrtab) const
Definition ELF.h:1412
Expected< ArrayRef< Elf_Word > > getSHNDXTable(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const
Definition ELF.h:1330
Expected< const Elf_Sym * > getSymbol(const Elf_Shdr *Sec, uint32_t Index) const
Definition ELF.h:650
Expected< std::vector< VerDef > > getVersionDefinitions(const Elf_Shdr &Sec) const
Definition ELF.h:1111
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:1321
Expected< const Elf_Shdr * > getSection(const Elf_Sym &Sym, Elf_Sym_Range Symtab, DataRegion< Elf_Word > ShndxTable) const
Definition ELF.h:637
Expected< Elf_Sym_Range > symbols(const Elf_Shdr *Sec) const
Definition ELF.h:392
Expected< uint64_t > getShNum() const
Definition ELF.h:307
Expected< ArrayRef< uint8_t > > getSegmentContents(const Elf_Phdr &Phdr) const
Definition ELF.h:702
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:479
uint32_t getRelativeRelocationType() const
Definition ELF.h:763
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:512
Expected< StringRef > getSymbolVersionByIndex(uint32_t SymbolVersionIndex, bool &IsDefault, SmallVector< std::optional< VersionEntry >, 0 > &VersionMap, std::optional< bool > IsSymHidden) const
Definition ELF.h:1082
Elf_Note_Iterator notes_begin(const Elf_Phdr &Phdr, Error &Err) const
Get an iterator over notes in a program header.
Definition ELF.h:450
Expected< ArrayRef< uint8_t > > getSectionContents(const Elf_Shdr &Sec) const
Definition ELF.h:722
Expected< Elf_Rela_Range > relas(const Elf_Shdr &Sec) const
Definition ELF.h:398
Expected< Elf_Phdr_Range > program_headers() const
Iterate over program header table.
Definition ELF.h:420
Expected< uint32_t > getShStrNdx() const
Definition ELF.h:315
Expected< StringRef > getStringTableForSymtab(const Elf_Shdr &Section) const
Definition ELF.h:1359
Expected< std::vector< VerNeed > > getVersionDependencies(const Elf_Shdr &Sec, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.h:1198
size_t getBufSize() const
Definition ELF.h:276
Expected< const T * > getEntry(uint32_t Section, uint32_t Entry) const
Definition ELF.h:1055
void getRelocationTypeName(uint32_t Type, SmallVectorImpl< char > &Result) const
Definition ELF.h:732
Expected< const Elf_Sym * > getRelocationSymbol(const Elf_Rel &Rel, const Elf_Shdr *SymTab) const
Get the symbol for a given relocation.
Definition ELF.h:806
Expected< RelsOrRelas > decodeCrel(ArrayRef< uint8_t > Content) const
Definition ELF.cpp:415
const uint8_t * end() const
Definition ELF.h:274
Expected< StringRef > getSectionStringTable(Elf_Shdr_Range Sections, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.h:816
Expected< uint64_t > getDynSymtabSize() const
This function determines the number of dynamic symbols.
Definition ELF.h:871
Expected< const T * > getEntry(const Elf_Shdr &Section, uint32_t Entry) const
Definition ELF.h:1065
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:974
ELFFile(const ELFFile &)=default
Expected< Elf_Shdr_Range > sections() const
Definition ELF.h:1000
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:524
const uint8_t * base() const
Definition ELF.h:273
bool isMipsELF64() const
Definition ELF.h:377
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:406
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:373
bool isMips64EL() const
Definition ELF.h:382
Elf_Note_Iterator notes_end() const
Get the end iterator for notes.
Definition ELF.h:501
Expected< StringRef > getSectionName(const Elf_Shdr &Section, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.h:1400
StringRef getRelocationTypeName(uint32_t Type) const
Definition ELF.h:727
Expected< StringRef > getStringTable(const Elf_Shdr &Section, WarningHandler WarnHandler=&defaultWarningHandler) const
Definition ELF.h:1295
llvm::function_ref< Error(const Twine &Msg)> WarningHandler
Definition ELF.h:271
Expected< uint32_t > getPhNum() const
Definition ELF.h:299
Expected< StringRef > getStringTableForSymtab(const Elf_Shdr &Section, Elf_Shdr_Range Sections) const
Definition ELF.h:1368
Expected< ArrayRef< T > > getSectionContentsAsArray(const Elf_Shdr &Sec) const
Definition ELF.h:666
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:769
Expected< Elf_Rel_Range > rels(const Elf_Shdr &Sec) const
Definition ELF.h:402
Expected< const Elf_Shdr * > getSection(const Elf_Sym &Sym, const Elf_Shdr *SymTab, DataRegion< Elf_Word > ShndxTable) const
Definition ELF.h:627
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:413
Expected< uint32_t > getSectionIndex(const Elf_Sym &Sym, Elf_Sym_Range Syms, DataRegion< Elf_Word > ShndxTable) const
Definition ELF.h:610
#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:592
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
Definition ELF.h:584
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:843
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:1441
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:577
ELFFile< ELF64BE > ELF64BEFile
Definition ELF.h:580
ELFFile< ELF32BE > ELF32BEFile
Definition ELF.h:579
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:1429
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:578
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