pe.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /* pe.h - PE COFF header information
  2. Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  15. #ifndef _PE_H
  16. #define _PE_H
  17. /* NT specific file attributes. */
  18. #define IMAGE_FILE_RELOCS_STRIPPED 0x0001
  19. #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
  20. #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
  21. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
  22. #define IMAGE_FILE_AGGRESSIVE_WS_TRIM 0x0010
  23. #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
  24. #define IMAGE_FILE_16BIT_MACHINE 0x0040
  25. #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
  26. #define IMAGE_FILE_32BIT_MACHINE 0x0100
  27. #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
  28. #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
  29. #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
  30. #define IMAGE_FILE_SYSTEM 0x1000
  31. #define IMAGE_FILE_DLL 0x2000
  32. #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
  33. #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
  34. /* DllCharacteristics flag bits. The inconsistent naming may seem
  35. odd, but that is how they are defined in the PE specification. */
  36. #define IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA 0x0020
  37. #define IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE 0x0040
  38. #define IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY 0x0080
  39. #define IMAGE_DLL_CHARACTERISTICS_NX_COMPAT 0x0100
  40. #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION 0x0200
  41. #define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
  42. #define IMAGE_DLLCHARACTERISTICS_NO_BIND 0x0800
  43. #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
  44. #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
  45. /* Additional flags to be set for section headers to allow the NT loader to
  46. read and write to the section data (to replace the addresses of data in
  47. dlls for one thing); also to execute the section in .text's case. */
  48. #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
  49. #define IMAGE_SCN_MEM_EXECUTE 0x20000000
  50. #define IMAGE_SCN_MEM_READ 0x40000000
  51. #define IMAGE_SCN_MEM_WRITE 0x80000000
  52. /* Section characteristics added for ppc-nt. */
  53. #define IMAGE_SCN_TYPE_NO_PAD 0x00000008 /* Reserved. */
  54. #define IMAGE_SCN_CNT_CODE 0x00000020 /* Section contains code. */
  55. #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 /* Section contains initialized data. */
  56. #define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 /* Section contains uninitialized data. */
  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. #define IMAGE_SCN_MEM_FARDATA 0x00008000
  62. #define IMAGE_SCN_MEM_PURGEABLE 0x00020000
  63. #define IMAGE_SCN_MEM_16BIT 0x00020000
  64. #define IMAGE_SCN_MEM_LOCKED 0x00040000
  65. #define IMAGE_SCN_MEM_PRELOAD 0x00080000
  66. /* Bit position in the s_flags field where the alignment values start. */
  67. #define IMAGE_SCN_ALIGN_POWER_BIT_POS 20
  68. #define IMAGE_SCN_ALIGN_POWER_BIT_MASK 0x00f00000
  69. #define IMAGE_SCN_ALIGN_POWER_NUM(val) \
  70. (((val) >> IMAGE_SCN_ALIGN_POWER_BIT_POS) - 1)
  71. #define IMAGE_SCN_ALIGN_POWER_CONST(val) \
  72. (((val) + 1) << IMAGE_SCN_ALIGN_POWER_BIT_POS)
  73. #define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_POWER_CONST (0)
  74. #define IMAGE_SCN_ALIGN_2BYTES IMAGE_SCN_ALIGN_POWER_CONST (1)
  75. #define IMAGE_SCN_ALIGN_4BYTES IMAGE_SCN_ALIGN_POWER_CONST (2)
  76. #define IMAGE_SCN_ALIGN_8BYTES IMAGE_SCN_ALIGN_POWER_CONST (3)
  77. /* Default alignment if no others are specified. */
  78. #define IMAGE_SCN_ALIGN_16BYTES IMAGE_SCN_ALIGN_POWER_CONST (4)
  79. #define IMAGE_SCN_ALIGN_32BYTES IMAGE_SCN_ALIGN_POWER_CONST (5)
  80. #define IMAGE_SCN_ALIGN_64BYTES IMAGE_SCN_ALIGN_POWER_CONST (6)
  81. #define IMAGE_SCN_ALIGN_128BYTES IMAGE_SCN_ALIGN_POWER_CONST (7)
  82. #define IMAGE_SCN_ALIGN_256BYTES IMAGE_SCN_ALIGN_POWER_CONST (8)
  83. #define IMAGE_SCN_ALIGN_512BYTES IMAGE_SCN_ALIGN_POWER_CONST (9)
  84. #define IMAGE_SCN_ALIGN_1024BYTES IMAGE_SCN_ALIGN_POWER_CONST (10)
  85. #define IMAGE_SCN_ALIGN_2048BYTES IMAGE_SCN_ALIGN_POWER_CONST (11)
  86. #define IMAGE_SCN_ALIGN_4096BYTES IMAGE_SCN_ALIGN_POWER_CONST (12)
  87. #define IMAGE_SCN_ALIGN_8192BYTES IMAGE_SCN_ALIGN_POWER_CONST (13)
  88. /* Encode alignment power into IMAGE_SCN_ALIGN bits of s_flags. */
  89. #define COFF_ENCODE_ALIGNMENT(SECTION, ALIGNMENT_POWER) \
  90. ((SECTION).s_flags |= IMAGE_SCN_ALIGN_POWER_CONST ((ALIGNMENT_POWER)))
  91. #define IMAGE_SCN_LNK_NRELOC_OVFL 0x01000000 /* Section contains extended relocations. */
  92. #define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 /* Section is not cachable. */
  93. #define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 /* Section is not pageable. */
  94. #define IMAGE_SCN_MEM_SHARED 0x10000000 /* Section is shareable. */
  95. /* COMDAT selection codes. */
  96. #define IMAGE_COMDAT_SELECT_NODUPLICATES (1) /* Warn if duplicates. */
  97. #define IMAGE_COMDAT_SELECT_ANY (2) /* No warning. */
  98. #define IMAGE_COMDAT_SELECT_SAME_SIZE (3) /* Warn if different size. */
  99. #define IMAGE_COMDAT_SELECT_EXACT_MATCH (4) /* Warn if different. */
  100. #define IMAGE_COMDAT_SELECT_ASSOCIATIVE (5) /* Base on other section. */
  101. /* Machine numbers. */
  102. #define IMAGE_FILE_MACHINE_UNKNOWN 0x0000
  103. #define IMAGE_FILE_MACHINE_ALPHA 0x0184
  104. #define IMAGE_FILE_MACHINE_ALPHA64 0x0284
  105. #define IMAGE_FILE_MACHINE_AM33 0x01d3
  106. #define IMAGE_FILE_MACHINE_AMD64 0x8664
  107. #define IMAGE_FILE_MACHINE_ARM 0x01c0
  108. #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
  109. #define IMAGE_FILE_MACHINE_CEE 0xc0ee
  110. #define IMAGE_FILE_MACHINE_CEF 0x0cef
  111. #define IMAGE_FILE_MACHINE_EBC 0x0ebc
  112. #define IMAGE_FILE_MACHINE_I386 0x014c
  113. #define IMAGE_FILE_MACHINE_IA64 0x0200
  114. #define IMAGE_FILE_MACHINE_M32R 0x9041
  115. #define IMAGE_FILE_MACHINE_M68K 0x0268
  116. #define IMAGE_FILE_MACHINE_MIPS16 0x0266
  117. #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
  118. #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
  119. #define IMAGE_FILE_MACHINE_POWERPC 0x01f0
  120. #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
  121. #define IMAGE_FILE_MACHINE_R10000 0x0168
  122. #define IMAGE_FILE_MACHINE_R3000 0x0162
  123. #define IMAGE_FILE_MACHINE_R4000 0x0166
  124. #define IMAGE_FILE_MACHINE_SH3 0x01a2
  125. #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
  126. #define IMAGE_FILE_MACHINE_SH3E 0x01a4
  127. #define IMAGE_FILE_MACHINE_SH4 0x01a6
  128. #define IMAGE_FILE_MACHINE_SH5 0x01a8
  129. #define IMAGE_FILE_MACHINE_THUMB 0x01c2
  130. #define IMAGE_FILE_MACHINE_TRICORE 0x0520
  131. #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
  132. #define IMAGE_FILE_MACHINE_AMD64 0x8664
  133. #define IMAGE_SUBSYSTEM_UNKNOWN 0
  134. #define IMAGE_SUBSYSTEM_NATIVE 1
  135. #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
  136. #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
  137. #define IMAGE_SUBSYSTEM_POSIX_CUI 7
  138. #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
  139. #define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
  140. #define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
  141. #define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
  142. #define IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
  143. #define IMAGE_SUBSYSTEM_XBOX 14
  144. /* Magic values that are true for all dos/nt implementations. */
  145. #define DOSMAGIC 0x5a4d
  146. #define NT_SIGNATURE 0x00004550
  147. /* NT allows long filenames, we want to accommodate this.
  148. This may break some of the bfd functions. */
  149. #undef FILNMLEN
  150. #define FILNMLEN 18 /* # characters in a file name. */
  151. struct external_PEI_DOS_hdr
  152. {
  153. /* DOS header fields - always at offset zero in the EXE file. */
  154. char e_magic[2]; /* Magic number, 0x5a4d. */
  155. char e_cblp[2]; /* Bytes on last page of file, 0x90. */
  156. char e_cp[2]; /* Pages in file, 0x3. */
  157. char e_crlc[2]; /* Relocations, 0x0. */
  158. char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
  159. char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
  160. char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
  161. char e_ss[2]; /* Initial (relative) SS value, 0x0. */
  162. char e_sp[2]; /* Initial SP value, 0xb8. */
  163. char e_csum[2]; /* Checksum, 0x0. */
  164. char e_ip[2]; /* Initial IP value, 0x0. */
  165. char e_cs[2]; /* Initial (relative) CS value, 0x0. */
  166. char e_lfarlc[2]; /* File address of relocation table, 0x40. */
  167. char e_ovno[2]; /* Overlay number, 0x0. */
  168. char e_res[4][2]; /* Reserved words, all 0x0. */
  169. char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
  170. char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
  171. char e_res2[10][2]; /* Reserved words, all 0x0. */
  172. char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
  173. char dos_message[16][4]; /* Other stuff, always follow DOS header. */
  174. };
  175. struct external_PEI_IMAGE_hdr
  176. {
  177. char nt_signature[4]; /* Required NT signature, 0x4550. */
  178. /* From standard header. */
  179. char f_magic[2]; /* Magic number. */
  180. char f_nscns[2]; /* Number of sections. */
  181. char f_timdat[4]; /* Time & date stamp. */
  182. char f_symptr[4]; /* File pointer to symtab. */
  183. char f_nsyms[4]; /* Number of symtab entries. */
  184. char f_opthdr[2]; /* Sizeof(optional hdr). */
  185. char f_flags[2]; /* Flags. */
  186. };
  187. struct external_PEI_filehdr
  188. {
  189. /* DOS header fields - always at offset zero in the EXE file. */
  190. char e_magic[2]; /* Magic number, 0x5a4d. */
  191. char e_cblp[2]; /* Bytes on last page of file, 0x90. */
  192. char e_cp[2]; /* Pages in file, 0x3. */
  193. char e_crlc[2]; /* Relocations, 0x0. */
  194. char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
  195. char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
  196. char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
  197. char e_ss[2]; /* Initial (relative) SS value, 0x0. */
  198. char e_sp[2]; /* Initial SP value, 0xb8. */
  199. char e_csum[2]; /* Checksum, 0x0. */
  200. char e_ip[2]; /* Initial IP value, 0x0. */
  201. char e_cs[2]; /* Initial (relative) CS value, 0x0. */
  202. char e_lfarlc[2]; /* File address of relocation table, 0x40. */
  203. char e_ovno[2]; /* Overlay number, 0x0. */
  204. char e_res[4][2]; /* Reserved words, all 0x0. */
  205. char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
  206. char e_oeminfo[2]; /* OEM information; e_oemid specific, 0x0. */
  207. char e_res2[10][2]; /* Reserved words, all 0x0. */
  208. char e_lfanew[4]; /* File address of new exe header, usually 0x80. */
  209. char dos_message[16][4]; /* Other stuff, always follow DOS header. */
  210. /* Note: additional bytes may be inserted before the signature. Use
  211. the e_lfanew field to find the actual location of the NT signature. */
  212. char nt_signature[4]; /* Required NT signature, 0x4550. */
  213. /* From standard header. */
  214. char f_magic[2]; /* Magic number. */
  215. char f_nscns[2]; /* Number of sections. */
  216. char f_timdat[4]; /* Time & date stamp. */
  217. char f_symptr[4]; /* File pointer to symtab. */
  218. char f_nsyms[4]; /* Number of symtab entries. */
  219. char f_opthdr[2]; /* Sizeof(optional hdr). */
  220. char f_flags[2]; /* Flags. */
  221. };
  222. #ifdef COFF_IMAGE_WITH_PE
  223. /* The filehdr is only weird in images. */
  224. #undef FILHDR
  225. #define FILHDR struct external_PEI_filehdr
  226. #undef FILHSZ
  227. #define FILHSZ 152
  228. #endif /* COFF_IMAGE_WITH_PE */
  229. /* 32-bit PE a.out header: */
  230. typedef struct
  231. {
  232. AOUTHDR standard;
  233. /* NT extra fields; see internal.h for descriptions. */
  234. char ImageBase[4];
  235. char SectionAlignment[4];
  236. char FileAlignment[4];
  237. char MajorOperatingSystemVersion[2];
  238. char MinorOperatingSystemVersion[2];
  239. char MajorImageVersion[2];
  240. char MinorImageVersion[2];
  241. char MajorSubsystemVersion[2];
  242. char MinorSubsystemVersion[2];
  243. char Reserved1[4];
  244. char SizeOfImage[4];
  245. char SizeOfHeaders[4];
  246. char CheckSum[4];
  247. char Subsystem[2];
  248. char DllCharacteristics[2];
  249. char SizeOfStackReserve[4];
  250. char SizeOfStackCommit[4];
  251. char SizeOfHeapReserve[4];
  252. char SizeOfHeapCommit[4];
  253. char LoaderFlags[4];
  254. char NumberOfRvaAndSizes[4];
  255. /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
  256. char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
  257. } PEAOUTHDR;
  258. #undef AOUTSZ
  259. #define AOUTSZ (AOUTHDRSZ + 196)
  260. /* Like PEAOUTHDR, except that the "standard" member has no BaseOfData
  261. (aka data_start) member and that some of the members are 8 instead
  262. of just 4 bytes long. */
  263. typedef struct
  264. {
  265. #ifdef AOUTHDRSZ64
  266. AOUTHDR64 standard;
  267. #else
  268. AOUTHDR standard;
  269. #endif
  270. /* NT extra fields; see internal.h for descriptions. */
  271. char ImageBase[8];
  272. char SectionAlignment[4];
  273. char FileAlignment[4];
  274. char MajorOperatingSystemVersion[2];
  275. char MinorOperatingSystemVersion[2];
  276. char MajorImageVersion[2];
  277. char MinorImageVersion[2];
  278. char MajorSubsystemVersion[2];
  279. char MinorSubsystemVersion[2];
  280. char Reserved1[4];
  281. char SizeOfImage[4];
  282. char SizeOfHeaders[4];
  283. char CheckSum[4];
  284. char Subsystem[2];
  285. char DllCharacteristics[2];
  286. char SizeOfStackReserve[8];
  287. char SizeOfStackCommit[8];
  288. char SizeOfHeapReserve[8];
  289. char SizeOfHeapCommit[8];
  290. char LoaderFlags[4];
  291. char NumberOfRvaAndSizes[4];
  292. /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
  293. char DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars. */
  294. } PEPAOUTHDR;
  295. #ifdef AOUTHDRSZ64
  296. #define PEPAOUTSZ (AOUTHDRSZ64 + 196 + 5 * 4) /* = 240 */
  297. #else
  298. #define PEPAOUTSZ 240
  299. #endif
  300. #undef E_FILNMLEN
  301. #define E_FILNMLEN 18 /* # characters in a file name. */
  302. /* Import Tyoes fot ILF format object files.. */
  303. #define IMPORT_CODE 0
  304. #define IMPORT_DATA 1
  305. #define IMPORT_CONST 2
  306. /* Import Name Tyoes for ILF format object files. */
  307. #define IMPORT_ORDINAL 0
  308. #define IMPORT_NAME 1
  309. #define IMPORT_NAME_NOPREFIX 2
  310. #define IMPORT_NAME_UNDECORATE 3
  311. /* Weak external characteristics. */
  312. #define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY 1
  313. #define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY 2
  314. #define IMAGE_WEAK_EXTERN_SEARCH_ALIAS 3
  315. /* Bigobj header. */
  316. struct external_ANON_OBJECT_HEADER_BIGOBJ
  317. {
  318. /* ANON_OBJECT_HEADER_V2 header. */
  319. char Sig1[2];
  320. char Sig2[2];
  321. char Version[2];
  322. char Machine[2];
  323. char TimeDateStamp[4];
  324. char ClassID[16];
  325. char SizeOfData[4];
  326. char Flags[4];
  327. char MetaDataSize[4];
  328. char MetaDataOffset[4];
  329. /* BIGOBJ specific. */
  330. char NumberOfSections[4];
  331. char PointerToSymbolTable[4];
  332. char NumberOfSymbols[4];
  333. };
  334. #define FILHSZ_BIGOBJ (14 * 4)
  335. struct external_SYMBOL_EX
  336. {
  337. union
  338. {
  339. char e_name[E_SYMNMLEN];
  340. struct
  341. {
  342. char e_zeroes[4];
  343. char e_offset[4];
  344. } e;
  345. } e;
  346. char e_value[4];
  347. char e_scnum[4];
  348. char e_type[2];
  349. char e_sclass[1];
  350. char e_numaux[1];
  351. } ATTRIBUTE_PACKED ;
  352. #define SYMENT_BIGOBJ struct external_SYMBOL_EX
  353. #define SYMESZ_BIGOBJ 20
  354. #define FILNMLEN_BIGOBJ 20
  355. union external_AUX_SYMBOL_EX
  356. {
  357. struct
  358. {
  359. char WeakDefaultSymIndex[4];
  360. char WeakSearchType[4];
  361. char rgbReserved[12];
  362. } Sym;
  363. struct
  364. {
  365. char Name[FILNMLEN_BIGOBJ];
  366. } File;
  367. struct
  368. {
  369. char Length[4]; /* Section length. */
  370. char NumberOfRelocations[2];/* # relocation entries. */
  371. char NumberOfLinenumbers[2];/* # line numbers. */
  372. char Checksum[4]; /* Section COMDAT checksum. */
  373. char Number[2]; /* COMDAT associated section index. */
  374. char Selection[1]; /* COMDAT selection number. */
  375. char bReserved[1];
  376. char HighNumber[2]; /* High bits of COMDAT associated sec. */
  377. char rgbReserved[2];
  378. } Section;
  379. } ATTRIBUTE_PACKED;
  380. #define AUXENT_BIGOBJ union external_AUX_SYMBOL_EX
  381. #define AUXESZ_BIGOBJ 20
  382. /* .pdata/.xdata defines and structures for x64 PE+ for exception handling. */
  383. /* .pdata in exception directory. */
  384. struct pex64_runtime_function
  385. {
  386. bfd_vma rva_BeginAddress;
  387. bfd_vma rva_EndAddress;
  388. bfd_vma rva_UnwindData;
  389. };
  390. struct external_pex64_runtime_function
  391. {
  392. bfd_byte rva_BeginAddress[4];
  393. bfd_byte rva_EndAddress[4];
  394. bfd_byte rva_UnwindData[4];
  395. };
  396. /* If the lowest significant bit is set for rva_UnwindData RVA, it
  397. means that the unified RVA points to another pex64_runtime_function
  398. that this entry shares the unwind_info block with. */
  399. #define PEX64_IS_RUNTIME_FUNCTION_CHAINED(PTR_RTF) \
  400. (((PTR_RTF)->rva_UnwindData & 1) != 0)
  401. #define PEX64_GET_UNWINDDATA_UNIFIED_RVA(PTR_RTF) \
  402. ((PTR_RTF)->rva_UnwindData & ~1)
  403. /* The unwind codes. */
  404. #define UWOP_PUSH_NONVOL 0
  405. #define UWOP_ALLOC_LARGE 1
  406. #define UWOP_ALLOC_SMALL 2
  407. #define UWOP_SET_FPREG 3
  408. #define UWOP_SAVE_NONVOL 4
  409. #define UWOP_SAVE_NONVOL_FAR 5
  410. #define UWOP_SAVE_XMM 6 /* For version 1. */
  411. #define UWOP_EPILOG 6 /* For version 2. */
  412. #define UWOP_SAVE_XMM_FAR 7 /* For version 1 (deprecated). */
  413. #define UWOP_SPARE 7 /* For version 2. */
  414. #define UWOP_SAVE_XMM128 8
  415. #define UWOP_SAVE_XMM128_FAR 9
  416. #define UWOP_PUSH_MACHFRAME 10
  417. struct pex64_unwind_code
  418. {
  419. bfd_vma prologue_offset;
  420. /* Contains Frame offset, or frame allocation size. */
  421. bfd_vma frame_addr;
  422. unsigned int uwop_code : 4;
  423. /* xmm, mm, or standard register from 0 - 15. */
  424. unsigned int reg : 4;
  425. /* Used for UWOP_PUSH_MACHFRAME to indicate optional errorcode stack
  426. argument. */
  427. unsigned int has_errorcode : 1;
  428. };
  429. struct external_pex64_unwind_code
  430. {
  431. bfd_byte dta[2];
  432. };
  433. #define PEX64_UNWCODE_CODE(VAL) ((VAL) & 0xf)
  434. #define PEX64_UNWCODE_INFO(VAL) (((VAL) >> 4) & 0xf)
  435. /* The unwind info. */
  436. #define UNW_FLAG_NHANDLER 0
  437. #define UNW_FLAG_EHANDLER 1
  438. #define UNW_FLAG_UHANDLER 2
  439. #define UNW_FLAG_FHANDLER 3
  440. #define UNW_FLAG_CHAININFO 4
  441. #define UNW_FLAG_MASK 0x1f
  442. struct pex64_unwind_info
  443. {
  444. bfd_vma SizeOfBlock;
  445. bfd_byte Version; /* Values from 0 up to 7 are possible. */
  446. bfd_byte Flags; /* Values from 0 up to 31 are possible. */
  447. bfd_vma SizeOfPrologue;
  448. bfd_vma CountOfCodes; /* Amount of pex64_unwind_code elements. */
  449. /* 0 = CFA, 1..15 are index of integer registers. */
  450. unsigned int FrameRegister : 4;
  451. bfd_vma FrameOffset;
  452. bfd_vma sizeofUnwindCodes;
  453. bfd_byte *rawUnwindCodes;
  454. bfd_vma rva_ExceptionHandler; /* UNW_EHANDLER or UNW_FLAG_UHANDLER. */
  455. bfd_vma rva_BeginAddress; /* UNW_FLAG_CHAININFO. */
  456. bfd_vma rva_EndAddress; /* UNW_FLAG_CHAININFO. */
  457. bfd_vma rva_UnwindData; /* UNW_FLAG_CHAININFO. */
  458. };
  459. struct external_pex64_unwind_info
  460. {
  461. bfd_byte Version_Flags;
  462. bfd_byte SizeOfPrologue;
  463. bfd_byte CountOfCodes;
  464. bfd_byte FrameRegisterOffset;
  465. /* external_pex64_unwind_code array. */
  466. /* bfd_byte handler[4]; */
  467. /* Optional language specific data. */
  468. };
  469. struct external_pex64_scope
  470. {
  471. bfd_vma Count;
  472. };
  473. struct pex64_scope
  474. {
  475. bfd_byte Count[4];
  476. };
  477. struct pex64_scope_entry
  478. {
  479. bfd_vma rva_BeginAddress;
  480. bfd_vma rva_EndAddress;
  481. bfd_vma rva_HandlerAddress;
  482. bfd_vma rva_JumpAddress;
  483. };
  484. #define PEX64_SCOPE_ENTRY_SIZE 16
  485. struct external_pex64_scope_entry
  486. {
  487. bfd_byte rva_BeginAddress[4];
  488. bfd_byte rva_EndAddress[4];
  489. bfd_byte rva_HandlerAddress[4];
  490. bfd_byte rva_JumpAddress[4];
  491. };
  492. #define PEX64_UWI_VERSION(VAL) ((VAL) & 7)
  493. #define PEX64_UWI_FLAGS(VAL) (((VAL) >> 3) & 0x1f)
  494. #define PEX64_UWI_FRAMEREG(VAL) ((VAL) & 0xf)
  495. #define PEX64_UWI_FRAMEOFF(VAL) (((VAL) >> 4) & 0xf)
  496. #define PEX64_UWI_SIZEOF_UWCODE_ARRAY(VAL) \
  497. ((((VAL) + 1) & ~1) * 2)
  498. #define PEX64_OFFSET_TO_UNWIND_CODE 0x4
  499. #define PEX64_OFFSET_TO_HANDLER_RVA (COUNTOFUNWINDCODES) \
  500. (PEX64_OFFSET_TO_UNWIND_CODE + \
  501. PEX64_UWI_SIZEOF_UWCODE_ARRAY(COUNTOFUNWINDCODES))
  502. #define PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) \
  503. (PEX64_OFFSET_TO_HANDLER_RVA(COUNTOFUNWINDCODES) + 4)
  504. #define PEX64_SCOPE_ENTRY(COUNTOFUNWINDCODES, IDX) \
  505. (PEX64_OFFSET_TO_SCOPE_COUNT(COUNTOFUNWINDCODES) + \
  506. PEX64_SCOPE_ENTRY_SIZE * (IDX))
  507. /* Extra structure used in debug directory. */
  508. struct external_IMAGE_DEBUG_DIRECTORY
  509. {
  510. char Characteristics[4];
  511. char TimeDateStamp[4];
  512. char MajorVersion[2];
  513. char MinorVersion[2];
  514. char Type[4];
  515. char SizeOfData[4];
  516. char AddressOfRawData[4];
  517. char PointerToRawData[4];
  518. };
  519. /* Extra structures used in codeview debug record. */
  520. /* This is not part of the PE specification. */
  521. #define CVINFO_PDB70_CVSIGNATURE 0x53445352 // "RSDS"
  522. #define CVINFO_PDB20_CVSIGNATURE 0x3031424e // "NB10"
  523. #define CVINFO_CV50_CVSIGNATURE 0x3131424e // "NB11"
  524. #define CVINFO_CV41_CVSIGNATURE 0x3930424e // âNB09"
  525. typedef struct _CV_INFO_PDB70
  526. {
  527. char CvSignature[4];
  528. char Signature[16];
  529. char Age[4];
  530. char PdbFileName[];
  531. } CV_INFO_PDB70;
  532. typedef struct _CV_INFO_PDB20
  533. {
  534. char CvHeader[4];
  535. char Offset[4];
  536. char Signature[4];
  537. char Age[4];
  538. char PdbFileName[];
  539. } CV_INFO_PDB20;
  540. #endif /* _PE_H */