1 /* $NetBSD: readelf.h,v 1.1.1.9 2017/09/08 13:22:41 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_Word a_type; /* 32-bit id */ 60 Elf32_Word a_v; /* 32-bit id */ 61 } Aux32Info; 62 63 typedef struct { 64 Elf64_Xword a_type; /* 64-bit id */ 65 Elf64_Xword a_v; /* 64-bit id */ 66 } Aux64Info; 67 68 #define AT_NULL 0 /* end of vector */ 69 #define AT_IGNORE 1 /* entry should be ignored */ 70 #define AT_EXECFD 2 /* file descriptor of program */ 71 #define AT_PHDR 3 /* program headers for program */ 72 #define AT_PHENT 4 /* size of program header entry */ 73 #define AT_PHNUM 5 /* number of program headers */ 74 #define AT_PAGESZ 6 /* system page size */ 75 #define AT_BASE 7 /* base address of interpreter */ 76 #define AT_FLAGS 8 /* flags */ 77 #define AT_ENTRY 9 /* entry point of program */ 78 #define AT_LINUX_NOTELF 10 /* program is not ELF */ 79 #define AT_LINUX_UID 11 /* real uid */ 80 #define AT_LINUX_EUID 12 /* effective uid */ 81 #define AT_LINUX_GID 13 /* real gid */ 82 #define AT_LINUX_EGID 14 /* effective gid */ 83 #define AT_LINUX_PLATFORM 15 /* string identifying CPU for optimizations */ 84 #define AT_LINUX_HWCAP 16 /* arch dependent hints at CPU capabilities */ 85 #define AT_LINUX_CLKTCK 17 /* frequency at which times() increments */ 86 /* AT_* values 18 through 22 are reserved */ 87 #define AT_LINUX_SECURE 23 /* secure mode boolean */ 88 #define AT_LINUX_BASE_PLATFORM 24 /* string identifying real platform, may 89 * differ from AT_PLATFORM. */ 90 #define AT_LINUX_RANDOM 25 /* address of 16 random bytes */ 91 #define AT_LINUX_HWCAP2 26 /* extension of AT_HWCAP */ 92 #define AT_LINUX_EXECFN 31 /* filename of program */ 93 94 typedef struct { 95 Elf32_Char e_ident[EI_NIDENT]; 96 Elf32_Half e_type; 97 Elf32_Half e_machine; 98 Elf32_Word e_version; 99 Elf32_Addr e_entry; /* Entry point */ 100 Elf32_Off e_phoff; 101 Elf32_Off e_shoff; 102 Elf32_Word e_flags; 103 Elf32_Half e_ehsize; 104 Elf32_Half e_phentsize; 105 Elf32_Half e_phnum; 106 Elf32_Half e_shentsize; 107 Elf32_Half e_shnum; 108 Elf32_Half e_shstrndx; 109 } Elf32_Ehdr; 110 111 typedef struct { 112 Elf64_Char e_ident[EI_NIDENT]; 113 Elf64_Half e_type; 114 Elf64_Half e_machine; 115 Elf64_Word e_version; 116 Elf64_Addr e_entry; /* Entry point */ 117 Elf64_Off e_phoff; 118 Elf64_Off e_shoff; 119 Elf64_Word e_flags; 120 Elf64_Half e_ehsize; 121 Elf64_Half e_phentsize; 122 Elf64_Half e_phnum; 123 Elf64_Half e_shentsize; 124 Elf64_Half e_shnum; 125 Elf64_Half e_shstrndx; 126 } Elf64_Ehdr; 127 128 /* e_type */ 129 #define ET_REL 1 130 #define ET_EXEC 2 131 #define ET_DYN 3 132 #define ET_CORE 4 133 134 /* e_machine (used only for SunOS 5.x hardware capabilities) */ 135 #define EM_SPARC 2 136 #define EM_386 3 137 #define EM_SPARC32PLUS 18 138 #define EM_SPARCV9 43 139 #define EM_IA_64 50 140 #define EM_AMD64 62 141 142 /* sh_type */ 143 #define SHT_SYMTAB 2 144 #define SHT_NOTE 7 145 #define SHT_DYNSYM 11 146 #define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilities */ 147 148 /* elf type */ 149 #define ELFDATANONE 0 /* e_ident[EI_DATA] */ 150 #define ELFDATA2LSB 1 151 #define ELFDATA2MSB 2 152 153 /* elf class */ 154 #define ELFCLASSNONE 0 155 #define ELFCLASS32 1 156 #define ELFCLASS64 2 157 158 /* magic number */ 159 #define EI_MAG0 0 /* e_ident[] indexes */ 160 #define EI_MAG1 1 161 #define EI_MAG2 2 162 #define EI_MAG3 3 163 #define EI_CLASS 4 164 #define EI_DATA 5 165 #define EI_VERSION 6 166 #define EI_PAD 7 167 168 #define ELFMAG0 0x7f /* EI_MAG */ 169 #define ELFMAG1 'E' 170 #define ELFMAG2 'L' 171 #define ELFMAG3 'F' 172 #define ELFMAG "\177ELF" 173 174 #define OLFMAG1 'O' 175 #define OLFMAG "\177OLF" 176 177 typedef struct { 178 Elf32_Word p_type; 179 Elf32_Off p_offset; 180 Elf32_Addr p_vaddr; 181 Elf32_Addr p_paddr; 182 Elf32_Word p_filesz; 183 Elf32_Word p_memsz; 184 Elf32_Word p_flags; 185 Elf32_Word p_align; 186 } Elf32_Phdr; 187 188 typedef struct { 189 Elf64_Word p_type; 190 Elf64_Word p_flags; 191 Elf64_Off p_offset; 192 Elf64_Addr p_vaddr; 193 Elf64_Addr p_paddr; 194 Elf64_Xword p_filesz; 195 Elf64_Xword p_memsz; 196 Elf64_Xword p_align; 197 } Elf64_Phdr; 198 199 #define PT_NULL 0 /* p_type */ 200 #define PT_LOAD 1 201 #define PT_DYNAMIC 2 202 #define PT_INTERP 3 203 #define PT_NOTE 4 204 #define PT_SHLIB 5 205 #define PT_PHDR 6 206 #define PT_NUM 7 207 208 typedef struct { 209 Elf32_Word sh_name; 210 Elf32_Word sh_type; 211 Elf32_Word sh_flags; 212 Elf32_Addr sh_addr; 213 Elf32_Off sh_offset; 214 Elf32_Word sh_size; 215 Elf32_Word sh_link; 216 Elf32_Word sh_info; 217 Elf32_Word sh_addralign; 218 Elf32_Word sh_entsize; 219 } Elf32_Shdr; 220 221 typedef struct { 222 Elf64_Word sh_name; 223 Elf64_Word sh_type; 224 Elf64_Off sh_flags; 225 Elf64_Addr sh_addr; 226 Elf64_Off sh_offset; 227 Elf64_Off sh_size; 228 Elf64_Word sh_link; 229 Elf64_Word sh_info; 230 Elf64_Off sh_addralign; 231 Elf64_Off sh_entsize; 232 } Elf64_Shdr; 233 234 #define NT_NETBSD_CORE_PROCINFO 1 235 #define NT_NETBSD_CORE_AUXV 2 236 237 struct NetBSD_elfcore_procinfo { 238 /* Version 1 fields start here. */ 239 uint32_t cpi_version; /* our version */ 240 uint32_t cpi_cpisize; /* sizeof(this struct) */ 241 uint32_t cpi_signo; /* killing signal */ 242 uint32_t cpi_sigcode; /* signal code */ 243 uint32_t cpi_sigpend[4]; /* pending signals */ 244 uint32_t cpi_sigmask[4]; /* blocked signals */ 245 uint32_t cpi_sigignore[4]; /* ignored signals */ 246 uint32_t cpi_sigcatch[4]; /* caught signals */ 247 int32_t cpi_pid; /* process ID */ 248 int32_t cpi_ppid; /* parent process ID */ 249 int32_t cpi_pgrp; /* process group ID */ 250 int32_t cpi_sid; /* session ID */ 251 uint32_t cpi_ruid; /* real user ID */ 252 uint32_t cpi_euid; /* effective user ID */ 253 uint32_t cpi_svuid; /* saved user ID */ 254 uint32_t cpi_rgid; /* real group ID */ 255 uint32_t cpi_egid; /* effective group ID */ 256 uint32_t cpi_svgid; /* saved group ID */ 257 uint32_t cpi_nlwps; /* number of LWPs */ 258 int8_t cpi_name[32]; /* copy of p->p_comm */ 259 /* Add version 2 fields below here. */ 260 int32_t cpi_siglwp; /* LWP target of killing signal */ 261 }; 262 263 /* Note header in a PT_NOTE section */ 264 typedef struct elf_note { 265 Elf32_Word n_namesz; /* Name size */ 266 Elf32_Word n_descsz; /* Content size */ 267 Elf32_Word n_type; /* Content type */ 268 } Elf32_Nhdr; 269 270 typedef struct { 271 Elf64_Word n_namesz; 272 Elf64_Word n_descsz; 273 Elf64_Word n_type; 274 } Elf64_Nhdr; 275 276 /* Notes used in ET_CORE */ 277 #define NT_PRSTATUS 1 278 #define NT_PRFPREG 2 279 #define NT_PRPSINFO 3 280 #define NT_PRXREG 4 281 #define NT_TASKSTRUCT 4 282 #define NT_PLATFORM 5 283 #define NT_AUXV 6 284 285 /* Note types used in executables */ 286 /* NetBSD executables (name = "NetBSD") */ 287 #define NT_NETBSD_VERSION 1 288 #define NT_NETBSD_EMULATION 2 289 #define NT_FREEBSD_VERSION 1 290 #define NT_OPENBSD_VERSION 1 291 #define NT_DRAGONFLY_VERSION 1 292 /* 293 * GNU executables (name = "GNU") 294 * word[0]: GNU OS tags 295 * word[1]: major version 296 * word[2]: minor version 297 * word[3]: tiny version 298 */ 299 #define NT_GNU_VERSION 1 300 301 /* GNU OS tags */ 302 #define GNU_OS_LINUX 0 303 #define GNU_OS_HURD 1 304 #define GNU_OS_SOLARIS 2 305 #define GNU_OS_KFREEBSD 3 306 #define GNU_OS_KNETBSD 4 307 308 /* 309 * GNU Hardware capability information 310 * word[0]: Number of entries 311 * word[1]: Bitmask of enabled entries 312 * Followed by a byte id, and a NUL terminated string per entry 313 */ 314 #define NT_GNU_HWCAP 2 315 316 /* 317 * GNU Build ID generated by ld 318 * 160 bit SHA1 [default] 319 * 128 bit md5 or uuid 320 */ 321 #define NT_GNU_BUILD_ID 3 322 323 /* 324 * NetBSD-specific note type: PaX. 325 * There should be 1 NOTE per executable. 326 * name: PaX\0 327 * namesz: 4 328 * desc: 329 * word[0]: capability bitmask 330 * descsz: 4 331 */ 332 #define NT_NETBSD_PAX 3 333 #define NT_NETBSD_PAX_MPROTECT 0x01 /* Force enable Mprotect */ 334 #define NT_NETBSD_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */ 335 #define NT_NETBSD_PAX_GUARD 0x04 /* Force enable Segvguard */ 336 #define NT_NETBSD_PAX_NOGUARD 0x08 /* Force disable Servguard */ 337 #define NT_NETBSD_PAX_ASLR 0x10 /* Force enable ASLR */ 338 #define NT_NETBSD_PAX_NOASLR 0x20 /* Force disable ASLR */ 339 340 /* 341 * NetBSD-specific note type: MACHINE_ARCH. 342 * There should be 1 NOTE per executable. 343 * name: NetBSD\0 344 * namesz: 7 345 * desc: string 346 * descsz: variable 347 */ 348 #define NT_NETBSD_MARCH 5 349 350 /* 351 * NetBSD-specific note type: COMPILER MODEL. 352 * There should be 1 NOTE per executable. 353 * name: NetBSD\0 354 * namesz: 7 355 * desc: string 356 * descsz: variable 357 */ 358 #define NT_NETBSD_CMODEL 6 359 360 /* 361 * FreeBSD specific notes 362 */ 363 #define NT_FREEBSD_PROCSTAT_AUXV 16 364 365 #if !defined(ELFSIZE) && defined(ARCH_ELFSIZE) 366 #define ELFSIZE ARCH_ELFSIZE 367 #endif 368 /* SunOS 5.x hardware/software capabilities */ 369 typedef struct { 370 Elf32_Word c_tag; 371 union { 372 Elf32_Word c_val; 373 Elf32_Addr c_ptr; 374 } c_un; 375 } Elf32_Cap; 376 377 typedef struct { 378 Elf64_Xword c_tag; 379 union { 380 Elf64_Xword c_val; 381 Elf64_Addr c_ptr; 382 } c_un; 383 } Elf64_Cap; 384 385 /* SunOS 5.x hardware/software capability tags */ 386 #define CA_SUNW_NULL 0 387 #define CA_SUNW_HW_1 1 388 #define CA_SUNW_SF_1 2 389 390 /* SunOS 5.x software capabilities */ 391 #define SF1_SUNW_FPKNWN 0x01 392 #define SF1_SUNW_FPUSED 0x02 393 #define SF1_SUNW_MASK 0x03 394 395 /* SunOS 5.x hardware capabilities: sparc */ 396 #define AV_SPARC_MUL32 0x0001 397 #define AV_SPARC_DIV32 0x0002 398 #define AV_SPARC_FSMULD 0x0004 399 #define AV_SPARC_V8PLUS 0x0008 400 #define AV_SPARC_POPC 0x0010 401 #define AV_SPARC_VIS 0x0020 402 #define AV_SPARC_VIS2 0x0040 403 #define AV_SPARC_ASI_BLK_INIT 0x0080 404 #define AV_SPARC_FMAF 0x0100 405 #define AV_SPARC_FJFMAU 0x4000 406 #define AV_SPARC_IMA 0x8000 407 408 /* SunOS 5.x hardware capabilities: 386 */ 409 #define AV_386_FPU 0x00000001 410 #define AV_386_TSC 0x00000002 411 #define AV_386_CX8 0x00000004 412 #define AV_386_SEP 0x00000008 413 #define AV_386_AMD_SYSC 0x00000010 414 #define AV_386_CMOV 0x00000020 415 #define AV_386_MMX 0x00000040 416 #define AV_386_AMD_MMX 0x00000080 417 #define AV_386_AMD_3DNow 0x00000100 418 #define AV_386_AMD_3DNowx 0x00000200 419 #define AV_386_FXSR 0x00000400 420 #define AV_386_SSE 0x00000800 421 #define AV_386_SSE2 0x00001000 422 #define AV_386_PAUSE 0x00002000 423 #define AV_386_SSE3 0x00004000 424 #define AV_386_MON 0x00008000 425 #define AV_386_CX16 0x00010000 426 #define AV_386_AHF 0x00020000 427 #define AV_386_TSCP 0x00040000 428 #define AV_386_AMD_SSE4A 0x00080000 429 #define AV_386_POPCNT 0x00100000 430 #define AV_386_AMD_LZCNT 0x00200000 431 #define AV_386_SSSE3 0x00400000 432 #define AV_386_SSE4_1 0x00800000 433 #define AV_386_SSE4_2 0x01000000 434 435 #endif 436