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