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