Line data Source code
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 : #include "llvm/ADT/StringRef.h"
16 : #include "llvm/Support/YAMLTraits.h"
17 : #include <cstdint>
18 : #include <cstring>
19 :
20 : #define ECase(X) IO.enumCase(Value, #X, COFF::X);
21 :
22 : namespace llvm {
23 :
24 : namespace COFFYAML {
25 :
26 1348 : Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
27 2680 : Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
28 516 : Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
29 :
30 : } // end namespace COFFYAML
31 :
32 : namespace yaml {
33 :
34 97 : void ScalarEnumerationTraits<COFFYAML::COMDATType>::enumeration(
35 : IO &IO, COFFYAML::COMDATType &Value) {
36 97 : IO.enumCase(Value, "0", 0);
37 97 : ECase(IMAGE_COMDAT_SELECT_NODUPLICATES);
38 97 : ECase(IMAGE_COMDAT_SELECT_ANY);
39 97 : ECase(IMAGE_COMDAT_SELECT_SAME_SIZE);
40 97 : ECase(IMAGE_COMDAT_SELECT_EXACT_MATCH);
41 97 : ECase(IMAGE_COMDAT_SELECT_ASSOCIATIVE);
42 97 : ECase(IMAGE_COMDAT_SELECT_LARGEST);
43 97 : ECase(IMAGE_COMDAT_SELECT_NEWEST);
44 97 : }
45 :
46 : void
47 6 : ScalarEnumerationTraits<COFFYAML::WeakExternalCharacteristics>::enumeration(
48 : IO &IO, COFFYAML::WeakExternalCharacteristics &Value) {
49 6 : IO.enumCase(Value, "0", 0);
50 6 : ECase(IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY);
51 6 : ECase(IMAGE_WEAK_EXTERN_SEARCH_LIBRARY);
52 6 : ECase(IMAGE_WEAK_EXTERN_SEARCH_ALIAS);
53 6 : }
54 :
55 0 : void ScalarEnumerationTraits<COFFYAML::AuxSymbolType>::enumeration(
56 : IO &IO, COFFYAML::AuxSymbolType &Value) {
57 0 : ECase(IMAGE_AUX_SYMBOL_TYPE_TOKEN_DEF);
58 0 : }
59 :
60 258 : void ScalarEnumerationTraits<COFF::MachineTypes>::enumeration(
61 : IO &IO, COFF::MachineTypes &Value) {
62 258 : ECase(IMAGE_FILE_MACHINE_UNKNOWN);
63 258 : ECase(IMAGE_FILE_MACHINE_AM33);
64 258 : ECase(IMAGE_FILE_MACHINE_AMD64);
65 258 : ECase(IMAGE_FILE_MACHINE_ARM);
66 258 : ECase(IMAGE_FILE_MACHINE_ARMNT);
67 258 : ECase(IMAGE_FILE_MACHINE_ARM64);
68 258 : ECase(IMAGE_FILE_MACHINE_EBC);
69 258 : ECase(IMAGE_FILE_MACHINE_I386);
70 258 : ECase(IMAGE_FILE_MACHINE_IA64);
71 258 : ECase(IMAGE_FILE_MACHINE_M32R);
72 258 : ECase(IMAGE_FILE_MACHINE_MIPS16);
73 258 : ECase(IMAGE_FILE_MACHINE_MIPSFPU);
74 258 : ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
75 258 : ECase(IMAGE_FILE_MACHINE_POWERPC);
76 258 : ECase(IMAGE_FILE_MACHINE_POWERPCFP);
77 258 : ECase(IMAGE_FILE_MACHINE_R4000);
78 258 : ECase(IMAGE_FILE_MACHINE_SH3);
79 258 : ECase(IMAGE_FILE_MACHINE_SH3DSP);
80 258 : ECase(IMAGE_FILE_MACHINE_SH4);
81 258 : ECase(IMAGE_FILE_MACHINE_SH5);
82 258 : ECase(IMAGE_FILE_MACHINE_THUMB);
83 258 : ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
84 258 : }
85 :
86 1340 : void ScalarEnumerationTraits<COFF::SymbolBaseType>::enumeration(
87 : IO &IO, COFF::SymbolBaseType &Value) {
88 1340 : ECase(IMAGE_SYM_TYPE_NULL);
89 1340 : ECase(IMAGE_SYM_TYPE_VOID);
90 1340 : ECase(IMAGE_SYM_TYPE_CHAR);
91 1340 : ECase(IMAGE_SYM_TYPE_SHORT);
92 1340 : ECase(IMAGE_SYM_TYPE_INT);
93 1340 : ECase(IMAGE_SYM_TYPE_LONG);
94 1340 : ECase(IMAGE_SYM_TYPE_FLOAT);
95 1340 : ECase(IMAGE_SYM_TYPE_DOUBLE);
96 1340 : ECase(IMAGE_SYM_TYPE_STRUCT);
97 1340 : ECase(IMAGE_SYM_TYPE_UNION);
98 1340 : ECase(IMAGE_SYM_TYPE_ENUM);
99 1340 : ECase(IMAGE_SYM_TYPE_MOE);
100 1340 : ECase(IMAGE_SYM_TYPE_BYTE);
101 1340 : ECase(IMAGE_SYM_TYPE_WORD);
102 1340 : ECase(IMAGE_SYM_TYPE_UINT);
103 1340 : ECase(IMAGE_SYM_TYPE_DWORD);
104 1340 : }
105 :
106 1340 : void ScalarEnumerationTraits<COFF::SymbolStorageClass>::enumeration(
107 : IO &IO, COFF::SymbolStorageClass &Value) {
108 1340 : ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
109 1340 : ECase(IMAGE_SYM_CLASS_NULL);
110 1340 : ECase(IMAGE_SYM_CLASS_AUTOMATIC);
111 1340 : ECase(IMAGE_SYM_CLASS_EXTERNAL);
112 1340 : ECase(IMAGE_SYM_CLASS_STATIC);
113 1340 : ECase(IMAGE_SYM_CLASS_REGISTER);
114 1340 : ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
115 1340 : ECase(IMAGE_SYM_CLASS_LABEL);
116 1340 : ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
117 1340 : ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
118 1340 : ECase(IMAGE_SYM_CLASS_ARGUMENT);
119 1340 : ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
120 1340 : ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
121 1340 : ECase(IMAGE_SYM_CLASS_UNION_TAG);
122 1340 : ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
123 1340 : ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
124 1340 : ECase(IMAGE_SYM_CLASS_ENUM_TAG);
125 1340 : ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
126 1340 : ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
127 1340 : ECase(IMAGE_SYM_CLASS_BIT_FIELD);
128 1340 : ECase(IMAGE_SYM_CLASS_BLOCK);
129 1340 : ECase(IMAGE_SYM_CLASS_FUNCTION);
130 1340 : ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
131 1340 : ECase(IMAGE_SYM_CLASS_FILE);
132 1340 : ECase(IMAGE_SYM_CLASS_SECTION);
133 1340 : ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
134 1340 : ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
135 1340 : }
136 :
137 1340 : void ScalarEnumerationTraits<COFF::SymbolComplexType>::enumeration(
138 : IO &IO, COFF::SymbolComplexType &Value) {
139 1340 : ECase(IMAGE_SYM_DTYPE_NULL);
140 1340 : ECase(IMAGE_SYM_DTYPE_POINTER);
141 1340 : ECase(IMAGE_SYM_DTYPE_FUNCTION);
142 1340 : ECase(IMAGE_SYM_DTYPE_ARRAY);
143 1340 : }
144 :
145 201 : void ScalarEnumerationTraits<COFF::RelocationTypeI386>::enumeration(
146 : IO &IO, COFF::RelocationTypeI386 &Value) {
147 201 : ECase(IMAGE_REL_I386_ABSOLUTE);
148 201 : ECase(IMAGE_REL_I386_DIR16);
149 201 : ECase(IMAGE_REL_I386_REL16);
150 201 : ECase(IMAGE_REL_I386_DIR32);
151 201 : ECase(IMAGE_REL_I386_DIR32NB);
152 201 : ECase(IMAGE_REL_I386_SEG12);
153 201 : ECase(IMAGE_REL_I386_SECTION);
154 201 : ECase(IMAGE_REL_I386_SECREL);
155 201 : ECase(IMAGE_REL_I386_TOKEN);
156 201 : ECase(IMAGE_REL_I386_SECREL7);
157 201 : ECase(IMAGE_REL_I386_REL32);
158 201 : }
159 :
160 500 : void ScalarEnumerationTraits<COFF::RelocationTypeAMD64>::enumeration(
161 : IO &IO, COFF::RelocationTypeAMD64 &Value) {
162 500 : ECase(IMAGE_REL_AMD64_ABSOLUTE);
163 500 : ECase(IMAGE_REL_AMD64_ADDR64);
164 500 : ECase(IMAGE_REL_AMD64_ADDR32);
165 500 : ECase(IMAGE_REL_AMD64_ADDR32NB);
166 500 : ECase(IMAGE_REL_AMD64_REL32);
167 500 : ECase(IMAGE_REL_AMD64_REL32_1);
168 500 : ECase(IMAGE_REL_AMD64_REL32_2);
169 500 : ECase(IMAGE_REL_AMD64_REL32_3);
170 500 : ECase(IMAGE_REL_AMD64_REL32_4);
171 500 : ECase(IMAGE_REL_AMD64_REL32_5);
172 500 : ECase(IMAGE_REL_AMD64_SECTION);
173 500 : ECase(IMAGE_REL_AMD64_SECREL);
174 500 : ECase(IMAGE_REL_AMD64_SECREL7);
175 500 : ECase(IMAGE_REL_AMD64_TOKEN);
176 500 : ECase(IMAGE_REL_AMD64_SREL32);
177 500 : ECase(IMAGE_REL_AMD64_PAIR);
178 500 : ECase(IMAGE_REL_AMD64_SSPAN32);
179 500 : }
180 :
181 16 : void ScalarEnumerationTraits<COFF::RelocationTypesARM>::enumeration(
182 : IO &IO, COFF::RelocationTypesARM &Value) {
183 16 : ECase(IMAGE_REL_ARM_ABSOLUTE);
184 16 : ECase(IMAGE_REL_ARM_ADDR32);
185 16 : ECase(IMAGE_REL_ARM_ADDR32NB);
186 16 : ECase(IMAGE_REL_ARM_BRANCH24);
187 16 : ECase(IMAGE_REL_ARM_BRANCH11);
188 16 : ECase(IMAGE_REL_ARM_TOKEN);
189 16 : ECase(IMAGE_REL_ARM_BLX24);
190 16 : ECase(IMAGE_REL_ARM_BLX11);
191 16 : ECase(IMAGE_REL_ARM_SECTION);
192 16 : ECase(IMAGE_REL_ARM_SECREL);
193 16 : ECase(IMAGE_REL_ARM_MOV32A);
194 16 : ECase(IMAGE_REL_ARM_MOV32T);
195 16 : ECase(IMAGE_REL_ARM_BRANCH20T);
196 16 : ECase(IMAGE_REL_ARM_BRANCH24T);
197 16 : ECase(IMAGE_REL_ARM_BLX23T);
198 16 : }
199 :
200 46 : void ScalarEnumerationTraits<COFF::RelocationTypesARM64>::enumeration(
201 : IO &IO, COFF::RelocationTypesARM64 &Value) {
202 46 : ECase(IMAGE_REL_ARM64_ABSOLUTE);
203 46 : ECase(IMAGE_REL_ARM64_ADDR32);
204 46 : ECase(IMAGE_REL_ARM64_ADDR32NB);
205 46 : ECase(IMAGE_REL_ARM64_BRANCH26);
206 46 : ECase(IMAGE_REL_ARM64_PAGEBASE_REL21);
207 46 : ECase(IMAGE_REL_ARM64_REL21);
208 46 : ECase(IMAGE_REL_ARM64_PAGEOFFSET_12A);
209 46 : ECase(IMAGE_REL_ARM64_PAGEOFFSET_12L);
210 46 : ECase(IMAGE_REL_ARM64_SECREL);
211 46 : ECase(IMAGE_REL_ARM64_SECREL_LOW12A);
212 46 : ECase(IMAGE_REL_ARM64_SECREL_HIGH12A);
213 46 : ECase(IMAGE_REL_ARM64_SECREL_LOW12L);
214 46 : ECase(IMAGE_REL_ARM64_TOKEN);
215 46 : ECase(IMAGE_REL_ARM64_SECTION);
216 46 : ECase(IMAGE_REL_ARM64_ADDR64);
217 46 : ECase(IMAGE_REL_ARM64_BRANCH19);
218 46 : ECase(IMAGE_REL_ARM64_BRANCH14);
219 46 : }
220 :
221 1 : void ScalarEnumerationTraits<COFF::WindowsSubsystem>::enumeration(
222 : IO &IO, COFF::WindowsSubsystem &Value) {
223 1 : ECase(IMAGE_SUBSYSTEM_UNKNOWN);
224 1 : ECase(IMAGE_SUBSYSTEM_NATIVE);
225 1 : ECase(IMAGE_SUBSYSTEM_WINDOWS_GUI);
226 1 : ECase(IMAGE_SUBSYSTEM_WINDOWS_CUI);
227 1 : ECase(IMAGE_SUBSYSTEM_OS2_CUI);
228 1 : ECase(IMAGE_SUBSYSTEM_POSIX_CUI);
229 1 : ECase(IMAGE_SUBSYSTEM_NATIVE_WINDOWS);
230 1 : ECase(IMAGE_SUBSYSTEM_WINDOWS_CE_GUI);
231 1 : ECase(IMAGE_SUBSYSTEM_EFI_APPLICATION);
232 1 : ECase(IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER);
233 1 : ECase(IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER);
234 1 : ECase(IMAGE_SUBSYSTEM_EFI_ROM);
235 1 : ECase(IMAGE_SUBSYSTEM_XBOX);
236 1 : ECase(IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION);
237 1 : }
238 : #undef ECase
239 :
240 : #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
241 256 : void ScalarBitSetTraits<COFF::Characteristics>::bitset(
242 : IO &IO, COFF::Characteristics &Value) {
243 256 : BCase(IMAGE_FILE_RELOCS_STRIPPED);
244 256 : BCase(IMAGE_FILE_EXECUTABLE_IMAGE);
245 256 : BCase(IMAGE_FILE_LINE_NUMS_STRIPPED);
246 256 : BCase(IMAGE_FILE_LOCAL_SYMS_STRIPPED);
247 256 : BCase(IMAGE_FILE_AGGRESSIVE_WS_TRIM);
248 256 : BCase(IMAGE_FILE_LARGE_ADDRESS_AWARE);
249 256 : BCase(IMAGE_FILE_BYTES_REVERSED_LO);
250 256 : BCase(IMAGE_FILE_32BIT_MACHINE);
251 256 : BCase(IMAGE_FILE_DEBUG_STRIPPED);
252 256 : BCase(IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP);
253 256 : BCase(IMAGE_FILE_NET_RUN_FROM_SWAP);
254 256 : BCase(IMAGE_FILE_SYSTEM);
255 256 : BCase(IMAGE_FILE_DLL);
256 256 : BCase(IMAGE_FILE_UP_SYSTEM_ONLY);
257 256 : BCase(IMAGE_FILE_BYTES_REVERSED_HI);
258 256 : }
259 :
260 674 : void ScalarBitSetTraits<COFF::SectionCharacteristics>::bitset(
261 : IO &IO, COFF::SectionCharacteristics &Value) {
262 674 : BCase(IMAGE_SCN_TYPE_NOLOAD);
263 674 : BCase(IMAGE_SCN_TYPE_NO_PAD);
264 674 : BCase(IMAGE_SCN_CNT_CODE);
265 674 : BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
266 674 : BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
267 674 : BCase(IMAGE_SCN_LNK_OTHER);
268 674 : BCase(IMAGE_SCN_LNK_INFO);
269 674 : BCase(IMAGE_SCN_LNK_REMOVE);
270 674 : BCase(IMAGE_SCN_LNK_COMDAT);
271 674 : BCase(IMAGE_SCN_GPREL);
272 674 : BCase(IMAGE_SCN_MEM_PURGEABLE);
273 674 : BCase(IMAGE_SCN_MEM_16BIT);
274 674 : BCase(IMAGE_SCN_MEM_LOCKED);
275 674 : BCase(IMAGE_SCN_MEM_PRELOAD);
276 674 : BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
277 674 : BCase(IMAGE_SCN_MEM_DISCARDABLE);
278 674 : BCase(IMAGE_SCN_MEM_NOT_CACHED);
279 674 : BCase(IMAGE_SCN_MEM_NOT_PAGED);
280 674 : BCase(IMAGE_SCN_MEM_SHARED);
281 674 : BCase(IMAGE_SCN_MEM_EXECUTE);
282 674 : BCase(IMAGE_SCN_MEM_READ);
283 674 : BCase(IMAGE_SCN_MEM_WRITE);
284 674 : }
285 :
286 1 : void ScalarBitSetTraits<COFF::DLLCharacteristics>::bitset(
287 : IO &IO, COFF::DLLCharacteristics &Value) {
288 1 : BCase(IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA);
289 1 : BCase(IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE);
290 1 : BCase(IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY);
291 1 : BCase(IMAGE_DLL_CHARACTERISTICS_NX_COMPAT);
292 1 : BCase(IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION);
293 1 : BCase(IMAGE_DLL_CHARACTERISTICS_NO_SEH);
294 1 : BCase(IMAGE_DLL_CHARACTERISTICS_NO_BIND);
295 1 : BCase(IMAGE_DLL_CHARACTERISTICS_APPCONTAINER);
296 1 : BCase(IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER);
297 1 : BCase(IMAGE_DLL_CHARACTERISTICS_GUARD_CF);
298 1 : BCase(IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE);
299 1 : }
300 : #undef BCase
301 :
302 : namespace {
303 :
304 : struct NSectionSelectionType {
305 0 : NSectionSelectionType(IO &)
306 0 : : SelectionType(COFFYAML::COMDATType(0)) {}
307 : NSectionSelectionType(IO &, uint8_t C)
308 : : SelectionType(COFFYAML::COMDATType(C)) {}
309 :
310 579 : uint8_t denormalize(IO &) { return SelectionType; }
311 :
312 : COFFYAML::COMDATType SelectionType;
313 : };
314 :
315 : struct NWeakExternalCharacteristics {
316 0 : NWeakExternalCharacteristics(IO &)
317 0 : : Characteristics(COFFYAML::WeakExternalCharacteristics(0)) {}
318 0 : NWeakExternalCharacteristics(IO &, uint32_t C)
319 0 : : Characteristics(COFFYAML::WeakExternalCharacteristics(C)) {}
320 :
321 5 : uint32_t denormalize(IO &) { return Characteristics; }
322 :
323 : COFFYAML::WeakExternalCharacteristics Characteristics;
324 : };
325 :
326 : struct NSectionCharacteristics {
327 0 : NSectionCharacteristics(IO &)
328 628 : : Characteristics(COFF::SectionCharacteristics(0)) {}
329 0 : NSectionCharacteristics(IO &, uint32_t C)
330 46 : : Characteristics(COFF::SectionCharacteristics(C)) {}
331 :
332 0 : uint32_t denormalize(IO &) { return Characteristics; }
333 :
334 : COFF::SectionCharacteristics Characteristics;
335 : };
336 :
337 : struct NAuxTokenType {
338 0 : NAuxTokenType(IO &)
339 0 : : AuxType(COFFYAML::AuxSymbolType(0)) {}
340 : NAuxTokenType(IO &, uint8_t C)
341 : : AuxType(COFFYAML::AuxSymbolType(C)) {}
342 :
343 0 : uint32_t denormalize(IO &) { return AuxType; }
344 :
345 : COFFYAML::AuxSymbolType AuxType;
346 : };
347 :
348 : struct NStorageClass {
349 1250 : NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
350 90 : NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
351 :
352 1250 : uint8_t denormalize(IO &) { return StorageClass; }
353 :
354 : COFF::SymbolStorageClass StorageClass;
355 : };
356 :
357 : struct NMachine {
358 244 : NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
359 14 : NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
360 :
361 244 : uint16_t denormalize(IO &) { return Machine; }
362 :
363 : COFF::MachineTypes Machine;
364 : };
365 :
366 : struct NHeaderCharacteristics {
367 244 : NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
368 : NHeaderCharacteristics(IO &, uint16_t C)
369 14 : : Characteristics(COFF::Characteristics(C)) {}
370 :
371 244 : uint16_t denormalize(IO &) { return Characteristics; }
372 :
373 : COFF::Characteristics Characteristics;
374 : };
375 :
376 : template <typename RelocType>
377 : struct NType {
378 703 : NType(IO &) : Type(RelocType(0)) {}
379 60 : NType(IO &, uint16_t T) : Type(RelocType(T)) {}
380 :
381 703 : uint16_t denormalize(IO &) { return Type; }
382 :
383 : RelocType Type;
384 : };
385 :
386 : struct NWindowsSubsystem {
387 1 : NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
388 0 : NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
389 :
390 1 : uint16_t denormalize(IO &) { return Subsystem; }
391 :
392 : COFF::WindowsSubsystem Subsystem;
393 : };
394 :
395 : struct NDLLCharacteristics {
396 1 : NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
397 : NDLLCharacteristics(IO &, uint16_t C)
398 0 : : Characteristics(COFF::DLLCharacteristics(C)) {}
399 :
400 1 : uint16_t denormalize(IO &) { return Characteristics; }
401 :
402 : COFF::DLLCharacteristics Characteristics;
403 : };
404 :
405 : } // end anonymous namespace
406 :
407 763 : void MappingTraits<COFFYAML::Relocation>::mapping(IO &IO,
408 : COFFYAML::Relocation &Rel) {
409 763 : IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
410 763 : IO.mapRequired("SymbolName", Rel.SymbolName);
411 :
412 763 : COFF::header &H = *static_cast<COFF::header *>(IO.getContext());
413 763 : if (H.Machine == COFF::IMAGE_FILE_MACHINE_I386) {
414 : MappingNormalization<NType<COFF::RelocationTypeI386>, uint16_t> NT(
415 201 : IO, Rel.Type);
416 201 : IO.mapRequired("Type", NT->Type);
417 562 : } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
418 : MappingNormalization<NType<COFF::RelocationTypeAMD64>, uint16_t> NT(
419 500 : IO, Rel.Type);
420 500 : IO.mapRequired("Type", NT->Type);
421 62 : } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_ARMNT) {
422 : MappingNormalization<NType<COFF::RelocationTypesARM>, uint16_t> NT(
423 16 : IO, Rel.Type);
424 16 : IO.mapRequired("Type", NT->Type);
425 46 : } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_ARM64) {
426 : MappingNormalization<NType<COFF::RelocationTypesARM64>, uint16_t> NT(
427 46 : IO, Rel.Type);
428 46 : IO.mapRequired("Type", NT->Type);
429 : } else {
430 0 : IO.mapRequired("Type", Rel.Type);
431 : }
432 763 : }
433 :
434 0 : void MappingTraits<COFF::DataDirectory>::mapping(IO &IO,
435 : COFF::DataDirectory &DD) {
436 0 : IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
437 0 : IO.mapRequired("Size", DD.Size);
438 0 : }
439 :
440 1 : void MappingTraits<COFFYAML::PEHeader>::mapping(IO &IO,
441 : COFFYAML::PEHeader &PH) {
442 : MappingNormalization<NWindowsSubsystem, uint16_t> NWS(IO,
443 1 : PH.Header.Subsystem);
444 : MappingNormalization<NDLLCharacteristics, uint16_t> NDC(
445 1 : IO, PH.Header.DLLCharacteristics);
446 :
447 1 : IO.mapRequired("AddressOfEntryPoint", PH.Header.AddressOfEntryPoint);
448 1 : IO.mapRequired("ImageBase", PH.Header.ImageBase);
449 1 : IO.mapRequired("SectionAlignment", PH.Header.SectionAlignment);
450 1 : IO.mapRequired("FileAlignment", PH.Header.FileAlignment);
451 : IO.mapRequired("MajorOperatingSystemVersion",
452 1 : PH.Header.MajorOperatingSystemVersion);
453 : IO.mapRequired("MinorOperatingSystemVersion",
454 1 : PH.Header.MinorOperatingSystemVersion);
455 1 : IO.mapRequired("MajorImageVersion", PH.Header.MajorImageVersion);
456 1 : IO.mapRequired("MinorImageVersion", PH.Header.MinorImageVersion);
457 1 : IO.mapRequired("MajorSubsystemVersion", PH.Header.MajorSubsystemVersion);
458 1 : IO.mapRequired("MinorSubsystemVersion", PH.Header.MinorSubsystemVersion);
459 1 : IO.mapRequired("Subsystem", NWS->Subsystem);
460 1 : IO.mapRequired("DLLCharacteristics", NDC->Characteristics);
461 1 : IO.mapRequired("SizeOfStackReserve", PH.Header.SizeOfStackReserve);
462 1 : IO.mapRequired("SizeOfStackCommit", PH.Header.SizeOfStackCommit);
463 1 : IO.mapRequired("SizeOfHeapReserve", PH.Header.SizeOfHeapReserve);
464 1 : IO.mapRequired("SizeOfHeapCommit", PH.Header.SizeOfHeapCommit);
465 :
466 1 : IO.mapOptional("ExportTable", PH.DataDirectories[COFF::EXPORT_TABLE]);
467 1 : IO.mapOptional("ImportTable", PH.DataDirectories[COFF::IMPORT_TABLE]);
468 1 : IO.mapOptional("ResourceTable", PH.DataDirectories[COFF::RESOURCE_TABLE]);
469 1 : IO.mapOptional("ExceptionTable", PH.DataDirectories[COFF::EXCEPTION_TABLE]);
470 1 : IO.mapOptional("CertificateTable", PH.DataDirectories[COFF::CERTIFICATE_TABLE]);
471 : IO.mapOptional("BaseRelocationTable",
472 1 : PH.DataDirectories[COFF::BASE_RELOCATION_TABLE]);
473 1 : IO.mapOptional("Debug", PH.DataDirectories[COFF::DEBUG_DIRECTORY]);
474 1 : IO.mapOptional("Architecture", PH.DataDirectories[COFF::ARCHITECTURE]);
475 1 : IO.mapOptional("GlobalPtr", PH.DataDirectories[COFF::GLOBAL_PTR]);
476 1 : IO.mapOptional("TlsTable", PH.DataDirectories[COFF::TLS_TABLE]);
477 : IO.mapOptional("LoadConfigTable",
478 1 : PH.DataDirectories[COFF::LOAD_CONFIG_TABLE]);
479 1 : IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
480 1 : IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
481 : IO.mapOptional("DelayImportDescriptor",
482 1 : PH.DataDirectories[COFF::DELAY_IMPORT_DESCRIPTOR]);
483 : IO.mapOptional("ClrRuntimeHeader",
484 1 : PH.DataDirectories[COFF::CLR_RUNTIME_HEADER]);
485 1 : }
486 :
487 258 : void MappingTraits<COFF::header>::mapping(IO &IO, COFF::header &H) {
488 258 : MappingNormalization<NMachine, uint16_t> NM(IO, H.Machine);
489 : MappingNormalization<NHeaderCharacteristics, uint16_t> NC(IO,
490 258 : H.Characteristics);
491 :
492 258 : IO.mapRequired("Machine", NM->Machine);
493 258 : IO.mapOptional("Characteristics", NC->Characteristics);
494 258 : IO.setContext(static_cast<void *>(&H));
495 258 : }
496 :
497 0 : void MappingTraits<COFF::AuxiliaryFunctionDefinition>::mapping(
498 : IO &IO, COFF::AuxiliaryFunctionDefinition &AFD) {
499 0 : IO.mapRequired("TagIndex", AFD.TagIndex);
500 0 : IO.mapRequired("TotalSize", AFD.TotalSize);
501 0 : IO.mapRequired("PointerToLinenumber", AFD.PointerToLinenumber);
502 0 : IO.mapRequired("PointerToNextFunction", AFD.PointerToNextFunction);
503 0 : }
504 :
505 0 : void MappingTraits<COFF::AuxiliarybfAndefSymbol>::mapping(
506 : IO &IO, COFF::AuxiliarybfAndefSymbol &AAS) {
507 0 : IO.mapRequired("Linenumber", AAS.Linenumber);
508 0 : IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
509 0 : }
510 :
511 6 : void MappingTraits<COFF::AuxiliaryWeakExternal>::mapping(
512 : IO &IO, COFF::AuxiliaryWeakExternal &AWE) {
513 : MappingNormalization<NWeakExternalCharacteristics, uint32_t> NWEC(
514 6 : IO, AWE.Characteristics);
515 6 : IO.mapRequired("TagIndex", AWE.TagIndex);
516 6 : IO.mapRequired("Characteristics", NWEC->Characteristics);
517 6 : }
518 :
519 634 : void MappingTraits<COFF::AuxiliarySectionDefinition>::mapping(
520 : IO &IO, COFF::AuxiliarySectionDefinition &ASD) {
521 : MappingNormalization<NSectionSelectionType, uint8_t> NSST(
522 634 : IO, ASD.Selection);
523 :
524 634 : IO.mapRequired("Length", ASD.Length);
525 634 : IO.mapRequired("NumberOfRelocations", ASD.NumberOfRelocations);
526 634 : IO.mapRequired("NumberOfLinenumbers", ASD.NumberOfLinenumbers);
527 634 : IO.mapRequired("CheckSum", ASD.CheckSum);
528 634 : IO.mapRequired("Number", ASD.Number);
529 634 : IO.mapOptional("Selection", NSST->SelectionType, COFFYAML::COMDATType(0));
530 634 : }
531 :
532 0 : void MappingTraits<COFF::AuxiliaryCLRToken>::mapping(
533 : IO &IO, COFF::AuxiliaryCLRToken &ACT) {
534 0 : MappingNormalization<NAuxTokenType, uint8_t> NATT(IO, ACT.AuxType);
535 0 : IO.mapRequired("AuxType", NATT->AuxType);
536 0 : IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
537 0 : }
538 :
539 1340 : void MappingTraits<COFFYAML::Symbol>::mapping(IO &IO, COFFYAML::Symbol &S) {
540 1340 : MappingNormalization<NStorageClass, uint8_t> NS(IO, S.Header.StorageClass);
541 :
542 1340 : IO.mapRequired("Name", S.Name);
543 1340 : IO.mapRequired("Value", S.Header.Value);
544 1340 : IO.mapRequired("SectionNumber", S.Header.SectionNumber);
545 1340 : IO.mapRequired("SimpleType", S.SimpleType);
546 1340 : IO.mapRequired("ComplexType", S.ComplexType);
547 1340 : IO.mapRequired("StorageClass", NS->StorageClass);
548 1340 : IO.mapOptional("FunctionDefinition", S.FunctionDefinition);
549 1340 : IO.mapOptional("bfAndefSymbol", S.bfAndefSymbol);
550 1340 : IO.mapOptional("WeakExternal", S.WeakExternal);
551 1340 : IO.mapOptional("File", S.File, StringRef());
552 1340 : IO.mapOptional("SectionDefinition", S.SectionDefinition);
553 1340 : IO.mapOptional("CLRToken", S.CLRToken);
554 1340 : }
555 :
556 674 : void MappingTraits<COFFYAML::Section>::mapping(IO &IO, COFFYAML::Section &Sec) {
557 : MappingNormalization<NSectionCharacteristics, uint32_t> NC(
558 674 : IO, Sec.Header.Characteristics);
559 674 : IO.mapRequired("Name", Sec.Name);
560 674 : IO.mapRequired("Characteristics", NC->Characteristics);
561 674 : IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
562 674 : IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
563 674 : IO.mapOptional("Alignment", Sec.Alignment, 0U);
564 :
565 : // If this is a .debug$S .debug$T .debug$P, or .debug$H section parse the
566 : // semantic representation of the symbols/types. If it is any other kind
567 : // of section, just deal in raw bytes.
568 674 : IO.mapOptional("SectionData", Sec.SectionData);
569 : if (Sec.Name == ".debug$S")
570 79 : IO.mapOptional("Subsections", Sec.DebugS);
571 : else if (Sec.Name == ".debug$T")
572 55 : IO.mapOptional("Types", Sec.DebugT);
573 : else if (Sec.Name == ".debug$P")
574 2 : IO.mapOptional("PrecompTypes", Sec.DebugP);
575 : else if (Sec.Name == ".debug$H")
576 5 : IO.mapOptional("GlobalHashes", Sec.DebugH);
577 :
578 674 : IO.mapOptional("Relocations", Sec.Relocations);
579 674 : }
580 :
581 258 : void MappingTraits<COFFYAML::Object>::mapping(IO &IO, COFFYAML::Object &Obj) {
582 516 : IO.mapTag("!COFF", true);
583 258 : IO.mapOptional("OptionalHeader", Obj.OptionalHeader);
584 258 : IO.mapRequired("header", Obj.Header);
585 258 : IO.mapRequired("sections", Obj.Sections);
586 258 : IO.mapRequired("symbols", Obj.Symbols);
587 258 : }
588 :
589 : } // end namespace yaml
590 :
591 : } // end namespace llvm
|