LLVM API Documentation
00001 //===-- llvm/Support/COFF.h -------------------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains an definitions used in Windows COFF Files. 00011 // 00012 // Structures and enums defined within this file where created using 00013 // information from Microsoft's publicly available PE/COFF format document: 00014 // 00015 // Microsoft Portable Executable and Common Object File Format Specification 00016 // Revision 8.1 - February 15, 2008 00017 // 00018 // As of 5/2/2010, hosted by Microsoft at: 00019 // http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx 00020 // 00021 //===----------------------------------------------------------------------===// 00022 00023 #ifndef LLVM_SUPPORT_COFF_H 00024 #define LLVM_SUPPORT_COFF_H 00025 00026 #include "llvm/Support/DataTypes.h" 00027 #include <cassert> 00028 #include <cstring> 00029 00030 namespace llvm { 00031 namespace COFF { 00032 00033 // Sizes in bytes of various things in the COFF format. 00034 enum { 00035 HeaderSize = 20, 00036 NameSize = 8, 00037 SymbolSize = 18, 00038 SectionSize = 40, 00039 RelocationSize = 10 00040 }; 00041 00042 struct header { 00043 uint16_t Machine; 00044 uint16_t NumberOfSections; 00045 uint32_t TimeDateStamp; 00046 uint32_t PointerToSymbolTable; 00047 uint32_t NumberOfSymbols; 00048 uint16_t SizeOfOptionalHeader; 00049 uint16_t Characteristics; 00050 }; 00051 00052 enum MachineTypes { 00053 MT_Invalid = 0xffff, 00054 00055 IMAGE_FILE_MACHINE_UNKNOWN = 0x0, 00056 IMAGE_FILE_MACHINE_AM33 = 0x13, 00057 IMAGE_FILE_MACHINE_AMD64 = 0x8664, 00058 IMAGE_FILE_MACHINE_ARM = 0x1C0, 00059 IMAGE_FILE_MACHINE_ARMV7 = 0x1C4, 00060 IMAGE_FILE_MACHINE_EBC = 0xEBC, 00061 IMAGE_FILE_MACHINE_I386 = 0x14C, 00062 IMAGE_FILE_MACHINE_IA64 = 0x200, 00063 IMAGE_FILE_MACHINE_M32R = 0x9041, 00064 IMAGE_FILE_MACHINE_MIPS16 = 0x266, 00065 IMAGE_FILE_MACHINE_MIPSFPU = 0x366, 00066 IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466, 00067 IMAGE_FILE_MACHINE_POWERPC = 0x1F0, 00068 IMAGE_FILE_MACHINE_POWERPCFP = 0x1F1, 00069 IMAGE_FILE_MACHINE_R4000 = 0x166, 00070 IMAGE_FILE_MACHINE_SH3 = 0x1A2, 00071 IMAGE_FILE_MACHINE_SH3DSP = 0x1A3, 00072 IMAGE_FILE_MACHINE_SH4 = 0x1A6, 00073 IMAGE_FILE_MACHINE_SH5 = 0x1A8, 00074 IMAGE_FILE_MACHINE_THUMB = 0x1C2, 00075 IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169 00076 }; 00077 00078 enum Characteristics { 00079 C_Invalid = 0, 00080 00081 /// The file does not contain base relocations and must be loaded at its 00082 /// preferred base. If this cannot be done, the loader will error. 00083 IMAGE_FILE_RELOCS_STRIPPED = 0x0001, 00084 /// The file is valid and can be run. 00085 IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002, 00086 /// COFF line numbers have been stripped. This is deprecated and should be 00087 /// 0. 00088 IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004, 00089 /// COFF symbol table entries for local symbols have been removed. This is 00090 /// deprecated and should be 0. 00091 IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008, 00092 /// Aggressively trim working set. This is deprecated and must be 0. 00093 IMAGE_FILE_AGGRESSIVE_WS_TRIM = 0x0010, 00094 /// Image can handle > 2GiB addresses. 00095 IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020, 00096 /// Little endian: the LSB precedes the MSB in memory. This is deprecated 00097 /// and should be 0. 00098 IMAGE_FILE_BYTES_REVERSED_LO = 0x0080, 00099 /// Machine is based on a 32bit word architecture. 00100 IMAGE_FILE_32BIT_MACHINE = 0x0100, 00101 /// Debugging info has been removed. 00102 IMAGE_FILE_DEBUG_STRIPPED = 0x0200, 00103 /// If the image is on removable media, fully load it and copy it to swap. 00104 IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400, 00105 /// If the image is on network media, fully load it and copy it to swap. 00106 IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800, 00107 /// The image file is a system file, not a user program. 00108 IMAGE_FILE_SYSTEM = 0x1000, 00109 /// The image file is a DLL. 00110 IMAGE_FILE_DLL = 0x2000, 00111 /// This file should only be run on a uniprocessor machine. 00112 IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000, 00113 /// Big endian: the MSB precedes the LSB in memory. This is deprecated 00114 /// and should be 0. 00115 IMAGE_FILE_BYTES_REVERSED_HI = 0x8000 00116 }; 00117 00118 struct symbol { 00119 char Name[NameSize]; 00120 uint32_t Value; 00121 uint16_t SectionNumber; 00122 uint16_t Type; 00123 uint8_t StorageClass; 00124 uint8_t NumberOfAuxSymbols; 00125 }; 00126 00127 enum SymbolFlags { 00128 SF_TypeMask = 0x0000FFFF, 00129 SF_TypeShift = 0, 00130 00131 SF_ClassMask = 0x00FF0000, 00132 SF_ClassShift = 16, 00133 00134 SF_WeakExternal = 0x01000000 00135 }; 00136 00137 enum SymbolSectionNumber { 00138 IMAGE_SYM_DEBUG = -2, 00139 IMAGE_SYM_ABSOLUTE = -1, 00140 IMAGE_SYM_UNDEFINED = 0 00141 }; 00142 00143 /// Storage class tells where and what the symbol represents 00144 enum SymbolStorageClass { 00145 SSC_Invalid = 0xff, 00146 00147 IMAGE_SYM_CLASS_END_OF_FUNCTION = -1, ///< Physical end of function 00148 IMAGE_SYM_CLASS_NULL = 0, ///< No symbol 00149 IMAGE_SYM_CLASS_AUTOMATIC = 1, ///< Stack variable 00150 IMAGE_SYM_CLASS_EXTERNAL = 2, ///< External symbol 00151 IMAGE_SYM_CLASS_STATIC = 3, ///< Static 00152 IMAGE_SYM_CLASS_REGISTER = 4, ///< Register variable 00153 IMAGE_SYM_CLASS_EXTERNAL_DEF = 5, ///< External definition 00154 IMAGE_SYM_CLASS_LABEL = 6, ///< Label 00155 IMAGE_SYM_CLASS_UNDEFINED_LABEL = 7, ///< Undefined label 00156 IMAGE_SYM_CLASS_MEMBER_OF_STRUCT = 8, ///< Member of structure 00157 IMAGE_SYM_CLASS_ARGUMENT = 9, ///< Function argument 00158 IMAGE_SYM_CLASS_STRUCT_TAG = 10, ///< Structure tag 00159 IMAGE_SYM_CLASS_MEMBER_OF_UNION = 11, ///< Member of union 00160 IMAGE_SYM_CLASS_UNION_TAG = 12, ///< Union tag 00161 IMAGE_SYM_CLASS_TYPE_DEFINITION = 13, ///< Type definition 00162 IMAGE_SYM_CLASS_UNDEFINED_STATIC = 14, ///< Undefined static 00163 IMAGE_SYM_CLASS_ENUM_TAG = 15, ///< Enumeration tag 00164 IMAGE_SYM_CLASS_MEMBER_OF_ENUM = 16, ///< Member of enumeration 00165 IMAGE_SYM_CLASS_REGISTER_PARAM = 17, ///< Register parameter 00166 IMAGE_SYM_CLASS_BIT_FIELD = 18, ///< Bit field 00167 /// ".bb" or ".eb" - beginning or end of block 00168 IMAGE_SYM_CLASS_BLOCK = 100, 00169 /// ".bf" or ".ef" - beginning or end of function 00170 IMAGE_SYM_CLASS_FUNCTION = 101, 00171 IMAGE_SYM_CLASS_END_OF_STRUCT = 102, ///< End of structure 00172 IMAGE_SYM_CLASS_FILE = 103, ///< File name 00173 /// Line number, reformatted as symbol 00174 IMAGE_SYM_CLASS_SECTION = 104, 00175 IMAGE_SYM_CLASS_WEAK_EXTERNAL = 105, ///< Duplicate tag 00176 /// External symbol in dmert public lib 00177 IMAGE_SYM_CLASS_CLR_TOKEN = 107 00178 }; 00179 00180 enum SymbolBaseType { 00181 IMAGE_SYM_TYPE_NULL = 0, ///< No type information or unknown base type. 00182 IMAGE_SYM_TYPE_VOID = 1, ///< Used with void pointers and functions. 00183 IMAGE_SYM_TYPE_CHAR = 2, ///< A character (signed byte). 00184 IMAGE_SYM_TYPE_SHORT = 3, ///< A 2-byte signed integer. 00185 IMAGE_SYM_TYPE_INT = 4, ///< A natural integer type on the target. 00186 IMAGE_SYM_TYPE_LONG = 5, ///< A 4-byte signed integer. 00187 IMAGE_SYM_TYPE_FLOAT = 6, ///< A 4-byte floating-point number. 00188 IMAGE_SYM_TYPE_DOUBLE = 7, ///< An 8-byte floating-point number. 00189 IMAGE_SYM_TYPE_STRUCT = 8, ///< A structure. 00190 IMAGE_SYM_TYPE_UNION = 9, ///< An union. 00191 IMAGE_SYM_TYPE_ENUM = 10, ///< An enumerated type. 00192 IMAGE_SYM_TYPE_MOE = 11, ///< A member of enumeration (a specific value). 00193 IMAGE_SYM_TYPE_BYTE = 12, ///< A byte; unsigned 1-byte integer. 00194 IMAGE_SYM_TYPE_WORD = 13, ///< A word; unsigned 2-byte integer. 00195 IMAGE_SYM_TYPE_UINT = 14, ///< An unsigned integer of natural size. 00196 IMAGE_SYM_TYPE_DWORD = 15 ///< An unsigned 4-byte integer. 00197 }; 00198 00199 enum SymbolComplexType { 00200 IMAGE_SYM_DTYPE_NULL = 0, ///< No complex type; simple scalar variable. 00201 IMAGE_SYM_DTYPE_POINTER = 1, ///< A pointer to base type. 00202 IMAGE_SYM_DTYPE_FUNCTION = 2, ///< A function that returns a base type. 00203 IMAGE_SYM_DTYPE_ARRAY = 3, ///< An array of base type. 00204 00205 /// Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT)) 00206 SCT_COMPLEX_TYPE_SHIFT = 4 00207 }; 00208 00209 struct section { 00210 char Name[NameSize]; 00211 uint32_t VirtualSize; 00212 uint32_t VirtualAddress; 00213 uint32_t SizeOfRawData; 00214 uint32_t PointerToRawData; 00215 uint32_t PointerToRelocations; 00216 uint32_t PointerToLineNumbers; 00217 uint16_t NumberOfRelocations; 00218 uint16_t NumberOfLineNumbers; 00219 uint32_t Characteristics; 00220 }; 00221 00222 enum SectionCharacteristics { 00223 SC_Invalid = 0xffffffff, 00224 00225 IMAGE_SCN_TYPE_NO_PAD = 0x00000008, 00226 IMAGE_SCN_CNT_CODE = 0x00000020, 00227 IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040, 00228 IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080, 00229 IMAGE_SCN_LNK_OTHER = 0x00000100, 00230 IMAGE_SCN_LNK_INFO = 0x00000200, 00231 IMAGE_SCN_LNK_REMOVE = 0x00000800, 00232 IMAGE_SCN_LNK_COMDAT = 0x00001000, 00233 IMAGE_SCN_GPREL = 0x00008000, 00234 IMAGE_SCN_MEM_PURGEABLE = 0x00020000, 00235 IMAGE_SCN_MEM_16BIT = 0x00020000, 00236 IMAGE_SCN_MEM_LOCKED = 0x00040000, 00237 IMAGE_SCN_MEM_PRELOAD = 0x00080000, 00238 IMAGE_SCN_ALIGN_1BYTES = 0x00100000, 00239 IMAGE_SCN_ALIGN_2BYTES = 0x00200000, 00240 IMAGE_SCN_ALIGN_4BYTES = 0x00300000, 00241 IMAGE_SCN_ALIGN_8BYTES = 0x00400000, 00242 IMAGE_SCN_ALIGN_16BYTES = 0x00500000, 00243 IMAGE_SCN_ALIGN_32BYTES = 0x00600000, 00244 IMAGE_SCN_ALIGN_64BYTES = 0x00700000, 00245 IMAGE_SCN_ALIGN_128BYTES = 0x00800000, 00246 IMAGE_SCN_ALIGN_256BYTES = 0x00900000, 00247 IMAGE_SCN_ALIGN_512BYTES = 0x00A00000, 00248 IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000, 00249 IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000, 00250 IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000, 00251 IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000, 00252 IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000, 00253 IMAGE_SCN_MEM_DISCARDABLE = 0x02000000, 00254 IMAGE_SCN_MEM_NOT_CACHED = 0x04000000, 00255 IMAGE_SCN_MEM_NOT_PAGED = 0x08000000, 00256 IMAGE_SCN_MEM_SHARED = 0x10000000, 00257 IMAGE_SCN_MEM_EXECUTE = 0x20000000, 00258 IMAGE_SCN_MEM_READ = 0x40000000, 00259 IMAGE_SCN_MEM_WRITE = 0x80000000 00260 }; 00261 00262 struct relocation { 00263 uint32_t VirtualAddress; 00264 uint32_t SymbolTableIndex; 00265 uint16_t Type; 00266 }; 00267 00268 enum RelocationTypeX86 { 00269 IMAGE_REL_I386_ABSOLUTE = 0x0000, 00270 IMAGE_REL_I386_DIR16 = 0x0001, 00271 IMAGE_REL_I386_REL16 = 0x0002, 00272 IMAGE_REL_I386_DIR32 = 0x0006, 00273 IMAGE_REL_I386_DIR32NB = 0x0007, 00274 IMAGE_REL_I386_SEG12 = 0x0009, 00275 IMAGE_REL_I386_SECTION = 0x000A, 00276 IMAGE_REL_I386_SECREL = 0x000B, 00277 IMAGE_REL_I386_TOKEN = 0x000C, 00278 IMAGE_REL_I386_SECREL7 = 0x000D, 00279 IMAGE_REL_I386_REL32 = 0x0014, 00280 00281 IMAGE_REL_AMD64_ABSOLUTE = 0x0000, 00282 IMAGE_REL_AMD64_ADDR64 = 0x0001, 00283 IMAGE_REL_AMD64_ADDR32 = 0x0002, 00284 IMAGE_REL_AMD64_ADDR32NB = 0x0003, 00285 IMAGE_REL_AMD64_REL32 = 0x0004, 00286 IMAGE_REL_AMD64_REL32_1 = 0x0005, 00287 IMAGE_REL_AMD64_REL32_2 = 0x0006, 00288 IMAGE_REL_AMD64_REL32_3 = 0x0007, 00289 IMAGE_REL_AMD64_REL32_4 = 0x0008, 00290 IMAGE_REL_AMD64_REL32_5 = 0x0009, 00291 IMAGE_REL_AMD64_SECTION = 0x000A, 00292 IMAGE_REL_AMD64_SECREL = 0x000B, 00293 IMAGE_REL_AMD64_SECREL7 = 0x000C, 00294 IMAGE_REL_AMD64_TOKEN = 0x000D, 00295 IMAGE_REL_AMD64_SREL32 = 0x000E, 00296 IMAGE_REL_AMD64_PAIR = 0x000F, 00297 IMAGE_REL_AMD64_SSPAN32 = 0x0010 00298 }; 00299 00300 enum RelocationTypesARM { 00301 IMAGE_REL_ARM_ABSOLUTE = 0x0000, 00302 IMAGE_REL_ARM_ADDR32 = 0x0001, 00303 IMAGE_REL_ARM_ADDR32NB = 0x0002, 00304 IMAGE_REL_ARM_BRANCH24 = 0x0003, 00305 IMAGE_REL_ARM_BRANCH11 = 0x0004, 00306 IMAGE_REL_ARM_TOKEN = 0x0005, 00307 IMAGE_REL_ARM_BLX24 = 0x0008, 00308 IMAGE_REL_ARM_BLX11 = 0x0009, 00309 IMAGE_REL_ARM_SECTION = 0x000E, 00310 IMAGE_REL_ARM_SECREL = 0x000F, 00311 IMAGE_REL_ARM_MOV32A = 0x0010, 00312 IMAGE_REL_ARM_MOV32T = 0x0011, 00313 IMAGE_REL_ARM_BRANCH20T = 0x0012, 00314 IMAGE_REL_ARM_BRANCH24T = 0x0014, 00315 IMAGE_REL_ARM_BLX23T = 0x0015 00316 }; 00317 00318 enum COMDATType { 00319 IMAGE_COMDAT_SELECT_NODUPLICATES = 1, 00320 IMAGE_COMDAT_SELECT_ANY, 00321 IMAGE_COMDAT_SELECT_SAME_SIZE, 00322 IMAGE_COMDAT_SELECT_EXACT_MATCH, 00323 IMAGE_COMDAT_SELECT_ASSOCIATIVE, 00324 IMAGE_COMDAT_SELECT_LARGEST, 00325 IMAGE_COMDAT_SELECT_NEWEST 00326 }; 00327 00328 // Auxiliary Symbol Formats 00329 struct AuxiliaryFunctionDefinition { 00330 uint32_t TagIndex; 00331 uint32_t TotalSize; 00332 uint32_t PointerToLinenumber; 00333 uint32_t PointerToNextFunction; 00334 uint8_t unused[2]; 00335 }; 00336 00337 struct AuxiliarybfAndefSymbol { 00338 uint8_t unused1[4]; 00339 uint16_t Linenumber; 00340 uint8_t unused2[6]; 00341 uint32_t PointerToNextFunction; 00342 uint8_t unused3[2]; 00343 }; 00344 00345 struct AuxiliaryWeakExternal { 00346 uint32_t TagIndex; 00347 uint32_t Characteristics; 00348 uint8_t unused[10]; 00349 }; 00350 00351 /// These are not documented in the spec, but are located in WinNT.h. 00352 enum WeakExternalCharacteristics { 00353 IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1, 00354 IMAGE_WEAK_EXTERN_SEARCH_LIBRARY = 2, 00355 IMAGE_WEAK_EXTERN_SEARCH_ALIAS = 3 00356 }; 00357 00358 struct AuxiliaryFile { 00359 uint8_t FileName[18]; 00360 }; 00361 00362 struct AuxiliarySectionDefinition { 00363 uint32_t Length; 00364 uint16_t NumberOfRelocations; 00365 uint16_t NumberOfLinenumbers; 00366 uint32_t CheckSum; 00367 uint16_t Number; 00368 uint8_t Selection; 00369 uint8_t unused[3]; 00370 }; 00371 00372 union Auxiliary { 00373 AuxiliaryFunctionDefinition FunctionDefinition; 00374 AuxiliarybfAndefSymbol bfAndefSymbol; 00375 AuxiliaryWeakExternal WeakExternal; 00376 AuxiliaryFile File; 00377 AuxiliarySectionDefinition SectionDefinition; 00378 }; 00379 00380 /// @brief The Import Directory Table. 00381 /// 00382 /// There is a single array of these and one entry per imported DLL. 00383 struct ImportDirectoryTableEntry { 00384 uint32_t ImportLookupTableRVA; 00385 uint32_t TimeDateStamp; 00386 uint32_t ForwarderChain; 00387 uint32_t NameRVA; 00388 uint32_t ImportAddressTableRVA; 00389 }; 00390 00391 /// @brief The PE32 Import Lookup Table. 00392 /// 00393 /// There is an array of these for each imported DLL. It represents either 00394 /// the ordinal to import from the target DLL, or a name to lookup and import 00395 /// from the target DLL. 00396 /// 00397 /// This also happens to be the same format used by the Import Address Table 00398 /// when it is initially written out to the image. 00399 struct ImportLookupTableEntry32 { 00400 uint32_t data; 00401 00402 /// @brief Is this entry specified by ordinal, or name? 00403 bool isOrdinal() const { return data & 0x80000000; } 00404 00405 /// @brief Get the ordinal value of this entry. isOrdinal must be true. 00406 uint16_t getOrdinal() const { 00407 assert(isOrdinal() && "ILT entry is not an ordinal!"); 00408 return data & 0xFFFF; 00409 } 00410 00411 /// @brief Set the ordinal value and set isOrdinal to true. 00412 void setOrdinal(uint16_t o) { 00413 data = o; 00414 data |= 0x80000000; 00415 } 00416 00417 /// @brief Get the Hint/Name entry RVA. isOrdinal must be false. 00418 uint32_t getHintNameRVA() const { 00419 assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!"); 00420 return data; 00421 } 00422 00423 /// @brief Set the Hint/Name entry RVA and set isOrdinal to false. 00424 void setHintNameRVA(uint32_t rva) { data = rva; } 00425 }; 00426 00427 /// @brief The DOS compatible header at the front of all PEs. 00428 struct DOSHeader { 00429 uint16_t Magic; 00430 uint16_t UsedBytesInTheLastPage; 00431 uint16_t FileSizeInPages; 00432 uint16_t NumberOfRelocationItems; 00433 uint16_t HeaderSizeInParagraphs; 00434 uint16_t MinimumExtraParagraphs; 00435 uint16_t MaximumExtraParagraphs; 00436 uint16_t InitialRelativeSS; 00437 uint16_t InitialSP; 00438 uint16_t Checksum; 00439 uint16_t InitialIP; 00440 uint16_t InitialRelativeCS; 00441 uint16_t AddressOfRelocationTable; 00442 uint16_t OverlayNumber; 00443 uint16_t Reserved[4]; 00444 uint16_t OEMid; 00445 uint16_t OEMinfo; 00446 uint16_t Reserved2[10]; 00447 uint32_t AddressOfNewExeHeader; 00448 }; 00449 00450 struct PEHeader { 00451 uint32_t Signature; 00452 header COFFHeader; 00453 uint16_t Magic; 00454 uint8_t MajorLinkerVersion; 00455 uint8_t MinorLinkerVersion; 00456 uint32_t SizeOfCode; 00457 uint32_t SizeOfInitializedData; 00458 uint32_t SizeOfUninitializedData; 00459 uint32_t AddressOfEntryPoint; // RVA 00460 uint32_t BaseOfCode; // RVA 00461 uint32_t BaseOfData; // RVA 00462 uint64_t ImageBase; 00463 uint32_t SectionAlignment; 00464 uint32_t FileAlignment; 00465 uint16_t MajorOperatingSystemVersion; 00466 uint16_t MinorOperatingSystemVersion; 00467 uint16_t MajorImageVersion; 00468 uint16_t MinorImageVersion; 00469 uint16_t MajorSubsystemVersion; 00470 uint16_t MinorSubsystemVersion; 00471 uint32_t Win32VersionValue; 00472 uint32_t SizeOfImage; 00473 uint32_t SizeOfHeaders; 00474 uint32_t CheckSum; 00475 uint16_t Subsystem; 00476 uint16_t DLLCharacteristics; 00477 uint64_t SizeOfStackReserve; 00478 uint64_t SizeOfStackCommit; 00479 uint64_t SizeOfHeapReserve; 00480 uint64_t SizeOfHeapCommit; 00481 uint32_t LoaderFlags; 00482 uint32_t NumberOfRvaAndSize; 00483 }; 00484 00485 struct DataDirectory { 00486 uint32_t RelativeVirtualAddress; 00487 uint32_t Size; 00488 }; 00489 00490 enum WindowsSubsystem { 00491 IMAGE_SUBSYSTEM_UNKNOWN = 0, ///< An unknown subsystem. 00492 IMAGE_SUBSYSTEM_NATIVE = 1, ///< Device drivers and native Windows processes 00493 IMAGE_SUBSYSTEM_WINDOWS_GUI = 2, ///< The Windows GUI subsystem. 00494 IMAGE_SUBSYSTEM_WINDOWS_CUI = 3, ///< The Windows character subsystem. 00495 IMAGE_SUBSYSTEM_POSIX_CUI = 7, ///< The POSIX character subsystem. 00496 IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9, ///< Windows CE. 00497 IMAGE_SUBSYSTEM_EFI_APPLICATION = 10, ///< An EFI application. 00498 IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11, ///< An EFI driver with boot 00499 /// services. 00500 IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12, ///< An EFI driver with run-time 00501 /// services. 00502 IMAGE_SUBSYSTEM_EFI_ROM = 13, ///< An EFI ROM image. 00503 IMAGE_SUBSYSTEM_XBOX = 14 ///< XBOX. 00504 }; 00505 00506 enum DLLCharacteristics { 00507 /// DLL can be relocated at load time. 00508 IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040, 00509 /// Code integrity checks are enforced. 00510 IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY = 0x0080, 00511 IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100, ///< Image is NX compatible. 00512 /// Isolation aware, but do not isolate the image. 00513 IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION = 0x0200, 00514 /// Does not use structured exception handling (SEH). No SEH handler may be 00515 /// called in this image. 00516 IMAGE_DLL_CHARACTERISTICS_NO_SEH = 0x0400, 00517 /// Do not bind the image. 00518 IMAGE_DLL_CHARACTERISTICS_NO_BIND = 0x0800, 00519 IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER = 0x2000, ///< A WDM driver. 00520 /// Terminal Server aware. 00521 IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000 00522 }; 00523 00524 enum DebugType { 00525 IMAGE_DEBUG_TYPE_UNKNOWN = 0, 00526 IMAGE_DEBUG_TYPE_COFF = 1, 00527 IMAGE_DEBUG_TYPE_CODEVIEW = 2, 00528 IMAGE_DEBUG_TYPE_FPO = 3, 00529 IMAGE_DEBUG_TYPE_MISC = 4, 00530 IMAGE_DEBUG_TYPE_EXCEPTION = 5, 00531 IMAGE_DEBUG_TYPE_FIXUP = 6, 00532 IMAGE_DEBUG_TYPE_OMAP_TO_SRC = 7, 00533 IMAGE_DEBUG_TYPE_OMAP_FROM_SRC = 8, 00534 IMAGE_DEBUG_TYPE_BORLAND = 9, 00535 IMAGE_DEBUG_TYPE_CLSID = 11 00536 }; 00537 00538 enum BaseRelocationType { 00539 IMAGE_REL_BASED_ABSOLUTE = 0, 00540 IMAGE_REL_BASED_HIGH = 1, 00541 IMAGE_REL_BASED_LOW = 2, 00542 IMAGE_REL_BASED_HIGHLOW = 3, 00543 IMAGE_REL_BASED_HIGHADJ = 4, 00544 IMAGE_REL_BASED_MIPS_JMPADDR = 5, 00545 IMAGE_REL_BASED_ARM_MOV32A = 5, 00546 IMAGE_REL_BASED_ARM_MOV32T = 7, 00547 IMAGE_REL_BASED_MIPS_JMPADDR16 = 9, 00548 IMAGE_REL_BASED_DIR64 = 10 00549 }; 00550 00551 enum ImportType { 00552 IMPORT_CODE = 0, 00553 IMPORT_DATA = 1, 00554 IMPORT_CONST = 2 00555 }; 00556 00557 enum ImportNameType { 00558 /// Import is by ordinal. This indicates that the value in the Ordinal/Hint 00559 /// field of the import header is the import's ordinal. If this constant is 00560 /// not specified, then the Ordinal/Hint field should always be interpreted 00561 /// as the import's hint. 00562 IMPORT_ORDINAL = 0, 00563 /// The import name is identical to the public symbol name 00564 IMPORT_NAME = 1, 00565 /// The import name is the public symbol name, but skipping the leading ?, 00566 /// @, or optionally _. 00567 IMPORT_NAME_NOPREFIX = 2, 00568 /// The import name is the public symbol name, but skipping the leading ?, 00569 /// @, or optionally _, and truncating at the first @. 00570 IMPORT_NAME_UNDECORATE = 3 00571 }; 00572 00573 struct ImportHeader { 00574 uint16_t Sig1; ///< Must be IMAGE_FILE_MACHINE_UNKNOWN (0). 00575 uint16_t Sig2; ///< Must be 0xFFFF. 00576 uint16_t Version; 00577 uint16_t Machine; 00578 uint32_t TimeDateStamp; 00579 uint32_t SizeOfData; 00580 uint16_t OrdinalHint; 00581 uint16_t TypeInfo; 00582 00583 ImportType getType() const { 00584 return static_cast<ImportType>(TypeInfo & 0x3); 00585 } 00586 00587 ImportNameType getNameType() const { 00588 return static_cast<ImportNameType>((TypeInfo & 0x1C) >> 3); 00589 } 00590 }; 00591 00592 } // End namespace COFF. 00593 } // End namespace llvm. 00594 00595 #endif