LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 {
23 }
24 
25 namespace yaml {
49 }
50 
69 }
70 
100 }
101 
108 }
109 
140 }
141 #undef ECase
142 
143 #define BCase(X) IO.bitSetCase(Value, #X, COFF::X);
161 }
162 
164  IO &IO, COFF::SectionCharacteristics &Value) {
165  BCase(IMAGE_SCN_TYPE_NO_PAD);
166  BCase(IMAGE_SCN_CNT_CODE);
167  BCase(IMAGE_SCN_CNT_INITIALIZED_DATA);
168  BCase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
169  BCase(IMAGE_SCN_LNK_OTHER);
170  BCase(IMAGE_SCN_LNK_INFO);
171  BCase(IMAGE_SCN_LNK_REMOVE);
172  BCase(IMAGE_SCN_LNK_COMDAT);
173  BCase(IMAGE_SCN_GPREL);
174  BCase(IMAGE_SCN_MEM_PURGEABLE);
175  BCase(IMAGE_SCN_MEM_16BIT);
176  BCase(IMAGE_SCN_MEM_LOCKED);
177  BCase(IMAGE_SCN_MEM_PRELOAD);
178  BCase(IMAGE_SCN_LNK_NRELOC_OVFL);
179  BCase(IMAGE_SCN_MEM_DISCARDABLE);
180  BCase(IMAGE_SCN_MEM_NOT_CACHED);
181  BCase(IMAGE_SCN_MEM_NOT_PAGED);
182  BCase(IMAGE_SCN_MEM_SHARED);
183  BCase(IMAGE_SCN_MEM_EXECUTE);
184  BCase(IMAGE_SCN_MEM_READ);
185  BCase(IMAGE_SCN_MEM_WRITE);
186 }
187 #undef BCase
188 
189 namespace {
190 struct NSectionCharacteristics {
191  NSectionCharacteristics(IO &)
192  : Characteristics(COFF::SectionCharacteristics(0)) {}
193  NSectionCharacteristics(IO &, uint32_t C)
194  : Characteristics(COFF::SectionCharacteristics(C)) {}
195  uint32_t denormalize(IO &) { return Characteristics; }
196  COFF::SectionCharacteristics Characteristics;
197 };
198 
199 struct NStorageClass {
200  NStorageClass(IO &) : StorageClass(COFF::SymbolStorageClass(0)) {}
201  NStorageClass(IO &, uint8_t S) : StorageClass(COFF::SymbolStorageClass(S)) {}
202  uint8_t denormalize(IO &) { return StorageClass; }
203 
205 };
206 
207 struct NMachine {
208  NMachine(IO &) : Machine(COFF::MachineTypes(0)) {}
209  NMachine(IO &, uint16_t M) : Machine(COFF::MachineTypes(M)) {}
210  uint16_t denormalize(IO &) { return Machine; }
212 };
213 
214 struct NHeaderCharacteristics {
215  NHeaderCharacteristics(IO &) : Characteristics(COFF::Characteristics(0)) {}
216  NHeaderCharacteristics(IO &, uint16_t C)
217  : Characteristics(COFF::Characteristics(C)) {}
218  uint16_t denormalize(IO &) { return Characteristics; }
219 
221 };
222 
223 struct NType {
224  NType(IO &) : Type(COFF::RelocationTypeX86(0)) {}
225  NType(IO &, uint16_t T) : Type(COFF::RelocationTypeX86(T)) {}
226  uint16_t denormalize(IO &) { return Type; }
228 };
229 
230 }
231 
233  COFFYAML::Relocation &Rel) {
235 
236  IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
237  IO.mapRequired("SymbolName", Rel.SymbolName);
238  IO.mapRequired("Type", NT->Type);
239 }
240 
244  H.Characteristics);
245 
246  IO.mapRequired("Machine", NM->Machine);
247  IO.mapOptional("Characteristics", NC->Characteristics);
248 }
249 
252 
253  IO.mapRequired("Name", S.Name);
254  IO.mapRequired("Value", S.Header.Value);
255  IO.mapRequired("SectionNumber", S.Header.SectionNumber);
256  IO.mapRequired("SimpleType", S.SimpleType);
257  IO.mapRequired("ComplexType", S.ComplexType);
258  IO.mapRequired("StorageClass", NS->StorageClass);
259  IO.mapOptional("NumberOfAuxSymbols", S.Header.NumberOfAuxSymbols,
260  (uint8_t) 0);
261  IO.mapOptional("AuxiliaryData", S.AuxiliaryData, object::yaml::BinaryRef());
262 }
263 
266  IO, Sec.Header.Characteristics);
267  IO.mapRequired("Name", Sec.Name);
268  IO.mapRequired("Characteristics", NC->Characteristics);
269  IO.mapOptional("Alignment", Sec.Alignment);
270  IO.mapRequired("SectionData", Sec.SectionData);
271  IO.mapOptional("Relocations", Sec.Relocations);
272 }
273 
275  IO.mapRequired("header", Obj.Header);
276  IO.mapRequired("sections", Obj.Sections);
277  IO.mapRequired("symbols", Obj.Symbols);
278 }
279 
280 }
281 }
COFF::section Header
Definition: COFFYAML.h:45
A byte; unsigned 1-byte integer.
Definition: Support/COFF.h:196
COFF::RelocationTypeX86 Type
Definition: COFFYAML.cpp:227
COFF::SymbolBaseType SimpleType
Definition: COFFYAML.h:55
Image can handle > 2GiB addresses.
Definition: Support/COFF.h:98
A pointer to base type.
Definition: Support/COFF.h:204
A 4-byte signed integer.
Definition: Support/COFF.h:189
COFF::symbol Header
Definition: COFFYAML.h:54
Aggressively trim working set. This is deprecated and must be 0.
Definition: Support/COFF.h:96
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:204
COFF::header Header
Definition: COFFYAML.h:63
uint16_t Characteristics
Definition: Support/COFF.h:52
".bf" or ".ef" - beginning or end of function
Definition: Support/COFF.h:173
No complex type; simple scalar variable.
Definition: Support/COFF.h:203
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:64
std::vector< Relocation > Relocations
Definition: COFFYAML.h:48
A 2-byte signed integer.
Definition: Support/COFF.h:187
External symbol in dmert public lib.
Definition: Support/COFF.h:180
std::vector< Section > Sections
Definition: COFFYAML.h:64
An unsigned integer of natural size.
Definition: Support/COFF.h:198
A 4-byte floating-point number.
Definition: Support/COFF.h:190
An array of base type.
Definition: Support/COFF.h:206
llvm::enable_if_c< has_SequenceTraits< T >::value, void >::type mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:392
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:211
uint8_t NumberOfAuxSymbols
Definition: Support/COFF.h:127
Used with void pointers and functions.
Definition: Support/COFF.h:185
Machine is based on a 32bit word architecture.
Definition: Support/COFF.h:103
No type information or unknown base type.
Definition: Support/COFF.h:184
Line number, reformatted as symbol.
Definition: Support/COFF.h:177
#define ECase(X)
Definition: COFFYAML.cpp:16
An 8-byte floating-point number.
Definition: Support/COFF.h:191
The image file is a DLL.
Definition: Support/COFF.h:113
#define H(x, y, z)
Definition: MD5.cpp:53
A function that returns a base type.
Definition: Support/COFF.h:205
uint16_t SectionNumber
Definition: Support/COFF.h:124
If the image is on removable media, fully load it and copy it to swap.
Definition: Support/COFF.h:107
A word; unsigned 2-byte integer.
Definition: Support/COFF.h:197
object::yaml::BinaryRef AuxiliaryData
Definition: COFFYAML.h:57
An unsigned 4-byte integer.
Definition: Support/COFF.h:199
This file should only be run on a uniprocessor machine.
Definition: Support/COFF.h:115
If the image is on network media, fully load it and copy it to swap.
Definition: Support/COFF.h:109
Debugging info has been removed.
Definition: Support/COFF.h:105
#define NC
Definition: regutils.h:39
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition: Support/COFF.h:147
".bb" or ".eb" - beginning or end of block
Definition: Support/COFF.h:171
A character (signed byte).
Definition: Support/COFF.h:186
The image file is a system file, not a user program.
Definition: Support/COFF.h:111
LLVM Value Representation.
Definition: Value.h:66
std::vector< Symbol > Symbols
Definition: COFFYAML.h:65
A member of enumeration (a specific value).
Definition: Support/COFF.h:195
#define BCase(X)
Definition: COFFYAML.cpp:143
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:386
COFF::SymbolComplexType ComplexType
Definition: COFFYAML.h:56
COFF::SectionCharacteristics Characteristics
Definition: COFFYAML.cpp:196
uint32_t Characteristics
Definition: Support/COFF.h:222
The file is valid and can be run.
Definition: Support/COFF.h:88
A natural integer type on the target.
Definition: Support/COFF.h:188
object::yaml::BinaryRef SectionData
Definition: COFFYAML.h:47