1f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===- COFF.h - COFF object file implementation -----------------*- C++ -*-===//
2f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
3f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//                     The LLVM Compiler Infrastructure
4f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
5f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file is distributed under the University of Illinois Open Source
6f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// License. See LICENSE.TXT for details.
7f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
8f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
9f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
10f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file declares the COFFObjectFile class.
11f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
12f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
13f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
14f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#ifndef LLVM_OBJECT_COFF_H
15f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define LLVM_OBJECT_COFF_H
16f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
17f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/iterator_range.h"
18f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/BinaryFormat/COFF.h"
19f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/DebugInfo/CodeView/CVDebugRecord.h"
20f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/MC/SubtargetFeature.h"
21f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Object/Binary.h"
22f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Object/Error.h"
23f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Object/ObjectFile.h"
24f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Support/BinaryByteStream.h"
25f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Support/ConvertUTF.h"
26f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Support/Endian.h"
27f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Support/ErrorHandling.h"
28f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <cassert>
29f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <cstddef>
30f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <cstdint>
31f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <system_error>
32f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
33f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace llvm {
34f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
35f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate <typename T> class ArrayRef;
36f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
37f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace object {
38f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
39f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass BaseRelocRef;
40f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass DelayImportDirectoryEntryRef;
41f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ExportDirectoryEntryRef;
42f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ImportDirectoryEntryRef;
43f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ImportedSymbolRef;
44f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ResourceSectionRef;
45f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
46f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing import_directory_iterator = content_iterator<ImportDirectoryEntryRef>;
47f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing delay_import_directory_iterator =
48f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    content_iterator<DelayImportDirectoryEntryRef>;
49f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing export_directory_iterator = content_iterator<ExportDirectoryEntryRef>;
50f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing imported_symbol_iterator = content_iterator<ImportedSymbolRef>;
51f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing base_reloc_iterator = content_iterator<BaseRelocRef>;
52f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
53f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// The DOS compatible header at the front of all PE/COFF executables.
54f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct dos_header {
55f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  char                 Magic[2];
56f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t UsedBytesInTheLastPage;
57f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t FileSizeInPages;
58f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberOfRelocationItems;
59f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t HeaderSizeInParagraphs;
60f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinimumExtraParagraphs;
61f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MaximumExtraParagraphs;
62f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t InitialRelativeSS;
63f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t InitialSP;
64f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Checksum;
65f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t InitialIP;
66f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t InitialRelativeCS;
67f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t AddressOfRelocationTable;
68f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t OverlayNumber;
69f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Reserved[4];
70f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t OEMid;
71f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t OEMinfo;
72f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Reserved2[10];
73f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t AddressOfNewExeHeader;
74f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
75f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
76f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_file_header {
77f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Machine;
78f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberOfSections;
79f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
80f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToSymbolTable;
81f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NumberOfSymbols;
82f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t SizeOfOptionalHeader;
83f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Characteristics;
84f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
85f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isImportLibrary() const { return NumberOfSections == 0xffff; }
86f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
87f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
88f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_bigobj_file_header {
89f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Sig1;
90f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Sig2;
91f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Version;
92f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Machine;
93f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
94f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t              UUID[16];
95f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t unused1;
96f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t unused2;
97f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t unused3;
98f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t unused4;
99f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NumberOfSections;
100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToSymbolTable;
101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NumberOfSymbols;
102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// The 32-bit PE header that follows the COFF header.
105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct pe32_header {
106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Magic;
107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t MajorLinkerVersion;
108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t MinorLinkerVersion;
109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfCode;
110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfInitializedData;
111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfUninitializedData;
112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t AddressOfEntryPoint;
113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t BaseOfCode;
114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t BaseOfData;
115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ImageBase;
116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SectionAlignment;
117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t FileAlignment;
118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorOperatingSystemVersion;
119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorOperatingSystemVersion;
120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorImageVersion;
121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorImageVersion;
122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorSubsystemVersion;
123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorSubsystemVersion;
124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Win32VersionValue;
125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfImage;
126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfHeaders;
127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t CheckSum;
128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Subsystem;
129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // FIXME: This should be DllCharacteristics.
130f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t DLLCharacteristics;
131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfStackReserve;
132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfStackCommit;
133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfHeapReserve;
134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfHeapCommit;
135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t LoaderFlags;
136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // FIXME: This should be NumberOfRvaAndSizes.
137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NumberOfRvaAndSize;
138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// The 64-bit PE header that follows the COFF header.
141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct pe32plus_header {
142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Magic;
143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t MajorLinkerVersion;
144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t MinorLinkerVersion;
145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfCode;
146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfInitializedData;
147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfUninitializedData;
148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t AddressOfEntryPoint;
149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t BaseOfCode;
150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t ImageBase;
151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SectionAlignment;
152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t FileAlignment;
153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorOperatingSystemVersion;
154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorOperatingSystemVersion;
155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorImageVersion;
156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorImageVersion;
157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorSubsystemVersion;
158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorSubsystemVersion;
159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Win32VersionValue;
160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfImage;
161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfHeaders;
162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t CheckSum;
163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Subsystem;
164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t DLLCharacteristics;
165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t SizeOfStackReserve;
166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t SizeOfStackCommit;
167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t SizeOfHeapReserve;
168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t SizeOfHeapCommit;
169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t LoaderFlags;
170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NumberOfRvaAndSize;
171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct data_directory {
174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t RelativeVirtualAddress;
175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Size;
176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct debug_directory {
179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Characteristics;
180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorVersion;
182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorVersion;
183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Type;
184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfData;
185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t AddressOfRawData;
186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToRawData;
187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate <typename IntTy>
190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct import_lookup_table_entry {
191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntTy Data;
192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isOrdinal() const { return Data < 0; }
194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
195f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint16_t getOrdinal() const {
196f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(isOrdinal() && "ILT entry is not an ordinal!");
197f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return Data & 0xFFFF;
198f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
199f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
200f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getHintNameRVA() const {
201f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!");
202f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return Data & 0xFFFFFFFF;
203f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
204f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
205f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
206f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing import_lookup_table_entry32 =
207f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    import_lookup_table_entry<support::little32_t>;
208f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing import_lookup_table_entry64 =
209f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    import_lookup_table_entry<support::little64_t>;
210f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
211f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct delay_import_directory_table_entry {
212f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // dumpbin reports this field as "Characteristics" instead of "Attributes".
213f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Attributes;
214f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Name;
215f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ModuleHandle;
216f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DelayImportAddressTable;
217f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DelayImportNameTable;
218f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t BoundDelayImportTable;
219f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t UnloadDelayImportTable;
220f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeStamp;
221f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
222f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
223f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct export_directory_table_entry {
224f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ExportFlags;
225f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
226f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorVersion;
227f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorVersion;
228f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NameRVA;
229f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t OrdinalBase;
230f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t AddressTableEntries;
231f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NumberOfNamePointers;
232f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ExportAddressTableRVA;
233f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NamePointerRVA;
234f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t OrdinalTableRVA;
235f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
236f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
237f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotunion export_address_table_entry {
238f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ExportRVA;
239f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ForwarderRVA;
240f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
241f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
242f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing export_name_pointer_table_entry = support::ulittle32_t;
243f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing export_ordinal_table_entry = support::ulittle16_t;
244f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
245f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct StringTableOffset {
246f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Zeroes;
247f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Offset;
248f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
249f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
250f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate <typename SectionNumberType>
251f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_symbol {
252f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  union {
253f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    char ShortName[COFF::NameSize];
254f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    StringTableOffset Offset;
255f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  } Name;
256f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
257f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Value;
258f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SectionNumberType SectionNumber;
259f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
260f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Type;
261f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
262f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t StorageClass;
263f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t NumberOfAuxSymbols;
264f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
265f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
266f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing coff_symbol16 = coff_symbol<support::ulittle16_t>;
267f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing coff_symbol32 = coff_symbol<support::ulittle32_t>;
268f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
269f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// Contains only common parts of coff_symbol16 and coff_symbol32.
270f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_symbol_generic {
271f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  union {
272f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    char ShortName[COFF::NameSize];
273f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    StringTableOffset Offset;
274f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  } Name;
275f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Value;
276f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
277f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
278f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass COFFSymbolRef {
279f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
280f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  COFFSymbolRef() = default;
281f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  COFFSymbolRef(const coff_symbol16 *CS) : CS16(CS) {}
282f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  COFFSymbolRef(const coff_symbol32 *CS) : CS32(CS) {}
283f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
284f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const void *getRawPtr() const {
285f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CS16 ? static_cast<const void *>(CS16) : CS32;
286f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
287f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
288f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_symbol_generic *getGeneric() const {
289f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (CS16)
290f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return reinterpret_cast<const coff_symbol_generic *>(CS16);
291f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return reinterpret_cast<const coff_symbol_generic *>(CS32);
292f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
293f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
294f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  friend bool operator<(COFFSymbolRef A, COFFSymbolRef B) {
295f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return A.getRawPtr() < B.getRawPtr();
296f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
297f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
298f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isBigObj() const {
299f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (CS16)
300f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return false;
301f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (CS32)
302f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return true;
303f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("COFFSymbolRef points to nothing!");
304f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
305f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
306f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const char *getShortName() const {
307f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CS16 ? CS16->Name.ShortName : CS32->Name.ShortName;
308f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
309f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
310f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const StringTableOffset &getStringTableOffset() const {
311f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(isSet() && "COFFSymbolRef points to nothing!");
312f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CS16 ? CS16->Name.Offset : CS32->Name.Offset;
313f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
314f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
315f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getValue() const { return CS16 ? CS16->Value : CS32->Value; }
316f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
317f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int32_t getSectionNumber() const {
318f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(isSet() && "COFFSymbolRef points to nothing!");
319f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (CS16) {
320f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      // Reserved sections are returned as negative numbers.
321f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (CS16->SectionNumber <= COFF::MaxNumberOfSections16)
322f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        return CS16->SectionNumber;
323f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return static_cast<int16_t>(CS16->SectionNumber);
324f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
325f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return static_cast<int32_t>(CS32->SectionNumber);
326f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
327f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
328f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint16_t getType() const {
329f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(isSet() && "COFFSymbolRef points to nothing!");
330f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CS16 ? CS16->Type : CS32->Type;
331f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
332f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
333f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t getStorageClass() const {
334f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(isSet() && "COFFSymbolRef points to nothing!");
335f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CS16 ? CS16->StorageClass : CS32->StorageClass;
336f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
337f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
338f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t getNumberOfAuxSymbols() const {
339f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(isSet() && "COFFSymbolRef points to nothing!");
340f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CS16 ? CS16->NumberOfAuxSymbols : CS32->NumberOfAuxSymbols;
341f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
342f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
343f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t getBaseType() const { return getType() & 0x0F; }
344f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
345f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t getComplexType() const {
346f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return (getType() & 0xF0) >> COFF::SCT_COMPLEX_TYPE_SHIFT;
347f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
348f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
349f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isAbsolute() const {
350f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getSectionNumber() == -1;
351f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
352f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
353f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isExternal() const {
354f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getStorageClass() == COFF::IMAGE_SYM_CLASS_EXTERNAL;
355f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
356f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
357f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isCommon() const {
358f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return isExternal() && getSectionNumber() == COFF::IMAGE_SYM_UNDEFINED &&
359f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot           getValue() != 0;
360f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
361f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
362f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isUndefined() const {
363f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return isExternal() && getSectionNumber() == COFF::IMAGE_SYM_UNDEFINED &&
364f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot           getValue() == 0;
365f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
366f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
367f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isWeakExternal() const {
368f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getStorageClass() == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL;
369f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
370f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
371f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isFunctionDefinition() const {
372f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return isExternal() && getBaseType() == COFF::IMAGE_SYM_TYPE_NULL &&
373f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot           getComplexType() == COFF::IMAGE_SYM_DTYPE_FUNCTION &&
374f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot           !COFF::isReservedSectionNumber(getSectionNumber());
375f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
376f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
377f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isFunctionLineInfo() const {
378f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getStorageClass() == COFF::IMAGE_SYM_CLASS_FUNCTION;
379f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
380f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
381f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isAnyUndefined() const {
382f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return isUndefined() || isWeakExternal();
383f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
384f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
385f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isFileRecord() const {
386f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getStorageClass() == COFF::IMAGE_SYM_CLASS_FILE;
387f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
388f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
389f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isSection() const {
390f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getStorageClass() == COFF::IMAGE_SYM_CLASS_SECTION;
391f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
392f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
393f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isSectionDefinition() const {
394f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // C++/CLI creates external ABS symbols for non-const appdomain globals.
395f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // These are also followed by an auxiliary section definition.
396f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool isAppdomainGlobal =
397f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        getStorageClass() == COFF::IMAGE_SYM_CLASS_EXTERNAL &&
398f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        getSectionNumber() == COFF::IMAGE_SYM_ABSOLUTE;
399f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool isOrdinarySection = getStorageClass() == COFF::IMAGE_SYM_CLASS_STATIC;
400f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!getNumberOfAuxSymbols())
401f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return false;
402f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return isAppdomainGlobal || isOrdinarySection;
403f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
404f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
405f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isCLRToken() const {
406f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getStorageClass() == COFF::IMAGE_SYM_CLASS_CLR_TOKEN;
407f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
408f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
409f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
410f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isSet() const { return CS16 || CS32; }
411f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
412f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_symbol16 *CS16 = nullptr;
413f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_symbol32 *CS32 = nullptr;
414f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
415f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
416f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_section {
417f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  char Name[COFF::NameSize];
418f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t VirtualSize;
419f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t VirtualAddress;
420f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfRawData;
421f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToRawData;
422f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToRelocations;
423f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToLinenumbers;
424f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberOfRelocations;
425f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberOfLinenumbers;
426f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Characteristics;
427f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
428f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Returns true if the actual number of relocations is stored in
429f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // VirtualAddress field of the first relocation table entry.
430f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool hasExtendedRelocations() const {
431f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return (Characteristics & COFF::IMAGE_SCN_LNK_NRELOC_OVFL) &&
432f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot           NumberOfRelocations == UINT16_MAX;
433f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
434f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
435f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getAlignment() const {
436f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // The IMAGE_SCN_TYPE_NO_PAD bit is a legacy way of getting to
437f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // IMAGE_SCN_ALIGN_1BYTES.
438f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (Characteristics & COFF::IMAGE_SCN_TYPE_NO_PAD)
439f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return 1;
440f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
441f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // Bit [20:24] contains section alignment. Both 0 and 1 mean alignment 1.
442f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    uint32_t Shift = (Characteristics >> 20) & 0xF;
443f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (Shift > 0)
444f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return 1U << (Shift - 1);
445f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return 1;
446f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
447f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
448f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
449f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_relocation {
450f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t VirtualAddress;
451f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SymbolTableIndex;
452f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Type;
453f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
454f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
455f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_aux_function_definition {
456f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TagIndex;
457f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TotalSize;
458f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToLinenumber;
459f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToNextFunction;
460f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  char Unused1[2];
461f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
462f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
463f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstatic_assert(sizeof(coff_aux_function_definition) == 18,
464f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot              "auxiliary entry must be 18 bytes");
465f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
466f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_aux_bf_and_ef_symbol {
467f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  char Unused1[4];
468f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Linenumber;
469f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  char Unused2[6];
470f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PointerToNextFunction;
471f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  char Unused3[2];
472f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
473f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
474f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstatic_assert(sizeof(coff_aux_bf_and_ef_symbol) == 18,
475f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot              "auxiliary entry must be 18 bytes");
476f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
477f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_aux_weak_external {
478f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TagIndex;
479f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Characteristics;
480f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  char Unused1[10];
481f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
482f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
483f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstatic_assert(sizeof(coff_aux_weak_external) == 18,
484f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot              "auxiliary entry must be 18 bytes");
485f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
486f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_aux_section_definition {
487f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Length;
488f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberOfRelocations;
489f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberOfLinenumbers;
490f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t CheckSum;
491f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberLowPart;
492f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t              Selection;
493f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t              Unused;
494f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberHighPart;
495f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int32_t getNumber(bool IsBigObj) const {
496f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    uint32_t Number = static_cast<uint32_t>(NumberLowPart);
497f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (IsBigObj)
498f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Number |= static_cast<uint32_t>(NumberHighPart) << 16;
499f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return static_cast<int32_t>(Number);
500f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
501f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
502f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
503f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstatic_assert(sizeof(coff_aux_section_definition) == 18,
504f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot              "auxiliary entry must be 18 bytes");
505f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
506f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_aux_clr_token {
507f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t              AuxType;
508f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t              Reserved;
509f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SymbolTableIndex;
510f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  char                 MBZ[12];
511f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
512f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
513f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstatic_assert(sizeof(coff_aux_clr_token) == 18,
514f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot              "auxiliary entry must be 18 bytes");
515f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
516f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_import_header {
517f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Sig1;
518f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Sig2;
519f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Version;
520f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Machine;
521f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
522f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfData;
523f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t OrdinalHint;
524f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t TypeInfo;
525f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
526f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int getType() const { return TypeInfo & 0x3; }
527f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int getNameType() const { return (TypeInfo >> 2) & 0x7; }
528f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
529f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
530f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_import_directory_table_entry {
531f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ImportLookupTableRVA;
532f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
533f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ForwarderChain;
534f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NameRVA;
535f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ImportAddressTableRVA;
536f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
537f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isNull() const {
538f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return ImportLookupTableRVA == 0 && TimeDateStamp == 0 &&
539f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot           ForwarderChain == 0 && NameRVA == 0 && ImportAddressTableRVA == 0;
540f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
541f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
542f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
543f3014761c955345d6e05491608e73228d014afbandroid-build-team Robottemplate <typename IntTy>
544f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_tls_directory {
545f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntTy StartAddressOfRawData;
546f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntTy EndAddressOfRawData;
547f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntTy AddressOfIndex;
548f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntTy AddressOfCallBacks;
549f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SizeOfZeroFill;
550f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Characteristics;
551f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
552f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getAlignment() const {
553f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // Bit [20:24] contains section alignment.
554f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    uint32_t Shift = (Characteristics & 0x00F00000) >> 20;
555f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (Shift > 0)
556f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return 1U << (Shift - 1);
557f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return 0;
558f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
559f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
560f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
561f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing coff_tls_directory32 = coff_tls_directory<support::little32_t>;
562f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotusing coff_tls_directory64 = coff_tls_directory<support::little64_t>;
563f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
564f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// Bits in control flow guard flags as we understand them.
565f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotenum class coff_guard_flags : uint32_t {
566f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  CFInstrumented = 0x00000100,
567f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  HasFidTable = 0x00000400,
568f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ProtectDelayLoadIAT = 0x00001000,
569f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DelayLoadIATSection = 0x00002000, // Delay load in separate section
570f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  HasLongJmpTable = 0x00010000,
571f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  FidTableHasFlags = 0x10000000, // Indicates that fid tables are 5 bytes
572f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
573f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
574f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_load_config_code_integrity {
575f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Flags;
576f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Catalog;
577f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t CatalogOffset;
578f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Reserved;
579f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
580f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
581f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// 32-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY32)
582f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_load_configuration32 {
583f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Size;
584f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
585f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorVersion;
586f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorVersion;
587f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GlobalFlagsClear;
588f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GlobalFlagsSet;
589f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t CriticalSectionDefaultTimeout;
590f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DeCommitFreeBlockThreshold;
591f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DeCommitTotalFreeThreshold;
592f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t LockPrefixTable;
593f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t MaximumAllocationSize;
594f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t VirtualMemoryThreshold;
595f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ProcessAffinityMask;
596f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ProcessHeapFlags;
597f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t CSDVersion;
598f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t DependentLoadFlags;
599f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t EditList;
600f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SecurityCookie;
601f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SEHandlerTable;
602f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t SEHandlerCount;
603f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
604f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Added in MSVC 2015 for /guard:cf.
605f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardCFCheckFunction;
606f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardCFCheckDispatch;
607f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardCFFunctionTable;
608f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardCFFunctionCount;
609f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardFlags; // coff_guard_flags
610f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
611f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Added in MSVC 2017
612f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  coff_load_config_code_integrity CodeIntegrity;
613f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardAddressTakenIatEntryTable;
614f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardAddressTakenIatEntryCount;
615f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardLongJumpTargetTable;
616f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardLongJumpTargetCount;
617f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DynamicValueRelocTable;
618f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t CHPEMetadataPointer;
619f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardRFFailureRoutine;
620f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardRFFailureRoutineFunctionPointer;
621f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DynamicValueRelocTableOffset;
622f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t DynamicValueRelocTableSection;
623f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Reserved2;
624f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardRFVerifyStackPointerFunctionPointer;
625f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t HotPatchTableOffset;
626f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
627f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
628f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// 64-bit load config (IMAGE_LOAD_CONFIG_DIRECTORY64)
629f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_load_configuration64 {
630f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Size;
631f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
632f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorVersion;
633f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorVersion;
634f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GlobalFlagsClear;
635f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GlobalFlagsSet;
636f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t CriticalSectionDefaultTimeout;
637f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t DeCommitFreeBlockThreshold;
638f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t DeCommitTotalFreeThreshold;
639f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t LockPrefixTable;
640f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t MaximumAllocationSize;
641f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t VirtualMemoryThreshold;
642f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t ProcessAffinityMask;
643f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t ProcessHeapFlags;
644f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t CSDVersion;
645f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t DependentLoadFlags;
646f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t EditList;
647f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t SecurityCookie;
648f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t SEHandlerTable;
649f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t SEHandlerCount;
650f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
651f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Added in MSVC 2015 for /guard:cf.
652f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardCFCheckFunction;
653f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardCFCheckDispatch;
654f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardCFFunctionTable;
655f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardCFFunctionCount;
656f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t GuardFlags;
657f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
658f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Added in MSVC 2017
659f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  coff_load_config_code_integrity CodeIntegrity;
660f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardAddressTakenIatEntryTable;
661f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardAddressTakenIatEntryCount;
662f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardLongJumpTargetTable;
663f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardLongJumpTargetCount;
664f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t DynamicValueRelocTable;
665f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t CHPEMetadataPointer;
666f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardRFFailureRoutine;
667f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardRFFailureRoutineFunctionPointer;
668f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DynamicValueRelocTableOffset;
669f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t DynamicValueRelocTableSection;
670f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Reserved2;
671f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle64_t GuardRFVerifyStackPointerFunctionPointer;
672f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t HotPatchTableOffset;
673f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
674f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
675f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_runtime_function_x64 {
676f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t BeginAddress;
677f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t EndAddress;
678f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t UnwindInformation;
679f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
680f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
681f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_base_reloc_block_header {
682f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t PageRVA;
683f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t BlockSize;
684f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
685f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
686f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_base_reloc_block_entry {
687f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Data;
688f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
689f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int getType() const { return Data >> 12; }
690f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int getOffset() const { return Data & ((1 << 12) - 1); }
691f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
692f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
693f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_resource_dir_entry {
694f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  union {
695f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    support::ulittle32_t NameOffset;
696f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    support::ulittle32_t ID;
697f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    uint32_t getNameOffset() const {
698f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return maskTrailingOnes<uint32_t>(31) & NameOffset;
699f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
700f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // Even though the PE/COFF spec doesn't mention this, the high bit of a name
701f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // offset is set.
702f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void setNameOffset(uint32_t Offset) { NameOffset = Offset | (1 << 31); }
703f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  } Identifier;
704f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  union {
705f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    support::ulittle32_t DataEntryOffset;
706f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    support::ulittle32_t SubdirOffset;
707f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
708f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool isSubDir() const { return SubdirOffset >> 31; }
709f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    uint32_t value() const {
710f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return maskTrailingOnes<uint32_t>(31) & SubdirOffset;
711f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
712f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
713f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  } Offset;
714f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
715f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
716f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_resource_data_entry {
717f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DataRVA;
718f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t DataSize;
719f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Codepage;
720f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Reserved;
721f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
722f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
723f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct coff_resource_dir_table {
724f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Characteristics;
725f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t TimeDateStamp;
726f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MajorVersion;
727f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t MinorVersion;
728f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberOfNameEntries;
729f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumberOfIDEntries;
730f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
731f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
732f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass COFFObjectFile : public ObjectFile {
733f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
734f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  friend class ImportDirectoryEntryRef;
735f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  friend class ExportDirectoryEntryRef;
736f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_file_header *COFFHeader;
737f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_bigobj_file_header *COFFBigObjHeader;
738f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const pe32_header *PE32Header;
739f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const pe32plus_header *PE32PlusHeader;
740f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const data_directory *DataDirectory;
741f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_section *SectionTable;
742f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_symbol16 *SymbolTable16;
743f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_symbol32 *SymbolTable32;
744f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const char *StringTable;
745f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t StringTableSize;
746f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_import_directory_table_entry *ImportDirectory;
747f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const delay_import_directory_table_entry *DelayImportDirectory;
748f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t NumberOfDelayImportDirectory;
749f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const export_directory_table_entry *ExportDirectory;
750f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_base_reloc_block_header *BaseRelocHeader;
751f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_base_reloc_block_header *BaseRelocEnd;
752f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const debug_directory *DebugDirectoryBegin;
753f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const debug_directory *DebugDirectoryEnd;
754f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Either coff_load_configuration32 or coff_load_configuration64.
755f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const void *LoadConfig = nullptr;
756f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
757f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getString(uint32_t offset, StringRef &Res) const;
758f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
759f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  template <typename coff_symbol_type>
760f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_symbol_type *toSymb(DataRefImpl Symb) const;
761f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_section *toSec(DataRefImpl Sec) const;
762f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_relocation *toRel(DataRefImpl Rel) const;
763f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
764f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code initSymbolTablePtr();
765f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code initImportTablePtr();
766f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code initDelayImportTablePtr();
767f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code initExportTablePtr();
768f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code initBaseRelocPtr();
769f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code initDebugDirectoryPtr();
770f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code initLoadConfigPtr();
771f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
772f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
773f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uintptr_t getSymbolTable() const {
774f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (SymbolTable16)
775f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return reinterpret_cast<uintptr_t>(SymbolTable16);
776f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (SymbolTable32)
777f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return reinterpret_cast<uintptr_t>(SymbolTable32);
778f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return uintptr_t(0);
779f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
780f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
781f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint16_t getMachine() const {
782f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFHeader)
783f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFHeader->Machine;
784f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFBigObjHeader)
785f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFBigObjHeader->Machine;
786f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("no COFF header!");
787f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
788f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
789f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint16_t getSizeOfOptionalHeader() const {
790f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFHeader)
791f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFHeader->isImportLibrary() ? 0
792f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                           : COFFHeader->SizeOfOptionalHeader;
793f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // bigobj doesn't have this field.
794f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFBigObjHeader)
795f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return 0;
796f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("no COFF header!");
797f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
798f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
799f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint16_t getCharacteristics() const {
800f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFHeader)
801f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFHeader->isImportLibrary() ? 0 : COFFHeader->Characteristics;
802f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // bigobj doesn't have characteristics to speak of,
803f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // editbin will silently lie to you if you attempt to set any.
804f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFBigObjHeader)
805f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return 0;
806f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("no COFF header!");
807f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
808f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
809f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getTimeDateStamp() const {
810f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFHeader)
811f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFHeader->TimeDateStamp;
812f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFBigObjHeader)
813f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFBigObjHeader->TimeDateStamp;
814f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("no COFF header!");
815f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
816f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
817f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getNumberOfSections() const {
818f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFHeader)
819f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFHeader->isImportLibrary() ? 0 : COFFHeader->NumberOfSections;
820f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFBigObjHeader)
821f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFBigObjHeader->NumberOfSections;
822f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("no COFF header!");
823f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
824f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
825f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getPointerToSymbolTable() const {
826f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFHeader)
827f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFHeader->isImportLibrary() ? 0
828f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                           : COFFHeader->PointerToSymbolTable;
829f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFBigObjHeader)
830f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFBigObjHeader->PointerToSymbolTable;
831f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("no COFF header!");
832f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
833f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
834f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getRawNumberOfSymbols() const {
835f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFHeader)
836f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFHeader->isImportLibrary() ? 0 : COFFHeader->NumberOfSymbols;
837f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFBigObjHeader)
838f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFBigObjHeader->NumberOfSymbols;
839f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("no COFF header!");
840f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
841f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
842f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getNumberOfSymbols() const {
843f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!SymbolTable16 && !SymbolTable32)
844f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return 0;
845f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getRawNumberOfSymbols();
846f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
847f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
848f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_load_configuration32 *getLoadConfig32() const {
849f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(!is64());
850f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return reinterpret_cast<const coff_load_configuration32 *>(LoadConfig);
851f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
852f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
853f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_load_configuration64 *getLoadConfig64() const {
854f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(is64());
855f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return reinterpret_cast<const coff_load_configuration64 *>(LoadConfig);
856f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
857f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
858f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprotected:
859f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void moveSymbolNext(DataRefImpl &Symb) const override;
860f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
861f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
862f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
863f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
864f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
865f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t getSymbolFlags(DataRefImpl Symb) const override;
866f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
867f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
868f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void moveSectionNext(DataRefImpl &Sec) const override;
869f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSectionName(DataRefImpl Sec,
870f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                 StringRef &Res) const override;
871f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getSectionAddress(DataRefImpl Sec) const override;
872f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getSectionIndex(DataRefImpl Sec) const override;
873f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getSectionSize(DataRefImpl Sec) const override;
874f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSectionContents(DataRefImpl Sec,
875f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                     StringRef &Res) const override;
876f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getSectionAlignment(DataRefImpl Sec) const override;
877f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isSectionCompressed(DataRefImpl Sec) const override;
878f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isSectionText(DataRefImpl Sec) const override;
879f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isSectionData(DataRefImpl Sec) const override;
880f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isSectionBSS(DataRefImpl Sec) const override;
881f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isSectionVirtual(DataRefImpl Sec) const override;
882f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
883f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  relocation_iterator section_rel_end(DataRefImpl Sec) const override;
884f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
885f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void moveRelocationNext(DataRefImpl &Rel) const override;
886f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
887f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
888f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getRelocationType(DataRefImpl Rel) const override;
889f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void getRelocationTypeName(DataRefImpl Rel,
890f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                             SmallVectorImpl<char> &Result) const override;
891f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
892f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
893f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  COFFObjectFile(MemoryBufferRef Object, std::error_code &EC);
894f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
895f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  basic_symbol_iterator symbol_begin() const override;
896f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  basic_symbol_iterator symbol_end() const override;
897f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  section_iterator section_begin() const override;
898f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  section_iterator section_end() const override;
899f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
900f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_section *getCOFFSection(const SectionRef &Section) const;
901f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  COFFSymbolRef getCOFFSymbol(const DataRefImpl &Ref) const;
902f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  COFFSymbolRef getCOFFSymbol(const SymbolRef &Symbol) const;
903f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_relocation *getCOFFRelocation(const RelocationRef &Reloc) const;
904f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned getSectionID(SectionRef Sec) const;
905f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned getSymbolSectionID(SymbolRef Sym) const;
906f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
907f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint8_t getBytesInAddress() const override;
908f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  StringRef getFileFormatName() const override;
909f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned getArch() const override;
910f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
911f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
912f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  import_directory_iterator import_directory_begin() const;
913f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  import_directory_iterator import_directory_end() const;
914f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  delay_import_directory_iterator delay_import_directory_begin() const;
915f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  delay_import_directory_iterator delay_import_directory_end() const;
916f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  export_directory_iterator export_directory_begin() const;
917f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  export_directory_iterator export_directory_end() const;
918f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  base_reloc_iterator base_reloc_begin() const;
919f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  base_reloc_iterator base_reloc_end() const;
920f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const debug_directory *debug_directory_begin() const {
921f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return DebugDirectoryBegin;
922f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
923f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const debug_directory *debug_directory_end() const {
924f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return DebugDirectoryEnd;
925f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
926f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
927f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<import_directory_iterator> import_directories() const;
928f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<delay_import_directory_iterator>
929f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      delay_import_directories() const;
930f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<export_directory_iterator> export_directories() const;
931f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<base_reloc_iterator> base_relocs() const;
932f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<const debug_directory *> debug_directories() const {
933f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return make_range(debug_directory_begin(), debug_directory_end());
934f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
935f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
936f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const dos_header *getDOSHeader() const {
937f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!PE32Header && !PE32PlusHeader)
938f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return nullptr;
939f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return reinterpret_cast<const dos_header *>(base());
940f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
941f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getPE32Header(const pe32_header *&Res) const;
942f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getPE32PlusHeader(const pe32plus_header *&Res) const;
943f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getDataDirectory(uint32_t index,
944f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                   const data_directory *&Res) const;
945f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSection(int32_t index, const coff_section *&Res) const;
946f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
947f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  template <typename coff_symbol_type>
948f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSymbol(uint32_t Index,
949f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                            const coff_symbol_type *&Res) const {
950f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (Index >= getNumberOfSymbols())
951f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return object_error::parse_failed;
952f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
953f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Res = reinterpret_cast<coff_symbol_type *>(getSymbolTable()) + Index;
954f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return std::error_code();
955f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
956f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<COFFSymbolRef> getSymbol(uint32_t index) const {
957f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (SymbolTable16) {
958f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      const coff_symbol16 *Symb = nullptr;
959f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (std::error_code EC = getSymbol(index, Symb))
960f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        return errorCodeToError(EC);
961f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFSymbolRef(Symb);
962f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
963f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (SymbolTable32) {
964f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      const coff_symbol32 *Symb = nullptr;
965f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (std::error_code EC = getSymbol(index, Symb))
966f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        return errorCodeToError(EC);
967f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return COFFSymbolRef(Symb);
968f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
969f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return errorCodeToError(object_error::parse_failed);
970f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
971f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
972f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  template <typename T>
973f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getAuxSymbol(uint32_t index, const T *&Res) const {
974f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Expected<COFFSymbolRef> S = getSymbol(index);
975f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (Error E = S.takeError())
976f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return errorToErrorCode(std::move(E));
977f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Res = reinterpret_cast<const T *>(S->getRawPtr());
978f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return std::error_code();
979f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
980f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
981f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSymbolName(COFFSymbolRef Symbol, StringRef &Res) const;
982f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSymbolName(const coff_symbol_generic *Symbol,
983f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                StringRef &Res) const;
984f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
985f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ArrayRef<uint8_t> getSymbolAuxData(COFFSymbolRef Symbol) const;
986f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
987f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  size_t getSymbolTableEntrySize() const {
988f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFHeader)
989f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return sizeof(coff_symbol16);
990f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (COFFBigObjHeader)
991f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return sizeof(coff_symbol32);
992f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm_unreachable("null symbol table pointer!");
993f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
994f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
995f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<const coff_relocation *>
996f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getRelocations(const coff_section *Sec) const;
997f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
998f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSectionName(const coff_section *Sec, StringRef &Res) const;
999f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getSectionSize(const coff_section *Sec) const;
1000f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSectionContents(const coff_section *Sec,
1001f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                     ArrayRef<uint8_t> &Res) const;
1002f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1003f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint64_t getImageBase() const;
1004f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getVaPtr(uint64_t VA, uintptr_t &Res) const;
1005f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getRvaPtr(uint32_t Rva, uintptr_t &Res) const;
1006f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1007f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Given an RVA base and size, returns a valid array of bytes or an error
1008f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// code if the RVA and size is not contained completely within a valid
1009f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// section.
1010f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getRvaAndSizeAsBytes(uint32_t RVA, uint32_t Size,
1011f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                       ArrayRef<uint8_t> &Contents) const;
1012f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1013f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getHintName(uint32_t Rva, uint16_t &Hint,
1014f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                              StringRef &Name) const;
1015f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1016f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Get PDB information out of a codeview debug directory entry.
1017f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getDebugPDBInfo(const debug_directory *DebugDir,
1018f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                  const codeview::DebugInfo *&Info,
1019f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                  StringRef &PDBFileName) const;
1020f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1021f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Get PDB information from an executable. If the information is not present,
1022f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Info will be set to nullptr and PDBFileName will be empty. An error is
1023f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// returned only on corrupt object files. Convenience accessor that can be
1024f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// used if the debug directory is not already handy.
1025f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getDebugPDBInfo(const codeview::DebugInfo *&Info,
1026f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                  StringRef &PDBFileName) const;
1027f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1028f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isRelocatableObject() const override;
1029f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool is64() const { return PE32PlusHeader; }
1030f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1031f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static bool classof(const Binary *v) { return v->isCOFF(); }
1032f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
1033f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1034f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// The iterator for the import directory table.
1035f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ImportDirectoryEntryRef {
1036f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
1037f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ImportDirectoryEntryRef() = default;
1038f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ImportDirectoryEntryRef(const coff_import_directory_table_entry *Table,
1039f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                          uint32_t I, const COFFObjectFile *Owner)
1040f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      : ImportTable(Table), Index(I), OwningObject(Owner) {}
1041f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1042f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool operator==(const ImportDirectoryEntryRef &Other) const;
1043f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void moveNext();
1044f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1045f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  imported_symbol_iterator imported_symbol_begin() const;
1046f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  imported_symbol_iterator imported_symbol_end() const;
1047f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<imported_symbol_iterator> imported_symbols() const;
1048f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1049f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  imported_symbol_iterator lookup_table_begin() const;
1050f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  imported_symbol_iterator lookup_table_end() const;
1051f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<imported_symbol_iterator> lookup_table_symbols() const;
1052f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1053f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getName(StringRef &Result) const;
1054f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getImportLookupTableRVA(uint32_t &Result) const;
1055f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getImportAddressTableRVA(uint32_t &Result) const;
1056f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1057f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code
1058f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getImportTableEntry(const coff_import_directory_table_entry *&Result) const;
1059f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1060f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
1061f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_import_directory_table_entry *ImportTable;
1062f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t Index;
1063f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const COFFObjectFile *OwningObject = nullptr;
1064f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
1065f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1066f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass DelayImportDirectoryEntryRef {
1067f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
1068f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DelayImportDirectoryEntryRef() = default;
1069f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DelayImportDirectoryEntryRef(const delay_import_directory_table_entry *T,
1070f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                               uint32_t I, const COFFObjectFile *Owner)
1071f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      : Table(T), Index(I), OwningObject(Owner) {}
1072f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1073f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool operator==(const DelayImportDirectoryEntryRef &Other) const;
1074f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void moveNext();
1075f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1076f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  imported_symbol_iterator imported_symbol_begin() const;
1077f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  imported_symbol_iterator imported_symbol_end() const;
1078f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  iterator_range<imported_symbol_iterator> imported_symbols() const;
1079f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1080f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getName(StringRef &Result) const;
1081f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getDelayImportTable(
1082f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      const delay_import_directory_table_entry *&Result) const;
1083f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getImportAddress(int AddrIndex, uint64_t &Result) const;
1084f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1085f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
1086f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const delay_import_directory_table_entry *Table;
1087f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t Index;
1088f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const COFFObjectFile *OwningObject = nullptr;
1089f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
1090f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1091f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// The iterator for the export directory table entry.
1092f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ExportDirectoryEntryRef {
1093f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
1094f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ExportDirectoryEntryRef() = default;
1095f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ExportDirectoryEntryRef(const export_directory_table_entry *Table, uint32_t I,
1096f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                          const COFFObjectFile *Owner)
1097f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      : ExportTable(Table), Index(I), OwningObject(Owner) {}
1098f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1099f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool operator==(const ExportDirectoryEntryRef &Other) const;
1100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void moveNext();
1101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getDllName(StringRef &Result) const;
1103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getOrdinalBase(uint32_t &Result) const;
1104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getOrdinal(uint32_t &Result) const;
1105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getExportRVA(uint32_t &Result) const;
1106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSymbolName(StringRef &Result) const;
1107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code isForwarder(bool &Result) const;
1109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getForwardTo(StringRef &Result) const;
1110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
1112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const export_directory_table_entry *ExportTable;
1113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t Index;
1114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const COFFObjectFile *OwningObject = nullptr;
1115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
1116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ImportedSymbolRef {
1118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
1119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ImportedSymbolRef() = default;
1120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ImportedSymbolRef(const import_lookup_table_entry32 *Entry, uint32_t I,
1121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    const COFFObjectFile *Owner)
1122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      : Entry32(Entry), Entry64(nullptr), Index(I), OwningObject(Owner) {}
1123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ImportedSymbolRef(const import_lookup_table_entry64 *Entry, uint32_t I,
1124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    const COFFObjectFile *Owner)
1125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      : Entry32(nullptr), Entry64(Entry), Index(I), OwningObject(Owner) {}
1126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool operator==(const ImportedSymbolRef &Other) const;
1128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void moveNext();
1129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1130f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getSymbolName(StringRef &Result) const;
1131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code isOrdinal(bool &Result) const;
1132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getOrdinal(uint16_t &Result) const;
1133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getHintNameRVA(uint32_t &Result) const;
1134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
1136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const import_lookup_table_entry32 *Entry32;
1137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const import_lookup_table_entry64 *Entry64;
1138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t Index;
1139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const COFFObjectFile *OwningObject = nullptr;
1140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
1141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass BaseRelocRef {
1143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
1144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  BaseRelocRef() = default;
1145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  BaseRelocRef(const coff_base_reloc_block_header *Header,
1146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot               const COFFObjectFile *Owner)
1147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      : Header(Header), Index(0), OwningObject(Owner) {}
1148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool operator==(const BaseRelocRef &Other) const;
1150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void moveNext();
1151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getType(uint8_t &Type) const;
1153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::error_code getRVA(uint32_t &Result) const;
1154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
1156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const coff_base_reloc_block_header *Header;
1157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  uint32_t Index;
1158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const COFFObjectFile *OwningObject = nullptr;
1159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
1160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ResourceSectionRef {
1162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
1163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ResourceSectionRef() = default;
1164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  explicit ResourceSectionRef(StringRef Ref) : BBS(Ref, support::little) {}
1165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<ArrayRef<UTF16>>
1167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getEntryNameString(const coff_resource_dir_entry &Entry);
1168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<const coff_resource_dir_table &>
1169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getEntrySubDir(const coff_resource_dir_entry &Entry);
1170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<const coff_resource_dir_table &> getBaseTable();
1171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
1173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  BinaryByteStream BBS;
1174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<const coff_resource_dir_table &> getTableAtOffset(uint32_t Offset);
1176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Expected<ArrayRef<UTF16>> getDirStringAtOffset(uint32_t Offset);
1177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
1178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// Corresponds to `_FPO_DATA` structure in the PE/COFF spec.
1180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotstruct FpoData {
1181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Offset; // ulOffStart: Offset 1st byte of function code
1182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t Size;   // cbProcSize: # bytes in function
1183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle32_t NumLocals; // cdwLocals: # bytes in locals/4
1184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t NumParams; // cdwParams: # bytes in params/4
1185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  support::ulittle16_t Attributes;
1186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // cbProlog: # bytes in prolog
1188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int getPrologSize() const { return Attributes & 0xF; }
1189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // cbRegs: # regs saved
1191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int getNumSavedRegs() const { return (Attributes >> 8) & 0x7; }
1192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // fHasSEH: true if seh is func
1194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool hasSEH() const { return (Attributes >> 9) & 1; }
1195f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1196f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // fUseBP: true if EBP has been allocated
1197f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool useBP() const { return (Attributes >> 10) & 1; }
1198f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1199f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // cbFrame: frame pointer
1200f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  int getFP() const { return Attributes >> 14; }
1201f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
1202f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1203f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} // end namespace object
1204f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1205f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} // end namespace llvm
1206f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
1207f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#endif // LLVM_OBJECT_COFF_H
1208