1 //===- COFFYAML.cpp - COFF YAMLIO implementation --------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines classes for handling the YAML representation of COFF.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ObjectYAML/COFFYAML.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/YAMLTraits.h"
19 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
25 Section::Section() { memset(&Header
, 0, sizeof(COFF::section
)); }
26 Symbol::Symbol() { memset(&Header
, 0, sizeof(COFF::symbol
)); }
27 Object::Object() { memset(&Header
, 0, sizeof(COFF::header
)); }
29 } // end namespace COFFYAML
33 void ScalarEnumerationTraits
<COFFYAML::COMDATType
>::enumeration(
34 IO
&IO
, COFFYAML::COMDATType
&Value
) {
35 IO
.enumCase(Value
, "0", 0);
36 ECase(IMAGE_COMDAT_SELECT_NODUPLICATES
);
37 ECase(IMAGE_COMDAT_SELECT_ANY
);
38 ECase(IMAGE_COMDAT_SELECT_SAME_SIZE
);
39 ECase(IMAGE_COMDAT_SELECT_EXACT_MATCH
);
40 ECase(IMAGE_COMDAT_SELECT_ASSOCIATIVE
);
41 ECase(IMAGE_COMDAT_SELECT_LARGEST
);
42 ECase(IMAGE_COMDAT_SELECT_NEWEST
);
46 ScalarEnumerationTraits
<COFFYAML::WeakExternalCharacteristics
>::enumeration(
47 IO
&IO
, COFFYAML::WeakExternalCharacteristics
&Value
) {
48 IO
.enumCase(Value
, "0", 0);
49 ECase(IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY
);
50 ECase(IMAGE_WEAK_EXTERN_SEARCH_LIBRARY
);
51 ECase(IMAGE_WEAK_EXTERN_SEARCH_ALIAS
);
52 ECase(IMAGE_WEAK_EXTERN_ANTI_DEPENDENCY
);
55 void ScalarEnumerationTraits
<COFFYAML::AuxSymbolType
>::enumeration(
56 IO
&IO
, COFFYAML::AuxSymbolType
&Value
) {
57 ECase(IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF
);
60 void ScalarEnumerationTraits
<COFF::MachineTypes
>::enumeration(
61 IO
&IO
, COFF::MachineTypes
&Value
) {
62 ECase(IMAGE_FILE_MACHINE_UNKNOWN
);
63 ECase(IMAGE_FILE_MACHINE_AM33
);
64 ECase(IMAGE_FILE_MACHINE_AMD64
);
65 ECase(IMAGE_FILE_MACHINE_ARM
);
66 ECase(IMAGE_FILE_MACHINE_ARMNT
);
67 ECase(IMAGE_FILE_MACHINE_ARM64
);
68 ECase(IMAGE_FILE_MACHINE_ARM64EC
);
69 ECase(IMAGE_FILE_MACHINE_ARM64X
);
70 ECase(IMAGE_FILE_MACHINE_EBC
);
71 ECase(IMAGE_FILE_MACHINE_I386
);
72 ECase(IMAGE_FILE_MACHINE_IA64
);
73 ECase(IMAGE_FILE_MACHINE_M32R
);
74 ECase(IMAGE_FILE_MACHINE_MIPS16
);
75 ECase(IMAGE_FILE_MACHINE_MIPSFPU
);
76 ECase(IMAGE_FILE_MACHINE_MIPSFPU16
);
77 ECase(IMAGE_FILE_MACHINE_POWERPC
);
78 ECase(IMAGE_FILE_MACHINE_POWERPCFP
);
79 ECase(IMAGE_FILE_MACHINE_R4000
);
80 ECase(IMAGE_FILE_MACHINE_RISCV32
);
81 ECase(IMAGE_FILE_MACHINE_RISCV64
);
82 ECase(IMAGE_FILE_MACHINE_RISCV128
);
83 ECase(IMAGE_FILE_MACHINE_SH3
);
84 ECase(IMAGE_FILE_MACHINE_SH3DSP
);
85 ECase(IMAGE_FILE_MACHINE_SH4
);
86 ECase(IMAGE_FILE_MACHINE_SH5
);
87 ECase(IMAGE_FILE_MACHINE_THUMB
);
88 ECase(IMAGE_FILE_MACHINE_WCEMIPSV2
);
91 void ScalarEnumerationTraits
<COFF::SymbolBaseType
>::enumeration(
92 IO
&IO
, COFF::SymbolBaseType
&Value
) {
93 ECase(IMAGE_SYM_TYPE_NULL
);
94 ECase(IMAGE_SYM_TYPE_VOID
);
95 ECase(IMAGE_SYM_TYPE_CHAR
);
96 ECase(IMAGE_SYM_TYPE_SHORT
);
97 ECase(IMAGE_SYM_TYPE_INT
);
98 ECase(IMAGE_SYM_TYPE_LONG
);
99 ECase(IMAGE_SYM_TYPE_FLOAT
);
100 ECase(IMAGE_SYM_TYPE_DOUBLE
);
101 ECase(IMAGE_SYM_TYPE_STRUCT
);
102 ECase(IMAGE_SYM_TYPE_UNION
);
103 ECase(IMAGE_SYM_TYPE_ENUM
);
104 ECase(IMAGE_SYM_TYPE_MOE
);
105 ECase(IMAGE_SYM_TYPE_BYTE
);
106 ECase(IMAGE_SYM_TYPE_WORD
);
107 ECase(IMAGE_SYM_TYPE_UINT
);
108 ECase(IMAGE_SYM_TYPE_DWORD
);
111 void ScalarEnumerationTraits
<COFF::SymbolStorageClass
>::enumeration(
112 IO
&IO
, COFF::SymbolStorageClass
&Value
) {
113 ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION
);
114 ECase(IMAGE_SYM_CLASS_NULL
);
115 ECase(IMAGE_SYM_CLASS_AUTOMATIC
);
116 ECase(IMAGE_SYM_CLASS_EXTERNAL
);
117 ECase(IMAGE_SYM_CLASS_STATIC
);
118 ECase(IMAGE_SYM_CLASS_REGISTER
);
119 ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF
);
120 ECase(IMAGE_SYM_CLASS_LABEL
);
121 ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL
);
122 ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT
);
123 ECase(IMAGE_SYM_CLASS_ARGUMENT
);
124 ECase(IMAGE_SYM_CLASS_STRUCT_TAG
);
125 ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION
);
126 ECase(IMAGE_SYM_CLASS_UNION_TAG
);
127 ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION
);
128 ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC
);
129 ECase(IMAGE_SYM_CLASS_ENUM_TAG
);
130 ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM
);
131 ECase(IMAGE_SYM_CLASS_REGISTER_PARAM
);
132 ECase(IMAGE_SYM_CLASS_BIT_FIELD
);
133 ECase(IMAGE_SYM_CLASS_BLOCK
);
134 ECase(IMAGE_SYM_CLASS_FUNCTION
);
135 ECase(IMAGE_SYM_CLASS_END_OF_STRUCT
);
136 ECase(IMAGE_SYM_CLASS_FILE
);
137 ECase(IMAGE_SYM_CLASS_SECTION
);
138 ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL
);
139 ECase(IMAGE_SYM_CLASS_CLR_TOKEN
);
142 void ScalarEnumerationTraits
<COFF::SymbolComplexType
>::enumeration(
143 IO
&IO
, COFF::SymbolComplexType
&Value
) {
144 ECase(IMAGE_SYM_DTYPE_NULL
);
145 ECase(IMAGE_SYM_DTYPE_POINTER
);
146 ECase(IMAGE_SYM_DTYPE_FUNCTION
);
147 ECase(IMAGE_SYM_DTYPE_ARRAY
);
150 void ScalarEnumerationTraits
<COFF::RelocationTypeI386
>::enumeration(
151 IO
&IO
, COFF::RelocationTypeI386
&Value
) {
152 ECase(IMAGE_REL_I386_ABSOLUTE
);
153 ECase(IMAGE_REL_I386_DIR16
);
154 ECase(IMAGE_REL_I386_REL16
);
155 ECase(IMAGE_REL_I386_DIR32
);
156 ECase(IMAGE_REL_I386_DIR32NB
);
157 ECase(IMAGE_REL_I386_SEG12
);
158 ECase(IMAGE_REL_I386_SECTION
);
159 ECase(IMAGE_REL_I386_SECREL
);
160 ECase(IMAGE_REL_I386_TOKEN
);
161 ECase(IMAGE_REL_I386_SECREL7
);
162 ECase(IMAGE_REL_I386_REL32
);
165 void ScalarEnumerationTraits
<COFF::RelocationTypeAMD64
>::enumeration(
166 IO
&IO
, COFF::RelocationTypeAMD64
&Value
) {
167 ECase(IMAGE_REL_AMD64_ABSOLUTE
);
168 ECase(IMAGE_REL_AMD64_ADDR64
);
169 ECase(IMAGE_REL_AMD64_ADDR32
);
170 ECase(IMAGE_REL_AMD64_ADDR32NB
);
171 ECase(IMAGE_REL_AMD64_REL32
);
172 ECase(IMAGE_REL_AMD64_REL32_1
);
173 ECase(IMAGE_REL_AMD64_REL32_2
);
174 ECase(IMAGE_REL_AMD64_REL32_3
);
175 ECase(IMAGE_REL_AMD64_REL32_4
);
176 ECase(IMAGE_REL_AMD64_REL32_5
);
177 ECase(IMAGE_REL_AMD64_SECTION
);
178 ECase(IMAGE_REL_AMD64_SECREL
);
179 ECase(IMAGE_REL_AMD64_SECREL7
);
180 ECase(IMAGE_REL_AMD64_TOKEN
);
181 ECase(IMAGE_REL_AMD64_SREL32
);
182 ECase(IMAGE_REL_AMD64_PAIR
);
183 ECase(IMAGE_REL_AMD64_SSPAN32
);
186 void ScalarEnumerationTraits
<COFF::RelocationTypesMips
>::enumeration(
187 IO
&IO
, COFF::RelocationTypesMips
&Value
) {
188 ECase(IMAGE_REL_MIPS_ABSOLUTE
);
189 ECase(IMAGE_REL_MIPS_REFHALF
);
190 ECase(IMAGE_REL_MIPS_REFWORD
);
191 ECase(IMAGE_REL_MIPS_JMPADDR
);
192 ECase(IMAGE_REL_MIPS_REFHI
);
193 ECase(IMAGE_REL_MIPS_REFLO
);
194 ECase(IMAGE_REL_MIPS_GPREL
);
195 ECase(IMAGE_REL_MIPS_LITERAL
);
196 ECase(IMAGE_REL_MIPS_SECTION
);
197 ECase(IMAGE_REL_MIPS_SECREL
);
198 ECase(IMAGE_REL_MIPS_SECRELLO
);
199 ECase(IMAGE_REL_MIPS_SECRELHI
);
200 ECase(IMAGE_REL_MIPS_JMPADDR16
);
201 ECase(IMAGE_REL_MIPS_REFWORDNB
);
202 ECase(IMAGE_REL_MIPS_PAIR
);
205 void ScalarEnumerationTraits
<COFF::RelocationTypesARM
>::enumeration(
206 IO
&IO
, COFF::RelocationTypesARM
&Value
) {
207 ECase(IMAGE_REL_ARM_ABSOLUTE
);
208 ECase(IMAGE_REL_ARM_ADDR32
);
209 ECase(IMAGE_REL_ARM_ADDR32NB
);
210 ECase(IMAGE_REL_ARM_BRANCH24
);
211 ECase(IMAGE_REL_ARM_BRANCH11
);
212 ECase(IMAGE_REL_ARM_TOKEN
);
213 ECase(IMAGE_REL_ARM_BLX24
);
214 ECase(IMAGE_REL_ARM_BLX11
);
215 ECase(IMAGE_REL_ARM_REL32
);
216 ECase(IMAGE_REL_ARM_SECTION
);
217 ECase(IMAGE_REL_ARM_SECREL
);
218 ECase(IMAGE_REL_ARM_MOV32A
);
219 ECase(IMAGE_REL_ARM_MOV32T
);
220 ECase(IMAGE_REL_ARM_BRANCH20T
);
221 ECase(IMAGE_REL_ARM_BRANCH24T
);
222 ECase(IMAGE_REL_ARM_BLX23T
);
223 ECase(IMAGE_REL_ARM_PAIR
);
226 void ScalarEnumerationTraits
<COFF::RelocationTypesARM64
>::enumeration(
227 IO
&IO
, COFF::RelocationTypesARM64
&Value
) {
228 ECase(IMAGE_REL_ARM64_ABSOLUTE
);
229 ECase(IMAGE_REL_ARM64_ADDR32
);
230 ECase(IMAGE_REL_ARM64_ADDR32NB
);
231 ECase(IMAGE_REL_ARM64_BRANCH26
);
232 ECase(IMAGE_REL_ARM64_PAGEBASE_REL21
);
233 ECase(IMAGE_REL_ARM64_REL21
);
234 ECase(IMAGE_REL_ARM64_PAGEOFFSET_12A
);
235 ECase(IMAGE_REL_ARM64_PAGEOFFSET_12L
);
236 ECase(IMAGE_REL_ARM64_SECREL
);
237 ECase(IMAGE_REL_ARM64_SECREL_LOW12A
);
238 ECase(IMAGE_REL_ARM64_SECREL_HIGH12A
);
239 ECase(IMAGE_REL_ARM64_SECREL_LOW12L
);
240 ECase(IMAGE_REL_ARM64_TOKEN
);
241 ECase(IMAGE_REL_ARM64_SECTION
);
242 ECase(IMAGE_REL_ARM64_ADDR64
);
243 ECase(IMAGE_REL_ARM64_BRANCH19
);
244 ECase(IMAGE_REL_ARM64_BRANCH14
);
245 ECase(IMAGE_REL_ARM64_REL32
);
248 void ScalarEnumerationTraits
<COFF::WindowsSubsystem
>::enumeration(
249 IO
&IO
, COFF::WindowsSubsystem
&Value
) {
250 ECase(IMAGE_SUBSYSTEM_UNKNOWN
);
251 ECase(IMAGE_SUBSYSTEM_NATIVE
);
252 ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI
);
253 ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI
);
254 ECase(IMAGE_SUBSYSTEM_OS2_CUI
);
255 ECase(IMAGE_SUBSYSTEM_POSIX_CUI
);
256 ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS
);
257 ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI
);
258 ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION
);
259 ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
);
260 ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
);
261 ECase(IMAGE_SUBSYSTEM_EFI_ROM
);
262 ECase(IMAGE_SUBSYSTEM_XBOX
);
263 ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION
);
267 #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
268 void ScalarBitSetTraits
<COFF::Characteristics
>::bitset(
269 IO
&IO
, COFF::Characteristics
&Value
) {
270 BCase(IMAGE_FILE_RELOCS_STRIPPED
);
271 BCase(IMAGE_FILE_EXECUTABLE_IMAGE
);
272 BCase(IMAGE_FILE_LINE_NUMS_STRIPPED
);
273 BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED
);
274 BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM
);
275 BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE
);
276 BCase(IMAGE_FILE_BYTES_REVERSED_LO
);
277 BCase(IMAGE_FILE_32BIT_MACHINE
);
278 BCase(IMAGE_FILE_DEBUG_STRIPPED
);
279 BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP
);
280 BCase(IMAGE_FILE_NET_RUN_FROM_SWAP
);
281 BCase(IMAGE_FILE_SYSTEM
);
282 BCase(IMAGE_FILE_DLL
);
283 BCase(IMAGE_FILE_UP_SYSTEM_ONLY
);
284 BCase(IMAGE_FILE_BYTES_REVERSED_HI
);
287 void ScalarBitSetTraits
<COFF::SectionCharacteristics
>::bitset(
288 IO
&IO
, COFF::SectionCharacteristics
&Value
) {
289 BCase(IMAGE_SCN_TYPE_NOLOAD
);
290 BCase(IMAGE_SCN_TYPE_NO_PAD
);
291 BCase(IMAGE_SCN_CNT_CODE
);
292 BCase(IMAGE_SCN_CNT_INITIALIZED_DATA
);
293 BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA
);
294 BCase(IMAGE_SCN_LNK_OTHER
);
295 BCase(IMAGE_SCN_LNK_INFO
);
296 BCase(IMAGE_SCN_LNK_REMOVE
);
297 BCase(IMAGE_SCN_LNK_COMDAT
);
298 BCase(IMAGE_SCN_GPREL
);
299 BCase(IMAGE_SCN_MEM_PURGEABLE
);
300 BCase(IMAGE_SCN_MEM_16BIT
);
301 BCase(IMAGE_SCN_MEM_LOCKED
);
302 BCase(IMAGE_SCN_MEM_PRELOAD
);
303 BCase(IMAGE_SCN_LNK_NRELOC_OVFL
);
304 BCase(IMAGE_SCN_MEM_DISCARDABLE
);
305 BCase(IMAGE_SCN_MEM_NOT_CACHED
);
306 BCase(IMAGE_SCN_MEM_NOT_PAGED
);
307 BCase(IMAGE_SCN_MEM_SHARED
);
308 BCase(IMAGE_SCN_MEM_EXECUTE
);
309 BCase(IMAGE_SCN_MEM_READ
);
310 BCase(IMAGE_SCN_MEM_WRITE
);
313 void ScalarBitSetTraits
<COFF::DLLCharacteristics
>::bitset(
314 IO
&IO
, COFF::DLLCharacteristics
&Value
) {
315 BCase(IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
);
316 BCase(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
);
317 BCase(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY
);
318 BCase(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT
);
319 BCase(IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION
);
320 BCase(IMAGE_DLL_CHARACTERISTICS_NO_SEH
);
321 BCase(IMAGE_DLL_CHARACTERISTICS_NO_BIND
);
322 BCase(IMAGE_DLL_CHARACTERISTICS_APPCONTAINER
);
323 BCase(IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER
);
324 BCase(IMAGE_DLL_CHARACTERISTICS_GUARD_CF
);
325 BCase(IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE
);
331 struct NSectionSelectionType
{
332 NSectionSelectionType(IO
&)
333 : SelectionType(COFFYAML::COMDATType(0)) {}
334 NSectionSelectionType(IO
&, uint8_t C
)
335 : SelectionType(COFFYAML::COMDATType(C
)) {}
337 uint8_t denormalize(IO
&) { return SelectionType
; }
339 COFFYAML::COMDATType SelectionType
;
342 struct NWeakExternalCharacteristics
{
343 NWeakExternalCharacteristics(IO
&)
344 : Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
345 NWeakExternalCharacteristics(IO
&, uint32_t C
)
346 : Characteristics(COFFYAML::WeakExternalCharacteristics(C
)) {}
348 uint32_t denormalize(IO
&) { return Characteristics
; }
350 COFFYAML::WeakExternalCharacteristics Characteristics
;
353 struct NSectionCharacteristics
{
354 NSectionCharacteristics(IO
&)
355 : Characteristics(COFF::SectionCharacteristics(0)) {}
356 NSectionCharacteristics(IO
&, uint32_t C
)
357 : Characteristics(COFF::SectionCharacteristics(C
)) {}
359 uint32_t denormalize(IO
&) { return Characteristics
; }
361 COFF::SectionCharacteristics Characteristics
;
364 struct NAuxTokenType
{
366 : AuxType(COFFYAML::AuxSymbolType(0)) {}
367 NAuxTokenType(IO
&, uint8_t C
)
368 : AuxType(COFFYAML::AuxSymbolType(C
)) {}
370 uint32_t denormalize(IO
&) { return AuxType
; }
372 COFFYAML::AuxSymbolType AuxType
;
375 struct NStorageClass
{
376 NStorageClass(IO
&) : StorageClass(COFF::SymbolStorageClass(0)) {}
377 NStorageClass(IO
&, uint8_t S
) : StorageClass(COFF::SymbolStorageClass(S
)) {}
379 uint8_t denormalize(IO
&) { return StorageClass
; }
381 COFF::SymbolStorageClass StorageClass
;
385 NMachine(IO
&) : Machine(COFF::MachineTypes(0)) {}
386 NMachine(IO
&, uint16_t M
) : Machine(COFF::MachineTypes(M
)) {}
388 uint16_t denormalize(IO
&) { return Machine
; }
390 COFF::MachineTypes Machine
;
393 struct NHeaderCharacteristics
{
394 NHeaderCharacteristics(IO
&) : Characteristics(COFF::Characteristics(0)) {}
395 NHeaderCharacteristics(IO
&, uint16_t C
)
396 : Characteristics(COFF::Characteristics(C
)) {}
398 uint16_t denormalize(IO
&) { return Characteristics
; }
400 COFF::Characteristics Characteristics
;
403 template <typename RelocType
>
405 NType(IO
&) : Type(RelocType(0)) {}
406 NType(IO
&, uint16_t T
) : Type(RelocType(T
)) {}
408 uint16_t denormalize(IO
&) { return Type
; }
413 struct NWindowsSubsystem
{
414 NWindowsSubsystem(IO
&) : Subsystem(COFF::WindowsSubsystem(0)) {}
415 NWindowsSubsystem(IO
&, uint16_t C
) : Subsystem(COFF::WindowsSubsystem(C
)) {}
417 uint16_t denormalize(IO
&) { return Subsystem
; }
419 COFF::WindowsSubsystem Subsystem
;
422 struct NDLLCharacteristics
{
423 NDLLCharacteristics(IO
&) : Characteristics(COFF::DLLCharacteristics(0)) {}
424 NDLLCharacteristics(IO
&, uint16_t C
)
425 : Characteristics(COFF::DLLCharacteristics(C
)) {}
427 uint16_t denormalize(IO
&) { return Characteristics
; }
429 COFF::DLLCharacteristics Characteristics
;
432 } // end anonymous namespace
434 void MappingTraits
<COFFYAML::Relocation
>::mapping(IO
&IO
,
435 COFFYAML::Relocation
&Rel
) {
436 IO
.mapRequired("VirtualAddress", Rel
.VirtualAddress
);
437 IO
.mapOptional("SymbolName", Rel
.SymbolName
, StringRef());
438 IO
.mapOptional("SymbolTableIndex", Rel
.SymbolTableIndex
);
440 COFF::header
&H
= *static_cast<COFF::header
*>(IO
.getContext());
441 if (H
.Machine
== COFF::IMAGE_FILE_MACHINE_I386
) {
442 MappingNormalization
<NType
<COFF::RelocationTypeI386
>, uint16_t> NT(
444 IO
.mapRequired("Type", NT
->Type
);
445 } else if (H
.Machine
== COFF::IMAGE_FILE_MACHINE_AMD64
) {
446 MappingNormalization
<NType
<COFF::RelocationTypeAMD64
>, uint16_t> NT(
448 IO
.mapRequired("Type", NT
->Type
);
449 } else if (H
.Machine
== COFF::IMAGE_FILE_MACHINE_R4000
) {
450 MappingNormalization
<NType
<COFF::RelocationTypesMips
>, uint16_t> NT(
452 IO
.mapRequired("Type", NT
->Type
);
453 } else if (H
.Machine
== COFF::IMAGE_FILE_MACHINE_ARMNT
) {
454 MappingNormalization
<NType
<COFF::RelocationTypesARM
>, uint16_t> NT(
456 IO
.mapRequired("Type", NT
->Type
);
457 } else if (COFF::isAnyArm64(H
.Machine
)) {
458 MappingNormalization
<NType
<COFF::RelocationTypesARM64
>, uint16_t> NT(
460 IO
.mapRequired("Type", NT
->Type
);
462 IO
.mapRequired("Type", Rel
.Type
);
466 void MappingTraits
<COFF::DataDirectory
>::mapping(IO
&IO
,
467 COFF::DataDirectory
&DD
) {
468 IO
.mapRequired("RelativeVirtualAddress", DD
.RelativeVirtualAddress
);
469 IO
.mapRequired("Size", DD
.Size
);
472 void MappingTraits
<COFFYAML::PEHeader
>::mapping(IO
&IO
,
473 COFFYAML::PEHeader
&PH
) {
474 MappingNormalization
<NWindowsSubsystem
, uint16_t> NWS(IO
,
475 PH
.Header
.Subsystem
);
476 MappingNormalization
<NDLLCharacteristics
, uint16_t> NDC(
477 IO
, PH
.Header
.DLLCharacteristics
);
479 IO
.mapOptional("AddressOfEntryPoint", PH
.Header
.AddressOfEntryPoint
);
480 IO
.mapOptional("ImageBase", PH
.Header
.ImageBase
);
481 IO
.mapOptional("SectionAlignment", PH
.Header
.SectionAlignment
, 1);
482 IO
.mapOptional("FileAlignment", PH
.Header
.FileAlignment
, 1);
483 IO
.mapOptional("MajorOperatingSystemVersion",
484 PH
.Header
.MajorOperatingSystemVersion
);
485 IO
.mapOptional("MinorOperatingSystemVersion",
486 PH
.Header
.MinorOperatingSystemVersion
);
487 IO
.mapOptional("MajorImageVersion", PH
.Header
.MajorImageVersion
);
488 IO
.mapOptional("MinorImageVersion", PH
.Header
.MinorImageVersion
);
489 IO
.mapOptional("MajorSubsystemVersion", PH
.Header
.MajorSubsystemVersion
);
490 IO
.mapOptional("MinorSubsystemVersion", PH
.Header
.MinorSubsystemVersion
);
491 IO
.mapOptional("Subsystem", NWS
->Subsystem
);
492 IO
.mapOptional("DLLCharacteristics", NDC
->Characteristics
);
493 IO
.mapOptional("SizeOfStackReserve", PH
.Header
.SizeOfStackReserve
);
494 IO
.mapOptional("SizeOfStackCommit", PH
.Header
.SizeOfStackCommit
);
495 IO
.mapOptional("SizeOfHeapReserve", PH
.Header
.SizeOfHeapReserve
);
496 IO
.mapOptional("SizeOfHeapCommit", PH
.Header
.SizeOfHeapCommit
);
498 IO
.mapOptional("NumberOfRvaAndSize", PH
.Header
.NumberOfRvaAndSize
,
499 COFF::NUM_DATA_DIRECTORIES
+ 1);
500 IO
.mapOptional("ExportTable", PH
.DataDirectories
[COFF::EXPORT_TABLE
]);
501 IO
.mapOptional("ImportTable", PH
.DataDirectories
[COFF::IMPORT_TABLE
]);
502 IO
.mapOptional("ResourceTable", PH
.DataDirectories
[COFF::RESOURCE_TABLE
]);
503 IO
.mapOptional("ExceptionTable", PH
.DataDirectories
[COFF::EXCEPTION_TABLE
]);
504 IO
.mapOptional("CertificateTable", PH
.DataDirectories
[COFF::CERTIFICATE_TABLE
]);
505 IO
.mapOptional("BaseRelocationTable",
506 PH
.DataDirectories
[COFF::BASE_RELOCATION_TABLE
]);
507 IO
.mapOptional("Debug", PH
.DataDirectories
[COFF::DEBUG_DIRECTORY
]);
508 IO
.mapOptional("Architecture", PH
.DataDirectories
[COFF::ARCHITECTURE
]);
509 IO
.mapOptional("GlobalPtr", PH
.DataDirectories
[COFF::GLOBAL_PTR
]);
510 IO
.mapOptional("TlsTable", PH
.DataDirectories
[COFF::TLS_TABLE
]);
511 IO
.mapOptional("LoadConfigTable",
512 PH
.DataDirectories
[COFF::LOAD_CONFIG_TABLE
]);
513 IO
.mapOptional("BoundImport", PH
.DataDirectories
[COFF::BOUND_IMPORT
]);
514 IO
.mapOptional("IAT", PH
.DataDirectories
[COFF::IAT
]);
515 IO
.mapOptional("DelayImportDescriptor",
516 PH
.DataDirectories
[COFF::DELAY_IMPORT_DESCRIPTOR
]);
517 IO
.mapOptional("ClrRuntimeHeader",
518 PH
.DataDirectories
[COFF::CLR_RUNTIME_HEADER
]);
521 void MappingTraits
<COFF::header
>::mapping(IO
&IO
, COFF::header
&H
) {
522 MappingNormalization
<NMachine
, uint16_t> NM(IO
, H
.Machine
);
523 MappingNormalization
<NHeaderCharacteristics
, uint16_t> NC(IO
,
526 IO
.mapRequired("Machine", NM
->Machine
);
527 IO
.mapOptional("Characteristics", NC
->Characteristics
);
528 IO
.setContext(static_cast<void *>(&H
));
531 void MappingTraits
<COFF::AuxiliaryFunctionDefinition
>::mapping(
532 IO
&IO
, COFF::AuxiliaryFunctionDefinition
&AFD
) {
533 IO
.mapRequired("TagIndex", AFD
.TagIndex
);
534 IO
.mapRequired("TotalSize", AFD
.TotalSize
);
535 IO
.mapRequired("PointerToLinenumber", AFD
.PointerToLinenumber
);
536 IO
.mapRequired("PointerToNextFunction", AFD
.PointerToNextFunction
);
539 void MappingTraits
<COFF::AuxiliarybfAndefSymbol
>::mapping(
540 IO
&IO
, COFF::AuxiliarybfAndefSymbol
&AAS
) {
541 IO
.mapRequired("Linenumber", AAS
.Linenumber
);
542 IO
.mapRequired("PointerToNextFunction", AAS
.PointerToNextFunction
);
545 void MappingTraits
<COFF::AuxiliaryWeakExternal
>::mapping(
546 IO
&IO
, COFF::AuxiliaryWeakExternal
&AWE
) {
547 MappingNormalization
<NWeakExternalCharacteristics
, uint32_t> NWEC(
548 IO
, AWE
.Characteristics
);
549 IO
.mapRequired("TagIndex", AWE
.TagIndex
);
550 IO
.mapRequired("Characteristics", NWEC
->Characteristics
);
553 void MappingTraits
<COFF::AuxiliarySectionDefinition
>::mapping(
554 IO
&IO
, COFF::AuxiliarySectionDefinition
&ASD
) {
555 MappingNormalization
<NSectionSelectionType
, uint8_t> NSST(
558 IO
.mapRequired("Length", ASD
.Length
);
559 IO
.mapRequired("NumberOfRelocations", ASD
.NumberOfRelocations
);
560 IO
.mapRequired("NumberOfLinenumbers", ASD
.NumberOfLinenumbers
);
561 IO
.mapRequired("CheckSum", ASD
.CheckSum
);
562 IO
.mapRequired("Number", ASD
.Number
);
563 IO
.mapOptional("Selection", NSST
->SelectionType
, COFFYAML::COMDATType(0));
566 void MappingTraits
<COFF::AuxiliaryCLRToken
>::mapping(
567 IO
&IO
, COFF::AuxiliaryCLRToken
&ACT
) {
568 MappingNormalization
<NAuxTokenType
, uint8_t> NATT(IO
, ACT
.AuxType
);
569 IO
.mapRequired("AuxType", NATT
->AuxType
);
570 IO
.mapRequired("SymbolTableIndex", ACT
.SymbolTableIndex
);
573 void MappingTraits
<object::coff_load_config_code_integrity
>::mapping(
574 IO
&IO
, object::coff_load_config_code_integrity
&S
) {
575 IO
.mapOptional("Flags", S
.Flags
);
576 IO
.mapOptional("Catalog", S
.Catalog
);
577 IO
.mapOptional("CatalogOffset", S
.CatalogOffset
);
580 template <typename T
, typename M
>
581 void mapLoadConfigMember(IO
&IO
, T
&LoadConfig
, const char *Name
, M
&Member
) {
582 // Map only members that match a specified size.
584 reinterpret_cast<char *>(&Member
) - reinterpret_cast<char *>(&LoadConfig
);
585 if (dist
< (ptrdiff_t)LoadConfig
.Size
)
586 IO
.mapOptional(Name
, Member
);
589 template <typename T
> void mapLoadConfig(IO
&IO
, T
&LoadConfig
) {
590 IO
.mapOptional("Size", LoadConfig
.Size
,
591 support::ulittle32_t(sizeof(LoadConfig
)));
592 // The size must be large enough to fit at least the size member itself.
593 if (LoadConfig
.Size
< sizeof(LoadConfig
.Size
)) {
594 IO
.setError("Size must be at least " + Twine(sizeof(LoadConfig
.Size
)));
598 #define MCase(X) mapLoadConfigMember(IO, LoadConfig, #X, LoadConfig.X)
599 MCase(TimeDateStamp
);
602 MCase(GlobalFlagsClear
);
603 MCase(GlobalFlagsSet
);
604 MCase(CriticalSectionDefaultTimeout
);
605 MCase(DeCommitFreeBlockThreshold
);
606 MCase(DeCommitTotalFreeThreshold
);
607 MCase(LockPrefixTable
);
608 MCase(MaximumAllocationSize
);
609 MCase(VirtualMemoryThreshold
);
610 MCase(ProcessAffinityMask
);
611 MCase(ProcessHeapFlags
);
613 MCase(DependentLoadFlags
);
615 MCase(SecurityCookie
);
616 MCase(SEHandlerTable
);
617 MCase(SEHandlerCount
);
618 MCase(GuardCFCheckFunction
);
619 MCase(GuardCFCheckDispatch
);
620 MCase(GuardCFFunctionTable
);
621 MCase(GuardCFFunctionCount
);
623 MCase(CodeIntegrity
);
624 MCase(GuardAddressTakenIatEntryTable
);
625 MCase(GuardAddressTakenIatEntryCount
);
626 MCase(GuardLongJumpTargetTable
);
627 MCase(GuardLongJumpTargetCount
);
628 MCase(DynamicValueRelocTable
);
629 MCase(CHPEMetadataPointer
);
630 MCase(GuardRFFailureRoutine
);
631 MCase(GuardRFFailureRoutineFunctionPointer
);
632 MCase(DynamicValueRelocTableOffset
);
633 MCase(DynamicValueRelocTableSection
);
634 MCase(GuardRFVerifyStackPointerFunctionPointer
);
635 MCase(HotPatchTableOffset
);
636 MCase(EnclaveConfigurationPointer
);
637 MCase(VolatileMetadataPointer
);
638 MCase(GuardEHContinuationTable
);
639 MCase(GuardEHContinuationCount
);
640 MCase(GuardXFGCheckFunctionPointer
);
641 MCase(GuardXFGDispatchFunctionPointer
);
642 MCase(GuardXFGTableDispatchFunctionPointer
);
643 MCase(CastGuardOsDeterminedFailureMode
);
647 void MappingTraits
<object::coff_load_configuration32
>::mapping(
648 IO
&IO
, object::coff_load_configuration32
&S
) {
649 mapLoadConfig(IO
, S
);
652 void MappingTraits
<object::coff_load_configuration64
>::mapping(
653 IO
&IO
, object::coff_load_configuration64
&S
) {
654 mapLoadConfig(IO
, S
);
657 void MappingTraits
<COFFYAML::SectionDataEntry
>::mapping(
658 IO
&IO
, COFFYAML::SectionDataEntry
&E
) {
659 IO
.mapOptional("UInt32", E
.UInt32
);
660 IO
.mapOptional("Binary", E
.Binary
);
662 COFF::header
&H
= *static_cast<COFF::header
*>(IO
.getContext());
663 if (COFF::is64Bit(H
.Machine
))
664 IO
.mapOptional("LoadConfig", E
.LoadConfig64
);
666 IO
.mapOptional("LoadConfig", E
.LoadConfig32
);
669 void MappingTraits
<COFFYAML::Symbol
>::mapping(IO
&IO
, COFFYAML::Symbol
&S
) {
670 MappingNormalization
<NStorageClass
, uint8_t> NS(IO
, S
.Header
.StorageClass
);
672 IO
.mapRequired("Name", S
.Name
);
673 IO
.mapRequired("Value", S
.Header
.Value
);
674 IO
.mapRequired("SectionNumber", S
.Header
.SectionNumber
);
675 IO
.mapRequired("SimpleType", S
.SimpleType
);
676 IO
.mapRequired("ComplexType", S
.ComplexType
);
677 IO
.mapRequired("StorageClass", NS
->StorageClass
);
678 IO
.mapOptional("FunctionDefinition", S
.FunctionDefinition
);
679 IO
.mapOptional("bfAndefSymbol", S
.bfAndefSymbol
);
680 IO
.mapOptional("WeakExternal", S
.WeakExternal
);
681 IO
.mapOptional("File", S
.File
, StringRef());
682 IO
.mapOptional("SectionDefinition", S
.SectionDefinition
);
683 IO
.mapOptional("CLRToken", S
.CLRToken
);
686 void MappingTraits
<COFFYAML::Section
>::mapping(IO
&IO
, COFFYAML::Section
&Sec
) {
687 MappingNormalization
<NSectionCharacteristics
, uint32_t> NC(
688 IO
, Sec
.Header
.Characteristics
);
689 IO
.mapRequired("Name", Sec
.Name
);
690 IO
.mapRequired("Characteristics", NC
->Characteristics
);
691 IO
.mapOptional("VirtualAddress", Sec
.Header
.VirtualAddress
, 0U);
692 IO
.mapOptional("VirtualSize", Sec
.Header
.VirtualSize
, 0U);
693 IO
.mapOptional("Alignment", Sec
.Alignment
, 0U);
695 // If this is a .debug$S .debug$T .debug$P, or .debug$H section parse the
696 // semantic representation of the symbols/types. If it is any other kind
697 // of section, just deal in raw bytes.
698 IO
.mapOptional("SectionData", Sec
.SectionData
);
699 if (Sec
.Name
== ".debug$S")
700 IO
.mapOptional("Subsections", Sec
.DebugS
);
701 else if (Sec
.Name
== ".debug$T")
702 IO
.mapOptional("Types", Sec
.DebugT
);
703 else if (Sec
.Name
== ".debug$P")
704 IO
.mapOptional("PrecompTypes", Sec
.DebugP
);
705 else if (Sec
.Name
== ".debug$H")
706 IO
.mapOptional("GlobalHashes", Sec
.DebugH
);
708 IO
.mapOptional("StructuredData", Sec
.StructuredData
);
710 if (!Sec
.StructuredData
.empty() && Sec
.SectionData
.binary_size()) {
711 IO
.setError("StructuredData and SectionData can't be used together");
715 IO
.mapOptional("SizeOfRawData", Sec
.Header
.SizeOfRawData
, 0U);
717 if (!Sec
.StructuredData
.empty() && Sec
.Header
.SizeOfRawData
) {
718 IO
.setError("StructuredData and SizeOfRawData can't be used together");
722 IO
.mapOptional("Relocations", Sec
.Relocations
);
725 void MappingTraits
<COFFYAML::Object
>::mapping(IO
&IO
, COFFYAML::Object
&Obj
) {
726 IO
.mapTag("!COFF", true);
727 IO
.mapOptional("OptionalHeader", Obj
.OptionalHeader
);
728 IO
.mapRequired("header", Obj
.Header
);
729 IO
.mapRequired("sections", Obj
.Sections
);
730 IO
.mapRequired("symbols", Obj
.Symbols
);
733 } // end namespace yaml
735 } // end namespace llvm