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. */
8typedef __u32	Elf32_Addr;
9typedef __u16	Elf32_Half;
10typedef __u32	Elf32_Off;
11typedef __s32	Elf32_Sword;
12typedef __u32	Elf32_Word;
13
14/* 64-bit ELF base types. */
15typedef __u64	Elf64_Addr;
16typedef __u16	Elf64_Half;
17typedef __s16	Elf64_SHalf;
18typedef __u64	Elf64_Off;
19typedef __s32	Elf64_Sword;
20typedef __u32	Elf64_Word;
21typedef __u64	Elf64_Xword;
22typedef __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_LOPROC  0x70000000
33#define PT_HIPROC  0x7fffffff
34#define PT_MIPS_REGINFO		0x70000000
35#define PT_MIPS_OPTIONS		0x70000001
36
37/* Flags in the e_flags field of the header */
38#define EF_MIPS_NOREORDER 0x00000001
39#define EF_MIPS_PIC       0x00000002
40#define EF_MIPS_CPIC      0x00000004
41#define EF_MIPS_ABI2      0x00000020
42#define EF_MIPS_OPTIONS_FIRST 0x00000080
43#define EF_MIPS_32BITMODE 0x00000100
44#define EF_MIPS_ABI       0x0000f000
45#define EF_MIPS_ARCH      0xf0000000
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_RS3_LE 10	/* MIPS R3000 little-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/*
90 * This is an interim value that we will use until the committee comes
91 * up with a final number.
92 */
93#define EM_ALPHA	0x9026
94
95/*
96 * This is the old interim value for S/390 architecture
97 */
98#define EM_S390_OLD     0xA390
99
100/* This is the info that is needed to parse the dynamic section of the file */
101#define DT_NULL		0
102#define DT_NEEDED	1
103#define DT_PLTRELSZ	2
104#define DT_PLTGOT	3
105#define DT_HASH		4
106#define DT_STRTAB	5
107#define DT_SYMTAB	6
108#define DT_RELA		7
109#define DT_RELASZ	8
110#define DT_RELAENT	9
111#define DT_STRSZ	10
112#define DT_SYMENT	11
113#define DT_INIT		12
114#define DT_FINI		13
115#define DT_SONAME	14
116#define DT_RPATH 	15
117#define DT_SYMBOLIC	16
118#define DT_REL	        17
119#define DT_RELSZ	18
120#define DT_RELENT	19
121#define DT_PLTREL	20
122#define DT_DEBUG	21
123#define DT_TEXTREL	22
124#define DT_JMPREL	23
125#define DT_LOPROC	0x70000000
126#define DT_HIPROC	0x7fffffff
127#define DT_MIPS_RLD_VERSION	0x70000001
128#define DT_MIPS_TIME_STAMP	0x70000002
129#define DT_MIPS_ICHECKSUM	0x70000003
130#define DT_MIPS_IVERSION	0x70000004
131#define DT_MIPS_FLAGS		0x70000005
132  #define RHF_NONE		  0
133  #define RHF_HARDWAY		  1
134  #define RHF_NOTPOT		  2
135#define DT_MIPS_BASE_ADDRESS	0x70000006
136#define DT_MIPS_CONFLICT	0x70000008
137#define DT_MIPS_LIBLIST		0x70000009
138#define DT_MIPS_LOCAL_GOTNO	0x7000000a
139#define DT_MIPS_CONFLICTNO	0x7000000b
140#define DT_MIPS_LIBLISTNO	0x70000010
141#define DT_MIPS_SYMTABNO	0x70000011
142#define DT_MIPS_UNREFEXTNO	0x70000012
143#define DT_MIPS_GOTSYM		0x70000013
144#define DT_MIPS_HIPAGENO	0x70000014
145#define DT_MIPS_RLD_MAP		0x70000016
146
147/* This info is needed when parsing the symbol table */
148#define STB_LOCAL  0
149#define STB_GLOBAL 1
150#define STB_WEAK   2
151
152#define STT_NOTYPE  0
153#define STT_OBJECT  1
154#define STT_FUNC    2
155#define STT_SECTION 3
156#define STT_FILE    4
157
158#define ELF32_ST_BIND(x) ((x) >> 4)
159#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
160
161/* Symbolic values for the entries in the auxiliary table
162   put on the initial stack */
163#define AT_NULL   0	/* end of vector */
164#define AT_IGNORE 1	/* entry should be ignored */
165#define AT_EXECFD 2	/* file descriptor of program */
166#define AT_PHDR   3	/* program headers for program */
167#define AT_PHENT  4	/* size of program header entry */
168#define AT_PHNUM  5	/* number of program headers */
169#define AT_PAGESZ 6	/* system page size */
170#define AT_BASE   7	/* base address of interpreter */
171#define AT_FLAGS  8	/* flags */
172#define AT_ENTRY  9	/* entry point of program */
173#define AT_NOTELF 10	/* program is not ELF */
174#define AT_UID    11	/* real uid */
175#define AT_EUID   12	/* effective uid */
176#define AT_GID    13	/* real gid */
177#define AT_EGID   14	/* effective gid */
178#define AT_PLATFORM 15  /* string identifying CPU for optimizations */
179#define AT_HWCAP  16    /* arch dependent hints at CPU capabilities */
180#define AT_CLKTCK 17	/* frequency at which times() increments */
181
182typedef struct dynamic{
183  Elf32_Sword d_tag;
184  union{
185    Elf32_Sword	d_val;
186    Elf32_Addr	d_ptr;
187  } d_un;
188} Elf32_Dyn;
189
190typedef struct {
191  Elf64_Sxword d_tag;		/* entry tag value */
192  union {
193    Elf64_Xword d_val;
194    Elf64_Addr d_ptr;
195  } d_un;
196} Elf64_Dyn;
197
198/* The following are used with relocations */
199#define ELF32_R_SYM(x) ((x) >> 8)
200#define ELF32_R_TYPE(x) ((x) & 0xff)
201
202#define R_386_NONE	0
203#define R_386_32	1
204#define R_386_PC32	2
205#define R_386_GOT32	3
206#define R_386_PLT32	4
207#define R_386_COPY	5
208#define R_386_GLOB_DAT	6
209#define R_386_JMP_SLOT	7
210#define R_386_RELATIVE	8
211#define R_386_GOTOFF	9
212#define R_386_GOTPC	10
213#define R_386_NUM	11
214
215#define R_MIPS_NONE		0
216#define R_MIPS_16		1
217#define R_MIPS_32		2
218#define R_MIPS_REL32		3
219#define R_MIPS_26		4
220#define R_MIPS_HI16		5
221#define R_MIPS_LO16		6
222#define R_MIPS_GPREL16		7
223#define R_MIPS_LITERAL		8
224#define R_MIPS_GOT16		9
225#define R_MIPS_PC16		10
226#define R_MIPS_CALL16		11
227#define R_MIPS_GPREL32		12
228/* The remaining relocs are defined on Irix, although they are not
229   in the MIPS ELF ABI.  */
230#define R_MIPS_UNUSED1		13
231#define R_MIPS_UNUSED2		14
232#define R_MIPS_UNUSED3		15
233#define R_MIPS_SHIFT5		16
234#define R_MIPS_SHIFT6		17
235#define R_MIPS_64		18
236#define R_MIPS_GOT_DISP		19
237#define R_MIPS_GOT_PAGE		20
238#define R_MIPS_GOT_OFST		21
239/*
240 * The following two relocation types are specified in the MIPS ABI
241 * conformance guide version 1.2 but not yet in the psABI.
242 */
243#define R_MIPS_GOTHI16		22
244#define R_MIPS_GOTLO16		23
245#define R_MIPS_SUB		24
246#define R_MIPS_INSERT_A		25
247#define R_MIPS_INSERT_B		26
248#define R_MIPS_DELETE		27
249#define R_MIPS_HIGHER		28
250#define R_MIPS_HIGHEST		29
251/*
252 * The following two relocation types are specified in the MIPS ABI
253 * conformance guide version 1.2 but not yet in the psABI.
254 */
255#define R_MIPS_CALLHI16		30
256#define R_MIPS_CALLLO16		31
257/*
258 * This range is reserved for vendor specific relocations.
259 */
260#define R_MIPS_LOVENDOR		100
261#define R_MIPS_HIVENDOR		127
262
263
264/*
265 * Sparc ELF relocation types
266 */
267#define	R_SPARC_NONE		0
268#define	R_SPARC_8		1
269#define	R_SPARC_16		2
270#define	R_SPARC_32		3
271#define	R_SPARC_DISP8		4
272#define	R_SPARC_DISP16		5
273#define	R_SPARC_DISP32		6
274#define	R_SPARC_WDISP30		7
275#define	R_SPARC_WDISP22		8
276#define	R_SPARC_HI22		9
277#define	R_SPARC_22		10
278#define	R_SPARC_13		11
279#define	R_SPARC_LO10		12
280#define	R_SPARC_GOT10		13
281#define	R_SPARC_GOT13		14
282#define	R_SPARC_GOT22		15
283#define	R_SPARC_PC10		16
284#define	R_SPARC_PC22		17
285#define	R_SPARC_WPLT30		18
286#define	R_SPARC_COPY		19
287#define	R_SPARC_GLOB_DAT	20
288#define	R_SPARC_JMP_SLOT	21
289#define	R_SPARC_RELATIVE	22
290#define	R_SPARC_UA32		23
291#define R_SPARC_PLT32		24
292#define R_SPARC_HIPLT22		25
293#define R_SPARC_LOPLT10		26
294#define R_SPARC_PCPLT32		27
295#define R_SPARC_PCPLT22		28
296#define R_SPARC_PCPLT10		29
297#define R_SPARC_10		30
298#define R_SPARC_11		31
299#define R_SPARC_WDISP16		40
300#define R_SPARC_WDISP19		41
301#define R_SPARC_7		43
302#define R_SPARC_5		44
303#define R_SPARC_6		45
304
305/* Bits present in AT_HWCAP, primarily for Sparc32.  */
306
307#define HWCAP_SPARC_FLUSH       1    /* CPU supports flush instruction. */
308#define HWCAP_SPARC_STBAR       2
309#define HWCAP_SPARC_SWAP        4
310#define HWCAP_SPARC_MULDIV      8
311#define HWCAP_SPARC_V9		16
312#define HWCAP_SPARC_ULTRA3	32
313
314/*
315 * 68k ELF relocation types
316 */
317#define R_68K_NONE	0
318#define R_68K_32	1
319#define R_68K_16	2
320#define R_68K_8		3
321#define R_68K_PC32	4
322#define R_68K_PC16	5
323#define R_68K_PC8	6
324#define R_68K_GOT32	7
325#define R_68K_GOT16	8
326#define R_68K_GOT8	9
327#define R_68K_GOT32O	10
328#define R_68K_GOT16O	11
329#define R_68K_GOT8O	12
330#define R_68K_PLT32	13
331#define R_68K_PLT16	14
332#define R_68K_PLT8	15
333#define R_68K_PLT32O	16
334#define R_68K_PLT16O	17
335#define R_68K_PLT8O	18
336#define R_68K_COPY	19
337#define R_68K_GLOB_DAT	20
338#define R_68K_JMP_SLOT	21
339#define R_68K_RELATIVE	22
340
341/*
342 * Alpha ELF relocation types
343 */
344#define R_ALPHA_NONE            0       /* No reloc */
345#define R_ALPHA_REFLONG         1       /* Direct 32 bit */
346#define R_ALPHA_REFQUAD         2       /* Direct 64 bit */
347#define R_ALPHA_GPREL32         3       /* GP relative 32 bit */
348#define R_ALPHA_LITERAL         4       /* GP relative 16 bit w/optimization */
349#define R_ALPHA_LITUSE          5       /* Optimization hint for LITERAL */
350#define R_ALPHA_GPDISP          6       /* Add displacement to GP */
351#define R_ALPHA_BRADDR          7       /* PC+4 relative 23 bit shifted */
352#define R_ALPHA_HINT            8       /* PC+4 relative 16 bit shifted */
353#define R_ALPHA_SREL16          9       /* PC relative 16 bit */
354#define R_ALPHA_SREL32          10      /* PC relative 32 bit */
355#define R_ALPHA_SREL64          11      /* PC relative 64 bit */
356#define R_ALPHA_OP_PUSH         12      /* OP stack push */
357#define R_ALPHA_OP_STORE        13      /* OP stack pop and store */
358#define R_ALPHA_OP_PSUB         14      /* OP stack subtract */
359#define R_ALPHA_OP_PRSHIFT      15      /* OP stack right shift */
360#define R_ALPHA_GPVALUE         16
361#define R_ALPHA_GPRELHIGH       17
362#define R_ALPHA_GPRELLOW        18
363#define R_ALPHA_IMMED_GP_16     19
364#define R_ALPHA_IMMED_GP_HI32   20
365#define R_ALPHA_IMMED_SCN_HI32  21
366#define R_ALPHA_IMMED_BR_HI32   22
367#define R_ALPHA_IMMED_LO32      23
368#define R_ALPHA_COPY            24      /* Copy symbol at runtime */
369#define R_ALPHA_GLOB_DAT        25      /* Create GOT entry */
370#define R_ALPHA_JMP_SLOT        26      /* Create PLT entry */
371#define R_ALPHA_RELATIVE        27      /* Adjust by program base */
372
373/* Legal values for e_flags field of Elf64_Ehdr.  */
374
375#define EF_ALPHA_32BIT		1	/* All addresses are below 2GB */
376
377
378typedef struct elf32_rel {
379  Elf32_Addr	r_offset;
380  Elf32_Word	r_info;
381} Elf32_Rel;
382
383typedef struct elf64_rel {
384  Elf64_Addr r_offset;	/* Location at which to apply the action */
385  Elf64_Xword r_info;	/* index and type of relocation */
386} Elf64_Rel;
387
388typedef struct elf32_rela{
389  Elf32_Addr	r_offset;
390  Elf32_Word	r_info;
391  Elf32_Sword	r_addend;
392} Elf32_Rela;
393
394typedef struct elf64_rela {
395  Elf64_Addr r_offset;	/* Location at which to apply the action */
396  Elf64_Xword r_info;	/* index and type of relocation */
397  Elf64_Sxword r_addend;	/* Constant addend used to compute value */
398} Elf64_Rela;
399
400typedef struct elf32_sym{
401  Elf32_Word	st_name;
402  Elf32_Addr	st_value;
403  Elf32_Word	st_size;
404  unsigned char	st_info;
405  unsigned char	st_other;
406  Elf32_Half	st_shndx;
407} Elf32_Sym;
408
409typedef struct elf64_sym {
410  Elf64_Word st_name;		/* Symbol name, index in string tbl */
411  unsigned char	st_info;	/* Type and binding attributes */
412  unsigned char	st_other;	/* No defined meaning, 0 */
413  Elf64_Half st_shndx;		/* Associated section index */
414  Elf64_Addr st_value;		/* Value of the symbol */
415  Elf64_Xword st_size;		/* Associated symbol size */
416} Elf64_Sym;
417
418
419#define EI_NIDENT	16
420
421typedef struct elf32_hdr{
422  unsigned char	e_ident[EI_NIDENT];
423  Elf32_Half	e_type;
424  Elf32_Half	e_machine;
425  Elf32_Word	e_version;
426  Elf32_Addr	e_entry;  /* Entry point */
427  Elf32_Off	e_phoff;
428  Elf32_Off	e_shoff;
429  Elf32_Word	e_flags;
430  Elf32_Half	e_ehsize;
431  Elf32_Half	e_phentsize;
432  Elf32_Half	e_phnum;
433  Elf32_Half	e_shentsize;
434  Elf32_Half	e_shnum;
435  Elf32_Half	e_shstrndx;
436} Elf32_Ehdr;
437
438typedef struct elf64_hdr {
439  unsigned char	e_ident[16];		/* ELF "magic number" */
440  Elf64_Half e_type;
441  Elf64_Half e_machine;
442  Elf64_Word e_version;
443  Elf64_Addr e_entry;		/* Entry point virtual address */
444  Elf64_Off e_phoff;		/* Program header table file offset */
445  Elf64_Off e_shoff;		/* Section header table file offset */
446  Elf64_Word e_flags;
447  Elf64_Half e_ehsize;
448  Elf64_Half e_phentsize;
449  Elf64_Half e_phnum;
450  Elf64_Half e_shentsize;
451  Elf64_Half e_shnum;
452  Elf64_Half e_shstrndx;
453} Elf64_Ehdr;
454
455/* These constants define the permissions on sections in the program
456   header, p_flags. */
457#define PF_R		0x4
458#define PF_W		0x2
459#define PF_X		0x1
460
461typedef struct elf32_phdr{
462  Elf32_Word	p_type;
463  Elf32_Off	p_offset;
464  Elf32_Addr	p_vaddr;
465  Elf32_Addr	p_paddr;
466  Elf32_Word	p_filesz;
467  Elf32_Word	p_memsz;
468  Elf32_Word	p_flags;
469  Elf32_Word	p_align;
470} Elf32_Phdr;
471
472typedef struct elf64_phdr {
473  Elf64_Word p_type;
474  Elf64_Word p_flags;
475  Elf64_Off p_offset;		/* Segment file offset */
476  Elf64_Addr p_vaddr;		/* Segment virtual address */
477  Elf64_Addr p_paddr;		/* Segment physical address */
478  Elf64_Xword p_filesz;		/* Segment size in file */
479  Elf64_Xword p_memsz;		/* Segment size in memory */
480  Elf64_Xword p_align;		/* Segment alignment, file & memory */
481} Elf64_Phdr;
482
483/* sh_type */
484#define SHT_NULL	0
485#define SHT_PROGBITS	1
486#define SHT_SYMTAB	2
487#define SHT_STRTAB	3
488#define SHT_RELA	4
489#define SHT_HASH	5
490#define SHT_DYNAMIC	6
491#define SHT_NOTE	7
492#define SHT_NOBITS	8
493#define SHT_REL		9
494#define SHT_SHLIB	10
495#define SHT_DYNSYM	11
496#define SHT_NUM		12
497#define SHT_LOPROC	0x70000000
498#define SHT_HIPROC	0x7fffffff
499#define SHT_LOUSER	0x80000000
500#define SHT_HIUSER	0xffffffff
501#define SHT_MIPS_LIST		0x70000000
502#define SHT_MIPS_CONFLICT	0x70000002
503#define SHT_MIPS_GPTAB		0x70000003
504#define SHT_MIPS_UCODE		0x70000004
505
506/* sh_flags */
507#define SHF_WRITE	0x1
508#define SHF_ALLOC	0x2
509#define SHF_EXECINSTR	0x4
510#define SHF_MASKPROC	0xf0000000
511#define SHF_MIPS_GPREL	0x10000000
512
513/* special section indexes */
514#define SHN_UNDEF	0
515#define SHN_LORESERVE	0xff00
516#define SHN_LOPROC	0xff00
517#define SHN_HIPROC	0xff1f
518#define SHN_ABS		0xfff1
519#define SHN_COMMON	0xfff2
520#define SHN_HIRESERVE	0xffff
521#define SHN_MIPS_ACCOMON	0xff00
522
523typedef struct {
524  Elf32_Word	sh_name;
525  Elf32_Word	sh_type;
526  Elf32_Word	sh_flags;
527  Elf32_Addr	sh_addr;
528  Elf32_Off	sh_offset;
529  Elf32_Word	sh_size;
530  Elf32_Word	sh_link;
531  Elf32_Word	sh_info;
532  Elf32_Word	sh_addralign;
533  Elf32_Word	sh_entsize;
534} Elf32_Shdr;
535
536typedef struct elf64_shdr {
537  Elf64_Word sh_name;		/* Section name, index in string tbl */
538  Elf64_Word sh_type;		/* Type of section */
539  Elf64_Xword sh_flags;		/* Miscellaneous section attributes */
540  Elf64_Addr sh_addr;		/* Section virtual addr at execution */
541  Elf64_Off sh_offset;		/* Section file offset */
542  Elf64_Xword sh_size;		/* Size of section in bytes */
543  Elf64_Word sh_link;		/* Index of another section */
544  Elf64_Word sh_info;		/* Additional section information */
545  Elf64_Xword sh_addralign;	/* Section alignment */
546  Elf64_Xword sh_entsize;	/* Entry size if section holds table */
547} Elf64_Shdr;
548
549#define	EI_MAG0		0		/* e_ident[] indexes */
550#define	EI_MAG1		1
551#define	EI_MAG2		2
552#define	EI_MAG3		3
553#define	EI_CLASS	4
554#define	EI_DATA		5
555#define	EI_VERSION	6
556#define	EI_PAD		7
557
558#define	ELFMAG0		0x7f		/* EI_MAG */
559#define	ELFMAG1		'E'
560#define	ELFMAG2		'L'
561#define	ELFMAG3		'F'
562#define	ELFMAG		"\177ELF"
563#define	SELFMAG		4
564
565#define	ELFCLASSNONE	0		/* EI_CLASS */
566#define	ELFCLASS32	1
567#define	ELFCLASS64	2
568#define	ELFCLASSNUM	3
569
570#define ELFDATANONE	0		/* e_ident[EI_DATA] */
571#define ELFDATA2LSB	1
572#define ELFDATA2MSB	2
573
574#define EV_NONE		0		/* e_version, EI_VERSION */
575#define EV_CURRENT	1
576#define EV_NUM		2
577
578/* Notes used in ET_CORE */
579#define NT_PRSTATUS	1
580#define NT_PRFPREG	2
581#define NT_PRPSINFO	3
582#define NT_TASKSTRUCT	4
583#define NT_PRFPXREG	20
584
585/* Note header in a PT_NOTE section */
586typedef struct elf32_note {
587  Elf32_Word	n_namesz;	/* Name size */
588  Elf32_Word	n_descsz;	/* Content size */
589  Elf32_Word	n_type;		/* Content type */
590} Elf32_Nhdr;
591
592/* Note header in a PT_NOTE section */
593typedef struct elf64_note {
594  Elf64_Word n_namesz;	/* Name size */
595  Elf64_Word n_descsz;	/* Content size */
596  Elf64_Word n_type;	/* Content type */
597} Elf64_Nhdr;
598
599#if ELF_CLASS == ELFCLASS32
600
601extern Elf32_Dyn _DYNAMIC [];
602#define elfhdr		elf32_hdr
603#define elf_phdr	elf32_phdr
604#define elf_note	elf32_note
605
606#else
607
608extern Elf64_Dyn _DYNAMIC [];
609#define elfhdr		elf64_hdr
610#define elf_phdr	elf64_phdr
611#define elf_note	elf64_note
612
613#endif
614
615
616#endif /* _LINUX_ELF_H */
617