LLVM 23.0.0git
ELFTypes.h
Go to the documentation of this file.
1//===- ELFTypes.h - Endian specific types for ELF ---------------*- 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#ifndef LLVM_OBJECT_ELFTYPES_H
10#define LLVM_OBJECT_ELFTYPES_H
11
12#include "llvm/ADT/ArrayRef.h"
14#include "llvm/ADT/StringRef.h"
16#include "llvm/Object/Error.h"
19#include "llvm/Support/Endian.h"
20#include "llvm/Support/Error.h"
23#include <cassert>
24#include <cstdint>
25#include <cstring>
26#include <type_traits>
27
28namespace llvm {
29
30namespace callgraph {
31// ELF call graph section entry Flag field supported values.
40} // namespace callgraph
41
42namespace object {
43
44template <class ELFT> struct Elf_Ehdr_Impl;
45template <class ELFT> struct Elf_Shdr_Impl;
46template <class ELFT> struct Elf_Sym_Impl;
47template <class ELFT> struct Elf_Dyn_Impl;
48template <class ELFT> struct Elf_Phdr_Impl;
49template <class ELFT, bool isRela> struct Elf_Rel_Impl;
50template <bool Is64> struct Elf_Crel_Impl;
51template <class ELFT> struct Elf_Verdef_Impl;
52template <class ELFT> struct Elf_Verdaux_Impl;
53template <class ELFT> struct Elf_Verneed_Impl;
54template <class ELFT> struct Elf_Vernaux_Impl;
55template <class ELFT> struct Elf_Versym_Impl;
56template <class ELFT> struct Elf_Hash_Impl;
57template <class ELFT> struct Elf_GnuHash_Impl;
58template <class ELFT> struct Elf_Chdr_Impl;
59template <class ELFT> struct Elf_Nhdr_Impl;
60template <class ELFT> class Elf_Note_Impl;
61template <class ELFT> class Elf_Note_Iterator_Impl;
62template <class ELFT> struct Elf_CGProfile_Impl;
63
64template <endianness E, bool Is64> struct ELFType {
65private:
66 template <typename Ty>
68
69public:
70 static const endianness Endianness = E;
71 static const bool Is64Bits = Is64;
72
73 using uint = std::conditional_t<Is64, uint64_t, uint32_t>;
82 using Relr = packed<uint>;
102
103 using Half = packed<uint16_t>;
104 using Word = packed<uint32_t>;
105 using Sword = packed<int32_t>;
106 using Xword = packed<uint64_t>;
107 using Sxword = packed<int64_t>;
108 using Addr = packed<uint>;
109 using Off = packed<uint>;
110};
111
116
117// Use an alignment of 2 for the typedefs since that is the worst case for
118// ELF files in archives.
119
120// I really don't like doing this, but the alternative is copypasta.
121#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \
122 using Elf_Addr = typename ELFT::Addr; \
123 using Elf_Off = typename ELFT::Off; \
124 using Elf_Half = typename ELFT::Half; \
125 using Elf_Word = typename ELFT::Word; \
126 using Elf_Sword = typename ELFT::Sword; \
127 using Elf_Xword = typename ELFT::Xword; \
128 using Elf_Sxword = typename ELFT::Sxword; \
129 using uintX_t = typename ELFT::uint; \
130 using Elf_Ehdr = typename ELFT::Ehdr; \
131 using Elf_Shdr = typename ELFT::Shdr; \
132 using Elf_Sym = typename ELFT::Sym; \
133 using Elf_Dyn = typename ELFT::Dyn; \
134 using Elf_Phdr = typename ELFT::Phdr; \
135 using Elf_Rel = typename ELFT::Rel; \
136 using Elf_Rela = typename ELFT::Rela; \
137 using Elf_Crel = typename ELFT::Crel; \
138 using Elf_Relr = typename ELFT::Relr; \
139 using Elf_Verdef = typename ELFT::Verdef; \
140 using Elf_Verdaux = typename ELFT::Verdaux; \
141 using Elf_Verneed = typename ELFT::Verneed; \
142 using Elf_Vernaux = typename ELFT::Vernaux; \
143 using Elf_Versym = typename ELFT::Versym; \
144 using Elf_Hash = typename ELFT::Hash; \
145 using Elf_GnuHash = typename ELFT::GnuHash; \
146 using Elf_Chdr = typename ELFT::Chdr; \
147 using Elf_Nhdr = typename ELFT::Nhdr; \
148 using Elf_Note = typename ELFT::Note; \
149 using Elf_Note_Iterator = typename ELFT::NoteIterator; \
150 using Elf_CGProfile = typename ELFT::CGProfile; \
151 using Elf_Dyn_Range = typename ELFT::DynRange; \
152 using Elf_Shdr_Range = typename ELFT::ShdrRange; \
153 using Elf_Sym_Range = typename ELFT::SymRange; \
154 using Elf_Rel_Range = typename ELFT::RelRange; \
155 using Elf_Rela_Range = typename ELFT::RelaRange; \
156 using Elf_Relr_Range = typename ELFT::RelrRange; \
157 using Elf_Phdr_Range = typename ELFT::PhdrRange;
158
159#define LLVM_ELF_COMMA ,
160#define LLVM_ELF_IMPORT_TYPES(E, W) \
161 LLVM_ELF_IMPORT_TYPES_ELFT(ELFType<E LLVM_ELF_COMMA W>)
162
163// Section header.
164template <class ELFT> struct Elf_Shdr_Base;
165
166template <endianness Endianness>
167struct Elf_Shdr_Base<ELFType<Endianness, false>> {
168 LLVM_ELF_IMPORT_TYPES(Endianness, false)
169 Elf_Word sh_name; // Section name (index into string table)
170 Elf_Word sh_type; // Section type (SHT_*)
171 Elf_Word sh_flags; // Section flags (SHF_*)
172 Elf_Addr sh_addr; // Address where section is to be loaded
173 Elf_Off sh_offset; // File offset of section data, in bytes
174 Elf_Word sh_size; // Size of section, in bytes
175 Elf_Word sh_link; // Section type-specific header table index link
176 Elf_Word sh_info; // Section type-specific extra information
177 Elf_Word sh_addralign; // Section address alignment
178 Elf_Word sh_entsize; // Size of records contained within the section
179};
180
181template <endianness Endianness>
182struct Elf_Shdr_Base<ELFType<Endianness, true>> {
183 LLVM_ELF_IMPORT_TYPES(Endianness, true)
184 Elf_Word sh_name; // Section name (index into string table)
185 Elf_Word sh_type; // Section type (SHT_*)
186 Elf_Xword sh_flags; // Section flags (SHF_*)
187 Elf_Addr sh_addr; // Address where section is to be loaded
188 Elf_Off sh_offset; // File offset of section data, in bytes
189 Elf_Xword sh_size; // Size of section, in bytes
190 Elf_Word sh_link; // Section type-specific header table index link
191 Elf_Word sh_info; // Section type-specific extra information
192 Elf_Xword sh_addralign; // Section address alignment
193 Elf_Xword sh_entsize; // Size of records contained within the section
194};
195
196template <class ELFT>
198 using Elf_Shdr_Base<ELFT>::sh_entsize;
199 using Elf_Shdr_Base<ELFT>::sh_size;
200
201 /// Get the number of entities this section contains if it has any.
202 unsigned getEntityCount() const {
203 if (sh_entsize == 0)
204 return 0;
205 return sh_size / sh_entsize;
206 }
207};
208
209template <class ELFT> struct Elf_Sym_Base;
210
211template <endianness Endianness>
212struct Elf_Sym_Base<ELFType<Endianness, false>> {
213 LLVM_ELF_IMPORT_TYPES(Endianness, false)
214 Elf_Word st_name; // Symbol name (index into string table)
215 Elf_Addr st_value; // Value or address associated with the symbol
216 Elf_Word st_size; // Size of the symbol
217 unsigned char st_info; // Symbol's type and binding attributes
218 unsigned char st_other; // Must be zero; reserved
219 Elf_Half st_shndx; // Which section (header table index) it's defined in
220};
221
222template <endianness Endianness>
223struct Elf_Sym_Base<ELFType<Endianness, true>> {
224 LLVM_ELF_IMPORT_TYPES(Endianness, true)
225 Elf_Word st_name; // Symbol name (index into string table)
226 unsigned char st_info; // Symbol's type and binding attributes
227 unsigned char st_other; // Must be zero; reserved
228 Elf_Half st_shndx; // Which section (header table index) it's defined in
229 Elf_Addr st_value; // Value or address associated with the symbol
230 Elf_Xword st_size; // Size of the symbol
231};
232
233template <class ELFT>
235 using Elf_Sym_Base<ELFT>::st_info;
236 using Elf_Sym_Base<ELFT>::st_shndx;
237 using Elf_Sym_Base<ELFT>::st_other;
238 using Elf_Sym_Base<ELFT>::st_value;
239
240 // These accessors and mutators correspond to the ELF32_ST_BIND,
241 // ELF32_ST_TYPE, and ELF32_ST_INFO macros defined in the ELF specification:
242 unsigned char getBinding() const { return st_info >> 4; }
243 unsigned char getType() const { return st_info & 0x0f; }
244 uint64_t getValue() const { return st_value; }
245 void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
246 void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
247
248 void setBindingAndType(unsigned char b, unsigned char t) {
249 st_info = (b << 4) + (t & 0x0f);
250 }
251
252 /// Access to the STV_xxx flag stored in the first two bits of st_other.
253 /// STV_DEFAULT: 0
254 /// STV_INTERNAL: 1
255 /// STV_HIDDEN: 2
256 /// STV_PROTECTED: 3
257 unsigned char getVisibility() const { return st_other & 0x3; }
258 void setVisibility(unsigned char v) {
259 assert(v < 4 && "Invalid value for visibility");
260 st_other = (st_other & ~0x3) | v;
261 }
262
263 bool isAbsolute() const { return st_shndx == ELF::SHN_ABS; }
264
265 bool isCommon() const {
266 return getType() == ELF::STT_COMMON || st_shndx == ELF::SHN_COMMON;
267 }
268
269 bool isDefined() const { return !isUndefined(); }
270
271 bool isProcessorSpecific() const {
272 return st_shndx >= ELF::SHN_LOPROC && st_shndx <= ELF::SHN_HIPROC;
273 }
274
275 bool isOSSpecific() const {
276 return st_shndx >= ELF::SHN_LOOS && st_shndx <= ELF::SHN_HIOS;
277 }
278
279 bool isReserved() const {
280 // ELF::SHN_HIRESERVE is 0xffff so st_shndx <= ELF::SHN_HIRESERVE is always
281 // true and some compilers warn about it.
282 return st_shndx >= ELF::SHN_LORESERVE;
283 }
284
285 bool isUndefined() const { return st_shndx == ELF::SHN_UNDEF; }
286
287 bool isExternal() const {
288 return getBinding() != ELF::STB_LOCAL;
289 }
290
292};
293
294template <class ELFT>
296 uint32_t Offset = this->st_name;
297 if (Offset >= StrTab.size())
299 "st_name (0x%" PRIx32
300 ") is past the end of the string table"
301 " of size 0x%zx",
302 Offset, StrTab.size());
303 return StringRef(StrTab.data() + Offset);
304}
305
306/// Elf_Versym: This is the structure of entries in the SHT_GNU_versym section
307/// (.gnu.version). This structure is identical for ELF32 and ELF64.
308template <class ELFT>
311 Elf_Half vs_index; // Version index with flags (e.g. VERSYM_HIDDEN)
312};
313
314/// Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section
315/// (.gnu.version_d). This structure is identical for ELF32 and ELF64.
316template <class ELFT>
319 Elf_Half vd_version; // Version of this structure (e.g. VER_DEF_CURRENT)
320 Elf_Half vd_flags; // Bitwise flags (VER_DEF_*)
321 Elf_Half vd_ndx; // Version index, used in .gnu.version entries
322 Elf_Half vd_cnt; // Number of Verdaux entries
323 Elf_Word vd_hash; // Hash of name
324 Elf_Word vd_aux; // Offset to the first Verdaux entry (in bytes)
325 Elf_Word vd_next; // Offset to the next Verdef entry (in bytes)
326
327 /// Get the first Verdaux entry for this Verdef.
328 const Elf_Verdaux *getAux() const {
329 return reinterpret_cast<const Elf_Verdaux *>((const char *)this + vd_aux);
330 }
331};
332
333/// Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef
334/// section (.gnu.version_d). This structure is identical for ELF32 and ELF64.
335template <class ELFT>
338 Elf_Word vda_name; // Version name (offset in string table)
339 Elf_Word vda_next; // Offset to next Verdaux entry (in bytes)
340};
341
342/// Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed
343/// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
344template <class ELFT>
347 Elf_Half vn_version; // Version of this structure (e.g. VER_NEED_CURRENT)
348 Elf_Half vn_cnt; // Number of associated Vernaux entries
349 Elf_Word vn_file; // Library name (string table offset)
350 Elf_Word vn_aux; // Offset to first Vernaux entry (in bytes)
351 Elf_Word vn_next; // Offset to next Verneed entry (in bytes)
352};
353
354/// Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed
355/// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
356template <class ELFT>
359 Elf_Word vna_hash; // Hash of dependency name
360 Elf_Half vna_flags; // Bitwise Flags (VER_FLAG_*)
361 Elf_Half vna_other; // Version index, used in .gnu.version entries
362 Elf_Word vna_name; // Dependency name
363 Elf_Word vna_next; // Offset to next Vernaux entry (in bytes)
364};
365
366/// Elf_Dyn_Base: This structure matches the form of entries in the dynamic
367/// table section (.dynamic) look like.
368template <class ELFT> struct Elf_Dyn_Base;
369
370template <endianness Endianness>
371struct Elf_Dyn_Base<ELFType<Endianness, false>> {
372 LLVM_ELF_IMPORT_TYPES(Endianness, false)
373 Elf_Sword d_tag;
374 union {
375 Elf_Word d_val;
376 Elf_Addr d_ptr;
377 } d_un;
378};
379
380template <endianness Endianness>
381struct Elf_Dyn_Base<ELFType<Endianness, true>> {
382 LLVM_ELF_IMPORT_TYPES(Endianness, true)
383 Elf_Sxword d_tag;
384 union {
385 Elf_Xword d_val;
386 Elf_Addr d_ptr;
387 } d_un;
388};
389
390/// Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters.
391template <class ELFT>
393 using Elf_Dyn_Base<ELFT>::d_tag;
394 using Elf_Dyn_Base<ELFT>::d_un;
395 using intX_t = std::conditional_t<ELFT::Is64Bits, int64_t, int32_t>;
396 using uintX_t = std::conditional_t<ELFT::Is64Bits, uint64_t, uint32_t>;
397 intX_t getTag() const { return d_tag; }
398 uintX_t getVal() const { return d_un.d_val; }
399 uintX_t getPtr() const { return d_un.d_ptr; }
400};
401
402template <endianness Endianness>
403struct Elf_Rel_Impl<ELFType<Endianness, false>, false> {
404 LLVM_ELF_IMPORT_TYPES(Endianness, false)
405 static const bool HasAddend = false;
406 static const bool IsCrel = false;
407 Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
408 Elf_Word r_info; // Symbol table index and type of relocation to apply
409
412 return r_info;
413 }
414 void setRInfo(uint32_t R, bool IsMips64EL) {
415 assert(!IsMips64EL);
416 r_info = R;
417 }
418
419 // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
420 // and ELF32_R_INFO macros defined in the ELF specification:
422 return this->getRInfo(isMips64EL) >> 8;
423 }
424 unsigned char getType(bool isMips64EL) const {
425 return (unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
426 }
427 void setSymbol(uint32_t s, bool IsMips64EL) {
428 setSymbolAndType(s, getType(IsMips64EL), IsMips64EL);
429 }
430 void setType(unsigned char t, bool IsMips64EL) {
431 setSymbolAndType(getSymbol(IsMips64EL), t, IsMips64EL);
432 }
433 void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL) {
434 this->setRInfo((s << 8) + t, IsMips64EL);
435 }
436};
437
438template <endianness Endianness>
439struct Elf_Rel_Impl<ELFType<Endianness, false>, true>
440 : public Elf_Rel_Impl<ELFType<Endianness, false>, false> {
441 LLVM_ELF_IMPORT_TYPES(Endianness, false)
442 static const bool HasAddend = true;
443 static const bool IsCrel = false;
444 Elf_Sword r_addend; // Compute value for relocatable field by adding this
445};
446
447template <endianness Endianness>
448struct Elf_Rel_Impl<ELFType<Endianness, true>, false> {
449 LLVM_ELF_IMPORT_TYPES(Endianness, true)
450 static const bool HasAddend = false;
451 static const bool IsCrel = false;
452 Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
453 Elf_Xword r_info; // Symbol table index and type of relocation to apply
454
456 uint64_t t = r_info;
457 if (!isMips64EL)
458 return t;
459 // Mips64 little endian has a "special" encoding of r_info. Instead of one
460 // 64 bit little endian number, it is a little endian 32 bit number followed
461 // by a 32 bit big endian number.
462 return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
463 ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
464 }
465
466 void setRInfo(uint64_t R, bool IsMips64EL) {
467 if (IsMips64EL)
468 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
469 ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
470 else
471 r_info = R;
472 }
473
474 // These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
475 // and ELF64_R_INFO macros defined in the ELF specification:
477 return (uint32_t)(this->getRInfo(isMips64EL) >> 32);
478 }
480 return (uint32_t)(this->getRInfo(isMips64EL) & 0xffffffffL);
481 }
482 void setSymbol(uint32_t s, bool IsMips64EL) {
483 setSymbolAndType(s, getType(IsMips64EL), IsMips64EL);
484 }
485 void setType(uint32_t t, bool IsMips64EL) {
486 setSymbolAndType(getSymbol(IsMips64EL), t, IsMips64EL);
487 }
488 void setSymbolAndType(uint32_t s, uint32_t t, bool IsMips64EL) {
489 this->setRInfo(((uint64_t)s << 32) + (t & 0xffffffffL), IsMips64EL);
490 }
491};
492
493template <endianness Endianness>
494struct Elf_Rel_Impl<ELFType<Endianness, true>, true>
495 : public Elf_Rel_Impl<ELFType<Endianness, true>, false> {
496 LLVM_ELF_IMPORT_TYPES(Endianness, true)
497 static const bool HasAddend = true;
498 static const bool IsCrel = false;
499 Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
500};
501
502// In-memory representation. The serialized representation uses LEB128.
503template <bool Is64> struct Elf_Crel_Impl {
504 using uint = std::conditional_t<Is64, uint64_t, uint32_t>;
505 static const bool HasAddend = true;
506 static const bool IsCrel = true;
510 std::conditional_t<Is64, int64_t, int32_t> r_addend;
511
512 // Dummy bool parameter is for compatibility with Elf_Rel_Impl.
513 uint32_t getType(bool) const { return r_type; }
514 uint32_t getSymbol(bool) const { return r_symidx; }
515 void setSymbolAndType(uint32_t s, unsigned char t, bool) {
516 r_symidx = s;
517 r_type = t;
518 }
519};
520
521template <class ELFT>
524 unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
525 Elf_Half e_type; // Type of file (see ET_*)
526 Elf_Half e_machine; // Required architecture for this file (see EM_*)
527 Elf_Word e_version; // Must be equal to 1
528 Elf_Addr e_entry; // Address to jump to in order to start program
529 Elf_Off e_phoff; // Program header table's file offset, in bytes
530 Elf_Off e_shoff; // Section header table's file offset, in bytes
531 Elf_Word e_flags; // Processor-specific flags
532 Elf_Half e_ehsize; // Size of ELF header, in bytes
533 Elf_Half e_phentsize; // Size of an entry in the program header table
534 Elf_Half e_phnum; // Number of entries in the program header table
535 Elf_Half e_shentsize; // Size of an entry in the section header table
536 Elf_Half e_shnum; // Number of entries in the section header table
537 Elf_Half e_shstrndx; // Section header table index of section name
538 // string table
539
540 bool checkMagic() const {
541 return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
542 }
543
544 unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; }
545 unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
546};
547
548template <endianness Endianness>
549struct Elf_Phdr_Impl<ELFType<Endianness, false>> {
550 LLVM_ELF_IMPORT_TYPES(Endianness, false)
551 Elf_Word p_type; // Type of segment
552 Elf_Off p_offset; // FileOffset where segment is located, in bytes
553 Elf_Addr p_vaddr; // Virtual Address of beginning of segment
554 Elf_Addr p_paddr; // Physical address of beginning of segment (OS-specific)
555 Elf_Word p_filesz; // Num. of bytes in file image of segment (may be zero)
556 Elf_Word p_memsz; // Num. of bytes in mem image of segment (may be zero)
557 Elf_Word p_flags; // Segment flags
558 Elf_Word p_align; // Segment alignment constraint
559};
560
561template <endianness Endianness>
562struct Elf_Phdr_Impl<ELFType<Endianness, true>> {
563 LLVM_ELF_IMPORT_TYPES(Endianness, true)
564 Elf_Word p_type; // Type of segment
565 Elf_Word p_flags; // Segment flags
566 Elf_Off p_offset; // FileOffset where segment is located, in bytes
567 Elf_Addr p_vaddr; // Virtual Address of beginning of segment
568 Elf_Addr p_paddr; // Physical address of beginning of segment (OS-specific)
569 Elf_Xword p_filesz; // Num. of bytes in file image of segment (may be zero)
570 Elf_Xword p_memsz; // Num. of bytes in mem image of segment (may be zero)
571 Elf_Xword p_align; // Segment alignment constraint
572};
573
574// ELFT needed for endianness.
575template <class ELFT>
578 Elf_Word nbucket;
579 Elf_Word nchain;
580
581 ArrayRef<Elf_Word> buckets() const {
582 return ArrayRef<Elf_Word>(&nbucket + 2, &nbucket + 2 + nbucket);
583 }
584
586 return ArrayRef<Elf_Word>(&nbucket + 2 + nbucket,
587 &nbucket + 2 + nbucket + nchain);
588 }
589};
590
591// .gnu.hash section
592template <class ELFT>
595 Elf_Word nbuckets;
596 Elf_Word symndx;
597 Elf_Word maskwords;
598 Elf_Word shift2;
599
600 ArrayRef<Elf_Off> filter() const {
601 return ArrayRef<Elf_Off>(reinterpret_cast<const Elf_Off *>(&shift2 + 1),
602 maskwords);
603 }
604
606 return ArrayRef<Elf_Word>(
607 reinterpret_cast<const Elf_Word *>(filter().end()), nbuckets);
608 }
609
610 ArrayRef<Elf_Word> values(unsigned DynamicSymCount) const {
611 assert(DynamicSymCount >= symndx);
612 return ArrayRef<Elf_Word>(buckets().end(), DynamicSymCount - symndx);
613 }
614};
615
616// Compressed section headers.
617// http://www.sco.com/developers/gabi/latest/ch4.sheader.html#compression_header
618template <endianness Endianness>
619struct Elf_Chdr_Impl<ELFType<Endianness, false>> {
620 LLVM_ELF_IMPORT_TYPES(Endianness, false)
621 Elf_Word ch_type;
622 Elf_Word ch_size;
623 Elf_Word ch_addralign;
624};
625
626template <endianness Endianness>
627struct Elf_Chdr_Impl<ELFType<Endianness, true>> {
628 LLVM_ELF_IMPORT_TYPES(Endianness, true)
629 Elf_Word ch_type;
630 Elf_Word ch_reserved;
631 Elf_Xword ch_size;
632 Elf_Xword ch_addralign;
633};
634
635/// Note header
636template <class ELFT>
639 Elf_Word n_namesz;
640 Elf_Word n_descsz;
641 Elf_Word n_type;
642
643 /// Get the size of the note, including name, descriptor, and padding. Both
644 /// the start and the end of the descriptor are aligned by the section
645 /// alignment. In practice many 64-bit systems deviate from the generic ABI by
646 /// using sh_addralign=4.
647 size_t getSize(size_t Align) const {
648 return alignToPowerOf2(sizeof(*this) + n_namesz, Align) +
650 }
651};
652
653/// An ELF note.
654///
655/// Wraps a note header, providing methods for accessing the name and
656/// descriptor safely.
657template <class ELFT>
660
661 const Elf_Nhdr_Impl<ELFT> &Nhdr;
662
663 template <class NoteIteratorELFT> friend class Elf_Note_Iterator_Impl;
664
665public:
666 Elf_Note_Impl(const Elf_Nhdr_Impl<ELFT> &Nhdr) : Nhdr(Nhdr) {}
667
668 /// Get the note's name, excluding the terminating null byte.
670 if (!Nhdr.n_namesz)
671 return StringRef();
672 return StringRef(reinterpret_cast<const char *>(&Nhdr) + sizeof(Nhdr),
673 Nhdr.n_namesz - 1);
674 }
675
676 /// Get the note's descriptor.
678 if (!Nhdr.n_descsz)
679 return ArrayRef<uint8_t>();
680 return ArrayRef<uint8_t>(
681 reinterpret_cast<const uint8_t *>(&Nhdr) +
682 alignToPowerOf2(sizeof(Nhdr) + Nhdr.n_namesz, Align),
683 Nhdr.n_descsz);
684 }
685
686 /// Get the note's descriptor as StringRef
689 return StringRef(reinterpret_cast<const char *>(Desc.data()), Desc.size());
690 }
691
692 /// Get the note's type.
693 Elf_Word getType() const { return Nhdr.n_type; }
694};
695
696template <class ELFT> class Elf_Note_Iterator_Impl {
697public:
698 using iterator_category = std::forward_iterator_tag;
700 using difference_type = std::ptrdiff_t;
703
704private:
705 // Nhdr being a nullptr marks the end of iteration.
706 const Elf_Nhdr_Impl<ELFT> *Nhdr = nullptr;
707 size_t RemainingSize = 0u;
708 size_t Align = 0;
709 Error *Err = nullptr;
710
711 template <class ELFFileELFT> friend class ELFFile;
712
713 // Stop iteration and indicate an overflow.
714 void stopWithOverflowError() {
715 Nhdr = nullptr;
716 *Err = make_error<StringError>("ELF note overflows container",
718 }
719
720 // Advance Nhdr by NoteSize bytes, starting from NhdrPos.
721 //
722 // Assumes NoteSize <= RemainingSize. Ensures Nhdr->getSize() <= RemainingSize
723 // upon returning. Handles stopping iteration when reaching the end of the
724 // container, either cleanly or with an overflow error.
725 void advanceNhdr(const uint8_t *NhdrPos, size_t NoteSize) {
726 RemainingSize -= NoteSize;
727 if (RemainingSize == 0u) {
728 // Ensure that if the iterator walks to the end, the error is checked
729 // afterwards.
730 *Err = Error::success();
731 Nhdr = nullptr;
732 } else if (sizeof(*Nhdr) > RemainingSize)
733 stopWithOverflowError();
734 else {
735 Nhdr = reinterpret_cast<const Elf_Nhdr_Impl<ELFT> *>(NhdrPos + NoteSize);
736 if (Nhdr->getSize(Align) > RemainingSize)
737 stopWithOverflowError();
738 else
739 *Err = Error::success();
740 }
741 }
742
743 Elf_Note_Iterator_Impl() = default;
744 explicit Elf_Note_Iterator_Impl(Error &Err) : Err(&Err) {}
745 Elf_Note_Iterator_Impl(const uint8_t *Start, size_t Size, size_t Align,
746 Error &Err)
747 : RemainingSize(Size), Align(Align), Err(&Err) {
748 consumeError(std::move(Err));
749 assert(Start && "ELF note iterator starting at NULL");
750 advanceNhdr(Start, 0u);
751 }
752
753public:
754 Elf_Note_Iterator_Impl &operator++() {
755 assert(Nhdr && "incremented ELF note end iterator");
756 const uint8_t *NhdrPos = reinterpret_cast<const uint8_t *>(Nhdr);
757 size_t NoteSize = Nhdr->getSize(Align);
758 advanceNhdr(NhdrPos, NoteSize);
759 return *this;
760 }
761 bool operator==(Elf_Note_Iterator_Impl Other) const {
762 if (!Nhdr && Other.Err)
763 (void)(bool)(*Other.Err);
764 if (!Other.Nhdr && Err)
765 (void)(bool)(*Err);
766 return Nhdr == Other.Nhdr;
767 }
768 bool operator!=(Elf_Note_Iterator_Impl Other) const {
769 return !(*this == Other);
770 }
772 assert(Nhdr && "dereferenced ELF note end iterator");
773 return Elf_Note_Impl<ELFT>(*Nhdr);
774 }
775};
776
777template <class ELFT> struct Elf_CGProfile_Impl {
779 Elf_Xword cgp_weight;
780};
781
782// MIPS .reginfo section
783template <class ELFT>
785
786template <llvm::endianness Endianness>
787struct Elf_Mips_RegInfo<ELFType<Endianness, false>> {
788 LLVM_ELF_IMPORT_TYPES(Endianness, false)
789 Elf_Word ri_gprmask; // bit-mask of used general registers
790 Elf_Word ri_cprmask[4]; // bit-mask of used co-processor registers
791 Elf_Addr ri_gp_value; // gp register value
792};
793
794template <llvm::endianness Endianness>
795struct Elf_Mips_RegInfo<ELFType<Endianness, true>> {
796 LLVM_ELF_IMPORT_TYPES(Endianness, true)
797 Elf_Word ri_gprmask; // bit-mask of used general registers
798 Elf_Word ri_pad; // unused padding field
799 Elf_Word ri_cprmask[4]; // bit-mask of used co-processor registers
800 Elf_Addr ri_gp_value; // gp register value
801};
802
803// .MIPS.options section
804template <class ELFT> struct Elf_Mips_Options {
806 uint8_t kind; // Determines interpretation of variable part of descriptor
807 uint8_t size; // Byte size of descriptor, including this header
808 Elf_Half section; // Section header index of section affected,
809 // or 0 for global options
810 Elf_Word info; // Kind-specific information
811
814 return *reinterpret_cast<Elf_Mips_RegInfo<ELFT> *>(
815 (uint8_t *)this + sizeof(Elf_Mips_Options));
816 }
818 return const_cast<Elf_Mips_Options *>(this)->getRegInfo();
819 }
820};
821
822// .MIPS.abiflags section content
823template <class ELFT> struct Elf_Mips_ABIFlags {
825 Elf_Half version; // Version of the structure
826 uint8_t isa_level; // ISA level: 1-5, 32, and 64
827 uint8_t isa_rev; // ISA revision (0 for MIPS I - MIPS V)
828 uint8_t gpr_size; // General purpose registers size
829 uint8_t cpr1_size; // Co-processor 1 registers size
830 uint8_t cpr2_size; // Co-processor 2 registers size
831 uint8_t fp_abi; // Floating-point ABI flag
832 Elf_Word isa_ext; // Processor-specific extension
833 Elf_Word ases; // ASEs flags
834 Elf_Word flags1; // General flags
835 Elf_Word flags2; // General flags
836};
837
838// Struct representing the BBAddrMap for one function.
839struct BBAddrMap {
840
841 // Bitfield of optional features to control the extra information
842 // emitted/encoded in the the section.
843 struct Features {
845 bool BBFreq : 1;
846 bool BrProb : 1;
847 bool MultiBBRange : 1;
850 bool BBHash : 1;
851 bool PostLinkCfg : 1;
852
853 bool hasPGOAnalysis() const { return FuncEntryCount || BBFreq || BrProb; }
854
855 bool hasPGOAnalysisBBData() const { return BBFreq || BrProb; }
856
857 // Encodes to minimum bit width representation.
858 uint16_t encode() const {
859 return (static_cast<uint16_t>(FuncEntryCount) << 0) |
860 (static_cast<uint16_t>(BBFreq) << 1) |
861 (static_cast<uint16_t>(BrProb) << 2) |
862 (static_cast<uint16_t>(MultiBBRange) << 3) |
863 (static_cast<uint16_t>(OmitBBEntries) << 4) |
864 (static_cast<uint16_t>(CallsiteEndOffsets) << 5) |
865 (static_cast<uint16_t>(BBHash) << 6) |
866 (static_cast<uint16_t>(PostLinkCfg) << 7);
867 }
868
869 // Decodes from minimum bit width representation and validates no
870 // unnecessary bits are used.
872 Features Feat{
873 static_cast<bool>(Val & (1 << 0)), static_cast<bool>(Val & (1 << 1)),
874 static_cast<bool>(Val & (1 << 2)), static_cast<bool>(Val & (1 << 3)),
875 static_cast<bool>(Val & (1 << 4)), static_cast<bool>(Val & (1 << 5)),
876 static_cast<bool>(Val & (1 << 6)), static_cast<bool>(Val & (1 << 7))};
877 if (Feat.encode() != Val)
878 return createStringError(
879 std::error_code(), "invalid encoding for BBAddrMap::Features: 0x%x",
880 Val);
881 return Feat;
882 }
883
884 bool operator==(const Features &Other) const {
885 return std::tie(FuncEntryCount, BBFreq, BrProb, MultiBBRange,
887 std::tie(Other.FuncEntryCount, Other.BBFreq, Other.BrProb,
888 Other.MultiBBRange, Other.OmitBBEntries,
889 Other.CallsiteEndOffsets, Other.BBHash,
890 Other.PostLinkCfg);
891 }
892 };
893
894 // Struct representing the BBAddrMap information for one basic block.
895 struct BBEntry {
896 struct Metadata {
897 bool HasReturn : 1; // If this block ends with a return (or tail
898 // call).
899 bool HasTailCall : 1; // If this block ends with a tail call.
900 bool IsEHPad : 1; // If this is an exception handling block.
901 bool CanFallThrough : 1; // If this block can fall through to its next.
902 bool HasIndirectBranch : 1; // If this block ends with an indirect branch
903 // (branch via a register).
904
905 bool operator==(const Metadata &Other) const {
906 return HasReturn == Other.HasReturn &&
907 HasTailCall == Other.HasTailCall && IsEHPad == Other.IsEHPad &&
908 CanFallThrough == Other.CanFallThrough &&
909 HasIndirectBranch == Other.HasIndirectBranch;
910 }
911
912 // Encodes this struct as a uint32_t value.
913 uint32_t encode() const {
914 return static_cast<uint32_t>(HasReturn) |
915 (static_cast<uint32_t>(HasTailCall) << 1) |
916 (static_cast<uint32_t>(IsEHPad) << 2) |
917 (static_cast<uint32_t>(CanFallThrough) << 3) |
918 (static_cast<uint32_t>(HasIndirectBranch) << 4);
919 }
920
921 // Decodes and returns a Metadata struct from a uint32_t value.
923 Metadata MD{/*HasReturn=*/static_cast<bool>(V & 1),
924 /*HasTailCall=*/static_cast<bool>(V & (1 << 1)),
925 /*IsEHPad=*/static_cast<bool>(V & (1 << 2)),
926 /*CanFallThrough=*/static_cast<bool>(V & (1 << 3)),
927 /*HasIndirectBranch=*/static_cast<bool>(V & (1 << 4))};
928 if (MD.encode() != V)
929 return createStringError(
930 std::error_code(), "invalid encoding for BBEntry::Metadata: 0x%x",
931 V);
932 return MD;
933 }
934 };
935
936 uint32_t ID = 0; // Unique ID of this basic block.
937 uint32_t Offset = 0; // Offset of basic block relative to the base address.
938 uint32_t Size = 0; // Size of the basic block.
939 Metadata MD = {false, false, false, false,
940 false}; // Metdata for this basic block.
941 // Offsets of end of call instructions, relative to the basic block start.
943 uint64_t Hash = 0; // Hash for this basic block.
944
949
950 UniqueBBID getID() const { return {ID, 0}; }
951
952 bool operator==(const BBEntry &Other) const {
953 return ID == Other.ID && Offset == Other.Offset && Size == Other.Size &&
954 MD == Other.MD && CallsiteEndOffsets == Other.CallsiteEndOffsets &&
955 Hash == Other.Hash;
956 }
957
958 bool hasReturn() const { return MD.HasReturn; }
959 bool hasTailCall() const { return MD.HasTailCall; }
960 bool isEHPad() const { return MD.IsEHPad; }
961 bool canFallThrough() const { return MD.CanFallThrough; }
962 bool hasIndirectBranch() const { return MD.HasIndirectBranch; }
963 };
964
965 // Struct representing the BBAddrMap information for a contiguous range of
966 // basic blocks (a function or a basic block section).
968 uint64_t BaseAddress = 0; // Base address of the range.
969 std::vector<BBEntry> BBEntries; // Basic block entries for this range.
970
971 // Equality operator for unit testing.
972 bool operator==(const BBRangeEntry &Other) const {
973 return BaseAddress == Other.BaseAddress &&
974 std::equal(BBEntries.begin(), BBEntries.end(),
975 Other.BBEntries.begin());
976 }
977 };
978
979 // All ranges for this function. Cannot be empty. The first range always
980 // corresponds to the function entry.
981 std::vector<BBRangeEntry> BBRanges;
982
983 // Returns the function address associated with this BBAddrMap, which is
984 // stored as the `BaseAddress` of its first BBRangeEntry.
986 assert(!BBRanges.empty());
987 return BBRanges.front().BaseAddress;
988 }
989
990 // Returns the total number of bb entries in all bb ranges.
991 size_t getNumBBEntries() const {
992 size_t NumBBEntries = 0;
993 for (const auto &BBR : BBRanges)
994 NumBBEntries += BBR.BBEntries.size();
995 return NumBBEntries;
996 }
997
998 // Returns the index of the bb range with the given base address, or
999 // `std::nullopt` if no such range exists.
1000 std::optional<size_t>
1002 for (size_t I = 0; I < BBRanges.size(); ++I)
1003 if (BBRanges[I].BaseAddress == BaseAddress)
1004 return I;
1005 return {};
1006 }
1007
1008 // Returns bb entries in the first range.
1009 const std::vector<BBEntry> &getBBEntries() const {
1010 return BBRanges.front().BBEntries;
1011 }
1012
1013 const std::vector<BBRangeEntry> &getBBRanges() const { return BBRanges; }
1014
1015 // Equality operator for unit testing.
1016 bool operator==(const BBAddrMap &Other) const {
1017 return std::equal(BBRanges.begin(), BBRanges.end(), Other.BBRanges.begin());
1018 }
1019};
1020
1021/// A feature extension of BBAddrMap that holds information relevant to PGO.
1023 /// Extra basic block data with fields for block frequency and branch
1024 /// probability.
1025 struct PGOBBEntry {
1026 /// Single successor of a given basic block that contains the tag and branch
1027 /// probability associated with it.
1029 /// Unique ID of this successor basic block.
1031 /// Branch Probability of the edge to this successor taken from MBPI.
1033 /// Raw edge count from the post link profile (e.g., from bolt or
1034 /// propeller).
1036
1037 bool operator==(const SuccessorEntry &Other) const {
1038 return std::tie(ID, Prob, PostLinkFreq) ==
1039 std::tie(Other.ID, Other.Prob, Other.PostLinkFreq);
1040 }
1041 };
1042
1043 /// Block frequency taken from MBFI
1045 /// Raw block count taken from the post link profile (e.g., from bolt or
1046 /// propeller).
1048 /// List of successors of the current block
1050
1051 bool operator==(const PGOBBEntry &Other) const {
1052 return std::tie(BlockFreq, PostLinkBlockFreq, Successors) ==
1053 std::tie(Other.BlockFreq, PostLinkBlockFreq, Other.Successors);
1054 }
1055 };
1056
1057 uint64_t FuncEntryCount; // Prof count from IR function
1058 std::vector<PGOBBEntry> BBEntries; // Extended basic block entries
1059
1060 // Flags to indicate if each PGO related info was enabled in this function
1062
1063 bool operator==(const PGOAnalysisMap &Other) const {
1064 return std::tie(FuncEntryCount, BBEntries, FeatEnable) ==
1065 std::tie(Other.FuncEntryCount, Other.BBEntries, Other.FeatEnable);
1066 }
1067};
1068
1069} // end namespace object.
1070} // end namespace llvm.
1071
1072#endif // LLVM_OBJECT_ELFTYPES_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool isMips64EL(const ELFYAML::Object &Obj)
#define LLVM_ELF_IMPORT_TYPES(E, W)
Definition ELFTypes.h:160
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Definition ELFTypes.h:121
#define I(x, y, z)
Definition MD5.cpp:57
Merge contiguous icmps into a memcmp
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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
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
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:137
StringRef getDescAsStringRef(size_t Align) const
Get the note's descriptor as StringRef.
Definition ELFTypes.h:687
Elf_Word getType() const
Get the note's type.
Definition ELFTypes.h:693
Elf_Note_Impl(const Elf_Nhdr_Impl< ELFT > &Nhdr)
Definition ELFTypes.h:666
StringRef getName() const
Get the note's name, excluding the terminating null byte.
Definition ELFTypes.h:669
ArrayRef< uint8_t > getDesc(size_t Align) const
Get the note's descriptor.
Definition ELFTypes.h:677
bool operator!=(Elf_Note_Iterator_Impl Other) const
Definition ELFTypes.h:768
Elf_Note_Impl< ELFType< E, Is64 > > value_type
Definition ELFTypes.h:699
Elf_Note_Impl< ELFT > operator*() const
Definition ELFTypes.h:771
Elf_Note_Iterator_Impl & operator++()
Definition ELFTypes.h:754
bool operator==(Elf_Note_Iterator_Impl Other) const
Definition ELFTypes.h:761
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ SHN_HIOS
Definition ELF.h:1139
@ SHN_ABS
Definition ELF.h:1140
@ SHN_COMMON
Definition ELF.h:1141
@ SHN_LOOS
Definition ELF.h:1138
@ SHN_LOPROC
Definition ELF.h:1136
@ SHN_UNDEF
Definition ELF.h:1134
@ SHN_HIPROC
Definition ELF.h:1137
@ SHN_LORESERVE
Definition ELF.h:1135
@ EI_DATA
Definition ELF.h:56
@ EI_CLASS
Definition ELF.h:55
static const char ElfMagic[]
Definition ELF.h:47
@ STB_LOCAL
Definition ELF.h:1406
@ STT_COMMON
Definition ELF.h:1423
@ ODK_REGINFO
Definition ELF.h:609
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
ELFType< llvm::endianness::big, true > ELF64BE
Definition ELFTypes.h:115
ELFType< llvm::endianness::little, false > ELF32LE
Definition ELFTypes.h:112
ELFType< llvm::endianness::little, true > ELF64LE
Definition ELFTypes.h:114
ELFType< llvm::endianness::big, false > ELF32BE
Definition ELFTypes.h:113
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
Op::Description Desc
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
Definition MathExtras.h:493
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
@ Other
Any other memory.
Definition ModRef.h:68
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
endianness
Definition bit.h:71
void consumeError(Error Err)
Consume a Error without doing anything.
Definition Error.h:1083
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static Expected< Metadata > decode(uint32_t V)
Definition ELFTypes.h:922
bool operator==(const Metadata &Other) const
Definition ELFTypes.h:905
BBEntry(uint32_t ID, uint32_t Offset, uint32_t Size, Metadata MD, SmallVector< uint32_t, 1 > CallsiteEndOffsets, uint64_t Hash)
Definition ELFTypes.h:945
SmallVector< uint32_t, 1 > CallsiteEndOffsets
Definition ELFTypes.h:942
bool operator==(const BBEntry &Other) const
Definition ELFTypes.h:952
bool operator==(const BBRangeEntry &Other) const
Definition ELFTypes.h:972
std::vector< BBEntry > BBEntries
Definition ELFTypes.h:969
bool operator==(const Features &Other) const
Definition ELFTypes.h:884
static Expected< Features > decode(uint16_t Val)
Definition ELFTypes.h:871
const std::vector< BBRangeEntry > & getBBRanges() const
Definition ELFTypes.h:1013
std::vector< BBRangeEntry > BBRanges
Definition ELFTypes.h:981
size_t getNumBBEntries() const
Definition ELFTypes.h:991
bool operator==(const BBAddrMap &Other) const
Definition ELFTypes.h:1016
const std::vector< BBEntry > & getBBEntries() const
Definition ELFTypes.h:1009
uint64_t getFunctionAddress() const
Definition ELFTypes.h:985
std::optional< size_t > getBBRangeIndexForBaseAddress(uint64_t BaseAddress) const
Definition ELFTypes.h:1001
Elf_Verdaux_Impl< ELFType< E, Is64 > > Verdaux
Definition ELFTypes.h:84
std::conditional_t< Is64, uint64_t, uint32_t > uint
Definition ELFTypes.h:73
Elf_Note_Impl< ELFType< E, Is64 > > Note
Definition ELFTypes.h:92
packed< int64_t > Sxword
Definition ELFTypes.h:107
Elf_Ehdr_Impl< ELFType< E, Is64 > > Ehdr
Definition ELFTypes.h:74
ArrayRef< Phdr > PhdrRange
Definition ELFTypes.h:101
packed< uint64_t > Xword
Definition ELFTypes.h:106
Elf_Dyn_Impl< ELFType< E, Is64 > > Dyn
Definition ELFTypes.h:77
Elf_Rel_Impl< ELFType< E, Is64 >, false > Rel
Definition ELFTypes.h:79
Elf_Versym_Impl< ELFType< E, Is64 > > Versym
Definition ELFTypes.h:87
Elf_Vernaux_Impl< ELFType< E, Is64 > > Vernaux
Definition ELFTypes.h:86
packed< uint16_t > Half
Definition ELFTypes.h:103
Elf_GnuHash_Impl< ELFType< E, Is64 > > GnuHash
Definition ELFTypes.h:89
packed< uint > Addr
Definition ELFTypes.h:108
Elf_Rel_Impl< ELFType< E, Is64 >, true > Rela
Definition ELFTypes.h:80
Elf_Note_Iterator_Impl< ELFType< E, Is64 > > NoteIterator
Definition ELFTypes.h:93
packed< int32_t > Sword
Definition ELFTypes.h:105
ArrayRef< Shdr > ShdrRange
Definition ELFTypes.h:96
packed< uint > Relr
Definition ELFTypes.h:82
packed< uint > Off
Definition ELFTypes.h:109
Elf_CGProfile_Impl< ELFType< E, Is64 > > CGProfile
Definition ELFTypes.h:94
Elf_Nhdr_Impl< ELFType< E, Is64 > > Nhdr
Definition ELFTypes.h:91
Elf_Shdr_Impl< ELFType< E, Is64 > > Shdr
Definition ELFTypes.h:75
ArrayRef< Rel > RelRange
Definition ELFTypes.h:98
Elf_Crel_Impl< Is64 > Crel
Definition ELFTypes.h:81
ArrayRef< Sym > SymRange
Definition ELFTypes.h:97
ArrayRef< Dyn > DynRange
Definition ELFTypes.h:95
Elf_Verneed_Impl< ELFType< E, Is64 > > Verneed
Definition ELFTypes.h:85
Elf_Chdr_Impl< ELFType< E, Is64 > > Chdr
Definition ELFTypes.h:90
ArrayRef< Rela > RelaRange
Definition ELFTypes.h:99
Elf_Hash_Impl< ELFType< E, Is64 > > Hash
Definition ELFTypes.h:88
Elf_Sym_Impl< ELFType< E, Is64 > > Sym
Definition ELFTypes.h:76
ArrayRef< Relr > RelrRange
Definition ELFTypes.h:100
Elf_Verdef_Impl< ELFType< E, Is64 > > Verdef
Definition ELFTypes.h:83
Elf_Phdr_Impl< ELFType< E, Is64 > > Phdr
Definition ELFTypes.h:78
packed< uint32_t > Word
Definition ELFTypes.h:104
uint32_t getType(bool) const
Definition ELFTypes.h:513
std::conditional_t< Is64, uint64_t, uint32_t > uint
Definition ELFTypes.h:504
uint32_t getSymbol(bool) const
Definition ELFTypes.h:514
static const bool IsCrel
Definition ELFTypes.h:506
static const bool HasAddend
Definition ELFTypes.h:505
void setSymbolAndType(uint32_t s, unsigned char t, bool)
Definition ELFTypes.h:515
std::conditional_t< Is64, int64_t, int32_t > r_addend
Definition ELFTypes.h:510
Elf_Dyn_Base: This structure matches the form of entries in the dynamic table section (....
Definition ELFTypes.h:368
Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters.
Definition ELFTypes.h:392
uintX_t getVal() const
Definition ELFTypes.h:398
std::conditional_t< ELFType< E, Is64 >::Is64Bits, int64_t, int32_t > intX_t
Definition ELFTypes.h:395
std::conditional_t< ELFType< E, Is64 >::Is64Bits, uint64_t, uint32_t > uintX_t
Definition ELFTypes.h:396
uintX_t getPtr() const
Definition ELFTypes.h:399
intX_t getTag() const
Definition ELFTypes.h:397
unsigned char getFileClass() const
Definition ELFTypes.h:544
unsigned char e_ident[ELF::EI_NIDENT]
Definition ELFTypes.h:524
unsigned char getDataEncoding() const
Definition ELFTypes.h:545
ArrayRef< Elf_Word > values(unsigned DynamicSymCount) const
Definition ELFTypes.h:610
ArrayRef< Elf_Word > buckets() const
Definition ELFTypes.h:605
ArrayRef< Elf_Word > chains() const
Definition ELFTypes.h:585
const Elf_Mips_RegInfo< ELFT > & getRegInfo() const
Definition ELFTypes.h:817
Elf_Mips_RegInfo< ELFT > & getRegInfo()
Definition ELFTypes.h:812
void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL)
Definition ELFTypes.h:433
void setSymbolAndType(uint32_t s, uint32_t t, bool IsMips64EL)
Definition ELFTypes.h:488
unsigned getEntityCount() const
Get the number of entities this section contains if it has any.
Definition ELFTypes.h:202
void setBindingAndType(unsigned char b, unsigned char t)
Definition ELFTypes.h:248
bool isProcessorSpecific() const
Definition ELFTypes.h:271
void setBinding(unsigned char b)
Definition ELFTypes.h:245
unsigned char getBinding() const
Definition ELFTypes.h:242
Expected< StringRef > getName(StringRef StrTab) const
Definition ELFTypes.h:295
bool isOSSpecific() const
Definition ELFTypes.h:275
unsigned char getType() const
Definition ELFTypes.h:243
uint64_t getValue() const
Definition ELFTypes.h:244
void setVisibility(unsigned char v)
Definition ELFTypes.h:258
void setType(unsigned char t)
Definition ELFTypes.h:246
unsigned char getVisibility() const
Access to the STV_xxx flag stored in the first two bits of st_other.
Definition ELFTypes.h:257
Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef section (....
Definition ELFTypes.h:336
Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section (.gnu.version_d).
Definition ELFTypes.h:317
Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed section (....
Definition ELFTypes.h:357
Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed section (.gnu....
Definition ELFTypes.h:345
Elf_Versym: This is the structure of entries in the SHT_GNU_versym section (.gnu.version).
Definition ELFTypes.h:309
Single successor of a given basic block that contains the tag and branch probability associated with ...
Definition ELFTypes.h:1028
uint32_t ID
Unique ID of this successor basic block.
Definition ELFTypes.h:1030
BranchProbability Prob
Branch Probability of the edge to this successor taken from MBPI.
Definition ELFTypes.h:1032
bool operator==(const SuccessorEntry &Other) const
Definition ELFTypes.h:1037
uint64_t PostLinkFreq
Raw edge count from the post link profile (e.g., from bolt or propeller).
Definition ELFTypes.h:1035
Extra basic block data with fields for block frequency and branch probability.
Definition ELFTypes.h:1025
bool operator==(const PGOBBEntry &Other) const
Definition ELFTypes.h:1051
uint64_t PostLinkBlockFreq
Raw block count taken from the post link profile (e.g., from bolt or propeller).
Definition ELFTypes.h:1047
llvm::SmallVector< SuccessorEntry, 2 > Successors
List of successors of the current block.
Definition ELFTypes.h:1049
BlockFrequency BlockFreq
Block frequency taken from MBFI.
Definition ELFTypes.h:1044
A feature extension of BBAddrMap that holds information relevant to PGO.
Definition ELFTypes.h:1022
bool operator==(const PGOAnalysisMap &Other) const
Definition ELFTypes.h:1063
std::vector< PGOBBEntry > BBEntries
Definition ELFTypes.h:1058
BBAddrMap::Features FeatEnable
Definition ELFTypes.h:1061