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