• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- COFFYAML.cpp - COFF YAMLIO implementation --------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines classes for handling the YAML representation of COFF.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/ObjectYAML/COFFYAML.h"
15 
16 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
17 namespace llvm {
18 
19 namespace COFFYAML {
Section()20 Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
Symbol()21 Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
Object()22 Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
23 }
24 
25 namespace yaml {
enumeration(IO & IO,COFFYAML::COMDATType & Value)26 void ScalarEnumerationTraits<COFFYAML::COMDATType>::enumeration(
27     IO &IO, COFFYAML::COMDATType &Value) {
28   IO.enumCase(Value, "0", 0);
29   ECase(IMAGE_COMDAT_SELECT_NODUPLICATES);
30   ECase(IMAGE_COMDAT_SELECT_ANY);
31   ECase(IMAGE_COMDAT_SELECT_SAME_SIZE);
32   ECase(IMAGE_COMDAT_SELECT_EXACT_MATCH);
33   ECase(IMAGE_COMDAT_SELECT_ASSOCIATIVE);
34   ECase(IMAGE_COMDAT_SELECT_LARGEST);
35   ECase(IMAGE_COMDAT_SELECT_NEWEST);
36 }
37 
38 void
enumeration(IO & IO,COFFYAML::WeakExternalCharacteristics & Value)39 ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics>::enumeration(
40     IO &IO, COFFYAML::WeakExternalCharacteristics &Value) {
41   IO.enumCase(Value, "0", 0);
42   ECase(IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY);
43   ECase(IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
44   ECase(IMAGE_WEAK_EXTERN_SEARCH_ALIAS);
45 }
46 
enumeration(IO & IO,COFFYAML::AuxSymbolType & Value)47 void ScalarEnumerationTraits<COFFYAML::AuxSymbolType>::enumeration(
48     IO &IO, COFFYAML::AuxSymbolType &Value) {
49   ECase(IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF);
50 }
51 
enumeration(IO & IO,COFF::MachineTypes & Value)52 void ScalarEnumerationTraits<COFF::MachineTypes>::enumeration(
53     IO &IO, COFF::MachineTypes &Value) {
54   ECase(IMAGE_FILE_MACHINE_UNKNOWN);
55   ECase(IMAGE_FILE_MACHINE_AM33);
56   ECase(IMAGE_FILE_MACHINE_AMD64);
57   ECase(IMAGE_FILE_MACHINE_ARM);
58   ECase(IMAGE_FILE_MACHINE_ARMNT);
59   ECase(IMAGE_FILE_MACHINE_ARM64);
60   ECase(IMAGE_FILE_MACHINE_EBC);
61   ECase(IMAGE_FILE_MACHINE_I386);
62   ECase(IMAGE_FILE_MACHINE_IA64);
63   ECase(IMAGE_FILE_MACHINE_M32R);
64   ECase(IMAGE_FILE_MACHINE_MIPS16);
65   ECase(IMAGE_FILE_MACHINE_MIPSFPU);
66   ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
67   ECase(IMAGE_FILE_MACHINE_POWERPC);
68   ECase(IMAGE_FILE_MACHINE_POWERPCFP);
69   ECase(IMAGE_FILE_MACHINE_R4000);
70   ECase(IMAGE_FILE_MACHINE_SH3);
71   ECase(IMAGE_FILE_MACHINE_SH3DSP);
72   ECase(IMAGE_FILE_MACHINE_SH4);
73   ECase(IMAGE_FILE_MACHINE_SH5);
74   ECase(IMAGE_FILE_MACHINE_THUMB);
75   ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
76 }
77 
enumeration(IO & IO,COFF::SymbolBaseType & Value)78 void ScalarEnumerationTraits<COFF::SymbolBaseType>::enumeration(
79     IO &IO, COFF::SymbolBaseType &Value) {
80   ECase(IMAGE_SYM_TYPE_NULL);
81   ECase(IMAGE_SYM_TYPE_VOID);
82   ECase(IMAGE_SYM_TYPE_CHAR);
83   ECase(IMAGE_SYM_TYPE_SHORT);
84   ECase(IMAGE_SYM_TYPE_INT);
85   ECase(IMAGE_SYM_TYPE_LONG);
86   ECase(IMAGE_SYM_TYPE_FLOAT);
87   ECase(IMAGE_SYM_TYPE_DOUBLE);
88   ECase(IMAGE_SYM_TYPE_STRUCT);
89   ECase(IMAGE_SYM_TYPE_UNION);
90   ECase(IMAGE_SYM_TYPE_ENUM);
91   ECase(IMAGE_SYM_TYPE_MOE);
92   ECase(IMAGE_SYM_TYPE_BYTE);
93   ECase(IMAGE_SYM_TYPE_WORD);
94   ECase(IMAGE_SYM_TYPE_UINT);
95   ECase(IMAGE_SYM_TYPE_DWORD);
96 }
97 
enumeration(IO & IO,COFF::SymbolStorageClass & Value)98 void ScalarEnumerationTraits<COFF::SymbolStorageClass>::enumeration(
99     IO &IO, COFF::SymbolStorageClass &Value) {
100   ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
101   ECase(IMAGE_SYM_CLASS_NULL);
102   ECase(IMAGE_SYM_CLASS_AUTOMATIC);
103   ECase(IMAGE_SYM_CLASS_EXTERNAL);
104   ECase(IMAGE_SYM_CLASS_STATIC);
105   ECase(IMAGE_SYM_CLASS_REGISTER);
106   ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
107   ECase(IMAGE_SYM_CLASS_LABEL);
108   ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
109   ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
110   ECase(IMAGE_SYM_CLASS_ARGUMENT);
111   ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
112   ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
113   ECase(IMAGE_SYM_CLASS_UNION_TAG);
114   ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
115   ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
116   ECase(IMAGE_SYM_CLASS_ENUM_TAG);
117   ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
118   ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
119   ECase(IMAGE_SYM_CLASS_BIT_FIELD);
120   ECase(IMAGE_SYM_CLASS_BLOCK);
121   ECase(IMAGE_SYM_CLASS_FUNCTION);
122   ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
123   ECase(IMAGE_SYM_CLASS_FILE);
124   ECase(IMAGE_SYM_CLASS_SECTION);
125   ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
126   ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
127 }
128 
enumeration(IO & IO,COFF::SymbolComplexType & Value)129 void ScalarEnumerationTraits<COFF::SymbolComplexType>::enumeration(
130     IO &IO, COFF::SymbolComplexType &Value) {
131   ECase(IMAGE_SYM_DTYPE_NULL);
132   ECase(IMAGE_SYM_DTYPE_POINTER);
133   ECase(IMAGE_SYM_DTYPE_FUNCTION);
134   ECase(IMAGE_SYM_DTYPE_ARRAY);
135 }
136 
enumeration(IO & IO,COFF::RelocationTypeI386 & Value)137 void ScalarEnumerationTraits<COFF::RelocationTypeI386>::enumeration(
138     IO &IO, COFF::RelocationTypeI386 &Value) {
139   ECase(IMAGE_REL_I386_ABSOLUTE);
140   ECase(IMAGE_REL_I386_DIR16);
141   ECase(IMAGE_REL_I386_REL16);
142   ECase(IMAGE_REL_I386_DIR32);
143   ECase(IMAGE_REL_I386_DIR32NB);
144   ECase(IMAGE_REL_I386_SEG12);
145   ECase(IMAGE_REL_I386_SECTION);
146   ECase(IMAGE_REL_I386_SECREL);
147   ECase(IMAGE_REL_I386_TOKEN);
148   ECase(IMAGE_REL_I386_SECREL7);
149   ECase(IMAGE_REL_I386_REL32);
150 }
151 
enumeration(IO & IO,COFF::RelocationTypeAMD64 & Value)152 void ScalarEnumerationTraits<COFF::RelocationTypeAMD64>::enumeration(
153     IO &IO, COFF::RelocationTypeAMD64 &Value) {
154   ECase(IMAGE_REL_AMD64_ABSOLUTE);
155   ECase(IMAGE_REL_AMD64_ADDR64);
156   ECase(IMAGE_REL_AMD64_ADDR32);
157   ECase(IMAGE_REL_AMD64_ADDR32NB);
158   ECase(IMAGE_REL_AMD64_REL32);
159   ECase(IMAGE_REL_AMD64_REL32_1);
160   ECase(IMAGE_REL_AMD64_REL32_2);
161   ECase(IMAGE_REL_AMD64_REL32_3);
162   ECase(IMAGE_REL_AMD64_REL32_4);
163   ECase(IMAGE_REL_AMD64_REL32_5);
164   ECase(IMAGE_REL_AMD64_SECTION);
165   ECase(IMAGE_REL_AMD64_SECREL);
166   ECase(IMAGE_REL_AMD64_SECREL7);
167   ECase(IMAGE_REL_AMD64_TOKEN);
168   ECase(IMAGE_REL_AMD64_SREL32);
169   ECase(IMAGE_REL_AMD64_PAIR);
170   ECase(IMAGE_REL_AMD64_SSPAN32);
171 }
172 
enumeration(IO & IO,COFF::WindowsSubsystem & Value)173 void ScalarEnumerationTraits<COFF::WindowsSubsystem>::enumeration(
174     IO &IO, COFF::WindowsSubsystem &Value) {
175     ECase(IMAGE_SUBSYSTEM_UNKNOWN);
176     ECase(IMAGE_SUBSYSTEM_NATIVE);
177     ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
178     ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
179     ECase(IMAGE_SUBSYSTEM_OS2_CUI);
180     ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
181     ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
182     ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
183     ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
184     ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
185     ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
186     ECase(IMAGE_SUBSYSTEM_EFI_ROM);
187     ECase(IMAGE_SUBSYSTEM_XBOX);
188     ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
189 }
190 #undef ECase
191 
192 #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
bitset(IO & IO,COFF::Characteristics & Value)193 void ScalarBitSetTraits<COFF::Characteristics>::bitset(
194     IO &IO, COFF::Characteristics &Value) {
195   BCase(IMAGE_FILE_RELOCS_STRIPPED);
196   BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
197   BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
198   BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
199   BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
200   BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
201   BCase(IMAGE_FILE_BYTES_REVERSED_LO);
202   BCase(IMAGE_FILE_32BIT_MACHINE);
203   BCase(IMAGE_FILE_DEBUG_STRIPPED);
204   BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
205   BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
206   BCase(IMAGE_FILE_SYSTEM);
207   BCase(IMAGE_FILE_DLL);
208   BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
209   BCase(IMAGE_FILE_BYTES_REVERSED_HI);
210 }
211 
bitset(IO & IO,COFF::SectionCharacteristics & Value)212 void ScalarBitSetTraits<COFF::SectionCharacteristics>::bitset(
213     IO &IO, COFF::SectionCharacteristics &Value) {
214   BCase(IMAGE_SCN_TYPE_NOLOAD);
215   BCase(IMAGE_SCN_TYPE_NO_PAD);
216   BCase(IMAGE_SCN_CNT_CODE);
217   BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
218   BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
219   BCase(IMAGE_SCN_LNK_OTHER);
220   BCase(IMAGE_SCN_LNK_INFO);
221   BCase(IMAGE_SCN_LNK_REMOVE);
222   BCase(IMAGE_SCN_LNK_COMDAT);
223   BCase(IMAGE_SCN_GPREL);
224   BCase(IMAGE_SCN_MEM_PURGEABLE);
225   BCase(IMAGE_SCN_MEM_16BIT);
226   BCase(IMAGE_SCN_MEM_LOCKED);
227   BCase(IMAGE_SCN_MEM_PRELOAD);
228   BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
229   BCase(IMAGE_SCN_MEM_DISCARDABLE);
230   BCase(IMAGE_SCN_MEM_NOT_CACHED);
231   BCase(IMAGE_SCN_MEM_NOT_PAGED);
232   BCase(IMAGE_SCN_MEM_SHARED);
233   BCase(IMAGE_SCN_MEM_EXECUTE);
234   BCase(IMAGE_SCN_MEM_READ);
235   BCase(IMAGE_SCN_MEM_WRITE);
236 }
237 
bitset(IO & IO,COFF::DLLCharacteristics & Value)238 void ScalarBitSetTraits<COFF::DLLCharacteristics>::bitset(
239     IO &IO, COFF::DLLCharacteristics &Value) {
240   BCase(IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA);
241   BCase(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE);
242   BCase(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY);
243   BCase(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT);
244   BCase(IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION);
245   BCase(IMAGE_DLL_CHARACTERISTICS_NO_SEH);
246   BCase(IMAGE_DLL_CHARACTERISTICS_NO_BIND);
247   BCase(IMAGE_DLL_CHARACTERISTICS_APPCONTAINER);
248   BCase(IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER);
249   BCase(IMAGE_DLL_CHARACTERISTICS_GUARD_CF);
250   BCase(IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE);
251 }
252 #undef BCase
253 
254 namespace {
255 struct NSectionSelectionType {
NSectionSelectionTypellvm::yaml::__anon16815bbb0111::NSectionSelectionType256   NSectionSelectionType(IO &)
257       : SelectionType(COFFYAML::COMDATType(0)) {}
NSectionSelectionTypellvm::yaml::__anon16815bbb0111::NSectionSelectionType258   NSectionSelectionType(IO &, uint8_t C)
259       : SelectionType(COFFYAML::COMDATType(C)) {}
denormalizellvm::yaml::__anon16815bbb0111::NSectionSelectionType260   uint8_t denormalize(IO &) { return SelectionType; }
261   COFFYAML::COMDATType SelectionType;
262 };
263 
264 struct NWeakExternalCharacteristics {
NWeakExternalCharacteristicsllvm::yaml::__anon16815bbb0111::NWeakExternalCharacteristics265   NWeakExternalCharacteristics(IO &)
266       : Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
NWeakExternalCharacteristicsllvm::yaml::__anon16815bbb0111::NWeakExternalCharacteristics267   NWeakExternalCharacteristics(IO &, uint32_t C)
268       : Characteristics(COFFYAML::WeakExternalCharacteristics(C)) {}
denormalizellvm::yaml::__anon16815bbb0111::NWeakExternalCharacteristics269   uint32_t denormalize(IO &) { return Characteristics; }
270   COFFYAML::WeakExternalCharacteristics Characteristics;
271 };
272 
273 struct NSectionCharacteristics {
NSectionCharacteristicsllvm::yaml::__anon16815bbb0111::NSectionCharacteristics274   NSectionCharacteristics(IO &)
275       : Characteristics(COFF::SectionCharacteristics(0)) {}
NSectionCharacteristicsllvm::yaml::__anon16815bbb0111::NSectionCharacteristics276   NSectionCharacteristics(IO &, uint32_t C)
277       : Characteristics(COFF::SectionCharacteristics(C)) {}
denormalizellvm::yaml::__anon16815bbb0111::NSectionCharacteristics278   uint32_t denormalize(IO &) { return Characteristics; }
279   COFF::SectionCharacteristics Characteristics;
280 };
281 
282 struct NAuxTokenType {
NAuxTokenTypellvm::yaml::__anon16815bbb0111::NAuxTokenType283   NAuxTokenType(IO &)
284       : AuxType(COFFYAML::AuxSymbolType(0)) {}
NAuxTokenTypellvm::yaml::__anon16815bbb0111::NAuxTokenType285   NAuxTokenType(IO &, uint8_t C)
286       : AuxType(COFFYAML::AuxSymbolType(C)) {}
denormalizellvm::yaml::__anon16815bbb0111::NAuxTokenType287   uint32_t denormalize(IO &) { return AuxType; }
288   COFFYAML::AuxSymbolType AuxType;
289 };
290 
291 struct NStorageClass {
NStorageClassllvm::yaml::__anon16815bbb0111::NStorageClass292   NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
NStorageClassllvm::yaml::__anon16815bbb0111::NStorageClass293   NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
denormalizellvm::yaml::__anon16815bbb0111::NStorageClass294   uint8_t denormalize(IO &) { return StorageClass; }
295 
296   COFF::SymbolStorageClass StorageClass;
297 };
298 
299 struct NMachine {
NMachinellvm::yaml::__anon16815bbb0111::NMachine300   NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
NMachinellvm::yaml::__anon16815bbb0111::NMachine301   NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
denormalizellvm::yaml::__anon16815bbb0111::NMachine302   uint16_t denormalize(IO &) { return Machine; }
303   COFF::MachineTypes Machine;
304 };
305 
306 struct NHeaderCharacteristics {
NHeaderCharacteristicsllvm::yaml::__anon16815bbb0111::NHeaderCharacteristics307   NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
NHeaderCharacteristicsllvm::yaml::__anon16815bbb0111::NHeaderCharacteristics308   NHeaderCharacteristics(IO &, uint16_t C)
309       : Characteristics(COFF::Characteristics(C)) {}
denormalizellvm::yaml::__anon16815bbb0111::NHeaderCharacteristics310   uint16_t denormalize(IO &) { return Characteristics; }
311 
312   COFF::Characteristics Characteristics;
313 };
314 
315 template <typename RelocType>
316 struct NType {
NTypellvm::yaml::__anon16815bbb0111::NType317   NType(IO &) : Type(RelocType(0)) {}
NTypellvm::yaml::__anon16815bbb0111::NType318   NType(IO &, uint16_t T) : Type(RelocType(T)) {}
denormalizellvm::yaml::__anon16815bbb0111::NType319   uint16_t denormalize(IO &) { return Type; }
320   RelocType Type;
321 };
322 
323 struct NWindowsSubsystem {
NWindowsSubsystemllvm::yaml::__anon16815bbb0111::NWindowsSubsystem324   NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
NWindowsSubsystemllvm::yaml::__anon16815bbb0111::NWindowsSubsystem325   NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
denormalizellvm::yaml::__anon16815bbb0111::NWindowsSubsystem326   uint16_t denormalize(IO &) { return Subsystem; }
327 
328   COFF::WindowsSubsystem Subsystem;
329 };
330 
331 struct NDLLCharacteristics {
NDLLCharacteristicsllvm::yaml::__anon16815bbb0111::NDLLCharacteristics332   NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
NDLLCharacteristicsllvm::yaml::__anon16815bbb0111::NDLLCharacteristics333   NDLLCharacteristics(IO &, uint16_t C)
334       : Characteristics(COFF::DLLCharacteristics(C)) {}
denormalizellvm::yaml::__anon16815bbb0111::NDLLCharacteristics335   uint16_t denormalize(IO &) { return Characteristics; }
336 
337   COFF::DLLCharacteristics Characteristics;
338 };
339 
340 }
341 
mapping(IO & IO,COFFYAML::Relocation & Rel)342 void MappingTraits<COFFYAML::Relocation>::mapping(IO &IO,
343                                                   COFFYAML::Relocation &Rel) {
344   IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
345   IO.mapRequired("SymbolName", Rel.SymbolName);
346 
347   COFF::header &H = *static_cast<COFF::header *>(IO.getContext());
348   if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
349     MappingNormalization<NType<COFF::RelocationTypeI386>, uint16_t> NT(
350         IO, Rel.Type);
351     IO.mapRequired("Type", NT->Type);
352   } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
353     MappingNormalization<NType<COFF::RelocationTypeAMD64>, uint16_t> NT(
354         IO, Rel.Type);
355     IO.mapRequired("Type", NT->Type);
356   } else {
357     IO.mapRequired("Type", Rel.Type);
358   }
359 }
360 
mapping(IO & IO,COFF::DataDirectory & DD)361 void MappingTraits<COFF::DataDirectory>::mapping(IO &IO,
362                                                  COFF::DataDirectory &DD) {
363   IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
364   IO.mapRequired("Size", DD.Size);
365 }
366 
mapping(IO & IO,COFFYAML::PEHeader & PH)367 void MappingTraits<COFFYAML::PEHeader>::mapping(IO &IO,
368                                                 COFFYAML::PEHeader &PH) {
369   MappingNormalization<NWindowsSubsystem, uint16_t> NWS(IO,
370                                                         PH.Header.Subsystem);
371   MappingNormalization<NDLLCharacteristics, uint16_t> NDC(
372       IO, PH.Header.DLLCharacteristics);
373 
374   IO.mapRequired("AddressOfEntryPoint", PH.Header.AddressOfEntryPoint);
375   IO.mapRequired("ImageBase", PH.Header.ImageBase);
376   IO.mapRequired("SectionAlignment", PH.Header.SectionAlignment);
377   IO.mapRequired("FileAlignment", PH.Header.FileAlignment);
378   IO.mapRequired("MajorOperatingSystemVersion",
379                  PH.Header.MajorOperatingSystemVersion);
380   IO.mapRequired("MinorOperatingSystemVersion",
381                  PH.Header.MinorOperatingSystemVersion);
382   IO.mapRequired("MajorImageVersion", PH.Header.MajorImageVersion);
383   IO.mapRequired("MinorImageVersion", PH.Header.MinorImageVersion);
384   IO.mapRequired("MajorSubsystemVersion", PH.Header.MajorSubsystemVersion);
385   IO.mapRequired("MinorSubsystemVersion", PH.Header.MinorSubsystemVersion);
386   IO.mapRequired("Subsystem", NWS->Subsystem);
387   IO.mapRequired("DLLCharacteristics", NDC->Characteristics);
388   IO.mapRequired("SizeOfStackReserve", PH.Header.SizeOfStackReserve);
389   IO.mapRequired("SizeOfStackCommit", PH.Header.SizeOfStackCommit);
390   IO.mapRequired("SizeOfHeapReserve", PH.Header.SizeOfHeapReserve);
391   IO.mapRequired("SizeOfHeapCommit", PH.Header.SizeOfHeapCommit);
392 
393   IO.mapOptional("ExportTable", PH.DataDirectories[COFF::EXPORT_TABLE]);
394   IO.mapOptional("ImportTable", PH.DataDirectories[COFF::IMPORT_TABLE]);
395   IO.mapOptional("ResourceTable", PH.DataDirectories[COFF::RESOURCE_TABLE]);
396   IO.mapOptional("ExceptionTable", PH.DataDirectories[COFF::EXCEPTION_TABLE]);
397   IO.mapOptional("CertificateTable", PH.DataDirectories[COFF::CERTIFICATE_TABLE]);
398   IO.mapOptional("BaseRelocationTable",
399                  PH.DataDirectories[COFF::BASE_RELOCATION_TABLE]);
400   IO.mapOptional("Debug", PH.DataDirectories[COFF::DEBUG_DIRECTORY]);
401   IO.mapOptional("Architecture", PH.DataDirectories[COFF::ARCHITECTURE]);
402   IO.mapOptional("GlobalPtr", PH.DataDirectories[COFF::GLOBAL_PTR]);
403   IO.mapOptional("TlsTable", PH.DataDirectories[COFF::TLS_TABLE]);
404   IO.mapOptional("LoadConfigTable",
405                  PH.DataDirectories[COFF::LOAD_CONFIG_TABLE]);
406   IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
407   IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
408   IO.mapOptional("DelayImportDescriptor",
409                  PH.DataDirectories[COFF::DELAY_IMPORT_DESCRIPTOR]);
410   IO.mapOptional("ClrRuntimeHeader",
411                  PH.DataDirectories[COFF::CLR_RUNTIME_HEADER]);
412 }
413 
mapping(IO & IO,COFF::header & H)414 void MappingTraits<COFF::header>::mapping(IO &IO, COFF::header &H) {
415   MappingNormalization<NMachine, uint16_t> NM(IO, H.Machine);
416   MappingNormalization<NHeaderCharacteristics, uint16_t> NC(IO,
417                                                             H.Characteristics);
418 
419   IO.mapRequired("Machine", NM->Machine);
420   IO.mapOptional("Characteristics", NC->Characteristics);
421   IO.setContext(static_cast<void *>(&H));
422 }
423 
mapping(IO & IO,COFF::AuxiliaryFunctionDefinition & AFD)424 void MappingTraits<COFF::AuxiliaryFunctionDefinition>::mapping(
425     IO &IO, COFF::AuxiliaryFunctionDefinition &AFD) {
426   IO.mapRequired("TagIndex", AFD.TagIndex);
427   IO.mapRequired("TotalSize", AFD.TotalSize);
428   IO.mapRequired("PointerToLinenumber", AFD.PointerToLinenumber);
429   IO.mapRequired("PointerToNextFunction", AFD.PointerToNextFunction);
430 }
431 
mapping(IO & IO,COFF::AuxiliarybfAndefSymbol & AAS)432 void MappingTraits<COFF::AuxiliarybfAndefSymbol>::mapping(
433     IO &IO, COFF::AuxiliarybfAndefSymbol &AAS) {
434   IO.mapRequired("Linenumber", AAS.Linenumber);
435   IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
436 }
437 
mapping(IO & IO,COFF::AuxiliaryWeakExternal & AWE)438 void MappingTraits<COFF::AuxiliaryWeakExternal>::mapping(
439     IO &IO, COFF::AuxiliaryWeakExternal &AWE) {
440   MappingNormalization<NWeakExternalCharacteristics, uint32_t> NWEC(
441       IO, AWE.Characteristics);
442   IO.mapRequired("TagIndex", AWE.TagIndex);
443   IO.mapRequired("Characteristics", NWEC->Characteristics);
444 }
445 
mapping(IO & IO,COFF::AuxiliarySectionDefinition & ASD)446 void MappingTraits<COFF::AuxiliarySectionDefinition>::mapping(
447     IO &IO, COFF::AuxiliarySectionDefinition &ASD) {
448   MappingNormalization<NSectionSelectionType, uint8_t> NSST(
449       IO, ASD.Selection);
450 
451   IO.mapRequired("Length", ASD.Length);
452   IO.mapRequired("NumberOfRelocations", ASD.NumberOfRelocations);
453   IO.mapRequired("NumberOfLinenumbers", ASD.NumberOfLinenumbers);
454   IO.mapRequired("CheckSum", ASD.CheckSum);
455   IO.mapRequired("Number", ASD.Number);
456   IO.mapOptional("Selection", NSST->SelectionType, COFFYAML::COMDATType(0));
457 }
458 
mapping(IO & IO,COFF::AuxiliaryCLRToken & ACT)459 void MappingTraits<COFF::AuxiliaryCLRToken>::mapping(
460     IO &IO, COFF::AuxiliaryCLRToken &ACT) {
461   MappingNormalization<NAuxTokenType, uint8_t> NATT(IO, ACT.AuxType);
462   IO.mapRequired("AuxType", NATT->AuxType);
463   IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
464 }
465 
mapping(IO & IO,COFFYAML::Symbol & S)466 void MappingTraits<COFFYAML::Symbol>::mapping(IO &IO, COFFYAML::Symbol &S) {
467   MappingNormalization<NStorageClass, uint8_t> NS(IO, S.Header.StorageClass);
468 
469   IO.mapRequired("Name", S.Name);
470   IO.mapRequired("Value", S.Header.Value);
471   IO.mapRequired("SectionNumber", S.Header.SectionNumber);
472   IO.mapRequired("SimpleType", S.SimpleType);
473   IO.mapRequired("ComplexType", S.ComplexType);
474   IO.mapRequired("StorageClass", NS->StorageClass);
475   IO.mapOptional("FunctionDefinition", S.FunctionDefinition);
476   IO.mapOptional("bfAndefSymbol", S.bfAndefSymbol);
477   IO.mapOptional("WeakExternal", S.WeakExternal);
478   IO.mapOptional("File", S.File, StringRef());
479   IO.mapOptional("SectionDefinition", S.SectionDefinition);
480   IO.mapOptional("CLRToken", S.CLRToken);
481 }
482 
mapping(IO & IO,COFFYAML::Section & Sec)483 void MappingTraits<COFFYAML::Section>::mapping(IO &IO, COFFYAML::Section &Sec) {
484   MappingNormalization<NSectionCharacteristics, uint32_t> NC(
485       IO, Sec.Header.Characteristics);
486   IO.mapRequired("Name", Sec.Name);
487   IO.mapRequired("Characteristics", NC->Characteristics);
488   IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
489   IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
490   IO.mapOptional("Alignment", Sec.Alignment, 0U);
491   IO.mapRequired("SectionData", Sec.SectionData);
492   IO.mapOptional("Relocations", Sec.Relocations);
493 }
494 
mapping(IO & IO,COFFYAML::Object & Obj)495 void MappingTraits<COFFYAML::Object>::mapping(IO &IO, COFFYAML::Object &Obj) {
496   IO.mapTag("!COFF", true);
497   IO.mapOptional("OptionalHeader", Obj.OptionalHeader);
498   IO.mapRequired("header", Obj.Header);
499   IO.mapRequired("sections", Obj.Sections);
500   IO.mapRequired("symbols", Obj.Symbols);
501 }
502 
503 }
504 }
505