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