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