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