1952b9480d0199c9017e0d12624b881983727065
[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/AlignOf.h"
14 #include "llvm/Support/DataTypes.h"
15 #include "llvm/Support/ELF.h"
16 #include "llvm/Support/Endian.h"
17
18 namespace llvm {
19 namespace object {
20
21 using support::endianness;
22
23 template <endianness target_endianness, std::size_t max_alignment,
24           bool is64Bits>
25 struct ELFType {
26   static const endianness TargetEndianness = target_endianness;
27   static const std::size_t MaxAlignment = max_alignment;
28   static const bool Is64Bits = is64Bits;
29 };
30
31 template <typename T, int max_align> struct MaximumAlignment {
32   enum { value = AlignOf<T>::Alignment > max_align ? max_align
33                                                    : AlignOf<T>::Alignment
34   };
35 };
36
37 // Templates to choose Elf_Addr and Elf_Off depending on is64Bits.
38 template <endianness target_endianness, std::size_t max_alignment>
39 struct ELFDataTypeTypedefHelperCommon {
40   typedef support::detail::packed_endian_specific_integral<
41       uint16_t, target_endianness,
42       MaximumAlignment<uint16_t, max_alignment>::value> Elf_Half;
43   typedef support::detail::packed_endian_specific_integral<
44       uint32_t, target_endianness,
45       MaximumAlignment<uint32_t, max_alignment>::value> Elf_Word;
46   typedef support::detail::packed_endian_specific_integral<
47       int32_t, target_endianness,
48       MaximumAlignment<int32_t, max_alignment>::value> Elf_Sword;
49   typedef support::detail::packed_endian_specific_integral<
50       uint64_t, target_endianness,
51       MaximumAlignment<uint64_t, max_alignment>::value> Elf_Xword;
52   typedef support::detail::packed_endian_specific_integral<
53       int64_t, target_endianness,
54       MaximumAlignment<int64_t, max_alignment>::value> Elf_Sxword;
55 };
56
57 template <class ELFT> struct ELFDataTypeTypedefHelper;
58
59 /// ELF 32bit types.
60 template <endianness TargetEndianness, std::size_t MaxAlign>
61 struct ELFDataTypeTypedefHelper<ELFType<TargetEndianness, MaxAlign, false> >
62     : ELFDataTypeTypedefHelperCommon<TargetEndianness, MaxAlign> {
63   typedef uint32_t value_type;
64   typedef support::detail::packed_endian_specific_integral<
65       value_type, TargetEndianness,
66       MaximumAlignment<value_type, MaxAlign>::value> Elf_Addr;
67   typedef support::detail::packed_endian_specific_integral<
68       value_type, TargetEndianness,
69       MaximumAlignment<value_type, MaxAlign>::value> Elf_Off;
70 };
71
72 /// ELF 64bit types.
73 template <endianness TargetEndianness, std::size_t MaxAlign>
74 struct ELFDataTypeTypedefHelper<ELFType<TargetEndianness, MaxAlign, true> >
75     : ELFDataTypeTypedefHelperCommon<TargetEndianness, MaxAlign> {
76   typedef uint64_t value_type;
77   typedef support::detail::packed_endian_specific_integral<
78       value_type, TargetEndianness,
79       MaximumAlignment<value_type, MaxAlign>::value> Elf_Addr;
80   typedef support::detail::packed_endian_specific_integral<
81       value_type, TargetEndianness,
82       MaximumAlignment<value_type, MaxAlign>::value> Elf_Off;
83 };
84
85 // I really don't like doing this, but the alternative is copypasta.
86 #define LLVM_ELF_IMPORT_TYPES(E, M, W)                                         \
87 typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Addr         \
88     Elf_Addr;                                                                  \
89 typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Off          \
90     Elf_Off;                                                                   \
91 typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Half         \
92     Elf_Half;                                                                  \
93 typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Word         \
94     Elf_Word;                                                                  \
95 typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Sword        \
96     Elf_Sword;                                                                 \
97 typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Xword        \
98     Elf_Xword;                                                                 \
99 typedef typename ELFDataTypeTypedefHelper<ELFType<E, M, W> >::Elf_Sxword       \
100     Elf_Sxword;
101
102 #define LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)                                       \
103   LLVM_ELF_IMPORT_TYPES(ELFT::TargetEndianness, ELFT::MaxAlignment,            \
104                         ELFT::Is64Bits)
105
106 // Section header.
107 template <class ELFT> struct Elf_Shdr_Base;
108
109 template <endianness TargetEndianness, std::size_t MaxAlign>
110 struct Elf_Shdr_Base<ELFType<TargetEndianness, MaxAlign, false> > {
111   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
112   Elf_Word sh_name;      // Section name (index into string table)
113   Elf_Word sh_type;      // Section type (SHT_*)
114   Elf_Word sh_flags;     // Section flags (SHF_*)
115   Elf_Addr sh_addr;      // Address where section is to be loaded
116   Elf_Off sh_offset;     // File offset of section data, in bytes
117   Elf_Word sh_size;      // Size of section, in bytes
118   Elf_Word sh_link;      // Section type-specific header table index link
119   Elf_Word sh_info;      // Section type-specific extra information
120   Elf_Word sh_addralign; // Section address alignment
121   Elf_Word sh_entsize;   // Size of records contained within the section
122 };
123
124 template <endianness TargetEndianness, std::size_t MaxAlign>
125 struct Elf_Shdr_Base<ELFType<TargetEndianness, MaxAlign, true> > {
126   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
127   Elf_Word sh_name;       // Section name (index into string table)
128   Elf_Word sh_type;       // Section type (SHT_*)
129   Elf_Xword sh_flags;     // Section flags (SHF_*)
130   Elf_Addr sh_addr;       // Address where section is to be loaded
131   Elf_Off sh_offset;      // File offset of section data, in bytes
132   Elf_Xword sh_size;      // Size of section, in bytes
133   Elf_Word sh_link;       // Section type-specific header table index link
134   Elf_Word sh_info;       // Section type-specific extra information
135   Elf_Xword sh_addralign; // Section address alignment
136   Elf_Xword sh_entsize;   // Size of records contained within the section
137 };
138
139 template <class ELFT>
140 struct Elf_Shdr_Impl : Elf_Shdr_Base<ELFT> {
141   using Elf_Shdr_Base<ELFT>::sh_entsize;
142   using Elf_Shdr_Base<ELFT>::sh_size;
143
144   /// @brief Get the number of entities this section contains if it has any.
145   unsigned getEntityCount() const {
146     if (sh_entsize == 0)
147       return 0;
148     return sh_size / sh_entsize;
149   }
150 };
151
152 template <class ELFT> struct Elf_Sym_Base;
153
154 template <endianness TargetEndianness, std::size_t MaxAlign>
155 struct Elf_Sym_Base<ELFType<TargetEndianness, MaxAlign, false> > {
156   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
157   Elf_Word st_name;       // Symbol name (index into string table)
158   Elf_Addr st_value;      // Value or address associated with the symbol
159   Elf_Word st_size;       // Size of the symbol
160   unsigned char st_info;  // Symbol's type and binding attributes
161   unsigned char st_other; // Must be zero; reserved
162   Elf_Half st_shndx;      // Which section (header table index) it's defined in
163 };
164
165 template <endianness TargetEndianness, std::size_t MaxAlign>
166 struct Elf_Sym_Base<ELFType<TargetEndianness, MaxAlign, true> > {
167   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
168   Elf_Word st_name;       // Symbol name (index into string table)
169   unsigned char st_info;  // Symbol's type and binding attributes
170   unsigned char st_other; // Must be zero; reserved
171   Elf_Half st_shndx;      // Which section (header table index) it's defined in
172   Elf_Addr st_value;      // Value or address associated with the symbol
173   Elf_Xword st_size;      // Size of the symbol
174 };
175
176 template <class ELFT>
177 struct Elf_Sym_Impl : Elf_Sym_Base<ELFT> {
178   using Elf_Sym_Base<ELFT>::st_info;
179   using Elf_Sym_Base<ELFT>::st_other;
180
181   // These accessors and mutators correspond to the ELF32_ST_BIND,
182   // ELF32_ST_TYPE, and ELF32_ST_INFO macros defined in the ELF specification:
183   unsigned char getBinding() const { return st_info >> 4; }
184   unsigned char getType() const { return st_info & 0x0f; }
185   void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
186   void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
187   void setBindingAndType(unsigned char b, unsigned char t) {
188     st_info = (b << 4) + (t & 0x0f);
189   }
190
191   /// Access to the STV_xxx flag stored in the first two bits of st_other.
192   /// STV_DEFAULT: 0
193   /// STV_INTERNAL: 1
194   /// STV_HIDDEN: 2
195   /// STV_PROTECTED: 3
196   unsigned char getVisibility() const { return st_other & 0x3; }
197   void setVisibility(unsigned char v) {
198     assert(v < 4 && "Invalid value for visibility");
199     st_other = (st_other & ~0x3) | v;
200   }
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, std::size_t MaxAlign>
271 struct Elf_Dyn_Base<ELFType<TargetEndianness, MaxAlign, false> > {
272   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, 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, std::size_t MaxAlign>
281 struct Elf_Dyn_Base<ELFType<TargetEndianness, MaxAlign, true> > {
282   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, 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, std::size_t MaxAlign>
304 struct Elf_Rel_Base<ELFType<TargetEndianness, MaxAlign, false>, false> {
305   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, 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, std::size_t MaxAlign>
320 struct Elf_Rel_Base<ELFType<TargetEndianness, MaxAlign, true>, false> {
321   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, 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, std::size_t MaxAlign>
345 struct Elf_Rel_Base<ELFType<TargetEndianness, MaxAlign, false>, true> {
346   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, 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, std::size_t MaxAlign>
362 struct Elf_Rel_Base<ELFType<TargetEndianness, MaxAlign, true>, true> {
363   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, 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, std::size_t MaxAlign, bool isRela>
390 struct Elf_Rel_Impl<ELFType<TargetEndianness, MaxAlign, true>,
391                     isRela> : Elf_Rel_Base<
392     ELFType<TargetEndianness, MaxAlign, true>, isRela> {
393   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, 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, std::size_t MaxAlign, bool isRela>
415 struct Elf_Rel_Impl<ELFType<TargetEndianness, MaxAlign, false>,
416                     isRela> : Elf_Rel_Base<
417     ELFType<TargetEndianness, MaxAlign, false>, isRela> {
418   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
419
420   // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
421   // and ELF32_R_INFO macros defined in the ELF specification:
422   uint32_t getSymbol(bool isMips64EL) const {
423     return this->getRInfo(isMips64EL) >> 8;
424   }
425   unsigned char getType(bool isMips64EL) const {
426     return (unsigned char)(this->getRInfo(isMips64EL) & 0x0ff);
427   }
428   void setSymbol(uint32_t s, bool IsMips64EL) {
429     setSymbolAndType(s, getType(), IsMips64EL);
430   }
431   void setType(unsigned char t, bool IsMips64EL) {
432     setSymbolAndType(getSymbol(), t, IsMips64EL);
433   }
434   void setSymbolAndType(uint32_t s, unsigned char t, bool IsMips64EL) {
435     this->setRInfo((s << 8) + t, IsMips64EL);
436   }
437 };
438
439 template <class ELFT>
440 struct Elf_Ehdr_Impl {
441   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
442   unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
443   Elf_Half e_type;                       // Type of file (see ET_*)
444   Elf_Half e_machine;   // Required architecture for this file (see EM_*)
445   Elf_Word e_version;   // Must be equal to 1
446   Elf_Addr e_entry;     // Address to jump to in order to start program
447   Elf_Off e_phoff;      // Program header table's file offset, in bytes
448   Elf_Off e_shoff;      // Section header table's file offset, in bytes
449   Elf_Word e_flags;     // Processor-specific flags
450   Elf_Half e_ehsize;    // Size of ELF header, in bytes
451   Elf_Half e_phentsize; // Size of an entry in the program header table
452   Elf_Half e_phnum;     // Number of entries in the program header table
453   Elf_Half e_shentsize; // Size of an entry in the section header table
454   Elf_Half e_shnum;     // Number of entries in the section header table
455   Elf_Half e_shstrndx;  // Section header table index of section name
456                         // string table
457   bool checkMagic() const {
458     return (memcmp(e_ident, ELF::ElfMagic, strlen(ELF::ElfMagic))) == 0;
459   }
460   unsigned char getFileClass() const { return e_ident[ELF::EI_CLASS]; }
461   unsigned char getDataEncoding() const { return e_ident[ELF::EI_DATA]; }
462 };
463
464 template <class ELFT> struct Elf_Phdr_Impl;
465
466 template <endianness TargetEndianness, std::size_t MaxAlign>
467 struct Elf_Phdr_Impl<ELFType<TargetEndianness, MaxAlign, false> > {
468   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, false)
469   Elf_Word p_type;   // Type of segment
470   Elf_Off p_offset;  // FileOffset where segment is located, in bytes
471   Elf_Addr p_vaddr;  // Virtual Address of beginning of segment
472   Elf_Addr p_paddr;  // Physical address of beginning of segment (OS-specific)
473   Elf_Word p_filesz; // Num. of bytes in file image of segment (may be zero)
474   Elf_Word p_memsz;  // Num. of bytes in mem image of segment (may be zero)
475   Elf_Word p_flags;  // Segment flags
476   Elf_Word p_align;  // Segment alignment constraint
477 };
478
479 template <endianness TargetEndianness, std::size_t MaxAlign>
480 struct Elf_Phdr_Impl<ELFType<TargetEndianness, MaxAlign, true> > {
481   LLVM_ELF_IMPORT_TYPES(TargetEndianness, MaxAlign, true)
482   Elf_Word p_type;    // Type of segment
483   Elf_Word p_flags;   // Segment flags
484   Elf_Off p_offset;   // FileOffset where segment is located, in bytes
485   Elf_Addr p_vaddr;   // Virtual Address of beginning of segment
486   Elf_Addr p_paddr;   // Physical address of beginning of segment (OS-specific)
487   Elf_Xword p_filesz; // Num. of bytes in file image of segment (may be zero)
488   Elf_Xword p_memsz;  // Num. of bytes in mem image of segment (may be zero)
489   Elf_Xword p_align;  // Segment alignment constraint
490 };
491
492 // .MIPS.abiflags section content
493 template <class ELFT> struct Elf_Mips_ABIFlags {
494   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
495   Elf_Half version;  // Version of the structure
496   uint8_t isa_level; // ISA level: 1-5, 32, and 64
497   uint8_t isa_rev;   // ISA revision (0 for MIPS I - MIPS V)
498   uint8_t gpr_size;  // General purpose registers size
499   uint8_t cpr1_size; // Co-processor 1 registers size
500   uint8_t cpr2_size; // Co-processor 2 registers size
501   uint8_t fp_abi;    // Floating-point ABI flag
502   Elf_Word isa_ext;  // Processor-specific extension
503   Elf_Word ases;     // ASEs flags
504   Elf_Word flags1;   // General flags
505   Elf_Word flags2;   // General flags
506 };
507
508 } // end namespace object.
509 } // end namespace llvm.
510
511 #endif