00001 /* $NetBSD: readelf.h,v 1.9 2002/05/18 07:00:47 pooka Exp $ */ 00002 /*@-redef@*/ 00003 00004 /* 00005 * readelf.h 00006 * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp 00007 * 00008 * Provide elf data structures for non-elf machines, allowing file 00009 * non-elf hosts to determine if an elf binary is stripped. 00010 * Note: cobbled from the linux header file, with modifications 00011 */ 00012 #ifndef __fake_elf_h__ 00013 #define __fake_elf_h__ 00014 00015 #if HAVE_STDINT_H 00016 #include <stdint.h> 00017 #endif 00018 00019 typedef uint32_t Elf32_Addr; 00020 typedef uint32_t Elf32_Off; 00021 typedef uint16_t Elf32_Half; 00022 typedef uint32_t Elf32_Word; 00023 typedef uint8_t Elf32_Char; 00024 00025 #if SIZEOF_UINT64_T != 8 00026 #define USE_ARRAY_FOR_64BIT_TYPES 00027 typedef uint32_t Elf64_Addr[2]; 00028 typedef uint32_t Elf64_Off[2]; 00029 typedef uint32_t Elf64_Xword[2]; 00030 #else 00031 typedef uint64_t Elf64_Addr; 00032 typedef uint64_t Elf64_Off; 00033 typedef uint64_t Elf64_Xword; 00034 #endif 00035 typedef uint16_t Elf64_Half; 00036 typedef uint32_t Elf64_Word; 00037 typedef uint8_t Elf64_Char; 00038 00039 #define EI_NIDENT 16 00040 00041 /*@-matchfields@*/ 00042 typedef struct { 00043 Elf32_Char e_ident[EI_NIDENT]; 00044 Elf32_Half e_type; 00045 Elf32_Half e_machine; 00046 Elf32_Word e_version; 00047 Elf32_Addr e_entry; /* Entry point */ 00048 Elf32_Off e_phoff; 00049 Elf32_Off e_shoff; 00050 Elf32_Word e_flags; 00051 Elf32_Half e_ehsize; 00052 Elf32_Half e_phentsize; 00053 Elf32_Half e_phnum; 00054 Elf32_Half e_shentsize; 00055 Elf32_Half e_shnum; 00056 Elf32_Half e_shstrndx; 00057 } Elf32_Ehdr; 00058 00059 typedef struct { 00060 Elf64_Char e_ident[EI_NIDENT]; 00061 Elf64_Half e_type; 00062 Elf64_Half e_machine; 00063 Elf64_Word e_version; 00064 Elf64_Addr e_entry; /* Entry point */ 00065 Elf64_Off e_phoff; 00066 Elf64_Off e_shoff; 00067 Elf64_Word e_flags; 00068 Elf64_Half e_ehsize; 00069 Elf64_Half e_phentsize; 00070 Elf64_Half e_phnum; 00071 Elf64_Half e_shentsize; 00072 Elf64_Half e_shnum; 00073 Elf64_Half e_shstrndx; 00074 } Elf64_Ehdr; 00075 /*@=matchfields@*/ 00076 00077 /* e_type */ 00078 #define ET_EXEC 2 00079 #define ET_CORE 4 00080 00081 /* sh_type */ 00082 #define SHT_SYMTAB 2 00083 #define SHT_NOTE 7 00084 #define SHT_DYNSYM 11 00085 00086 /* elf type */ 00087 #define ELFDATANONE 0 /* e_ident[EI_DATA] */ 00088 #define ELFDATA2LSB 1 00089 #define ELFDATA2MSB 2 00090 00091 /* elf class */ 00092 #define ELFCLASSNONE 0 00093 #define ELFCLASS32 1 00094 #define ELFCLASS64 2 00095 00096 /* magic number */ 00097 #define EI_MAG0 0 /* e_ident[] indexes */ 00098 #define EI_MAG1 1 00099 #define EI_MAG2 2 00100 #define EI_MAG3 3 00101 #define EI_CLASS 4 00102 #define EI_DATA 5 00103 #define EI_VERSION 6 00104 #define EI_PAD 7 00105 00106 #define ELFMAG0 0x7f /* EI_MAG */ 00107 #define ELFMAG1 'E' 00108 #define ELFMAG2 'L' 00109 #define ELFMAG3 'F' 00110 #define ELFMAG "\177ELF" 00111 00112 #define OLFMAG1 'O' 00113 #define OLFMAG "\177OLF" 00114 00115 typedef struct { 00116 Elf32_Word p_type; 00117 Elf32_Off p_offset; 00118 Elf32_Addr p_vaddr; 00119 Elf32_Addr p_paddr; 00120 Elf32_Word p_filesz; 00121 Elf32_Word p_memsz; 00122 Elf32_Word p_flags; 00123 Elf32_Word p_align; 00124 } Elf32_Phdr; 00125 00126 typedef struct { 00127 Elf64_Word p_type; 00128 Elf64_Word p_flags; 00129 Elf64_Off p_offset; 00130 Elf64_Addr p_vaddr; 00131 Elf64_Addr p_paddr; 00132 Elf64_Xword p_filesz; 00133 Elf64_Xword p_memsz; 00134 Elf64_Xword p_align; 00135 } Elf64_Phdr; 00136 00137 #define PT_NULL 0 /* p_type */ 00138 #define PT_LOAD 1 00139 #define PT_DYNAMIC 2 00140 #define PT_INTERP 3 00141 #define PT_NOTE 4 00142 #define PT_SHLIB 5 00143 #define PT_PHDR 6 00144 #define PT_NUM 7 00145 00146 typedef struct { 00147 Elf32_Word sh_name; 00148 Elf32_Word sh_type; 00149 Elf32_Word sh_flags; 00150 Elf32_Addr sh_addr; 00151 Elf32_Off sh_offset; 00152 Elf32_Word sh_size; 00153 Elf32_Word sh_link; 00154 Elf32_Word sh_info; 00155 Elf32_Word sh_addralign; 00156 Elf32_Word sh_entsize; 00157 } Elf32_Shdr; 00158 00159 /*@-matchfields@*/ 00160 typedef struct { 00161 Elf64_Word sh_name; 00162 Elf64_Word sh_type; 00163 Elf64_Off sh_flags; 00164 Elf64_Addr sh_addr; 00165 Elf64_Off sh_offset; 00166 Elf64_Off sh_size; 00167 Elf64_Word sh_link; 00168 Elf64_Word sh_info; 00169 Elf64_Off sh_addralign; 00170 Elf64_Off sh_entsize; 00171 } Elf64_Shdr; 00172 /*@=matchfields@*/ 00173 00174 /* Notes used in ET_CORE */ 00175 #define NT_PRSTATUS 1 00176 #define NT_PRFPREG 2 00177 #define NT_PRPSINFO 3 00178 #define NT_TASKSTRUCT 4 00179 00180 #define NT_NETBSD_CORE_PROCINFO 1 00181 00182 /* Note header in a PT_NOTE section */ 00183 typedef struct elf_note { 00184 Elf32_Word n_namesz; /* Name size */ 00185 Elf32_Word n_descsz; /* Content size */ 00186 Elf32_Word n_type; /* Content type */ 00187 } Elf32_Nhdr; 00188 00189 typedef struct { 00190 Elf64_Word n_namesz; 00191 Elf64_Word n_descsz; 00192 Elf64_Word n_type; 00193 } Elf64_Nhdr; 00194 00195 #define NT_PRSTATUS 1 00196 #define NT_PRFPREG 2 00197 #define NT_PRPSINFO 3 00198 #define NT_PRXREG 4 00199 #define NT_PLATFORM 5 00200 #define NT_AUXV 6 00201 00202 /* Note types used in executables */ 00203 /* NetBSD executables (name = "NetBSD") */ 00204 #define NT_NETBSD_VERSION 1 00205 #define NT_NETBSD_EMULATION 2 00206 #define NT_FREEBSD_VERSION 1 00207 #define NT_OPENBSD_VERSION 1 00208 /* GNU executables (name = "GNU") */ 00209 #define NT_GNU_VERSION 1 00210 00211 /* GNU OS tags */ 00212 #define GNU_OS_LINUX 0 00213 #define GNU_OS_HURD 1 00214 #define GNU_OS_SOLARIS 2 00215 /*@=redef@*/ 00216 00217 #endif