Update to file-4.19.
[dragonfly.git] / contrib / file-4 / src / readelf.h
CommitLineData
ab0b56cc
JS
1/*
2 * Copyright (c) Christos Zoulas 2003.
3 * All Rights Reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
14 *
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
25 * SUCH DAMAGE.
26 */
27/*
28 * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp
29 *
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
33 */
34#ifndef __fake_elf_h__
35#define __fake_elf_h__
36
37#if HAVE_STDINT_H
38#include <stdint.h>
39#endif
40
41typedef uint32_t Elf32_Addr;
42typedef uint32_t Elf32_Off;
43typedef uint16_t Elf32_Half;
44typedef uint32_t Elf32_Word;
45typedef uint8_t Elf32_Char;
46
47#if SIZEOF_UINT64_T != 8
48#define USE_ARRAY_FOR_64BIT_TYPES
49typedef uint32_t Elf64_Addr[2];
50typedef uint32_t Elf64_Off[2];
51typedef uint32_t Elf64_Xword[2];
52#else
9b22a626 53#undef USE_ARRAY_FOR_64BIT_TYPES
ab0b56cc
JS
54typedef uint64_t Elf64_Addr;
55typedef uint64_t Elf64_Off;
56typedef uint64_t Elf64_Xword;
57#endif
58typedef uint16_t Elf64_Half;
59typedef uint32_t Elf64_Word;
60typedef uint8_t Elf64_Char;
61
62#define EI_NIDENT 16
63
64typedef struct {
65 Elf32_Char e_ident[EI_NIDENT];
66 Elf32_Half e_type;
67 Elf32_Half e_machine;
68 Elf32_Word e_version;
69 Elf32_Addr e_entry; /* Entry point */
70 Elf32_Off e_phoff;
71 Elf32_Off e_shoff;
72 Elf32_Word e_flags;
73 Elf32_Half e_ehsize;
74 Elf32_Half e_phentsize;
75 Elf32_Half e_phnum;
76 Elf32_Half e_shentsize;
77 Elf32_Half e_shnum;
78 Elf32_Half e_shstrndx;
79} Elf32_Ehdr;
80
81typedef struct {
82 Elf64_Char e_ident[EI_NIDENT];
83 Elf64_Half e_type;
84 Elf64_Half e_machine;
85 Elf64_Word e_version;
86 Elf64_Addr e_entry; /* Entry point */
87 Elf64_Off e_phoff;
88 Elf64_Off e_shoff;
89 Elf64_Word e_flags;
90 Elf64_Half e_ehsize;
91 Elf64_Half e_phentsize;
92 Elf64_Half e_phnum;
93 Elf64_Half e_shentsize;
94 Elf64_Half e_shnum;
95 Elf64_Half e_shstrndx;
96} Elf64_Ehdr;
97
98/* e_type */
99#define ET_EXEC 2
100#define ET_CORE 4
101
102/* sh_type */
103#define SHT_SYMTAB 2
104#define SHT_NOTE 7
105#define SHT_DYNSYM 11
106
107/* elf type */
108#define ELFDATANONE 0 /* e_ident[EI_DATA] */
109#define ELFDATA2LSB 1
110#define ELFDATA2MSB 2
111
112/* elf class */
113#define ELFCLASSNONE 0
114#define ELFCLASS32 1
115#define ELFCLASS64 2
116
117/* magic number */
118#define EI_MAG0 0 /* e_ident[] indexes */
119#define EI_MAG1 1
120#define EI_MAG2 2
121#define EI_MAG3 3
122#define EI_CLASS 4
123#define EI_DATA 5
124#define EI_VERSION 6
125#define EI_PAD 7
126
127#define ELFMAG0 0x7f /* EI_MAG */
128#define ELFMAG1 'E'
129#define ELFMAG2 'L'
130#define ELFMAG3 'F'
131#define ELFMAG "\177ELF"
132
133#define OLFMAG1 'O'
134#define OLFMAG "\177OLF"
135
136typedef struct {
137 Elf32_Word p_type;
138 Elf32_Off p_offset;
139 Elf32_Addr p_vaddr;
140 Elf32_Addr p_paddr;
141 Elf32_Word p_filesz;
142 Elf32_Word p_memsz;
143 Elf32_Word p_flags;
144 Elf32_Word p_align;
145} Elf32_Phdr;
146
147typedef struct {
148 Elf64_Word p_type;
149 Elf64_Word p_flags;
150 Elf64_Off p_offset;
151 Elf64_Addr p_vaddr;
152 Elf64_Addr p_paddr;
153 Elf64_Xword p_filesz;
154 Elf64_Xword p_memsz;
155 Elf64_Xword p_align;
156} Elf64_Phdr;
157
158#define PT_NULL 0 /* p_type */
159#define PT_LOAD 1
160#define PT_DYNAMIC 2
161#define PT_INTERP 3
162#define PT_NOTE 4
163#define PT_SHLIB 5
164#define PT_PHDR 6
165#define PT_NUM 7
166
167typedef struct {
168 Elf32_Word sh_name;
169 Elf32_Word sh_type;
170 Elf32_Word sh_flags;
171 Elf32_Addr sh_addr;
172 Elf32_Off sh_offset;
173 Elf32_Word sh_size;
174 Elf32_Word sh_link;
175 Elf32_Word sh_info;
176 Elf32_Word sh_addralign;
177 Elf32_Word sh_entsize;
178} Elf32_Shdr;
179
180typedef struct {
181 Elf64_Word sh_name;
182 Elf64_Word sh_type;
183 Elf64_Off sh_flags;
184 Elf64_Addr sh_addr;
185 Elf64_Off sh_offset;
186 Elf64_Off sh_size;
187 Elf64_Word sh_link;
188 Elf64_Word sh_info;
189 Elf64_Off sh_addralign;
190 Elf64_Off sh_entsize;
191} Elf64_Shdr;
192
193/* Notes used in ET_CORE */
194#define NT_PRSTATUS 1
195#define NT_PRFPREG 2
196#define NT_PRPSINFO 3
197#define NT_TASKSTRUCT 4
198
199#define NT_NETBSD_CORE_PROCINFO 1
200
201/* Note header in a PT_NOTE section */
202typedef struct elf_note {
203 Elf32_Word n_namesz; /* Name size */
204 Elf32_Word n_descsz; /* Content size */
205 Elf32_Word n_type; /* Content type */
206} Elf32_Nhdr;
207
208typedef struct {
209 Elf64_Word n_namesz;
210 Elf64_Word n_descsz;
211 Elf64_Word n_type;
212} Elf64_Nhdr;
213
214#define NT_PRSTATUS 1
215#define NT_PRFPREG 2
216#define NT_PRPSINFO 3
217#define NT_PRXREG 4
218#define NT_PLATFORM 5
219#define NT_AUXV 6
220
221/* Note types used in executables */
222/* NetBSD executables (name = "NetBSD") */
223#define NT_NETBSD_VERSION 1
224#define NT_NETBSD_EMULATION 2
225#define NT_FREEBSD_VERSION 1
226#define NT_OPENBSD_VERSION 1
2be182fc 227#define NT_DRAGONFLY_VERSION 1
ab0b56cc
JS
228/* GNU executables (name = "GNU") */
229#define NT_GNU_VERSION 1
230
231/* GNU OS tags */
232#define GNU_OS_LINUX 0
233#define GNU_OS_HURD 1
234#define GNU_OS_SOLARIS 2
235
236#endif