9#ifndef LLVM_OBJECT_ELFTYPES_H
10#define LLVM_OBJECT_ELFTYPES_H
29template <
class ELFT>
struct Elf_Ehdr_Impl;
30template <
class ELFT>
struct Elf_Shdr_Impl;
31template <
class ELFT>
struct Elf_Sym_Impl;
32template <
class ELFT>
struct Elf_Dyn_Impl;
49template <endianness E,
bool Is64>
struct ELFType {
51 template <
typename Ty>
58 using uint = std::conditional_t<Is64, uint64_t, uint32_t>;
106#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \
107 using Elf_Addr = typename ELFT::Addr; \
108 using Elf_Off = typename ELFT::Off; \
109 using Elf_Half = typename ELFT::Half; \
110 using Elf_Word = typename ELFT::Word; \
111 using Elf_Sword = typename ELFT::Sword; \
112 using Elf_Xword = typename ELFT::Xword; \
113 using Elf_Sxword = typename ELFT::Sxword; \
114 using uintX_t = typename ELFT::uint; \
115 using Elf_Ehdr = typename ELFT::Ehdr; \
116 using Elf_Shdr = typename ELFT::Shdr; \
117 using Elf_Sym = typename ELFT::Sym; \
118 using Elf_Dyn = typename ELFT::Dyn; \
119 using Elf_Phdr = typename ELFT::Phdr; \
120 using Elf_Rel = typename ELFT::Rel; \
121 using Elf_Rela = typename ELFT::Rela; \
122 using Elf_Crel = typename ELFT::Crel; \
123 using Elf_Relr = typename ELFT::Relr; \
124 using Elf_Verdef = typename ELFT::Verdef; \
125 using Elf_Verdaux = typename ELFT::Verdaux; \
126 using Elf_Verneed = typename ELFT::Verneed; \
127 using Elf_Vernaux = typename ELFT::Vernaux; \
128 using Elf_Versym = typename ELFT::Versym; \
129 using Elf_Hash = typename ELFT::Hash; \
130 using Elf_GnuHash = typename ELFT::GnuHash; \
131 using Elf_Chdr = typename ELFT::Chdr; \
132 using Elf_Nhdr = typename ELFT::Nhdr; \
133 using Elf_Note = typename ELFT::Note; \
134 using Elf_Note_Iterator = typename ELFT::NoteIterator; \
135 using Elf_CGProfile = typename ELFT::CGProfile; \
136 using Elf_Dyn_Range = typename ELFT::DynRange; \
137 using Elf_Shdr_Range = typename ELFT::ShdrRange; \
138 using Elf_Sym_Range = typename ELFT::SymRange; \
139 using Elf_Rel_Range = typename ELFT::RelRange; \
140 using Elf_Rela_Range = typename ELFT::RelaRange; \
141 using Elf_Relr_Range = typename ELFT::RelrRange; \
142 using Elf_Phdr_Range = typename ELFT::PhdrRange;
144#define LLVM_ELF_COMMA ,
145#define LLVM_ELF_IMPORT_TYPES(E, W) \
146 LLVM_ELF_IMPORT_TYPES_ELFT(ELFType<E LLVM_ELF_COMMA W>)
151template <endianness Endianness>
162 Elf_Word sh_addralign;
177 Elf_Xword sh_addralign;
178 Elf_Xword sh_entsize;
190 return sh_size / sh_entsize;
196template <endianness Endianness>
202 unsigned char st_info;
203 unsigned char st_other;
211 unsigned char st_info;
212 unsigned char st_other;
228 unsigned char getType()
const {
return st_info & 0x0f; }
231 void setType(
unsigned char t) { setBindingAndType(getBinding(), t); }
234 st_info = (b << 4) + (t & 0x0f);
244 assert(v < 4 &&
"Invalid value for visibility");
245 st_other = (st_other & ~0x3) | v;
251 return getType() == ELF::STT_COMMON || st_shndx == ELF::SHN_COMMON;
257 return st_shndx >= ELF::SHN_LOPROC && st_shndx <= ELF::SHN_HIPROC;
261 return st_shndx >= ELF::SHN_LOOS && st_shndx <= ELF::SHN_HIOS;
267 return st_shndx >= ELF::SHN_LORESERVE;
273 return getBinding() != ELF::STB_LOCAL;
284 "st_name (0x%" PRIx32
285 ") is past the end of the string table"
314 return reinterpret_cast<const Elf_Verdaux *
>((
const char *)
this + vd_aux);
365template <endianness Endianness>
380 using intX_t = std::conditional_t<ELFT::Is64Bits, int64_t, int32_t>;
381 using uintX_t = std::conditional_t<ELFT::Is64Bits, uint64_t, uint32_t>;
387template <endianness Endianness>
410 return (
unsigned char)(this->getRInfo(
isMips64EL) & 0x0ff);
413 setSymbolAndType(s,
getType(IsMips64EL), IsMips64EL);
415 void setType(
unsigned char t,
bool IsMips64EL) {
416 setSymbolAndType(getSymbol(IsMips64EL), t, IsMips64EL);
419 this->setRInfo((s << 8) + t, IsMips64EL);
423template <endianness Endianness>
425 :
public Elf_Rel_Impl<ELFType<Endianness, false>, false> {
447 return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
448 ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
453 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
454 ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
468 setSymbolAndType(s,
getType(IsMips64EL), IsMips64EL);
471 setSymbolAndType(getSymbol(IsMips64EL), t, IsMips64EL);
474 this->setRInfo(((
uint64_t)s << 32) + (t & 0xffffffffL), IsMips64EL);
478template <endianness Endianness>
480 :
public Elf_Rel_Impl<ELFType<Endianness, true>, false> {
489 using uint = std::conditional_t<Is64, uint64_t, uint32_t>;
490 static const bool HasAddend =
true;
491 static const bool IsCrel =
true;
495 std::conditional_t<Is64, int64_t, int32_t>
r_addend;
518 Elf_Half e_phentsize;
520 Elf_Half e_shentsize;
525 bool checkMagic()
const {
526 return (
memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
533template <endianness Endianness>
572 &nbucket + 2 + nbucket + nchain);
592 reinterpret_cast<const Elf_Word *
>(filter().end()), nbuckets);
596 assert(DynamicSymCount >= symndx);
603template <endianness Endianness>
608 Elf_Word ch_addralign;
615 Elf_Word ch_reserved;
617 Elf_Xword ch_addralign;
657 return StringRef(
reinterpret_cast<const char *
>(&Nhdr) +
sizeof(Nhdr),
666 reinterpret_cast<const uint8_t *
>(&Nhdr) +
692 size_t RemainingSize = 0u;
694 Error *Err =
nullptr;
696 template <
class ELFFileELFT>
friend class ELFFile;
699 void stopWithOverflowError() {
701 *Err = make_error<StringError>(
"ELF note overflows container",
702 object_error::parse_failed);
710 void advanceNhdr(
const uint8_t *NhdrPos,
size_t NoteSize) {
711 RemainingSize -= NoteSize;
712 if (RemainingSize == 0u) {
715 *Err = Error::success();
717 }
else if (
sizeof(*Nhdr) > RemainingSize)
718 stopWithOverflowError();
720 Nhdr =
reinterpret_cast<const Elf_Nhdr_Impl<ELFT> *
>(NhdrPos + NoteSize);
722 stopWithOverflowError();
724 *Err = Error::success();
728 Elf_Note_Iterator_Impl() =
default;
729 explicit Elf_Note_Iterator_Impl(Error &Err) : Err(&Err) {}
734 assert(Start &&
"ELF note iterator starting at NULL");
735 advanceNhdr(Start, 0u);
740 assert(Nhdr &&
"incremented ELF note end iterator");
743 advanceNhdr(NhdrPos, NoteSize);
747 if (!Nhdr &&
Other.Err)
748 (void)(
bool)(*
Other.Err);
749 if (!
Other.Nhdr && Err)
751 return Nhdr ==
Other.Nhdr;
754 return !(*
this ==
Other);
757 assert(Nhdr &&
"dereferenced ELF note end iterator");
764 Elf_Xword cgp_weight;
775 Elf_Word ri_cprmask[4];
776 Elf_Addr ri_gp_value;
784 Elf_Word ri_cprmask[4];
785 Elf_Addr ri_gp_value;
798 assert(kind == ELF::ODK_REGINFO);
844 (
static_cast<uint8_t>(MultiBBRange) << 3) |
845 (
static_cast<uint8_t>(OmitBBEntries) << 4);
852 static_cast<bool>(Val & (1 << 0)),
static_cast<bool>(Val & (1 << 1)),
853 static_cast<bool>(Val & (1 << 2)),
static_cast<bool>(Val & (1 << 3)),
854 static_cast<bool>(Val & (1 << 4))};
855 if (Feat.encode() != Val)
857 std::error_code(),
"invalid encoding for BBAddrMap::Features: 0x%x",
882 return HasReturn ==
Other.HasReturn &&
883 HasTailCall ==
Other.HasTailCall && IsEHPad ==
Other.IsEHPad &&
884 CanFallThrough ==
Other.CanFallThrough &&
885 HasIndirectBranch ==
Other.HasIndirectBranch;
890 return static_cast<uint32_t>(HasReturn) |
891 (
static_cast<uint32_t>(HasTailCall) << 1) |
892 (
static_cast<uint32_t>(IsEHPad) << 2) |
893 (
static_cast<uint32_t>(CanFallThrough) << 3) |
894 (
static_cast<uint32_t>(HasIndirectBranch) << 4);
899 Metadata MD{
static_cast<bool>(V & 1),
900 static_cast<bool>(V & (1 << 1)),
901 static_cast<bool>(V & (1 << 2)),
902 static_cast<bool>(V & (1 << 3)),
903 static_cast<bool>(V & (1 << 4))};
904 if (MD.encode() != V)
906 std::error_code(),
"invalid encoding for BBEntry::Metadata: 0x%x",
941 return BaseAddress ==
Other.BaseAddress &&
942 std::equal(BBEntries.begin(), BBEntries.end(),
943 Other.BBEntries.begin());
954 assert(!BBRanges.empty());
955 return BBRanges.front().BaseAddress;
960 size_t NumBBEntries = 0;
961 for (
const auto &BBR : BBRanges)
962 NumBBEntries += BBR.BBEntries.size();
968 std::optional<size_t>
970 for (
size_t I = 0;
I < BBRanges.size(); ++
I)
971 if (BBRanges[
I].BaseAddress == BaseAddress)
978 return BBRanges.front().BBEntries;
981 const std::vector<BBRangeEntry> &
getBBRanges()
const {
return BBRanges; }
985 return std::equal(BBRanges.begin(), BBRanges.end(),
Other.BBRanges.begin());
1003 return std::tie(
ID, Prob) == std::tie(
Other.ID,
Other.Prob);
1013 return std::tie(BlockFreq, Successors) ==
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)
std::optional< std::vector< StOtherPiece > > Other
Merge contiguous icmps into a memcmp
static StringRef getName(Value *V)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SymbolRef::Type getType(const Symbol *Sym)
static unsigned getSize(unsigned Kind)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
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.
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
std::ptrdiff_t difference_type
Elf_Note_Impl< ELFT > operator*() const
Elf_Note_Iterator_Impl & operator++()
bool operator==(Elf_Note_Iterator_Impl Other) const
This is an optimization pass for GlobalISel generic memory operations.
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.
void consumeError(Error Err)
Consume a Error without doing anything.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Description of the encoding of one expression Op.
static Expected< Metadata > decode(uint32_t V)
bool operator==(const Metadata &Other) const
bool canFallThrough() const
bool hasIndirectBranch() const
bool operator==(const BBEntry &Other) const
BBEntry(uint32_t ID, uint32_t Offset, uint32_t Size, Metadata MD)
bool operator==(const BBRangeEntry &Other) const
std::vector< BBEntry > BBEntries
bool operator==(const Features &Other) const
bool hasPGOAnalysisBBData() const
static Expected< Features > decode(uint8_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
std::conditional_t< Is64, uint64_t, uint32_t > uint
static const endianness Endianness
static const bool Is64Bits
uint32_t getType(bool) const
std::conditional_t< Is64, uint64_t, uint32_t > uint
uint32_t getSymbol(bool) const
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< ELFT::Is64Bits, int64_t, int32_t > intX_t
std::conditional_t< ELFT::Is64Bits, uint64_t, uint32_t > uintX_t
unsigned char getFileClass() const
unsigned char getDataEncoding() const
ArrayRef< Elf_Word > values(unsigned DynamicSymCount) const
ArrayRef< Elf_Word > buckets() const
ArrayRef< Elf_Word > chains() const
const Elf_Mips_RegInfo< ELFT > & getRegInfo() const
size_t getSize(size_t Align) const
Get the size of the note, including name, descriptor, and padding.
unsigned char getType(bool isMips64EL) const
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)
void setType(uint32_t t, bool IsMips64EL)
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
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
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).
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
Extra basic block data with fields for block frequency and branch probability.
bool operator==(const PGOBBEntry &Other) const
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