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