xref: /minix/external/bsd/file/dist/src/readelf.h (revision ebfedea0)
1 /*	$NetBSD: readelf.h,v 1.1.1.3 2013/03/23 15:49:15 christos Exp $	*/
2 
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  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 /*
30  * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp
31  *
32  * Provide elf data structures for non-elf machines, allowing file
33  * non-elf hosts to determine if an elf binary is stripped.
34  * Note: cobbled from the linux header file, with modifications
35  */
36 #ifndef __fake_elf_h__
37 #define	__fake_elf_h__
38 
39 #if HAVE_STDINT_H
40 #include <stdint.h>
41 #endif
42 
43 typedef uint32_t	Elf32_Addr;
44 typedef uint32_t	Elf32_Off;
45 typedef uint16_t	Elf32_Half;
46 typedef uint32_t	Elf32_Word;
47 typedef uint8_t		Elf32_Char;
48 
49 typedef	uint64_t 	Elf64_Addr;
50 typedef	uint64_t 	Elf64_Off;
51 typedef uint64_t 	Elf64_Xword;
52 typedef uint16_t	Elf64_Half;
53 typedef uint32_t	Elf64_Word;
54 typedef uint8_t		Elf64_Char;
55 
56 #define	EI_NIDENT	16
57 
58 typedef struct {
59     Elf32_Char	e_ident[EI_NIDENT];
60     Elf32_Half	e_type;
61     Elf32_Half	e_machine;
62     Elf32_Word	e_version;
63     Elf32_Addr	e_entry;  /* Entry point */
64     Elf32_Off	e_phoff;
65     Elf32_Off	e_shoff;
66     Elf32_Word	e_flags;
67     Elf32_Half	e_ehsize;
68     Elf32_Half	e_phentsize;
69     Elf32_Half	e_phnum;
70     Elf32_Half	e_shentsize;
71     Elf32_Half	e_shnum;
72     Elf32_Half	e_shstrndx;
73 } Elf32_Ehdr;
74 
75 typedef struct {
76     Elf64_Char	e_ident[EI_NIDENT];
77     Elf64_Half	e_type;
78     Elf64_Half	e_machine;
79     Elf64_Word	e_version;
80     Elf64_Addr	e_entry;  /* Entry point */
81     Elf64_Off	e_phoff;
82     Elf64_Off	e_shoff;
83     Elf64_Word	e_flags;
84     Elf64_Half	e_ehsize;
85     Elf64_Half	e_phentsize;
86     Elf64_Half	e_phnum;
87     Elf64_Half	e_shentsize;
88     Elf64_Half	e_shnum;
89     Elf64_Half	e_shstrndx;
90 } Elf64_Ehdr;
91 
92 /* e_type */
93 #define	ET_REL		1
94 #define	ET_EXEC		2
95 #define	ET_DYN		3
96 #define	ET_CORE		4
97 
98 /* e_machine (used only for SunOS 5.x hardware capabilities) */
99 #define	EM_SPARC	2
100 #define	EM_386		3
101 #define	EM_SPARC32PLUS	18
102 #define	EM_SPARCV9	43
103 #define	EM_IA_64	50
104 #define	EM_AMD64	62
105 
106 /* sh_type */
107 #define	SHT_SYMTAB	2
108 #define	SHT_NOTE	7
109 #define	SHT_DYNSYM	11
110 #define	SHT_SUNW_cap	0x6ffffff5	/* SunOS 5.x hw/sw capabilites */
111 
112 /* elf type */
113 #define	ELFDATANONE	0		/* e_ident[EI_DATA] */
114 #define	ELFDATA2LSB	1
115 #define	ELFDATA2MSB	2
116 
117 /* elf class */
118 #define	ELFCLASSNONE	0
119 #define	ELFCLASS32	1
120 #define	ELFCLASS64	2
121 
122 /* magic number */
123 #define	EI_MAG0		0		/* e_ident[] indexes */
124 #define	EI_MAG1		1
125 #define	EI_MAG2		2
126 #define	EI_MAG3		3
127 #define	EI_CLASS	4
128 #define	EI_DATA		5
129 #define	EI_VERSION	6
130 #define	EI_PAD		7
131 
132 #define	ELFMAG0		0x7f		/* EI_MAG */
133 #define	ELFMAG1		'E'
134 #define	ELFMAG2		'L'
135 #define	ELFMAG3		'F'
136 #define	ELFMAG		"\177ELF"
137 
138 #define	OLFMAG1		'O'
139 #define	OLFMAG		"\177OLF"
140 
141 typedef struct {
142     Elf32_Word	p_type;
143     Elf32_Off	p_offset;
144     Elf32_Addr	p_vaddr;
145     Elf32_Addr	p_paddr;
146     Elf32_Word	p_filesz;
147     Elf32_Word	p_memsz;
148     Elf32_Word	p_flags;
149     Elf32_Word	p_align;
150 } Elf32_Phdr;
151 
152 typedef struct {
153     Elf64_Word	p_type;
154     Elf64_Word	p_flags;
155     Elf64_Off	p_offset;
156     Elf64_Addr	p_vaddr;
157     Elf64_Addr	p_paddr;
158     Elf64_Xword	p_filesz;
159     Elf64_Xword	p_memsz;
160     Elf64_Xword	p_align;
161 } Elf64_Phdr;
162 
163 #define	PT_NULL		0		/* p_type */
164 #define	PT_LOAD		1
165 #define	PT_DYNAMIC	2
166 #define	PT_INTERP	3
167 #define	PT_NOTE		4
168 #define	PT_SHLIB	5
169 #define	PT_PHDR		6
170 #define	PT_NUM		7
171 
172 typedef struct {
173     Elf32_Word	sh_name;
174     Elf32_Word	sh_type;
175     Elf32_Word	sh_flags;
176     Elf32_Addr	sh_addr;
177     Elf32_Off	sh_offset;
178     Elf32_Word	sh_size;
179     Elf32_Word	sh_link;
180     Elf32_Word	sh_info;
181     Elf32_Word	sh_addralign;
182     Elf32_Word	sh_entsize;
183 } Elf32_Shdr;
184 
185 typedef struct {
186     Elf64_Word	sh_name;
187     Elf64_Word	sh_type;
188     Elf64_Off	sh_flags;
189     Elf64_Addr	sh_addr;
190     Elf64_Off	sh_offset;
191     Elf64_Off	sh_size;
192     Elf64_Word	sh_link;
193     Elf64_Word	sh_info;
194     Elf64_Off	sh_addralign;
195     Elf64_Off	sh_entsize;
196 } Elf64_Shdr;
197 
198 #define	NT_NETBSD_CORE_PROCINFO		1
199 
200 /* Note header in a PT_NOTE section */
201 typedef struct elf_note {
202     Elf32_Word	n_namesz;	/* Name size */
203     Elf32_Word	n_descsz;	/* Content size */
204     Elf32_Word	n_type;		/* Content type */
205 } Elf32_Nhdr;
206 
207 typedef struct {
208     Elf64_Word	n_namesz;
209     Elf64_Word	n_descsz;
210     Elf64_Word	n_type;
211 } Elf64_Nhdr;
212 
213 /* Notes used in ET_CORE */
214 #define	NT_PRSTATUS	1
215 #define	NT_PRFPREG	2
216 #define	NT_PRPSINFO	3
217 #define	NT_PRXREG	4
218 #define	NT_TASKSTRUCT	4
219 #define	NT_PLATFORM	5
220 #define	NT_AUXV		6
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
228 #define	NT_DRAGONFLY_VERSION	1
229 /*
230  * GNU executables (name = "GNU")
231  * word[0]: GNU OS tags
232  * word[1]: major version
233  * word[2]: minor version
234  * word[3]: tiny version
235  */
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 
245 /*
246  * GNU Hardware capability information
247  * word[0]: Number of entries
248  * word[1]: Bitmask of enabled entries
249  * Followed by a byte id, and a NUL terminated string per entry
250  */
251 #define	NT_GNU_HWCAP		2
252 
253 /*
254  * GNU Build ID generated by ld
255  * 160 bit SHA1 [default]
256  * 128 bit md5 or uuid
257  */
258 #define	NT_GNU_BUILD_ID		3
259 
260 /* SunOS 5.x hardware/software capabilities */
261 typedef struct {
262 	Elf32_Word	c_tag;
263 	union {
264 		Elf32_Word	c_val;
265 		Elf32_Addr	c_ptr;
266 	} c_un;
267 } Elf32_Cap;
268 
269 typedef struct {
270 	Elf64_Xword	c_tag;
271 	union {
272 		Elf64_Xword	c_val;
273 		Elf64_Addr	c_ptr;
274 	} c_un;
275 } Elf64_Cap;
276 
277 /* SunOS 5.x hardware/software capability tags */
278 #define	CA_SUNW_NULL	0
279 #define	CA_SUNW_HW_1	1
280 #define	CA_SUNW_SF_1	2
281 
282 /* SunOS 5.x software capabilities */
283 #define	SF1_SUNW_FPKNWN	0x01
284 #define	SF1_SUNW_FPUSED	0x02
285 #define	SF1_SUNW_MASK	0x03
286 
287 /* SunOS 5.x hardware capabilities: sparc */
288 #define	AV_SPARC_MUL32		0x0001
289 #define	AV_SPARC_DIV32		0x0002
290 #define	AV_SPARC_FSMULD		0x0004
291 #define	AV_SPARC_V8PLUS		0x0008
292 #define	AV_SPARC_POPC		0x0010
293 #define	AV_SPARC_VIS		0x0020
294 #define	AV_SPARC_VIS2		0x0040
295 #define	AV_SPARC_ASI_BLK_INIT	0x0080
296 #define	AV_SPARC_FMAF		0x0100
297 #define	AV_SPARC_FJFMAU		0x4000
298 #define	AV_SPARC_IMA		0x8000
299 
300 /* SunOS 5.x hardware capabilities: 386 */
301 #define	AV_386_FPU		0x00000001
302 #define	AV_386_TSC		0x00000002
303 #define	AV_386_CX8		0x00000004
304 #define	AV_386_SEP		0x00000008
305 #define	AV_386_AMD_SYSC		0x00000010
306 #define	AV_386_CMOV		0x00000020
307 #define	AV_386_MMX		0x00000040
308 #define	AV_386_AMD_MMX		0x00000080
309 #define	AV_386_AMD_3DNow	0x00000100
310 #define	AV_386_AMD_3DNowx	0x00000200
311 #define	AV_386_FXSR		0x00000400
312 #define	AV_386_SSE		0x00000800
313 #define	AV_386_SSE2		0x00001000
314 #define	AV_386_PAUSE		0x00002000
315 #define	AV_386_SSE3		0x00004000
316 #define	AV_386_MON		0x00008000
317 #define	AV_386_CX16		0x00010000
318 #define	AV_386_AHF		0x00020000
319 #define	AV_386_TSCP		0x00040000
320 #define	AV_386_AMD_SSE4A	0x00080000
321 #define	AV_386_POPCNT		0x00100000
322 #define	AV_386_AMD_LZCNT	0x00200000
323 #define	AV_386_SSSE3		0x00400000
324 #define	AV_386_SSE4_1		0x00800000
325 #define	AV_386_SSE4_2		0x01000000
326 
327 #endif
328