LLVM  3.7.0
COFFYAML.cpp
Go to the documentation of this file.
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/Object/COFFYAML.h"
15 
16 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
17 namespace llvm {
18 
19 namespace COFFYAML {
20 Section::Section() { memset(&Header, 0, sizeof(COFF::section)); }
21 Symbol::Symbol() { memset(&Header, 0, sizeof(COFF::symbol)); }
22 Object::Object() { memset(&Header, 0, sizeof(COFF::header)); }
23 }
24 
25 namespace yaml {
28  IO.enumCase(Value, "0", 0);
36 }
37 
38 void
41  IO.enumCase(Value, "0", 0);
45 }
46 
50 }
51 
75 }
76 
95 }
96 
126 }
127 
134 }
135 
149 }
150 
170 }
171 
188 }
189 #undef ECase
190 
191 #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
209 }
210 
234 }
235 
249 }
250 #undef BCase
251 
252 namespace {
253 struct NSectionSelectionType {
254  NSectionSelectionType(IO &)
255  : SelectionType(COFFYAML::COMDATType(0)) {}
256  NSectionSelectionType(IO &, uint8_t C)
257  : SelectionType(COFFYAML::COMDATType(C)) {}
258  uint8_t denormalize(IO &) { return SelectionType; }
260 };
261 
262 struct NWeakExternalCharacteristics {
263  NWeakExternalCharacteristics(IO &)
265  NWeakExternalCharacteristics(IO &, uint32_t C)
267  uint32_t denormalize(IO &) { return Characteristics; }
269 };
270 
271 struct NSectionCharacteristics {
272  NSectionCharacteristics(IO &)
274  NSectionCharacteristics(IO &, uint32_t C)
276  uint32_t denormalize(IO &) { return Characteristics; }
278 };
279 
280 struct NAuxTokenType {
281  NAuxTokenType(IO &)
282  : AuxType(COFFYAML::AuxSymbolType(0)) {}
283  NAuxTokenType(IO &, uint8_t C)
284  : AuxType(COFFYAML::AuxSymbolType(C)) {}
285  uint32_t denormalize(IO &) { return AuxType; }
287 };
288 
289 struct NStorageClass {
290  NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
291  NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
292  uint8_t denormalize(IO &) { return StorageClass; }
293 
295 };
296 
297 struct NMachine {
298  NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
299  NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
300  uint16_t denormalize(IO &) { return Machine; }
302 };
303 
304 struct NHeaderCharacteristics {
305  NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
306  NHeaderCharacteristics(IO &, uint16_t C)
307  : Characteristics(COFF::Characteristics(C)) {}
308  uint16_t denormalize(IO &) { return Characteristics; }
309 
311 };
312 
313 template <typename RelocType>
314 struct NType {
315  NType(IO &) : Type(RelocType(0)) {}
316  NType(IO &, uint16_t T) : Type(RelocType(T)) {}
317  uint16_t denormalize(IO &) { return Type; }
318  RelocType Type;
319 };
320 
321 struct NWindowsSubsystem {
322  NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
323  NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
324  uint16_t denormalize(IO &) { return Subsystem; }
325 
327 };
328 
329 struct NDLLCharacteristics {
330  NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
331  NDLLCharacteristics(IO &, uint16_t C)
332  : Characteristics(COFF::DLLCharacteristics(C)) {}
333  uint16_t denormalize(IO &) { return Characteristics; }
334 
336 };
337 
338 }
339 
341  COFFYAML::Relocation &Rel) {
342  IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
343  IO.mapRequired("SymbolName", Rel.SymbolName);
344 
345  COFF::header &H = *static_cast<COFF::header *>(IO.getContext());
348  IO, Rel.Type);
349  IO.mapRequired("Type", NT->Type);
350  } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
352  IO, Rel.Type);
353  IO.mapRequired("Type", NT->Type);
354  } else {
355  IO.mapRequired("Type", Rel.Type);
356  }
357 }
358 
360  COFF::DataDirectory &DD) {
361  IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
362  IO.mapRequired("Size", DD.Size);
363 }
364 
366  COFFYAML::PEHeader &PH) {
368  PH.Header.Subsystem);
370  IO, PH.Header.DLLCharacteristics);
371 
372  IO.mapRequired("AddressOfEntryPoint", PH.Header.AddressOfEntryPoint);
373  IO.mapRequired("ImageBase", PH.Header.ImageBase);
374  IO.mapRequired("SectionAlignment", PH.Header.SectionAlignment);
375  IO.mapRequired("FileAlignment", PH.Header.FileAlignment);
376  IO.mapRequired("MajorOperatingSystemVersion",
378  IO.mapRequired("MinorOperatingSystemVersion",
380  IO.mapRequired("MajorImageVersion", PH.Header.MajorImageVersion);
381  IO.mapRequired("MinorImageVersion", PH.Header.MinorImageVersion);
382  IO.mapRequired("MajorSubsystemVersion", PH.Header.MajorSubsystemVersion);
383  IO.mapRequired("MinorSubsystemVersion", PH.Header.MinorSubsystemVersion);
384  IO.mapRequired("Subsystem", NWS->Subsystem);
385  IO.mapRequired("DLLCharacteristics", NDC->Characteristics);
386  IO.mapRequired("SizeOfStackReserve", PH.Header.SizeOfStackReserve);
387  IO.mapRequired("SizeOfStackCommit", PH.Header.SizeOfStackCommit);
388  IO.mapRequired("SizeOfHeapReserve", PH.Header.SizeOfHeapReserve);
389  IO.mapRequired("SizeOfHeapCommit", PH.Header.SizeOfHeapCommit);
390 
391  IO.mapOptional("ExportTable", PH.DataDirectories[COFF::EXPORT_TABLE]);
392  IO.mapOptional("ImportTable", PH.DataDirectories[COFF::IMPORT_TABLE]);
393  IO.mapOptional("ResourceTable", PH.DataDirectories[COFF::RESOURCE_TABLE]);
394  IO.mapOptional("ExceptionTable", PH.DataDirectories[COFF::EXCEPTION_TABLE]);
395  IO.mapOptional("CertificateTable", PH.DataDirectories[COFF::CERTIFICATE_TABLE]);
396  IO.mapOptional("BaseRelocationTable",
398  IO.mapOptional("Debug", PH.DataDirectories[COFF::DEBUG]);
399  IO.mapOptional("Architecture", PH.DataDirectories[COFF::ARCHITECTURE]);
400  IO.mapOptional("GlobalPtr", PH.DataDirectories[COFF::GLOBAL_PTR]);
401  IO.mapOptional("TlsTable", PH.DataDirectories[COFF::TLS_TABLE]);
402  IO.mapOptional("LoadConfigTable",
404  IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
405  IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
406  IO.mapOptional("DelayImportDescriptor",
408  IO.mapOptional("ClrRuntimeHeader",
410 }
411 
415  H.Characteristics);
416 
417  IO.mapRequired("Machine", NM->Machine);
418  IO.mapOptional("Characteristics", NC->Characteristics);
419  IO.setContext(static_cast<void *>(&H));
420 }
421 
424  IO.mapRequired("TagIndex", AFD.TagIndex);
425  IO.mapRequired("TotalSize", AFD.TotalSize);
426  IO.mapRequired("PointerToLinenumber", AFD.PointerToLinenumber);
427  IO.mapRequired("PointerToNextFunction", AFD.PointerToNextFunction);
428 }
429 
432  IO.mapRequired("Linenumber", AAS.Linenumber);
433  IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
434 }
435 
439  IO, AWE.Characteristics);
440  IO.mapRequired("TagIndex", AWE.TagIndex);
441  IO.mapRequired("Characteristics", NWEC->Characteristics);
442 }
443 
447  IO, ASD.Selection);
448 
449  IO.mapRequired("Length", ASD.Length);
450  IO.mapRequired("NumberOfRelocations", ASD.NumberOfRelocations);
451  IO.mapRequired("NumberOfLinenumbers", ASD.NumberOfLinenumbers);
452  IO.mapRequired("CheckSum", ASD.CheckSum);
453  IO.mapRequired("Number", ASD.Number);
454  IO.mapOptional("Selection", NSST->SelectionType, COFFYAML::COMDATType(0));
455 }
456 
458  IO &IO, COFF::AuxiliaryCLRToken &ACT) {
460  IO.mapRequired("AuxType", NATT->AuxType);
461  IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
462 }
463 
466 
467  IO.mapRequired("Name", S.Name);
468  IO.mapRequired("Value", S.Header.Value);
469  IO.mapRequired("SectionNumber", S.Header.SectionNumber);
470  IO.mapRequired("SimpleType", S.SimpleType);
471  IO.mapRequired("ComplexType", S.ComplexType);
472  IO.mapRequired("StorageClass", NS->StorageClass);
473  IO.mapOptional("FunctionDefinition", S.FunctionDefinition);
474  IO.mapOptional("bfAndefSymbol", S.bfAndefSymbol);
475  IO.mapOptional("WeakExternal", S.WeakExternal);
476  IO.mapOptional("File", S.File, StringRef());
477  IO.mapOptional("SectionDefinition", S.SectionDefinition);
478  IO.mapOptional("CLRToken", S.CLRToken);
479 }
480 
483  IO, Sec.Header.Characteristics);
484  IO.mapRequired("Name", Sec.Name);
485  IO.mapRequired("Characteristics", NC->Characteristics);
486  IO.mapOptional("VirtualAddress", Sec.Header.VirtualAddress, 0U);
487  IO.mapOptional("VirtualSize", Sec.Header.VirtualSize, 0U);
488  IO.mapOptional("Alignment", Sec.Alignment);
489  IO.mapRequired("SectionData", Sec.SectionData);
490  IO.mapOptional("Relocations", Sec.Relocations);
491 }
492 
494  IO.mapOptional("OptionalHeader", Obj.OptionalHeader);
495  IO.mapRequired("header", Obj.Header);
496  IO.mapRequired("sections", Obj.Sections);
497  IO.mapRequired("symbols", Obj.Symbols);
498 }
499 
500 }
501 }
COFF::section Header
Definition: COFFYAML.h:56
A byte; unsigned 1-byte integer.
Definition: Support/COFF.h:214
std::enable_if< has_SequenceTraits< T >::value, void >::type mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:582
COFF::PE32Header Header
Definition: COFFYAML.h:79
COFF::SymbolBaseType SimpleType
Definition: COFFYAML.h:66
The Windows character subsystem.
Definition: Support/COFF.h:548
Image can handle > 2GiB addresses.
Definition: Support/COFF.h:126
A pointer to base type.
Definition: Support/COFF.h:222
Device drivers and native Windows processes.
Definition: Support/COFF.h:546
Optional< COFF::AuxiliarybfAndefSymbol > bfAndefSymbol
Definition: COFFYAML.h:69
A 4-byte signed integer.
Definition: Support/COFF.h:207
COFF::symbol Header
Definition: COFFYAML.h:65
void * getContext()
Definition: YAMLTraits.cpp:35
Aggressively trim working set. This is deprecated and must be 0.
Definition: Support/COFF.h:124
Image supports Control Flow Guard.
Definition: Support/COFF.h:582
Isolation aware, but do not isolate the image.
Definition: Support/COFF.h:573
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:294
The Windows GUI subsystem.
Definition: Support/COFF.h:547
uint16_t MinorSubsystemVersion
Definition: Support/COFF.h:502
COFF::header Header
Definition: COFFYAML.h:85
COFF symbol table entries for local symbols have been removed.
Definition: Support/COFF.h:122
uint16_t Characteristics
Definition: Support/COFF.h:62
".bf" or ".ef" - beginning or end of function
Definition: Support/COFF.h:191
No complex type; simple scalar variable.
Definition: Support/COFF.h:221
std::vector< Relocation > Relocations
Definition: COFFYAML.h:59
A 2-byte signed integer.
Definition: Support/COFF.h:205
uint16_t MajorOperatingSystemVersion
Definition: Support/COFF.h:497
External symbol in dmert public lib.
Definition: Support/COFF.h:198
std::vector< Section > Sections
Definition: COFFYAML.h:86
An unsigned integer of natural size.
Definition: Support/COFF.h:216
A 4-byte floating-point number.
Definition: Support/COFF.h:208
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
Definition: YAMLTraits.h:44
COFFYAML::COMDATType SelectionType
Definition: COFFYAML.cpp:259
An array of base type.
Definition: Support/COFF.h:224
The OS/2 character subsytem.
Definition: Support/COFF.h:549
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:301
Used with void pointers and functions.
Definition: Support/COFF.h:203
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:520
Machine is based on a 32bit word architecture.
Definition: Support/COFF.h:131
An EFI driver with run-time services.
Definition: Support/COFF.h:556
An EFI driver with boot services.
Definition: Support/COFF.h:554
No type information or unknown base type.
Definition: Support/COFF.h:202
uint16_t MinorOperatingSystemVersion
Definition: Support/COFF.h:498
COFF::WindowsSubsystem Subsystem
Definition: COFFYAML.cpp:326
Line number, reformatted as symbol.
Definition: Support/COFF.h:195
#define ECase(X)
Definition: COFFYAML.cpp:16
An 8-byte floating-point number.
Definition: Support/COFF.h:209
The image file is a DLL.
Definition: Support/COFF.h:141
#define H(x, y, z)
Definition: MD5.cpp:53
A function that returns a base type.
Definition: Support/COFF.h:223
If the image is on removable media, fully load it and copy it to swap.
Definition: Support/COFF.h:135
A word; unsigned 2-byte integer.
Definition: Support/COFF.h:215
uint16_t MajorSubsystemVersion
Definition: Support/COFF.h:501
yaml::BinaryRef SectionData
Definition: COFFYAML.h:58
Little endian: the LSB precedes the MSB in memory.
Definition: Support/COFF.h:129
An unsigned 4-byte integer.
Definition: Support/COFF.h:217
Optional< COFF::AuxiliaryFunctionDefinition > FunctionDefinition
Definition: COFFYAML.h:68
COFFYAML::AuxSymbolType AuxType
Definition: COFFYAML.cpp:286
This file should only be run on a uniprocessor machine.
Definition: Support/COFF.h:143
DLL can be relocated at load time.
Definition: Support/COFF.h:567
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:68
Optional< COFF::AuxiliaryCLRToken > CLRToken
Definition: COFFYAML.h:73
If the image is on network media, fully load it and copy it to swap.
Definition: Support/COFF.h:137
Debugging info has been removed.
Definition: Support/COFF.h:133
#define NC
Definition: regutils.h:42
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition: Support/COFF.h:165
".bb" or ".eb" - beginning or end of block
Definition: Support/COFF.h:189
void setContext(void *)
Definition: YAMLTraits.cpp:39
COFF line numbers have been stripped.
Definition: Support/COFF.h:119
Optional< COFF::DataDirectory > DataDirectories[COFF::NUM_DATA_DIRECTORIES]
Definition: COFFYAML.h:80
Big endian: the MSB precedes the LSB in memory.
Definition: Support/COFF.h:146
A character (signed byte).
Definition: Support/COFF.h:204
The POSIX character subsystem.
Definition: Support/COFF.h:550
Code integrity checks are enforced.
Definition: Support/COFF.h:569
Optional< COFF::AuxiliaryWeakExternal > WeakExternal
Definition: COFFYAML.h:70
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:268
Does not use structured exception handling (SEH).
Definition: Support/COFF.h:576
The image file is a system file, not a user program.
Definition: Support/COFF.h:139
This class should be specialized by any integer type that is a union of bit values and the YAML repre...
Definition: YAMLTraits.h:86
LLVM Value Representation.
Definition: Value.h:69
std::vector< Symbol > Symbols
Definition: COFFYAML.h:87
RelocType Type
Definition: COFFYAML.cpp:318
A member of enumeration (a specific value).
Definition: Support/COFF.h:213
#define BCase(X)
Definition: COFFYAML.cpp:191
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
The file does not contain base relocations and must be loaded at its preferred base.
Definition: Support/COFF.h:114
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:576
COFF::SymbolComplexType ComplexType
Definition: COFFYAML.h:67
Optional< PEHeader > OptionalHeader
Definition: COFFYAML.h:84
WeakExternalCharacteristics
These are not documented in the spec, but are located in WinNT.h.
Definition: Support/COFF.h:379
uint32_t Characteristics
Definition: Support/COFF.h:244
The file is valid and can be run.
Definition: Support/COFF.h:116
Optional< COFF::AuxiliarySectionDefinition > SectionDefinition
Definition: COFFYAML.h:72
A natural integer type on the target.
Definition: Support/COFF.h:206