1284194Sdelphij/* 2284194Sdelphij * Copyright (c) Christos Zoulas 2003. 3284194Sdelphij * All Rights Reserved. 4284194Sdelphij * 5284194Sdelphij * Redistribution and use in source and binary forms, with or without 6284194Sdelphij * modification, are permitted provided that the following conditions 7284194Sdelphij * are met: 8284194Sdelphij * 1. Redistributions of source code must retain the above copyright 9284194Sdelphij * notice immediately at the beginning of the file, without modification, 10284194Sdelphij * this list of conditions, and the following disclaimer. 11284194Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 12284194Sdelphij * notice, this list of conditions and the following disclaimer in the 13284194Sdelphij * documentation and/or other materials provided with the distribution. 14284194Sdelphij * 15284194Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16284194Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17284194Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18284194Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 19284194Sdelphij * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20284194Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21284194Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22284194Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23284194Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24284194Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25284194Sdelphij * SUCH DAMAGE. 26284194Sdelphij */ 27284194Sdelphij/* 28284194Sdelphij * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp 29284194Sdelphij * 30284194Sdelphij * Provide elf data structures for non-elf machines, allowing file 31284194Sdelphij * non-elf hosts to determine if an elf binary is stripped. 32284194Sdelphij * Note: cobbled from the linux header file, with modifications 33284194Sdelphij */ 34284194Sdelphij#ifndef __fake_elf_h__ 35284194Sdelphij#define __fake_elf_h__ 36284194Sdelphij 37284194Sdelphij#if HAVE_STDINT_H 38284194Sdelphij#include <stdint.h> 39284194Sdelphij#endif 40284194Sdelphij 41284194Sdelphijtypedef uint32_t Elf32_Addr; 42284194Sdelphijtypedef uint32_t Elf32_Off; 43284194Sdelphijtypedef uint16_t Elf32_Half; 44284194Sdelphijtypedef uint32_t Elf32_Word; 45284194Sdelphijtypedef uint8_t Elf32_Char; 46284194Sdelphij 47284194Sdelphijtypedef uint64_t Elf64_Addr; 48284194Sdelphijtypedef uint64_t Elf64_Off; 49284194Sdelphijtypedef uint64_t Elf64_Xword; 50284194Sdelphijtypedef uint16_t Elf64_Half; 51284194Sdelphijtypedef uint32_t Elf64_Word; 52284194Sdelphijtypedef uint8_t Elf64_Char; 53284194Sdelphij 54284194Sdelphij#define EI_NIDENT 16 55284194Sdelphij 56284194Sdelphijtypedef struct { 57284194Sdelphij Elf32_Char e_ident[EI_NIDENT]; 58284194Sdelphij Elf32_Half e_type; 59284194Sdelphij Elf32_Half e_machine; 60284194Sdelphij Elf32_Word e_version; 61284194Sdelphij Elf32_Addr e_entry; /* Entry point */ 62284194Sdelphij Elf32_Off e_phoff; 63284194Sdelphij Elf32_Off e_shoff; 64284194Sdelphij Elf32_Word e_flags; 65284194Sdelphij Elf32_Half e_ehsize; 66284194Sdelphij Elf32_Half e_phentsize; 67284194Sdelphij Elf32_Half e_phnum; 68284194Sdelphij Elf32_Half e_shentsize; 69284194Sdelphij Elf32_Half e_shnum; 70284194Sdelphij Elf32_Half e_shstrndx; 71284194Sdelphij} Elf32_Ehdr; 72284194Sdelphij 73284194Sdelphijtypedef struct { 74284194Sdelphij Elf64_Char e_ident[EI_NIDENT]; 75284194Sdelphij Elf64_Half e_type; 76284194Sdelphij Elf64_Half e_machine; 77284194Sdelphij Elf64_Word e_version; 78284194Sdelphij Elf64_Addr e_entry; /* Entry point */ 79284194Sdelphij Elf64_Off e_phoff; 80284194Sdelphij Elf64_Off e_shoff; 81284194Sdelphij Elf64_Word e_flags; 82284194Sdelphij Elf64_Half e_ehsize; 83284194Sdelphij Elf64_Half e_phentsize; 84284194Sdelphij Elf64_Half e_phnum; 85284194Sdelphij Elf64_Half e_shentsize; 86284194Sdelphij Elf64_Half e_shnum; 87284194Sdelphij Elf64_Half e_shstrndx; 88284194Sdelphij} Elf64_Ehdr; 89284194Sdelphij 90284194Sdelphij/* e_type */ 91284194Sdelphij#define ET_REL 1 92284194Sdelphij#define ET_EXEC 2 93284194Sdelphij#define ET_DYN 3 94284194Sdelphij#define ET_CORE 4 95284194Sdelphij 96284194Sdelphij/* e_machine (used only for SunOS 5.x hardware capabilities) */ 97284194Sdelphij#define EM_SPARC 2 98284194Sdelphij#define EM_386 3 99284194Sdelphij#define EM_SPARC32PLUS 18 100284194Sdelphij#define EM_SPARCV9 43 101284194Sdelphij#define EM_IA_64 50 102284194Sdelphij#define EM_AMD64 62 103284194Sdelphij 104284194Sdelphij/* sh_type */ 105284194Sdelphij#define SHT_SYMTAB 2 106284194Sdelphij#define SHT_NOTE 7 107284194Sdelphij#define SHT_DYNSYM 11 108284194Sdelphij#define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */ 109284194Sdelphij 110284194Sdelphij/* elf type */ 111284194Sdelphij#define ELFDATANONE 0 /* e_ident[EI_DATA] */ 112284194Sdelphij#define ELFDATA2LSB 1 113284194Sdelphij#define ELFDATA2MSB 2 114284194Sdelphij 115284194Sdelphij/* elf class */ 116284194Sdelphij#define ELFCLASSNONE 0 117284194Sdelphij#define ELFCLASS32 1 118284194Sdelphij#define ELFCLASS64 2 119284194Sdelphij 120284194Sdelphij/* magic number */ 121284194Sdelphij#define EI_MAG0 0 /* e_ident[] indexes */ 122284194Sdelphij#define EI_MAG1 1 123284194Sdelphij#define EI_MAG2 2 124284194Sdelphij#define EI_MAG3 3 125284194Sdelphij#define EI_CLASS 4 126284194Sdelphij#define EI_DATA 5 127284194Sdelphij#define EI_VERSION 6 128284194Sdelphij#define EI_PAD 7 129284194Sdelphij 130284194Sdelphij#define ELFMAG0 0x7f /* EI_MAG */ 131284194Sdelphij#define ELFMAG1 'E' 132284194Sdelphij#define ELFMAG2 'L' 133284194Sdelphij#define ELFMAG3 'F' 134284194Sdelphij#define ELFMAG "\177ELF" 135284194Sdelphij 136284194Sdelphij#define OLFMAG1 'O' 137284194Sdelphij#define OLFMAG "\177OLF" 138284194Sdelphij 139284194Sdelphijtypedef struct { 140284194Sdelphij Elf32_Word p_type; 141284194Sdelphij Elf32_Off p_offset; 142284194Sdelphij Elf32_Addr p_vaddr; 143284194Sdelphij Elf32_Addr p_paddr; 144284194Sdelphij Elf32_Word p_filesz; 145284194Sdelphij Elf32_Word p_memsz; 146284194Sdelphij Elf32_Word p_flags; 147284194Sdelphij Elf32_Word p_align; 148284194Sdelphij} Elf32_Phdr; 149284194Sdelphij 150284194Sdelphijtypedef struct { 151284194Sdelphij Elf64_Word p_type; 152284194Sdelphij Elf64_Word p_flags; 153284194Sdelphij Elf64_Off p_offset; 154284194Sdelphij Elf64_Addr p_vaddr; 155284194Sdelphij Elf64_Addr p_paddr; 156284194Sdelphij Elf64_Xword p_filesz; 157284194Sdelphij Elf64_Xword p_memsz; 158284194Sdelphij Elf64_Xword p_align; 159284194Sdelphij} Elf64_Phdr; 160284194Sdelphij 161284194Sdelphij#define PT_NULL 0 /* p_type */ 162284194Sdelphij#define PT_LOAD 1 163284194Sdelphij#define PT_DYNAMIC 2 164284194Sdelphij#define PT_INTERP 3 165284194Sdelphij#define PT_NOTE 4 166284194Sdelphij#define PT_SHLIB 5 167284194Sdelphij#define PT_PHDR 6 168284194Sdelphij#define PT_NUM 7 169284194Sdelphij 170284194Sdelphijtypedef struct { 171284194Sdelphij Elf32_Word sh_name; 172284194Sdelphij Elf32_Word sh_type; 173284194Sdelphij Elf32_Word sh_flags; 174284194Sdelphij Elf32_Addr sh_addr; 175284194Sdelphij Elf32_Off sh_offset; 176284194Sdelphij Elf32_Word sh_size; 177284194Sdelphij Elf32_Word sh_link; 178284194Sdelphij Elf32_Word sh_info; 179284194Sdelphij Elf32_Word sh_addralign; 180284194Sdelphij Elf32_Word sh_entsize; 181284194Sdelphij} Elf32_Shdr; 182284194Sdelphij 183284194Sdelphijtypedef struct { 184284194Sdelphij Elf64_Word sh_name; 185284194Sdelphij Elf64_Word sh_type; 186284194Sdelphij Elf64_Off sh_flags; 187284194Sdelphij Elf64_Addr sh_addr; 188284194Sdelphij Elf64_Off sh_offset; 189284194Sdelphij Elf64_Off sh_size; 190284194Sdelphij Elf64_Word sh_link; 191284194Sdelphij Elf64_Word sh_info; 192284194Sdelphij Elf64_Off sh_addralign; 193284194Sdelphij Elf64_Off sh_entsize; 194284194Sdelphij} Elf64_Shdr; 195284194Sdelphij 196284194Sdelphij#define NT_NETBSD_CORE_PROCINFO 1 197284194Sdelphij 198284194Sdelphij/* Note header in a PT_NOTE section */ 199284194Sdelphijtypedef struct elf_note { 200284194Sdelphij Elf32_Word n_namesz; /* Name size */ 201284194Sdelphij Elf32_Word n_descsz; /* Content size */ 202284194Sdelphij Elf32_Word n_type; /* Content type */ 203284194Sdelphij} Elf32_Nhdr; 204284194Sdelphij 205284194Sdelphijtypedef struct { 206284194Sdelphij Elf64_Word n_namesz; 207284194Sdelphij Elf64_Word n_descsz; 208284194Sdelphij Elf64_Word n_type; 209284194Sdelphij} Elf64_Nhdr; 210284194Sdelphij 211284194Sdelphij/* Notes used in ET_CORE */ 212284194Sdelphij#define NT_PRSTATUS 1 213284194Sdelphij#define NT_PRFPREG 2 214284194Sdelphij#define NT_PRPSINFO 3 215284194Sdelphij#define NT_PRXREG 4 216284194Sdelphij#define NT_TASKSTRUCT 4 217284194Sdelphij#define NT_PLATFORM 5 218284194Sdelphij#define NT_AUXV 6 219284194Sdelphij 220284194Sdelphij/* Note types used in executables */ 221284194Sdelphij/* NetBSD executables (name = "NetBSD") */ 222284194Sdelphij#define NT_NETBSD_VERSION 1 223284194Sdelphij#define NT_NETBSD_EMULATION 2 224284194Sdelphij#define NT_FREEBSD_VERSION 1 225284194Sdelphij#define NT_OPENBSD_VERSION 1 226284194Sdelphij#define NT_DRAGONFLY_VERSION 1 227284194Sdelphij/* 228284194Sdelphij * GNU executables (name = "GNU") 229284194Sdelphij * word[0]: GNU OS tags 230284194Sdelphij * word[1]: major version 231284194Sdelphij * word[2]: minor version 232284194Sdelphij * word[3]: tiny version 233284194Sdelphij */ 234284194Sdelphij#define NT_GNU_VERSION 1 235284194Sdelphij 236284194Sdelphij/* GNU OS tags */ 237284194Sdelphij#define GNU_OS_LINUX 0 238284194Sdelphij#define GNU_OS_HURD 1 239284194Sdelphij#define GNU_OS_SOLARIS 2 240284194Sdelphij#define GNU_OS_KFREEBSD 3 241284194Sdelphij#define GNU_OS_KNETBSD 4 242284194Sdelphij 243284194Sdelphij/* 244284194Sdelphij * GNU Hardware capability information 245284194Sdelphij * word[0]: Number of entries 246284194Sdelphij * word[1]: Bitmask of enabled entries 247284194Sdelphij * Followed by a byte id, and a NUL terminated string per entry 248284194Sdelphij */ 249284194Sdelphij#define NT_GNU_HWCAP 2 250284194Sdelphij 251284194Sdelphij/* 252284194Sdelphij * GNU Build ID generated by ld 253284194Sdelphij * 160 bit SHA1 [default] 254284194Sdelphij * 128 bit md5 or uuid 255284194Sdelphij */ 256284194Sdelphij#define NT_GNU_BUILD_ID 3 257284194Sdelphij 258284194Sdelphij/* 259284194Sdelphij * NetBSD-specific note type: PaX. 260284194Sdelphij * There should be 1 NOTE per executable. 261284194Sdelphij * name: PaX\0 262284194Sdelphij * namesz: 4 263284194Sdelphij * desc: 264284194Sdelphij * word[0]: capability bitmask 265284194Sdelphij * descsz: 4 266284194Sdelphij */ 267284194Sdelphij#define NT_NETBSD_PAX 3 268284194Sdelphij#define NT_NETBSD_PAX_MPROTECT 0x01 /* Force enable Mprotect */ 269284194Sdelphij#define NT_NETBSD_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */ 270284194Sdelphij#define NT_NETBSD_PAX_GUARD 0x04 /* Force enable Segvguard */ 271284194Sdelphij#define NT_NETBSD_PAX_NOGUARD 0x08 /* Force disable Servguard */ 272284194Sdelphij#define NT_NETBSD_PAX_ASLR 0x10 /* Force enable ASLR */ 273284194Sdelphij#define NT_NETBSD_PAX_NOASLR 0x20 /* Force disable ASLR */ 274284194Sdelphij 275284194Sdelphij/* 276284194Sdelphij * NetBSD-specific note type: MACHINE_ARCH. 277284194Sdelphij * There should be 1 NOTE per executable. 278284194Sdelphij * name: NetBSD\0 279284194Sdelphij * namesz: 7 280284194Sdelphij * desc: string 281284194Sdelphij * descsz: variable 282284194Sdelphij */ 283284194Sdelphij#define NT_NETBSD_MARCH 5 284284194Sdelphij 285284194Sdelphij/* 286284194Sdelphij * NetBSD-specific note type: COMPILER MODEL. 287284194Sdelphij * There should be 1 NOTE per executable. 288284194Sdelphij * name: NetBSD\0 289284194Sdelphij * namesz: 7 290284194Sdelphij * desc: string 291284194Sdelphij * descsz: variable 292284194Sdelphij */ 293284194Sdelphij#define NT_NETBSD_CMODEL 6 294284194Sdelphij 295284194Sdelphij#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE) 296284194Sdelphij#define ELFSIZE ARCH_ELFSIZE 297284194Sdelphij#endif 298284194Sdelphij/* SunOS 5.x hardware/software capabilities */ 299284194Sdelphijtypedef struct { 300284194Sdelphij Elf32_Word c_tag; 301284194Sdelphij union { 302284194Sdelphij Elf32_Word c_val; 303284194Sdelphij Elf32_Addr c_ptr; 304284194Sdelphij } c_un; 305284194Sdelphij} Elf32_Cap; 306284194Sdelphij 307284194Sdelphijtypedef struct { 308284194Sdelphij Elf64_Xword c_tag; 309284194Sdelphij union { 310284194Sdelphij Elf64_Xword c_val; 311284194Sdelphij Elf64_Addr c_ptr; 312284194Sdelphij } c_un; 313284194Sdelphij} Elf64_Cap; 314284194Sdelphij 315284194Sdelphij/* SunOS 5.x hardware/software capability tags */ 316284194Sdelphij#define CA_SUNW_NULL 0 317284194Sdelphij#define CA_SUNW_HW_1 1 318284194Sdelphij#define CA_SUNW_SF_1 2 319284194Sdelphij 320284194Sdelphij/* SunOS 5.x software capabilities */ 321284194Sdelphij#define SF1_SUNW_FPKNWN 0x01 322284194Sdelphij#define SF1_SUNW_FPUSED 0x02 323284194Sdelphij#define SF1_SUNW_MASK 0x03 324284194Sdelphij 325284194Sdelphij/* SunOS 5.x hardware capabilities: sparc */ 326284194Sdelphij#define AV_SPARC_MUL32 0x0001 327284194Sdelphij#define AV_SPARC_DIV32 0x0002 328284194Sdelphij#define AV_SPARC_FSMULD 0x0004 329284194Sdelphij#define AV_SPARC_V8PLUS 0x0008 330284194Sdelphij#define AV_SPARC_POPC 0x0010 331284194Sdelphij#define AV_SPARC_VIS 0x0020 332284194Sdelphij#define AV_SPARC_VIS2 0x0040 333284194Sdelphij#define AV_SPARC_ASI_BLK_INIT 0x0080 334284194Sdelphij#define AV_SPARC_FMAF 0x0100 335284194Sdelphij#define AV_SPARC_FJFMAU 0x4000 336284194Sdelphij#define AV_SPARC_IMA 0x8000 337284194Sdelphij 338284194Sdelphij/* SunOS 5.x hardware capabilities: 386 */ 339284194Sdelphij#define AV_386_FPU 0x00000001 340284194Sdelphij#define AV_386_TSC 0x00000002 341284194Sdelphij#define AV_386_CX8 0x00000004 342284194Sdelphij#define AV_386_SEP 0x00000008 343284194Sdelphij#define AV_386_AMD_SYSC 0x00000010 344284194Sdelphij#define AV_386_CMOV 0x00000020 345284194Sdelphij#define AV_386_MMX 0x00000040 346284194Sdelphij#define AV_386_AMD_MMX 0x00000080 347284194Sdelphij#define AV_386_AMD_3DNow 0x00000100 348284194Sdelphij#define AV_386_AMD_3DNowx 0x00000200 349284194Sdelphij#define AV_386_FXSR 0x00000400 350284194Sdelphij#define AV_386_SSE 0x00000800 351284194Sdelphij#define AV_386_SSE2 0x00001000 352284194Sdelphij#define AV_386_PAUSE 0x00002000 353284194Sdelphij#define AV_386_SSE3 0x00004000 354284194Sdelphij#define AV_386_MON 0x00008000 355284194Sdelphij#define AV_386_CX16 0x00010000 356284194Sdelphij#define AV_386_AHF 0x00020000 357284194Sdelphij#define AV_386_TSCP 0x00040000 358284194Sdelphij#define AV_386_AMD_SSE4A 0x00080000 359284194Sdelphij#define AV_386_POPCNT 0x00100000 360284194Sdelphij#define AV_386_AMD_LZCNT 0x00200000 361284194Sdelphij#define AV_386_SSSE3 0x00400000 362284194Sdelphij#define AV_386_SSE4_1 0x00800000 363284194Sdelphij#define AV_386_SSE4_2 0x01000000 364284194Sdelphij 365284194Sdelphij#endif 366