4 #include <linux/types.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 __s32 Elf64_Sword;
20 typedef __u32 Elf64_Word;
21 typedef __u64 Elf64_Xword;
22 typedef __s64 Elf64_Sxword;
24 /* These constants are for the segment types stored in the image headers */
32 #define PT_LOPROC 0x70000000
33 #define PT_HIPROC 0x7fffffff
34 #define PT_MIPS_REGINFO 0x70000000
36 /* Flags in the e_flags field of the header */
37 #define EF_MIPS_NOREORDER 0x00000001
38 #define EF_MIPS_PIC 0x00000002
39 #define EF_MIPS_CPIC 0x00000004
40 #define EF_MIPS_ARCH 0xf0000000
42 /* These constants define the different elf file types */
48 #define ET_LOPROC 0xff00
49 #define ET_HIPROC 0xffff
51 /* These constants define the various ELF target machines */
58 #define EM_486 6 /* Perhaps disused */
61 #define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */
63 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
65 #define EM_PARISC 15 /* HPPA */
67 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
69 #define EM_PPC 20 /* PowerPC */
70 #define EM_PPC64 21 /* PowerPC64 */
72 #define EM_SH 42 /* SuperH */
74 #define EM_SPARCV9 43 /* SPARC v9 64-bit */
76 #define EM_IA_64 50 /* HP/Intel IA-64 */
78 #define EM_X86_64 62 /* AMD x86-64 */
80 #define EM_S390 22 /* IBM S/390 */
82 #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
85 * This is an interim value that we will use until the committee comes
86 * up with a final number.
88 #define EM_ALPHA 0x9026
91 * This is the old interim value for S/390 architecture
93 #define EM_S390_OLD 0xA390
95 /* This is the info that is needed to parse the dynamic section of the file */
112 #define DT_SYMBOLIC 16
118 #define DT_TEXTREL 22
120 #define DT_LOPROC 0x70000000
121 #define DT_HIPROC 0x7fffffff
122 #define DT_MIPS_RLD_VERSION 0x70000001
123 #define DT_MIPS_TIME_STAMP 0x70000002
124 #define DT_MIPS_ICHECKSUM 0x70000003
125 #define DT_MIPS_IVERSION 0x70000004
126 #define DT_MIPS_FLAGS 0x70000005
128 #define RHF_HARDWAY 1
130 #define DT_MIPS_BASE_ADDRESS 0x70000006
131 #define DT_MIPS_CONFLICT 0x70000008
132 #define DT_MIPS_LIBLIST 0x70000009
133 #define DT_MIPS_LOCAL_GOTNO 0x7000000a
134 #define DT_MIPS_CONFLICTNO 0x7000000b
135 #define DT_MIPS_LIBLISTNO 0x70000010
136 #define DT_MIPS_SYMTABNO 0x70000011
137 #define DT_MIPS_UNREFEXTNO 0x70000012
138 #define DT_MIPS_GOTSYM 0x70000013
139 #define DT_MIPS_HIPAGENO 0x70000014
140 #define DT_MIPS_RLD_MAP 0x70000016
142 /* This info is needed when parsing the symbol table */
150 #define STT_SECTION 3
153 #define ELF32_ST_BIND(x) ((x) >> 4)
154 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
156 /* Symbolic values for the entries in the auxiliary table
157 put on the initial stack */
158 #define AT_NULL 0 /* end of vector */
159 #define AT_IGNORE 1 /* entry should be ignored */
160 #define AT_EXECFD 2 /* file descriptor of program */
161 #define AT_PHDR 3 /* program headers for program */
162 #define AT_PHENT 4 /* size of program header entry */
163 #define AT_PHNUM 5 /* number of program headers */
164 #define AT_PAGESZ 6 /* system page size */
165 #define AT_BASE 7 /* base address of interpreter */
166 #define AT_FLAGS 8 /* flags */
167 #define AT_ENTRY 9 /* entry point of program */
168 #define AT_NOTELF 10 /* program is not ELF */
169 #define AT_UID 11 /* real uid */
170 #define AT_EUID 12 /* effective uid */
171 #define AT_GID 13 /* real gid */
172 #define AT_EGID 14 /* effective gid */
173 #define AT_PLATFORM 15 /* string identifying CPU for optimizations */
174 #define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
175 #define AT_CLKTCK 17 /* frequency at which times() increments */
177 typedef struct dynamic{
186 Elf64_Sxword d_tag; /* entry tag value */
193 /* The following are used with relocations */
194 #define ELF32_R_SYM(x) ((x) >> 8)
195 #define ELF32_R_TYPE(x) ((x) & 0xff)
200 #define R_386_GOT32 3
201 #define R_386_PLT32 4
203 #define R_386_GLOB_DAT 6
204 #define R_386_JMP_SLOT 7
205 #define R_386_RELATIVE 8
206 #define R_386_GOTOFF 9
207 #define R_386_GOTPC 10
210 #define R_MIPS_NONE 0
213 #define R_MIPS_REL32 3
215 #define R_MIPS_HI16 5
216 #define R_MIPS_LO16 6
217 #define R_MIPS_GPREL16 7
218 #define R_MIPS_LITERAL 8
219 #define R_MIPS_GOT16 9
220 #define R_MIPS_PC16 10
221 #define R_MIPS_CALL16 11
222 #define R_MIPS_GPREL32 12
223 /* The remaining relocs are defined on Irix, although they are not
224 in the MIPS ELF ABI. */
225 #define R_MIPS_UNUSED1 13
226 #define R_MIPS_UNUSED2 14
227 #define R_MIPS_UNUSED3 15
228 #define R_MIPS_SHIFT5 16
229 #define R_MIPS_SHIFT6 17
231 #define R_MIPS_GOT_DISP 19
232 #define R_MIPS_GOT_PAGE 20
233 #define R_MIPS_GOT_OFST 21
235 * The following two relocation types are specified in the MIPS ABI
236 * conformance guide version 1.2 but not yet in the psABI.
238 #define R_MIPS_GOTHI16 22
239 #define R_MIPS_GOTLO16 23
240 #define R_MIPS_SUB 24
241 #define R_MIPS_INSERT_A 25
242 #define R_MIPS_INSERT_B 26
243 #define R_MIPS_DELETE 27
244 #define R_MIPS_HIGHER 28
245 #define R_MIPS_HIGHEST 29
247 * The following two relocation types are specified in the MIPS ABI
248 * conformance guide version 1.2 but not yet in the psABI.
250 #define R_MIPS_CALLHI16 30
251 #define R_MIPS_CALLLO16 31
253 * This range is reserved for vendor specific relocations.
255 #define R_MIPS_LOVENDOR 100
256 #define R_MIPS_HIVENDOR 127
260 * Sparc ELF relocation types
262 #define R_SPARC_NONE 0
266 #define R_SPARC_DISP8 4
267 #define R_SPARC_DISP16 5
268 #define R_SPARC_DISP32 6
269 #define R_SPARC_WDISP30 7
270 #define R_SPARC_WDISP22 8
271 #define R_SPARC_HI22 9
272 #define R_SPARC_22 10
273 #define R_SPARC_13 11
274 #define R_SPARC_LO10 12
275 #define R_SPARC_GOT10 13
276 #define R_SPARC_GOT13 14
277 #define R_SPARC_GOT22 15
278 #define R_SPARC_PC10 16
279 #define R_SPARC_PC22 17
280 #define R_SPARC_WPLT30 18
281 #define R_SPARC_COPY 19
282 #define R_SPARC_GLOB_DAT 20
283 #define R_SPARC_JMP_SLOT 21
284 #define R_SPARC_RELATIVE 22
285 #define R_SPARC_UA32 23
286 #define R_SPARC_PLT32 24
287 #define R_SPARC_HIPLT22 25
288 #define R_SPARC_LOPLT10 26
289 #define R_SPARC_PCPLT32 27
290 #define R_SPARC_PCPLT22 28
291 #define R_SPARC_PCPLT10 29
292 #define R_SPARC_10 30
293 #define R_SPARC_11 31
294 #define R_SPARC_WDISP16 40
295 #define R_SPARC_WDISP19 41
300 /* Bits present in AT_HWCAP, primarily for Sparc32. */
302 #define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
303 #define HWCAP_SPARC_STBAR 2
304 #define HWCAP_SPARC_SWAP 4
305 #define HWCAP_SPARC_MULDIV 8
306 #define HWCAP_SPARC_V9 16
307 #define HWCAP_SPARC_ULTRA3 32
310 * 68k ELF relocation types
319 #define R_68K_GOT32 7
320 #define R_68K_GOT16 8
322 #define R_68K_GOT32O 10
323 #define R_68K_GOT16O 11
324 #define R_68K_GOT8O 12
325 #define R_68K_PLT32 13
326 #define R_68K_PLT16 14
327 #define R_68K_PLT8 15
328 #define R_68K_PLT32O 16
329 #define R_68K_PLT16O 17
330 #define R_68K_PLT8O 18
331 #define R_68K_COPY 19
332 #define R_68K_GLOB_DAT 20
333 #define R_68K_JMP_SLOT 21
334 #define R_68K_RELATIVE 22
337 * Alpha ELF relocation types
339 #define R_ALPHA_NONE 0 /* No reloc */
340 #define R_ALPHA_REFLONG 1 /* Direct 32 bit */
341 #define R_ALPHA_REFQUAD 2 /* Direct 64 bit */
342 #define R_ALPHA_GPREL32 3 /* GP relative 32 bit */
343 #define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */
344 #define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */
345 #define R_ALPHA_GPDISP 6 /* Add displacement to GP */
346 #define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */
347 #define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */
348 #define R_ALPHA_SREL16 9 /* PC relative 16 bit */
349 #define R_ALPHA_SREL32 10 /* PC relative 32 bit */
350 #define R_ALPHA_SREL64 11 /* PC relative 64 bit */
351 #define R_ALPHA_OP_PUSH 12 /* OP stack push */
352 #define R_ALPHA_OP_STORE 13 /* OP stack pop and store */
353 #define R_ALPHA_OP_PSUB 14 /* OP stack subtract */
354 #define R_ALPHA_OP_PRSHIFT 15 /* OP stack right shift */
355 #define R_ALPHA_GPVALUE 16
356 #define R_ALPHA_GPRELHIGH 17
357 #define R_ALPHA_GPRELLOW 18
358 #define R_ALPHA_IMMED_GP_16 19
359 #define R_ALPHA_IMMED_GP_HI32 20
360 #define R_ALPHA_IMMED_SCN_HI32 21
361 #define R_ALPHA_IMMED_BR_HI32 22
362 #define R_ALPHA_IMMED_LO32 23
363 #define R_ALPHA_COPY 24 /* Copy symbol at runtime */
364 #define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */
365 #define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */
366 #define R_ALPHA_RELATIVE 27 /* Adjust by program base */
368 /* Legal values for e_flags field of Elf64_Ehdr. */
370 #define EF_ALPHA_32BIT 1 /* All addresses are below 2GB */
373 typedef struct elf32_rel {
378 typedef struct elf64_rel {
379 Elf64_Addr r_offset; /* Location at which to apply the action */
380 Elf64_Xword r_info; /* index and type of relocation */
383 typedef struct elf32_rela{
386 Elf32_Sword r_addend;
389 typedef struct elf64_rela {
390 Elf64_Addr r_offset; /* Location at which to apply the action */
391 Elf64_Xword r_info; /* index and type of relocation */
392 Elf64_Sxword r_addend; /* Constant addend used to compute value */
395 typedef struct elf32_sym{
399 unsigned char st_info;
400 unsigned char st_other;
404 typedef struct elf64_sym {
405 Elf64_Word st_name; /* Symbol name, index in string tbl */
406 unsigned char st_info; /* Type and binding attributes */
407 unsigned char st_other; /* No defined meaning, 0 */
408 Elf64_Half st_shndx; /* Associated section index */
409 Elf64_Addr st_value; /* Value of the symbol */
410 Elf64_Xword st_size; /* Associated symbol size */
416 typedef struct elf32_hdr{
417 unsigned char e_ident[EI_NIDENT];
419 Elf32_Half e_machine;
420 Elf32_Word e_version;
421 Elf32_Addr e_entry; /* Entry point */
426 Elf32_Half e_phentsize;
428 Elf32_Half e_shentsize;
430 Elf32_Half e_shstrndx;
433 typedef struct elf64_hdr {
434 unsigned char e_ident[16]; /* ELF "magic number" */
436 Elf64_Half e_machine;
437 Elf64_Word e_version;
438 Elf64_Addr e_entry; /* Entry point virtual address */
439 Elf64_Off e_phoff; /* Program header table file offset */
440 Elf64_Off e_shoff; /* Section header table file offset */
443 Elf64_Half e_phentsize;
445 Elf64_Half e_shentsize;
447 Elf64_Half e_shstrndx;
450 /* These constants define the permissions on sections in the program
456 typedef struct elf32_phdr{
467 typedef struct elf64_phdr {
470 Elf64_Off p_offset; /* Segment file offset */
471 Elf64_Addr p_vaddr; /* Segment virtual address */
472 Elf64_Addr p_paddr; /* Segment physical address */
473 Elf64_Xword p_filesz; /* Segment size in file */
474 Elf64_Xword p_memsz; /* Segment size in memory */
475 Elf64_Xword p_align; /* Segment alignment, file & memory */
480 #define SHT_PROGBITS 1
485 #define SHT_DYNAMIC 6
490 #define SHT_DYNSYM 11
492 #define SHT_LOPROC 0x70000000
493 #define SHT_HIPROC 0x7fffffff
494 #define SHT_LOUSER 0x80000000
495 #define SHT_HIUSER 0xffffffff
496 #define SHT_MIPS_LIST 0x70000000
497 #define SHT_MIPS_CONFLICT 0x70000002
498 #define SHT_MIPS_GPTAB 0x70000003
499 #define SHT_MIPS_UCODE 0x70000004
502 #define SHF_WRITE 0x1
503 #define SHF_ALLOC 0x2
504 #define SHF_EXECINSTR 0x4
505 #define SHF_MASKPROC 0xf0000000
506 #define SHF_MIPS_GPREL 0x10000000
508 /* special section indexes */
510 #define SHN_LORESERVE 0xff00
511 #define SHN_LOPROC 0xff00
512 #define SHN_HIPROC 0xff1f
513 #define SHN_ABS 0xfff1
514 #define SHN_COMMON 0xfff2
515 #define SHN_HIRESERVE 0xffff
516 #define SHN_MIPS_ACCOMON 0xff00
527 Elf32_Word sh_addralign;
528 Elf32_Word sh_entsize;
531 typedef struct elf64_shdr {
532 Elf64_Word sh_name; /* Section name, index in string tbl */
533 Elf64_Word sh_type; /* Type of section */
534 Elf64_Xword sh_flags; /* Miscellaneous section attributes */
535 Elf64_Addr sh_addr; /* Section virtual addr at execution */
536 Elf64_Off sh_offset; /* Section file offset */
537 Elf64_Xword sh_size; /* Size of section in bytes */
538 Elf64_Word sh_link; /* Index of another section */
539 Elf64_Word sh_info; /* Additional section information */
540 Elf64_Xword sh_addralign; /* Section alignment */
541 Elf64_Xword sh_entsize; /* Entry size if section holds table */
544 #define EI_MAG0 0 /* e_ident[] indexes */
553 #define ELFMAG0 0x7f /* EI_MAG */
557 #define ELFMAG "\177ELF"
560 #define ELFCLASSNONE 0 /* EI_CLASS */
563 #define ELFCLASSNUM 3
565 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
566 #define ELFDATA2LSB 1
567 #define ELFDATA2MSB 2
569 #define EV_NONE 0 /* e_version, EI_VERSION */
573 /* Notes used in ET_CORE */
574 #define NT_PRSTATUS 1
576 #define NT_PRPSINFO 3
577 #define NT_TASKSTRUCT 4
578 #define NT_PRFPXREG 20
580 /* Note header in a PT_NOTE section */
581 typedef struct elf32_note {
582 Elf32_Word n_namesz; /* Name size */
583 Elf32_Word n_descsz; /* Content size */
584 Elf32_Word n_type; /* Content type */
587 /* Note header in a PT_NOTE section */
588 typedef struct elf64_note {
589 Elf64_Word n_namesz; /* Name size */
590 Elf64_Word n_descsz; /* Content size */
591 Elf64_Word n_type; /* Content type */
594 #if ELF_CLASS == ELFCLASS32
596 extern Elf32_Dyn _DYNAMIC [];
597 #define elfhdr elf32_hdr
598 #define elf_phdr elf32_phdr
599 #define elf_note elf32_note
603 extern Elf64_Dyn _DYNAMIC [];
604 #define elfhdr elf64_hdr
605 #define elf_phdr elf64_phdr
606 #define elf_note elf64_note
611 #endif /* _LINUX_ELF_H */