[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / ObjectYAML / COFFYAML.cpp
blob96069c0c590f0eb9ef82cc3648b4993adcd5a4d1
1 //===- COFFYAML.cpp - COFF YAMLIO implementation --------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
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"
16 #include <cstdint>
17 #include <cstring>
19 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
21 namespace llvm {
23 namespace COFFYAML {
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
31 namespace yaml {
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);
45 void
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_EBC);
69 ECase(IMAGE_FILE_MACHINE_I386);
70 ECase(IMAGE_FILE_MACHINE_IA64);
71 ECase(IMAGE_FILE_MACHINE_M32R);
72 ECase(IMAGE_FILE_MACHINE_MIPS16);
73 ECase(IMAGE_FILE_MACHINE_MIPSFPU);
74 ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
75 ECase(IMAGE_FILE_MACHINE_POWERPC);
76 ECase(IMAGE_FILE_MACHINE_POWERPCFP);
77 ECase(IMAGE_FILE_MACHINE_R4000);
78 ECase(IMAGE_FILE_MACHINE_SH3);
79 ECase(IMAGE_FILE_MACHINE_SH3DSP);
80 ECase(IMAGE_FILE_MACHINE_SH4);
81 ECase(IMAGE_FILE_MACHINE_SH5);
82 ECase(IMAGE_FILE_MACHINE_THUMB);
83 ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
86 void ScalarEnumerationTraits<COFF::SymbolBaseType>::enumeration(
87 IO &IO, COFF::SymbolBaseType &Value) {
88 ECase(IMAGE_SYM_TYPE_NULL);
89 ECase(IMAGE_SYM_TYPE_VOID);
90 ECase(IMAGE_SYM_TYPE_CHAR);
91 ECase(IMAGE_SYM_TYPE_SHORT);
92 ECase(IMAGE_SYM_TYPE_INT);
93 ECase(IMAGE_SYM_TYPE_LONG);
94 ECase(IMAGE_SYM_TYPE_FLOAT);
95 ECase(IMAGE_SYM_TYPE_DOUBLE);
96 ECase(IMAGE_SYM_TYPE_STRUCT);
97 ECase(IMAGE_SYM_TYPE_UNION);
98 ECase(IMAGE_SYM_TYPE_ENUM);
99 ECase(IMAGE_SYM_TYPE_MOE);
100 ECase(IMAGE_SYM_TYPE_BYTE);
101 ECase(IMAGE_SYM_TYPE_WORD);
102 ECase(IMAGE_SYM_TYPE_UINT);
103 ECase(IMAGE_SYM_TYPE_DWORD);
106 void ScalarEnumerationTraits<COFF::SymbolStorageClass>::enumeration(
107 IO &IO, COFF::SymbolStorageClass &Value) {
108 ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
109 ECase(IMAGE_SYM_CLASS_NULL);
110 ECase(IMAGE_SYM_CLASS_AUTOMATIC);
111 ECase(IMAGE_SYM_CLASS_EXTERNAL);
112 ECase(IMAGE_SYM_CLASS_STATIC);
113 ECase(IMAGE_SYM_CLASS_REGISTER);
114 ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
115 ECase(IMAGE_SYM_CLASS_LABEL);
116 ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
117 ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
118 ECase(IMAGE_SYM_CLASS_ARGUMENT);
119 ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
120 ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
121 ECase(IMAGE_SYM_CLASS_UNION_TAG);
122 ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
123 ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
124 ECase(IMAGE_SYM_CLASS_ENUM_TAG);
125 ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
126 ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
127 ECase(IMAGE_SYM_CLASS_BIT_FIELD);
128 ECase(IMAGE_SYM_CLASS_BLOCK);
129 ECase(IMAGE_SYM_CLASS_FUNCTION);
130 ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
131 ECase(IMAGE_SYM_CLASS_FILE);
132 ECase(IMAGE_SYM_CLASS_SECTION);
133 ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
134 ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
137 void ScalarEnumerationTraits<COFF::SymbolComplexType>::enumeration(
138 IO &IO, COFF::SymbolComplexType &Value) {
139 ECase(IMAGE_SYM_DTYPE_NULL);
140 ECase(IMAGE_SYM_DTYPE_POINTER);
141 ECase(IMAGE_SYM_DTYPE_FUNCTION);
142 ECase(IMAGE_SYM_DTYPE_ARRAY);
145 void ScalarEnumerationTraits<COFF::RelocationTypeI386>::enumeration(
146 IO &IO, COFF::RelocationTypeI386 &Value) {
147 ECase(IMAGE_REL_I386_ABSOLUTE);
148 ECase(IMAGE_REL_I386_DIR16);
149 ECase(IMAGE_REL_I386_REL16);
150 ECase(IMAGE_REL_I386_DIR32);
151 ECase(IMAGE_REL_I386_DIR32NB);
152 ECase(IMAGE_REL_I386_SEG12);
153 ECase(IMAGE_REL_I386_SECTION);
154 ECase(IMAGE_REL_I386_SECREL);
155 ECase(IMAGE_REL_I386_TOKEN);
156 ECase(IMAGE_REL_I386_SECREL7);
157 ECase(IMAGE_REL_I386_REL32);
160 void ScalarEnumerationTraits<COFF::RelocationTypeAMD64>::enumeration(
161 IO &IO, COFF::RelocationTypeAMD64 &Value) {
162 ECase(IMAGE_REL_AMD64_ABSOLUTE);
163 ECase(IMAGE_REL_AMD64_ADDR64);
164 ECase(IMAGE_REL_AMD64_ADDR32);
165 ECase(IMAGE_REL_AMD64_ADDR32NB);
166 ECase(IMAGE_REL_AMD64_REL32);
167 ECase(IMAGE_REL_AMD64_REL32_1);
168 ECase(IMAGE_REL_AMD64_REL32_2);
169 ECase(IMAGE_REL_AMD64_REL32_3);
170 ECase(IMAGE_REL_AMD64_REL32_4);
171 ECase(IMAGE_REL_AMD64_REL32_5);
172 ECase(IMAGE_REL_AMD64_SECTION);
173 ECase(IMAGE_REL_AMD64_SECREL);
174 ECase(IMAGE_REL_AMD64_SECREL7);
175 ECase(IMAGE_REL_AMD64_TOKEN);
176 ECase(IMAGE_REL_AMD64_SREL32);
177 ECase(IMAGE_REL_AMD64_PAIR);
178 ECase(IMAGE_REL_AMD64_SSPAN32);
181 void ScalarEnumerationTraits<COFF::RelocationTypesARM>::enumeration(
182 IO &IO, COFF::RelocationTypesARM &Value) {
183 ECase(IMAGE_REL_ARM_ABSOLUTE);
184 ECase(IMAGE_REL_ARM_ADDR32);
185 ECase(IMAGE_REL_ARM_ADDR32NB);
186 ECase(IMAGE_REL_ARM_BRANCH24);
187 ECase(IMAGE_REL_ARM_BRANCH11);
188 ECase(IMAGE_REL_ARM_TOKEN);
189 ECase(IMAGE_REL_ARM_BLX24);
190 ECase(IMAGE_REL_ARM_BLX11);
191 ECase(IMAGE_REL_ARM_REL32);
192 ECase(IMAGE_REL_ARM_SECTION);
193 ECase(IMAGE_REL_ARM_SECREL);
194 ECase(IMAGE_REL_ARM_MOV32A);
195 ECase(IMAGE_REL_ARM_MOV32T);
196 ECase(IMAGE_REL_ARM_BRANCH20T);
197 ECase(IMAGE_REL_ARM_BRANCH24T);
198 ECase(IMAGE_REL_ARM_BLX23T);
199 ECase(IMAGE_REL_ARM_PAIR);
202 void ScalarEnumerationTraits<COFF::RelocationTypesARM64>::enumeration(
203 IO &IO, COFF::RelocationTypesARM64 &Value) {
204 ECase(IMAGE_REL_ARM64_ABSOLUTE);
205 ECase(IMAGE_REL_ARM64_ADDR32);
206 ECase(IMAGE_REL_ARM64_ADDR32NB);
207 ECase(IMAGE_REL_ARM64_BRANCH26);
208 ECase(IMAGE_REL_ARM64_PAGEBASE_REL21);
209 ECase(IMAGE_REL_ARM64_REL21);
210 ECase(IMAGE_REL_ARM64_PAGEOFFSET_12A);
211 ECase(IMAGE_REL_ARM64_PAGEOFFSET_12L);
212 ECase(IMAGE_REL_ARM64_SECREL);
213 ECase(IMAGE_REL_ARM64_SECREL_LOW12A);
214 ECase(IMAGE_REL_ARM64_SECREL_HIGH12A);
215 ECase(IMAGE_REL_ARM64_SECREL_LOW12L);
216 ECase(IMAGE_REL_ARM64_TOKEN);
217 ECase(IMAGE_REL_ARM64_SECTION);
218 ECase(IMAGE_REL_ARM64_ADDR64);
219 ECase(IMAGE_REL_ARM64_BRANCH19);
220 ECase(IMAGE_REL_ARM64_BRANCH14);
221 ECase(IMAGE_REL_ARM64_REL32);
224 void ScalarEnumerationTraits<COFF::WindowsSubsystem>::enumeration(
225 IO &IO, COFF::WindowsSubsystem &Value) {
226 ECase(IMAGE_SUBSYSTEM_UNKNOWN);
227 ECase(IMAGE_SUBSYSTEM_NATIVE);
228 ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
229 ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
230 ECase(IMAGE_SUBSYSTEM_OS2_CUI);
231 ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
232 ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
233 ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
234 ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
235 ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
236 ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
237 ECase(IMAGE_SUBSYSTEM_EFI_ROM);
238 ECase(IMAGE_SUBSYSTEM_XBOX);
239 ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
241 #undef ECase
243 #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
244 void ScalarBitSetTraits<COFF::Characteristics>::bitset(
245 IO &IO, COFF::Characteristics &Value) {
246 BCase(IMAGE_FILE_RELOCS_STRIPPED);
247 BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
248 BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
249 BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
250 BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
251 BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
252 BCase(IMAGE_FILE_BYTES_REVERSED_LO);
253 BCase(IMAGE_FILE_32BIT_MACHINE);
254 BCase(IMAGE_FILE_DEBUG_STRIPPED);
255 BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
256 BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
257 BCase(IMAGE_FILE_SYSTEM);
258 BCase(IMAGE_FILE_DLL);
259 BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
260 BCase(IMAGE_FILE_BYTES_REVERSED_HI);
263 void ScalarBitSetTraits<COFF::SectionCharacteristics>::bitset(
264 IO &IO, COFF::SectionCharacteristics &Value) {
265 BCase(IMAGE_SCN_TYPE_NOLOAD);
266 BCase(IMAGE_SCN_TYPE_NO_PAD);
267 BCase(IMAGE_SCN_CNT_CODE);
268 BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
269 BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
270 BCase(IMAGE_SCN_LNK_OTHER);
271 BCase(IMAGE_SCN_LNK_INFO);
272 BCase(IMAGE_SCN_LNK_REMOVE);
273 BCase(IMAGE_SCN_LNK_COMDAT);
274 BCase(IMAGE_SCN_GPREL);
275 BCase(IMAGE_SCN_MEM_PURGEABLE);
276 BCase(IMAGE_SCN_MEM_16BIT);
277 BCase(IMAGE_SCN_MEM_LOCKED);
278 BCase(IMAGE_SCN_MEM_PRELOAD);
279 BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
280 BCase(IMAGE_SCN_MEM_DISCARDABLE);
281 BCase(IMAGE_SCN_MEM_NOT_CACHED);
282 BCase(IMAGE_SCN_MEM_NOT_PAGED);
283 BCase(IMAGE_SCN_MEM_SHARED);
284 BCase(IMAGE_SCN_MEM_EXECUTE);
285 BCase(IMAGE_SCN_MEM_READ);
286 BCase(IMAGE_SCN_MEM_WRITE);
289 void ScalarBitSetTraits<COFF::DLLCharacteristics>::bitset(
290 IO &IO, COFF::DLLCharacteristics &Value) {
291 BCase(IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA);
292 BCase(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE);
293 BCase(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY);
294 BCase(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT);
295 BCase(IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION);
296 BCase(IMAGE_DLL_CHARACTERISTICS_NO_SEH);
297 BCase(IMAGE_DLL_CHARACTERISTICS_NO_BIND);
298 BCase(IMAGE_DLL_CHARACTERISTICS_APPCONTAINER);
299 BCase(IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER);
300 BCase(IMAGE_DLL_CHARACTERISTICS_GUARD_CF);
301 BCase(IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE);
303 #undef BCase
305 namespace {
307 struct NSectionSelectionType {
308 NSectionSelectionType(IO &)
309 : SelectionType(COFFYAML::COMDATType(0)) {}
310 NSectionSelectionType(IO &, uint8_t C)
311 : SelectionType(COFFYAML::COMDATType(C)) {}
313 uint8_t denormalize(IO &) { return SelectionType; }
315 COFFYAML::COMDATType SelectionType;
318 struct NWeakExternalCharacteristics {
319 NWeakExternalCharacteristics(IO &)
320 : Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
321 NWeakExternalCharacteristics(IO &, uint32_t C)
322 : Characteristics(COFFYAML::WeakExternalCharacteristics(C)) {}
324 uint32_t denormalize(IO &) { return Characteristics; }
326 COFFYAML::WeakExternalCharacteristics Characteristics;
329 struct NSectionCharacteristics {
330 NSectionCharacteristics(IO &)
331 : Characteristics(COFF::SectionCharacteristics(0)) {}
332 NSectionCharacteristics(IO &, uint32_t C)
333 : Characteristics(COFF::SectionCharacteristics(C)) {}
335 uint32_t denormalize(IO &) { return Characteristics; }
337 COFF::SectionCharacteristics Characteristics;
340 struct NAuxTokenType {
341 NAuxTokenType(IO &)
342 : AuxType(COFFYAML::AuxSymbolType(0)) {}
343 NAuxTokenType(IO &, uint8_t C)
344 : AuxType(COFFYAML::AuxSymbolType(C)) {}
346 uint32_t denormalize(IO &) { return AuxType; }
348 COFFYAML::AuxSymbolType AuxType;
351 struct NStorageClass {
352 NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
353 NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
355 uint8_t denormalize(IO &) { return StorageClass; }
357 COFF::SymbolStorageClass StorageClass;
360 struct NMachine {
361 NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
362 NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
364 uint16_t denormalize(IO &) { return Machine; }
366 COFF::MachineTypes Machine;
369 struct NHeaderCharacteristics {
370 NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
371 NHeaderCharacteristics(IO &, uint16_t C)
372 : Characteristics(COFF::Characteristics(C)) {}
374 uint16_t denormalize(IO &) { return Characteristics; }
376 COFF::Characteristics Characteristics;
379 template <typename RelocType>
380 struct NType {
381 NType(IO &) : Type(RelocType(0)) {}
382 NType(IO &, uint16_t T) : Type(RelocType(T)) {}
384 uint16_t denormalize(IO &) { return Type; }
386 RelocType Type;
389 struct NWindowsSubsystem {
390 NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
391 NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
393 uint16_t denormalize(IO &) { return Subsystem; }
395 COFF::WindowsSubsystem Subsystem;
398 struct NDLLCharacteristics {
399 NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
400 NDLLCharacteristics(IO &, uint16_t C)
401 : Characteristics(COFF::DLLCharacteristics(C)) {}
403 uint16_t denormalize(IO &) { return Characteristics; }
405 COFF::DLLCharacteristics Characteristics;
408 } // end anonymous namespace
410 void MappingTraits<COFFYAML::Relocation>::mapping(IO &IO,
411 COFFYAML::Relocation &Rel) {
412 IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
413 IO.mapOptional("SymbolName", Rel.SymbolName, StringRef());
414 IO.mapOptional("SymbolTableIndex", Rel.SymbolTableIndex);
416 COFF::header &H = *static_cast<COFF::header *>(IO.getContext());
417 if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
418 MappingNormalization<NType<COFF::RelocationTypeI386>, uint16_t> NT(
419 IO, Rel.Type);
420 IO.mapRequired("Type", NT->Type);
421 } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
422 MappingNormalization<NType<COFF::RelocationTypeAMD64>, uint16_t> NT(
423 IO, Rel.Type);
424 IO.mapRequired("Type", NT->Type);
425 } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_ARMNT) {
426 MappingNormalization<NType<COFF::RelocationTypesARM>, uint16_t> NT(
427 IO, Rel.Type);
428 IO.mapRequired("Type", NT->Type);
429 } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_ARM64) {
430 MappingNormalization<NType<COFF::RelocationTypesARM64>, uint16_t> NT(
431 IO, Rel.Type);
432 IO.mapRequired("Type", NT->Type);
433 } else {
434 IO.mapRequired("Type", Rel.Type);
438 void MappingTraits<COFF::DataDirectory>::mapping(IO &IO,
439 COFF::DataDirectory &DD) {
440 IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
441 IO.mapRequired("Size", DD.Size);
444 void MappingTraits<COFFYAML::PEHeader>::mapping(IO &IO,
445 COFFYAML::PEHeader &PH) {
446 MappingNormalization<NWindowsSubsystem, uint16_t> NWS(IO,
447 PH.Header.Subsystem);
448 MappingNormalization<NDLLCharacteristics, uint16_t> NDC(
449 IO, PH.Header.DLLCharacteristics);
451 IO.mapRequired("AddressOfEntryPoint", PH.Header.AddressOfEntryPoint);
452 IO.mapRequired("ImageBase", PH.Header.ImageBase);
453 IO.mapRequired("SectionAlignment", PH.Header.SectionAlignment);
454 IO.mapRequired("FileAlignment", PH.Header.FileAlignment);
455 IO.mapRequired("MajorOperatingSystemVersion",
456 PH.Header.MajorOperatingSystemVersion);
457 IO.mapRequired("MinorOperatingSystemVersion",
458 PH.Header.MinorOperatingSystemVersion);
459 IO.mapRequired("MajorImageVersion", PH.Header.MajorImageVersion);
460 IO.mapRequired("MinorImageVersion", PH.Header.MinorImageVersion);
461 IO.mapRequired("MajorSubsystemVersion", PH.Header.MajorSubsystemVersion);
462 IO.mapRequired("MinorSubsystemVersion", PH.Header.MinorSubsystemVersion);
463 IO.mapRequired("Subsystem", NWS->Subsystem);
464 IO.mapRequired("DLLCharacteristics", NDC->Characteristics);
465 IO.mapRequired("SizeOfStackReserve", PH.Header.SizeOfStackReserve);
466 IO.mapRequired("SizeOfStackCommit", PH.Header.SizeOfStackCommit);
467 IO.mapRequired("SizeOfHeapReserve", PH.Header.SizeOfHeapReserve);
468 IO.mapRequired("SizeOfHeapCommit", PH.Header.SizeOfHeapCommit);
470 IO.mapOptional("ExportTable", PH.DataDirectories[COFF::EXPORT_TABLE]);
471 IO.mapOptional("ImportTable", PH.DataDirectories[COFF::IMPORT_TABLE]);
472 IO.mapOptional("ResourceTable", PH.DataDirectories[COFF::RESOURCE_TABLE]);
473 IO.mapOptional("ExceptionTable", PH.DataDirectories[COFF::EXCEPTION_TABLE]);
474 IO.mapOptional("CertificateTable", PH.DataDirectories[COFF::CERTIFICATE_TABLE]);
475 IO.mapOptional("BaseRelocationTable",
476 PH.DataDirectories[COFF::BASE_RELOCATION_TABLE]);
477 IO.mapOptional("Debug", PH.DataDirectories[COFF::DEBUG_DIRECTORY]);
478 IO.mapOptional("Architecture", PH.DataDirectories[COFF::ARCHITECTURE]);
479 IO.mapOptional("GlobalPtr", PH.DataDirectories[COFF::GLOBAL_PTR]);
480 IO.mapOptional("TlsTable", PH.DataDirectories[COFF::TLS_TABLE]);
481 IO.mapOptional("LoadConfigTable",
482 PH.DataDirectories[COFF::LOAD_CONFIG_TABLE]);
483 IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
484 IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
485 IO.mapOptional("DelayImportDescriptor",
486 PH.DataDirectories[COFF::DELAY_IMPORT_DESCRIPTOR]);
487 IO.mapOptional("ClrRuntimeHeader",
488 PH.DataDirectories[COFF::CLR_RUNTIME_HEADER]);
491 void MappingTraits<COFF::header>::mapping(IO &IO, COFF::header &H) {
492 MappingNormalization<NMachine, uint16_t> NM(IO, H.Machine);
493 MappingNormalization<NHeaderCharacteristics, uint16_t> NC(IO,
494 H.Characteristics);
496 IO.mapRequired("Machine", NM->Machine);
497 IO.mapOptional("Characteristics", NC->Characteristics);
498 IO.setContext(static_cast<void *>(&H));
501 void MappingTraits<COFF::AuxiliaryFunctionDefinition>::mapping(
502 IO &IO, COFF::AuxiliaryFunctionDefinition &AFD) {
503 IO.mapRequired("TagIndex", AFD.TagIndex);
504 IO.mapRequired("TotalSize", AFD.TotalSize);
505 IO.mapRequired("PointerToLinenumber", AFD.PointerToLinenumber);
506 IO.mapRequired("PointerToNextFunction", AFD.PointerToNextFunction);
509 void MappingTraits<COFF::AuxiliarybfAndefSymbol>::mapping(
510 IO &IO, COFF::AuxiliarybfAndefSymbol &AAS) {
511 IO.mapRequired("Linenumber", AAS.Linenumber);
512 IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
515 void MappingTraits<COFF::AuxiliaryWeakExternal>::mapping(
516 IO &IO, COFF::AuxiliaryWeakExternal &AWE) {
517 MappingNormalization<NWeakExternalCharacteristics, uint32_t> NWEC(
518 IO, AWE.Characteristics);
519 IO.mapRequired("TagIndex", AWE.TagIndex);
520 IO.mapRequired("Characteristics", NWEC->Characteristics);
523 void MappingTraits<COFF::AuxiliarySectionDefinition>::mapping(
524 IO &IO, COFF::AuxiliarySectionDefinition &ASD) {
525 MappingNormalization<NSectionSelectionType, uint8_t> NSST(
526 IO, ASD.Selection);
528 IO.mapRequired("Length", ASD.Length);
529 IO.mapRequired("NumberOfRelocations", ASD.NumberOfRelocations);
530 IO.mapRequired("NumberOfLinenumbers", ASD.NumberOfLinenumbers);
531 IO.mapRequired("CheckSum", ASD.CheckSum);
532 IO.mapRequired("Number", ASD.Number);
533 IO.mapOptional("Selection", NSST->SelectionType, COFFYAML::COMDATType(0));
536 void MappingTraits<COFF::AuxiliaryCLRToken>::mapping(
537 IO &IO, COFF::AuxiliaryCLRToken &ACT) {
538 MappingNormalization<NAuxTokenType, uint8_t> NATT(IO, ACT.AuxType);
539 IO.mapRequired("AuxType", NATT->AuxType);
540 IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
543 void MappingTraits<COFFYAML::Symbol>::mapping(IO &IO, COFFYAML::Symbol &S) {
544 MappingNormalization<NStorageClass, uint8_t> NS(IO, S.Header.StorageClass);
546 IO.mapRequired("Name", S.Name);
547 IO.mapRequired("Value", S.Header.Value);
548 IO.mapRequired("SectionNumber", S.Header.SectionNumber);
549 IO.mapRequired("SimpleType", S.SimpleType);
550 IO.mapRequired("ComplexType", S.ComplexType);
551 IO.mapRequired("StorageClass", NS->StorageClass);
552 IO.mapOptional("FunctionDefinition", S.FunctionDefinition);
553 IO.mapOptional("bfAndefSymbol", S.bfAndefSymbol);
554 IO.mapOptional("WeakExternal", S.WeakExternal);
555 IO.mapOptional("File", S.File, StringRef());
556 IO.mapOptional("SectionDefinition", S.SectionDefinition);
557 IO.mapOptional("CLRToken", S.CLRToken);
560 void MappingTraits<COFFYAML::Section>::mapping(IO &IO, COFFYAML::Section &Sec) {
561 MappingNormalization<NSectionCharacteristics, uint32_t> NC(
562 IO, Sec.Header.Characteristics);
563 IO.mapRequired("Name", Sec.Name);
564 IO.mapRequired("Characteristics", NC->Characteristics);
565 IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
566 IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
567 IO.mapOptional("Alignment", Sec.Alignment, 0U);
569 // If this is a .debug$S .debug$T .debug$P, or .debug$H section parse the
570 // semantic representation of the symbols/types. If it is any other kind
571 // of section, just deal in raw bytes.
572 IO.mapOptional("SectionData", Sec.SectionData);
573 if (Sec.Name == ".debug$S")
574 IO.mapOptional("Subsections", Sec.DebugS);
575 else if (Sec.Name == ".debug$T")
576 IO.mapOptional("Types", Sec.DebugT);
577 else if (Sec.Name == ".debug$P")
578 IO.mapOptional("PrecompTypes", Sec.DebugP);
579 else if (Sec.Name == ".debug$H")
580 IO.mapOptional("GlobalHashes", Sec.DebugH);
582 // Uninitialized sections, such as .bss, typically have no data, but the size
583 // is carried in SizeOfRawData, even though PointerToRawData is zero.
584 if (Sec.SectionData.binary_size() == 0 &&
585 NC->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
586 IO.mapOptional("SizeOfRawData", Sec.Header.SizeOfRawData);
588 IO.mapOptional("Relocations", Sec.Relocations);
591 void MappingTraits<COFFYAML::Object>::mapping(IO &IO, COFFYAML::Object &Obj) {
592 IO.mapTag("!COFF", true);
593 IO.mapOptional("OptionalHeader", Obj.OptionalHeader);
594 IO.mapRequired("header", Obj.Header);
595 IO.mapRequired("sections", Obj.Sections);
596 IO.mapRequired("symbols", Obj.Symbols);
599 } // end namespace yaml
601 } // end namespace llvm