include/linux/elf.h
14205 #ifndef _LINUX_ELF_H
14206 #define _LINUX_ELF_H
14207
14208 #include <linux/types.h>
14209 #include <asm/elf.h>
14210
14211 /* 32-bit ELF base types. */
14212 typedef __u32 Elf32_Addr;
14213 typedef __u16 Elf32_Half;
14214 typedef __u32 Elf32_Off;
14215 typedef __s32 Elf32_Sword;
14216 typedef __u32 Elf32_Word;
14217
14218 /* 64-bit ELF base types. */
14219 typedef __u64 Elf64_Addr;
14220 typedef __u16 Elf64_Half;
14221 typedef __s16 Elf64_SHalf;
14222 typedef __u64 Elf64_Off;
14223 typedef __s64 Elf64_Sword;
14224 typedef __u64 Elf64_Word;
14225
14226 /* These constants are for the segment types stored in
14227 * the image headers */
14228 #define PT_NULL 0
14229 #define PT_LOAD 1
14230 #define PT_DYNAMIC 2
14231 #define PT_INTERP 3
14232 #define PT_NOTE 4
14233 #define PT_SHLIB 5
14234 #define PT_PHDR 6
14235 #define PT_LOPROC 0x70000000
14236 #define PT_HIPROC 0x7fffffff
14237
14238 /* These constants define the different elf file types */
14239 #define ET_NONE 0
14240 #define ET_REL 1
14241 #define ET_EXEC 2
14242 #define ET_DYN 3
14243 #define ET_CORE 4
14244 #define ET_LOPROC 5
14245 #define ET_HIPROC 6
14246
14247 /* These constants define the various ELF target machs */
14248 #define EM_NONE 0
14249 #define EM_M32 1
14250 #define EM_SPARC 2
14251 #define EM_386 3
14252 #define EM_68K 4
14253 #define EM_88K 5
14254 #define EM_486 6 /* Perhaps disused */
14255 #define EM_860 7
14256
14257 /* MIPS R3000 (officially, big-endian only) */
14258 #define EM_MIPS 8
14259
14260 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
14261
14262 #define EM_PARISC 15 /* HPPA */
14263
14264 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
14265
14266 #define EM_PPC 20 /* PowerPC */
14267
14268 #define EM_SPARCV9 43 /* SPARC v9 64-bit */
14269
14270 /* This is an interim value that we will use until the
14271 * committee comes up with a final number. */
14272 #define EM_ALPHA 0x9026
14273
14274
14275 /* This is the info that is needed to parse the dynamic
14276 * section of the file */
14277 #define DT_NULL 0
14278 #define DT_NEEDED 1
14279 #define DT_PLTRELSZ 2
14280 #define DT_PLTGOT 3
14281 #define DT_HASH 4
14282 #define DT_STRTAB 5
14283 #define DT_SYMTAB 6
14284 #define DT_RELA 7
14285 #define DT_RELASZ 8
14286 #define DT_RELAENT 9
14287 #define DT_STRSZ 10
14288 #define DT_SYMENT 11
14289 #define DT_INIT 12
14290 #define DT_FINI 13
14291 #define DT_SONAME 14
14292 #define DT_RPATH 15
14293 #define DT_SYMBOLIC 16
14294 #define DT_REL 17
14295 #define DT_RELSZ 18
14296 #define DT_RELENT 19
14297 #define DT_PLTREL 20
14298 #define DT_DEBUG 21
14299 #define DT_TEXTREL 22
14300 #define DT_JMPREL 23
14301 #define DT_LOPROC 0x70000000
14302 #define DT_HIPROC 0x7fffffff
14303
14304 /* This info is needed when parsing the symbol table */
14305 #define STB_LOCAL 0
14306 #define STB_GLOBAL 1
14307 #define STB_WEAK 2
14308
14309 #define STT_NOTYPE 0
14310 #define STT_OBJECT 1
14311 #define STT_FUNC 2
14312 #define STT_SECTION 3
14313 #define STT_FILE 4
14314
14315 #define ELF32_ST_BIND(x) ((x) >> 4)
14316 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
14317
14318 /* Symbolic values for the entries in the auxiliary table
14319 put on the initial stack */
14320 #define AT_NULL 0 /* end of vector */
14321 #define AT_IGNORE 1 /* entry should be ignored */
14322 #define AT_EXECFD 2 /* file descriptor of program */
14323 #define AT_PHDR 3 /* program headers for program */
14324 #define AT_PHENT 4 /* size of program header entry */
14325 #define AT_PHNUM 5 /* number of program headers */
14326 #define AT_PAGESZ 6 /* system page size */
14327 #define AT_BASE 7 /* base address of interpreter */
14328 #define AT_FLAGS 8 /* flags */
14329 #define AT_ENTRY 9 /* entry point of program */
14330 #define AT_NOTELF 10 /* program is not ELF */
14331 #define AT_UID 11 /* real uid */
14332 #define AT_EUID 12 /* effective uid */
14333 #define AT_GID 13 /* real gid */
14334 #define AT_EGID 14 /* effective gid */
14335 #define AT_PLATFORM 15 /* string identifying CPU for
14336 * optimizations */
14337 #define AT_HWCAP 16 /* arch dependent hints at CPU
14338 * capabilities */
14339
14340 typedef struct dynamic{
14341 Elf32_Sword d_tag;
14342 union{
14343 Elf32_Sword d_val;
14344 Elf32_Addr d_ptr;
14345 } d_un;
14346 } Elf32_Dyn;
14347
14348 typedef struct {
14349 Elf64_Word d_tag; /* entry tag value */
14350 union {
14351 Elf64_Word d_val;
14352 Elf64_Word d_ptr;
14353 } d_un;
14354 } Elf64_Dyn;
14355
14356 /* The following are used with relocations */
14357 #define ELF32_R_SYM(x) ((x) >> 8)
14358 #define ELF32_R_TYPE(x) ((x) & 0xff)
14359
14360 #define R_386_NONE 0
14361 #define R_386_32 1
14362 #define R_386_PC32 2
14363 #define R_386_GOT32 3
14364 #define R_386_PLT32 4
14365 #define R_386_COPY 5
14366 #define R_386_GLOB_DAT 6
14367 #define R_386_JMP_SLOT 7
14368 #define R_386_RELATIVE 8
14369 #define R_386_GOTOFF 9
14370 #define R_386_GOTPC 10
14371 #define R_386_NUM 11
14372
14373 /* Sparc ELF relocation types */
14374 #define R_SPARC_NONE 0
14375 #define R_SPARC_8 1
14376 #define R_SPARC_16 2
14377 #define R_SPARC_32 3
14378 #define R_SPARC_DISP8 4
14379 #define R_SPARC_DISP16 5
14380 #define R_SPARC_DISP32 6
14381 #define R_SPARC_WDISP30 7
14382 #define R_SPARC_WDISP22 8
14383 #define R_SPARC_HI22 9
14384 #define R_SPARC_22 10
14385 #define R_SPARC_13 11
14386 #define R_SPARC_LO10 12
14387 #define R_SPARC_GOT10 13
14388 #define R_SPARC_GOT13 14
14389 #define R_SPARC_GOT22 15
14390 #define R_SPARC_PC10 16
14391 #define R_SPARC_PC22 17
14392 #define R_SPARC_WPLT30 18
14393 #define R_SPARC_COPY 19
14394 #define R_SPARC_GLOB_DAT 20
14395 #define R_SPARC_JMP_SLOT 21
14396 #define R_SPARC_RELATIVE 22
14397 #define R_SPARC_UA32 23
14398 #define R_SPARC_PLT32 24
14399 #define R_SPARC_HIPLT22 25
14400 #define R_SPARC_LOPLT10 26
14401 #define R_SPARC_PCPLT32 27
14402 #define R_SPARC_PCPLT22 28
14403 #define R_SPARC_PCPLT10 29
14404 #define R_SPARC_10 30
14405 #define R_SPARC_11 31
14406 #define R_SPARC_WDISP16 40
14407 #define R_SPARC_WDISP19 41
14408 #define R_SPARC_7 43
14409 #define R_SPARC_5 44
14410 #define R_SPARC_6 45
14411
14412 /* Bits present in AT_HWCAP, primarily for Sparc32. */
14413
14414 #define HWCAP_SPARC_FLUSH 1 /* CPU supports flush
14415 * instruction. */
14416 #define HWCAP_SPARC_STBAR 2
14417 #define HWCAP_SPARC_SWAP 4
14418 #define HWCAP_SPARC_MULDIV 8
14419 #define HWCAP_SPARC_V9 16
14420
14421
14422 /* 68k ELF relocation types */
14423 #define R_68K_NONE 0
14424 #define R_68K_32 1
14425 #define R_68K_16 2
14426 #define R_68K_8 3
14427 #define R_68K_PC32 4
14428 #define R_68K_PC16 5
14429 #define R_68K_PC8 6
14430 #define R_68K_GOT32 7
14431 #define R_68K_GOT16 8
14432 #define R_68K_GOT8 9
14433 #define R_68K_GOT32O 10
14434 #define R_68K_GOT16O 11
14435 #define R_68K_GOT8O 12
14436 #define R_68K_PLT32 13
14437 #define R_68K_PLT16 14
14438 #define R_68K_PLT8 15
14439 #define R_68K_PLT32O 16
14440 #define R_68K_PLT16O 17
14441 #define R_68K_PLT8O 18
14442 #define R_68K_COPY 19
14443 #define R_68K_GLOB_DAT 20
14444 #define R_68K_JMP_SLOT 21
14445 #define R_68K_RELATIVE 22
14446
14447 /* Alpha ELF relocation types */
14448 #define R_ALPHA_NONE 0 /* No reloc */
14449 #define R_ALPHA_REFLONG 1 /* Direct 32 bit */
14450 #define R_ALPHA_REFQUAD 2 /* Direct 64 bit */
14451 #define R_ALPHA_GPREL32 3 /* GP relative 32 bit*/
14452 #define R_ALPHA_LITERAL 4 /* GP relative 16 bit
14453 * w/optimization */
14454 #define R_ALPHA_LITUSE 5 /* Optimization hint
14455 * for LITERAL */
14456 #define R_ALPHA_GPDISP 6 /* Add displacement to
14457 * GP */
14458 #define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit
14459 * shifted */
14460 #define R_ALPHA_HINT 8 /* PC+4 relative 16 bit
14461 * shifted */
14462 #define R_ALPHA_SREL16 9 /* PC relative 16 bit*/
14463 #define R_ALPHA_SREL32 10 /* PC relative 32 bit*/
14464 #define R_ALPHA_SREL64 11 /* PC relative 64 bit*/
14465 #define R_ALPHA_OP_PUSH 12 /* OP stack push */
14466 #define R_ALPHA_OP_STORE 13 /* OP stack pop and
14467 * store */
14468 #define R_ALPHA_OP_PSUB 14 /* OP stack subtract */
14469 #define R_ALPHA_OP_PRSHIFT 15 /* OP stack right shift
14470 */
14471 #define R_ALPHA_GPVALUE 16
14472 #define R_ALPHA_GPRELHIGH 17
14473 #define R_ALPHA_GPRELLOW 18
14474 #define R_ALPHA_IMMED_GP_16 19
14475 #define R_ALPHA_IMMED_GP_HI32 20
14476 #define R_ALPHA_IMMED_SCN_HI32 21
14477 #define R_ALPHA_IMMED_BR_HI32 22
14478 #define R_ALPHA_IMMED_LO32 23
14479 #define R_ALPHA_COPY 24 /* Copy symbol at
14480 * runtime */
14481 #define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */
14482 #define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */
14483 #define R_ALPHA_RELATIVE 27 /* Adjust by program
14484 * base */
14485
14486 /* Legal values for e_flags field of Elf64_Ehdr. */
14487
14488 #define EF_ALPHA_32BIT 1 /* All addresses are
14489 * below 2GB */
14490
14491
14492 typedef struct elf32_rel {
14493 Elf32_Addr r_offset;
14494 Elf32_Word r_info;
14495 } Elf32_Rel;
14496
14497 typedef struct elf64_rel {
14498 /* Location at which to apply the action */
14499 Elf64_Addr r_offset;
14500 Elf64_Word r_info; /* index and type of relocation */
14501 } Elf64_Rel;
14502
14503 typedef struct elf32_rela{
14504 Elf32_Addr r_offset;
14505 Elf32_Word r_info;
14506 Elf32_Sword r_addend;
14507 } Elf32_Rela;
14508
14509 typedef struct elf64_rela {
14510 /* Location at which to apply the action */
14511 Elf64_Addr r_offset;
14512 /* index and type of relocation */
14513 Elf64_Word r_info;
14514 /* Constant addend used to compute value */
14515 Elf64_Word r_addend;
14516 } Elf64_Rela;
14517
14518 typedef struct elf32_sym{
14519 Elf32_Word st_name;
14520 Elf32_Addr st_value;
14521 Elf32_Word st_size;
14522 unsigned char st_info;
14523 unsigned char st_other;
14524 Elf32_Half st_shndx;
14525 } Elf32_Sym;
14526
14527 typedef struct elf64_sym {
14528 Elf32_Word st_name; /* Symbol name, index in
14529 * string tbl (yes, Elf32) */
14530 unsigned char st_info; /* Type and binding
14531 * attributes */
14532 unsigned char st_other; /* No defined meaning, 0 */
14533 Elf64_Half st_shndx; /* Associated section index */
14534 Elf64_Addr st_value; /* Value of the symbol */
14535 Elf64_Word st_size; /* Associated symbol size */
14536 } Elf64_Sym;
14537
14538
14539 #define EI_NIDENT 16
14540
14541 typedef struct elf32_hdr{
14542 unsigned char e_ident[EI_NIDENT];
14543 Elf32_Half e_type;
14544 Elf32_Half e_machine;
14545 Elf32_Word e_version;
14546 Elf32_Addr e_entry; /* Entry point */
14547 Elf32_Off e_phoff;
14548 Elf32_Off e_shoff;
14549 Elf32_Word e_flags;
14550 Elf32_Half e_ehsize;
14551 Elf32_Half e_phentsize;
14552 Elf32_Half e_phnum;
14553 Elf32_Half e_shentsize;
14554 Elf32_Half e_shnum;
14555 Elf32_Half e_shstrndx;
14556 } Elf32_Ehdr;
14557
14558 typedef struct elf64_hdr {
14559 unsigned char e_ident[16]; /* ELF "magic number" */
14560 Elf64_SHalf e_type;
14561 Elf64_Half e_machine;
14562 __s32 e_version;
14563 Elf64_Addr e_entry; /* Entry point virtual address */
14564 Elf64_Off e_phoff; /* Program hdr table file offset */
14565 Elf64_Off e_shoff; /* Section hdr table file offset */
14566 __s32 e_flags;
14567 Elf64_SHalf e_ehsize;
14568 Elf64_SHalf e_phentsize;
14569 Elf64_SHalf e_phnum;
14570 Elf64_SHalf e_shentsize;
14571 Elf64_SHalf e_shnum;
14572 Elf64_SHalf e_shstrndx;
14573 } Elf64_Ehdr;
14574
14575 /* These constants define the permissions on sections in
14576 the program header, p_flags. */
14577 #define PF_R 0x4
14578 #define PF_W 0x2
14579 #define PF_X 0x1
14580
14581 typedef struct elf32_phdr{
14582 Elf32_Word p_type;
14583 Elf32_Off p_offset;
14584 Elf32_Addr p_vaddr;
14585 Elf32_Addr p_paddr;
14586 Elf32_Word p_filesz;
14587 Elf32_Word p_memsz;
14588 Elf32_Word p_flags;
14589 Elf32_Word p_align;
14590 } Elf32_Phdr;
14591
14592 typedef struct elf64_phdr {
14593 __s32 p_type;
14594 __s32 p_flags;
14595 Elf64_Off p_offset; /* Segment file offset */
14596 Elf64_Addr p_vaddr; /* Segment virtual address */
14597 Elf64_Addr p_paddr; /* Segment physical address */
14598 Elf64_Word p_filesz; /* Segment size in file */
14599 Elf64_Word p_memsz; /* Segment size in memory */
14600 Elf64_Word p_align; /* Segment alignment,
14601 * file & memory */
14602 } Elf64_Phdr;
14603
14604 /* sh_type */
14605 #define SHT_NULL 0
14606 #define SHT_PROGBITS 1
14607 #define SHT_SYMTAB 2
14608 #define SHT_STRTAB 3
14609 #define SHT_RELA 4
14610 #define SHT_HASH 5
14611 #define SHT_DYNAMIC 6
14612 #define SHT_NOTE 7
14613 #define SHT_NOBITS 8
14614 #define SHT_REL 9
14615 #define SHT_SHLIB 10
14616 #define SHT_DYNSYM 11
14617 #define SHT_NUM 12
14618 #define SHT_LOPROC 0x70000000
14619 #define SHT_HIPROC 0x7fffffff
14620 #define SHT_LOUSER 0x80000000
14621 #define SHT_HIUSER 0xffffffff
14622
14623 /* sh_flags */
14624 #define SHF_WRITE 0x1
14625 #define SHF_ALLOC 0x2
14626 #define SHF_EXECINSTR 0x4
14627 #define SHF_MASKPROC 0xf0000000
14628
14629 /* special section indexes */
14630 #define SHN_UNDEF 0
14631 #define SHN_LORESERVE 0xff00
14632 #define SHN_LOPROC 0xff00
14633 #define SHN_HIPROC 0xff1f
14634 #define SHN_ABS 0xfff1
14635 #define SHN_COMMON 0xfff2
14636 #define SHN_HIRESERVE 0xffff
14637
14638 typedef struct {
14639 Elf32_Word sh_name;
14640 Elf32_Word sh_type;
14641 Elf32_Word sh_flags;
14642 Elf32_Addr sh_addr;
14643 Elf32_Off sh_offset;
14644 Elf32_Word sh_size;
14645 Elf32_Word sh_link;
14646 Elf32_Word sh_info;
14647 Elf32_Word sh_addralign;
14648 Elf32_Word sh_entsize;
14649 } Elf32_Shdr;
14650
14651 typedef struct elf64_shdr {
14652 Elf32_Word sh_name; /* Section name, index in
14653 * string tbl (yes Elf32) */
14654 Elf32_Word sh_type; /* Type of section
14655 * (yes Elf32) */
14656 Elf64_Word sh_flags; /* Miscellaneous section
14657 * attributes */
14658 Elf64_Addr sh_addr; /* Section virtual addr at
14659 * execution */
14660 Elf64_Off sh_offset; /* Section file offset */
14661 Elf64_Word sh_size; /* Size of section in bytes */
14662 Elf32_Word sh_link; /* Index of another section
14663 * (yes Elf32) */
14664 Elf32_Word sh_info; /* Additional section
14665 * information (yes Elf32) */
14666 Elf64_Word sh_addralign; /* Section alignment */
14667 Elf64_Word sh_entsize; /* Entry size if section holds
14668 * table */
14669 } Elf64_Shdr;
14670
14671 #define EI_MAG0 0 /* e_ident[] indexes */
14672 #define EI_MAG1 1
14673 #define EI_MAG2 2
14674 #define EI_MAG3 3
14675 #define EI_CLASS 4
14676 #define EI_DATA 5
14677 #define EI_VERSION 6
14678 #define EI_PAD 7
14679
14680 #define ELFMAG0 0x7f /* EI_MAG */
14681 #define ELFMAG1 'E'
14682 #define ELFMAG2 'L'
14683 #define ELFMAG3 'F'
14684 #define ELFMAG "\177ELF"
14685 #define SELFMAG 4
14686
14687 #define ELFCLASSNONE 0 /* EI_CLASS */
14688 #define ELFCLASS32 1
14689 #define ELFCLASS64 2
14690 #define ELFCLASSNUM 3
14691
14692 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
14693 #define ELFDATA2LSB 1
14694 #define ELFDATA2MSB 2
14695
14696 #define EV_NONE 0 /* e_version, EI_VERSION */
14697 #define EV_CURRENT 1
14698 #define EV_NUM 2
14699
14700 /* Notes used in ET_CORE */
14701 #define NT_PRSTATUS 1
14702 #define NT_PRFPREG 2
14703 #define NT_PRPSINFO 3
14704 #define NT_TASKSTRUCT 4
14705
14706 /* Note header in a PT_NOTE section */
14707 typedef struct elf32_note {
14708 Elf32_Word n_namesz; /* Name size */
14709 Elf32_Word n_descsz; /* Content size */
14710 Elf32_Word n_type; /* Content type */
14711 } Elf32_Nhdr;
14712
14713 /* Note header in a PT_NOTE section */
14714 /* For now we use the 32 bit version of the structure
14715 * until we figure out whether we need anything better.
14716 * Note - on the Alpha, "unsigned int" is only 32 bits.*/
14717 typedef struct elf64_note {
14718 Elf32_Word n_namesz; /* Name size */
14719 Elf32_Word n_descsz; /* Content size */
14720 Elf32_Word n_type; /* Content type */
14721 } Elf64_Nhdr;
14722
14723 #if ELF_CLASS == ELFCLASS32
14724
14725 extern Elf32_Dyn _DYNAMIC [];
14726 #define elfhdr elf32_hdr
14727 #define elf_phdr elf32_phdr
14728 #define elf_note elf32_note
14729
14730 #else
14731
14732 extern Elf64_Dyn _DYNAMIC [];
14733 #define elfhdr elf64_hdr
14734 #define elf_phdr elf64_phdr
14735 #define elf_note elf64_note
14736
14737 #endif
14738
14739
14740 #endif /* _LINUX_ELF_H */
Сайт управляется системой
uCoz