Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

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