10 #ifndef LLVM_OBJECT_ELFTYPES_H
11 #define LLVM_OBJECT_ELFTYPES_H
15 #include "llvm/Support/DataTypes.h"
25 template <endianness target_endianness,
bool is64Bits>
struct ELFType {
55 template <endianness TargetEndianness>
66 template <endianness TargetEndianness>
77 #define LLVM_ELF_IMPORT_TYPES(E, W) \
78 typedef typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Addr Elf_Addr; \
79 typedef typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Off Elf_Off; \
80 typedef typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Half Elf_Half; \
81 typedef typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Word Elf_Word; \
83 typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Sword Elf_Sword; \
85 typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Xword Elf_Xword; \
87 typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Sxword Elf_Sxword;
89 #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \
90 LLVM_ELF_IMPORT_TYPES(ELFT::TargetEndianness, ELFT::Is64Bits)
95 template <endianness TargetEndianness>
106 Elf_Word sh_addralign;
121 Elf_Xword sh_addralign;
122 Elf_Xword sh_entsize;
125 template <class ELFT>
134 return sh_size / sh_entsize;
140 template <endianness TargetEndianness>
146 unsigned char st_info;
147 unsigned char st_other;
155 unsigned char st_info;
156 unsigned char st_other;
162 template <class ELFT>
172 unsigned char getType()
const {
return st_info & 0x0f; }
175 void setType(
unsigned char t) { setBindingAndType(getBinding(), t); }
177 st_info = (b << 4) + (t & 0x0f);
187 assert(v < 4 &&
"Invalid value for visibility");
188 st_other = (st_other & ~0x3) | v;
215 template <
class ELFT>
217 uint32_t Offset = this->st_name;
218 if (Offset >= StrTab.
size())
225 template <
class ELFT>
235 template <class ELFT>
249 return reinterpret_cast<const Elf_Verdaux *
>((
const char *)
this + vd_aux);
255 template <
class ELFT>
264 template <class ELFT>
276 template <class ELFT>
300 template <endianness TargetEndianness>
311 template <
class ELFT>
316 uint64_t
getVal()
const {
return d_un.d_val; }
317 uint64_t
getPtr()
const {
return d_un.d_ptr; }
323 template <endianness TargetEndianness>
329 uint32_t getRInfo(
bool isMips64EL)
const {
341 return this->getRInfo(isMips64EL) >> 8;
343 unsigned char getType(
bool isMips64EL)
const {
344 return (
unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
347 setSymbolAndType(s,
getType(), IsMips64EL);
349 void setType(
unsigned char t,
bool IsMips64EL) {
350 setSymbolAndType(getSymbol(), t, IsMips64EL);
353 this->setRInfo((s << 8) + t, IsMips64EL);
357 template <endianness TargetEndianness>
359 :
public Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
370 uint64_t getRInfo(
bool isMips64EL)
const {
377 return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
378 ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
382 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
383 ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
391 return (uint32_t)(this->getRInfo(isMips64EL) >> 32);
394 return (uint32_t)(this->getRInfo(isMips64EL) & 0xffffffffL);
397 setSymbolAndType(s,
getType(), IsMips64EL);
400 setSymbolAndType(getSymbol(), t, IsMips64EL);
403 this->setRInfo(((uint64_t)s << 32) + (t & 0xffffffffL), IsMips64EL);
407 template <endianness TargetEndianness>
409 :
public Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
414 template <class ELFT>
426 Elf_Half e_phentsize;
428 Elf_Half e_shentsize;
432 bool checkMagic()
const {
441 template <endianness TargetEndianness>
468 template <class ELFT>
480 &nbucket + 2 + nbucket + nchain);
485 template <
class ELFT>
488 template <llvm::support::endianness TargetEndianness>
492 Elf_Word ri_cprmask[4];
493 Elf_Addr ri_gp_value;
496 template <llvm::support::
endianness TargetEndianness>
501 Elf_Word ri_cprmask[4];
502 Elf_Addr ri_gp_value;
517 (
const uint8_t *)
this +
sizeof(Elf_Mips_Options));
unsigned char getType() const
void setSymbolAndType(uint32_t s, uint32_t t, bool IsMips64EL)
static const bool Is64Bits
Represents either an error or a value T.
void setType(unsigned char t, bool IsMips64EL)
void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL)
size_t size() const
size - Get the string size.
void setVisibility(unsigned char v)
Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section (.gnu.version_d).
unsigned char getDataEncoding() const
unsigned char getType(bool isMips64EL) const
void setBinding(unsigned char b)
void setSymbol(uint32_t s, bool IsMips64EL)
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
bool isOSSpecific() const
Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters and setters.
ELFType< support::little, true > ELF64LE
ELFType< support::big, false > ELF32BE
uint64_t getValue() const
void setType(uint32_t t, bool IsMips64EL)
support::detail::packed_endian_specific_integral< int32_t, target_endianness, 2 > Elf_Sword
uint32_t getSymbol(bool isMips64EL) const
unsigned char getFileClass() const
support::detail::packed_endian_specific_integral< value_type, TargetEndianness, 2 > Elf_Addr
static StringRef getName(Value *V)
Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed section (.gnu.version_r).
#define LLVM_ELF_IMPORT_TYPES(E, W)
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
support::detail::packed_endian_specific_integral< uint16_t, target_endianness, 2 > Elf_Half
support::detail::packed_endian_specific_integral< value_type, TargetEndianness, 2 > Elf_Addr
void setSymbol(uint32_t s, bool IsMips64EL)
Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef section (...
bool isProcessorSpecific() const
ErrorOr< StringRef > getName(StringRef StrTab) const
ELFType< support::little, false > ELF32LE
void setType(unsigned char t)
support::detail::packed_endian_specific_integral< value_type, TargetEndianness, 2 > Elf_Off
unsigned char getVisibility() const
Access to the STV_xxx flag stored in the first two bits of st_other.
Elf_Dyn_Base: This structure matches the form of entries in the dynamic table section (...
ELFType< support::big, true > ELF64BE
support::detail::packed_endian_specific_integral< uint32_t, target_endianness, 2 > Elf_Word
static const char ElfMagic[]
void setBindingAndType(unsigned char b, unsigned char t)
support::detail::packed_endian_specific_integral< int64_t, target_endianness, 2 > Elf_Sxword
Elf_Versym: This is the structure of entries in the SHT_GNU_versym section (.gnu.version).
void setRInfo(uint64_t R, bool IsMips64EL)
ArrayRef< Elf_Word > chains() const
unsigned getEntityCount() const
Get the number of entities this section contains if it has any.
void setRInfo(uint32_t R, bool IsMips64EL)
Provides ErrorOr<T> smart pointer.
static const endianness TargetEndianness
support::detail::packed_endian_specific_integral< value_type, TargetEndianness, 2 > Elf_Off
uint32_t getType(bool isMips64EL) const
uint32_t getSymbol(bool isMips64EL) const
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
StringRef - Represent a constant reference to a string, i.e.
Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed section (.gnu.version_r).
unsigned char getBinding() const
support::detail::packed_endian_specific_integral< uint64_t, target_endianness, 2 > Elf_Xword