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