9#ifndef LLVM_OBJECT_ELFTYPES_H
10#define LLVM_OBJECT_ELFTYPES_H
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;
64template <endianness E,
bool Is64>
struct ELFType {
66 template <
typename Ty>
73 using uint = std::conditional_t<Is64, uint64_t, uint32_t>;
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;
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>)
166template <endianness Endianness>
205 return sh_size / sh_entsize;
211template <endianness Endianness>
243 unsigned char getType()
const {
return st_info & 0x0f; }
249 st_info = (b << 4) + (t & 0x0f);
259 assert(v < 4 &&
"Invalid value for visibility");
260 st_other = (st_other & ~0x3) | v;
299 "st_name (0x%" PRIx32
300 ") is past the end of the string table"
329 return reinterpret_cast<const Elf_Verdaux *
>((
const char *)
this +
vd_aux);
380template <endianness Endianness>
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>;
402template <endianness Endianness>
430 void setType(
unsigned char t,
bool IsMips64EL) {
434 this->
setRInfo((s << 8) + t, IsMips64EL);
438template <endianness Endianness>
440 :
public Elf_Rel_Impl<ELFType<Endianness, false>, false> {
462 return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
463 ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
468 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
469 ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
493template <endianness Endianness>
495 :
public Elf_Rel_Impl<ELFType<Endianness, true>, false> {
504 using uint = std::conditional_t<Is64, uint64_t, uint32_t>;
510 std::conditional_t<Is64, int64_t, int32_t>
r_addend;
548template <endianness Endianness>
618template <endianness Endianness>
672 return StringRef(
reinterpret_cast<const char *
>(&Nhdr) +
sizeof(Nhdr),
681 reinterpret_cast<const uint8_t *
>(&Nhdr) +
693 Elf_Word
getType()
const {
return Nhdr.n_type; }
696template <
class ELFT>
class Elf_Note_Iterator_Impl {
707 size_t RemainingSize = 0u;
709 Error *Err =
nullptr;
711 template <
class ELFFileELFT>
friend class ELFFile;
714 void stopWithOverflowError() {
725 void advanceNhdr(
const uint8_t *NhdrPos,
size_t NoteSize) {
726 RemainingSize -= NoteSize;
727 if (RemainingSize == 0u) {
732 }
else if (
sizeof(*Nhdr) > RemainingSize)
733 stopWithOverflowError();
735 Nhdr =
reinterpret_cast<const Elf_Nhdr_Impl<ELFT> *
>(NhdrPos + NoteSize);
737 stopWithOverflowError();
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,
749 assert(Start &&
"ELF note iterator starting at NULL");
750 advanceNhdr(Start, 0u);
755 assert(Nhdr &&
"incremented ELF note end iterator");
757 size_t NoteSize = Nhdr->getSize(Align);
758 advanceNhdr(NhdrPos, NoteSize);
762 if (!Nhdr &&
Other.Err)
763 (void)(
bool)(*
Other.Err);
764 if (!
Other.Nhdr && Err)
766 return Nhdr ==
Other.Nhdr;
769 return !(*
this ==
Other);
772 assert(Nhdr &&
"dereferenced ELF note end iterator");
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))};
879 std::error_code(),
"invalid encoding for BBAddrMap::Features: 0x%x",
924 static_cast<bool>(V & (1 << 1)),
925 static_cast<bool>(V & (1 << 2)),
926 static_cast<bool>(V & (1 << 3)),
927 static_cast<bool>(V & (1 << 4))};
928 if (
MD.encode() != V)
930 std::error_code(),
"invalid encoding for BBEntry::Metadata: 0x%x",
975 Other.BBEntries.begin());
987 return BBRanges.front().BaseAddress;
992 size_t NumBBEntries = 0;
994 NumBBEntries += BBR.BBEntries.size();
1000 std::optional<size_t>
1003 if (
BBRanges[
I].BaseAddress == BaseAddress)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool isMips64EL(const ELFYAML::Object &Obj)
#define LLVM_ELF_IMPORT_TYPES(E, W)
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
Merge contiguous icmps into a memcmp
static SymbolRef::Type getType(const Symbol *Sym)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
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.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef getDescAsStringRef(size_t Align) const
Get the note's descriptor as StringRef.
friend class Elf_Note_Iterator_Impl
Elf_Word getType() const
Get the note's type.
Elf_Note_Impl(const Elf_Nhdr_Impl< ELFT > &Nhdr)
StringRef getName() const
Get the note's name, excluding the terminating null byte.
ArrayRef< uint8_t > getDesc(size_t Align) const
Get the note's descriptor.
bool operator!=(Elf_Note_Iterator_Impl Other) const
std::forward_iterator_tag iterator_category
Elf_Note_Impl< ELFType< E, Is64 > > value_type
std::ptrdiff_t difference_type
Elf_Note_Impl< ELFT > operator*() const
Elf_Note_Iterator_Impl & operator++()
bool operator==(Elf_Note_Iterator_Impl Other) const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static const char ElfMagic[]
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
ELFType< llvm::endianness::big, true > ELF64BE
ELFType< llvm::endianness::little, false > ELF32LE
ELFType< llvm::endianness::little, true > ELF64LE
ELFType< llvm::endianness::big, false > ELF32BE
This is an optimization pass for GlobalISel generic memory operations.
@ LLVM_MARK_AS_BITMASK_ENUM
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
void consumeError(Error Err)
Consume a Error without doing anything.
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static Expected< Metadata > decode(uint32_t V)
bool operator==(const Metadata &Other) const
BBEntry(uint32_t ID, uint32_t Offset, uint32_t Size, Metadata MD, SmallVector< uint32_t, 1 > CallsiteEndOffsets, uint64_t Hash)
SmallVector< uint32_t, 1 > CallsiteEndOffsets
bool canFallThrough() const
bool hasIndirectBranch() const
bool operator==(const BBEntry &Other) const
bool operator==(const BBRangeEntry &Other) const
std::vector< BBEntry > BBEntries
bool operator==(const Features &Other) const
bool hasPGOAnalysisBBData() const
static Expected< Features > decode(uint16_t Val)
bool hasPGOAnalysis() const
const std::vector< BBRangeEntry > & getBBRanges() const
std::vector< BBRangeEntry > BBRanges
size_t getNumBBEntries() const
bool operator==(const BBAddrMap &Other) const
const std::vector< BBEntry > & getBBEntries() const
uint64_t getFunctionAddress() const
std::optional< size_t > getBBRangeIndexForBaseAddress(uint64_t BaseAddress) const
Elf_Verdaux_Impl< ELFType< E, Is64 > > Verdaux
std::conditional_t< Is64, uint64_t, uint32_t > uint
Elf_Note_Impl< ELFType< E, Is64 > > Note
Elf_Ehdr_Impl< ELFType< E, Is64 > > Ehdr
ArrayRef< Phdr > PhdrRange
static const endianness Endianness
Elf_Dyn_Impl< ELFType< E, Is64 > > Dyn
Elf_Rel_Impl< ELFType< E, Is64 >, false > Rel
Elf_Versym_Impl< ELFType< E, Is64 > > Versym
Elf_Vernaux_Impl< ELFType< E, Is64 > > Vernaux
Elf_GnuHash_Impl< ELFType< E, Is64 > > GnuHash
Elf_Rel_Impl< ELFType< E, Is64 >, true > Rela
Elf_Note_Iterator_Impl< ELFType< E, Is64 > > NoteIterator
static const bool Is64Bits
ArrayRef< Shdr > ShdrRange
Elf_CGProfile_Impl< ELFType< E, Is64 > > CGProfile
Elf_Nhdr_Impl< ELFType< E, Is64 > > Nhdr
Elf_Shdr_Impl< ELFType< E, Is64 > > Shdr
Elf_Crel_Impl< Is64 > Crel
Elf_Verneed_Impl< ELFType< E, Is64 > > Verneed
Elf_Chdr_Impl< ELFType< E, Is64 > > Chdr
ArrayRef< Rela > RelaRange
Elf_Hash_Impl< ELFType< E, Is64 > > Hash
Elf_Sym_Impl< ELFType< E, Is64 > > Sym
ArrayRef< Relr > RelrRange
Elf_Verdef_Impl< ELFType< E, Is64 > > Verdef
Elf_Phdr_Impl< ELFType< E, Is64 > > Phdr
uint32_t getType(bool) const
std::conditional_t< Is64, uint64_t, uint32_t > uint
uint32_t getSymbol(bool) const
static const bool HasAddend
void setSymbolAndType(uint32_t s, unsigned char t, bool)
std::conditional_t< Is64, int64_t, int32_t > r_addend
Elf_Dyn_Base: This structure matches the form of entries in the dynamic table section (....
Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters.
std::conditional_t< ELFType< E, Is64 >::Is64Bits, int64_t, int32_t > intX_t
std::conditional_t< ELFType< E, Is64 >::Is64Bits, uint64_t, uint32_t > uintX_t
unsigned char getFileClass() const
unsigned char e_ident[ELF::EI_NIDENT]
unsigned char getDataEncoding() const
ArrayRef< Elf_Word > values(unsigned DynamicSymCount) const
ArrayRef< Elf_Word > buckets() const
ArrayRef< Elf_Off > filter() const
ArrayRef< Elf_Word > chains() const
ArrayRef< Elf_Word > buckets() const
const Elf_Mips_RegInfo< ELFT > & getRegInfo() const
Elf_Mips_RegInfo< ELFT > & getRegInfo()
size_t getSize(size_t Align) const
unsigned char getType(bool isMips64EL) const
static const bool HasAddend
void setType(unsigned char t, bool IsMips64EL)
void setRInfo(uint32_t R, bool IsMips64EL)
uint32_t getSymbol(bool isMips64EL) const
void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL)
void setSymbol(uint32_t s, bool IsMips64EL)
uint32_t getRInfo(bool isMips64EL) const
static const bool HasAddend
void setType(uint32_t t, bool IsMips64EL)
static const bool HasAddend
void setSymbolAndType(uint32_t s, uint32_t t, bool IsMips64EL)
void setSymbol(uint32_t s, bool IsMips64EL)
uint32_t getSymbol(bool isMips64EL) const
void setRInfo(uint64_t R, bool IsMips64EL)
uint32_t getType(bool isMips64EL) const
uint64_t getRInfo(bool isMips64EL) const
static const bool HasAddend
unsigned getEntityCount() const
Get the number of entities this section contains if it has any.
void setBindingAndType(unsigned char b, unsigned char t)
bool isProcessorSpecific() const
void setBinding(unsigned char b)
unsigned char getBinding() const
Expected< StringRef > getName(StringRef StrTab) const
bool isOSSpecific() const
unsigned char getType() const
uint64_t getValue() const
void setVisibility(unsigned char v)
void setType(unsigned char t)
unsigned char getVisibility() const
Access to the STV_xxx flag stored in the first two bits of st_other.
Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef section (....
Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section (.gnu.version_d).
const Elf_Verdaux * getAux() const
Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed section (....
Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed section (.gnu....
Elf_Versym: This is the structure of entries in the SHT_GNU_versym section (.gnu.version).
Single successor of a given basic block that contains the tag and branch probability associated with ...
uint32_t ID
Unique ID of this successor basic block.
BranchProbability Prob
Branch Probability of the edge to this successor taken from MBPI.
bool operator==(const SuccessorEntry &Other) const
uint64_t PostLinkFreq
Raw edge count from the post link profile (e.g., from bolt or propeller).
Extra basic block data with fields for block frequency and branch probability.
bool operator==(const PGOBBEntry &Other) const
uint64_t PostLinkBlockFreq
Raw block count taken from the post link profile (e.g., from bolt or propeller).
llvm::SmallVector< SuccessorEntry, 2 > Successors
List of successors of the current block.
BlockFrequency BlockFreq
Block frequency taken from MBFI.
A feature extension of BBAddrMap that holds information relevant to PGO.
bool operator==(const PGOAnalysisMap &Other) const
std::vector< PGOBBEntry > BBEntries
BBAddrMap::Features FeatEnable