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