COFF.h (218893) | COFF.h (234353) |
---|---|
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//===----------------------------------------------------------------------===// --- 10 unchanged lines hidden (view full) --- 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" | 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//===----------------------------------------------------------------------===// --- 10 unchanged lines hidden (view full) --- 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> |
|
27#include <cstring> 28 29namespace llvm { 30namespace COFF { 31 32 // Sizes in bytes of various things in the COFF format. 33 enum { 34 HeaderSize = 20, --- 9 unchanged lines hidden (view full) --- 44 uint32_t TimeDateStamp; 45 uint32_t PointerToSymbolTable; 46 uint32_t NumberOfSymbols; 47 uint16_t SizeOfOptionalHeader; 48 uint16_t Characteristics; 49 }; 50 51 enum MachineTypes { | 28#include <cstring> 29 30namespace llvm { 31namespace COFF { 32 33 // Sizes in bytes of various things in the COFF format. 34 enum { 35 HeaderSize = 20, --- 9 unchanged lines hidden (view full) --- 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 { |
52 IMAGE_FILE_MACHINE_I386 = 0x14C, 53 IMAGE_FILE_MACHINE_AMD64 = 0x8664 | 53 IMAGE_FILE_MACHINE_UNKNOWN = 0x0, 54 IMAGE_FILE_MACHINE_AM33 = 0x13, 55 IMAGE_FILE_MACHINE_AMD64 = 0x8664, 56 IMAGE_FILE_MACHINE_ARM = 0x1C0, 57 IMAGE_FILE_MACHINE_ARMV7 = 0x1C4, 58 IMAGE_FILE_MACHINE_EBC = 0xEBC, 59 IMAGE_FILE_MACHINE_I386 = 0x14C, 60 IMAGE_FILE_MACHINE_IA64 = 0x200, 61 IMAGE_FILE_MACHINE_M32R = 0x9041, 62 IMAGE_FILE_MACHINE_MIPS16 = 0x266, 63 IMAGE_FILE_MACHINE_MIPSFPU = 0x366, 64 IMAGE_FILE_MACHINE_MIPSFPU16 = 0x466, 65 IMAGE_FILE_MACHINE_POWERPC = 0x1F0, 66 IMAGE_FILE_MACHINE_POWERPCFP = 0x1F1, 67 IMAGE_FILE_MACHINE_R4000 = 0x166, 68 IMAGE_FILE_MACHINE_SH3 = 0x1A2, 69 IMAGE_FILE_MACHINE_SH3DSP = 0x1A3, 70 IMAGE_FILE_MACHINE_SH4 = 0x1A6, 71 IMAGE_FILE_MACHINE_SH5 = 0x1A8, 72 IMAGE_FILE_MACHINE_THUMB = 0x1C2, 73 IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x169 |
54 }; 55 | 74 }; 75 |
76 enum Characteristics { 77 /// The file does not contain base relocations and must be loaded at its 78 /// preferred base. If this cannot be done, the loader will error. 79 IMAGE_FILE_RELOCS_STRIPPED = 0x0001, 80 /// The file is valid and can be run. 81 IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002, 82 /// COFF line numbers have been stripped. This is deprecated and should be 83 /// 0. 84 IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004, 85 /// COFF symbol table entries for local symbols have been removed. This is 86 /// deprecated and should be 0. 87 IMAGE_FILE_LOCAL_SYMS_STRIPPED = 0x0008, 88 /// Aggressively trim working set. This is deprecated and must be 0. 89 IMAGE_FILE_AGGRESSIVE_WS_TRIM = 0x0010, 90 /// Image can handle > 2GiB addresses. 91 IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020, 92 /// Little endian: the LSB precedes the MSB in memory. This is deprecated 93 /// and should be 0. 94 IMAGE_FILE_BYTES_REVERSED_LO = 0x0080, 95 /// Machine is based on a 32bit word architecture. 96 IMAGE_FILE_32BIT_MACHINE = 0x0100, 97 /// Debugging info has been removed. 98 IMAGE_FILE_DEBUG_STRIPPED = 0x0200, 99 /// If the image is on removable media, fully load it and copy it to swap. 100 IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = 0x0400, 101 /// If the image is on network media, fully load it and copy it to swap. 102 IMAGE_FILE_NET_RUN_FROM_SWAP = 0x0800, 103 /// The image file is a system file, not a user program. 104 IMAGE_FILE_SYSTEM = 0x1000, 105 /// The image file is a DLL. 106 IMAGE_FILE_DLL = 0x2000, 107 /// This file should only be run on a uniprocessor machine. 108 IMAGE_FILE_UP_SYSTEM_ONLY = 0x4000, 109 /// Big endian: the MSB precedes the LSB in memory. This is deprecated 110 /// and should be 0. 111 IMAGE_FILE_BYTES_REVERSED_HI = 0x8000 112 }; 113 |
|
56 struct symbol { 57 char Name[NameSize]; 58 uint32_t Value; 59 uint16_t Type; 60 uint8_t StorageClass; 61 uint16_t SectionNumber; 62 uint8_t NumberOfAuxSymbols; 63 }; --- 162 unchanged lines hidden (view full) --- 226 IMAGE_REL_AMD64_SECREL = 0x000B, 227 IMAGE_REL_AMD64_SECREL7 = 0x000C, 228 IMAGE_REL_AMD64_TOKEN = 0x000D, 229 IMAGE_REL_AMD64_SREL32 = 0x000E, 230 IMAGE_REL_AMD64_PAIR = 0x000F, 231 IMAGE_REL_AMD64_SSPAN32 = 0x0010 232 }; 233 | 114 struct symbol { 115 char Name[NameSize]; 116 uint32_t Value; 117 uint16_t Type; 118 uint8_t StorageClass; 119 uint16_t SectionNumber; 120 uint8_t NumberOfAuxSymbols; 121 }; --- 162 unchanged lines hidden (view full) --- 284 IMAGE_REL_AMD64_SECREL = 0x000B, 285 IMAGE_REL_AMD64_SECREL7 = 0x000C, 286 IMAGE_REL_AMD64_TOKEN = 0x000D, 287 IMAGE_REL_AMD64_SREL32 = 0x000E, 288 IMAGE_REL_AMD64_PAIR = 0x000F, 289 IMAGE_REL_AMD64_SSPAN32 = 0x0010 290 }; 291 |
292 enum RelocationTypesARM { 293 IMAGE_REL_ARM_ABSOLUTE = 0x0000, 294 IMAGE_REL_ARM_ADDR32 = 0x0001, 295 IMAGE_REL_ARM_ADDR32NB = 0x0002, 296 IMAGE_REL_ARM_BRANCH24 = 0x0003, 297 IMAGE_REL_ARM_BRANCH11 = 0x0004, 298 IMAGE_REL_ARM_TOKEN = 0x0005, 299 IMAGE_REL_ARM_BLX24 = 0x0008, 300 IMAGE_REL_ARM_BLX11 = 0x0009, 301 IMAGE_REL_ARM_SECTION = 0x000E, 302 IMAGE_REL_ARM_SECREL = 0x000F, 303 IMAGE_REL_ARM_MOV32A = 0x0010, 304 IMAGE_REL_ARM_MOV32T = 0x0011, 305 IMAGE_REL_ARM_BRANCH20T = 0x0012, 306 IMAGE_REL_ARM_BRANCH24T = 0x0014, 307 IMAGE_REL_ARM_BLX23T = 0x0015 308 }; 309 |
|
234 enum COMDATType { 235 IMAGE_COMDAT_SELECT_NODUPLICATES = 1, 236 IMAGE_COMDAT_SELECT_ANY, 237 IMAGE_COMDAT_SELECT_SAME_SIZE, 238 IMAGE_COMDAT_SELECT_EXACT_MATCH, 239 IMAGE_COMDAT_SELECT_ASSOCIATIVE, 240 IMAGE_COMDAT_SELECT_LARGEST 241 }; --- 45 unchanged lines hidden (view full) --- 287 union Auxiliary { 288 AuxiliaryFunctionDefinition FunctionDefinition; 289 AuxiliarybfAndefSymbol bfAndefSymbol; 290 AuxiliaryWeakExternal WeakExternal; 291 AuxiliaryFile File; 292 AuxiliarySectionDefinition SectionDefinition; 293 }; 294 | 310 enum COMDATType { 311 IMAGE_COMDAT_SELECT_NODUPLICATES = 1, 312 IMAGE_COMDAT_SELECT_ANY, 313 IMAGE_COMDAT_SELECT_SAME_SIZE, 314 IMAGE_COMDAT_SELECT_EXACT_MATCH, 315 IMAGE_COMDAT_SELECT_ASSOCIATIVE, 316 IMAGE_COMDAT_SELECT_LARGEST 317 }; --- 45 unchanged lines hidden (view full) --- 363 union Auxiliary { 364 AuxiliaryFunctionDefinition FunctionDefinition; 365 AuxiliarybfAndefSymbol bfAndefSymbol; 366 AuxiliaryWeakExternal WeakExternal; 367 AuxiliaryFile File; 368 AuxiliarySectionDefinition SectionDefinition; 369 }; 370 |
295} // End namespace llvm. | 371 /// @brief The Import Directory Table. 372 /// 373 /// There is a single array of these and one entry per imported DLL. 374 struct ImportDirectoryTableEntry { 375 uint32_t ImportLookupTableRVA; 376 uint32_t TimeDateStamp; 377 uint32_t ForwarderChain; 378 uint32_t NameRVA; 379 uint32_t ImportAddressTableRVA; 380 }; 381 382 /// @brief The PE32 Import Lookup Table. 383 /// 384 /// There is an array of these for each imported DLL. It represents either 385 /// the ordinal to import from the target DLL, or a name to lookup and import 386 /// from the target DLL. 387 /// 388 /// This also happens to be the same format used by the Import Address Table 389 /// when it is initially written out to the image. 390 struct ImportLookupTableEntry32 { 391 uint32_t data; 392 393 /// @brief Is this entry specified by ordinal, or name? 394 bool isOrdinal() const { return data & 0x80000000; } 395 396 /// @brief Get the ordinal value of this entry. isOrdinal must be true. 397 uint16_t getOrdinal() const { 398 assert(isOrdinal() && "ILT entry is not an ordinal!"); 399 return data & 0xFFFF; 400 } 401 402 /// @brief Set the ordinal value and set isOrdinal to true. 403 void setOrdinal(uint16_t o) { 404 data = o; 405 data |= 0x80000000; 406 } 407 408 /// @brief Get the Hint/Name entry RVA. isOrdinal must be false. 409 uint32_t getHintNameRVA() const { 410 assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!"); 411 return data; 412 } 413 414 /// @brief Set the Hint/Name entry RVA and set isOrdinal to false. 415 void setHintNameRVA(uint32_t rva) { data = rva; } 416 }; 417 418 /// @brief The DOS compatible header at the front of all PEs. 419 struct DOSHeader { 420 uint16_t Magic; 421 uint16_t UsedBytesInTheLastPage; 422 uint16_t FileSizeInPages; 423 uint16_t NumberOfRelocationItems; 424 uint16_t HeaderSizeInParagraphs; 425 uint16_t MinimumExtraParagraphs; 426 uint16_t MaximumExtraParagraphs; 427 uint16_t InitialRelativeSS; 428 uint16_t InitialSP; 429 uint16_t Checksum; 430 uint16_t InitialIP; 431 uint16_t InitialRelativeCS; 432 uint16_t AddressOfRelocationTable; 433 uint16_t OverlayNumber; 434 uint16_t Reserved[4]; 435 uint16_t OEMid; 436 uint16_t OEMinfo; 437 uint16_t Reserved2[10]; 438 uint32_t AddressOfNewExeHeader; 439 }; 440 441 struct PEHeader { 442 uint32_t Signature; 443 header COFFHeader; 444 uint16_t Magic; 445 uint8_t MajorLinkerVersion; 446 uint8_t MinorLinkerVersion; 447 uint32_t SizeOfCode; 448 uint32_t SizeOfInitializedData; 449 uint32_t SizeOfUninitializedData; 450 uint32_t AddressOfEntryPoint; // RVA 451 uint32_t BaseOfCode; // RVA 452 uint32_t BaseOfData; // RVA 453 uint64_t ImageBase; 454 uint32_t SectionAlignment; 455 uint32_t FileAlignment; 456 uint16_t MajorOperatingSystemVersion; 457 uint16_t MinorOperatingSystemVersion; 458 uint16_t MajorImageVersion; 459 uint16_t MinorImageVersion; 460 uint16_t MajorSubsystemVersion; 461 uint16_t MinorSubsystemVersion; 462 uint32_t Win32VersionValue; 463 uint32_t SizeOfImage; 464 uint32_t SizeOfHeaders; 465 uint32_t CheckSum; 466 uint16_t Subsystem; 467 uint16_t DLLCharacteristics; 468 uint64_t SizeOfStackReserve; 469 uint64_t SizeOfStackCommit; 470 uint64_t SizeOfHeapReserve; 471 uint64_t SizeOfHeapCommit; 472 uint32_t LoaderFlags; 473 uint32_t NumberOfRvaAndSize; 474 }; 475 476 struct DataDirectory { 477 uint32_t RelativeVirtualAddress; 478 uint32_t Size; 479 }; 480 481 enum WindowsSubsystem { 482 IMAGE_SUBSYSTEM_UNKNOWN = 0, ///< An unknown subsystem. 483 IMAGE_SUBSYSTEM_NATIVE = 1, ///< Device drivers and native Windows processes 484 IMAGE_SUBSYSTEM_WINDOWS_GUI = 2, ///< The Windows GUI subsystem. 485 IMAGE_SUBSYSTEM_WINDOWS_CUI = 3, ///< The Windows character subsystem. 486 IMAGE_SUBSYSTEM_POSIX_CUI = 7, ///< The POSIX character subsystem. 487 IMAGE_SUBSYSTEM_WINDOWS_CE_GUI = 9, ///< Windows CE. 488 IMAGE_SUBSYSTEM_EFI_APPLICATION = 10, ///< An EFI application. 489 IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER = 11, ///< An EFI driver with boot 490 /// services. 491 IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER = 12, ///< An EFI driver with run-time 492 /// services. 493 IMAGE_SUBSYSTEM_EFI_ROM = 13, ///< An EFI ROM image. 494 IMAGE_SUBSYSTEM_XBOX = 14 ///< XBOX. 495 }; 496 497 enum DLLCharacteristics { 498 /// DLL can be relocated at load time. 499 IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE = 0x0040, 500 /// Code integrity checks are enforced. 501 IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY = 0x0080, 502 IMAGE_DLL_CHARACTERISTICS_NX_COMPAT = 0x0100, ///< Image is NX compatible. 503 /// Isolation aware, but do not isolate the image. 504 IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION = 0x0200, 505 /// Does not use structured exception handling (SEH). No SEH handler may be 506 /// called in this image. 507 IMAGE_DLL_CHARACTERISTICS_NO_SEH = 0x0400, 508 /// Do not bind the image. 509 IMAGE_DLL_CHARACTERISTICS_NO_BIND = 0x0800, 510 IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER = 0x2000, ///< A WDM driver. 511 /// Terminal Server aware. 512 IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE = 0x8000 513 }; 514 515 enum DebugType { 516 IMAGE_DEBUG_TYPE_UNKNOWN = 0, 517 IMAGE_DEBUG_TYPE_COFF = 1, 518 IMAGE_DEBUG_TYPE_CODEVIEW = 2, 519 IMAGE_DEBUG_TYPE_FPO = 3, 520 IMAGE_DEBUG_TYPE_MISC = 4, 521 IMAGE_DEBUG_TYPE_EXCEPTION = 5, 522 IMAGE_DEBUG_TYPE_FIXUP = 6, 523 IMAGE_DEBUG_TYPE_OMAP_TO_SRC = 7, 524 IMAGE_DEBUG_TYPE_OMAP_FROM_SRC = 8, 525 IMAGE_DEBUG_TYPE_BORLAND = 9, 526 IMAGE_DEBUG_TYPE_CLSID = 11 527 }; 528 529 enum BaseRelocationType { 530 IMAGE_REL_BASED_ABSOLUTE = 0, 531 IMAGE_REL_BASED_HIGH = 1, 532 IMAGE_REL_BASED_LOW = 2, 533 IMAGE_REL_BASED_HIGHLOW = 3, 534 IMAGE_REL_BASED_HIGHADJ = 4, 535 IMAGE_REL_BASED_MIPS_JMPADDR = 5, 536 IMAGE_REL_BASED_ARM_MOV32A = 5, 537 IMAGE_REL_BASED_ARM_MOV32T = 7, 538 IMAGE_REL_BASED_MIPS_JMPADDR16 = 9, 539 IMAGE_REL_BASED_DIR64 = 10 540 }; 541 542 enum ImportType { 543 IMPORT_CODE = 0, 544 IMPORT_DATA = 1, 545 IMPORT_CONST = 2 546 }; 547 548 enum ImportNameType { 549 /// Import is by ordinal. This indicates that the value in the Ordinal/Hint 550 /// field of the import header is the import's ordinal. If this constant is 551 /// not specified, then the Ordinal/Hint field should always be interpreted 552 /// as the import's hint. 553 IMPORT_ORDINAL = 0, 554 /// The import name is identical to the public symbol name 555 IMPORT_NAME = 1, 556 /// The import name is the public symbol name, but skipping the leading ?, 557 /// @, or optionally _. 558 IMPORT_NAME_NOPREFIX = 2, 559 /// The import name is the public symbol name, but skipping the leading ?, 560 /// @, or optionally _, and truncating at the first @. 561 IMPORT_NAME_UNDECORATE = 3 562 }; 563 564 struct ImportHeader { 565 uint16_t Sig1; ///< Must be IMAGE_FILE_MACHINE_UNKNOWN (0). 566 uint16_t Sig2; ///< Must be 0xFFFF. 567 uint16_t Version; 568 uint16_t Machine; 569 uint32_t TimeDateStamp; 570 uint32_t SizeOfData; 571 uint16_t OrdinalHint; 572 uint16_t TypeInfo; 573 574 ImportType getType() const { 575 return static_cast<ImportType>(TypeInfo & 0x3); 576 } 577 578 ImportNameType getNameType() const { 579 return static_cast<ImportNameType>((TypeInfo & 0x1C) >> 3); 580 } 581 }; 582 |
296} // End namespace COFF. | 583} // End namespace COFF. |
584} // End namespace llvm. |
|
297 298#endif | 585 586#endif |