Go to the documentation of this file.
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 = std::conditional_t<Is64, uint64_t, uint32_t>;
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; \
111 using uintX_t = typename ELFT::uint; \
112 using Elf_Ehdr = typename ELFT::Ehdr; \
113 using Elf_Shdr = typename ELFT::Shdr; \
114 using Elf_Sym = typename ELFT::Sym; \
115 using Elf_Dyn = typename ELFT::Dyn; \
116 using Elf_Phdr = typename ELFT::Phdr; \
117 using Elf_Rel = typename ELFT::Rel; \
118 using Elf_Rela = typename ELFT::Rela; \
119 using Elf_Relr = typename ELFT::Relr; \
120 using Elf_Verdef = typename ELFT::Verdef; \
121 using Elf_Verdaux = typename ELFT::Verdaux; \
122 using Elf_Verneed = typename ELFT::Verneed; \
123 using Elf_Vernaux = typename ELFT::Vernaux; \
124 using Elf_Versym = typename ELFT::Versym; \
125 using Elf_Hash = typename ELFT::Hash; \
126 using Elf_GnuHash = typename ELFT::GnuHash; \
127 using Elf_Nhdr = typename ELFT::Nhdr; \
128 using Elf_Note = typename ELFT::Note; \
129 using Elf_Note_Iterator = typename ELFT::NoteIterator; \
130 using Elf_CGProfile = typename ELFT::CGProfile; \
131 using Elf_Dyn_Range = typename ELFT::DynRange; \
132 using Elf_Shdr_Range = typename ELFT::ShdrRange; \
133 using Elf_Sym_Range = typename ELFT::SymRange; \
134 using Elf_Rel_Range = typename ELFT::RelRange; \
135 using Elf_Rela_Range = typename ELFT::RelaRange; \
136 using Elf_Relr_Range = typename ELFT::RelrRange; \
137 using Elf_Phdr_Range = typename ELFT::PhdrRange; \
139 #define LLVM_ELF_COMMA ,
140 #define LLVM_ELF_IMPORT_TYPES(E, W) \
141 LLVM_ELF_IMPORT_TYPES_ELFT(ELFType<E LLVM_ELF_COMMA W>)
146 template <endianness TargetEndianness>
157 Elf_Word sh_addralign;
172 Elf_Xword sh_addralign;
173 Elf_Xword sh_entsize;
176 template <class ELFT>
185 return sh_size / sh_entsize;
191 template <endianness TargetEndianness>
197 unsigned char st_info;
198 unsigned char st_other;
206 unsigned char st_info;
207 unsigned char st_other;
213 template <class ELFT>
223 unsigned char getType()
const {
return st_info & 0x0f; }
226 void setType(
unsigned char t) { setBindingAndType(getBinding(),
t); }
229 st_info = (
b << 4) + (
t & 0x0f);
239 assert(v < 4 &&
"Invalid value for visibility");
240 st_other = (st_other & ~0x3) | v;
274 template <
class ELFT>
279 "st_name (0x%" PRIx32
280 ") is past the end of the string table"
288 template <
class ELFT>
296 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 = std::conditional_t<ELFT::Is64Bits, int64_t, int32_t>;
376 using uintX_t = std::conditional_t<ELFT::Is64Bits, uint64_t, uint32_t>;
382 template <endianness TargetEndianness>
404 return (
unsigned char)(this->getRInfo(
isMips64EL) & 0x0ff);
407 setSymbolAndType(
s,
getType(IsMips64EL), IsMips64EL);
410 setSymbolAndType(getSymbol(IsMips64EL),
t, IsMips64EL);
413 this->setRInfo((
s << 8) +
t, IsMips64EL);
417 template <endianness TargetEndianness>
419 :
public Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
439 return (
t << 32) | ((
t >> 8) & 0xff000000) | ((
t >> 24) & 0x00ff0000) |
440 ((
t >> 40) & 0x0000ff00) | ((
t >> 56) & 0x000000ff);
445 r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
446 ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
460 setSymbolAndType(
s,
getType(IsMips64EL), IsMips64EL);
463 setSymbolAndType(getSymbol(IsMips64EL),
t, IsMips64EL);
466 this->setRInfo(((uint64_t)
s << 32) + (
t & 0xffffffffL), IsMips64EL);
470 template <endianness TargetEndianness>
472 :
public Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
478 template <class ELFT>
490 Elf_Half e_phentsize;
492 Elf_Half e_shentsize;
497 bool checkMagic()
const {
505 template <endianness TargetEndianness>
532 template <class ELFT>
544 &nbucket + 2 + nbucket + nchain);
549 template <
class ELFT>
550 struct Elf_GnuHash_Impl {
564 reinterpret_cast<const Elf_Word *
>(filter().
end()), nbuckets);
568 assert(DynamicSymCount >= symndx);
575 template <endianness TargetEndianness>
580 Elf_Word ch_addralign;
587 Elf_Word ch_reserved;
589 Elf_Xword ch_addralign;
593 template <class ELFT>
607 size_t getSize()
const {
608 return sizeof(*this) + alignTo<Align>(n_namesz) + alignTo<Align>(n_descsz);
616 template <
class ELFT>
617 class Elf_Note_Impl {
620 const Elf_Nhdr_Impl<ELFT> &Nhdr;
631 return StringRef(
reinterpret_cast<const char *
>(&Nhdr) +
sizeof(Nhdr),
640 reinterpret_cast<const uint8_t *
>(&Nhdr) +
sizeof(Nhdr) +
652 Elf_Word
getType()
const {
return Nhdr.n_type; }
655 template <
class ELFT>
656 class Elf_Note_Iterator_Impl
657 : std::iterator<std::forward_iterator_tag, Elf_Note_Impl<ELFT>> {
659 const Elf_Nhdr_Impl<ELFT> *Nhdr =
nullptr;
660 size_t RemainingSize = 0u;
661 Error *Err =
nullptr;
663 template <
class ELFFileELFT>
friend class ELFFile;
666 void stopWithOverflowError() {
668 *Err = make_error<StringError>(
"ELF note overflows container",
677 void advanceNhdr(
const uint8_t *NhdrPos,
size_t NoteSize) {
678 RemainingSize -= NoteSize;
679 if (RemainingSize == 0u) {
684 }
else if (
sizeof(*Nhdr) > RemainingSize)
685 stopWithOverflowError();
687 Nhdr =
reinterpret_cast<const Elf_Nhdr_Impl<ELFT> *
>(NhdrPos + NoteSize);
688 if (Nhdr->getSize() > RemainingSize)
689 stopWithOverflowError();
695 Elf_Note_Iterator_Impl() {}
696 explicit Elf_Note_Iterator_Impl(
Error &Err) : Err(&Err) {}
697 Elf_Note_Iterator_Impl(
const uint8_t *Start,
size_t Size,
Error &Err)
698 : RemainingSize(
Size), Err(&Err) {
700 assert(Start &&
"ELF note iterator starting at NULL");
701 advanceNhdr(Start, 0u);
706 assert(Nhdr &&
"incremented ELF note end iterator");
707 const uint8_t *NhdrPos =
reinterpret_cast<const uint8_t *
>(Nhdr);
708 size_t NoteSize = Nhdr->getSize();
709 advanceNhdr(NhdrPos, NoteSize);
713 if (!Nhdr &&
Other.Err)
714 (void)(
bool)(*
Other.Err);
715 if (!
Other.Nhdr && Err)
717 return Nhdr ==
Other.Nhdr;
720 return !(*
this ==
Other);
723 assert(Nhdr &&
"dereferenced ELF note end iterator");
728 template <
class ELFT>
struct Elf_CGProfile_Impl {
732 Elf_Xword cgp_weight;
736 template <class ELFT>
743 Elf_Word ri_cprmask[4];
744 Elf_Addr ri_gp_value;
752 Elf_Word ri_cprmask[4];
753 Elf_Addr ri_gp_value;
794 #endif // LLVM_OBJECT_ELFTYPES_H
const Elf_Mips_RegInfo< ELFT > & getRegInfo() const
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
uint32_t getSymbol(bool isMips64EL) const
static StringRef getName(Value *V)
This class represents lattice values for constants.
const MCInstrDesc & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getEntityCount() const
Get the number of entities this section contains if it has any.
llvm::support::endianness endianness
void setSymbolAndType(uint32_t s, uint32_t t, bool IsMips64EL)
static const endianness TargetEndianness
unsigned char getType() const
static ErrorSuccess success()
Create a success value.
Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters.
bool isOSSpecific() const
Merge contiguous icmps into a memcmp
uint32_t getType(bool isMips64EL) const
void setRInfo(uint32_t R, bool IsMips64EL)
static const bool Is64Bits
#define LLVM_ELF_IMPORT_TYPES(E, W)
void setSymbol(uint32_t s, bool IsMips64EL)
const_iterator end(StringRef path)
Get end iterator over path.
uint64_t getValue() const
Elf_Note_Impl(const Elf_Nhdr_Impl< ELFT > &Nhdr)
Tagged union holding either a T or a Error.
static wasm::ValType getType(const TargetRegisterClass *RC)
Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef section (....
unsigned char getVisibility() const
Access to the STV_xxx flag stored in the first two bits of st_other.
void consumeError(Error Err)
Consume a Error without doing anything.
bool operator!=(Elf_Note_Iterator_Impl Other) const
void setType(unsigned char t)
void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL)
Elf_Versym: This is the structure of entries in the SHT_GNU_versym section (.gnu.version).
Expected< StringRef > getName(StringRef StrTab) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::conditional_t< ELFT::Is64Bits, int64_t, int32_t > intX_t
ArrayRef< Elf_Word > buckets() const
bitcast float %x to i32 %s=and i32 %t, 2147483647 %d=bitcast i32 %s to float ret float %d } declare float @fabsf(float %n) define float @bar(float %x) nounwind { %d=call float @fabsf(float %x) ret float %d } This IR(from PR6194):target datalayout="e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple="x86_64-apple-darwin10.0.0" %0=type { double, double } %struct.float3=type { float, float, float } define void @test(%0, %struct.float3 *nocapture %res) nounwind noinline ssp { entry:%tmp18=extractvalue %0 %0, 0 t
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int b
This struct is a compact representation of a valid (non-zero power of two) alignment.
void setBinding(unsigned char b)
bar al al movzbl eax ret Missed when stored in a memory object
multiplies can be turned into SHL s
std::conditional_t< Is64, uint64_t, uint32_t > uint
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Elf_Dyn_Base: This structure matches the form of entries in the dynamic table section (....
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed section (.gnu....
static bool isMips64EL(const ELFYAML::Object &Obj)
Elf_Note_Impl< ELFT > operator*() const
void setVisibility(unsigned char v)
void setRInfo(uint64_t R, bool IsMips64EL)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
bool operator==(Elf_Note_Iterator_Impl Other) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
uint32_t getSymbol(bool isMips64EL) const
StringRef - Represent a constant reference to a string, i.e.
ArrayRef< Elf_Word > chains() const
bool isProcessorSpecific() const
StringRef getDescAsStringRef() const
Get the note's descriptor as StringRef.
void setType(unsigned char t, bool IsMips64EL)
unsigned char getDataEncoding() const
#define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
unsigned char getBinding() const
Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section (.gnu.version_d).
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Lightweight error class with error context and mandatory checking.
Elf_Note_Iterator_Impl & operator++()
Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed section (....
ArrayRef< uint8_t > getDesc() const
Get the note's descriptor.
unsigned char getType(bool isMips64EL) const
void setType(uint32_t t, bool IsMips64EL)
ArrayRef< Elf_Word > values(unsigned DynamicSymCount) const
static const char ElfMagic[]
std::conditional_t< ELFT::Is64Bits, uint64_t, uint32_t > uintX_t
void setBindingAndType(unsigned char b, unsigned char t)
size_t size() const
size - Get the array size.
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
void setSymbol(uint32_t s, bool IsMips64EL)
LLVM_NODISCARD size_t size() const
size - Get the string size.
unsigned char getFileClass() const
StringRef getName() const
Get the note's name, excluding the terminating null byte.
Elf_Word getType() const
Get the note's type.
Optional< std::vector< StOtherPiece > > Other