[PGO] Fix remaining bugs in ProfData template file (when used by compiler-rt)
[oota-llvm.git] / include / llvm / Object / ELFTypes.h
1 //===- ELFTypes.h - Endian specific types for ELF ---------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_OBJECT_ELFTYPES_H
11 #define LLVM_OBJECT_ELFTYPES_H
12
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/Object/Error.h"
15 #include "llvm/Support/ELF.h"
16 #include "llvm/Support/Endian.h"
17 #include "llvm/Support/ErrorOr.h"
18
19 namespace llvm {
20 namespace object {
21
22 using support::endianness;
23
24 template <endianness target_endianness, bool is64Bits> struct ELFType {
25   static const endianness TargetEndianness = target_endianness;
26   static const bool Is64Bits = is64Bits;
27 };
28
29 typedef ELFType<support::little, false> ELF32LE;
30 typedef ELFType<support::big, false> ELF32BE;
31 typedef ELFType<support::little, true> ELF64LE;
32 typedef ELFType<support::big, true> ELF64BE;
33
34 // Use an alignment of 2 for the typedefs since that is the worst case for
35 // ELF files in archives.
36
37 // Templates to choose Elf_Addr and Elf_Off depending on is64Bits.
38 template <endianness target_endianness> struct ELFDataTypeTypedefHelperCommon {
39   typedef support::detail::packed_endian_specific_integral<
40       uint16_t, target_endianness, 2> Elf_Half;
41   typedef support::detail::packed_endian_specific_integral<
42       uint32_t, target_endianness, 2> Elf_Word;
43   typedef support::detail::packed_endian_specific_integral<
44       int32_t, target_endianness, 2> Elf_Sword;
45   typedef support::detail::packed_endian_specific_integral<
46       uint64_t, target_endianness, 2> Elf_Xword;
47   typedef support::detail::packed_endian_specific_integral<
48       int64_t, target_endianness, 2> Elf_Sxword;
49 };
50
51 template <class ELFT> struct ELFDataTypeTypedefHelper;
52
53 /// ELF 32bit types.
54 template <endianness TargetEndianness>
55 struct ELFDataTypeTypedefHelper<ELFType<TargetEndianness, false>>
56     : ELFDataTypeTypedefHelperCommon<TargetEndianness> {
57   typedef uint32_t value_type;
58   typedef support::detail::packed_endian_specific_integral<
59       value_type, TargetEndianness, 2> Elf_Addr;
60   typedef support::detail::packed_endian_specific_integral<
61       value_type, TargetEndianness, 2> Elf_Off;
62 };
63
64 /// ELF 64bit types.
65 template <endianness TargetEndianness>
66 struct ELFDataTypeTypedefHelper<ELFType<TargetEndianness, true>>
67     : ELFDataTypeTypedefHelperCommon<TargetEndianness> {
68   typedef uint64_t value_type;
69   typedef support::detail::packed_endian_specific_integral<
70       value_type, TargetEndianness, 2> Elf_Addr;
71   typedef support::detail::packed_endian_specific_integral<
72       value_type, TargetEndianness, 2> Elf_Off;
73 };
74
75 // I really don't like doing this, but the alternative is copypasta.
76 #define LLVM_ELF_IMPORT_TYPES(E, W)                                            \
77   typedef typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Addr Elf_Addr; \
78   typedef typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Off Elf_Off;   \
79   typedef typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Half Elf_Half; \
80   typedef typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Word Elf_Word; \
81   typedef                                                                      \
82       typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Sword Elf_Sword;   \
83   typedef                                                                      \
84       typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Xword Elf_Xword;   \
85   typedef                                                                      \
86       typename ELFDataTypeTypedefHelper<ELFType<E, W>>::Elf_Sxword Elf_Sxword;
87
88 #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)                                       \
89   LLVM_ELF_IMPORT_TYPES(ELFT::TargetEndianness, ELFT::Is64Bits)
90
91 // Section header.
92 template <class ELFT> struct Elf_Shdr_Base;
93
94 template <endianness TargetEndianness>
95 struct Elf_Shdr_Base<ELFType<TargetEndianness, false>> {
96   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
97   Elf_Word sh_name;      // Section name (index into string table)
98   Elf_Word sh_type;      // Section type (SHT_*)
99   Elf_Word sh_flags;     // Section flags (SHF_*)
100   Elf_Addr sh_addr;      // Address where section is to be loaded
101   Elf_Off sh_offset;     // File offset of section data, in bytes
102   Elf_Word sh_size;      // Size of section, in bytes
103   Elf_Word sh_link;      // Section type-specific header table index link
104   Elf_Word sh_info;      // Section type-specific extra information
105   Elf_Word sh_addralign; // Section address alignment
106   Elf_Word sh_entsize;   // Size of records contained within the section
107 };
108
109 template <endianness TargetEndianness>
110 struct Elf_Shdr_Base<ELFType<TargetEndianness, true>> {
111   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
112   Elf_Word sh_name;       // Section name (index into string table)
113   Elf_Word sh_type;       // Section type (SHT_*)
114   Elf_Xword sh_flags;     // Section flags (SHF_*)
115   Elf_Addr sh_addr;       // Address where section is to be loaded
116   Elf_Off sh_offset;      // File offset of section data, in bytes
117   Elf_Xword sh_size;      // Size of section, in bytes
118   Elf_Word sh_link;       // Section type-specific header table index link
119   Elf_Word sh_info;       // Section type-specific extra information
120   Elf_Xword sh_addralign; // Section address alignment
121   Elf_Xword sh_entsize;   // Size of records contained within the section
122 };
123
124 template <class ELFT>
125 struct Elf_Shdr_Impl : Elf_Shdr_Base<ELFT> {
126   using Elf_Shdr_Base<ELFT>::sh_entsize;
127   using Elf_Shdr_Base<ELFT>::sh_size;
128
129   /// @brief Get the number of entities this section contains if it has any.
130   unsigned getEntityCount() const {
131     if (sh_entsize == 0)
132       return 0;
133     return sh_size / sh_entsize;
134   }
135 };
136
137 template <class ELFT> struct Elf_Sym_Base;
138
139 template <endianness TargetEndianness>
140 struct Elf_Sym_Base<ELFType<TargetEndianness, false>> {
141   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
142   Elf_Word st_name;       // Symbol name (index into string table)
143   Elf_Addr st_value;      // Value or address associated with the symbol
144   Elf_Word st_size;       // Size of the symbol
145   unsigned char st_info;  // Symbol's type and binding attributes
146   unsigned char st_other; // Must be zero; reserved
147   Elf_Half st_shndx;      // Which section (header table index) it's defined in
148 };
149
150 template <endianness TargetEndianness>
151 struct Elf_Sym_Base<ELFType<TargetEndianness, true>> {
152   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
153   Elf_Word st_name;       // Symbol name (index into string table)
154   unsigned char st_info;  // Symbol's type and binding attributes
155   unsigned char st_other; // Must be zero; reserved
156   Elf_Half st_shndx;      // Which section (header table index) it's defined in
157   Elf_Addr st_value;      // Value or address associated with the symbol
158   Elf_Xword st_size;      // Size of the symbol
159 };
160
161 template <class ELFT>
162 struct Elf_Sym_Impl : Elf_Sym_Base<ELFT> {
163   using Elf_Sym_Base<ELFT>::st_info;
164   using Elf_Sym_Base<ELFT>::st_shndx;
165   using Elf_Sym_Base<ELFT>::st_other;
166   using Elf_Sym_Base<ELFT>::st_value;
167
168   // These accessors and mutators correspond to the ELF32_ST_BIND,
169   // ELF32_ST_TYPE, and ELF32_ST_INFO macros defined in the ELF specification:
170   unsigned char getBinding() const { return st_info >> 4; }
171   unsigned char getType() const { return st_info & 0x0f; }
172   uint64_t getValue() const { return st_value; }
173   void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
174   void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
175   void setBindingAndType(unsigned char b, unsigned char t) {
176     st_info = (b << 4) + (t & 0x0f);
177   }
178
179   /// Access to the STV_xxx flag stored in the first two bits of st_other.
180   /// STV_DEFAULT: 0
181   /// STV_INTERNAL: 1
182   /// STV_HIDDEN: 2
183   /// STV_PROTECTED: 3
184   unsigned char getVisibility() const { return st_other & 0x3; }
185   void setVisibility(unsigned char v) {
186     assert(v < 4 && "Invalid value for visibility");
187     st_other = (st_other & ~0x3) | v;
188   }
189
190   bool isAbsolute() const { return st_shndx == ELF::SHN_ABS; }
191   bool isCommon() const {
192     return getType() == ELF::STT_COMMON || st_shndx == ELF::SHN_COMMON;
193   }
194   bool isDefined() const { return !isUndefined(); }
195   bool isProcessorSpecific() const {
196     return st_shndx >= ELF::SHN_LOPROC && st_shndx <= ELF::SHN_HIPROC;
197   }
198   bool isOSSpecific() const {
199     return st_shndx >= ELF::SHN_LOOS && st_shndx <= ELF::SHN_HIOS;
200   }
201   bool isReserved() const {
202     // ELF::SHN_HIRESERVE is 0xffff so st_shndx <= ELF::SHN_HIRESERVE is always
203     // true and some compilers warn about it.
204     return st_shndx >= ELF::SHN_LORESERVE;
205   }
206   bool isUndefined() const { return st_shndx == ELF::SHN_UNDEF; }
207   bool isExternal() const {
208     return getBinding() != ELF::STB_LOCAL;
209   }
210
211   ErrorOr<StringRef> getName(StringRef StrTab) const;
212 };
213
214 template <class ELFT>
215 ErrorOr<StringRef> Elf_Sym_Impl<ELFT>::getName(StringRef StrTab) const {
216   uint32_t Offset = this->st_name;
217   if (Offset >= StrTab.size())
218     return object_error::parse_failed;
219   return StringRef(StrTab.data() + Offset);
220 }
221
222 /// Elf_Versym: This is the structure of entries in the SHT_GNU_versym section
223 /// (.gnu.version). This structure is identical for ELF32 and ELF64.
224 template <class ELFT>
225 struct Elf_Versym_Impl {
226   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
227   Elf_Half vs_index; // Version index with flags (e.g. VERSYM_HIDDEN)
228 };
229
230 template <class ELFT> struct Elf_Verdaux_Impl;
231
232 /// Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section
233 /// (.gnu.version_d). This structure is identical for ELF32 and ELF64.
234 template <class ELFT>
235 struct Elf_Verdef_Impl {
236   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
237   typedef Elf_Verdaux_Impl<ELFT> Elf_Verdaux;
238   Elf_Half vd_version; // Version of this structure (e.g. VER_DEF_CURRENT)
239   Elf_Half vd_flags;   // Bitwise flags (VER_DEF_*)
240   Elf_Half vd_ndx;     // Version index, used in .gnu.version entries
241   Elf_Half vd_cnt;     // Number of Verdaux entries
242   Elf_Word vd_hash;    // Hash of name
243   Elf_Word vd_aux;     // Offset to the first Verdaux entry (in bytes)
244   Elf_Word vd_next;    // Offset to the next Verdef entry (in bytes)
245
246   /// Get the first Verdaux entry for this Verdef.
247   const Elf_Verdaux *getAux() const {
248     return reinterpret_cast<const Elf_Verdaux *>((const char *)this + vd_aux);
249   }
250 };
251
252 /// Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef
253 /// section (.gnu.version_d). This structure is identical for ELF32 and ELF64.
254 template <class ELFT>
255 struct Elf_Verdaux_Impl {
256   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
257   Elf_Word vda_name; // Version name (offset in string table)
258   Elf_Word vda_next; // Offset to next Verdaux entry (in bytes)
259 };
260
261 /// Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed
262 /// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
263 template <class ELFT>
264 struct Elf_Verneed_Impl {
265   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
266   Elf_Half vn_version; // Version of this structure (e.g. VER_NEED_CURRENT)
267   Elf_Half vn_cnt;     // Number of associated Vernaux entries
268   Elf_Word vn_file;    // Library name (string table offset)
269   Elf_Word vn_aux;     // Offset to first Vernaux entry (in bytes)
270   Elf_Word vn_next;    // Offset to next Verneed entry (in bytes)
271 };
272
273 /// Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed
274 /// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
275 template <class ELFT>
276 struct Elf_Vernaux_Impl {
277   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
278   Elf_Word vna_hash;  // Hash of dependency name
279   Elf_Half vna_flags; // Bitwise Flags (VER_FLAG_*)
280   Elf_Half vna_other; // Version index, used in .gnu.version entries
281   Elf_Word vna_name;  // Dependency name
282   Elf_Word vna_next;  // Offset to next Vernaux entry (in bytes)
283 };
284
285 /// Elf_Dyn_Base: This structure matches the form of entries in the dynamic
286 ///               table section (.dynamic) look like.
287 template <class ELFT> struct Elf_Dyn_Base;
288
289 template <endianness TargetEndianness>
290 struct Elf_Dyn_Base<ELFType<TargetEndianness, false>> {
291   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
292   Elf_Sword d_tag;
293   union {
294     Elf_Word d_val;
295     Elf_Addr d_ptr;
296   } d_un;
297 };
298
299 template <endianness TargetEndianness>
300 struct Elf_Dyn_Base<ELFType<TargetEndianness, true>> {
301   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
302   Elf_Sxword d_tag;
303   union {
304     Elf_Xword d_val;
305     Elf_Addr d_ptr;
306   } d_un;
307 };
308
309 /// Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters.
310 template <class ELFT>
311 struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {
312   using Elf_Dyn_Base<ELFT>::d_tag;
313   using Elf_Dyn_Base<ELFT>::d_un;
314   typedef typename std::conditional<ELFT::Is64Bits,
315                                     int64_t, int32_t>::type intX_t;
316   typedef typename std::conditional<ELFT::Is64Bits,
317                                     uint64_t, uint32_t>::type uintX_t;
318   intX_t getTag() const { return d_tag; }
319   uintX_t getVal() const { return d_un.d_val; }
320   uintX_t getPtr() const { return d_un.d_ptr; }
321 };
322
323 // Elf_Rel: Elf Relocation
324 template <class ELFT, bool isRela> struct Elf_Rel_Impl;
325
326 template <endianness TargetEndianness>
327 struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
328   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
329   Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
330   Elf_Word r_info;   // Symbol table index and type of relocation to apply
331
332   uint32_t getRInfo(bool isMips64EL) const {
333     assert(!isMips64EL);
334     return r_info;
335   }
336   void setRInfo(uint32_t R, bool IsMips64EL) {
337     assert(!IsMips64EL);
338     r_info = R;
339   }
340
341   // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
342   // and ELF32_R_INFO macros defined in the ELF specification:
343   uint32_t getSymbol(bool isMips64EL) const {
344     return this->getRInfo(isMips64EL) >> 8;
345   }
346   unsigned char getType(bool isMips64EL) const {
347     return (unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
348   }
349   void setSymbol(uint32_t s, bool IsMips64EL) {
350     setSymbolAndType(s, getType(), IsMips64EL);
351   }
352   void setType(unsigned char t, bool IsMips64EL) {
353     setSymbolAndType(getSymbol(), t, IsMips64EL);
354   }
355   void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL) {
356     this->setRInfo((s << 8) + t, IsMips64EL);
357   }
358 };
359
360 template <endianness TargetEndianness>
361 struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, true>
362     : public Elf_Rel_Impl<ELFType<TargetEndianness, false>, false> {
363   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
364   Elf_Sword r_addend; // Compute value for relocatable field by adding this
365 };
366
367 template <endianness TargetEndianness>
368 struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
369   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
370   Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
371   Elf_Xword r_info;  // Symbol table index and type of relocation to apply
372
373   uint64_t getRInfo(bool isMips64EL) const {
374     uint64_t t = r_info;
375     if (!isMips64EL)
376       return t;
377     // Mips64 little endian has a "special" encoding of r_info. Instead of one
378     // 64 bit little endian number, it is a little endian 32 bit number followed
379     // by a 32 bit big endian number.
380     return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
381            ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
382   }
383   void setRInfo(uint64_t R, bool IsMips64EL) {
384     if (IsMips64EL)
385       r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
386                ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
387     else
388       r_info = R;
389   }
390
391   // These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
392   // and ELF64_R_INFO macros defined in the ELF specification:
393   uint32_t getSymbol(bool isMips64EL) const {
394     return (uint32_t)(this->getRInfo(isMips64EL) >> 32);
395   }
396   uint32_t getType(bool isMips64EL) const {
397     return (uint32_t)(this->getRInfo(isMips64EL) & 0xffffffffL);
398   }
399   void setSymbol(uint32_t s, bool IsMips64EL) {
400     setSymbolAndType(s, getType(), IsMips64EL);
401   }
402   void setType(uint32_t t, bool IsMips64EL) {
403     setSymbolAndType(getSymbol(), t, IsMips64EL);
404   }
405   void setSymbolAndType(uint32_t s, uint32_t t, bool IsMips64EL) {
406     this->setRInfo(((uint64_t)s << 32) + (t & 0xffffffffL), IsMips64EL);
407   }
408 };
409
410 template <endianness TargetEndianness>
411 struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, true>
412     : public Elf_Rel_Impl<ELFType<TargetEndianness, true>, false> {
413   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
414   Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
415 };
416
417 template <class ELFT>
418 struct Elf_Ehdr_Impl {
419   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
420   unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
421   Elf_Half e_type;                       // Type of file (see ET_*)
422   Elf_Half e_machine;   // Required architecture for this file (see EM_*)
423   Elf_Word e_version;   // Must be equal to 1
424   Elf_Addr e_entry;     // Address to jump to in order to start program
425   Elf_Off e_phoff;      // Program header table's file offset, in bytes
426   Elf_Off e_shoff;      // Section header table's file offset, in bytes
427   Elf_Word e_flags;     // Processor-specific flags
428   Elf_Half e_ehsize;    // Size of ELF header, in bytes
429   Elf_Half e_phentsize; // Size of an entry in the program header table
430   Elf_Half e_phnum;     // Number of entries in the program header table
431   Elf_Half e_shentsize; // Size of an entry in the section header table
432   Elf_Half e_shnum;     // Number of entries in the section header table
433   Elf_Half e_shstrndx;  // Section header table index of section name
434                         // string table
435   bool checkMagic() const {
436     return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
437   }
438   unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; }
439   unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
440 };
441
442 template <class ELFT> struct Elf_Phdr_Impl;
443
444 template <endianness TargetEndianness>
445 struct Elf_Phdr_Impl<ELFType<TargetEndianness, false>> {
446   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
447   Elf_Word p_type;   // Type of segment
448   Elf_Off p_offset;  // FileOffset where segment is located, in bytes
449   Elf_Addr p_vaddr;  // Virtual Address of beginning of segment
450   Elf_Addr p_paddr;  // Physical address of beginning of segment (OS-specific)
451   Elf_Word p_filesz; // Num. of bytes in file image of segment (may be zero)
452   Elf_Word p_memsz;  // Num. of bytes in mem image of segment (may be zero)
453   Elf_Word p_flags;  // Segment flags
454   Elf_Word p_align;  // Segment alignment constraint
455 };
456
457 template <endianness TargetEndianness>
458 struct Elf_Phdr_Impl<ELFType<TargetEndianness, true>> {
459   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
460   Elf_Word p_type;    // Type of segment
461   Elf_Word p_flags;   // Segment flags
462   Elf_Off p_offset;   // FileOffset where segment is located, in bytes
463   Elf_Addr p_vaddr;   // Virtual Address of beginning of segment
464   Elf_Addr p_paddr;   // Physical address of beginning of segment (OS-specific)
465   Elf_Xword p_filesz; // Num. of bytes in file image of segment (may be zero)
466   Elf_Xword p_memsz;  // Num. of bytes in mem image of segment (may be zero)
467   Elf_Xword p_align;  // Segment alignment constraint
468 };
469
470 // ELFT needed for endianess.
471 template <class ELFT>
472 struct Elf_Hash_Impl {
473   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
474   Elf_Word nbucket;
475   Elf_Word nchain;
476
477   ArrayRef<Elf_Word> buckets() const {
478     return ArrayRef<Elf_Word>(&nbucket + 2, &nbucket + 2 + nbucket);
479   }
480
481   ArrayRef<Elf_Word> chains() const {
482     return ArrayRef<Elf_Word>(&nbucket + 2 + nbucket,
483                               &nbucket + 2 + nbucket + nchain);
484   }
485 };
486
487 // .gnu.hash section
488 template <class ELFT>
489 struct Elf_GnuHash_Impl {
490   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
491   Elf_Word nbuckets;
492   Elf_Word symndx;
493   Elf_Word maskwords;
494   Elf_Word shift2;
495
496   ArrayRef<Elf_Off> filter() const {
497     return ArrayRef<Elf_Off>(reinterpret_cast<const Elf_Off *>(&shift2 + 1),
498                              maskwords);
499   }
500
501   ArrayRef<Elf_Word> buckets() const {
502     return ArrayRef<Elf_Word>(
503         reinterpret_cast<const Elf_Word *>(filter().end()), nbuckets);
504   }
505
506   ArrayRef<Elf_Word> values(unsigned DynamicSymCount) const {
507     return ArrayRef<Elf_Word>(buckets().end(), DynamicSymCount - symndx);
508   }
509 };
510
511 // MIPS .reginfo section
512 template <class ELFT>
513 struct Elf_Mips_RegInfo;
514
515 template <llvm::support::endianness TargetEndianness>
516 struct Elf_Mips_RegInfo<ELFType<TargetEndianness, false>> {
517   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
518   Elf_Word ri_gprmask;     // bit-mask of used general registers
519   Elf_Word ri_cprmask[4];  // bit-mask of used co-processor registers
520   Elf_Addr ri_gp_value;    // gp register value
521 };
522
523 template <llvm::support::endianness TargetEndianness>
524 struct Elf_Mips_RegInfo<ELFType<TargetEndianness, true>> {
525   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
526   Elf_Word ri_gprmask;     // bit-mask of used general registers
527   Elf_Word ri_pad;         // unused padding field
528   Elf_Word ri_cprmask[4];  // bit-mask of used co-processor registers
529   Elf_Addr ri_gp_value;    // gp register value
530 };
531
532 // .MIPS.options section
533 template <class ELFT> struct Elf_Mips_Options {
534   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
535   uint8_t kind;     // Determines interpretation of variable part of descriptor
536   uint8_t size;     // Byte size of descriptor, including this header
537   Elf_Half section; // Section header index of section affected,
538                     // or 0 for global options
539   Elf_Word info;    // Kind-specific information
540
541   const Elf_Mips_RegInfo<ELFT> &getRegInfo() const {
542     assert(kind == llvm::ELF::ODK_REGINFO);
543     return *reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(
544                (const uint8_t *)this + sizeof(Elf_Mips_Options));
545   }
546 };
547
548 // .MIPS.abiflags section content
549 template <class ELFT> struct Elf_Mips_ABIFlags {
550   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
551   Elf_Half version;  // Version of the structure
552   uint8_t isa_level; // ISA level: 1-5, 32, and 64
553   uint8_t isa_rev;   // ISA revision (0 for MIPS I - MIPS V)
554   uint8_t gpr_size;  // General purpose registers size
555   uint8_t cpr1_size; // Co-processor 1 registers size
556   uint8_t cpr2_size; // Co-processor 2 registers size
557   uint8_t fp_abi;    // Floating-point ABI flag
558   Elf_Word isa_ext;  // Processor-specific extension
559   Elf_Word ases;     // ASEs flags
560   Elf_Word flags1;   // General flags
561   Elf_Word flags2;   // General flags
562 };
563
564 } // end namespace object.
565 } // end namespace llvm.
566
567 #endif