📄 elf.h
字号:
/* *---------------------------------------------------------------------- * T-Kernel / Standard Extension * * Copyright (C) 2006 by Ken Sakamura. All rights reserved. * T-Kernel / Standard Extension is distributed * under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * * Version: 1.00.00 * Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* * elf.h * * ELF (Executable and Linking Format) definitions */#ifndef __SYS_ELF_H__#define __SYS_ELF_H__#include <basic.h>#ifdef __cplusplusextern "C" {#endif/* ELF header */#define EI_NIDENT 16typedef struct { UB e_ident[EI_NIDENT]; /* ELF identifier */ UH e_type; /* Object format */ UH e_machine; /* Model */ UW e_version; /* File format/version */ VP e_entry; /* Entry address */ UW e_phoff; /* Position of program header */ UW e_shoff; /* Position of section header */ UW e_flags; /* Flag (EF_xxx) */ UH e_ehsize; /* ELF header size */ UH e_phentsize; /* Size of a program header */ UH e_phnum; /* Number of program headers */ UH e_shentsize; /* Size of a section header */ UH e_shnum; /* Number of section headers */ UH e_shstrndx; /* Position of section header character sting */} Elf32_Ehdr;/* Index of e_ident[] */#define EI_MAG0 0 /* Magic */#define EI_MAG1 1#define EI_MAG2 2#define EI_MAG3 3#define EI_CLASS 4 /* File class */#define EI_DATA 5 /* Data encoding */#define EI_VERSION 6 /* ELF version */#define EI_PAD 7 /* Reserved (0) *//* EI_MAG */#define ELFMAG0 0x7fU#define ELFMAG1 'E'#define ELFMAG2 'L'#define ELFMAG3 'F'/* EI_CLASS */#define ELFCLASSNONE 0 /* Invalid */#define ELFCLASS32 1 /* 32bit object */#define ELFCLASS64 2 /* 64bit object *//* EI_DATA */#define ELFDATANONE 0 /* Invalid */#define ELFDATA2LSB 1 /* Two's complement, little endian */#define ELFDATA2MSB 2 /* Two's complement, big endian *//* e_type */#define ET_NONE 0U /* Unknown */#define ET_REL 1U /* Relocatable format */#define ET_EXEC 2U /* Executable format */#define ET_DYN 3U /* Shared object format */#define ET_CORE 4U /* core format */#define ET_LOPROC 0xff00U /* CPU-specific */#define ET_HIPROC 0xffffU/* e_machine */#define EM_NONE 0 /* Unknown */#define EM_M32 1 /* AT&T WE 32100 */#define EM_SPARC 2 /* Sun SPARC */#define EM_386 3 /* Intel 80386 */#define EM_68K 4 /* Motorola 68000 */#define EM_88K 5 /* Motorola 88000 */#define EM_486 6 /* Intel 80486 */#define EM_860 7 /* Intel i860 */#define EM_MIPS 8 /* MIPS R3000 */#define EM_V810 0x24 /* NEC V810 */#define EM_ARM 40 /* ARM */#define EM_SH 42 /* Hitachi SH *//* e_version, EI_VERSION */#define EV_NONE 0 /* Invalid */#define EV_CURRENT 1 /* Current version *//* Section header */typedef struct { UW sh_name; /* Section name (index) */ UW sh_type; /* Section type (SHT_xxx) */ UW sh_flags; /* Section flag (SHF_xxx) */ VP sh_addr; /* Address */ UW sh_offset; /* Section position */ UW sh_size; /* Section size */ UW sh_link; /* Section connection information */ UW sh_info; /* Extension information */ UW sh_addralign; /* Alignment */ UW sh_entsize; /* Entry size */} Elf32_Shdr;/* sh_name : Special section name index */#define SHN_UNDEF 0U /* Not defined */#define SHN_LORESERVE 0xff00U /* Start of special section name index */#define SHN_ABS 0xfff1U /* Fixed value section */#define SHN_COMMON 0xfff2U /* Shared symbol section */#define SHN_HIRESERVE 0xffffU /* End of special section name index */#define SHN_LOPROC 0xff00U /* CPU-specific */#define SHN_HIPROC 0xff1fU/* sh_type */#define SHT_NULL 0U /* Invalid section */#define SHT_PROGBITS 1U /* Program */#define SHT_SYMTAB 2U /* Symbol table */#define SHT_STRTAB 3U /* String table */#define SHT_RELA 4U /* Relocation information */#define SHT_HASH 5U /* Symbol hash table */#define SHT_DYNAMIC 6U /* Dynamic link information */#define SHT_NOTE 7U /* Note */#define SHT_NOBITS 8U /* Free section */#define SHT_REL 9U /* Relocation information */#define SHT_SHLIB 10U /* (Reserved) */#define SHT_DYNSYM 11U /* Symbol table for dynamic link */#define SHT_LOUSER 0x80000000U /* Application-specific */#define SHT_HIUSER 0xffffffffU#define SHT_LOPROC 0x70000000U /* CPU-specific */#define SHT_HIPROC 0x7fffffffU#define SHT_MIPS_REGINFO 0x70000006U /* MIPS-specific *//* sh_flags */#define SHF_WRITE 0x1U /* Write enabled at runtime */#define SHF_ALLOC 0x2U /* Occupy memory at runtime*/#define SHF_EXECINSTR 0x4U /* Include execution command */#define SHF_MASKPROC 0xf0000000U /* CPU-specific *//* Symbol table */typedef struct { UW st_name; /* Symbol name (index) */ VP st_value; /* Value */ UW st_size; /* Size */ UB st_info; /* Symbol type and join attribute */ UB st_other; /* Reserved (0) */ UH st_shndx; /* Section index */} Elf32_Sym;#define STN_UNDEF 0 /* Not defined *//* st_info */#define ELF32_ST_BIND(info) ((UB)(info) >> 4)#define ELF32_ST_TYPE(info) ((UB)(info) & 0xf)#define ELF32_ST_INFO(bind, type) (UB)(((bind) << 4) + ((type) & 0xf))/* st_info : bind */#define STB_LOCAL 0U /* Local symbol */#define STB_GLOBAL 1U /* Global symbol */#define STB_WEAK 2U /* Weak global symbol */#define STB_LOPROC 13U /* CPU-specific */#define STB_HIPROC 15U/* st_info : type */#define STT_NOTYPE 0U /* Not defined */#define STT_OBJECT 1U /* Data */#define STT_FUNC 2U /* Function */#define STT_SECTION 3U /* Section */#define STT_FILE 4U /* File name */#define STT_LOPROC 13U /* CPU-specific */#define STT_HIPROC 15U/* st_other */#define STO_MIPS16 0xf0 /* mips16 *//* Relocation */typedef struct { VP r_offset; /* Position to be relocated */ UW r_info; /* Symbol number and relocation type */} Elf32_Rel;typedef struct { VP r_offset; /* Position to be relocated */ UW r_info; /* Symbol number and relocation type */ W r_addend; /* Constant to be added */} Elf32_Rela;/* r_info */#define ELF32_R_SYM(info) ((UW)(info) >> 8)#define ELF32_R_TYPE(info) ((UB)(info))#define ELF32_R_INFO(sym, type) (UW)(((sym) << 8) + (UB)(type))/* i386 Relocation Type */#define R_386_NONE 0#define R_386_32 1#define R_386_PC32 2#define R_386_GOT32 3#define R_386_PLT32 4#define R_386_COPY 5#define R_386_GLOB_DAT 6#define R_386_JMP_SLOT 7#define R_386_RELATIVE 8#define R_386_GOTOFF 9#define R_386_GOTPC 10/* SH Relocation Type */#define R_SH_NONE 0 /* No relocation */#define R_SH_DIR32 1 /* 32 bit absolute relocation */#define R_SH_REL32 2 /* 32 bit PC relative relocation */#define R_SH_DIR8WPN 3 /* 8 bit PC relative branch divided by 2 */#define R_SH_IND12W 4 /* 12 bit PC relative branch divided by 2 */#define R_SH_DIR8WPL 5 /* 8 bit unsigned PC relative divided by 4 */#define R_SH_DIR8WPZ 6 /* 8 bit unsigned PC relative divided by 2 */#define R_SH_DIR8BP 7 /* 8 bit GBR relative */#define R_SH_DIR8W 8 /* 8 bit GBR relative divided by 2 */#define R_SH_DIR8L 9 /* 8 bit GBR relative divided by 4 */#define R_SH_GOT32 160#define R_SH_PLT32 161#define R_SH_COPY 162#define R_SH_GLOB_DAT 163#define R_SH_JMP_SLOT 164#define R_SH_RELATIVE 165/* ARM Relocation Type */#define R_ARM_NONE 0#define R_ARM_PC24 1#define R_ARM_ABS32 2#define R_ARM_REL32 3#define R_ARM_THM_PC22 10#define R_ARM_COPY 20 /* Copy symbol at runtime. */#define R_ARM_GLOB_DAT 21 /* Create GOT entry. */#define R_ARM_JUMP_SLOT 22 /* Create PLT entry. */#define R_ARM_RELATIVE 23 /* Adjust by program base. */#define R_ARM_GOTOFF 24 /* 32 bit offset to GOT. */#define R_ARM_GOTPC 25 /* 32 bit PC relative offset to GOT. */#define R_ARM_GOT32 26 /* 32 bit GOT entry. */#define R_ARM_PLT32 27 /* 32 bit PLT address. *//* MIPS Relocation Type */#define R_MIPS_NONE 0#define R_MIPS_16 1#define R_MIPS_32 2#define R_MIPS_REL32 3#define R_MIPS_26 4#define R_MIPS_HI16 5#define R_MIPS_LO16 6#define R_MIPS_GPREL16 7#define R_MIPS_LITERAL 8#define R_MIPS16_26 100#define R_MIPS16_GPREL 101/* Program header */typedef struct { UW p_type; /* Segment format */ UW p_offset; /* Segment position */ VP p_vaddr; /* Virtual address */ VP p_paddr; /* Physical address */ UW p_filesz; /* Segment size in file */ UW p_memsz; /* Segment size on memory */ UW p_flags; /* Flag (PF_xxx) */ UW p_align; /* Alignment */} Elf32_Phdr;/* p_type */#define PT_NULL 0 /* Invalid segment */#define PT_LOAD 1 /* Loadable segment */#define PT_DYNAMIC 2 /* Dynamic link information */#define PT_INTERP 3 /* Interpreter path name */#define PT_NOTE 4 /* Supplementary information */#define PT_SHLIB 5 /* (Reserved) */#define PT_PHDR 6 /* Program header itself */#define PT_LOPROC 0x70000000 /* CPU-specific */#define PT_HIPROC 0x7fffffff/* p_flags */#define PF_R 0x4 /* Read */#define PF_W 0x2 /* Write */#define PF_X 0x1 /* Execute */#define PF_MASKPROC 0xf0000000 /* CPU-specific *//* Dynamic structure */typedef struct { W d_tag; /* Type */ union { UW d_val; /* Value */ VP d_ptr; /* Virtual address */ } d_un;} Elf32_Dyn;IMPORT Elf32_Dyn _DYNAMIC[];/* d_tag I:ignored V:d_val P:d_ptr */#define DT_NULL 0 /* I: _DYNAMIC end mark */#define DT_NEEDED 1 /* V: Dependent library name */#define DT_PLTRELSZ 2 /* V: PLT size */#define DT_PLTGOT 3 /* P: PLT and/or GOT */#define DT_HASH 4 /* P: Symbol hash table */#define DT_STRTAB 5 /* P: String table */#define DT_SYMTAB 6 /* P: Symbol table */#define DT_RELA 7 /* P: Relocation table Elf32_Rela */#define DT_RELASZ 8 /* V: Total size of DT_RELA */#define DT_RELAENT 9 /* V: Size of DT_RELA entry */#define DT_STRSZ 10 /* V: Size of string table */#define DT_SYMENT 11 /* V: Size of symbol table entry */#define DT_INIT 12 /* P: Address of initialization processing function */#define DT_FINI 13 /* P: Address of termination processing function */#define DT_SONAME 14 /* V: Shared object name */#define DT_RPATH 15 /* V: Library search path name */#define DT_SYMBOLIC 16 /* I: Specify change of symbol analysis method */#define DT_REL 17 /* P: Relocation table Elf32_Rel */#define DT_RELSZ 18 /* V: Total size of DT_REL */#define DT_RELENT 19 /* V: Size of DT_REL entry */#define DT_PLTREL 20 /* V: Relocation type REL/RELA of PLT */#define DT_DEBUG 21 /* P: For debugging */#define DT_TEXTREL 22 /* I: Specify text relocation */#define DT_JMPREL 23 /* P: Position of PLTREL that allows lazy binding */#define DT_LOPROC 0x70000000 /* CPU-dependent From */#define DT_HIPROC 0x7fffffff /* To */#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local GOT entries */#define DT_MIPS_SYMTABNO 0x70000011 /* Number of DYNSYM entries */#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry *//* Global offset table */IMPORT VP _GLOBAL_OFFSET_TABLE_[];/* Hashing function */Inline UW Elf_hash( const UB *name ){ UW h = 0, g; while ( *name != '\0' ) { h = (h << 4) + *(name++); g = h & 0xf0000000U; h = (h ^ (g >> 24)) & ~g; } return h;}/* Register Information */typedef struct { UW ri_gprmask; /* General-purpose register in use */ UW ri_cprmask[4]; /* Coprocessor register in use */ W ri_gp_value; /* gp register value */} Elf32_RegInfo;#ifdef __cplusplus}#endif#endif /* __SYS_ELF_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -