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