10 #ifndef LLVM_OBJECT_ELFTYPES_H
11 #define LLVM_OBJECT_ELFTYPES_H
22 #include <type_traits>
44 template <endianness E,
bool Is64>
struct ELFType {
46 template <
typename Ty>
53 using uint =
typename std::conditional<Is64, uint64_t, uint32_t>::type;
96 uint16_t, target_endianness, 2>;
100 int32_t, target_endianness, 2>;
102 uint64_t, target_endianness, 2>;
104 int64_t, target_endianness, 2>;
110 template <endianness TargetEndianness>
121 template <endianness TargetEndianness>
133 #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \
134 using Elf_Addr = typename ELFT::Addr; \
135 using Elf_Off = typename ELFT::Off; \
136 using Elf_Half = typename ELFT::Half; \
137 using Elf_Word = typename ELFT::Word; \
138 using Elf_Sword = typename ELFT::Sword; \
139 using Elf_Xword = typename ELFT::Xword; \
140 using Elf_Sxword = typename ELFT::Sxword;
142 #define LLD_ELF_COMMA ,
143 #define LLVM_ELF_IMPORT_TYPES(E, W) \
144 LLVM_ELF_IMPORT_TYPES_ELFT(ELFType<E LLD_ELF_COMMA W>)
149 template <endianness TargetEndianness>
160 Elf_Word sh_addralign;
175 Elf_Xword sh_addralign;
176 Elf_Xword sh_entsize;
179 template <class ELFT>
188 return sh_size / sh_entsize;
194 template <endianness TargetEndianness>
200 unsigned char st_info;
201 unsigned char st_other;
209 unsigned char st_info;
210 unsigned char st_other;
216 template <class ELFT>
226 unsigned char getType()
const {
return st_info & 0x0f; }
229 void setType(
unsigned char t) { setBindingAndType(getBinding(), t); }
232 st_info = (b << 4) + (t & 0x0f);
242 assert(v < 4 &&
"Invalid value for visibility");
243 st_other = (st_other & ~0x3) | v;
277 template <
class ELFT>
280 if (Offset >= StrTab.
size())
287 template <
class ELFT>
295 template <class ELFT>
309 return reinterpret_cast<const Elf_Verdaux *
>((
const char *)
this + vd_aux);
315 template <
class ELFT>
316 struct Elf_Verdaux_Impl {
324 template <class ELFT>
336 template <class ELFT>
360 template <endianness TargetEndianness>
371 template <
class ELFT>
372 struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {
373 using Elf_Dyn_Base<ELFT>::d_tag;
374 using Elf_Dyn_Base<ELFT>::d_un;
375 using intX_t =
typename std::conditional<ELFT::Is64Bits,
376 int64_t, int32_t>::type;
377 using uintX_t =
typename std::conditional<ELFT::Is64Bits,
384 template <endianness TargetEndianness>
403 return this->getRInfo(isMips64EL) >> 8;
405 unsigned char getType(
bool isMips64EL)
const {
406 return (
unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
409 setSymbolAndType(s,
getType(), IsMips64EL);
412 setSymbolAndType(
getSymbol(), t, IsMips64EL);
415 this->setRInfo((s << 8) + t, IsMips64EL);
419 template <endianness TargetEndianness>
421 :
public Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
434 uint64_t getRInfo(
bool isMips64EL)
const {
441 return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
442 ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
447 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
448 ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
456 return (
uint32_t)(this->getRInfo(isMips64EL) >> 32);
459 return (
uint32_t)(this->getRInfo(isMips64EL) & 0xffffffff
L);
462 setSymbolAndType(s,
getType(), IsMips64EL);
465 setSymbolAndType(
getSymbol(), t, IsMips64EL);
468 this->setRInfo(((uint64_t)s << 32) + (t & 0xffffffffL), IsMips64EL);
472 template <endianness TargetEndianness>
474 :
public Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
480 template <class ELFT>
492 Elf_Half e_phentsize;
494 Elf_Half e_shentsize;
499 bool checkMagic()
const {
507 template <endianness TargetEndianness>
534 template <class ELFT>
546 &nbucket + 2 + nbucket + nchain);
551 template <
class ELFT>
552 struct Elf_GnuHash_Impl {
566 reinterpret_cast<const Elf_Word *
>(filter().end()), nbuckets);
576 template <endianness TargetEndianness>
581 Elf_Word ch_addralign;
588 Elf_Word ch_reserved;
590 Elf_Xword ch_addralign;
594 template <class ELFT>
597 template <support::
endianness TargetEndianness>
601 Elf_Word ri_cprmask[4];
602 Elf_Addr ri_gp_value;
605 template <support::
endianness TargetEndianness>
606 struct Elf_Mips_RegInfo<
ELFType<TargetEndianness, true>> {
610 Elf_Word ri_cprmask[4];
611 Elf_Addr ri_gp_value;
623 Elf_Mips_RegInfo<ELFT> &getRegInfo() {
626 (uint8_t *)
this +
sizeof(Elf_Mips_Options));
652 #endif // LLVM_OBJECT_ELFTYPES_H
unsigned char getType() const
void setSymbolAndType(uint32_t s, uint32_t t, bool IsMips64EL)
void setType(unsigned char t, bool IsMips64EL)
void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL)
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
ArrayRef< Elf_Word > values(unsigned DynamicSymCount) const
unsigned char getType(bool isMips64EL) const
void setBinding(unsigned char b)
void setSymbol(uint32_t s, bool IsMips64EL)
bool isOSSpecific() const
Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters.
static const endianness TargetEndianness
uint64_t getValue() const
void setType(uint32_t t, bool IsMips64EL)
uint32_t getSymbol(bool isMips64EL) const
unsigned char getFileClass() const
llvm::support::endianness endianness
static StringRef getName(Value *V)
Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed section (.gnu.version_r).
Tagged union holding either a T or a Error.
#define LLVM_ELF_IMPORT_TYPES(E, W)
ArrayRef< Elf_Word > buckets() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
void setSymbol(uint32_t s, bool IsMips64EL)
Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef section (...
Function Alias Analysis false
bool isProcessorSpecific() const
Expected< StringRef > getName(StringRef StrTab) const
void setType(unsigned char t)
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
typename std::conditional< Is64, uint64_t, uint32_t >::type uint
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 (...
static wasm::ValType getType(const TargetRegisterClass *RC)
static const char ElfMagic[]
void setBindingAndType(unsigned char b, unsigned char t)
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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint32_t getType(bool isMips64EL) const
static const bool Is64Bits
const Elf_Mips_RegInfo< ELFT > & getRegInfo() const
uint32_t getSymbol(bool isMips64EL) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
typename std::conditional< ELFT::Is64Bits, int64_t, int32_t >::type intX_t
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
StringRef - Represent a constant reference to a string, i.e.
typename std::conditional< ELFT::Is64Bits, uint64_t, uint32_t >::type uintX_t
Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed section (.gnu.version_r).
unsigned char getBinding() const