include
[deliverable/binutils-gdb.git] / include / coff / pe.h
1 /* pe.h - PE COFF header information
2
3 Copyright 1999, 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20 #ifndef _PE_H
21 #define _PE_H
22
23 /* NT specific file attributes. */
24 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001
25 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
26 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
27 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
28 #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
29 #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
30 #define IMAGE_FILE_16BIT_MACHINE 0x0040
31 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
32 #define IMAGE_FILE_32BIT_MACHINE 0x0100
33 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
34 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
35 #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
36 #define IMAGE_FILE_SYSTEM 0x1000
37 #define IMAGE_FILE_DLL 0x2000
38 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
39 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
40
41 /* Additional flags to be set for section headers to allow the NT loader to
42 read and write to the section data (to replace the addresses of data in
43 dlls for one thing); also to execute the section in .text's case. */
44 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
45 #define IMAGE_SCN_MEM_EXECUTE 0x20000000
46 #define IMAGE_SCN_MEM_READ 0x40000000
47 #define IMAGE_SCN_MEM_WRITE 0x80000000
48
49 /* Section characteristics added for ppc-nt. */
50
51 #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
52
53 #define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
54 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
55 #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
56
57 #define IMAGE_SCN_LNK_OTHER 0x00000100 /* Reserved. */
58 #define IMAGE_SCN_LNK_INFO 0x00000200 /* Section contains comments or some other type of information. */
59 #define IMAGE_SCN_LNK_REMOVE 0x00000800 /* Section contents will not become part of image. */
60 #define IMAGE_SCN_LNK_COMDAT 0x00001000 /* Section contents comdat. */
61
62 #define IMAGE_SCN_MEM_FARDATA 0x00008000
63
64 #define IMAGE_SCN_MEM_PURGEABLE 0x00020000
65 #define IMAGE_SCN_MEM_16BIT 0x00020000
66 #define IMAGE_SCN_MEM_LOCKED 0x00040000
67 #define IMAGE_SCN_MEM_PRELOAD 0x00080000
68
69 /* Bit position in the s_flags field where the alignment values start. */
70 #define IMAGE_SCN_ALIGN_POWER_BIT_POS 20
71 #define IMAGE_SCN_ALIGN_POWER_BIT_MASK 0x00f00000
72 #define IMAGE_SCN_ALIGN_POWER_NUM(val) \
73 (((val) >> IMAGE_SCN_ALIGN_POWER_BIT_POS) - 1)
74 #define IMAGE_SCN_ALIGN_POWER_CONST(val) \
75 (((val) + 1) << IMAGE_SCN_ALIGN_POWER_BIT_POS)
76
77 #define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_POWER_CONST (0)
78 #define IMAGE_SCN_ALIGN_2BYTES IMAGE_SCN_ALIGN_POWER_CONST (1)
79 #define IMAGE_SCN_ALIGN_4BYTES IMAGE_SCN_ALIGN_POWER_CONST (2)
80 #define IMAGE_SCN_ALIGN_8BYTES IMAGE_SCN_ALIGN_POWER_CONST (3)
81 /* Default alignment if no others are specified. */
82 #define IMAGE_SCN_ALIGN_16BYTES IMAGE_SCN_ALIGN_POWER_CONST (4)
83 #define IMAGE_SCN_ALIGN_32BYTES IMAGE_SCN_ALIGN_POWER_CONST (5)
84 #define IMAGE_SCN_ALIGN_64BYTES IMAGE_SCN_ALIGN_POWER_CONST (6)
85 #define IMAGE_SCN_ALIGN_128BYTES IMAGE_SCN_ALIGN_POWER_CONST (7)
86 #define IMAGE_SCN_ALIGN_256BYTES IMAGE_SCN_ALIGN_POWER_CONST (8)
87 #define IMAGE_SCN_ALIGN_512BYTES IMAGE_SCN_ALIGN_POWER_CONST (9)
88 #define IMAGE_SCN_ALIGN_1024BYTES IMAGE_SCN_ALIGN_POWER_CONST (10)
89 #define IMAGE_SCN_ALIGN_2048BYTES IMAGE_SCN_ALIGN_POWER_CONST (11)
90 #define IMAGE_SCN_ALIGN_4096BYTES IMAGE_SCN_ALIGN_POWER_CONST (12)
91 #define IMAGE_SCN_ALIGN_8192BYTES IMAGE_SCN_ALIGN_POWER_CONST (13)
92
93 /* Encode alignment power into IMAGE_SCN_ALIGN bits of s_flags */
94 #define COFF_ENCODE_ALIGNMENT(SECTION, ALIGNMENT_POWER) \
95 ((SECTION).s_flags |= IMAGE_SCN_ALIGN_POWER_CONST ((ALIGNMENT_POWER)))
96
97 #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
98 #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
99 #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */
100 #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
101
102 /* COMDAT selection codes. */
103
104 #define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */
105 #define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */
106 #define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */
107 #define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */
108 #define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */
109
110 /* Machine numbers. */
111
112 #define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
113 #define IMAGE_FILE_MACHINE_ALPHA 0x0184
114 #define IMAGE_FILE_MACHINE_ALPHA64 0x0284
115 #define IMAGE_FILE_MACHINE_AM33 0x01d3
116 #define IMAGE_FILE_MACHINE_AMD64 0x8664
117 #define IMAGE_FILE_MACHINE_ARM 0x01c0
118 #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
119 #define IMAGE_FILE_MACHINE_CEE 0xc0ee
120 #define IMAGE_FILE_MACHINE_CEF 0x0cef
121 #define IMAGE_FILE_MACHINE_EBC 0x0ebc
122 #define IMAGE_FILE_MACHINE_I386 0x014c
123 #define IMAGE_FILE_MACHINE_IA64 0x0200
124 #define IMAGE_FILE_MACHINE_M32R 0x9041
125 #define IMAGE_FILE_MACHINE_M68K 0x0268
126 #define IMAGE_FILE_MACHINE_MIPS16 0x0266
127 #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
128 #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
129 #define IMAGE_FILE_MACHINE_POWERPC 0x01f0
130 #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
131 #define IMAGE_FILE_MACHINE_R10000 0x0168
132 #define IMAGE_FILE_MACHINE_R3000 0x0162
133 #define IMAGE_FILE_MACHINE_R4000 0x0166
134 #define IMAGE_FILE_MACHINE_SH3 0x01a2
135 #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
136 #define IMAGE_FILE_MACHINE_SH3E 0x01a4
137 #define IMAGE_FILE_MACHINE_SH4 0x01a6
138 #define IMAGE_FILE_MACHINE_SH5 0x01a8
139 #define IMAGE_FILE_MACHINE_THUMB 0x01c2
140 #define IMAGE_FILE_MACHINE_TRICORE 0x0520
141 #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
142 #define IMAGE_FILE_MACHINE_AMD64 0x8664
143
144 #define IMAGE_SUBSYSTEM_UNKNOWN 0
145 #define IMAGE_SUBSYSTEM_NATIVE 1
146 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
147 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
148 #define IMAGE_SUBSYSTEM_POSIX_CUI 7
149 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
150 #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
151 #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
152 #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
153 #define IMAGE_SUBSYSTEM_EFI_ROM 13
154 #define IMAGE_SUBSYSTEM_XBOX 14
155
156 /* Magic values that are true for all dos/nt implementations. */
157 #define DOSMAGIC 0x5a4d
158 #define NT_SIGNATURE 0x00004550
159
160 /* NT allows long filenames, we want to accommodate this.
161 This may break some of the bfd functions. */
162 #undef FILNMLEN
163 #define FILNMLEN 18 /* # characters in a file name. */
164
165 struct external_PEI_DOS_hdr
166 {
167 /* DOS header fields - always at offset zero in the EXE file. */
168 char e_magic[2]; /* Magic number, 0x5a4d. */
169 char e_cblp[2]; /* Bytes on last page of file, 0x90. */
170 char e_cp[2]; /* Pages in file, 0x3. */
171 char e_crlc[2]; /* Relocations, 0x0. */
172 char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
173 char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
174 char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
175 char e_ss[2]; /* Initial (relative) SS value, 0x0. */
176 char e_sp[2]; /* Initial SP value, 0xb8. */
177 char e_csum[2]; /* Checksum, 0x0. */
178 char e_ip[2]; /* Initial IP value, 0x0. */
179 char e_cs[2]; /* Initial (relative) CS value, 0x0. */
180 char e_lfarlc[2]; /* File address of relocation table, 0x40. */
181 char e_ovno[2]; /* Overlay number, 0x0. */
182 char e_res[4][2]; /* Reserved words, all 0x0. */
183 char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
184 char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
185 char e_res2[10][2]; /* Reserved words, all 0x0. */
186 char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
187 char dos_message[16][4]; /* Other stuff, always follow DOS header. */
188 };
189
190 struct external_PEI_IMAGE_hdr
191 {
192 char nt_signature[4]; /* required NT signature, 0x4550. */
193
194 /* From standard header. */
195 char f_magic[2]; /* Magic number. */
196 char f_nscns[2]; /* Number of sections. */
197 char f_timdat[4]; /* Time & date stamp. */
198 char f_symptr[4]; /* File pointer to symtab. */
199 char f_nsyms[4]; /* Number of symtab entries. */
200 char f_opthdr[2]; /* Sizeof(optional hdr). */
201 char f_flags[2]; /* Flags. */
202 };
203
204 struct external_PEI_filehdr
205 {
206 /* DOS header fields - always at offset zero in the EXE file. */
207 char e_magic[2]; /* Magic number, 0x5a4d. */
208 char e_cblp[2]; /* Bytes on last page of file, 0x90. */
209 char e_cp[2]; /* Pages in file, 0x3. */
210 char e_crlc[2]; /* Relocations, 0x0. */
211 char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
212 char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
213 char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
214 char e_ss[2]; /* Initial (relative) SS value, 0x0. */
215 char e_sp[2]; /* Initial SP value, 0xb8. */
216 char e_csum[2]; /* Checksum, 0x0. */
217 char e_ip[2]; /* Initial IP value, 0x0. */
218 char e_cs[2]; /* Initial (relative) CS value, 0x0. */
219 char e_lfarlc[2]; /* File address of relocation table, 0x40. */
220 char e_ovno[2]; /* Overlay number, 0x0. */
221 char e_res[4][2]; /* Reserved words, all 0x0. */
222 char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
223 char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
224 char e_res2[10][2]; /* Reserved words, all 0x0. */
225 char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
226 char dos_message[16][4]; /* Other stuff, always follow DOS header. */
227
228 /* Note: additional bytes may be inserted before the signature. Use
229 the e_lfanew field to find the actual location of the NT signature. */
230
231 char nt_signature[4]; /* required NT signature, 0x4550. */
232
233 /* From standard header. */
234 char f_magic[2]; /* Magic number. */
235 char f_nscns[2]; /* Number of sections. */
236 char f_timdat[4]; /* Time & date stamp. */
237 char f_symptr[4]; /* File pointer to symtab. */
238 char f_nsyms[4]; /* Number of symtab entries. */
239 char f_opthdr[2]; /* Sizeof(optional hdr). */
240 char f_flags[2]; /* Flags. */
241 };
242
243 #ifdef COFF_IMAGE_WITH_PE
244
245 /* The filehdr is only weird in images. */
246
247 #undef FILHDR
248 #define FILHDR struct external_PEI_filehdr
249 #undef FILHSZ
250 #define FILHSZ 152
251
252 #endif /* COFF_IMAGE_WITH_PE */
253
254 /* 32-bit PE a.out header: */
255
256 typedef struct
257 {
258 AOUTHDR standard;
259
260 /* NT extra fields; see internal.h for descriptions. */
261 char ImageBase[4];
262 char SectionAlignment[4];
263 char FileAlignment[4];
264 char MajorOperatingSystemVersion[2];
265 char MinorOperatingSystemVersion[2];
266 char MajorImageVersion[2];
267 char MinorImageVersion[2];
268 char MajorSubsystemVersion[2];
269 char MinorSubsystemVersion[2];
270 char Reserved1[4];
271 char SizeOfImage[4];
272 char SizeOfHeaders[4];
273 char CheckSum[4];
274 char Subsystem[2];
275 char DllCharacteristics[2];
276 char SizeOfStackReserve[4];
277 char SizeOfStackCommit[4];
278 char SizeOfHeapReserve[4];
279 char SizeOfHeapCommit[4];
280 char LoaderFlags[4];
281 char NumberOfRvaAndSizes[4];
282 /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
283 char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
284 } PEAOUTHDR;
285
286 #undef AOUTSZ
287 #define AOUTSZ (AOUTHDRSZ + 196)
288
289 /* Like PEAOUTHDR, except that the "standard" member has no BaseOfData
290 (aka data_start) member and that some of the members are 8 instead
291 of just 4 bytes long. */
292 typedef struct
293 {
294 #ifdef AOUTHDRSZ64
295 AOUTHDR64 standard;
296 #else
297 AOUTHDR standard;
298 #endif
299 /* NT extra fields; see internal.h for descriptions. */
300 char ImageBase[8];
301 char SectionAlignment[4];
302 char FileAlignment[4];
303 char MajorOperatingSystemVersion[2];
304 char MinorOperatingSystemVersion[2];
305 char MajorImageVersion[2];
306 char MinorImageVersion[2];
307 char MajorSubsystemVersion[2];
308 char MinorSubsystemVersion[2];
309 char Reserved1[4];
310 char SizeOfImage[4];
311 char SizeOfHeaders[4];
312 char CheckSum[4];
313 char Subsystem[2];
314 char DllCharacteristics[2];
315 char SizeOfStackReserve[8];
316 char SizeOfStackCommit[8];
317 char SizeOfHeapReserve[8];
318 char SizeOfHeapCommit[8];
319 char LoaderFlags[4];
320 char NumberOfRvaAndSizes[4];
321 /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
322 char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
323 } PEPAOUTHDR;
324
325 #ifdef AOUTHDRSZ64
326 #define PEPAOUTSZ (AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */
327 #else
328 #define PEPAOUTSZ 240
329 #endif
330
331 #undef E_FILNMLEN
332 #define E_FILNMLEN 18 /* # characters in a file name. */
333
334 /* Import Tyoes fot ILF format object files.. */
335 #define IMPORT_CODE 0
336 #define IMPORT_DATA 1
337 #define IMPORT_CONST 2
338
339 /* Import Name Tyoes for ILF format object files. */
340 #define IMPORT_ORDINAL 0
341 #define IMPORT_NAME 1
342 #define IMPORT_NAME_NOPREFIX 2
343 #define IMPORT_NAME_UNDECORATE 3
344
345 /* Weak external characteristics. */
346 #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
347 #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
348 #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
349
350 #endif /* _PE_H */
This page took 0.039433 seconds and 5 git commands to generate.