vserver 1.9.3
[linux-2.6.git] / include / linux / elf.h
1 #ifndef _LINUX_ELF_H
2 #define _LINUX_ELF_H
3
4 #include <linux/types.h>
5 #include <asm/elf.h>
6
7 #ifndef elf_read_implies_exec
8   /* Executables for which elf_read_implies_exec() returns TRUE will
9      have the READ_IMPLIES_EXEC personality flag set automatically.
10      Override in asm/elf.h as needed.  */
11 # define elf_read_implies_exec(ex, have_pt_gnu_stack)   0
12 #endif
13
14 /* 32-bit ELF base types. */
15 typedef __u32   Elf32_Addr;
16 typedef __u16   Elf32_Half;
17 typedef __u32   Elf32_Off;
18 typedef __s32   Elf32_Sword;
19 typedef __u32   Elf32_Word;
20
21 /* 64-bit ELF base types. */
22 typedef __u64   Elf64_Addr;
23 typedef __u16   Elf64_Half;
24 typedef __s16   Elf64_SHalf;
25 typedef __u64   Elf64_Off;
26 typedef __s32   Elf64_Sword;
27 typedef __u32   Elf64_Word;
28 typedef __u64   Elf64_Xword;
29 typedef __s64   Elf64_Sxword;
30
31 /* These constants are for the segment types stored in the image headers */
32 #define PT_NULL    0
33 #define PT_LOAD    1
34 #define PT_DYNAMIC 2
35 #define PT_INTERP  3
36 #define PT_NOTE    4
37 #define PT_SHLIB   5
38 #define PT_PHDR    6
39 #define PT_LOOS    0x60000000
40 #define PT_HIOS    0x6fffffff
41 #define PT_LOPROC  0x70000000
42 #define PT_HIPROC  0x7fffffff
43 #define PT_GNU_EH_FRAME         0x6474e550
44
45 #define PT_GNU_STACK    (PT_LOOS + 0x474e551)
46
47 /* These constants define the different elf file types */
48 #define ET_NONE   0
49 #define ET_REL    1
50 #define ET_EXEC   2
51 #define ET_DYN    3
52 #define ET_CORE   4
53 #define ET_LOPROC 0xff00
54 #define ET_HIPROC 0xffff
55
56 /* These constants define the various ELF target machines */
57 #define EM_NONE  0
58 #define EM_M32   1
59 #define EM_SPARC 2
60 #define EM_386   3
61 #define EM_68K   4
62 #define EM_88K   5
63 #define EM_486   6   /* Perhaps disused */
64 #define EM_860   7
65
66 #define EM_MIPS         8       /* MIPS R3000 (officially, big-endian only) */
67
68 #define EM_MIPS_RS4_BE 10       /* MIPS R4000 big-endian */
69
70 #define EM_PARISC      15       /* HPPA */
71
72 #define EM_SPARC32PLUS 18       /* Sun's "v8plus" */
73
74 #define EM_PPC         20       /* PowerPC */
75 #define EM_PPC64       21       /* PowerPC64 */
76
77 #define EM_SH          42       /* SuperH */
78
79 #define EM_SPARCV9     43       /* SPARC v9 64-bit */
80
81 #define EM_IA_64        50      /* HP/Intel IA-64 */
82
83 #define EM_X86_64       62      /* AMD x86-64 */
84
85 #define EM_S390         22      /* IBM S/390 */
86
87 #define EM_CRIS         76      /* Axis Communications 32-bit embedded processor */
88
89 #define EM_V850         87      /* NEC v850 */
90
91 #define EM_M32R         88      /* Renesas M32R */
92
93 #define EM_H8_300       46      /* Renesas H8/300,300H,H8S */
94
95 /*
96  * This is an interim value that we will use until the committee comes
97  * up with a final number.
98  */
99 #define EM_ALPHA        0x9026
100
101 /* Bogus old v850 magic number, used by old tools.  */
102 #define EM_CYGNUS_V850  0x9080
103
104 /* Bogus old m32r magic number, used by old tools.  */
105 #define EM_CYGNUS_M32R  0x9041
106
107 /*
108  * This is the old interim value for S/390 architecture
109  */
110 #define EM_S390_OLD     0xA390
111
112 /* This is the info that is needed to parse the dynamic section of the file */
113 #define DT_NULL         0
114 #define DT_NEEDED       1
115 #define DT_PLTRELSZ     2
116 #define DT_PLTGOT       3
117 #define DT_HASH         4
118 #define DT_STRTAB       5
119 #define DT_SYMTAB       6
120 #define DT_RELA         7
121 #define DT_RELASZ       8
122 #define DT_RELAENT      9
123 #define DT_STRSZ        10
124 #define DT_SYMENT       11
125 #define DT_INIT         12
126 #define DT_FINI         13
127 #define DT_SONAME       14
128 #define DT_RPATH        15
129 #define DT_SYMBOLIC     16
130 #define DT_REL          17
131 #define DT_RELSZ        18
132 #define DT_RELENT       19
133 #define DT_PLTREL       20
134 #define DT_DEBUG        21
135 #define DT_TEXTREL      22
136 #define DT_JMPREL       23
137 #define DT_LOPROC       0x70000000
138 #define DT_HIPROC       0x7fffffff
139
140 /* This info is needed when parsing the symbol table */
141 #define STB_LOCAL  0
142 #define STB_GLOBAL 1
143 #define STB_WEAK   2
144
145 #define STT_NOTYPE  0
146 #define STT_OBJECT  1
147 #define STT_FUNC    2
148 #define STT_SECTION 3
149 #define STT_FILE    4
150
151 #define ELF_ST_BIND(x)          ((x) >> 4)
152 #define ELF_ST_TYPE(x)          (((unsigned int) x) & 0xf)
153 #define ELF32_ST_BIND(x)        ELF_ST_BIND(x)
154 #define ELF32_ST_TYPE(x)        ELF_ST_TYPE(x)
155 #define ELF64_ST_BIND(x)        ELF_ST_BIND(x)
156 #define ELF64_ST_TYPE(x)        ELF_ST_TYPE(x)
157
158 /* Symbolic values for the entries in the auxiliary table
159    put on the initial stack */
160 #define AT_NULL   0     /* end of vector */
161 #define AT_IGNORE 1     /* entry should be ignored */
162 #define AT_EXECFD 2     /* file descriptor of program */
163 #define AT_PHDR   3     /* program headers for program */
164 #define AT_PHENT  4     /* size of program header entry */
165 #define AT_PHNUM  5     /* number of program headers */
166 #define AT_PAGESZ 6     /* system page size */
167 #define AT_BASE   7     /* base address of interpreter */
168 #define AT_FLAGS  8     /* flags */
169 #define AT_ENTRY  9     /* entry point of program */
170 #define AT_NOTELF 10    /* program is not ELF */
171 #define AT_UID    11    /* real uid */
172 #define AT_EUID   12    /* effective uid */
173 #define AT_GID    13    /* real gid */
174 #define AT_EGID   14    /* effective gid */
175 #define AT_PLATFORM 15  /* string identifying CPU for optimizations */
176 #define AT_HWCAP  16    /* arch dependent hints at CPU capabilities */
177 #define AT_CLKTCK 17    /* frequency at which times() increments */
178
179 #define AT_SECURE 23   /* secure mode boolean */
180
181 typedef struct dynamic{
182   Elf32_Sword d_tag;
183   union{
184     Elf32_Sword d_val;
185     Elf32_Addr  d_ptr;
186   } d_un;
187 } Elf32_Dyn;
188
189 typedef struct {
190   Elf64_Sxword d_tag;           /* entry tag value */
191   union {
192     Elf64_Xword d_val;
193     Elf64_Addr d_ptr;
194   } d_un;
195 } Elf64_Dyn;
196
197 /* The following are used with relocations */
198 #define ELF32_R_SYM(x) ((x) >> 8)
199 #define ELF32_R_TYPE(x) ((x) & 0xff)
200
201 #define ELF64_R_SYM(i)                  ((i) >> 32)
202 #define ELF64_R_TYPE(i)                 ((i) & 0xffffffff)
203
204 typedef struct elf32_rel {
205   Elf32_Addr    r_offset;
206   Elf32_Word    r_info;
207 } Elf32_Rel;
208
209 typedef struct elf64_rel {
210   Elf64_Addr r_offset;  /* Location at which to apply the action */
211   Elf64_Xword r_info;   /* index and type of relocation */
212 } Elf64_Rel;
213
214 typedef struct elf32_rela{
215   Elf32_Addr    r_offset;
216   Elf32_Word    r_info;
217   Elf32_Sword   r_addend;
218 } Elf32_Rela;
219
220 typedef struct elf64_rela {
221   Elf64_Addr r_offset;  /* Location at which to apply the action */
222   Elf64_Xword r_info;   /* index and type of relocation */
223   Elf64_Sxword r_addend;        /* Constant addend used to compute value */
224 } Elf64_Rela;
225
226 typedef struct elf32_sym{
227   Elf32_Word    st_name;
228   Elf32_Addr    st_value;
229   Elf32_Word    st_size;
230   unsigned char st_info;
231   unsigned char st_other;
232   Elf32_Half    st_shndx;
233 } Elf32_Sym;
234
235 typedef struct elf64_sym {
236   Elf64_Word st_name;           /* Symbol name, index in string tbl */
237   unsigned char st_info;        /* Type and binding attributes */
238   unsigned char st_other;       /* No defined meaning, 0 */
239   Elf64_Half st_shndx;          /* Associated section index */
240   Elf64_Addr st_value;          /* Value of the symbol */
241   Elf64_Xword st_size;          /* Associated symbol size */
242 } Elf64_Sym;
243
244
245 #define EI_NIDENT       16
246
247 typedef struct elf32_hdr{
248   unsigned char e_ident[EI_NIDENT];
249   Elf32_Half    e_type;
250   Elf32_Half    e_machine;
251   Elf32_Word    e_version;
252   Elf32_Addr    e_entry;  /* Entry point */
253   Elf32_Off     e_phoff;
254   Elf32_Off     e_shoff;
255   Elf32_Word    e_flags;
256   Elf32_Half    e_ehsize;
257   Elf32_Half    e_phentsize;
258   Elf32_Half    e_phnum;
259   Elf32_Half    e_shentsize;
260   Elf32_Half    e_shnum;
261   Elf32_Half    e_shstrndx;
262 } Elf32_Ehdr;
263
264 typedef struct elf64_hdr {
265   unsigned char e_ident[16];            /* ELF "magic number" */
266   Elf64_Half e_type;
267   Elf64_Half e_machine;
268   Elf64_Word e_version;
269   Elf64_Addr e_entry;           /* Entry point virtual address */
270   Elf64_Off e_phoff;            /* Program header table file offset */
271   Elf64_Off e_shoff;            /* Section header table file offset */
272   Elf64_Word e_flags;
273   Elf64_Half e_ehsize;
274   Elf64_Half e_phentsize;
275   Elf64_Half e_phnum;
276   Elf64_Half e_shentsize;
277   Elf64_Half e_shnum;
278   Elf64_Half e_shstrndx;
279 } Elf64_Ehdr;
280
281 /* These constants define the permissions on sections in the program
282    header, p_flags. */
283 #define PF_R            0x4
284 #define PF_W            0x2
285 #define PF_X            0x1
286
287 typedef struct elf32_phdr{
288   Elf32_Word    p_type;
289   Elf32_Off     p_offset;
290   Elf32_Addr    p_vaddr;
291   Elf32_Addr    p_paddr;
292   Elf32_Word    p_filesz;
293   Elf32_Word    p_memsz;
294   Elf32_Word    p_flags;
295   Elf32_Word    p_align;
296 } Elf32_Phdr;
297
298 typedef struct elf64_phdr {
299   Elf64_Word p_type;
300   Elf64_Word p_flags;
301   Elf64_Off p_offset;           /* Segment file offset */
302   Elf64_Addr p_vaddr;           /* Segment virtual address */
303   Elf64_Addr p_paddr;           /* Segment physical address */
304   Elf64_Xword p_filesz;         /* Segment size in file */
305   Elf64_Xword p_memsz;          /* Segment size in memory */
306   Elf64_Xword p_align;          /* Segment alignment, file & memory */
307 } Elf64_Phdr;
308
309 /* sh_type */
310 #define SHT_NULL        0
311 #define SHT_PROGBITS    1
312 #define SHT_SYMTAB      2
313 #define SHT_STRTAB      3
314 #define SHT_RELA        4
315 #define SHT_HASH        5
316 #define SHT_DYNAMIC     6
317 #define SHT_NOTE        7
318 #define SHT_NOBITS      8
319 #define SHT_REL         9
320 #define SHT_SHLIB       10
321 #define SHT_DYNSYM      11
322 #define SHT_NUM         12
323 #define SHT_LOPROC      0x70000000
324 #define SHT_HIPROC      0x7fffffff
325 #define SHT_LOUSER      0x80000000
326 #define SHT_HIUSER      0xffffffff
327
328 /* sh_flags */
329 #define SHF_WRITE       0x1
330 #define SHF_ALLOC       0x2
331 #define SHF_EXECINSTR   0x4
332 #define SHF_MASKPROC    0xf0000000
333
334 /* special section indexes */
335 #define SHN_UNDEF       0
336 #define SHN_LORESERVE   0xff00
337 #define SHN_LOPROC      0xff00
338 #define SHN_HIPROC      0xff1f
339 #define SHN_ABS         0xfff1
340 #define SHN_COMMON      0xfff2
341 #define SHN_HIRESERVE   0xffff
342  
343 typedef struct {
344   Elf32_Word    sh_name;
345   Elf32_Word    sh_type;
346   Elf32_Word    sh_flags;
347   Elf32_Addr    sh_addr;
348   Elf32_Off     sh_offset;
349   Elf32_Word    sh_size;
350   Elf32_Word    sh_link;
351   Elf32_Word    sh_info;
352   Elf32_Word    sh_addralign;
353   Elf32_Word    sh_entsize;
354 } Elf32_Shdr;
355
356 typedef struct elf64_shdr {
357   Elf64_Word sh_name;           /* Section name, index in string tbl */
358   Elf64_Word sh_type;           /* Type of section */
359   Elf64_Xword sh_flags;         /* Miscellaneous section attributes */
360   Elf64_Addr sh_addr;           /* Section virtual addr at execution */
361   Elf64_Off sh_offset;          /* Section file offset */
362   Elf64_Xword sh_size;          /* Size of section in bytes */
363   Elf64_Word sh_link;           /* Index of another section */
364   Elf64_Word sh_info;           /* Additional section information */
365   Elf64_Xword sh_addralign;     /* Section alignment */
366   Elf64_Xword sh_entsize;       /* Entry size if section holds table */
367 } Elf64_Shdr;
368
369 #define EI_MAG0         0               /* e_ident[] indexes */
370 #define EI_MAG1         1
371 #define EI_MAG2         2
372 #define EI_MAG3         3
373 #define EI_CLASS        4
374 #define EI_DATA         5
375 #define EI_VERSION      6
376 #define EI_OSABI        7
377 #define EI_PAD          8
378
379 #define ELFMAG0         0x7f            /* EI_MAG */
380 #define ELFMAG1         'E'
381 #define ELFMAG2         'L'
382 #define ELFMAG3         'F'
383 #define ELFMAG          "\177ELF"
384 #define SELFMAG         4
385
386 #define ELFCLASSNONE    0               /* EI_CLASS */
387 #define ELFCLASS32      1
388 #define ELFCLASS64      2
389 #define ELFCLASSNUM     3
390
391 #define ELFDATANONE     0               /* e_ident[EI_DATA] */
392 #define ELFDATA2LSB     1
393 #define ELFDATA2MSB     2
394
395 #define EV_NONE         0               /* e_version, EI_VERSION */
396 #define EV_CURRENT      1
397 #define EV_NUM          2
398
399 #define ELFOSABI_NONE   0
400 #define ELFOSABI_LINUX  3
401
402 #ifndef ELF_OSABI
403 #define ELF_OSABI ELFOSABI_NONE
404 #endif
405
406 /* Notes used in ET_CORE */
407 #define NT_PRSTATUS     1
408 #define NT_PRFPREG      2
409 #define NT_PRPSINFO     3
410 #define NT_TASKSTRUCT   4
411 #define NT_AUXV         6
412 #define NT_PRXFPREG     0x46e62b7f      /* copied from gdb5.1/include/elf/common.h */
413
414
415 /* Note header in a PT_NOTE section */
416 typedef struct elf32_note {
417   Elf32_Word    n_namesz;       /* Name size */
418   Elf32_Word    n_descsz;       /* Content size */
419   Elf32_Word    n_type;         /* Content type */
420 } Elf32_Nhdr;
421
422 /* Note header in a PT_NOTE section */
423 typedef struct elf64_note {
424   Elf64_Word n_namesz;  /* Name size */
425   Elf64_Word n_descsz;  /* Content size */
426   Elf64_Word n_type;    /* Content type */
427 } Elf64_Nhdr;
428
429 #if ELF_CLASS == ELFCLASS32
430
431 extern Elf32_Dyn _DYNAMIC [];
432 #define elfhdr          elf32_hdr
433 #define elf_phdr        elf32_phdr
434 #define elf_note        elf32_note
435
436 #else
437
438 extern Elf64_Dyn _DYNAMIC [];
439 #define elfhdr          elf64_hdr
440 #define elf_phdr        elf64_phdr
441 #define elf_note        elf64_note
442
443 #endif
444
445
446 #endif /* _LINUX_ELF_H */