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