ELF.h revision 3cede2d0b2b6cc0a06f55da7c2f8e4263ec0091e
1//===-- llvm/Support/ELF.h - ELF constants and data structures --*- 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// This header contains common, non-processor-specific data structures and
11// constants for the ELF file format.
12//
13// The details of the ELF32 bits in this file are largely based on the Tool
14// Interface Standard (TIS) Executable and Linking Format (ELF) Specification
15// Version 1.2, May 1995. The ELF64 stuff is based on ELF-64 Object File Format
16// Version 1.5, Draft 2, May 1998 as well as OpenBSD header files.
17//
18//===----------------------------------------------------------------------===//
19
20#ifndef LLVM_SUPPORT_ELF_H
21#define LLVM_SUPPORT_ELF_H
22
23#include "llvm/System/DataTypes.h"
24#include <cstring>
25
26namespace llvm {
27
28namespace ELF {
29
30typedef uint32_t Elf32_Addr; // Program address
31typedef uint16_t Elf32_Half;
32typedef uint32_t Elf32_Off;  // File offset
33typedef int32_t  Elf32_Sword;
34typedef uint32_t Elf32_Word;
35
36typedef uint64_t Elf64_Addr;
37typedef uint64_t Elf64_Off;
38typedef int32_t  Elf64_Shalf;
39typedef int32_t  Elf64_Sword;
40typedef uint32_t Elf64_Word;
41typedef int64_t  Elf64_Sxword;
42typedef uint64_t Elf64_Xword;
43typedef uint32_t Elf64_Half;
44typedef uint16_t Elf64_Quarter;
45
46// Object file magic string.
47static const char ElfMagic[] = { 0x7f, 'E', 'L', 'F', '\0' };
48
49// e_ident size and indices.
50enum {
51  EI_MAG0       = 0,          // File identification index.
52  EI_MAG1       = 1,          // File identification index.
53  EI_MAG2       = 2,          // File identification index.
54  EI_MAG3       = 3,          // File identification index.
55  EI_CLASS      = 4,          // File class.
56  EI_DATA       = 5,          // Data encoding.
57  EI_VERSION    = 6,          // File version.
58  EI_OSABI      = 7,          // OS/ABI identification.
59  EI_ABIVERSION = 8,          // ABI version.
60  EI_PAD        = 9,          // Start of padding bytes.
61  EI_NIDENT     = 16          // Number of bytes in e_ident.
62};
63
64struct Elf32_Ehdr {
65  unsigned char e_ident[EI_NIDENT]; // ELF Identification bytes
66  Elf32_Half    e_type;      // Type of file (see ET_* below)
67  Elf32_Half    e_machine;   // Required architecture for this file (see EM_*)
68  Elf32_Word    e_version;   // Must be equal to 1
69  Elf32_Addr    e_entry;     // Address to jump to in order to start program
70  Elf32_Off     e_phoff;     // Program header table's file offset, in bytes
71  Elf32_Off     e_shoff;     // Section header table's file offset, in bytes
72  Elf32_Word    e_flags;     // Processor-specific flags
73  Elf32_Half    e_ehsize;    // Size of ELF header, in bytes
74  Elf32_Half    e_phentsize; // Size of an entry in the program header table
75  Elf32_Half    e_phnum;     // Number of entries in the program header table
76  Elf32_Half    e_shentsize; // Size of an entry in the section header table
77  Elf32_Half    e_shnum;     // Number of entries in the section header table
78  Elf32_Half    e_shstrndx;  // Sect hdr table index of sect name string table
79  bool checkMagic() const {
80    return (memcmp(e_ident, ElfMagic, strlen(ElfMagic))) == 0;
81  }
82  unsigned char getFileClass() const { return e_ident[EI_CLASS]; }
83  unsigned char getDataEncoding() const { return e_ident[EI_DATA]; }
84};
85
86// 64-bit ELF header. Fields are the same as for ELF32, but with different
87// types (see above).
88struct Elf64_Ehdr {
89  unsigned char e_ident[EI_NIDENT];
90  Elf64_Quarter e_type;
91  Elf64_Quarter e_machine;
92  Elf64_Half    e_version;
93  Elf64_Addr    e_entry;
94  Elf64_Off     e_phoff;
95  Elf64_Off     e_shoff;
96  Elf64_Half    e_flags;
97  Elf64_Quarter e_ehsize;
98  Elf64_Quarter e_phentsize;
99  Elf64_Quarter e_phnum;
100  Elf64_Quarter e_shentsize;
101  Elf64_Quarter e_shnum;
102  Elf64_Quarter e_shstrndx;
103  bool checkMagic() const {
104    return (memcmp(e_ident, ElfMagic, strlen(ElfMagic))) == 0;
105  }
106  unsigned char getFileClass() const { return e_ident[EI_CLASS]; }
107  unsigned char getDataEncoding() const { return e_ident[EI_DATA]; }
108};
109
110// File types
111enum {
112  ET_NONE   = 0,      // No file type
113  ET_REL    = 1,      // Relocatable file
114  ET_EXEC   = 2,      // Executable file
115  ET_DYN    = 3,      // Shared object file
116  ET_CORE   = 4,      // Core file
117  ET_LOPROC = 0xff00, // Beginning of processor-specific codes
118  ET_HIPROC = 0xffff  // Processor-specific
119};
120
121// Versioning
122enum {
123  EV_NONE = 0,
124  EV_CURRENT = 1
125};
126
127// Machine architectures
128enum {
129  EM_NONE = 0,      // No machine
130  EM_M32 = 1,       // AT&T WE 32100
131  EM_SPARC = 2,     // SPARC
132  EM_386 = 3,       // Intel 386
133  EM_68K = 4,       // Motorola 68000
134  EM_88K = 5,       // Motorola 88000
135  EM_486 = 6,       // Intel 486 (deprecated)
136  EM_860 = 7,       // Intel 80860
137  EM_MIPS = 8,      // MIPS R3000
138  EM_PPC = 20,      // PowerPC
139  EM_PPC64 = 21,    // PowerPC64
140  EM_ARM = 40,      // ARM
141  EM_ALPHA = 41,    // DEC Alpha
142  EM_SPARCV9 = 43,  // SPARC V9
143  EM_X86_64 = 62,   // AMD64
144  EM_MBLAZE = 47787 // Xilinx MicroBlaze
145};
146
147// Object file classes.
148enum {
149  ELFCLASS32 = 1, // 32-bit object file
150  ELFCLASS64 = 2  // 64-bit object file
151};
152
153// Object file byte orderings.
154enum {
155  ELFDATANONE = 0, // Invalid data encoding.
156  ELFDATA2LSB = 1, // Little-endian object file
157  ELFDATA2MSB = 2  // Big-endian object file
158};
159
160// OS ABI identification.
161enum {
162  ELFOSABI_NONE = 0,          // UNIX System V ABI
163  ELFOSABI_HPUX = 1,          // HP-UX operating system
164  ELFOSABI_NETBSD = 2,        // NetBSD
165  ELFOSABI_LINUX = 3,         // GNU/Linux
166  ELFOSABI_HURD = 4,          // GNU/Hurd
167  ELFOSABI_SOLARIS = 6,       // Solaris
168  ELFOSABI_AIX = 7,           // AIX
169  ELFOSABI_IRIX = 8,          // IRIX
170  ELFOSABI_FREEBSD = 9,       // FreeBSD
171  ELFOSABI_TRU64 = 10,        // TRU64 UNIX
172  ELFOSABI_MODESTO = 11,      // Novell Modesto
173  ELFOSABI_OPENBSD = 12,      // OpenBSD
174  ELFOSABI_OPENVMS = 13,      // OpenVMS
175  ELFOSABI_NSK = 14,          // Hewlett-Packard Non-Stop Kernel
176  ELFOSABI_AROS = 15,         // AROS
177  ELFOSABI_FENIXOS = 16,      // FenixOS
178  ELFOSABI_C6000_ELFABI = 64, // Bare-metal TMS320C6000
179  ELFOSABI_C6000_LINUX = 65,  // Linux TMS320C6000
180  ELFOSABI_ARM = 97,          // ARM
181  ELFOSABI_STANDALONE = 255   // Standalone (embedded) application
182};
183
184// X86_64 relocations.
185enum {
186  R_X86_64_NONE       = 0,
187  R_X86_64_64         = 1,
188  R_X86_64_PC32       = 2,
189  R_X86_64_GOT32      = 3,
190  R_X86_64_PLT32      = 4,
191  R_X86_64_COPY       = 5,
192  R_X86_64_GLOB_DAT   = 6,
193  R_X86_64_JUMP_SLOT  = 7,
194  R_X86_64_RELATIVE   = 8,
195  R_X86_64_GOTPCREL   = 9,
196  R_X86_64_32         = 10,
197  R_X86_64_32S        = 11,
198  R_X86_64_16         = 12,
199  R_X86_64_PC16       = 13,
200  R_X86_64_8          = 14,
201  R_X86_64_PC8        = 15,
202  R_X86_64_DTPMOD64   = 16,
203  R_X86_64_DTPOFF64   = 17,
204  R_X86_64_TPOFF64    = 18,
205  R_X86_64_TLSGD      = 19,
206  R_X86_64_TLSLD      = 20,
207  R_X86_64_DTPOFF32   = 21,
208  R_X86_64_GOTTPOFF   = 22,
209  R_X86_64_TPOFF32    = 23,
210  R_X86_64_PC64       = 24,
211  R_X86_64_GOTOFF64   = 25,
212  R_X86_64_GOTPC32    = 26,
213  R_X86_64_SIZE32     = 32,
214  R_X86_64_SIZE64     = 33,
215  R_X86_64_GOTPC32_TLSDESC = 34,
216  R_X86_64_TLSDESC_CALL    = 35,
217  R_X86_64_TLSDESC    = 36
218};
219
220// i386 relocations.
221// TODO: this is just a subset
222enum {
223  R_386_NONE          = 0,
224  R_386_32            = 1,
225  R_386_PC32          = 2,
226  R_386_GOT32         = 3,
227  R_386_PLT32         = 4,
228  R_386_COPY          = 5,
229  R_386_GLOB_DAT      = 6,
230  R_386_JUMP_SLOT     = 7,
231  R_386_RELATIVE      = 8,
232  R_386_GOTOFF        = 9,
233  R_386_GOTPC         = 10,
234  R_386_32PLT         = 11,
235  R_386_TLS_TPOFF     = 14,
236  R_386_TLS_IE        = 15,
237  R_386_TLS_GOTIE     = 16,
238  R_386_TLS_LE        = 17,
239  R_386_TLS_GD        = 18,
240  R_386_TLS_LDM       = 19,
241  R_386_16            = 20,
242  R_386_PC16          = 21,
243  R_386_8             = 22,
244  R_386_PC8           = 23,
245  R_386_TLS_GD_32     = 24,
246  R_386_TLS_GD_PUSH   = 25,
247  R_386_TLS_GD_CALL   = 26,
248  R_386_TLS_GD_POP    = 27,
249  R_386_TLS_LDM_32    = 28,
250  R_386_TLS_LDM_PUSH  = 29,
251  R_386_TLS_LDM_CALL  = 30,
252  R_386_TLS_LDM_POP   = 31,
253  R_386_TLS_LDO_32    = 32,
254  R_386_TLS_IE_32     = 33,
255  R_386_TLS_LE_32     = 34,
256  R_386_TLS_DTPMOD32  = 35,
257  R_386_TLS_DTPOFF32  = 36,
258  R_386_TLS_TPOFF32   = 37,
259  R_386_TLS_GOTDESC   = 39,
260  R_386_TLS_DESC_CALL = 40,
261  R_386_TLS_DESC      = 41,
262  R_386_IRELATIVE     = 42,
263  R_386_NUM           = 43
264};
265
266// Section header.
267struct Elf32_Shdr {
268  Elf32_Word sh_name;      // Section name (index into string table)
269  Elf32_Word sh_type;      // Section type (SHT_*)
270  Elf32_Word sh_flags;     // Section flags (SHF_*)
271  Elf32_Addr sh_addr;      // Address where section is to be loaded
272  Elf32_Off  sh_offset;    // File offset of section data, in bytes
273  Elf32_Word sh_size;      // Size of section, in bytes
274  Elf32_Word sh_link;      // Section type-specific header table index link
275  Elf32_Word sh_info;      // Section type-specific extra information
276  Elf32_Word sh_addralign; // Section address alignment
277  Elf32_Word sh_entsize;   // Size of records contained within the section
278};
279
280// Section header for ELF64 - same fields as ELF32, different types.
281struct Elf64_Shdr {
282  Elf64_Half  sh_name;
283  Elf64_Half  sh_type;
284  Elf64_Xword sh_flags;
285  Elf64_Addr  sh_addr;
286  Elf64_Off   sh_offset;
287  Elf64_Xword sh_size;
288  Elf64_Half  sh_link;
289  Elf64_Half  sh_info;
290  Elf64_Xword sh_addralign;
291  Elf64_Xword sh_entsize;
292};
293
294// Special section indices.
295enum {
296  SHN_UNDEF     = 0,      // Undefined, missing, irrelevant, or meaningless
297  SHN_LORESERVE = 0xff00, // Lowest reserved index
298  SHN_LOPROC    = 0xff00, // Lowest processor-specific index
299  SHN_HIPROC    = 0xff1f, // Highest processor-specific index
300  SHN_ABS       = 0xfff1, // Symbol has absolute value; does not need relocation
301  SHN_COMMON    = 0xfff2, // FORTRAN COMMON or C external global variables
302  SHN_HIRESERVE = 0xffff  // Highest reserved index
303};
304
305// Section types.
306enum {
307  SHT_NULL          = 0,  // No associated section (inactive entry).
308  SHT_PROGBITS      = 1,  // Program-defined contents.
309  SHT_SYMTAB        = 2,  // Symbol table.
310  SHT_STRTAB        = 3,  // String table.
311  SHT_RELA          = 4,  // Relocation entries; explicit addends.
312  SHT_HASH          = 5,  // Symbol hash table.
313  SHT_DYNAMIC       = 6,  // Information for dynamic linking.
314  SHT_NOTE          = 7,  // Information about the file.
315  SHT_NOBITS        = 8,  // Data occupies no space in the file.
316  SHT_REL           = 9,  // Relocation entries; no explicit addends.
317  SHT_SHLIB         = 10, // Reserved.
318  SHT_DYNSYM        = 11, // Symbol table.
319  SHT_INIT_ARRAY    = 14, // Pointers to initialisation functions.
320  SHT_FINI_ARRAY    = 15, // Pointers to termination functions.
321  SHT_PREINIT_ARRAY = 16, // Pointers to pre-init functions.
322  SHT_GROUP         = 17, // Section group.
323  SHT_SYMTAB_SHNDX  = 18, // Indicies for SHN_XINDEX entries.
324  SHT_LOOS          = 0x60000000, // Lowest operating system-specific type.
325  SHT_HIOS          = 0x6fffffff, // Highest operating system-specific type.
326  SHT_LOPROC        = 0x70000000, // Lowest processor architecture-specific type.
327  // Fixme: All this is duplicated in MCSectionELF. Why??
328  // Exception Index table
329  SHT_ARM_EXIDX           = 0x70000001U,
330  // BPABI DLL dynamic linking pre-emption map
331  SHT_ARM_PREEMPTMAP      = 0x70000002U,
332  //  Object file compatibility attributes
333  SHT_ARM_ATTRIBUTES      = 0x70000003U,
334  SHT_ARM_DEBUGOVERLAY    = 0x70000004U,
335  SHT_ARM_OVERLAYSECTION  = 0x70000005U,
336
337  SHT_HIPROC        = 0x7fffffff, // Highest processor architecture-specific type.
338  SHT_LOUSER        = 0x80000000, // Lowest type reserved for applications.
339  SHT_HIUSER        = 0xffffffff  // Highest type reserved for applications.
340};
341
342// Section flags.
343enum {
344  SHF_WRITE     = 0x1, // Section data should be writable during execution.
345  SHF_ALLOC     = 0x2, // Section occupies memory during program execution.
346  SHF_EXECINSTR = 0x4, // Section contains executable machine instructions.
347  SHF_MASKPROC  = 0xf0000000 // Bits indicating processor-specific flags.
348};
349
350// Symbol table entries for ELF32.
351struct Elf32_Sym {
352  Elf32_Word    st_name;  // Symbol name (index into string table)
353  Elf32_Addr    st_value; // Value or address associated with the symbol
354  Elf32_Word    st_size;  // Size of the symbol
355  unsigned char st_info;  // Symbol's type and binding attributes
356  unsigned char st_other; // Must be zero; reserved
357  Elf32_Half    st_shndx; // Which section (header table index) it's defined in
358
359  // These accessors and mutators correspond to the ELF32_ST_BIND,
360  // ELF32_ST_TYPE, and ELF32_ST_INFO macros defined in the ELF specification:
361  unsigned char getBinding() const { return st_info >> 4; }
362  unsigned char getType() const { return st_info & 0x0f; }
363  void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
364  void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
365  void setBindingAndType(unsigned char b, unsigned char t) {
366    st_info = (b << 4) + (t & 0x0f);
367  }
368};
369
370// Symbol table entries for ELF64.
371struct Elf64_Sym {
372  Elf64_Word      st_name;  // Symbol name (index into string table)
373  unsigned char   st_info;  // Symbol's type and binding attributes
374  unsigned char   st_other; // Must be zero; reserved
375  Elf64_Half      st_shndx; // Which section (header table index) it's defined in
376  Elf64_Addr      st_value; // Value or address associated with the symbol
377  Elf64_Xword     st_size;  // Size of the symbol
378
379  // These accessors and mutators are identical to those defined for ELF32
380  // symbol table entries.
381  unsigned char getBinding() const { return st_info >> 4; }
382  unsigned char getType() const { return st_info & 0x0f; }
383  void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
384  void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
385  void setBindingAndType(unsigned char b, unsigned char t) {
386    st_info = (b << 4) + (t & 0x0f);
387  }
388};
389
390// The size (in bytes) of symbol table entries.
391enum {
392  SYMENTRY_SIZE32 = 16, // 32-bit symbol entry size
393  SYMENTRY_SIZE64 = 24  // 64-bit symbol entry size.
394};
395
396// Symbol bindings.
397enum {
398  STB_LOCAL = 0,   // Local symbol, not visible outside obj file containing def
399  STB_GLOBAL = 1,  // Global symbol, visible to all object files being combined
400  STB_WEAK = 2,    // Weak symbol, like global but lower-precedence
401  STB_LOPROC = 13, // Lowest processor-specific binding type
402  STB_HIPROC = 15  // Highest processor-specific binding type
403};
404
405// Symbol types.
406enum {
407  STT_NOTYPE  = 0,   // Symbol's type is not specified
408  STT_OBJECT  = 1,   // Symbol is a data object (variable, array, etc.)
409  STT_FUNC    = 2,   // Symbol is executable code (function, etc.)
410  STT_SECTION = 3,   // Symbol refers to a section
411  STT_FILE    = 4,   // Local, absolute symbol that refers to a file
412  STT_COMMON  = 5,   // An uninitialised common block
413  STT_TLS     = 6,   // Thread local data object
414  STT_LOPROC  = 13,  // Lowest processor-specific symbol type
415  STT_HIPROC  = 15   // Highest processor-specific symbol type
416};
417
418enum {
419  STV_DEFAULT   = 0,  // Visibility is specified by binding type
420  STV_INTERNAL  = 1,  // Defined by processor supplements
421  STV_HIDDEN    = 2,  // Not visible to other components
422  STV_PROTECTED = 3   // Visible in other components but not preemptable
423};
424
425// Relocation entry, without explicit addend.
426struct Elf32_Rel {
427  Elf32_Addr r_offset; // Location (file byte offset, or program virtual addr)
428  Elf32_Word r_info;   // Symbol table index and type of relocation to apply
429
430  // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
431  // and ELF32_R_INFO macros defined in the ELF specification:
432  Elf32_Word getSymbol() const { return (r_info >> 8); }
433  unsigned char getType() const { return (unsigned char) (r_info & 0x0ff); }
434  void setSymbol(Elf32_Word s) { setSymbolAndType(s, getType()); }
435  void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
436  void setSymbolAndType(Elf32_Word s, unsigned char t) {
437    r_info = (s << 8) + t;
438  }
439};
440
441// Relocation entry with explicit addend.
442struct Elf32_Rela {
443  Elf32_Addr  r_offset; // Location (file byte offset, or program virtual addr)
444  Elf32_Word  r_info;   // Symbol table index and type of relocation to apply
445  Elf32_Sword r_addend; // Compute value for relocatable field by adding this
446
447  // These accessors and mutators correspond to the ELF32_R_SYM, ELF32_R_TYPE,
448  // and ELF32_R_INFO macros defined in the ELF specification:
449  Elf32_Word getSymbol() const { return (r_info >> 8); }
450  unsigned char getType() const { return (unsigned char) (r_info & 0x0ff); }
451  void setSymbol(Elf32_Word s) { setSymbolAndType(s, getType()); }
452  void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
453  void setSymbolAndType(Elf32_Word s, unsigned char t) {
454    r_info = (s << 8) + t;
455  }
456};
457
458// Relocation entry, without explicit addend.
459struct Elf64_Rel {
460  Elf64_Addr r_offset; // Location (file byte offset, or program virtual addr).
461  Elf64_Xword r_info;   // Symbol table index and type of relocation to apply.
462
463  // These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
464  // and ELF64_R_INFO macros defined in the ELF specification:
465  Elf64_Xword getSymbol() const { return (r_info >> 32); }
466  unsigned char getType() const {
467    return (unsigned char) (r_info & 0xffffffffL);
468  }
469  void setSymbol(Elf32_Word s) { setSymbolAndType(s, getType()); }
470  void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
471  void setSymbolAndType(Elf64_Xword s, unsigned char t) {
472    r_info = (s << 32) + (t&0xffffffffL);
473  }
474};
475
476// Relocation entry with explicit addend.
477struct Elf64_Rela {
478  Elf64_Addr  r_offset; // Location (file byte offset, or program virtual addr).
479  Elf64_Xword  r_info;   // Symbol table index and type of relocation to apply.
480  Elf64_Sxword r_addend; // Compute value for relocatable field by adding this.
481
482  // These accessors and mutators correspond to the ELF64_R_SYM, ELF64_R_TYPE,
483  // and ELF64_R_INFO macros defined in the ELF specification:
484  Elf64_Xword getSymbol() const { return (r_info >> 32); }
485  unsigned char getType() const {
486    return (unsigned char) (r_info & 0xffffffffL);
487  }
488  void setSymbol(Elf64_Xword s) { setSymbolAndType(s, getType()); }
489  void setType(unsigned char t) { setSymbolAndType(getSymbol(), t); }
490  void setSymbolAndType(Elf64_Xword s, unsigned char t) {
491    r_info = (s << 32) + (t&0xffffffffL);
492  }
493};
494
495// Program header for ELF32.
496struct Elf32_Phdr {
497  Elf32_Word p_type;   // Type of segment
498  Elf32_Off  p_offset; // File offset where segment is located, in bytes
499  Elf32_Addr p_vaddr;  // Virtual address of beginning of segment
500  Elf32_Addr p_paddr;  // Physical address of beginning of segment (OS-specific)
501  Elf32_Word p_filesz; // Num. of bytes in file image of segment (may be zero)
502  Elf32_Word p_memsz;  // Num. of bytes in mem image of segment (may be zero)
503  Elf32_Word p_flags;  // Segment flags
504  Elf32_Word p_align;  // Segment alignment constraint
505};
506
507// Program header for ELF64.
508struct Elf64_Phdr {
509  Elf64_Word   p_type;   // Type of segment
510  Elf64_Word   p_flags;  // Segment flags
511  Elf64_Off    p_offset; // File offset where segment is located, in bytes
512  Elf64_Addr   p_vaddr;  // Virtual address of beginning of segment
513  Elf64_Addr   p_paddr;  // Physical address of beginning of segment (OS-specific)
514  Elf64_Xword  p_filesz; // Num. of bytes in file image of segment (may be zero)
515  Elf64_Xword  p_memsz;  // Num. of bytes in mem image of segment (may be zero)
516  Elf64_Xword  p_align;  // Segment alignment constraint
517};
518
519// Segment types.
520enum {
521  PT_NULL    = 0, // Unused segment.
522  PT_LOAD    = 1, // Loadable segment.
523  PT_DYNAMIC = 2, // Dynamic linking information.
524  PT_INTERP  = 3, // Interpreter pathname.
525  PT_NOTE    = 4, // Auxiliary information.
526  PT_SHLIB   = 5, // Reserved.
527  PT_PHDR    = 6, // The program header table itself.
528  PT_LOPROC  = 0x70000000, // Lowest processor-specific program hdr entry type.
529  PT_HIPROC  = 0x7fffffff  // Highest processor-specific program hdr entry type.
530};
531
532// Segment flag bits.
533enum {
534  PF_X        = 1,         // Execute
535  PF_W        = 2,         // Write
536  PF_R        = 4,         // Read
537  PF_MASKPROC = 0xf0000000 // Unspecified
538};
539
540// Dynamic table entry for ELF32.
541struct Elf32_Dyn
542{
543  Elf32_Sword d_tag;            // Type of dynamic table entry.
544  union
545  {
546      Elf32_Word d_val;         // Integer value of entry.
547      Elf32_Addr d_ptr;         // Pointer value of entry.
548  } d_un;
549};
550
551// Dynamic table entry for ELF64.
552struct Elf64_Dyn
553{
554  Elf64_Sxword d_tag;           // Type of dynamic table entry.
555  union
556  {
557      Elf64_Xword d_val;        // Integer value of entry.
558      Elf64_Addr  d_ptr;        // Pointer value of entry.
559  } d_un;
560};
561
562// Dynamic table entry tags.
563enum {
564  DT_NULL         = 0,        // Marks end of dynamic array.
565  DT_NEEDED       = 1,        // String table offset of needed library.
566  DT_PLTRELSZ     = 2,        // Size of relocation entries in PLT.
567  DT_PLTGOT       = 3,        // Address associated with linkage table.
568  DT_HASH         = 4,        // Address of symbolic hash table.
569  DT_STRTAB       = 5,        // Address of dynamic string table.
570  DT_SYMTAB       = 6,        // Address of dynamic symbol table.
571  DT_RELA         = 7,        // Address of relocation table (Rela entries).
572  DT_RELASZ       = 8,        // Size of Rela relocation table.
573  DT_RELAENT      = 9,        // Size of a Rela relocation entry.
574  DT_STRSZ        = 10,       // Total size of the string table.
575  DT_SYMENT       = 11,       // Size of a symbol table entry.
576  DT_INIT         = 12,       // Address of initialization function.
577  DT_FINI         = 13,       // Address of termination function.
578  DT_SONAME       = 14,       // String table offset of a shared objects name.
579  DT_RPATH        = 15,       // String table offset of library search path.
580  DT_SYMBOLIC     = 16,       // Changes symbol resolution algorithm.
581  DT_REL          = 17,       // Address of relocation table (Rel entries).
582  DT_RELSZ        = 18,       // Size of Rel relocation table.
583  DT_RELENT       = 19,       // Size of a Rel relocation entry.
584  DT_PLTREL       = 20,       // Type of relocation entry used for linking.
585  DT_DEBUG        = 21,       // Reserved for debugger.
586  DT_TEXTREL      = 22,       // Relocations exist for non-writable segements.
587  DT_JMPREL       = 23,       // Address of relocations associated with PLT.
588  DT_BIND_NOW     = 24,       // Process all relocations before execution.
589  DT_INIT_ARRAY   = 25,       // Pointer to array of initialization functions.
590  DT_FINI_ARRAY   = 26,       // Pointer to array of termination functions.
591  DT_INIT_ARRAYSZ = 27,       // Size of DT_INIT_ARRAY.
592  DT_FINI_ARRAYSZ = 28,       // Size of DT_FINI_ARRAY.
593  DT_LOOS         = 0x60000000, // Start of environment specific tags.
594  DT_HIOS         = 0x6FFFFFFF, // End of environment specific tags.
595  DT_LOPROC       = 0x70000000, // Start of processor specific tags.
596  DT_HIPROC       = 0x7FFFFFFF  // End of processor specific tags.
597};
598
599} // end namespace ELF
600
601} // end namespace llvm
602
603#endif
604