1 //===-- llvm/Support/COFF.h -------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file contains an definitions used in Windows COFF Files. 11 // 12 // Structures and enums defined within this file where created using 13 // information from Microsoft's publicly available PE/COFF format document: 14 // 15 // Microsoft Portable Executable and Common Object File Format Specification 16 // Revision 8.1 - February 15, 2008 17 // 18 // As of 5/2/2010, hosted by Microsoft at: 19 // http://www.microsoft.com/whdc/system/platform/firmware/pecoff.mspx 20 // 21 //===----------------------------------------------------------------------===// 22 23 #ifndef LLVM_SUPPORT_WIN_COFF_H 24 #define LLVM_SUPPORT_WIN_COFF_H 25 26 #include "llvm/Support/DataTypes.h" 27 #include <cassert> 28 #include <cstring> 29 30 namespace llvm { 31 namespace COFF { 32 33 // Sizes in bytes of various things in the COFF format. 34 enum { 35 HeaderSize = 20, 36 NameSize = 8, 37 SymbolSize = 18, 38 SectionSize = 40, 39 RelocationSize = 10 40 }; 41 42 struct header { 43 uint16_t Machine; 44 uint16_t NumberOfSections; 45 uint32_t TimeDateStamp; 46 uint32_t PointerToSymbolTable; 47 uint32_t NumberOfSymbols; 48 uint16_t SizeOfOptionalHeader; 49 uint16_t Characteristics; 50 }; 51 52 enum MachineTypes { 53 MT_Invalid = 0xffff, 54 55 IMAGE_FILE_MACHINE_UNKNOWN = 0x0, 56 IMAGE_FILE_MACHINE_AM33 = 0x13, 57 IMAGE_FILE_MACHINE_AMD64 = 0x8664, 58 IMAGE_FILE_MACHINE_ARM = 0x1C0, 59 IMAGE_FILE_MACHINE_ARMV7 = 0x1C4, 60 IMAGE_FILE_MACHINE_EBC = 0xEBC, 61 IMAGE_FILE_MACHINE_I386 = 0x14C, 62 IMAGE_FILE_MACHINE_IA64 = 0x200, 63 IMAGE_FILE_MACHINE_M32R = 0x9041, 64 IMAGE_FILE_MACHINE_MIPS16 = 0x266, 65 IMAGE_FILE_MACHINE_MIPSFPU = 0x366, 66 IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466, 67 IMAGE_FILE_MACHINE_POWERPC = 0x1F0, 68 IMAGE_FILE_MACHINE_POWERPCFP = 0x1F1, 69 IMAGE_FILE_MACHINE_R4000 = 0x166, 70 IMAGE_FILE_MACHINE_SH3 = 0x1A2, 71 IMAGE_FILE_MACHINE_SH3DSP = 0x1A3, 72 IMAGE_FILE_MACHINE_SH4 = 0x1A6, 73 IMAGE_FILE_MACHINE_SH5 = 0x1A8, 74 IMAGE_FILE_MACHINE_THUMB = 0x1C2, 75 IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169 76 }; 77 78 enum Characteristics { 79 C_Invalid = 0, 80 81 /// The file does not contain base relocations and must be loaded at its 82 /// preferred base. If this cannot be done, the loader will error. 83 IMAGE_FILE_RELOCS_STRIPPED = 0x0001, 84 /// The file is valid and can be run. 85 IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002, 86 /// COFF line numbers have been stripped. This is deprecated and should be 87 /// 0. 88 IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004, 89 /// COFF symbol table entries for local symbols have been removed. This is 90 /// deprecated and should be 0. 91 IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008, 92 /// Aggressively trim working set. This is deprecated and must be 0. 93 IMAGE_FILE_AGGRESSIVE_WS_TRIM = 0x0010, 94 /// Image can handle > 2GiB addresses. 95 IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020, 96 /// Little endian: the LSB precedes the MSB in memory. This is deprecated 97 /// and should be 0. 98 IMAGE_FILE_BYTES_REVERSED_LO = 0x0080, 99 /// Machine is based on a 32bit word architecture. 100 IMAGE_FILE_32BIT_MACHINE = 0x0100, 101 /// Debugging info has been removed. 102 IMAGE_FILE_DEBUG_STRIPPED = 0x0200, 103 /// If the image is on removable media, fully load it and copy it to swap. 104 IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400, 105 /// If the image is on network media, fully load it and copy it to swap. 106 IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800, 107 /// The image file is a system file, not a user program. 108 IMAGE_FILE_SYSTEM = 0x1000, 109 /// The image file is a DLL. 110 IMAGE_FILE_DLL = 0x2000, 111 /// This file should only be run on a uniprocessor machine. 112 IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000, 113 /// Big endian: the MSB precedes the LSB in memory. This is deprecated 114 /// and should be 0. 115 IMAGE_FILE_BYTES_REVERSED_HI = 0x8000 116 }; 117 118 struct symbol { 119 char Name[NameSize]; 120 uint32_t Value; 121 uint16_t SectionNumber; 122 uint16_t Type; 123 uint8_t StorageClass; 124 uint8_t NumberOfAuxSymbols; 125 }; 126 127 enum SymbolFlags { 128 SF_TypeMask = 0x0000FFFF, 129 SF_TypeShift = 0, 130 131 SF_ClassMask = 0x00FF0000, 132 SF_ClassShift = 16, 133 134 SF_WeakExternal = 0x01000000 135 }; 136 137 enum SymbolSectionNumber { 138 IMAGE_SYM_DEBUG = -2, 139 IMAGE_SYM_ABSOLUTE = -1, 140 IMAGE_SYM_UNDEFINED = 0 141 }; 142 143 /// Storage class tells where and what the symbol represents 144 enum SymbolStorageClass { 145 SSC_Invalid = 0xff, 146 147 IMAGE_SYM_CLASS_END_OF_FUNCTION = -1, ///< Physical end of function 148 IMAGE_SYM_CLASS_NULL = 0, ///< No symbol 149 IMAGE_SYM_CLASS_AUTOMATIC = 1, ///< Stack variable 150 IMAGE_SYM_CLASS_EXTERNAL = 2, ///< External symbol 151 IMAGE_SYM_CLASS_STATIC = 3, ///< Static 152 IMAGE_SYM_CLASS_REGISTER = 4, ///< Register variable 153 IMAGE_SYM_CLASS_EXTERNAL_DEF = 5, ///< External definition 154 IMAGE_SYM_CLASS_LABEL = 6, ///< Label 155 IMAGE_SYM_CLASS_UNDEFINED_LABEL = 7, ///< Undefined label 156 IMAGE_SYM_CLASS_MEMBER_OF_STRUCT = 8, ///< Member of structure 157 IMAGE_SYM_CLASS_ARGUMENT = 9, ///< Function argument 158 IMAGE_SYM_CLASS_STRUCT_TAG = 10, ///< Structure tag 159 IMAGE_SYM_CLASS_MEMBER_OF_UNION = 11, ///< Member of union 160 IMAGE_SYM_CLASS_UNION_TAG = 12, ///< Union tag 161 IMAGE_SYM_CLASS_TYPE_DEFINITION = 13, ///< Type definition 162 IMAGE_SYM_CLASS_UNDEFINED_STATIC = 14, ///< Undefined static 163 IMAGE_SYM_CLASS_ENUM_TAG = 15, ///< Enumeration tag 164 IMAGE_SYM_CLASS_MEMBER_OF_ENUM = 16, ///< Member of enumeration 165 IMAGE_SYM_CLASS_REGISTER_PARAM = 17, ///< Register parameter 166 IMAGE_SYM_CLASS_BIT_FIELD = 18, ///< Bit field 167 /// ".bb" or ".eb" - beginning or end of block 168 IMAGE_SYM_CLASS_BLOCK = 100, 169 /// ".bf" or ".ef" - beginning or end of function 170 IMAGE_SYM_CLASS_FUNCTION = 101, 171 IMAGE_SYM_CLASS_END_OF_STRUCT = 102, ///< End of structure 172 IMAGE_SYM_CLASS_FILE = 103, ///< File name 173 /// Line number, reformatted as symbol 174 IMAGE_SYM_CLASS_SECTION = 104, 175 IMAGE_SYM_CLASS_WEAK_EXTERNAL = 105, ///< Duplicate tag 176 /// External symbol in dmert public lib 177 IMAGE_SYM_CLASS_CLR_TOKEN = 107 178 }; 179 180 enum SymbolBaseType { 181 IMAGE_SYM_TYPE_NULL = 0, ///< No type information or unknown base type. 182 IMAGE_SYM_TYPE_VOID = 1, ///< Used with void pointers and functions. 183 IMAGE_SYM_TYPE_CHAR = 2, ///< A character (signed byte). 184 IMAGE_SYM_TYPE_SHORT = 3, ///< A 2-byte signed integer. 185 IMAGE_SYM_TYPE_INT = 4, ///< A natural integer type on the target. 186 IMAGE_SYM_TYPE_LONG = 5, ///< A 4-byte signed integer. 187 IMAGE_SYM_TYPE_FLOAT = 6, ///< A 4-byte floating-point number. 188 IMAGE_SYM_TYPE_DOUBLE = 7, ///< An 8-byte floating-point number. 189 IMAGE_SYM_TYPE_STRUCT = 8, ///< A structure. 190 IMAGE_SYM_TYPE_UNION = 9, ///< An union. 191 IMAGE_SYM_TYPE_ENUM = 10, ///< An enumerated type. 192 IMAGE_SYM_TYPE_MOE = 11, ///< A member of enumeration (a specific value). 193 IMAGE_SYM_TYPE_BYTE = 12, ///< A byte; unsigned 1-byte integer. 194 IMAGE_SYM_TYPE_WORD = 13, ///< A word; unsigned 2-byte integer. 195 IMAGE_SYM_TYPE_UINT = 14, ///< An unsigned integer of natural size. 196 IMAGE_SYM_TYPE_DWORD = 15 ///< An unsigned 4-byte integer. 197 }; 198 199 enum SymbolComplexType { 200 IMAGE_SYM_DTYPE_NULL = 0, ///< No complex type; simple scalar variable. 201 IMAGE_SYM_DTYPE_POINTER = 1, ///< A pointer to base type. 202 IMAGE_SYM_DTYPE_FUNCTION = 2, ///< A function that returns a base type. 203 IMAGE_SYM_DTYPE_ARRAY = 3, ///< An array of base type. 204 205 /// Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT)) 206 SCT_COMPLEX_TYPE_SHIFT = 4 207 }; 208 209 struct section { 210 char Name[NameSize]; 211 uint32_t VirtualSize; 212 uint32_t VirtualAddress; 213 uint32_t SizeOfRawData; 214 uint32_t PointerToRawData; 215 uint32_t PointerToRelocations; 216 uint32_t PointerToLineNumbers; 217 uint16_t NumberOfRelocations; 218 uint16_t NumberOfLineNumbers; 219 uint32_t Characteristics; 220 }; 221 222 enum SectionCharacteristics { 223 SC_Invalid = 0xffffffff, 224 225 IMAGE_SCN_TYPE_NO_PAD = 0x00000008, 226 IMAGE_SCN_CNT_CODE = 0x00000020, 227 IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040, 228 IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080, 229 IMAGE_SCN_LNK_OTHER = 0x00000100, 230 IMAGE_SCN_LNK_INFO = 0x00000200, 231 IMAGE_SCN_LNK_REMOVE = 0x00000800, 232 IMAGE_SCN_LNK_COMDAT = 0x00001000, 233 IMAGE_SCN_GPREL = 0x00008000, 234 IMAGE_SCN_MEM_PURGEABLE = 0x00020000, 235 IMAGE_SCN_MEM_16BIT = 0x00020000, 236 IMAGE_SCN_MEM_LOCKED = 0x00040000, 237 IMAGE_SCN_MEM_PRELOAD = 0x00080000, 238 IMAGE_SCN_ALIGN_1BYTES = 0x00100000, 239 IMAGE_SCN_ALIGN_2BYTES = 0x00200000, 240 IMAGE_SCN_ALIGN_4BYTES = 0x00300000, 241 IMAGE_SCN_ALIGN_8BYTES = 0x00400000, 242 IMAGE_SCN_ALIGN_16BYTES = 0x00500000, 243 IMAGE_SCN_ALIGN_32BYTES = 0x00600000, 244 IMAGE_SCN_ALIGN_64BYTES = 0x00700000, 245 IMAGE_SCN_ALIGN_128BYTES = 0x00800000, 246 IMAGE_SCN_ALIGN_256BYTES = 0x00900000, 247 IMAGE_SCN_ALIGN_512BYTES = 0x00A00000, 248 IMAGE_SCN_ALIGN_1024BYTES = 0x00B00000, 249 IMAGE_SCN_ALIGN_2048BYTES = 0x00C00000, 250 IMAGE_SCN_ALIGN_4096BYTES = 0x00D00000, 251 IMAGE_SCN_ALIGN_8192BYTES = 0x00E00000, 252 IMAGE_SCN_LNK_NRELOC_OVFL = 0x01000000, 253 IMAGE_SCN_MEM_DISCARDABLE = 0x02000000, 254 IMAGE_SCN_MEM_NOT_CACHED = 0x04000000, 255 IMAGE_SCN_MEM_NOT_PAGED = 0x08000000, 256 IMAGE_SCN_MEM_SHARED = 0x10000000, 257 IMAGE_SCN_MEM_EXECUTE = 0x20000000, 258 IMAGE_SCN_MEM_READ = 0x40000000, 259 IMAGE_SCN_MEM_WRITE = 0x80000000 260 }; 261 262 struct relocation { 263 uint32_t VirtualAddress; 264 uint32_t SymbolTableIndex; 265 uint16_t Type; 266 }; 267 268 enum RelocationTypeX86 { 269 IMAGE_REL_I386_ABSOLUTE = 0x0000, 270 IMAGE_REL_I386_DIR16 = 0x0001, 271 IMAGE_REL_I386_REL16 = 0x0002, 272 IMAGE_REL_I386_DIR32 = 0x0006, 273 IMAGE_REL_I386_DIR32NB = 0x0007, 274 IMAGE_REL_I386_SEG12 = 0x0009, 275 IMAGE_REL_I386_SECTION = 0x000A, 276 IMAGE_REL_I386_SECREL = 0x000B, 277 IMAGE_REL_I386_TOKEN = 0x000C, 278 IMAGE_REL_I386_SECREL7 = 0x000D, 279 IMAGE_REL_I386_REL32 = 0x0014, 280 281 IMAGE_REL_AMD64_ABSOLUTE = 0x0000, 282 IMAGE_REL_AMD64_ADDR64 = 0x0001, 283 IMAGE_REL_AMD64_ADDR32 = 0x0002, 284 IMAGE_REL_AMD64_ADDR32NB = 0x0003, 285 IMAGE_REL_AMD64_REL32 = 0x0004, 286 IMAGE_REL_AMD64_REL32_1 = 0x0005, 287 IMAGE_REL_AMD64_REL32_2 = 0x0006, 288 IMAGE_REL_AMD64_REL32_3 = 0x0007, 289 IMAGE_REL_AMD64_REL32_4 = 0x0008, 290 IMAGE_REL_AMD64_REL32_5 = 0x0009, 291 IMAGE_REL_AMD64_SECTION = 0x000A, 292 IMAGE_REL_AMD64_SECREL = 0x000B, 293 IMAGE_REL_AMD64_SECREL7 = 0x000C, 294 IMAGE_REL_AMD64_TOKEN = 0x000D, 295 IMAGE_REL_AMD64_SREL32 = 0x000E, 296 IMAGE_REL_AMD64_PAIR = 0x000F, 297 IMAGE_REL_AMD64_SSPAN32 = 0x0010 298 }; 299 300 enum RelocationTypesARM { 301 IMAGE_REL_ARM_ABSOLUTE = 0x0000, 302 IMAGE_REL_ARM_ADDR32 = 0x0001, 303 IMAGE_REL_ARM_ADDR32NB = 0x0002, 304 IMAGE_REL_ARM_BRANCH24 = 0x0003, 305 IMAGE_REL_ARM_BRANCH11 = 0x0004, 306 IMAGE_REL_ARM_TOKEN = 0x0005, 307 IMAGE_REL_ARM_BLX24 = 0x0008, 308 IMAGE_REL_ARM_BLX11 = 0x0009, 309 IMAGE_REL_ARM_SECTION = 0x000E, 310 IMAGE_REL_ARM_SECREL = 0x000F, 311 IMAGE_REL_ARM_MOV32A = 0x0010, 312 IMAGE_REL_ARM_MOV32T = 0x0011, 313 IMAGE_REL_ARM_BRANCH20T = 0x0012, 314 IMAGE_REL_ARM_BRANCH24T = 0x0014, 315 IMAGE_REL_ARM_BLX23T = 0x0015 316 }; 317 318 enum COMDATType { 319 IMAGE_COMDAT_SELECT_NODUPLICATES = 1, 320 IMAGE_COMDAT_SELECT_ANY, 321 IMAGE_COMDAT_SELECT_SAME_SIZE, 322 IMAGE_COMDAT_SELECT_EXACT_MATCH, 323 IMAGE_COMDAT_SELECT_ASSOCIATIVE, 324 IMAGE_COMDAT_SELECT_LARGEST 325 }; 326 327 // Auxiliary Symbol Formats 328 struct AuxiliaryFunctionDefinition { 329 uint32_t TagIndex; 330 uint32_t TotalSize; 331 uint32_t PointerToLinenumber; 332 uint32_t PointerToNextFunction; 333 uint8_t unused[2]; 334 }; 335 336 struct AuxiliarybfAndefSymbol { 337 uint8_t unused1[4]; 338 uint16_t Linenumber; 339 uint8_t unused2[6]; 340 uint32_t PointerToNextFunction; 341 uint8_t unused3[2]; 342 }; 343 344 struct AuxiliaryWeakExternal { 345 uint32_t TagIndex; 346 uint32_t Characteristics; 347 uint8_t unused[10]; 348 }; 349 350 /// These are not documented in the spec, but are located in WinNT.h. 351 enum WeakExternalCharacteristics { 352 IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY = 1, 353 IMAGE_WEAK_EXTERN_SEARCH_LIBRARY = 2, 354 IMAGE_WEAK_EXTERN_SEARCH_ALIAS = 3 355 }; 356 357 struct AuxiliaryFile { 358 uint8_t FileName[18]; 359 }; 360 361 struct AuxiliarySectionDefinition { 362 uint32_t Length; 363 uint16_t NumberOfRelocations; 364 uint16_t NumberOfLinenumbers; 365 uint32_t CheckSum; 366 uint16_t Number; 367 uint8_t Selection; 368 uint8_t unused[3]; 369 }; 370 371 union Auxiliary { 372 AuxiliaryFunctionDefinition FunctionDefinition; 373 AuxiliarybfAndefSymbol bfAndefSymbol; 374 AuxiliaryWeakExternal WeakExternal; 375 AuxiliaryFile File; 376 AuxiliarySectionDefinition SectionDefinition; 377 }; 378 379 /// @brief The Import Directory Table. 380 /// 381 /// There is a single array of these and one entry per imported DLL. 382 struct ImportDirectoryTableEntry { 383 uint32_t ImportLookupTableRVA; 384 uint32_t TimeDateStamp; 385 uint32_t ForwarderChain; 386 uint32_t NameRVA; 387 uint32_t ImportAddressTableRVA; 388 }; 389 390 /// @brief The PE32 Import Lookup Table. 391 /// 392 /// There is an array of these for each imported DLL. It represents either 393 /// the ordinal to import from the target DLL, or a name to lookup and import 394 /// from the target DLL. 395 /// 396 /// This also happens to be the same format used by the Import Address Table 397 /// when it is initially written out to the image. 398 struct ImportLookupTableEntry32 { 399 uint32_t data; 400 401 /// @brief Is this entry specified by ordinal, or name? 402 bool isOrdinal() const { return data & 0x80000000; } 403 404 /// @brief Get the ordinal value of this entry. isOrdinal must be true. 405 uint16_t getOrdinal() const { 406 assert(isOrdinal() && "ILT entry is not an ordinal!"); 407 return data & 0xFFFF; 408 } 409 410 /// @brief Set the ordinal value and set isOrdinal to true. 411 void setOrdinal(uint16_t o) { 412 data = o; 413 data |= 0x80000000; 414 } 415 416 /// @brief Get the Hint/Name entry RVA. isOrdinal must be false. 417 uint32_t getHintNameRVA() const { 418 assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!"); 419 return data; 420 } 421 422 /// @brief Set the Hint/Name entry RVA and set isOrdinal to false. 423 void setHintNameRVA(uint32_t rva) { data = rva; } 424 }; 425 426 /// @brief The DOS compatible header at the front of all PEs. 427 struct DOSHeader { 428 uint16_t Magic; 429 uint16_t UsedBytesInTheLastPage; 430 uint16_t FileSizeInPages; 431 uint16_t NumberOfRelocationItems; 432 uint16_t HeaderSizeInParagraphs; 433 uint16_t MinimumExtraParagraphs; 434 uint16_t MaximumExtraParagraphs; 435 uint16_t InitialRelativeSS; 436 uint16_t InitialSP; 437 uint16_t Checksum; 438 uint16_t InitialIP; 439 uint16_t InitialRelativeCS; 440 uint16_t AddressOfRelocationTable; 441 uint16_t OverlayNumber; 442 uint16_t Reserved[4]; 443 uint16_t OEMid; 444 uint16_t OEMinfo; 445 uint16_t Reserved2[10]; 446 uint32_t AddressOfNewExeHeader; 447 }; 448 449 struct PEHeader { 450 uint32_t Signature; 451 header COFFHeader; 452 uint16_t Magic; 453 uint8_t MajorLinkerVersion; 454 uint8_t MinorLinkerVersion; 455 uint32_t SizeOfCode; 456 uint32_t SizeOfInitializedData; 457 uint32_t SizeOfUninitializedData; 458 uint32_t AddressOfEntryPoint; // RVA 459 uint32_t BaseOfCode; // RVA 460 uint32_t BaseOfData; // RVA 461 uint64_t ImageBase; 462 uint32_t SectionAlignment; 463 uint32_t FileAlignment; 464 uint16_t MajorOperatingSystemVersion; 465 uint16_t MinorOperatingSystemVersion; 466 uint16_t MajorImageVersion; 467 uint16_t MinorImageVersion; 468 uint16_t MajorSubsystemVersion; 469 uint16_t MinorSubsystemVersion; 470 uint32_t Win32VersionValue; 471 uint32_t SizeOfImage; 472 uint32_t SizeOfHeaders; 473 uint32_t CheckSum; 474 uint16_t Subsystem; 475 uint16_t DLLCharacteristics; 476 uint64_t SizeOfStackReserve; 477 uint64_t SizeOfStackCommit; 478 uint64_t SizeOfHeapReserve; 479 uint64_t SizeOfHeapCommit; 480 uint32_t LoaderFlags; 481 uint32_t NumberOfRvaAndSize; 482 }; 483 484 struct DataDirectory { 485 uint32_t RelativeVirtualAddress; 486 uint32_t Size; 487 }; 488 489 enum WindowsSubsystem { 490 IMAGE_SUBSYSTEM_UNKNOWN = 0, ///< An unknown subsystem. 491 IMAGE_SUBSYSTEM_NATIVE = 1, ///< Device drivers and native Windows processes 492 IMAGE_SUBSYSTEM_WINDOWS_GUI = 2, ///< The Windows GUI subsystem. 493 IMAGE_SUBSYSTEM_WINDOWS_CUI = 3, ///< The Windows character subsystem. 494 IMAGE_SUBSYSTEM_POSIX_CUI = 7, ///< The POSIX character subsystem. 495 IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9, ///< Windows CE. 496 IMAGE_SUBSYSTEM_EFI_APPLICATION = 10, ///< An EFI application. 497 IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11, ///< An EFI driver with boot 498 /// services. 499 IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12, ///< An EFI driver with run-time 500 /// services. 501 IMAGE_SUBSYSTEM_EFI_ROM = 13, ///< An EFI ROM image. 502 IMAGE_SUBSYSTEM_XBOX = 14 ///< XBOX. 503 }; 504 505 enum DLLCharacteristics { 506 /// DLL can be relocated at load time. 507 IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040, 508 /// Code integrity checks are enforced. 509 IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY = 0x0080, 510 IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100, ///< Image is NX compatible. 511 /// Isolation aware, but do not isolate the image. 512 IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION = 0x0200, 513 /// Does not use structured exception handling (SEH). No SEH handler may be 514 /// called in this image. 515 IMAGE_DLL_CHARACTERISTICS_NO_SEH = 0x0400, 516 /// Do not bind the image. 517 IMAGE_DLL_CHARACTERISTICS_NO_BIND = 0x0800, 518 IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER = 0x2000, ///< A WDM driver. 519 /// Terminal Server aware. 520 IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000 521 }; 522 523 enum DebugType { 524 IMAGE_DEBUG_TYPE_UNKNOWN = 0, 525 IMAGE_DEBUG_TYPE_COFF = 1, 526 IMAGE_DEBUG_TYPE_CODEVIEW = 2, 527 IMAGE_DEBUG_TYPE_FPO = 3, 528 IMAGE_DEBUG_TYPE_MISC = 4, 529 IMAGE_DEBUG_TYPE_EXCEPTION = 5, 530 IMAGE_DEBUG_TYPE_FIXUP = 6, 531 IMAGE_DEBUG_TYPE_OMAP_TO_SRC = 7, 532 IMAGE_DEBUG_TYPE_OMAP_FROM_SRC = 8, 533 IMAGE_DEBUG_TYPE_BORLAND = 9, 534 IMAGE_DEBUG_TYPE_CLSID = 11 535 }; 536 537 enum BaseRelocationType { 538 IMAGE_REL_BASED_ABSOLUTE = 0, 539 IMAGE_REL_BASED_HIGH = 1, 540 IMAGE_REL_BASED_LOW = 2, 541 IMAGE_REL_BASED_HIGHLOW = 3, 542 IMAGE_REL_BASED_HIGHADJ = 4, 543 IMAGE_REL_BASED_MIPS_JMPADDR = 5, 544 IMAGE_REL_BASED_ARM_MOV32A = 5, 545 IMAGE_REL_BASED_ARM_MOV32T = 7, 546 IMAGE_REL_BASED_MIPS_JMPADDR16 = 9, 547 IMAGE_REL_BASED_DIR64 = 10 548 }; 549 550 enum ImportType { 551 IMPORT_CODE = 0, 552 IMPORT_DATA = 1, 553 IMPORT_CONST = 2 554 }; 555 556 enum ImportNameType { 557 /// Import is by ordinal. This indicates that the value in the Ordinal/Hint 558 /// field of the import header is the import's ordinal. If this constant is 559 /// not specified, then the Ordinal/Hint field should always be interpreted 560 /// as the import's hint. 561 IMPORT_ORDINAL = 0, 562 /// The import name is identical to the public symbol name 563 IMPORT_NAME = 1, 564 /// The import name is the public symbol name, but skipping the leading ?, 565 /// @, or optionally _. 566 IMPORT_NAME_NOPREFIX = 2, 567 /// The import name is the public symbol name, but skipping the leading ?, 568 /// @, or optionally _, and truncating at the first @. 569 IMPORT_NAME_UNDECORATE = 3 570 }; 571 572 struct ImportHeader { 573 uint16_t Sig1; ///< Must be IMAGE_FILE_MACHINE_UNKNOWN (0). 574 uint16_t Sig2; ///< Must be 0xFFFF. 575 uint16_t Version; 576 uint16_t Machine; 577 uint32_t TimeDateStamp; 578 uint32_t SizeOfData; 579 uint16_t OrdinalHint; 580 uint16_t TypeInfo; 581 582 ImportType getType() const { 583 return static_cast<ImportType>(TypeInfo & 0x3); 584 } 585 586 ImportNameType getNameType() const { 587 return static_cast<ImportNameType>((TypeInfo & 0x1C) >> 3); 588 } 589 }; 590 591 } // End namespace COFF. 592 } // End namespace llvm. 593 594 #endif 595