168349Sobrien/* 2133359Sobrien * Copyright (c) Christos Zoulas 2003. 3133359Sobrien * All Rights Reserved. 4133359Sobrien * 5133359Sobrien * Redistribution and use in source and binary forms, with or without 6133359Sobrien * modification, are permitted provided that the following conditions 7133359Sobrien * are met: 8133359Sobrien * 1. Redistributions of source code must retain the above copyright 9133359Sobrien * notice immediately at the beginning of the file, without modification, 10133359Sobrien * this list of conditions, and the following disclaimer. 11133359Sobrien * 2. Redistributions in binary form must reproduce the above copyright 12133359Sobrien * notice, this list of conditions and the following disclaimer in the 13133359Sobrien * documentation and/or other materials provided with the distribution. 14133359Sobrien * 15133359Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16133359Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17133359Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18133359Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 19133359Sobrien * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20133359Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21133359Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22133359Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23133359Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24133359Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25133359Sobrien * SUCH DAMAGE. 26133359Sobrien */ 27133359Sobrien/* 28133359Sobrien * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp 2968349Sobrien * 3068349Sobrien * Provide elf data structures for non-elf machines, allowing file 3168349Sobrien * non-elf hosts to determine if an elf binary is stripped. 3268349Sobrien * Note: cobbled from the linux header file, with modifications 3368349Sobrien */ 3468349Sobrien#ifndef __fake_elf_h__ 35226048Sobrien#define __fake_elf_h__ 3668349Sobrien 37103373Sobrien#if HAVE_STDINT_H 38103373Sobrien#include <stdint.h> 39103373Sobrien#endif 40103373Sobrien 4168349Sobrientypedef uint32_t Elf32_Addr; 4268349Sobrientypedef uint32_t Elf32_Off; 4368349Sobrientypedef uint16_t Elf32_Half; 4468349Sobrientypedef uint32_t Elf32_Word; 4568349Sobrientypedef uint8_t Elf32_Char; 4668349Sobrien 4768349Sobrientypedef uint64_t Elf64_Addr; 4868349Sobrientypedef uint64_t Elf64_Off; 4968349Sobrientypedef uint64_t Elf64_Xword; 5068349Sobrientypedef uint16_t Elf64_Half; 5168349Sobrientypedef uint32_t Elf64_Word; 5268349Sobrientypedef uint8_t Elf64_Char; 5368349Sobrien 54226048Sobrien#define EI_NIDENT 16 5568349Sobrien 5668349Sobrientypedef struct { 5768349Sobrien Elf32_Char e_ident[EI_NIDENT]; 5868349Sobrien Elf32_Half e_type; 5968349Sobrien Elf32_Half e_machine; 6068349Sobrien Elf32_Word e_version; 6168349Sobrien Elf32_Addr e_entry; /* Entry point */ 6268349Sobrien Elf32_Off e_phoff; 6368349Sobrien Elf32_Off e_shoff; 6468349Sobrien Elf32_Word e_flags; 6568349Sobrien Elf32_Half e_ehsize; 6668349Sobrien Elf32_Half e_phentsize; 6768349Sobrien Elf32_Half e_phnum; 6868349Sobrien Elf32_Half e_shentsize; 6968349Sobrien Elf32_Half e_shnum; 7068349Sobrien Elf32_Half e_shstrndx; 7168349Sobrien} Elf32_Ehdr; 7268349Sobrien 7368349Sobrientypedef struct { 7468349Sobrien Elf64_Char e_ident[EI_NIDENT]; 7568349Sobrien Elf64_Half e_type; 7668349Sobrien Elf64_Half e_machine; 7768349Sobrien Elf64_Word e_version; 7868349Sobrien Elf64_Addr e_entry; /* Entry point */ 7968349Sobrien Elf64_Off e_phoff; 8068349Sobrien Elf64_Off e_shoff; 8168349Sobrien Elf64_Word e_flags; 8268349Sobrien Elf64_Half e_ehsize; 8368349Sobrien Elf64_Half e_phentsize; 8468349Sobrien Elf64_Half e_phnum; 8568349Sobrien Elf64_Half e_shentsize; 8668349Sobrien Elf64_Half e_shnum; 8768349Sobrien Elf64_Half e_shstrndx; 8868349Sobrien} Elf64_Ehdr; 8968349Sobrien 9068349Sobrien/* e_type */ 91226048Sobrien#define ET_REL 1 92226048Sobrien#define ET_EXEC 2 93226048Sobrien#define ET_DYN 3 94226048Sobrien#define ET_CORE 4 9568349Sobrien 96186690Sobrien/* e_machine (used only for SunOS 5.x hardware capabilities) */ 97186690Sobrien#define EM_SPARC 2 98186690Sobrien#define EM_386 3 99186690Sobrien#define EM_SPARC32PLUS 18 100186690Sobrien#define EM_SPARCV9 43 101186690Sobrien#define EM_IA_64 50 102186690Sobrien#define EM_AMD64 62 103186690Sobrien 10468349Sobrien/* sh_type */ 105226048Sobrien#define SHT_SYMTAB 2 106226048Sobrien#define SHT_NOTE 7 107226048Sobrien#define SHT_DYNSYM 11 108226048Sobrien#define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */ 10968349Sobrien 11068349Sobrien/* elf type */ 111226048Sobrien#define ELFDATANONE 0 /* e_ident[EI_DATA] */ 112226048Sobrien#define ELFDATA2LSB 1 113226048Sobrien#define ELFDATA2MSB 2 11468349Sobrien 11568349Sobrien/* elf class */ 116226048Sobrien#define ELFCLASSNONE 0 117226048Sobrien#define ELFCLASS32 1 118226048Sobrien#define ELFCLASS64 2 11968349Sobrien 12068349Sobrien/* magic number */ 12168349Sobrien#define EI_MAG0 0 /* e_ident[] indexes */ 12268349Sobrien#define EI_MAG1 1 12368349Sobrien#define EI_MAG2 2 12468349Sobrien#define EI_MAG3 3 12568349Sobrien#define EI_CLASS 4 12668349Sobrien#define EI_DATA 5 12768349Sobrien#define EI_VERSION 6 12868349Sobrien#define EI_PAD 7 12968349Sobrien 13068349Sobrien#define ELFMAG0 0x7f /* EI_MAG */ 13168349Sobrien#define ELFMAG1 'E' 13268349Sobrien#define ELFMAG2 'L' 13368349Sobrien#define ELFMAG3 'F' 13468349Sobrien#define ELFMAG "\177ELF" 13568349Sobrien 13668349Sobrien#define OLFMAG1 'O' 13768349Sobrien#define OLFMAG "\177OLF" 13868349Sobrien 13968349Sobrientypedef struct { 14068349Sobrien Elf32_Word p_type; 14168349Sobrien Elf32_Off p_offset; 14268349Sobrien Elf32_Addr p_vaddr; 14368349Sobrien Elf32_Addr p_paddr; 14468349Sobrien Elf32_Word p_filesz; 14568349Sobrien Elf32_Word p_memsz; 14668349Sobrien Elf32_Word p_flags; 14768349Sobrien Elf32_Word p_align; 14868349Sobrien} Elf32_Phdr; 14968349Sobrien 15068349Sobrientypedef struct { 15168349Sobrien Elf64_Word p_type; 15268349Sobrien Elf64_Word p_flags; 15368349Sobrien Elf64_Off p_offset; 15468349Sobrien Elf64_Addr p_vaddr; 15568349Sobrien Elf64_Addr p_paddr; 15668349Sobrien Elf64_Xword p_filesz; 15768349Sobrien Elf64_Xword p_memsz; 15868349Sobrien Elf64_Xword p_align; 15968349Sobrien} Elf64_Phdr; 16068349Sobrien 16168349Sobrien#define PT_NULL 0 /* p_type */ 16268349Sobrien#define PT_LOAD 1 16368349Sobrien#define PT_DYNAMIC 2 16468349Sobrien#define PT_INTERP 3 16568349Sobrien#define PT_NOTE 4 16668349Sobrien#define PT_SHLIB 5 16768349Sobrien#define PT_PHDR 6 16868349Sobrien#define PT_NUM 7 16968349Sobrien 17068349Sobrientypedef struct { 17168349Sobrien Elf32_Word sh_name; 17268349Sobrien Elf32_Word sh_type; 17368349Sobrien Elf32_Word sh_flags; 17468349Sobrien Elf32_Addr sh_addr; 17568349Sobrien Elf32_Off sh_offset; 17668349Sobrien Elf32_Word sh_size; 17768349Sobrien Elf32_Word sh_link; 17868349Sobrien Elf32_Word sh_info; 17968349Sobrien Elf32_Word sh_addralign; 18068349Sobrien Elf32_Word sh_entsize; 18168349Sobrien} Elf32_Shdr; 18268349Sobrien 18368349Sobrientypedef struct { 18468349Sobrien Elf64_Word sh_name; 18568349Sobrien Elf64_Word sh_type; 18668349Sobrien Elf64_Off sh_flags; 18768349Sobrien Elf64_Addr sh_addr; 18868349Sobrien Elf64_Off sh_offset; 18968349Sobrien Elf64_Off sh_size; 19068349Sobrien Elf64_Word sh_link; 19168349Sobrien Elf64_Word sh_info; 19268349Sobrien Elf64_Off sh_addralign; 19368349Sobrien Elf64_Off sh_entsize; 19468349Sobrien} Elf64_Shdr; 19568349Sobrien 196103373Sobrien#define NT_NETBSD_CORE_PROCINFO 1 197103373Sobrien 19868349Sobrien/* Note header in a PT_NOTE section */ 19968349Sobrientypedef struct elf_note { 20068349Sobrien Elf32_Word n_namesz; /* Name size */ 20168349Sobrien Elf32_Word n_descsz; /* Content size */ 20268349Sobrien Elf32_Word n_type; /* Content type */ 20368349Sobrien} Elf32_Nhdr; 20468349Sobrien 20568349Sobrientypedef struct { 20668349Sobrien Elf64_Word n_namesz; 20768349Sobrien Elf64_Word n_descsz; 20868349Sobrien Elf64_Word n_type; 20968349Sobrien} Elf64_Nhdr; 21068349Sobrien 211175296Sobrien/* Notes used in ET_CORE */ 21268349Sobrien#define NT_PRSTATUS 1 21368349Sobrien#define NT_PRFPREG 2 21468349Sobrien#define NT_PRPSINFO 3 21568349Sobrien#define NT_PRXREG 4 216226048Sobrien#define NT_TASKSTRUCT 4 21768349Sobrien#define NT_PLATFORM 5 21868349Sobrien#define NT_AUXV 6 21968349Sobrien 220103373Sobrien/* Note types used in executables */ 221103373Sobrien/* NetBSD executables (name = "NetBSD") */ 222226048Sobrien#define NT_NETBSD_VERSION 1 223226048Sobrien#define NT_NETBSD_EMULATION 2 224226048Sobrien#define NT_FREEBSD_VERSION 1 225226048Sobrien#define NT_OPENBSD_VERSION 1 226226048Sobrien#define NT_DRAGONFLY_VERSION 1 227226048Sobrien/* 228226048Sobrien * GNU executables (name = "GNU") 229226048Sobrien * word[0]: GNU OS tags 230226048Sobrien * word[1]: major version 231226048Sobrien * word[2]: minor version 232226048Sobrien * word[3]: tiny version 233226048Sobrien */ 234226048Sobrien#define NT_GNU_VERSION 1 235103373Sobrien 236103373Sobrien/* GNU OS tags */ 237226048Sobrien#define GNU_OS_LINUX 0 238226048Sobrien#define GNU_OS_HURD 1 239226048Sobrien#define GNU_OS_SOLARIS 2 240226048Sobrien#define GNU_OS_KFREEBSD 3 241226048Sobrien#define GNU_OS_KNETBSD 4 242103373Sobrien 243226048Sobrien/* 244226048Sobrien * GNU Hardware capability information 245226048Sobrien * word[0]: Number of entries 246226048Sobrien * word[1]: Bitmask of enabled entries 247226048Sobrien * Followed by a byte id, and a NUL terminated string per entry 248226048Sobrien */ 249226048Sobrien#define NT_GNU_HWCAP 2 250226048Sobrien 251226048Sobrien/* 252226048Sobrien * GNU Build ID generated by ld 253226048Sobrien * 160 bit SHA1 [default] 254226048Sobrien * 128 bit md5 or uuid 255226048Sobrien */ 256226048Sobrien#define NT_GNU_BUILD_ID 3 257226048Sobrien 258267843Sdelphij/* 259267843Sdelphij * NetBSD-specific note type: PaX. 260267843Sdelphij * There should be 1 NOTE per executable. 261267843Sdelphij * name: PaX\0 262267843Sdelphij * namesz: 4 263267843Sdelphij * desc: 264267843Sdelphij * word[0]: capability bitmask 265267843Sdelphij * descsz: 4 266267843Sdelphij */ 267267843Sdelphij#define NT_NETBSD_PAX 3 268267843Sdelphij#define NT_NETBSD_PAX_MPROTECT 0x01 /* Force enable Mprotect */ 269267843Sdelphij#define NT_NETBSD_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */ 270267843Sdelphij#define NT_NETBSD_PAX_GUARD 0x04 /* Force enable Segvguard */ 271267843Sdelphij#define NT_NETBSD_PAX_NOGUARD 0x08 /* Force disable Servguard */ 272267843Sdelphij#define NT_NETBSD_PAX_ASLR 0x10 /* Force enable ASLR */ 273267843Sdelphij#define NT_NETBSD_PAX_NOASLR 0x20 /* Force disable ASLR */ 274267843Sdelphij 275267843Sdelphij/* 276267843Sdelphij * NetBSD-specific note type: MACHINE_ARCH. 277267843Sdelphij * There should be 1 NOTE per executable. 278267843Sdelphij * name: NetBSD\0 279267843Sdelphij * namesz: 7 280267843Sdelphij * desc: string 281267843Sdelphij * descsz: variable 282267843Sdelphij */ 283267843Sdelphij#define NT_NETBSD_MARCH 5 284267843Sdelphij 285267843Sdelphij/* 286267843Sdelphij * NetBSD-specific note type: COMPILER MODEL. 287267843Sdelphij * There should be 1 NOTE per executable. 288267843Sdelphij * name: NetBSD\0 289267843Sdelphij * namesz: 7 290267843Sdelphij * desc: string 291267843Sdelphij * descsz: variable 292267843Sdelphij */ 293267843Sdelphij#define NT_NETBSD_CMODEL 6 294267843Sdelphij 295267843Sdelphij#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE) 296267843Sdelphij#define ELFSIZE ARCH_ELFSIZE 297267843Sdelphij#endif 298186690Sobrien/* SunOS 5.x hardware/software capabilities */ 299186690Sobrientypedef struct { 300186690Sobrien Elf32_Word c_tag; 301186690Sobrien union { 302186690Sobrien Elf32_Word c_val; 303186690Sobrien Elf32_Addr c_ptr; 304186690Sobrien } c_un; 305186690Sobrien} Elf32_Cap; 306186690Sobrien 307186690Sobrientypedef struct { 308186690Sobrien Elf64_Xword c_tag; 309186690Sobrien union { 310186690Sobrien Elf64_Xword c_val; 311186690Sobrien Elf64_Addr c_ptr; 312186690Sobrien } c_un; 313186690Sobrien} Elf64_Cap; 314186690Sobrien 315186690Sobrien/* SunOS 5.x hardware/software capability tags */ 316186690Sobrien#define CA_SUNW_NULL 0 317186690Sobrien#define CA_SUNW_HW_1 1 318186690Sobrien#define CA_SUNW_SF_1 2 319186690Sobrien 320186690Sobrien/* SunOS 5.x software capabilities */ 321186690Sobrien#define SF1_SUNW_FPKNWN 0x01 322186690Sobrien#define SF1_SUNW_FPUSED 0x02 323186690Sobrien#define SF1_SUNW_MASK 0x03 324186690Sobrien 325186690Sobrien/* SunOS 5.x hardware capabilities: sparc */ 326186690Sobrien#define AV_SPARC_MUL32 0x0001 327186690Sobrien#define AV_SPARC_DIV32 0x0002 328186690Sobrien#define AV_SPARC_FSMULD 0x0004 329186690Sobrien#define AV_SPARC_V8PLUS 0x0008 330186690Sobrien#define AV_SPARC_POPC 0x0010 331186690Sobrien#define AV_SPARC_VIS 0x0020 332186690Sobrien#define AV_SPARC_VIS2 0x0040 333186690Sobrien#define AV_SPARC_ASI_BLK_INIT 0x0080 334186690Sobrien#define AV_SPARC_FMAF 0x0100 335186690Sobrien#define AV_SPARC_FJFMAU 0x4000 336186690Sobrien#define AV_SPARC_IMA 0x8000 337186690Sobrien 338186690Sobrien/* SunOS 5.x hardware capabilities: 386 */ 339186690Sobrien#define AV_386_FPU 0x00000001 340186690Sobrien#define AV_386_TSC 0x00000002 341186690Sobrien#define AV_386_CX8 0x00000004 342186690Sobrien#define AV_386_SEP 0x00000008 343186690Sobrien#define AV_386_AMD_SYSC 0x00000010 344186690Sobrien#define AV_386_CMOV 0x00000020 345186690Sobrien#define AV_386_MMX 0x00000040 346186690Sobrien#define AV_386_AMD_MMX 0x00000080 347186690Sobrien#define AV_386_AMD_3DNow 0x00000100 348186690Sobrien#define AV_386_AMD_3DNowx 0x00000200 349186690Sobrien#define AV_386_FXSR 0x00000400 350186690Sobrien#define AV_386_SSE 0x00000800 351186690Sobrien#define AV_386_SSE2 0x00001000 352186690Sobrien#define AV_386_PAUSE 0x00002000 353186690Sobrien#define AV_386_SSE3 0x00004000 354186690Sobrien#define AV_386_MON 0x00008000 355186690Sobrien#define AV_386_CX16 0x00010000 356186690Sobrien#define AV_386_AHF 0x00020000 357186690Sobrien#define AV_386_TSCP 0x00040000 358186690Sobrien#define AV_386_AMD_SSE4A 0x00080000 359186690Sobrien#define AV_386_POPCNT 0x00100000 360186690Sobrien#define AV_386_AMD_LZCNT 0x00200000 361186690Sobrien#define AV_386_SSSE3 0x00400000 362186690Sobrien#define AV_386_SSE4_1 0x00800000 363186690Sobrien#define AV_386_SSE4_2 0x01000000 364186690Sobrien 36568349Sobrien#endif 366