00001 #ifndef _ELF_H 00002 #define _ELF_H 00003 00004 /// THese constants are for the segment types stored in the image headers 00005 #define PT_NULL 0 00006 #define PT_LOAD 1 00007 #define PT_DYNAMIC 2 00008 #define PT_INTERP 3 00009 #define PT_NOTE 4 00010 #define PT_SHLIB 5 00011 #define PT_PHDR 6 00012 #define PT_LOPROC 0x70000000 00013 #define PT_HIPROC 0x7fffffff 00014 00015 /// These constants define the different elf file types 00016 #define ET_NONE 0 00017 #define ET_REL 1 00018 #define ET_EXEC 2 00019 #define ET_DYN 3 00020 #define ET_CORE 4 00021 #define ET_LOPROC 5 00022 #define ET_HIPROC 6 00023 00024 /// These constants define the various ELF target machines 00025 #define EM_NONE 0 00026 #define EM_M32 1 00027 #define EM_SPARC 2 00028 #define EM_386 3 00029 #define EM_68K 4 00030 #define EM_88K 5 00031 #define EM_486 6 ///< Perhaps disused 00032 #define EM_860 7 00033 00034 /// This is the info that is needed to parse the dynamic section of the file 00035 #define DT_NULL 0 00036 #define DT_NEEDED 1 00037 #define DT_PLTRELSZ 2 00038 #define DT_PLTGOT 3 00039 #define DT_HASH 4 00040 #define DT_STRTAB 5 00041 #define DT_SYMTAB 6 00042 #define DT_RELA 7 00043 #define DT_RELASZ 8 00044 #define DT_RELAENT 9 00045 #define DT_STRSZ 10 00046 #define DT_SYMENT 11 00047 #define DT_INIT 12 00048 #define DT_FINI 13 00049 #define DT_SONAME 14 00050 #define DT_RPATH 15 00051 #define DT_SYMBOLIC 16 00052 #define DT_REL 17 00053 #define DT_RELSZ 18 00054 #define DT_RELENT 19 00055 #define DT_PLTREL 20 00056 #define DT_DEBUG 21 00057 #define DT_TEXTREL 22 00058 #define DT_JMPREL 23 00059 #define DT_LOPROC 0x70000000 00060 #define DT_HIPROC 0x7fffffff 00061 00062 /// This info is needed when parsing the symbol table 00063 #define STB_LOCAL 0 00064 #define STB_GLOBAL 1 00065 #define STB_WEAK 2 00066 00067 #define STT_NOTYPE 0 00068 #define STT_OBJECT 1 00069 #define STT_FUNC 2 00070 #define STT_SECTION 3 00071 #define STT_FILE 4 00072 00073 #define ELF32_ST_BIND(x) ((x) >> 4) 00074 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) 00075 00076 00077 00078 struct dynamic{ 00079 int d_tag; 00080 union{ 00081 int d_val; 00082 char * d_ptr; 00083 } d_un; 00084 }; 00085 00086 /// THe following are used with relocations 00087 #define ELF32_R_SYM(x) ((x) >> 8) 00088 #define ELF32_R_TYPE(x) ((x) & 0xff) 00089 00090 #define R_386_NONE 0 00091 #define R_386_32 1 00092 #define R_386_PC32 2 00093 #define R_386_GOT32 3 00094 #define R_386_PLT32 4 00095 #define R_386_COPY 5 00096 #define R_386_GLOB_DAT 6 00097 #define R_386_JMP_SLOT 7 00098 #define R_386_RELATIVE 8 00099 #define R_386_GOTOFF 9 00100 #define R_386_GOTPC 10 00101 #define R_386_NUM 11 00102 00103 struct Elf32_Rel{ 00104 unsigned int * offset; 00105 int info; 00106 }; 00107 00108 struct Elf32_Rela{ 00109 unsigned int * offset; 00110 int info; 00111 int addend; 00112 }; 00113 00114 struct Elf32_Sym{ 00115 int st_name; 00116 unsigned int st_value; 00117 int st_size; 00118 unsigned char st_info; 00119 unsigned char st_other; 00120 short int st_shndx; 00121 }; 00122 00123 struct elfhdr{ 00124 char e_ident[16]; 00125 short int e_type; 00126 short int e_machine; 00127 int e_version; 00128 char *e_entry; ///< Entry point 00129 int e_phoff; 00130 int e_shoff; 00131 int e_flags; 00132 short int e_ehsize; 00133 short int e_phentsize; 00134 short int e_phnum; 00135 short int e_shentsize; 00136 short int e_shnum; 00137 short int e_shstrndx; 00138 }; 00139 00140 struct elf_phdr{ 00141 int p_type; 00142 int p_offset; 00143 int p_vaddr; 00144 int p_paddr; 00145 int p_filesz; 00146 int p_memsz; 00147 int p_flags; 00148 int p_align; 00149 }; 00150 00151 #define ELF_START_MMAP 0x80000000 00152 00153 #endif
1.4.6-5