[Object/ELF] Provide helpers for symbol types.
[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
160   // These accessors and mutators correspond to the ELF32_ST_BIND,
161   // ELF32_ST_TYPE, and ELF32_ST_INFO macros defined in the ELF specification:
162   unsigned char getBinding() const { return st_info >> 4; }
163   unsigned char getType() const { return st_info & 0x0f; }
164   void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
165   void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
166   void setBindingAndType(unsigned char b, unsigned char t) {
167     st_info = (b << 4) + (t & 0x0f);
168   }
169
170   /// Access to the STV_xxx flag stored in the first two bits of st_other.
171   /// STV_DEFAULT: 0
172   /// STV_INTERNAL: 1
173   /// STV_HIDDEN: 2
174   /// STV_PROTECTED: 3
175   unsigned char getVisibility() const { return st_other & 0x3; }
176   void setVisibility(unsigned char v) {
177     assert(v < 4 && "Invalid value for visibility");
178     st_other = (st_other & ~0x3) | v;
179   }
180
181   bool isAbsolute() const { return st_shndx == ELF::SHN_ABS; }
182   bool isCommon() const {
183     return !isUndefined() &&
184            !(st_shndx >= ELF::SHN_LORESERVE && st_shndx < ELF::SHN_ABS);
185   }
186   bool isDefined() const {
187     return !isUndefined() &&
188            (!(st_shndx >= ELF::SHN_LORESERVE &&
189               st_shndx <= ELF::SHN_HIRESERVE) ||
190             st_shndx == ELF::SHN_XINDEX);
191   }
192   bool isProcessorSpecific() const {
193     return st_shndx >= ELF::SHN_LOPROC && st_shndx <= ELF::SHN_HIPROC;
194   }
195   bool isOSSpecific() const {
196     return st_shndx >= ELF::SHN_LOOS && st_shndx <= ELF::SHN_HIOS;
197   }
198   bool isReserved() const {
199     return st_shndx > ELF::SHN_HIOS && st_shndx < ELF::SHN_ABS;
200   }
201   bool isUndefined() const { return st_shndx == ELF::SHN_UNDEF; }
202 };
203
204 /// Elf_Versym: This is the structure of entries in the SHT_GNU_versym section
205 /// (.gnu.version). This structure is identical for ELF32 and ELF64.
206 template <class ELFT>
207 struct Elf_Versym_Impl {
208   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
209   Elf_Half vs_index; // Version index with flags (e.g. VERSYM_HIDDEN)
210 };
211
212 template <class ELFT> struct Elf_Verdaux_Impl;
213
214 /// Elf_Verdef: This is the structure of entries in the SHT_GNU_verdef section
215 /// (.gnu.version_d). This structure is identical for ELF32 and ELF64.
216 template <class ELFT>
217 struct Elf_Verdef_Impl {
218   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
219   typedef Elf_Verdaux_Impl<ELFT> Elf_Verdaux;
220   Elf_Half vd_version; // Version of this structure (e.g. VER_DEF_CURRENT)
221   Elf_Half vd_flags;   // Bitwise flags (VER_DEF_*)
222   Elf_Half vd_ndx;     // Version index, used in .gnu.version entries
223   Elf_Half vd_cnt;     // Number of Verdaux entries
224   Elf_Word vd_hash;    // Hash of name
225   Elf_Word vd_aux;     // Offset to the first Verdaux entry (in bytes)
226   Elf_Word vd_next;    // Offset to the next Verdef entry (in bytes)
227
228   /// Get the first Verdaux entry for this Verdef.
229   const Elf_Verdaux *getAux() const {
230     return reinterpret_cast<const Elf_Verdaux *>((const char *)this + vd_aux);
231   }
232 };
233
234 /// Elf_Verdaux: This is the structure of auxiliary data in the SHT_GNU_verdef
235 /// section (.gnu.version_d). This structure is identical for ELF32 and ELF64.
236 template <class ELFT>
237 struct Elf_Verdaux_Impl {
238   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
239   Elf_Word vda_name; // Version name (offset in string table)
240   Elf_Word vda_next; // Offset to next Verdaux entry (in bytes)
241 };
242
243 /// Elf_Verneed: This is the structure of entries in the SHT_GNU_verneed
244 /// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
245 template <class ELFT>
246 struct Elf_Verneed_Impl {
247   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
248   Elf_Half vn_version; // Version of this structure (e.g. VER_NEED_CURRENT)
249   Elf_Half vn_cnt;     // Number of associated Vernaux entries
250   Elf_Word vn_file;    // Library name (string table offset)
251   Elf_Word vn_aux;     // Offset to first Vernaux entry (in bytes)
252   Elf_Word vn_next;    // Offset to next Verneed entry (in bytes)
253 };
254
255 /// Elf_Vernaux: This is the structure of auxiliary data in SHT_GNU_verneed
256 /// section (.gnu.version_r). This structure is identical for ELF32 and ELF64.
257 template <class ELFT>
258 struct Elf_Vernaux_Impl {
259   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
260   Elf_Word vna_hash;  // Hash of dependency name
261   Elf_Half vna_flags; // Bitwise Flags (VER_FLAG_*)
262   Elf_Half vna_other; // Version index, used in .gnu.version entries
263   Elf_Word vna_name;  // Dependency name
264   Elf_Word vna_next;  // Offset to next Vernaux entry (in bytes)
265 };
266
267 /// Elf_Dyn_Base: This structure matches the form of entries in the dynamic
268 ///               table section (.dynamic) look like.
269 template <class ELFT> struct Elf_Dyn_Base;
270
271 template <endianness TargetEndianness>
272 struct Elf_Dyn_Base<ELFType<TargetEndianness, false>> {
273   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
274   Elf_Sword d_tag;
275   union {
276     Elf_Word d_val;
277     Elf_Addr d_ptr;
278   } d_un;
279 };
280
281 template <endianness TargetEndianness>
282 struct Elf_Dyn_Base<ELFType<TargetEndianness, true>> {
283   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
284   Elf_Sxword d_tag;
285   union {
286     Elf_Xword d_val;
287     Elf_Addr d_ptr;
288   } d_un;
289 };
290
291 /// Elf_Dyn_Impl: This inherits from Elf_Dyn_Base, adding getters and setters.
292 template <class ELFT>
293 struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {
294   using Elf_Dyn_Base<ELFT>::d_tag;
295   using Elf_Dyn_Base<ELFT>::d_un;
296   int64_t getTag() const { return d_tag; }
297   uint64_t getVal() const { return d_un.d_val; }
298   uint64_t getPtr() const { return d_un.ptr; }
299 };
300
301 // Elf_Rel: Elf Relocation
302 template <class ELFT, bool isRela> struct Elf_Rel_Base;
303
304 template <endianness TargetEndianness>
305 struct Elf_Rel_Base<ELFType<TargetEndianness, false>, false> {
306   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
307   Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
308   Elf_Word r_info;   // Symbol table index and type of relocation to apply
309
310   uint32_t getRInfo(bool isMips64EL) const {
311     assert(!isMips64EL);
312     return r_info;
313   }
314   void setRInfo(uint32_t R, bool IsMips64EL) {
315     assert(!IsMips64EL);
316     r_info = R;
317   }
318 };
319
320 template <endianness TargetEndianness>
321 struct Elf_Rel_Base<ELFType<TargetEndianness, true>, false> {
322   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
323   Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
324   Elf_Xword r_info;  // Symbol table index and type of relocation to apply
325
326   uint64_t getRInfo(bool isMips64EL) const {
327     uint64_t t = r_info;
328     if (!isMips64EL)
329       return t;
330     // Mips64 little endian has a "special" encoding of r_info. Instead of one
331     // 64 bit little endian number, it is a little endian 32 bit number followed
332     // by a 32 bit big endian number.
333     return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
334            ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
335   }
336   void setRInfo(uint64_t R, bool IsMips64EL) {
337     if (IsMips64EL)
338       r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
339                ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
340     else
341       r_info = R;
342   }
343 };
344
345 template <endianness TargetEndianness>
346 struct Elf_Rel_Base<ELFType<TargetEndianness, false>, true> {
347   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
348   Elf_Addr r_offset;  // Location (file byte offset, or program virtual addr)
349   Elf_Word r_info;    // Symbol table index and type of relocation to apply
350   Elf_Sword r_addend; // Compute value for relocatable field by adding this
351
352   uint32_t getRInfo(bool isMips64EL) const {
353     assert(!isMips64EL);
354     return r_info;
355   }
356   void setRInfo(uint32_t R, bool IsMips64EL) {
357     assert(!IsMips64EL);
358     r_info = R;
359   }
360 };
361
362 template <endianness TargetEndianness>
363 struct Elf_Rel_Base<ELFType<TargetEndianness, true>, true> {
364   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
365   Elf_Addr r_offset;   // Location (file byte offset, or program virtual addr)
366   Elf_Xword r_info;    // Symbol table index and type of relocation to apply
367   Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
368
369   uint64_t getRInfo(bool isMips64EL) const {
370     // Mips64 little endian has a "special" encoding of r_info. Instead of one
371     // 64 bit little endian number, it is a little endian 32 bit number followed
372     // by a 32 bit big endian number.
373     uint64_t t = r_info;
374     if (!isMips64EL)
375       return t;
376     return (t << 32) | ((t >> 8) & 0xff000000) | ((t >> 24) & 0x00ff0000) |
377            ((t >> 40) & 0x0000ff00) | ((t >> 56) & 0x000000ff);
378   }
379   void setRInfo(uint64_t R, bool IsMips64EL) {
380     if (IsMips64EL)
381       r_info = (R >> 32) | ((R & 0xff000000) << 8) | ((R & 0x00ff0000) << 24) |
382                ((R & 0x0000ff00) << 40) | ((R & 0x000000ff) << 56);
383     else
384       r_info = R;
385   }
386 };
387
388 template <class ELFT, bool isRela> struct Elf_Rel_Impl;
389
390 template <endianness TargetEndianness, bool isRela>
391 struct Elf_Rel_Impl<ELFType<TargetEndianness, true>, isRela>
392     : Elf_Rel_Base<ELFType<TargetEndianness, true>, isRela> {
393   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
394
395   // These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
396   // and ELF64_R_INFO macros defined in the ELF specification:
397   uint32_t getSymbol(bool isMips64EL) const {
398     return (uint32_t)(this->getRInfo(isMips64EL) >> 32);
399   }
400   uint32_t getType(bool isMips64EL) const {
401     return (uint32_t)(this->getRInfo(isMips64EL) & 0xffffffffL);
402   }
403   void setSymbol(uint32_t s, bool IsMips64EL) {
404     setSymbolAndType(s, getType(), IsMips64EL);
405   }
406   void setType(uint32_t t, bool IsMips64EL) {
407     setSymbolAndType(getSymbol(), t, IsMips64EL);
408   }
409   void setSymbolAndType(uint32_t s, uint32_t t, bool IsMips64EL) {
410     this->setRInfo(((uint64_t)s << 32) + (t & 0xffffffffL), IsMips64EL);
411   }
412 };
413
414 template <endianness TargetEndianness, bool isRela>
415 struct Elf_Rel_Impl<ELFType<TargetEndianness, false>, isRela>
416     : Elf_Rel_Base<ELFType<TargetEndianness, false>, isRela> {
417   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
418
419   // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
420   // and ELF32_R_INFO macros defined in the ELF specification:
421   uint32_t getSymbol(bool isMips64EL) const {
422     return this->getRInfo(isMips64EL) >> 8;
423   }
424   unsigned char getType(bool isMips64EL) const {
425     return (unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
426   }
427   void setSymbol(uint32_t s, bool IsMips64EL) {
428     setSymbolAndType(s, getType(), IsMips64EL);
429   }
430   void setType(unsigned char t, bool IsMips64EL) {
431     setSymbolAndType(getSymbol(), t, IsMips64EL);
432   }
433   void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL) {
434     this->setRInfo((s << 8) + t, IsMips64EL);
435   }
436 };
437
438 template <class ELFT>
439 struct Elf_Ehdr_Impl {
440   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
441   unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
442   Elf_Half e_type;                       // Type of file (see ET_*)
443   Elf_Half e_machine;   // Required architecture for this file (see EM_*)
444   Elf_Word e_version;   // Must be equal to 1
445   Elf_Addr e_entry;     // Address to jump to in order to start program
446   Elf_Off e_phoff;      // Program header table's file offset, in bytes
447   Elf_Off e_shoff;      // Section header table's file offset, in bytes
448   Elf_Word e_flags;     // Processor-specific flags
449   Elf_Half e_ehsize;    // Size of ELF header, in bytes
450   Elf_Half e_phentsize; // Size of an entry in the program header table
451   Elf_Half e_phnum;     // Number of entries in the program header table
452   Elf_Half e_shentsize; // Size of an entry in the section header table
453   Elf_Half e_shnum;     // Number of entries in the section header table
454   Elf_Half e_shstrndx;  // Section header table index of section name
455                         // string table
456   bool checkMagic() const {
457     return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
458   }
459   unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; }
460   unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
461 };
462
463 template <class ELFT> struct Elf_Phdr_Impl;
464
465 template <endianness TargetEndianness>
466 struct Elf_Phdr_Impl<ELFType<TargetEndianness, false>> {
467   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
468   Elf_Word p_type;   // Type of segment
469   Elf_Off p_offset;  // FileOffset where segment is located, in bytes
470   Elf_Addr p_vaddr;  // Virtual Address of beginning of segment
471   Elf_Addr p_paddr;  // Physical address of beginning of segment (OS-specific)
472   Elf_Word p_filesz; // Num. of bytes in file image of segment (may be zero)
473   Elf_Word p_memsz;  // Num. of bytes in mem image of segment (may be zero)
474   Elf_Word p_flags;  // Segment flags
475   Elf_Word p_align;  // Segment alignment constraint
476 };
477
478 template <endianness TargetEndianness>
479 struct Elf_Phdr_Impl<ELFType<TargetEndianness, true>> {
480   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
481   Elf_Word p_type;    // Type of segment
482   Elf_Word p_flags;   // Segment flags
483   Elf_Off p_offset;   // FileOffset where segment is located, in bytes
484   Elf_Addr p_vaddr;   // Virtual Address of beginning of segment
485   Elf_Addr p_paddr;   // Physical address of beginning of segment (OS-specific)
486   Elf_Xword p_filesz; // Num. of bytes in file image of segment (may be zero)
487   Elf_Xword p_memsz;  // Num. of bytes in mem image of segment (may be zero)
488   Elf_Xword p_align;  // Segment alignment constraint
489 };
490
491 // MIPS .reginfo section
492 template <class ELFT>
493 struct Elf_Mips_RegInfo;
494
495 template <llvm::support::endianness TargetEndianness>
496 struct Elf_Mips_RegInfo<ELFType<TargetEndianness, false>> {
497   LLVM_ELF_IMPORT_TYPES(TargetEndianness, false)
498   Elf_Word ri_gprmask;     // bit-mask of used general registers
499   Elf_Word ri_cprmask[4];  // bit-mask of used co-processor registers
500   Elf_Addr ri_gp_value;    // gp register value
501 };
502
503 template <llvm::support::endianness TargetEndianness>
504 struct Elf_Mips_RegInfo<ELFType<TargetEndianness, true>> {
505   LLVM_ELF_IMPORT_TYPES(TargetEndianness, true)
506   Elf_Word ri_gprmask;     // bit-mask of used general registers
507   Elf_Word ri_pad;         // unused padding field
508   Elf_Word ri_cprmask[4];  // bit-mask of used co-processor registers
509   Elf_Addr ri_gp_value;    // gp register value
510 };
511
512 // .MIPS.options section
513 template <class ELFT> struct Elf_Mips_Options {
514   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
515   uint8_t kind;     // Determines interpretation of variable part of descriptor
516   uint8_t size;     // Byte size of descriptor, including this header
517   Elf_Half section; // Section header index of section affected,
518                     // or 0 for global options
519   Elf_Word info;    // Kind-specific information
520
521   const Elf_Mips_RegInfo<ELFT> &getRegInfo() const {
522     assert(kind == llvm::ELF::ODK_REGINFO);
523     return *reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(
524                (const uint8_t *)this + sizeof(Elf_Mips_Options));
525   }
526 };
527
528 // .MIPS.abiflags section content
529 template <class ELFT> struct Elf_Mips_ABIFlags {
530   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
531   Elf_Half version;  // Version of the structure
532   uint8_t isa_level; // ISA level: 1-5, 32, and 64
533   uint8_t isa_rev;   // ISA revision (0 for MIPS I - MIPS V)
534   uint8_t gpr_size;  // General purpose registers size
535   uint8_t cpr1_size; // Co-processor 1 registers size
536   uint8_t cpr2_size; // Co-processor 2 registers size
537   uint8_t fp_abi;    // Floating-point ABI flag
538   Elf_Word isa_ext;  // Processor-specific extension
539   Elf_Word ases;     // ASEs flags
540   Elf_Word flags1;   // General flags
541   Elf_Word flags2;   // General flags
542 };
543
544 } // end namespace object.
545 } // end namespace llvm.
546
547 #endif