1 /** $MirOS: src/usr.bin/file/readelf.h,v 1.5 2007/07/19 18:22:15 tg Exp $ */ 2 /* $OpenBSD: readelf.h,v 1.5 2004/05/19 02:32:36 tedu Exp $ */ 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 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 /* 32 * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp 33 * 34 * Provide elf data structures for non-elf machines, allowing file 35 * non-elf hosts to determine if an elf binary is stripped. 36 * Note: cobbled from the linux header file, with modifications 37 */ 38 #ifndef __fake_elf_h__ 39 #define __fake_elf_h__ 40 41 #if HAVE_STDINT_H 42 #include <stdint.h> 43 #endif 44 45 typedef uint32_t Elf32_Addr; 46 typedef uint32_t Elf32_Off; 47 typedef uint16_t Elf32_Half; 48 typedef uint32_t Elf32_Word; 49 typedef uint8_t Elf32_Char; 50 51 #if SIZEOF_UINT64_T != 8 52 #define USE_ARRAY_FOR_64BIT_TYPES 53 typedef uint32_t Elf64_Addr[2]; 54 typedef uint32_t Elf64_Off[2]; 55 typedef uint32_t Elf64_Xword[2]; 56 #else 57 typedef uint64_t Elf64_Addr; 58 typedef uint64_t Elf64_Off; 59 typedef uint64_t Elf64_Xword; 60 #endif 61 typedef uint16_t Elf64_Half; 62 typedef uint32_t Elf64_Word; 63 typedef uint8_t Elf64_Char; 64 65 #define EI_NIDENT 16 66 67 typedef struct { 68 Elf32_Char e_ident[EI_NIDENT]; 69 Elf32_Half e_type; 70 Elf32_Half e_machine; 71 Elf32_Word e_version; 72 Elf32_Addr e_entry; /* Entry point */ 73 Elf32_Off e_phoff; 74 Elf32_Off e_shoff; 75 Elf32_Word e_flags; 76 Elf32_Half e_ehsize; 77 Elf32_Half e_phentsize; 78 Elf32_Half e_phnum; 79 Elf32_Half e_shentsize; 80 Elf32_Half e_shnum; 81 Elf32_Half e_shstrndx; 82 } Elf32_Ehdr; 83 84 typedef struct { 85 Elf64_Char e_ident[EI_NIDENT]; 86 Elf64_Half e_type; 87 Elf64_Half e_machine; 88 Elf64_Word e_version; 89 Elf64_Addr e_entry; /* Entry point */ 90 Elf64_Off e_phoff; 91 Elf64_Off e_shoff; 92 Elf64_Word e_flags; 93 Elf64_Half e_ehsize; 94 Elf64_Half e_phentsize; 95 Elf64_Half e_phnum; 96 Elf64_Half e_shentsize; 97 Elf64_Half e_shnum; 98 Elf64_Half e_shstrndx; 99 } Elf64_Ehdr; 100 101 /* e_type */ 102 #define ET_EXEC 2 103 #define ET_DYN 3 104 #define ET_CORE 4 105 106 /* sh_type */ 107 #define SHT_SYMTAB 2 108 #define SHT_NOTE 7 109 #define SHT_DYNSYM 11 110 111 /* elf type */ 112 #define ELFDATANONE 0 /* e_ident[EI_DATA] */ 113 #define ELFDATA2LSB 1 114 #define ELFDATA2MSB 2 115 116 /* elf class */ 117 #define ELFCLASSNONE 0 118 #define ELFCLASS32 1 119 #define ELFCLASS64 2 120 121 /* magic number */ 122 #define EI_MAG0 0 /* e_ident[] indexes */ 123 #define EI_MAG1 1 124 #define EI_MAG2 2 125 #define EI_MAG3 3 126 #define EI_CLASS 4 127 #define EI_DATA 5 128 #define EI_VERSION 6 129 #define EI_PAD 7 130 131 #define ELFMAG0 0x7f /* EI_MAG */ 132 #define ELFMAG1 'E' 133 #define ELFMAG2 'L' 134 #define ELFMAG3 'F' 135 #define ELFMAG "\177ELF" 136 137 #define OLFMAG1 'O' 138 #define OLFMAG "\177OLF" 139 140 typedef struct { 141 Elf32_Word p_type; 142 Elf32_Off p_offset; 143 Elf32_Addr p_vaddr; 144 Elf32_Addr p_paddr; 145 Elf32_Word p_filesz; 146 Elf32_Word p_memsz; 147 Elf32_Word p_flags; 148 Elf32_Word p_align; 149 } Elf32_Phdr; 150 151 typedef struct { 152 Elf64_Word p_type; 153 Elf64_Word p_flags; 154 Elf64_Off p_offset; 155 Elf64_Addr p_vaddr; 156 Elf64_Addr p_paddr; 157 Elf64_Xword p_filesz; 158 Elf64_Xword p_memsz; 159 Elf64_Xword p_align; 160 } Elf64_Phdr; 161 162 #define PT_NULL 0 /* p_type */ 163 #define PT_LOAD 1 164 #define PT_DYNAMIC 2 165 #define PT_INTERP 3 166 #define PT_NOTE 4 167 #define PT_SHLIB 5 168 #define PT_PHDR 6 169 #define PT_NUM 7 170 171 typedef struct { 172 Elf32_Word sh_name; 173 Elf32_Word sh_type; 174 Elf32_Word sh_flags; 175 Elf32_Addr sh_addr; 176 Elf32_Off sh_offset; 177 Elf32_Word sh_size; 178 Elf32_Word sh_link; 179 Elf32_Word sh_info; 180 Elf32_Word sh_addralign; 181 Elf32_Word sh_entsize; 182 } Elf32_Shdr; 183 184 typedef struct { 185 Elf64_Word sh_name; 186 Elf64_Word sh_type; 187 Elf64_Off sh_flags; 188 Elf64_Addr sh_addr; 189 Elf64_Off sh_offset; 190 Elf64_Off sh_size; 191 Elf64_Word sh_link; 192 Elf64_Word sh_info; 193 Elf64_Off sh_addralign; 194 Elf64_Off sh_entsize; 195 } Elf64_Shdr; 196 197 /* Notes used in ET_CORE */ 198 #define NT_PRSTATUS 1 199 #define NT_PRFPREG 2 200 #define NT_PRPSINFO 3 201 #define NT_TASKSTRUCT 4 202 203 #define NT_NETBSD_CORE_PROCINFO 1 204 205 /* Note header in a PT_NOTE section */ 206 typedef struct elf_note { 207 Elf32_Word n_namesz; /* Name size */ 208 Elf32_Word n_descsz; /* Content size */ 209 Elf32_Word n_type; /* Content type */ 210 } Elf32_Nhdr; 211 212 typedef struct { 213 Elf64_Word n_namesz; 214 Elf64_Word n_descsz; 215 Elf64_Word n_type; 216 } Elf64_Nhdr; 217 218 #define NT_PRSTATUS 1 219 #define NT_PRFPREG 2 220 #define NT_PRPSINFO 3 221 #define NT_PRXREG 4 222 #define NT_PLATFORM 5 223 #define NT_AUXV 6 224 225 /* Note types used in executables */ 226 /* NetBSD executables (name = "NetBSD") */ 227 #define NT_NETBSD_VERSION 1 228 #define NT_NETBSD_EMULATION 2 229 #define NT_FREEBSD_VERSION 1 230 #define NT_OPENBSD_VERSION 1 231 #define NT_MIRBSD_VERSION 1 232 #define NT_MIROS_VERSION 1 233 #define NT_MIROS_STRTEST "MirOS " 234 #define NT_MIROS_STRTLEN 6 235 /* GNU executables (name = "GNU") */ 236 #define NT_GNU_VERSION 1 237 238 /* GNU OS tags */ 239 #define GNU_OS_LINUX 0 240 #define GNU_OS_HURD 1 241 #define GNU_OS_SOLARIS 2 242 #define GNU_OS_KFREEBSD 3 243 #define GNU_OS_KNETBSD 4 244 #define GNU_OS_SYLLABLE 5 245 246 #endif 247