10 #ifndef LLVM_OBJECT_ELFTYPES_H 11 #define LLVM_OBJECT_ELFTYPES_H 22 #include <type_traits> 48 template <endianness E,
bool Is64>
struct ELFType {
50 template <
typename Ty>
57 using uint =
typename std::conditional<Is64, uint64_t, uint32_t>::type;
104 #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \ 105 using Elf_Addr = typename ELFT::Addr; \ 106 using Elf_Off = typename ELFT::Off; \ 107 using Elf_Half = typename ELFT::Half; \ 108 using Elf_Word = typename ELFT::Word; \ 109 using Elf_Sword = typename ELFT::Sword; \ 110 using Elf_Xword = typename ELFT::Xword; \ 111 using Elf_Sxword = typename ELFT::Sxword; 113 #define LLVM_ELF_COMMA , 114 #define LLVM_ELF_IMPORT_TYPES(E, W) \ 115 LLVM_ELF_IMPORT_TYPES_ELFT(ELFType<E LLVM_ELF_COMMA W>) 120 template <endianness TargetEndianness>
131 Elf_Word sh_addralign;
146 Elf_Xword sh_addralign;
147 Elf_Xword sh_entsize;
150 template <class ELFT>
159 return sh_size / sh_entsize;
165 template <endianness TargetEndianness>
171 unsigned char st_info;
172 unsigned char st_other;
180 unsigned char st_info;
181 unsigned char st_other;
187 template <class ELFT>
197 unsigned char getType()
const {
return st_info & 0x0f; }
200 void setType(
unsigned char t) { setBindingAndType(getBinding(), t); }
203 st_info = (b << 4) + (t & 0x0f);
213 assert(v < 4 &&
"Invalid value for visibility");
214 st_other = (st_other & ~0x3) | v;
248 template <
class ELFT>
251 if (Offset >= StrTab.
size())
258 template <
class ELFT>
266 template <class ELFT>
280 return reinterpret_cast<const Elf_Verdaux *
>((
const char *)
this + vd_aux);
286 template <
class ELFT>
295 template <class ELFT>
307 template <class ELFT>
331 template <endianness TargetEndianness>
342 template <
class ELFT>
346 using intX_t =
typename std::conditional<ELFT::Is64Bits,
348 using uintX_t =
typename std::conditional<ELFT::Is64Bits,
355 template <endianness TargetEndianness>
374 return this->getRInfo(isMips64EL) >> 8;
376 unsigned char getType(
bool isMips64EL)
const {
377 return (
unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
380 setSymbolAndType(s,
getType(IsMips64EL), IsMips64EL);
382 void setType(
unsigned char t,
bool IsMips64EL) {
383 setSymbolAndType(
getSymbol(IsMips64EL), t, IsMips64EL);
386 this->setRInfo((s << 8) + t, IsMips64EL);
390 template <endianness TargetEndianness>
392 :
public Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
405 uint64_t getRInfo(
bool isMips64EL)
const {
412 return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
413 ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
418 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
419 ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
427 return (
uint32_t)(this->getRInfo(isMips64EL) >> 32);
430 return (
uint32_t)(this->getRInfo(isMips64EL) & 0xffffffffL);
433 setSymbolAndType(s,
getType(IsMips64EL), IsMips64EL);
436 setSymbolAndType(
getSymbol(IsMips64EL), t, IsMips64EL);
439 this->setRInfo(((uint64_t)s << 32) + (t & 0xffffffffL), IsMips64EL);
443 template <endianness TargetEndianness>
445 :
public Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
451 template <class ELFT>
463 Elf_Half e_phentsize;
465 Elf_Half e_shentsize;
470 bool checkMagic()
const {
478 template <endianness TargetEndianness>
505 template <class ELFT>
517 &nbucket + 2 + nbucket + nchain);
522 template <
class ELFT>
537 reinterpret_cast<const Elf_Word *
>(filter().end()), nbuckets);
547 template <endianness TargetEndianness>
552 Elf_Word ch_addralign;
559 Elf_Word ch_reserved;
561 Elf_Xword ch_addralign;
565 template <class ELFT>
579 size_t getSize()
const {
580 return sizeof(*this) + alignTo<Align>(n_namesz) + alignTo<Align>(n_descsz);
588 template <
class ELFT>
603 return StringRef(reinterpret_cast<const char *>(&Nhdr) +
sizeof(Nhdr),
612 reinterpret_cast<const uint8_t *
>(&
Nhdr) +
sizeof(Nhdr) +
621 template <
class ELFT>
623 : std::iterator<std::forward_iterator_tag, Elf_Note_Impl<ELFT>> {
626 size_t RemainingSize = 0u;
627 Error *Err =
nullptr;
629 template <
class ELFFileELFT>
friend class ELFFile;
632 void stopWithOverflowError() {
634 *Err = make_error<StringError>(
"ELF note overflows container",
643 void advanceNhdr(
const uint8_t *NhdrPos,
size_t NoteSize) {
644 RemainingSize -= NoteSize;
645 if (RemainingSize == 0u) {
650 }
else if (
sizeof(*Nhdr) > RemainingSize)
651 stopWithOverflowError();
654 if (Nhdr->
getSize() > RemainingSize)
655 stopWithOverflowError();
664 : RemainingSize(Size), Err(&Err) {
666 assert(Start &&
"ELF note iterator starting at NULL");
667 advanceNhdr(Start, 0u);
672 assert(Nhdr &&
"incremented ELF note end iterator");
673 const uint8_t *NhdrPos =
reinterpret_cast<const uint8_t *
>(
Nhdr);
674 size_t NoteSize = Nhdr->
getSize();
675 advanceNhdr(NhdrPos, NoteSize);
679 if (!Nhdr && Other.Err)
680 (void)(
bool)(*Other.Err);
681 if (!Other.Nhdr && Err)
683 return Nhdr == Other.Nhdr;
686 return !(*
this ==
Other);
689 assert(Nhdr &&
"dereferenced ELF note end iterator");
698 Elf_Xword cgp_weight;
702 template <class ELFT>
709 Elf_Word ri_cprmask[4];
710 Elf_Addr ri_gp_value;
713 template <support::
endianness TargetEndianness>
718 Elf_Word ri_cprmask[4];
719 Elf_Addr ri_gp_value;
731 Elf_Mips_RegInfo<ELFT> &getRegInfo() {
734 (uint8_t *)
this +
sizeof(Elf_Mips_Options));
760 #endif // LLVM_OBJECT_ELFTYPES_H unsigned char getType() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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)
This class represents lattice values for constants.
void setVisibility(unsigned char v)
bool isProcessorSpecific() const
Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section (.gnu.version_d).
bool isOSSpecific() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
void setBinding(unsigned char b)
void setSymbol(uint32_t s, bool IsMips64EL)
Elf_Nhdr_Impl< ELFType< E, Is64 > > Nhdr
block Block Frequency true
Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters.
static const endianness TargetEndianness
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).
unsigned char getFileClass() const
Elf_Note_Iterator_Impl & operator++()
void setType(uint32_t t, bool IsMips64EL)
llvm::support::endianness endianness
static StringRef getName(Value *V)
uint32_t getType(bool isMips64EL) const
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)
uint64_t getValue() const
unsigned char getVisibility() const
Access to the STV_xxx flag stored in the first two bits of st_other.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
ArrayRef< uint8_t > getDesc() const
Get the note's descriptor.
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 (...
Expected< StringRef > getName(StringRef StrTab) const
unsigned char getDataEncoding() const
void setType(unsigned char t)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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 getEntityCount() const
Get the number of entities this section contains if it has any.
Elf_Dyn_Base: This structure matches the form of entries in the dynamic table section (...
uint32_t getSymbol(bool isMips64EL) const
void consumeError(Error Err)
Consume a Error without doing anything.
static wasm::ValType getType(const TargetRegisterClass *RC)
bool operator!=(Elf_Note_Iterator_Impl Other) const
ArrayRef< Elf_Word > chains() const
ArrayRef< Elf_Word > values(unsigned DynamicSymCount) const
static const char ElfMagic[]
bool operator==(Elf_Note_Iterator_Impl Other) const
static ErrorSuccess success()
Create a success value.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Elf_Note_Impl< ELFT > operator*() const
unsigned char getBinding() const
StringRef getName() const
Get the note's name, excluding the terminating null byte.
unsigned char getType(bool isMips64EL) const
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)
Merge contiguous icmps into a memcmp
void setRInfo(uint32_t R, bool IsMips64EL)
uint32_t getSymbol(bool isMips64EL) const
Elf_Word getType() const
Get the note's type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const bool Is64Bits
Lightweight error class with error context and mandatory checking.
ArrayRef< Elf_Word > buckets() const
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.
const Elf_Mips_RegInfo< ELFT > & getRegInfo() const
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).
size_t getSize() const
Get the size of the note, including name, descriptor, and padding.