1 /* $NetBSD: readelf.h,v 1.1.1.6 2015/01/02 20:34:27 christos Exp $ */ 2 3 /* 4 * Copyright (c) Christos Zoulas 2003. 5 * All Rights Reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice immediately at the beginning of the file, without modification, 12 * this list of conditions, and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 /* 30 * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp 31 * 32 * Provide elf data structures for non-elf machines, allowing file 33 * non-elf hosts to determine if an elf binary is stripped. 34 * Note: cobbled from the linux header file, with modifications 35 */ 36 #ifndef __fake_elf_h__ 37 #define __fake_elf_h__ 38 39 #if HAVE_STDINT_H 40 #include <stdint.h> 41 #endif 42 43 typedef uint32_t Elf32_Addr; 44 typedef uint32_t Elf32_Off; 45 typedef uint16_t Elf32_Half; 46 typedef uint32_t Elf32_Word; 47 typedef uint8_t Elf32_Char; 48 49 typedef uint64_t Elf64_Addr; 50 typedef uint64_t Elf64_Off; 51 typedef uint64_t Elf64_Xword; 52 typedef uint16_t Elf64_Half; 53 typedef uint32_t Elf64_Word; 54 typedef uint8_t Elf64_Char; 55 56 #define EI_NIDENT 16 57 58 typedef struct { 59 Elf32_Char e_ident[EI_NIDENT]; 60 Elf32_Half e_type; 61 Elf32_Half e_machine; 62 Elf32_Word e_version; 63 Elf32_Addr e_entry; /* Entry point */ 64 Elf32_Off e_phoff; 65 Elf32_Off e_shoff; 66 Elf32_Word e_flags; 67 Elf32_Half e_ehsize; 68 Elf32_Half e_phentsize; 69 Elf32_Half e_phnum; 70 Elf32_Half e_shentsize; 71 Elf32_Half e_shnum; 72 Elf32_Half e_shstrndx; 73 } Elf32_Ehdr; 74 75 typedef struct { 76 Elf64_Char e_ident[EI_NIDENT]; 77 Elf64_Half e_type; 78 Elf64_Half e_machine; 79 Elf64_Word e_version; 80 Elf64_Addr e_entry; /* Entry point */ 81 Elf64_Off e_phoff; 82 Elf64_Off e_shoff; 83 Elf64_Word e_flags; 84 Elf64_Half e_ehsize; 85 Elf64_Half e_phentsize; 86 Elf64_Half e_phnum; 87 Elf64_Half e_shentsize; 88 Elf64_Half e_shnum; 89 Elf64_Half e_shstrndx; 90 } Elf64_Ehdr; 91 92 /* e_type */ 93 #define ET_REL 1 94 #define ET_EXEC 2 95 #define ET_DYN 3 96 #define ET_CORE 4 97 98 /* e_machine (used only for SunOS 5.x hardware capabilities) */ 99 #define EM_SPARC 2 100 #define EM_386 3 101 #define EM_SPARC32PLUS 18 102 #define EM_SPARCV9 43 103 #define EM_IA_64 50 104 #define EM_AMD64 62 105 106 /* sh_type */ 107 #define SHT_SYMTAB 2 108 #define SHT_NOTE 7 109 #define SHT_DYNSYM 11 110 #define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */ 111 112 /* elf type */ 113 #define ELFDATANONE 0 /* e_ident[EI_DATA] */ 114 #define ELFDATA2LSB 1 115 #define ELFDATA2MSB 2 116 117 /* elf class */ 118 #define ELFCLASSNONE 0 119 #define ELFCLASS32 1 120 #define ELFCLASS64 2 121 122 /* magic number */ 123 #define EI_MAG0 0 /* e_ident[] indexes */ 124 #define EI_MAG1 1 125 #define EI_MAG2 2 126 #define EI_MAG3 3 127 #define EI_CLASS 4 128 #define EI_DATA 5 129 #define EI_VERSION 6 130 #define EI_PAD 7 131 132 #define ELFMAG0 0x7f /* EI_MAG */ 133 #define ELFMAG1 'E' 134 #define ELFMAG2 'L' 135 #define ELFMAG3 'F' 136 #define ELFMAG "\177ELF" 137 138 #define OLFMAG1 'O' 139 #define OLFMAG "\177OLF" 140 141 typedef struct { 142 Elf32_Word p_type; 143 Elf32_Off p_offset; 144 Elf32_Addr p_vaddr; 145 Elf32_Addr p_paddr; 146 Elf32_Word p_filesz; 147 Elf32_Word p_memsz; 148 Elf32_Word p_flags; 149 Elf32_Word p_align; 150 } Elf32_Phdr; 151 152 typedef struct { 153 Elf64_Word p_type; 154 Elf64_Word p_flags; 155 Elf64_Off p_offset; 156 Elf64_Addr p_vaddr; 157 Elf64_Addr p_paddr; 158 Elf64_Xword p_filesz; 159 Elf64_Xword p_memsz; 160 Elf64_Xword p_align; 161 } Elf64_Phdr; 162 163 #define PT_NULL 0 /* p_type */ 164 #define PT_LOAD 1 165 #define PT_DYNAMIC 2 166 #define PT_INTERP 3 167 #define PT_NOTE 4 168 #define PT_SHLIB 5 169 #define PT_PHDR 6 170 #define PT_NUM 7 171 172 typedef struct { 173 Elf32_Word sh_name; 174 Elf32_Word sh_type; 175 Elf32_Word sh_flags; 176 Elf32_Addr sh_addr; 177 Elf32_Off sh_offset; 178 Elf32_Word sh_size; 179 Elf32_Word sh_link; 180 Elf32_Word sh_info; 181 Elf32_Word sh_addralign; 182 Elf32_Word sh_entsize; 183 } Elf32_Shdr; 184 185 typedef struct { 186 Elf64_Word sh_name; 187 Elf64_Word sh_type; 188 Elf64_Off sh_flags; 189 Elf64_Addr sh_addr; 190 Elf64_Off sh_offset; 191 Elf64_Off sh_size; 192 Elf64_Word sh_link; 193 Elf64_Word sh_info; 194 Elf64_Off sh_addralign; 195 Elf64_Off sh_entsize; 196 } Elf64_Shdr; 197 198 #define NT_NETBSD_CORE_PROCINFO 1 199 200 /* Note header in a PT_NOTE section */ 201 typedef struct elf_note { 202 Elf32_Word n_namesz; /* Name size */ 203 Elf32_Word n_descsz; /* Content size */ 204 Elf32_Word n_type; /* Content type */ 205 } Elf32_Nhdr; 206 207 typedef struct { 208 Elf64_Word n_namesz; 209 Elf64_Word n_descsz; 210 Elf64_Word n_type; 211 } Elf64_Nhdr; 212 213 /* Notes used in ET_CORE */ 214 #define NT_PRSTATUS 1 215 #define NT_PRFPREG 2 216 #define NT_PRPSINFO 3 217 #define NT_PRXREG 4 218 #define NT_TASKSTRUCT 4 219 #define NT_PLATFORM 5 220 #define NT_AUXV 6 221 222 /* Note types used in executables */ 223 /* NetBSD executables (name = "NetBSD") */ 224 #define NT_NETBSD_VERSION 1 225 #define NT_NETBSD_EMULATION 2 226 #define NT_FREEBSD_VERSION 1 227 #define NT_OPENBSD_VERSION 1 228 #define NT_DRAGONFLY_VERSION 1 229 /* 230 * GNU executables (name = "GNU") 231 * word[0]: GNU OS tags 232 * word[1]: major version 233 * word[2]: minor version 234 * word[3]: tiny version 235 */ 236 #define NT_GNU_VERSION 1 237 238 /* GNU OS tags */ 239 #define GNU_OS_LINUX 0 240 #define GNU_OS_HURD 1 241 #define GNU_OS_SOLARIS 2 242 #define GNU_OS_KFREEBSD 3 243 #define GNU_OS_KNETBSD 4 244 245 /* 246 * GNU Hardware capability information 247 * word[0]: Number of entries 248 * word[1]: Bitmask of enabled entries 249 * Followed by a byte id, and a NUL terminated string per entry 250 */ 251 #define NT_GNU_HWCAP 2 252 253 /* 254 * GNU Build ID generated by ld 255 * 160 bit SHA1 [default] 256 * 128 bit md5 or uuid 257 */ 258 #define NT_GNU_BUILD_ID 3 259 260 /* 261 * NetBSD-specific note type: PaX. 262 * There should be 1 NOTE per executable. 263 * name: PaX\0 264 * namesz: 4 265 * desc: 266 * word[0]: capability bitmask 267 * descsz: 4 268 */ 269 #define NT_NETBSD_PAX 3 270 #define NT_NETBSD_PAX_MPROTECT 0x01 /* Force enable Mprotect */ 271 #define NT_NETBSD_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */ 272 #define NT_NETBSD_PAX_GUARD 0x04 /* Force enable Segvguard */ 273 #define NT_NETBSD_PAX_NOGUARD 0x08 /* Force disable Servguard */ 274 #define NT_NETBSD_PAX_ASLR 0x10 /* Force enable ASLR */ 275 #define NT_NETBSD_PAX_NOASLR 0x20 /* Force disable ASLR */ 276 277 /* 278 * NetBSD-specific note type: MACHINE_ARCH. 279 * There should be 1 NOTE per executable. 280 * name: NetBSD\0 281 * namesz: 7 282 * desc: string 283 * descsz: variable 284 */ 285 #define NT_NETBSD_MARCH 5 286 287 /* 288 * NetBSD-specific note type: COMPILER MODEL. 289 * There should be 1 NOTE per executable. 290 * name: NetBSD\0 291 * namesz: 7 292 * desc: string 293 * descsz: variable 294 */ 295 #define NT_NETBSD_CMODEL 6 296 297 #if !defined(ELFSIZE) && defined(ARCH_ELFSIZE) 298 #define ELFSIZE ARCH_ELFSIZE 299 #endif 300 /* SunOS 5.x hardware/software capabilities */ 301 typedef struct { 302 Elf32_Word c_tag; 303 union { 304 Elf32_Word c_val; 305 Elf32_Addr c_ptr; 306 } c_un; 307 } Elf32_Cap; 308 309 typedef struct { 310 Elf64_Xword c_tag; 311 union { 312 Elf64_Xword c_val; 313 Elf64_Addr c_ptr; 314 } c_un; 315 } Elf64_Cap; 316 317 /* SunOS 5.x hardware/software capability tags */ 318 #define CA_SUNW_NULL 0 319 #define CA_SUNW_HW_1 1 320 #define CA_SUNW_SF_1 2 321 322 /* SunOS 5.x software capabilities */ 323 #define SF1_SUNW_FPKNWN 0x01 324 #define SF1_SUNW_FPUSED 0x02 325 #define SF1_SUNW_MASK 0x03 326 327 /* SunOS 5.x hardware capabilities: sparc */ 328 #define AV_SPARC_MUL32 0x0001 329 #define AV_SPARC_DIV32 0x0002 330 #define AV_SPARC_FSMULD 0x0004 331 #define AV_SPARC_V8PLUS 0x0008 332 #define AV_SPARC_POPC 0x0010 333 #define AV_SPARC_VIS 0x0020 334 #define AV_SPARC_VIS2 0x0040 335 #define AV_SPARC_ASI_BLK_INIT 0x0080 336 #define AV_SPARC_FMAF 0x0100 337 #define AV_SPARC_FJFMAU 0x4000 338 #define AV_SPARC_IMA 0x8000 339 340 /* SunOS 5.x hardware capabilities: 386 */ 341 #define AV_386_FPU 0x00000001 342 #define AV_386_TSC 0x00000002 343 #define AV_386_CX8 0x00000004 344 #define AV_386_SEP 0x00000008 345 #define AV_386_AMD_SYSC 0x00000010 346 #define AV_386_CMOV 0x00000020 347 #define AV_386_MMX 0x00000040 348 #define AV_386_AMD_MMX 0x00000080 349 #define AV_386_AMD_3DNow 0x00000100 350 #define AV_386_AMD_3DNowx 0x00000200 351 #define AV_386_FXSR 0x00000400 352 #define AV_386_SSE 0x00000800 353 #define AV_386_SSE2 0x00001000 354 #define AV_386_PAUSE 0x00002000 355 #define AV_386_SSE3 0x00004000 356 #define AV_386_MON 0x00008000 357 #define AV_386_CX16 0x00010000 358 #define AV_386_AHF 0x00020000 359 #define AV_386_TSCP 0x00040000 360 #define AV_386_AMD_SSE4A 0x00080000 361 #define AV_386_POPCNT 0x00100000 362 #define AV_386_AMD_LZCNT 0x00200000 363 #define AV_386_SSSE3 0x00400000 364 #define AV_386_SSE4_1 0x00800000 365 #define AV_386_SSE4_2 0x01000000 366 367 #endif 368