LLVM  4.0.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 
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 
76 }
77 
96 }
97 
127 }
128 
135 }
136 
150 }
151 
171 }
172 
189 }
190 #undef ECase
191 
192 #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
210 }
211 
236 }
237 
251 }
252 #undef BCase
253 
254 namespace {
255 struct NSectionSelectionType {
256  NSectionSelectionType(IO &)
257  : SelectionType(COFFYAML::COMDATType(0)) {}
258  NSectionSelectionType(IO &, uint8_t C)
259  : SelectionType(COFFYAML::COMDATType(C)) {}
260  uint8_t denormalize(IO &) { return SelectionType; }
262 };
263 
264 struct NWeakExternalCharacteristics {
265  NWeakExternalCharacteristics(IO &)
267  NWeakExternalCharacteristics(IO &, uint32_t C)
269  uint32_t denormalize(IO &) { return Characteristics; }
271 };
272 
273 struct NSectionCharacteristics {
274  NSectionCharacteristics(IO &)
276  NSectionCharacteristics(IO &, uint32_t C)
278  uint32_t denormalize(IO &) { return Characteristics; }
280 };
281 
282 struct NAuxTokenType {
283  NAuxTokenType(IO &)
284  : AuxType(COFFYAML::AuxSymbolType(0)) {}
285  NAuxTokenType(IO &, uint8_t C)
286  : AuxType(COFFYAML::AuxSymbolType(C)) {}
287  uint32_t denormalize(IO &) { return AuxType; }
289 };
290 
291 struct NStorageClass {
292  NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
293  NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
294  uint8_t denormalize(IO &) { return StorageClass; }
295 
297 };
298 
299 struct NMachine {
300  NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
301  NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
302  uint16_t denormalize(IO &) { return Machine; }
304 };
305 
306 struct NHeaderCharacteristics {
307  NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
308  NHeaderCharacteristics(IO &, uint16_t C)
309  : Characteristics(COFF::Characteristics(C)) {}
310  uint16_t denormalize(IO &) { return Characteristics; }
311 
313 };
314 
315 template <typename RelocType>
316 struct NType {
317  NType(IO &) : Type(RelocType(0)) {}
318  NType(IO &, uint16_t T) : Type(RelocType(T)) {}
319  uint16_t denormalize(IO &) { return Type; }
320  RelocType Type;
321 };
322 
323 struct NWindowsSubsystem {
324  NWindowsSubsystem(IO &) : Subsystem(COFF::WindowsSubsystem(0)) {}
325  NWindowsSubsystem(IO &, uint16_t C) : Subsystem(COFF::WindowsSubsystem(C)) {}
326  uint16_t denormalize(IO &) { return Subsystem; }
327 
329 };
330 
331 struct NDLLCharacteristics {
332  NDLLCharacteristics(IO &) : Characteristics(COFF::DLLCharacteristics(0)) {}
333  NDLLCharacteristics(IO &, uint16_t C)
334  : Characteristics(COFF::DLLCharacteristics(C)) {}
335  uint16_t denormalize(IO &) { return Characteristics; }
336 
338 };
339 
340 }
341 
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());
350  IO, Rel.Type);
351  IO.mapRequired("Type", NT->Type);
352  } else if (H.Machine == COFF::IMAGE_FILE_MACHINE_AMD64) {
354  IO, Rel.Type);
355  IO.mapRequired("Type", NT->Type);
356  } else {
357  IO.mapRequired("Type", Rel.Type);
358  }
359 }
360 
362  COFF::DataDirectory &DD) {
363  IO.mapRequired("RelativeVirtualAddress", DD.RelativeVirtualAddress);
364  IO.mapRequired("Size", DD.Size);
365 }
366 
368  COFFYAML::PEHeader &PH) {
370  PH.Header.Subsystem);
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",
380  IO.mapRequired("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",
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",
406  IO.mapOptional("BoundImport", PH.DataDirectories[COFF::BOUND_IMPORT]);
407  IO.mapOptional("IAT", PH.DataDirectories[COFF::IAT]);
408  IO.mapOptional("DelayImportDescriptor",
410  IO.mapOptional("ClrRuntimeHeader",
412 }
413 
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 
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 
434  IO.mapRequired("Linenumber", AAS.Linenumber);
435  IO.mapRequired("PointerToNextFunction", AAS.PointerToNextFunction);
436 }
437 
441  IO, AWE.Characteristics);
442  IO.mapRequired("TagIndex", AWE.TagIndex);
443  IO.mapRequired("Characteristics", NWEC->Characteristics);
444 }
445 
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 
460  IO &IO, COFF::AuxiliaryCLRToken &ACT) {
462  IO.mapRequired("AuxType", NATT->AuxType);
463  IO.mapRequired("SymbolTableIndex", ACT.SymbolTableIndex);
464 }
465 
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 
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 
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 }
COFF::section Header
Definition: COFFYAML.h:56
A byte; unsigned 1-byte integer.
Definition: Support/COFF.h:220
void mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:646
COFF::PE32Header Header
Definition: COFFYAML.h:79
COFF::SymbolBaseType SimpleType
Definition: COFFYAML.h:66
The Windows character subsystem.
Definition: Support/COFF.h:554
Image can handle > 2GiB addresses.
Definition: Support/COFF.h:132
A pointer to base type.
Definition: Support/COFF.h:228
Device drivers and native Windows processes.
Definition: Support/COFF.h:552
Optional< COFF::AuxiliarybfAndefSymbol > bfAndefSymbol
Definition: COFFYAML.h:69
A 4-byte signed integer.
Definition: Support/COFF.h:213
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:130
Image supports Control Flow Guard.
Definition: Support/COFF.h:588
Isolation aware, but do not isolate the image.
Definition: Support/COFF.h:579
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:296
The Windows GUI subsystem.
Definition: Support/COFF.h:553
uint16_t MinorSubsystemVersion
Definition: Support/COFF.h:508
COFF::header Header
Definition: COFFYAML.h:85
COFF symbol table entries for local symbols have been removed.
Definition: Support/COFF.h:128
uint16_t Characteristics
Definition: Support/COFF.h:67
".bf" or ".ef" - beginning or end of function
Definition: Support/COFF.h:197
No complex type; simple scalar variable.
Definition: Support/COFF.h:227
std::vector< Relocation > Relocations
Definition: COFFYAML.h:59
A 2-byte signed integer.
Definition: Support/COFF.h:211
uint16_t MajorOperatingSystemVersion
Definition: Support/COFF.h:503
External symbol in dmert public lib.
Definition: Support/COFF.h:204
std::vector< Section > Sections
Definition: COFFYAML.h:86
An unsigned integer of natural size.
Definition: Support/COFF.h:222
A 4-byte floating-point number.
Definition: Support/COFF.h:214
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
COFFYAML::COMDATType SelectionType
Definition: COFFYAML.cpp:261
An array of base type.
Definition: Support/COFF.h:230
The OS/2 character subsytem.
Definition: Support/COFF.h:555
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:303
virtual bool mapTag(StringRef Tag, bool Default=false)=0
Used with void pointers and functions.
Definition: Support/COFF.h:209
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:581
Machine is based on a 32bit word architecture.
Definition: Support/COFF.h:137
An EFI driver with run-time services.
Definition: Support/COFF.h:562
An EFI driver with boot services.
Definition: Support/COFF.h:560
No type information or unknown base type.
Definition: Support/COFF.h:208
uint16_t MinorOperatingSystemVersion
Definition: Support/COFF.h:504
COFF::WindowsSubsystem Subsystem
Definition: COFFYAML.cpp:328
Line number, reformatted as symbol.
Definition: Support/COFF.h:201
#define ECase(X)
Definition: COFFYAML.cpp:16
An 8-byte floating-point number.
Definition: Support/COFF.h:215
The image file is a DLL.
Definition: Support/COFF.h:147
#define H(x, y, z)
Definition: MD5.cpp:53
A function that returns a base type.
Definition: Support/COFF.h:229
If the image is on removable media, fully load it and copy it to swap.
Definition: Support/COFF.h:141
A word; unsigned 2-byte integer.
Definition: Support/COFF.h:221
uint16_t MajorSubsystemVersion
Definition: Support/COFF.h:507
yaml::BinaryRef SectionData
Definition: COFFYAML.h:58
Little endian: the LSB precedes the MSB in memory.
Definition: Support/COFF.h:135
An unsigned 4-byte integer.
Definition: Support/COFF.h:223
Optional< COFF::AuxiliaryFunctionDefinition > FunctionDefinition
Definition: COFFYAML.h:68
COFFYAML::AuxSymbolType AuxType
Definition: COFFYAML.cpp:288
This file should only be run on a uniprocessor machine.
Definition: Support/COFF.h:149
DLL can be relocated at load time.
Definition: Support/COFF.h:573
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:97
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:143
Debugging info has been removed.
Definition: Support/COFF.h:139
#define NC
Definition: regutils.h:42
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition: Support/COFF.h:171
".bb" or ".eb" - beginning or end of block
Definition: Support/COFF.h:195
void setContext(void *)
Definition: YAMLTraits.cpp:39
COFF line numbers have been stripped.
Definition: Support/COFF.h:125
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:152
A character (signed byte).
Definition: Support/COFF.h:210
The POSIX character subsystem.
Definition: Support/COFF.h:556
Code integrity checks are enforced.
Definition: Support/COFF.h:575
Optional< COFF::AuxiliaryWeakExternal > WeakExternal
Definition: COFFYAML.h:70
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:270
Does not use structured exception handling (SEH).
Definition: Support/COFF.h:582
The image file is a system file, not a user program.
Definition: Support/COFF.h:145
This class should be specialized by any integer type that is a union of bit values and the YAML repre...
Definition: YAMLTraits.h:114
LLVM Value Representation.
Definition: Value.h:71
std::vector< Symbol > Symbols
Definition: COFFYAML.h:87
RelocType Type
Definition: COFFYAML.cpp:320
A member of enumeration (a specific value).
Definition: Support/COFF.h:219
#define BCase(X)
Definition: COFFYAML.cpp:192
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
The file does not contain base relocations and must be loaded at its preferred base.
Definition: Support/COFF.h:120
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:637
COFF::SymbolComplexType ComplexType
Definition: COFFYAML.h:67
Optional< PEHeader > OptionalHeader
Definition: COFFYAML.h:84
WeakExternalCharacteristics
Definition: Support/COFF.h:385
uint32_t Characteristics
Definition: Support/COFF.h:250
The file is valid and can be run.
Definition: Support/COFF.h:122
Optional< COFF::AuxiliarySectionDefinition > SectionDefinition
Definition: COFFYAML.h:72
A natural integer type on the target.
Definition: Support/COFF.h:212