Merge from vendor branch CVS:
[dragonfly.git] / contrib / file / readelf.h
1 /*      $NetBSD: readelf.h,v 1.9 2002/05/18 07:00:47 pooka Exp $        */
2
3 /*
4  * readelf.h 
5  * @(#)Id: readelf.h,v 1.9 2002/05/16 18:45:56 christos Exp 
6  *
7  * Provide elf data structures for non-elf machines, allowing file
8  * non-elf hosts to determine if an elf binary is stripped.
9  * Note: cobbled from the linux header file, with modifications
10  */
11 #ifndef __fake_elf_h__
12 #define __fake_elf_h__
13
14 #if HAVE_STDINT_H
15 #include <stdint.h>
16 #endif
17
18 typedef uint32_t        Elf32_Addr;
19 typedef uint32_t        Elf32_Off;
20 typedef uint16_t        Elf32_Half;
21 typedef uint32_t        Elf32_Word;
22 typedef uint8_t         Elf32_Char;
23
24 #if SIZEOF_UINT64_T != 8
25 #define USE_ARRAY_FOR_64BIT_TYPES
26 typedef uint32_t        Elf64_Addr[2];
27 typedef uint32_t        Elf64_Off[2];
28 typedef uint32_t        Elf64_Xword[2];
29 #else
30 typedef uint64_t        Elf64_Addr;
31 typedef uint64_t        Elf64_Off;
32 typedef uint64_t        Elf64_Xword;
33 #endif
34 typedef uint16_t        Elf64_Half;
35 typedef uint32_t        Elf64_Word;
36 typedef uint8_t         Elf64_Char;
37
38 #define EI_NIDENT       16
39
40 typedef struct {
41     Elf32_Char  e_ident[EI_NIDENT];
42     Elf32_Half  e_type;
43     Elf32_Half  e_machine;
44     Elf32_Word  e_version;
45     Elf32_Addr  e_entry;  /* Entry point */
46     Elf32_Off   e_phoff;
47     Elf32_Off   e_shoff;
48     Elf32_Word  e_flags;
49     Elf32_Half  e_ehsize;
50     Elf32_Half  e_phentsize;
51     Elf32_Half  e_phnum;
52     Elf32_Half  e_shentsize;
53     Elf32_Half  e_shnum;
54     Elf32_Half  e_shstrndx;
55 } Elf32_Ehdr;
56
57 typedef struct {
58     Elf64_Char  e_ident[EI_NIDENT];
59     Elf64_Half  e_type;
60     Elf64_Half  e_machine;
61     Elf64_Word  e_version;
62     Elf64_Addr  e_entry;  /* Entry point */
63     Elf64_Off   e_phoff;
64     Elf64_Off   e_shoff;
65     Elf64_Word  e_flags;
66     Elf64_Half  e_ehsize;
67     Elf64_Half  e_phentsize;
68     Elf64_Half  e_phnum;
69     Elf64_Half  e_shentsize;
70     Elf64_Half  e_shnum;
71     Elf64_Half  e_shstrndx;
72 } Elf64_Ehdr;
73
74 /* e_type */
75 #define ET_EXEC         2
76 #define ET_CORE         4
77
78 /* sh_type */
79 #define SHT_SYMTAB      2
80 #define SHT_NOTE        7
81 #define SHT_DYNSYM      11
82
83 /* elf type */
84 #define ELFDATANONE     0               /* e_ident[EI_DATA] */
85 #define ELFDATA2LSB     1
86 #define ELFDATA2MSB     2
87
88 /* elf class */
89 #define ELFCLASSNONE    0
90 #define ELFCLASS32      1
91 #define ELFCLASS64      2
92
93 /* magic number */
94 #define EI_MAG0         0               /* e_ident[] indexes */
95 #define EI_MAG1         1
96 #define EI_MAG2         2
97 #define EI_MAG3         3
98 #define EI_CLASS        4
99 #define EI_DATA         5
100 #define EI_VERSION      6
101 #define EI_PAD          7
102
103 #define ELFMAG0         0x7f            /* EI_MAG */
104 #define ELFMAG1         'E'
105 #define ELFMAG2         'L'
106 #define ELFMAG3         'F'
107 #define ELFMAG          "\177ELF"
108
109 #define OLFMAG1         'O'
110 #define OLFMAG          "\177OLF"
111
112 typedef struct {
113     Elf32_Word  p_type;
114     Elf32_Off   p_offset;
115     Elf32_Addr  p_vaddr;
116     Elf32_Addr  p_paddr;
117     Elf32_Word  p_filesz;
118     Elf32_Word  p_memsz;
119     Elf32_Word  p_flags;
120     Elf32_Word  p_align;
121 } Elf32_Phdr;
122
123 typedef struct {
124     Elf64_Word  p_type;
125     Elf64_Word  p_flags;
126     Elf64_Off   p_offset;
127     Elf64_Addr  p_vaddr;
128     Elf64_Addr  p_paddr;
129     Elf64_Xword p_filesz;
130     Elf64_Xword p_memsz;
131     Elf64_Xword p_align;
132 } Elf64_Phdr;
133
134 #define PT_NULL         0               /* p_type */
135 #define PT_LOAD         1
136 #define PT_DYNAMIC      2
137 #define PT_INTERP       3
138 #define PT_NOTE         4
139 #define PT_SHLIB        5
140 #define PT_PHDR         6
141 #define PT_NUM          7
142
143 typedef struct {
144     Elf32_Word  sh_name;
145     Elf32_Word  sh_type;
146     Elf32_Word  sh_flags;
147     Elf32_Addr  sh_addr;
148     Elf32_Off   sh_offset;
149     Elf32_Word  sh_size;
150     Elf32_Word  sh_link;
151     Elf32_Word  sh_info;
152     Elf32_Word  sh_addralign;
153     Elf32_Word  sh_entsize;
154 } Elf32_Shdr;
155
156 typedef struct {
157     Elf64_Word  sh_name;
158     Elf64_Word  sh_type;
159     Elf64_Off   sh_flags;
160     Elf64_Addr  sh_addr;
161     Elf64_Off   sh_offset;
162     Elf64_Off   sh_size;
163     Elf64_Word  sh_link;
164     Elf64_Word  sh_info;
165     Elf64_Off   sh_addralign;
166     Elf64_Off   sh_entsize;
167 } Elf64_Shdr;
168
169 /* Notes used in ET_CORE */
170 #define NT_PRSTATUS     1
171 #define NT_PRFPREG      2
172 #define NT_PRPSINFO     3
173 #define NT_TASKSTRUCT   4
174
175 #define NT_NETBSD_CORE_PROCINFO         1
176
177 /* Note header in a PT_NOTE section */
178 typedef struct elf_note {
179     Elf32_Word  n_namesz;       /* Name size */
180     Elf32_Word  n_descsz;       /* Content size */
181     Elf32_Word  n_type;         /* Content type */
182 } Elf32_Nhdr;
183
184 typedef struct {
185     Elf64_Word  n_namesz;
186     Elf64_Word  n_descsz;
187     Elf64_Word  n_type;
188 } Elf64_Nhdr;
189
190 #define NT_PRSTATUS     1
191 #define NT_PRFPREG      2
192 #define NT_PRPSINFO     3
193 #define NT_PRXREG       4
194 #define NT_PLATFORM     5
195 #define NT_AUXV         6
196
197 /* Note types used in executables */
198 /* NetBSD executables (name = "NetBSD") */
199 #define NT_NETBSD_VERSION       1
200 #define NT_NETBSD_EMULATION     2
201 #define NT_FREEBSD_VERSION      1
202 #define NT_OPENBSD_VERSION      1
203 /* GNU executables (name = "GNU") */
204 #define NT_GNU_VERSION          1
205
206 /* GNU OS tags */
207 #define GNU_OS_LINUX    0
208 #define GNU_OS_HURD     1
209 #define GNU_OS_SOLARIS  2
210
211 #endif