2 * Copyright (c) Christos Zoulas 2003.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice immediately at the beginning of the file, without modification,
10 * this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp
30 * Provide elf data structures for non-elf machines, allowing file
31 * non-elf hosts to determine if an elf binary is stripped.
32 * Note: cobbled from the linux header file, with modifications
34 #ifndef __fake_elf_h__
35 #define __fake_elf_h__
41 typedef uint32_t Elf32_Addr
;
42 typedef uint32_t Elf32_Off
;
43 typedef uint16_t Elf32_Half
;
44 typedef uint32_t Elf32_Word
;
45 typedef uint8_t Elf32_Char
;
47 typedef uint64_t Elf64_Addr
;
48 typedef uint64_t Elf64_Off
;
49 typedef uint64_t Elf64_Xword
;
50 typedef uint16_t Elf64_Half
;
51 typedef uint32_t Elf64_Word
;
52 typedef uint8_t Elf64_Char
;
57 Elf32_Word a_type
; /* 32-bit id */
58 Elf32_Word a_v
; /* 32-bit id */
62 Elf64_Xword a_type
; /* 64-bit id */
63 Elf64_Xword a_v
; /* 64-bit id */
66 #define AT_NULL 0 /* end of vector */
67 #define AT_IGNORE 1 /* entry should be ignored */
68 #define AT_EXECFD 2 /* file descriptor of program */
69 #define AT_PHDR 3 /* program headers for program */
70 #define AT_PHENT 4 /* size of program header entry */
71 #define AT_PHNUM 5 /* number of program headers */
72 #define AT_PAGESZ 6 /* system page size */
73 #define AT_BASE 7 /* base address of interpreter */
74 #define AT_FLAGS 8 /* flags */
75 #define AT_ENTRY 9 /* entry point of program */
76 #define AT_LINUX_NOTELF 10 /* program is not ELF */
77 #define AT_LINUX_UID 11 /* real uid */
78 #define AT_LINUX_EUID 12 /* effective uid */
79 #define AT_LINUX_GID 13 /* real gid */
80 #define AT_LINUX_EGID 14 /* effective gid */
81 #define AT_LINUX_PLATFORM 15 /* string identifying CPU for optimizations */
82 #define AT_LINUX_HWCAP 16 /* arch dependent hints at CPU capabilities */
83 #define AT_LINUX_CLKTCK 17 /* frequency at which times() increments */
84 /* AT_* values 18 through 22 are reserved */
85 #define AT_LINUX_SECURE 23 /* secure mode boolean */
86 #define AT_LINUX_BASE_PLATFORM 24 /* string identifying real platform, may
87 * differ from AT_PLATFORM. */
88 #define AT_LINUX_RANDOM 25 /* address of 16 random bytes */
89 #define AT_LINUX_HWCAP2 26 /* extension of AT_HWCAP */
90 #define AT_LINUX_EXECFN 31 /* filename of program */
93 Elf32_Char e_ident
[EI_NIDENT
];
97 Elf32_Addr e_entry
; /* Entry point */
102 Elf32_Half e_phentsize
;
104 Elf32_Half e_shentsize
;
106 Elf32_Half e_shstrndx
;
110 Elf64_Char e_ident
[EI_NIDENT
];
112 Elf64_Half e_machine
;
113 Elf64_Word e_version
;
114 Elf64_Addr e_entry
; /* Entry point */
119 Elf64_Half e_phentsize
;
121 Elf64_Half e_shentsize
;
123 Elf64_Half e_shstrndx
;
132 /* e_machine (used only for SunOS 5.x hardware capabilities) */
135 #define EM_SPARC32PLUS 18
136 #define EM_SPARCV9 43
143 #define SHT_DYNSYM 11
144 #define SHT_SUNW_cap 0x6ffffff5 /* SunOS 5.x hw/sw capabilites */
147 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
148 #define ELFDATA2LSB 1
149 #define ELFDATA2MSB 2
152 #define ELFCLASSNONE 0
157 #define EI_MAG0 0 /* e_ident[] indexes */
166 #define ELFMAG0 0x7f /* EI_MAG */
170 #define ELFMAG "\177ELF"
173 #define OLFMAG "\177OLF"
192 Elf64_Xword p_filesz
;
197 #define PT_NULL 0 /* p_type */
215 Elf32_Word sh_addralign
;
216 Elf32_Word sh_entsize
;
228 Elf64_Off sh_addralign
;
229 Elf64_Off sh_entsize
;
232 #define NT_NETBSD_CORE_PROCINFO 1
234 /* Note header in a PT_NOTE section */
235 typedef struct elf_note
{
236 Elf32_Word n_namesz
; /* Name size */
237 Elf32_Word n_descsz
; /* Content size */
238 Elf32_Word n_type
; /* Content type */
247 /* Notes used in ET_CORE */
248 #define NT_PRSTATUS 1
250 #define NT_PRPSINFO 3
252 #define NT_TASKSTRUCT 4
253 #define NT_PLATFORM 5
256 /* Note types used in executables */
257 /* NetBSD executables (name = "NetBSD") */
258 #define NT_NETBSD_VERSION 1
259 #define NT_NETBSD_EMULATION 2
260 #define NT_FREEBSD_VERSION 1
261 #define NT_OPENBSD_VERSION 1
262 #define NT_DRAGONFLY_VERSION 1
264 * GNU executables (name = "GNU")
265 * word[0]: GNU OS tags
266 * word[1]: major version
267 * word[2]: minor version
268 * word[3]: tiny version
270 #define NT_GNU_VERSION 1
273 #define GNU_OS_LINUX 0
274 #define GNU_OS_HURD 1
275 #define GNU_OS_SOLARIS 2
276 #define GNU_OS_KFREEBSD 3
277 #define GNU_OS_KNETBSD 4
280 * GNU Hardware capability information
281 * word[0]: Number of entries
282 * word[1]: Bitmask of enabled entries
283 * Followed by a byte id, and a NUL terminated string per entry
285 #define NT_GNU_HWCAP 2
288 * GNU Build ID generated by ld
289 * 160 bit SHA1 [default]
290 * 128 bit md5 or uuid
292 #define NT_GNU_BUILD_ID 3
295 * NetBSD-specific note type: PaX.
296 * There should be 1 NOTE per executable.
300 * word[0]: capability bitmask
303 #define NT_NETBSD_PAX 3
304 #define NT_NETBSD_PAX_MPROTECT 0x01 /* Force enable Mprotect */
305 #define NT_NETBSD_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */
306 #define NT_NETBSD_PAX_GUARD 0x04 /* Force enable Segvguard */
307 #define NT_NETBSD_PAX_NOGUARD 0x08 /* Force disable Servguard */
308 #define NT_NETBSD_PAX_ASLR 0x10 /* Force enable ASLR */
309 #define NT_NETBSD_PAX_NOASLR 0x20 /* Force disable ASLR */
312 * NetBSD-specific note type: MACHINE_ARCH.
313 * There should be 1 NOTE per executable.
319 #define NT_NETBSD_MARCH 5
322 * NetBSD-specific note type: COMPILER MODEL.
323 * There should be 1 NOTE per executable.
329 #define NT_NETBSD_CMODEL 6
331 #if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
332 #define ELFSIZE ARCH_ELFSIZE
334 /* SunOS 5.x hardware/software capabilities */
351 /* SunOS 5.x hardware/software capability tags */
352 #define CA_SUNW_NULL 0
353 #define CA_SUNW_HW_1 1
354 #define CA_SUNW_SF_1 2
356 /* SunOS 5.x software capabilities */
357 #define SF1_SUNW_FPKNWN 0x01
358 #define SF1_SUNW_FPUSED 0x02
359 #define SF1_SUNW_MASK 0x03
361 /* SunOS 5.x hardware capabilities: sparc */
362 #define AV_SPARC_MUL32 0x0001
363 #define AV_SPARC_DIV32 0x0002
364 #define AV_SPARC_FSMULD 0x0004
365 #define AV_SPARC_V8PLUS 0x0008
366 #define AV_SPARC_POPC 0x0010
367 #define AV_SPARC_VIS 0x0020
368 #define AV_SPARC_VIS2 0x0040
369 #define AV_SPARC_ASI_BLK_INIT 0x0080
370 #define AV_SPARC_FMAF 0x0100
371 #define AV_SPARC_FJFMAU 0x4000
372 #define AV_SPARC_IMA 0x8000
374 /* SunOS 5.x hardware capabilities: 386 */
375 #define AV_386_FPU 0x00000001
376 #define AV_386_TSC 0x00000002
377 #define AV_386_CX8 0x00000004
378 #define AV_386_SEP 0x00000008
379 #define AV_386_AMD_SYSC 0x00000010
380 #define AV_386_CMOV 0x00000020
381 #define AV_386_MMX 0x00000040
382 #define AV_386_AMD_MMX 0x00000080
383 #define AV_386_AMD_3DNow 0x00000100
384 #define AV_386_AMD_3DNowx 0x00000200
385 #define AV_386_FXSR 0x00000400
386 #define AV_386_SSE 0x00000800
387 #define AV_386_SSE2 0x00001000
388 #define AV_386_PAUSE 0x00002000
389 #define AV_386_SSE3 0x00004000
390 #define AV_386_MON 0x00008000
391 #define AV_386_CX16 0x00010000
392 #define AV_386_AHF 0x00020000
393 #define AV_386_TSCP 0x00040000
394 #define AV_386_AMD_SSE4A 0x00080000
395 #define AV_386_POPCNT 0x00100000
396 #define AV_386_AMD_LZCNT 0x00200000
397 #define AV_386_SSSE3 0x00400000
398 #define AV_386_SSE4_1 0x00800000
399 #define AV_386_SSE4_2 0x01000000