pre-2.3.4..
[davej-history.git] / include / linux / elf.h
blob7c0c6542fd520b52f0a8a348e309f70bd634dfc1
1 #ifndef _LINUX_ELF_H
2 #define _LINUX_ELF_H
4 #include <linux/types.h>
5 #include <asm/elf.h>
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;
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 __s64 Elf64_Sword;
20 typedef __u64 Elf64_Word;
22 /* These constants are for the segment types stored in the image headers */
23 #define PT_NULL 0
24 #define PT_LOAD 1
25 #define PT_DYNAMIC 2
26 #define PT_INTERP 3
27 #define PT_NOTE 4
28 #define PT_SHLIB 5
29 #define PT_PHDR 6
30 #define PT_LOPROC 0x70000000
31 #define PT_HIPROC 0x7fffffff
33 /* These constants define the different elf file types */
34 #define ET_NONE 0
35 #define ET_REL 1
36 #define ET_EXEC 2
37 #define ET_DYN 3
38 #define ET_CORE 4
39 #define ET_LOPROC 5
40 #define ET_HIPROC 6
42 /* These constants define the various ELF target machines */
43 #define EM_NONE 0
44 #define EM_M32 1
45 #define EM_SPARC 2
46 #define EM_386 3
47 #define EM_68K 4
48 #define EM_88K 5
49 #define EM_486 6 /* Perhaps disused */
50 #define EM_860 7
52 #define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */
54 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
56 #define EM_PARISC 15 /* HPPA */
58 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
60 #define EM_PPC 20 /* PowerPC */
62 #define EM_SPARCV9 43 /* SPARC v9 64-bit */
65 * This is an interim value that we will use until the committee comes
66 * up with a final number.
68 #define EM_ALPHA 0x9026
71 /* This is the info that is needed to parse the dynamic section of the file */
72 #define DT_NULL 0
73 #define DT_NEEDED 1
74 #define DT_PLTRELSZ 2
75 #define DT_PLTGOT 3
76 #define DT_HASH 4
77 #define DT_STRTAB 5
78 #define DT_SYMTAB 6
79 #define DT_RELA 7
80 #define DT_RELASZ 8
81 #define DT_RELAENT 9
82 #define DT_STRSZ 10
83 #define DT_SYMENT 11
84 #define DT_INIT 12
85 #define DT_FINI 13
86 #define DT_SONAME 14
87 #define DT_RPATH 15
88 #define DT_SYMBOLIC 16
89 #define DT_REL 17
90 #define DT_RELSZ 18
91 #define DT_RELENT 19
92 #define DT_PLTREL 20
93 #define DT_DEBUG 21
94 #define DT_TEXTREL 22
95 #define DT_JMPREL 23
96 #define DT_LOPROC 0x70000000
97 #define DT_HIPROC 0x7fffffff
99 /* This info is needed when parsing the symbol table */
100 #define STB_LOCAL 0
101 #define STB_GLOBAL 1
102 #define STB_WEAK 2
104 #define STT_NOTYPE 0
105 #define STT_OBJECT 1
106 #define STT_FUNC 2
107 #define STT_SECTION 3
108 #define STT_FILE 4
110 #define ELF32_ST_BIND(x) ((x) >> 4)
111 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
113 /* Symbolic values for the entries in the auxiliary table
114 put on the initial stack */
115 #define AT_NULL 0 /* end of vector */
116 #define AT_IGNORE 1 /* entry should be ignored */
117 #define AT_EXECFD 2 /* file descriptor of program */
118 #define AT_PHDR 3 /* program headers for program */
119 #define AT_PHENT 4 /* size of program header entry */
120 #define AT_PHNUM 5 /* number of program headers */
121 #define AT_PAGESZ 6 /* system page size */
122 #define AT_BASE 7 /* base address of interpreter */
123 #define AT_FLAGS 8 /* flags */
124 #define AT_ENTRY 9 /* entry point of program */
125 #define AT_NOTELF 10 /* program is not ELF */
126 #define AT_UID 11 /* real uid */
127 #define AT_EUID 12 /* effective uid */
128 #define AT_GID 13 /* real gid */
129 #define AT_EGID 14 /* effective gid */
130 #define AT_PLATFORM 15 /* string identifying CPU for optimizations */
131 #define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
133 typedef struct dynamic{
134 Elf32_Sword d_tag;
135 union{
136 Elf32_Sword d_val;
137 Elf32_Addr d_ptr;
138 } d_un;
139 } Elf32_Dyn;
141 typedef struct {
142 Elf64_Word d_tag; /* entry tag value */
143 union {
144 Elf64_Word d_val;
145 Elf64_Word d_ptr;
146 } d_un;
147 } Elf64_Dyn;
149 /* The following are used with relocations */
150 #define ELF32_R_SYM(x) ((x) >> 8)
151 #define ELF32_R_TYPE(x) ((x) & 0xff)
153 #define R_386_NONE 0
154 #define R_386_32 1
155 #define R_386_PC32 2
156 #define R_386_GOT32 3
157 #define R_386_PLT32 4
158 #define R_386_COPY 5
159 #define R_386_GLOB_DAT 6
160 #define R_386_JMP_SLOT 7
161 #define R_386_RELATIVE 8
162 #define R_386_GOTOFF 9
163 #define R_386_GOTPC 10
164 #define R_386_NUM 11
167 * Sparc ELF relocation types
169 #define R_SPARC_NONE 0
170 #define R_SPARC_8 1
171 #define R_SPARC_16 2
172 #define R_SPARC_32 3
173 #define R_SPARC_DISP8 4
174 #define R_SPARC_DISP16 5
175 #define R_SPARC_DISP32 6
176 #define R_SPARC_WDISP30 7
177 #define R_SPARC_WDISP22 8
178 #define R_SPARC_HI22 9
179 #define R_SPARC_22 10
180 #define R_SPARC_13 11
181 #define R_SPARC_LO10 12
182 #define R_SPARC_GOT10 13
183 #define R_SPARC_GOT13 14
184 #define R_SPARC_GOT22 15
185 #define R_SPARC_PC10 16
186 #define R_SPARC_PC22 17
187 #define R_SPARC_WPLT30 18
188 #define R_SPARC_COPY 19
189 #define R_SPARC_GLOB_DAT 20
190 #define R_SPARC_JMP_SLOT 21
191 #define R_SPARC_RELATIVE 22
192 #define R_SPARC_UA32 23
193 #define R_SPARC_PLT32 24
194 #define R_SPARC_HIPLT22 25
195 #define R_SPARC_LOPLT10 26
196 #define R_SPARC_PCPLT32 27
197 #define R_SPARC_PCPLT22 28
198 #define R_SPARC_PCPLT10 29
199 #define R_SPARC_10 30
200 #define R_SPARC_11 31
201 #define R_SPARC_WDISP16 40
202 #define R_SPARC_WDISP19 41
203 #define R_SPARC_7 43
204 #define R_SPARC_5 44
205 #define R_SPARC_6 45
207 /* Bits present in AT_HWCAP, primarily for Sparc32. */
209 #define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
210 #define HWCAP_SPARC_STBAR 2
211 #define HWCAP_SPARC_SWAP 4
212 #define HWCAP_SPARC_MULDIV 8
213 #define HWCAP_SPARC_V9 16
217 * 68k ELF relocation types
219 #define R_68K_NONE 0
220 #define R_68K_32 1
221 #define R_68K_16 2
222 #define R_68K_8 3
223 #define R_68K_PC32 4
224 #define R_68K_PC16 5
225 #define R_68K_PC8 6
226 #define R_68K_GOT32 7
227 #define R_68K_GOT16 8
228 #define R_68K_GOT8 9
229 #define R_68K_GOT32O 10
230 #define R_68K_GOT16O 11
231 #define R_68K_GOT8O 12
232 #define R_68K_PLT32 13
233 #define R_68K_PLT16 14
234 #define R_68K_PLT8 15
235 #define R_68K_PLT32O 16
236 #define R_68K_PLT16O 17
237 #define R_68K_PLT8O 18
238 #define R_68K_COPY 19
239 #define R_68K_GLOB_DAT 20
240 #define R_68K_JMP_SLOT 21
241 #define R_68K_RELATIVE 22
244 * Alpha ELF relocation types
246 #define R_ALPHA_NONE 0 /* No reloc */
247 #define R_ALPHA_REFLONG 1 /* Direct 32 bit */
248 #define R_ALPHA_REFQUAD 2 /* Direct 64 bit */
249 #define R_ALPHA_GPREL32 3 /* GP relative 32 bit */
250 #define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */
251 #define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */
252 #define R_ALPHA_GPDISP 6 /* Add displacement to GP */
253 #define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */
254 #define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */
255 #define R_ALPHA_SREL16 9 /* PC relative 16 bit */
256 #define R_ALPHA_SREL32 10 /* PC relative 32 bit */
257 #define R_ALPHA_SREL64 11 /* PC relative 64 bit */
258 #define R_ALPHA_OP_PUSH 12 /* OP stack push */
259 #define R_ALPHA_OP_STORE 13 /* OP stack pop and store */
260 #define R_ALPHA_OP_PSUB 14 /* OP stack subtract */
261 #define R_ALPHA_OP_PRSHIFT 15 /* OP stack right shift */
262 #define R_ALPHA_GPVALUE 16
263 #define R_ALPHA_GPRELHIGH 17
264 #define R_ALPHA_GPRELLOW 18
265 #define R_ALPHA_IMMED_GP_16 19
266 #define R_ALPHA_IMMED_GP_HI32 20
267 #define R_ALPHA_IMMED_SCN_HI32 21
268 #define R_ALPHA_IMMED_BR_HI32 22
269 #define R_ALPHA_IMMED_LO32 23
270 #define R_ALPHA_COPY 24 /* Copy symbol at runtime */
271 #define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */
272 #define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */
273 #define R_ALPHA_RELATIVE 27 /* Adjust by program base */
275 /* Legal values for e_flags field of Elf64_Ehdr. */
277 #define EF_ALPHA_32BIT 1 /* All addresses are below 2GB */
280 typedef struct elf32_rel {
281 Elf32_Addr r_offset;
282 Elf32_Word r_info;
283 } Elf32_Rel;
285 typedef struct elf64_rel {
286 Elf64_Addr r_offset; /* Location at which to apply the action */
287 Elf64_Word r_info; /* index and type of relocation */
288 } Elf64_Rel;
290 typedef struct elf32_rela{
291 Elf32_Addr r_offset;
292 Elf32_Word r_info;
293 Elf32_Sword r_addend;
294 } Elf32_Rela;
296 typedef struct elf64_rela {
297 Elf64_Addr r_offset; /* Location at which to apply the action */
298 Elf64_Word r_info; /* index and type of relocation */
299 Elf64_Word r_addend; /* Constant addend used to compute value */
300 } Elf64_Rela;
302 typedef struct elf32_sym{
303 Elf32_Word st_name;
304 Elf32_Addr st_value;
305 Elf32_Word st_size;
306 unsigned char st_info;
307 unsigned char st_other;
308 Elf32_Half st_shndx;
309 } Elf32_Sym;
311 typedef struct elf64_sym {
312 Elf32_Word st_name; /* Symbol name, index in string tbl (yes, Elf32) */
313 unsigned char st_info; /* Type and binding attributes */
314 unsigned char st_other; /* No defined meaning, 0 */
315 Elf64_Half st_shndx; /* Associated section index */
316 Elf64_Addr st_value; /* Value of the symbol */
317 Elf64_Word st_size; /* Associated symbol size */
318 } Elf64_Sym;
321 #define EI_NIDENT 16
323 typedef struct elf32_hdr{
324 unsigned char e_ident[EI_NIDENT];
325 Elf32_Half e_type;
326 Elf32_Half e_machine;
327 Elf32_Word e_version;
328 Elf32_Addr e_entry; /* Entry point */
329 Elf32_Off e_phoff;
330 Elf32_Off e_shoff;
331 Elf32_Word e_flags;
332 Elf32_Half e_ehsize;
333 Elf32_Half e_phentsize;
334 Elf32_Half e_phnum;
335 Elf32_Half e_shentsize;
336 Elf32_Half e_shnum;
337 Elf32_Half e_shstrndx;
338 } Elf32_Ehdr;
340 typedef struct elf64_hdr {
341 unsigned char e_ident[16]; /* ELF "magic number" */
342 Elf64_SHalf e_type;
343 Elf64_Half e_machine;
344 __s32 e_version;
345 Elf64_Addr e_entry; /* Entry point virtual address */
346 Elf64_Off e_phoff; /* Program header table file offset */
347 Elf64_Off e_shoff; /* Section header table file offset */
348 __s32 e_flags;
349 Elf64_SHalf e_ehsize;
350 Elf64_SHalf e_phentsize;
351 Elf64_SHalf e_phnum;
352 Elf64_SHalf e_shentsize;
353 Elf64_SHalf e_shnum;
354 Elf64_SHalf e_shstrndx;
355 } Elf64_Ehdr;
357 /* These constants define the permissions on sections in the program
358 header, p_flags. */
359 #define PF_R 0x4
360 #define PF_W 0x2
361 #define PF_X 0x1
363 typedef struct elf32_phdr{
364 Elf32_Word p_type;
365 Elf32_Off p_offset;
366 Elf32_Addr p_vaddr;
367 Elf32_Addr p_paddr;
368 Elf32_Word p_filesz;
369 Elf32_Word p_memsz;
370 Elf32_Word p_flags;
371 Elf32_Word p_align;
372 } Elf32_Phdr;
374 typedef struct elf64_phdr {
375 __s32 p_type;
376 __s32 p_flags;
377 Elf64_Off p_offset; /* Segment file offset */
378 Elf64_Addr p_vaddr; /* Segment virtual address */
379 Elf64_Addr p_paddr; /* Segment physical address */
380 Elf64_Word p_filesz; /* Segment size in file */
381 Elf64_Word p_memsz; /* Segment size in memory */
382 Elf64_Word p_align; /* Segment alignment, file & memory */
383 } Elf64_Phdr;
385 /* sh_type */
386 #define SHT_NULL 0
387 #define SHT_PROGBITS 1
388 #define SHT_SYMTAB 2
389 #define SHT_STRTAB 3
390 #define SHT_RELA 4
391 #define SHT_HASH 5
392 #define SHT_DYNAMIC 6
393 #define SHT_NOTE 7
394 #define SHT_NOBITS 8
395 #define SHT_REL 9
396 #define SHT_SHLIB 10
397 #define SHT_DYNSYM 11
398 #define SHT_NUM 12
399 #define SHT_LOPROC 0x70000000
400 #define SHT_HIPROC 0x7fffffff
401 #define SHT_LOUSER 0x80000000
402 #define SHT_HIUSER 0xffffffff
404 /* sh_flags */
405 #define SHF_WRITE 0x1
406 #define SHF_ALLOC 0x2
407 #define SHF_EXECINSTR 0x4
408 #define SHF_MASKPROC 0xf0000000
410 /* special section indexes */
411 #define SHN_UNDEF 0
412 #define SHN_LORESERVE 0xff00
413 #define SHN_LOPROC 0xff00
414 #define SHN_HIPROC 0xff1f
415 #define SHN_ABS 0xfff1
416 #define SHN_COMMON 0xfff2
417 #define SHN_HIRESERVE 0xffff
419 typedef struct {
420 Elf32_Word sh_name;
421 Elf32_Word sh_type;
422 Elf32_Word sh_flags;
423 Elf32_Addr sh_addr;
424 Elf32_Off sh_offset;
425 Elf32_Word sh_size;
426 Elf32_Word sh_link;
427 Elf32_Word sh_info;
428 Elf32_Word sh_addralign;
429 Elf32_Word sh_entsize;
430 } Elf32_Shdr;
432 typedef struct elf64_shdr {
433 Elf32_Word sh_name; /* Section name, index in string tbl (yes Elf32) */
434 Elf32_Word sh_type; /* Type of section (yes Elf32) */
435 Elf64_Word sh_flags; /* Miscellaneous section attributes */
436 Elf64_Addr sh_addr; /* Section virtual addr at execution */
437 Elf64_Off sh_offset; /* Section file offset */
438 Elf64_Word sh_size; /* Size of section in bytes */
439 Elf32_Word sh_link; /* Index of another section (yes Elf32) */
440 Elf32_Word sh_info; /* Additional section information (yes Elf32) */
441 Elf64_Word sh_addralign; /* Section alignment */
442 Elf64_Word sh_entsize; /* Entry size if section holds table */
443 } Elf64_Shdr;
445 #define EI_MAG0 0 /* e_ident[] indexes */
446 #define EI_MAG1 1
447 #define EI_MAG2 2
448 #define EI_MAG3 3
449 #define EI_CLASS 4
450 #define EI_DATA 5
451 #define EI_VERSION 6
452 #define EI_PAD 7
454 #define ELFMAG0 0x7f /* EI_MAG */
455 #define ELFMAG1 'E'
456 #define ELFMAG2 'L'
457 #define ELFMAG3 'F'
458 #define ELFMAG "\177ELF"
459 #define SELFMAG 4
461 #define ELFCLASSNONE 0 /* EI_CLASS */
462 #define ELFCLASS32 1
463 #define ELFCLASS64 2
464 #define ELFCLASSNUM 3
466 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
467 #define ELFDATA2LSB 1
468 #define ELFDATA2MSB 2
470 #define EV_NONE 0 /* e_version, EI_VERSION */
471 #define EV_CURRENT 1
472 #define EV_NUM 2
474 /* Notes used in ET_CORE */
475 #define NT_PRSTATUS 1
476 #define NT_PRFPREG 2
477 #define NT_PRPSINFO 3
478 #define NT_TASKSTRUCT 4
480 /* Note header in a PT_NOTE section */
481 typedef struct elf32_note {
482 Elf32_Word n_namesz; /* Name size */
483 Elf32_Word n_descsz; /* Content size */
484 Elf32_Word n_type; /* Content type */
485 } Elf32_Nhdr;
487 /* Note header in a PT_NOTE section */
489 * For now we use the 32 bit version of the structure until we figure
490 * out whether we need anything better. Note - on the Alpha, "unsigned int"
491 * is only 32 bits.
493 typedef struct elf64_note {
494 Elf32_Word n_namesz; /* Name size */
495 Elf32_Word n_descsz; /* Content size */
496 Elf32_Word n_type; /* Content type */
497 } Elf64_Nhdr;
499 #if ELF_CLASS == ELFCLASS32
501 extern Elf32_Dyn _DYNAMIC [];
502 #define elfhdr elf32_hdr
503 #define elf_phdr elf32_phdr
504 #define elf_note elf32_note
506 #else
508 extern Elf64_Dyn _DYNAMIC [];
509 #define elfhdr elf64_hdr
510 #define elf_phdr elf64_phdr
511 #define elf_note elf64_note
513 #endif
516 #endif /* _LINUX_ELF_H */