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