32 #ifndef _L4_EXEC_ELF_H 33 #define _L4_EXEC_ELF_H 35 #include <l4/sys/l4int.h> 61 #if L4_MWORD_BITS == 64 66 #define ElfW(type) _ElfW(Elf, 64, type) 68 #define ElfW(type) _ElfW(Elf, 32, type) 70 #define _ElfW(e,w,t) __ElfW(e, w, _##t) 71 #define __ElfW(e,w,t) e##w##t 74 #define L4_ARCH_EI_DATA ELFDATA2LSB 75 #define L4_ARCH_E_MACHINE EM_386 76 #define L4_ARCH_EI_CLASS ELFCLASS32 77 #elif defined(ARCH_amd64) 78 #define L4_ARCH_EI_DATA ELFDATA2LSB 79 #define L4_ARCH_E_MACHINE EM_X86_64 80 #define L4_ARCH_EI_CLASS ELFCLASS64 81 #elif defined(ARCH_arm) 82 #define L4_ARCH_EI_DATA ELFDATA2LSB 83 #define L4_ARCH_E_MACHINE EM_ARM 84 #define L4_ARCH_EI_CLASS ELFCLASS32 85 #elif defined(ARCH_arm64) 86 #define L4_ARCH_EI_DATA ELFDATA2LSB 87 #define L4_ARCH_E_MACHINE EM_AARCH64 88 #define L4_ARCH_EI_CLASS ELFCLASS64 89 #elif defined(ARCH_ppc32) 90 #define L4_ARCH_EI_DATA ELFDATA2MSB 91 #define L4_ARCH_E_MACHINE EM_PPC 92 #define L4_ARCH_EI_CLASS ELFCLASS32 93 #elif defined(ARCH_sparc) 94 #define L4_ARCH_EI_DATA ELFDATA2MSB 95 #define L4_ARCH_E_MACHINE EM_SPARC 96 #define L4_ARCH_EI_CLASS ELFCLASS32 97 #elif defined(ARCH_mips) 98 #define L4_ARCH_EI_DATA ELFDATA2LSB 99 #define L4_ARCH_E_MACHINE EM_MIPS 101 #define L4_ARCH_EI_CLASS ELFCLASS64 103 #define L4_ARCH_EI_CLASS ELFCLASS32 106 #warning elf.h: Unsupported build architecture! 160 #define ELFCLASSNONE 0 163 #define ELFCLASSNUM 3 166 #define ELFDATANONE 0 167 #define ELFDATA2LSB 1 168 #define ELFDATA2MSB 2 175 #define ELFOSABI_NONE 0 176 #define ELFOSABI_SYSV 0 177 #define ELFOSABI_HPUX 1 178 #define ELFOSABI_NETBSD 2 179 #define ELFOSABI_LINUX 3 180 #define ELFOSABI_SOLARIS 6 181 #define ELFOSABI_AIX 7 182 #define ELFOSABI_IRIX 8 183 #define ELFOSABI_FREEBSD 9 184 #define ELFOSABI_TRU64 10 185 #define ELFOSABI_MODESTO 11 186 #define ELFOSABI_OPENBSD 12 187 #define ELFOSABI_ARM 97 188 #define ELFOSABI_STANDALONE 255 190 #define EI_ABIVERSION 8 201 #define ET_LOPROC 0xff00 202 #define ET_HIPROC 0xffff 214 #define EM_MIPS_RS4_BE 10 215 #define EM_SPARC64 11 218 #define EM_SPARC32PLUS 18 228 #define EM_SPARCV9 43 229 #define EM_TRICORE 44 232 #define EM_H8_300H 47 237 #define EM_COLDFIRE 52 242 #define EM_ST9PLUS 67 252 #define EM_JAVELIN 77 253 #define EM_FIREPATH 78 264 #define EM_MN10300 89 265 #define EM_MN10200 90 267 #define EM_OPENRISC 92 270 #define EM_ALTERA_NIOS2 113 271 #define EM_AARCH64 183 272 #define EM_TILEPRO 188 273 #define EM_MICROBLAZE 189 274 #define EM_TILEGX 191 278 #define EM_ALPHA 0x9026 280 #define EM_S390 0xA390 298 #define EI_ABIVERSION 8 310 #define ELFCLASSNONE 0 311 #define ELFCLASSS32 1 312 #define ELFCLASSS64 2 316 #define ELFDATANONE 0 317 #define ELFDATA2LSB 1 318 #define ELFDATA2MSB 2 322 #define ELFOSABI_SYSV 0 323 #define ELFOSABI_HPUX 1 324 #define ELFOSABI_STANDALONE 255 334 #define SHN_LORESERVE 0xff00 335 #define SHN_LOPROC 0xff00 336 #define SHN_HIPROC 0xff1f 337 #define SHN_ABS 0xfff1 338 #define SHN_COMMON 0xfff2 339 #define SHN_HIRESERVE 0xffff 372 #define SHT_PROGBITS 1 377 #define SHT_DYNAMIC 6 382 #define SHT_DYNSYM 11 383 #define SHT_INIT_ARRAY 14 384 #define SHT_FINI_ARRAY 15 385 #define SHT_PREINIT_ARRAY 16 387 #define SHT_SYMTAB_SHNDX 18 389 #define SHT_LOOS 0x60000000 390 #define SHT_HIOS 0x6fffffff 391 #define SHT_LOPROC 0x70000000 392 #define SHT_HIPROC 0x7fffffff 393 #define SHT_LOUSER 0x80000000 394 #define SHT_HIUSER 0xffffffff 398 #define SHF_WRITE 0x1 399 #define SHF_ALLOC 0x2 400 #define SHF_EXECINSTR 0x4 401 #define SHF_MERGE 0x10 402 #define SHF_STRINGS 0x20 403 #define SHF_INFO_LINK 0x40 404 #define SHF_LINK_ORDER 0x80 405 #define SHF_OS_NONCONFORMING 0x100 407 #define SHF_GROUP 0x200 408 #define SHF_TLS 0x400 409 #define SHF_MASKOS 0x0ff00000 410 #define SHF_MASKPROC 0xf0000000 452 #define PT_LOOS 0x60000000 453 #define PT_HIOS 0x6fffffff 454 #define PT_LOPROC 0x70000000 455 #define PT_HIPROC 0x7fffffff 457 #define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550) 458 #define PT_GNU_STACK (PT_LOOS + 0x474e551) 459 #define PT_GNU_RELRO (PT_LOOS + 0x474e552) 461 #define PT_L4_STACK (PT_LOOS + 0x12) 462 #define PT_L4_KIP (PT_LOOS + 0x13) 463 #define PT_L4_AUX (PT_LOOS + 0x14) 470 #define PF_MASKOS 0x0ff00000 471 #define PF_MASKPROC 0x7fffffff 475 #define NT_PRSTATUS 1 476 #define NT_FPREGSET 2 477 #define NT_PRPSINFO 3 479 #define NT_TASKSTRUCT 4 480 #define NT_PLATFORM 5 482 #define NT_GWINDOWS 7 484 #define NT_PSTATUS 10 487 #define NT_UTSNAME 15 488 #define NT_LWPSTATUS 16 489 #define NT_LWPSINFO 17 490 #define NT_PRFPXREG 20 520 #define DT_PLTRELSZ 2 534 #define DT_SYMBOLIC 16 540 #define DT_TEXTREL 22 542 #define DT_BIND_NOW 24 543 #define DT_INIT_ARRAY 25 544 #define DT_FINI_ARRAY 26 545 #define DT_INIT_ARRAYSZ 27 546 #define DT_FINI_ARRAYSZ 28 547 #define DT_RUNPATH 29 549 #define DT_ENCODING 32 550 #define DT_PREINIT_ARRAY 32 551 #define DT_PREINIT_ARRAYSZ 33 553 #define DT_LOOS 0x6000000d 554 #define DT_HIOS 0x6ffff000 555 #define DT_LOPROC 0x70000000 556 #define DT_HIPROC 0x7fffffff 559 #define DF_ORIGIN 0x00000001 560 #define DF_SYMBOLIC 0x00000002 561 #define DF_TEXTREL 0x00000004 562 #define DF_BIND_NOW 0x00000008 563 #define DF_STATIC_TLS 0x00000010 567 #define DF_1_NOW 0x00000001 568 #define DF_1_GLOBAL 0x00000002 569 #define DF_1_GROUP 0x00000004 570 #define DF_1_NODELETE 0x00000008 571 #define DF_1_LOADFLTR 0x00000010 572 #define DF_1_INITFIRST 0x00000020 573 #define DF_1_NOOPEN 0x00000040 574 #define DF_1_ORIGIN 0x00000080 575 #define DF_1_DIRECT 0x00000100 576 #define DF_1_TRANS 0x00000200 577 #define DF_1_INTERPOSE 0x00000400 578 #define DF_1_NODEFLIB 0x00000800 579 #define DF_1_NODUMP 0x00001000 580 #define DF_1_CONFALT 0x00002000 581 #define DF_1_ENDFILTEE 0x00004000 582 #define DF_1_DISPRELDNE 0x00008000 583 #define DF_1_DISPRELPND 0x00010000 586 #define DTF_1_PARINIT 0x00000001 587 #define DTF_1_CONFEXP 0x00000002 590 #define DF_P1_LAZYLOAD 0x00000001 591 #define DF_P1_GROUPPERM 0x00000002 618 #define ELF32_R_SYM(i) ((i)>>8) 619 #define ELF32_R_TYPE(i) ((unsigned char)(i)) 620 #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) 622 #define ELF64_R_SYM(i) ((i)>>32) 623 #define ELF64_R_TYPE(i) ((i)&0xffffffffL) 624 #define ELF64_R_INFO(s,t) (((s)<<32)+(t)&0xffffffffL) 631 #define R_386_GOT32 3 632 #define R_386_PLT32 4 634 #define R_386_GLOB_DAT 6 635 #define R_386_JMP_SLOT 7 636 #define R_386_RELATIVE 8 637 #define R_386_GOTOFF 9 638 #define R_386_GOTPC 10 639 #define R_386_32PLT 11 640 #define R_386_TLS_TPOFF 14 641 #define R_386_TLS_IE 15 643 #define R_386_TLS_GOTIE 16 645 #define R_386_TLS_LE 17 647 #define R_386_TLS_GD 18 649 #define R_386_TLS_LDM 19 653 #define R_386_PC16 21 656 #define R_386_TLS_GD_32 24 658 #define R_386_TLS_GD_PUSH 25 659 #define R_386_TLS_GD_CALL 26 661 #define R_386_TLS_GD_POP 27 662 #define R_386_TLS_LDM_32 28 664 #define R_386_TLS_LDM_PUSH 29 665 #define R_386_TLS_LDM_CALL 30 667 #define R_386_TLS_LDM_POP 31 668 #define R_386_TLS_LDO_32 32 669 #define R_386_TLS_IE_32 33 671 #define R_386_TLS_LE_32 34 673 #define R_386_TLS_DTPMOD32 35 674 #define R_386_TLS_DTPOFF32 36 675 #define R_386_TLS_TPOFF32 37 682 #define EF_ARM_RELEXEC 0x01 683 #define EF_ARM_HASENTRY 0x02 684 #define EF_ARM_INTERWORK 0x04 685 #define EF_ARM_APCS_26 0x08 686 #define EF_ARM_APCS_FLOAT 0x10 687 #define EF_ARM_PIC 0x20 688 #define EF_ARM_ALIGN8 0x40 689 #define EF_ARM_NEW_ABI 0x80 690 #define EF_ARM_OLD_ABI 0x100 694 #define EF_ARM_SYMSARESORTED 0x04 695 #define EF_ARM_DYNSYMSUSESEGIDX 0x08 696 #define EF_ARM_MAPSYMSFIRST 0x10 697 #define EF_ARM_EABIMASK 0XFF000000 699 #define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) 700 #define EF_ARM_EABI_UNKNOWN 0x00000000 701 #define EF_ARM_EABI_VER1 0x01000000 702 #define EF_ARM_EABI_VER2 0x02000000 705 #define STT_ARM_TFUNC 0xd 708 #define SHF_ARM_ENTRYSECT 0x10000000 709 #define SHF_ARM_COMDEF 0x80000000 713 #define PF_ARM_SB 0x10000000 719 #define R_ARM_ABS32 2 720 #define R_ARM_REL32 3 722 #define R_ARM_ABS16 5 723 #define R_ARM_ABS12 6 724 #define R_ARM_THM_ABS5 7 726 #define R_ARM_SBREL32 9 727 #define R_ARM_THM_PC22 10 728 #define R_ARM_THM_PC8 11 729 #define R_ARM_AMP_VCALL9 12 730 #define R_ARM_SWI24 13 731 #define R_ARM_THM_SWI8 14 732 #define R_ARM_XPC25 15 733 #define R_ARM_THM_XPC22 16 734 #define R_ARM_COPY 20 735 #define R_ARM_GLOB_DAT 21 736 #define R_ARM_JUMP_SLOT 22 737 #define R_ARM_RELATIVE 23 738 #define R_ARM_GOTOFF 24 739 #define R_ARM_GOTPC 25 740 #define R_ARM_GOT32 26 741 #define R_ARM_PLT32 27 742 #define R_ARM_ALU_PCREL_7_0 32 743 #define R_ARM_ALU_PCREL_15_8 33 744 #define R_ARM_ALU_PCREL_23_15 34 745 #define R_ARM_LDR_SBREL_11_0 35 746 #define R_ARM_ALU_SBREL_19_12 36 747 #define R_ARM_ALU_SBREL_27_20 37 748 #define R_ARM_GNU_VTENTRY 100 749 #define R_ARM_GNU_VTINHERIT 101 750 #define R_ARM_THM_PC11 102 751 #define R_ARM_THM_PC9 103 752 #define R_ARM_RXPC25 249 753 #define R_ARM_RSBREL32 250 754 #define R_ARM_THM_RPC22 251 755 #define R_ARM_RREL32 252 756 #define R_ARM_RABS22 253 757 #define R_ARM_RPC24 254 758 #define R_ARM_RBASE 255 760 #define R_ARM_NUM 256 763 #define R_X86_64_NONE 0 764 #define R_X86_64_64 1 765 #define R_X86_64_PC32 2 766 #define R_X86_64_GOT32 3 767 #define R_X86_64_PLT32 4 768 #define R_X86_64_COPY 5 769 #define R_X86_64_GLOB_DAT 6 770 #define R_X86_64_JUMP_SLOT 7 771 #define R_X86_64_RELATIVE 8 772 #define R_X86_64_GOTPCREL 9 774 #define R_X86_64_32 10 775 #define R_X86_64_32S 11 776 #define R_X86_64_16 12 777 #define R_X86_64_PC16 13 778 #define R_X86_64_8 14 779 #define R_X86_64_PC8 15 780 #define R_X86_64_DTPMOD64 16 781 #define R_X86_64_DTPOFF64 17 782 #define R_X86_64_TPOFF64 18 783 #define R_X86_64_TLSGD 19 785 #define R_X86_64_TLSLD 20 787 #define R_X86_64_DTPOFF32 21 788 #define R_X86_64_GOTTPOFF 22 790 #define R_X86_64_TPOFF32 23 792 #define R_X86_64_NUM 24 803 unsigned char st_info;
804 unsigned char st_other;
811 unsigned char st_info;
812 unsigned char st_other;
818 #define ELF32_ST_BIND(i) ((i)>>4) 819 #define ELF32_ST_TYPE(i) ((i)&0xf) 820 #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) 822 #define ELF64_ST_BIND(i) ((i)>>4) 823 #define ELF64_ST_TYPE(i) ((i)&0xf) 824 #define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) 833 #define STB_LOPROC 13 834 #define STB_HIPROC 15 841 #define STT_SECTION 3 845 #define STT_LOPROC 13 846 #define STT_HIPROC 15 870 typedef struct Elf32_Auxv
876 typedef struct Elf64_Auxv
883 static inline int l4util_elf_check_magic(ElfW(Ehdr) *hdr);
884 static inline int l4util_elf_check_arch(ElfW(Ehdr) *hdr);
885 static inline ElfW(Phdr) *l4util_elf_phdr(ElfW(Ehdr) *hdr);
890 int l4util_elf_check_magic(ElfW(Ehdr) *hdr)
899 int l4util_elf_check_arch(ElfW(Ehdr) *hdr)
901 return hdr->e_ident[
EI_CLASS] == L4_ARCH_EI_CLASS
902 && hdr->e_ident[
EI_DATA] == L4_ARCH_EI_DATA
903 && hdr->e_machine == L4_ARCH_E_MACHINE;
907 ElfW(Phdr) *l4util_elf_phdr(ElfW(Ehdr) *hdr)
909 return (ElfW(Phdr) *)((
char *)hdr + hdr->e_phoff);
Elf64_Addr e_entry
initial eip
l4_uint64_t Elf64_Addr
size 8 align 8
Elf64_Word sh_link
idx to associated header section
Elf64_Half e_phentsize
size of program header entry
l4_uint16_t Elf64_Half
size 2 align 2
Elf64_Half e_machine
required architecture
Elf32_Word sh_flags
section's flags
Elf32_Off e_shoff
offset of file header table
Elf32_Word e_version
file version
Elf32_Word e_flags
processor-specific flags
ELF32 section header - figure 1-9, page 1-9.
l4_uint32_t Elf32_Word
size 4 align 4
Elf32_Half e_type
type of ELF file
Elf32_Half e_shnum
of entries in sect.
signed int l4_int32_t
Signed 32bit value.
Elf32_Word sh_link
idx to associated header section
Elf64_Half e_shentsize
size of section header entry
Elf64_Half e_shnum
of entries in sect.
ELF32 symbol table entry.
Elf64_Xword sh_flags
section's flags
unsigned short int l4_uint16_t
Unsigned 16bit value.
l4_int32_t Elf32_Sword
size 4 align 4
Elf32_Half e_phentsize
size of program header entry
Elf32_Word sh_addralign
address alignment constraints
signed long long l4_int64_t
Signed 64bit value.
Elf32_Word sh_info
extra info of header section
#define ELFMAG1
e_ident[EI_MAG1]
Elf64_Half e_shstrndx
sect.head.tab.idx of strtab
Elf64_Xword sh_entsize
size of entry if sect is table
l4_int64_t Elf64_Sxword
size 8 align 8
l4_uint32_t Elf32_Addr
size 4 align 4
#define EI_CLASS
ELF class byte index.
#define ELFMAG0
e_ident[EI_MAG0]
Elf32_Word sh_size
file size of section
Elf32_Addr sh_addr
memory address of section
Elf32_Half e_shstrndx
sect.head.tab.idx of strtab
Elf64_Word e_flags
processor-specific flags
Elf32_Word sh_entsize
size of entry if sect is table
#define EI_DATA
Data encoding byte index.
Elf64_Off sh_offset
file offset of section
l4_uint64_t Elf64_Off
size 8 align 8
Elf32_Off e_phoff
offset of program header table
Elf64_Xword sh_addralign
address alignment constraints
#define ELFMAG3
e_ident[EI_MAG3]
Elf64_Half e_type
type of ELF file
Elf32_Addr e_entry
initial eip
Elf32_Word sh_name
name of sect (idx into strtab)
Elf32_Half e_shentsize
size of section header entry
Elf64_Word sh_type
section's type
Elf64_Off e_shoff
offset of file header table
Elf32_Half e_phnum
of entries in prog.
Elf32_Word sh_type
section's type
#define ELFMAG2
e_ident[EI_MAG2]
Elf64_Addr sh_addr
memory address of section
l4_uint64_t Elf64_Xword
size 8 align 8
Elf64_Half e_phnum
of entries in prog.
Elf32_Half e_machine
required architecture
Elf32_Half e_ehsize
size of ELF header
l4_uint32_t Elf32_Off
size 4 align 4
Elf64_Word e_version
file version
Elf64_Word sh_info
extra info of header section
Elf32_Off sh_offset
file offset of section
unsigned long long l4_uint64_t
Unsigned 64bit value.
l4_uint32_t Elf64_Word
size 4 align 4
#define EI_NIDENT
number of characters
Elf64_Xword sh_size
file size of section
l4_uint16_t Elf32_Half
size 2 align 2
Elf64_Half e_ehsize
size of ELF header
ELF64 symbol table entry.
Elf64_Word sh_name
name of sect (idx into strtab)
l4_int32_t Elf64_Sword
size 4 align 4
unsigned int l4_uint32_t
Unsigned 32bit value.
Elf64_Off e_phoff
offset of program header table