9 #ifndef LLVM_OBJECT_ELFTYPES_H 10 #define LLVM_OBJECT_ELFTYPES_H 21 #include <type_traits> 47 template <endianness E,
bool Is64>
struct ELFType {
49 template <
typename Ty>
56 using uint =
typename std::conditional<Is64, uint64_t, uint32_t>::type;
103 #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT) \ 104 using Elf_Addr = typename ELFT::Addr; \ 105 using Elf_Off = typename ELFT::Off; \ 106 using Elf_Half = typename ELFT::Half; \ 107 using Elf_Word = typename ELFT::Word; \ 108 using Elf_Sword = typename ELFT::Sword; \ 109 using Elf_Xword = typename ELFT::Xword; \ 110 using Elf_Sxword = typename ELFT::Sxword; 112 #define LLVM_ELF_COMMA , 113 #define LLVM_ELF_IMPORT_TYPES(E, W) \ 114 LLVM_ELF_IMPORT_TYPES_ELFT(ELFType<E LLVM_ELF_COMMA W>) 119 template <endianness TargetEndianness>
130 Elf_Word sh_addralign;
145 Elf_Xword sh_addralign;
146 Elf_Xword sh_entsize;
149 template <class ELFT>
158 return sh_size / sh_entsize;
164 template <endianness TargetEndianness>
170 unsigned char st_info;
171 unsigned char st_other;
179 unsigned char st_info;
180 unsigned char st_other;
186 template <class ELFT>
196 unsigned char getType()
const {
return st_info & 0x0f; }
199 void setType(
unsigned char t) { setBindingAndType(getBinding(), t); }
202 st_info = (b << 4) + (t & 0x0f);
212 assert(v < 4 &&
"Invalid value for visibility");
213 st_other = (st_other & ~0x3) | v;
247 template <
class ELFT>
250 if (Offset >= StrTab.
size())
252 "st_name (0x%" PRIx32
253 ") is past the end of the string table" 255 Offset, StrTab.
size());
261 template <
class ELFT>
269 template <class ELFT>
283 return reinterpret_cast<const Elf_Verdaux *
>((
const char *)
this + vd_aux);
289 template <
class ELFT>
298 template <class ELFT>
310 template <class ELFT>
334 template <endianness TargetEndianness>
345 template <
class ELFT>
349 using intX_t =
typename std::conditional<ELFT::Is64Bits,
351 using uintX_t =
typename std::conditional<ELFT::Is64Bits,
358 template <endianness TargetEndianness>
377 return this->getRInfo(isMips64EL) >> 8;
380 return (
unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
383 setSymbolAndType(s,
getType(IsMips64EL), IsMips64EL);
385 void setType(
unsigned char t,
bool IsMips64EL) {
386 setSymbolAndType(getSymbol(IsMips64EL), t, IsMips64EL);
389 this->setRInfo((s << 8) + t, IsMips64EL);
393 template <endianness TargetEndianness>
395 :
public Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
415 return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
416 ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
421 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
422 ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
430 return (
uint32_t)(this->getRInfo(isMips64EL) >> 32);
433 return (
uint32_t)(this->getRInfo(isMips64EL) & 0xffffffffL);
436 setSymbolAndType(s,
getType(IsMips64EL), IsMips64EL);
439 setSymbolAndType(getSymbol(IsMips64EL), t, IsMips64EL);
442 this->setRInfo(((uint64_t)s << 32) + (t & 0xffffffffL), IsMips64EL);
446 template <endianness TargetEndianness>
448 :
public Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
454 template <class ELFT>
466 Elf_Half e_phentsize;
468 Elf_Half e_shentsize;
473 bool checkMagic()
const {
481 template <endianness TargetEndianness>
508 template <class ELFT>
520 &nbucket + 2 + nbucket + nchain);
525 template <
class ELFT>
540 reinterpret_cast<const Elf_Word *
>(filter().end()), nbuckets);
550 template <endianness TargetEndianness>
555 Elf_Word ch_addralign;
562 Elf_Word ch_reserved;
564 Elf_Xword ch_addralign;
568 template <class ELFT>
582 size_t getSize()
const {
583 return sizeof(*this) + alignTo<Align>(n_namesz) + alignTo<Align>(n_descsz);
591 template <
class ELFT>
606 return StringRef(reinterpret_cast<const char *>(&Nhdr) +
sizeof(Nhdr),
615 reinterpret_cast<const uint8_t *
>(&
Nhdr) +
sizeof(Nhdr) +
624 template <
class ELFT>
626 : std::iterator<std::forward_iterator_tag, Elf_Note_Impl<ELFT>> {
629 size_t RemainingSize = 0u;
630 Error *Err =
nullptr;
632 template <
class ELFFileELFT>
friend class ELFFile;
635 void stopWithOverflowError() {
637 *Err = make_error<StringError>(
"ELF note overflows container",
646 void advanceNhdr(
const uint8_t *NhdrPos,
size_t NoteSize) {
647 RemainingSize -= NoteSize;
648 if (RemainingSize == 0u) {
653 }
else if (
sizeof(*Nhdr) > RemainingSize)
654 stopWithOverflowError();
657 if (Nhdr->
getSize() > RemainingSize)
658 stopWithOverflowError();
667 : RemainingSize(Size), Err(&Err) {
669 assert(Start &&
"ELF note iterator starting at NULL");
670 advanceNhdr(Start, 0u);
675 assert(Nhdr &&
"incremented ELF note end iterator");
676 const uint8_t *NhdrPos =
reinterpret_cast<const uint8_t *
>(
Nhdr);
677 size_t NoteSize = Nhdr->
getSize();
678 advanceNhdr(NhdrPos, NoteSize);
682 if (!Nhdr && Other.Err)
683 (void)(
bool)(*Other.Err);
684 if (!Other.Nhdr && Err)
686 return Nhdr == Other.Nhdr;
689 return !(*
this ==
Other);
692 assert(Nhdr &&
"dereferenced ELF note end iterator");
701 Elf_Xword cgp_weight;
705 template <class ELFT>
712 Elf_Word ri_cprmask[4];
713 Elf_Addr ri_gp_value;
716 template <support::
endianness TargetEndianness>
721 Elf_Word ri_cprmask[4];
722 Elf_Addr ri_gp_value;
734 Elf_Mips_RegInfo<ELFT> &getRegInfo() {
737 (uint8_t *)
this +
sizeof(Elf_Mips_Options));
763 #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
void setBinding(unsigned char b)
void setSymbol(uint32_t s, bool IsMips64EL)
Optional< std::vector< StOtherPiece > > Other
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
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)...
LLVM_NODISCARD size_t size() const
size - Get the string size.
ArrayRef< uint8_t > getDesc() const
Get the note's descriptor.
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")
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
Elf_Note_Impl(const Elf_Nhdr_Impl< ELFT > &Nhdr)
void consumeError(Error Err)
Consume a Error without doing anything.
static wasm::ValType getType(const TargetRegisterClass *RC)
This struct is a compact representation of a valid (non-zero power of two) alignment.
bool operator!=(Elf_Note_Iterator_Impl Other) const
ArrayRef< Elf_Word > chains() const
ArrayRef< Elf_Word > values(unsigned DynamicSymCount) const
static bool isMips64EL(const ELFYAML::Object &Doc)
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
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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).
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
size_t getSize() const
Get the size of the note, including name, descriptor, and padding.