1 //===- yaml2obj - Convert YAML to a binary object file --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This program takes a YAML description of an object file and outputs the
13 // This is used for writing tests that require binary files.
15 //===----------------------------------------------------------------------===//
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringSwitch.h"
21 #include "llvm/Support/COFF.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/Endian.h"
25 #include "llvm/Support/ManagedStatic.h"
26 #include "llvm/Support/MemoryBuffer.h"
27 #include "llvm/Support/PrettyStackTrace.h"
28 #include "llvm/Support/Signals.h"
29 #include "llvm/Support/SourceMgr.h"
30 #include "llvm/Support/YAMLTraits.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include "llvm/Support/system_error.h"
37 static cl::opt<std::string>
38 Input(cl::Positional, cl::desc("<input>"), cl::init("-"));
43 typename llvm::enable_if_c<std::numeric_limits<T>::is_integer, bool>::type
44 getAs(const llvm::yaml::ScalarNode *SN, T &Result) {
45 SmallString<4> Storage;
46 StringRef Value = SN->getValue(Storage);
47 if (Value.getAsInteger(0, Result))
52 // Given a container with begin and end with ::value_type of a character type.
53 // Iterate through pairs of characters in the the set of [a-fA-F0-9] ignoring
54 // all other characters.
55 struct hex_pair_iterator {
56 StringRef::const_iterator Current, End;
57 typedef SmallVector<char, 2> value_type;
61 hex_pair_iterator(StringRef C)
62 : Current(C.begin()), End(C.end()), IsDone(false) {
68 hex_pair_iterator() : Current(), End(), IsDone(true) {}
70 value_type operator *() const {
74 hex_pair_iterator operator ++() {
75 // We're at the end of the input.
81 for (; Current != End && Pair.size() != 2; ++Current) {
82 // Is a valid hex digit.
83 if ((*Current >= '0' && *Current <= '9') ||
84 (*Current >= 'a' && *Current <= 'f') ||
85 (*Current >= 'A' && *Current <= 'F'))
86 Pair.push_back(*Current);
88 // Hit the end without getting 2 hex digits. Pair is invalid.
94 bool operator ==(const hex_pair_iterator Other) {
95 return (IsDone == Other.IsDone) ||
96 (Current == Other.Current && End == Other.End);
99 bool operator !=(const hex_pair_iterator Other) {
100 return !(*this == Other);
104 template <class ContainerOut>
105 static bool hexStringToByteArray(StringRef Str, ContainerOut &Out) {
106 for (hex_pair_iterator I(Str), E; I != E; ++I) {
107 typename hex_pair_iterator::value_type Pair = *I;
108 typename ContainerOut::value_type Byte;
109 if (StringRef(Pair.data(), 2).getAsInteger(16, Byte))
116 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
117 // to use yaml::IO, we use these structures which are closer to the source.
120 uint32_t VirtualAddress;
121 uint32_t SymbolTableIndex;
122 COFF::RelocationTypeX86 Type;
126 std::vector<COFF::SectionCharacteristics> Characteristics;
127 StringRef SectionData;
128 std::vector<Relocation> Relocations;
133 COFF::MachineTypes Machine;
137 COFF::SymbolBaseType SimpleType;
138 uint8_t NumberOfAuxSymbols;
140 COFF::SymbolStorageClass StorageClass;
141 StringRef AuxillaryData;
142 COFF::SymbolComplexType ComplexType;
144 uint16_t SectionNumber;
149 std::vector<Section> Sections;
150 std::vector<Symbol> Symbols;
154 /// This parses a yaml stream that represents a COFF object file.
155 /// See docs/yaml2obj for the yaml scheema.
157 COFFParser(COFFYAML::Object &Obj) : Obj(Obj) {
158 std::memset(&Header, 0, sizeof(Header));
159 // A COFF string table always starts with a 4 byte size field. Offsets into
160 // it include this size, so allocate it now.
161 StringTable.append(4, 0);
164 bool parseSections() {
165 for (std::vector<COFFYAML::Section>::iterator i = Obj.Sections.begin(),
166 e = Obj.Sections.end(); i != e; ++i) {
167 const COFFYAML::Section &YamlSection = *i;
169 std::memset(&Sec.Header, 0, sizeof(Sec.Header));
171 // If the name is less than 8 bytes, store it in place, otherwise
172 // store it in the string table.
173 StringRef Name = YamlSection.Name;
174 std::fill_n(Sec.Header.Name, unsigned(COFF::NameSize), 0);
175 if (Name.size() <= COFF::NameSize) {
176 std::copy(Name.begin(), Name.end(), Sec.Header.Name);
178 // Add string to the string table and format the index for output.
179 unsigned Index = getStringIndex(Name);
180 std::string str = utostr(Index);
181 if (str.size() > 7) {
182 errs() << "String table got too large";
185 Sec.Header.Name[0] = '/';
186 std::copy(str.begin(), str.end(), Sec.Header.Name + 1);
189 for (std::vector<COFF::SectionCharacteristics>::const_iterator i =
190 YamlSection.Characteristics.begin(),
191 e = YamlSection.Characteristics.end();
193 uint32_t Characteristic = *i;
194 Sec.Header.Characteristics |= Characteristic;
197 StringRef Data = YamlSection.SectionData;
198 if (!hexStringToByteArray(Data, Sec.Data)) {
199 errs() << "SectionData must be a collection of pairs of hex bytes";
202 Sections.push_back(Sec);
207 bool parseSymbols() {
208 for (std::vector<COFFYAML::Symbol>::iterator i = Obj.Symbols.begin(),
209 e = Obj.Symbols.end(); i != e; ++i) {
210 COFFYAML::Symbol YamlSymbol = *i;
212 std::memset(&Sym.Header, 0, sizeof(Sym.Header));
214 // If the name is less than 8 bytes, store it in place, otherwise
215 // store it in the string table.
216 StringRef Name = YamlSymbol.Name;
217 std::fill_n(Sym.Header.Name, unsigned(COFF::NameSize), 0);
218 if (Name.size() <= COFF::NameSize) {
219 std::copy(Name.begin(), Name.end(), Sym.Header.Name);
221 // Add string to the string table and format the index for output.
222 unsigned Index = getStringIndex(Name);
223 *reinterpret_cast<support::aligned_ulittle32_t*>(
224 Sym.Header.Name + 4) = Index;
227 Sym.Header.Value = YamlSymbol.Value;
228 Sym.Header.Type |= YamlSymbol.SimpleType;
229 Sym.Header.Type |= YamlSymbol.ComplexType << COFF::SCT_COMPLEX_TYPE_SHIFT;
230 Sym.Header.StorageClass = YamlSymbol.StorageClass;
231 Sym.Header.SectionNumber = YamlSymbol.SectionNumber;
233 StringRef Data = YamlSymbol.AuxillaryData;
234 if (!hexStringToByteArray(Data, Sym.AuxSymbols)) {
235 errs() << "AuxillaryData must be a collection of pairs of hex bytes";
238 Symbols.push_back(Sym);
244 Header.Machine = Obj.HeaderData.Machine;
245 if (!parseSections())
252 unsigned getStringIndex(StringRef Str) {
253 StringMap<unsigned>::iterator i = StringTableMap.find(Str);
254 if (i == StringTableMap.end()) {
255 unsigned Index = StringTable.size();
256 StringTable.append(Str.begin(), Str.end());
257 StringTable.push_back(0);
258 StringTableMap[Str] = Index;
264 COFFYAML::Object &Obj;
268 COFF::section Header;
269 std::vector<uint8_t> Data;
270 std::vector<COFF::relocation> Relocations;
275 std::vector<uint8_t> AuxSymbols;
278 std::vector<Section> Sections;
279 std::vector<Symbol> Symbols;
280 StringMap<unsigned> StringTableMap;
281 std::string StringTable;
284 // Take a CP and assign addresses and sizes to everything. Returns false if the
285 // layout is not valid to do.
286 static bool layoutCOFF(COFFParser &CP) {
287 uint32_t SectionTableStart = 0;
288 uint32_t SectionTableSize = 0;
290 // The section table starts immediately after the header, including the
292 SectionTableStart = sizeof(COFF::header) + CP.Header.SizeOfOptionalHeader;
293 SectionTableSize = sizeof(COFF::section) * CP.Sections.size();
295 uint32_t CurrentSectionDataOffset = SectionTableStart + SectionTableSize;
297 // Assign each section data address consecutively.
298 for (std::vector<COFFParser::Section>::iterator i = CP.Sections.begin(),
299 e = CP.Sections.end();
301 if (!i->Data.empty()) {
302 i->Header.SizeOfRawData = i->Data.size();
303 i->Header.PointerToRawData = CurrentSectionDataOffset;
304 CurrentSectionDataOffset += i->Header.SizeOfRawData;
305 // TODO: Handle alignment.
307 i->Header.SizeOfRawData = 0;
308 i->Header.PointerToRawData = 0;
312 uint32_t SymbolTableStart = CurrentSectionDataOffset;
314 // Calculate number of symbols.
315 uint32_t NumberOfSymbols = 0;
316 for (std::vector<COFFParser::Symbol>::iterator i = CP.Symbols.begin(),
317 e = CP.Symbols.end();
319 if (i->AuxSymbols.size() % COFF::SymbolSize != 0) {
320 errs() << "AuxillaryData size not a multiple of symbol size!\n";
323 i->Header.NumberOfAuxSymbols = i->AuxSymbols.size() / COFF::SymbolSize;
324 NumberOfSymbols += 1 + i->Header.NumberOfAuxSymbols;
327 // Store all the allocated start addresses in the header.
328 CP.Header.NumberOfSections = CP.Sections.size();
329 CP.Header.NumberOfSymbols = NumberOfSymbols;
330 CP.Header.PointerToSymbolTable = SymbolTableStart;
332 *reinterpret_cast<support::ulittle32_t *>(&CP.StringTable[0])
333 = CP.StringTable.size();
338 template <typename value_type>
339 struct binary_le_impl {
341 binary_le_impl(value_type V) : Value(V) {}
344 template <typename value_type>
345 raw_ostream &operator <<( raw_ostream &OS
346 , const binary_le_impl<value_type> &BLE) {
347 char Buffer[sizeof(BLE.Value)];
348 support::endian::write<value_type, support::little, support::unaligned>(
350 OS.write(Buffer, sizeof(BLE.Value));
354 template <typename value_type>
355 binary_le_impl<value_type> binary_le(value_type V) {
356 return binary_le_impl<value_type>(V);
359 void writeCOFF(COFFParser &CP, raw_ostream &OS) {
360 OS << binary_le(CP.Header.Machine)
361 << binary_le(CP.Header.NumberOfSections)
362 << binary_le(CP.Header.TimeDateStamp)
363 << binary_le(CP.Header.PointerToSymbolTable)
364 << binary_le(CP.Header.NumberOfSymbols)
365 << binary_le(CP.Header.SizeOfOptionalHeader)
366 << binary_le(CP.Header.Characteristics);
368 // Output section table.
369 for (std::vector<COFFParser::Section>::const_iterator i = CP.Sections.begin(),
370 e = CP.Sections.end();
372 OS.write(i->Header.Name, COFF::NameSize);
373 OS << binary_le(i->Header.VirtualSize)
374 << binary_le(i->Header.VirtualAddress)
375 << binary_le(i->Header.SizeOfRawData)
376 << binary_le(i->Header.PointerToRawData)
377 << binary_le(i->Header.PointerToRelocations)
378 << binary_le(i->Header.PointerToLineNumbers)
379 << binary_le(i->Header.NumberOfRelocations)
380 << binary_le(i->Header.NumberOfLineNumbers)
381 << binary_le(i->Header.Characteristics);
384 // Output section data.
385 for (std::vector<COFFParser::Section>::const_iterator i = CP.Sections.begin(),
386 e = CP.Sections.end();
388 if (!i->Data.empty())
389 OS.write(reinterpret_cast<const char*>(&i->Data[0]), i->Data.size());
392 // Output symbol table.
394 for (std::vector<COFFParser::Symbol>::const_iterator i = CP.Symbols.begin(),
395 e = CP.Symbols.end();
397 OS.write(i->Header.Name, COFF::NameSize);
398 OS << binary_le(i->Header.Value)
399 << binary_le(i->Header.SectionNumber)
400 << binary_le(i->Header.Type)
401 << binary_le(i->Header.StorageClass)
402 << binary_le(i->Header.NumberOfAuxSymbols);
403 if (!i->AuxSymbols.empty())
404 OS.write( reinterpret_cast<const char*>(&i->AuxSymbols[0])
405 , i->AuxSymbols.size());
408 // Output string table.
409 OS.write(&CP.StringTable[0], CP.StringTable.size());
414 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
415 LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::SectionCharacteristics)
416 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
417 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
421 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
424 struct ScalarEnumerationTraits<COFF::SymbolComplexType> {
425 static void enumeration(IO &IO, COFF::SymbolComplexType &Value) {
426 ECase(IMAGE_SYM_DTYPE_NULL);
427 ECase(IMAGE_SYM_DTYPE_POINTER);
428 ECase(IMAGE_SYM_DTYPE_FUNCTION);
429 ECase(IMAGE_SYM_DTYPE_ARRAY);
433 // FIXME: We cannot use ScalarBitSetTraits because of
434 // IMAGE_SYM_CLASS_END_OF_FUNCTION which is -1.
436 struct ScalarEnumerationTraits<COFF::SymbolStorageClass> {
437 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value) {
438 ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
439 ECase(IMAGE_SYM_CLASS_NULL);
440 ECase(IMAGE_SYM_CLASS_AUTOMATIC);
441 ECase(IMAGE_SYM_CLASS_EXTERNAL);
442 ECase(IMAGE_SYM_CLASS_STATIC);
443 ECase(IMAGE_SYM_CLASS_REGISTER);
444 ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
445 ECase(IMAGE_SYM_CLASS_LABEL);
446 ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
447 ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
448 ECase(IMAGE_SYM_CLASS_ARGUMENT);
449 ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
450 ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
451 ECase(IMAGE_SYM_CLASS_UNION_TAG);
452 ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
453 ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
454 ECase(IMAGE_SYM_CLASS_ENUM_TAG);
455 ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
456 ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
457 ECase(IMAGE_SYM_CLASS_BIT_FIELD);
458 ECase(IMAGE_SYM_CLASS_BLOCK);
459 ECase(IMAGE_SYM_CLASS_FUNCTION);
460 ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
461 ECase(IMAGE_SYM_CLASS_FILE);
462 ECase(IMAGE_SYM_CLASS_SECTION);
463 ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
464 ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
469 struct ScalarEnumerationTraits<COFF::SymbolBaseType> {
470 static void enumeration(IO &IO, COFF::SymbolBaseType &Value) {
471 ECase(IMAGE_SYM_TYPE_NULL);
472 ECase(IMAGE_SYM_TYPE_VOID);
473 ECase(IMAGE_SYM_TYPE_CHAR);
474 ECase(IMAGE_SYM_TYPE_SHORT);
475 ECase(IMAGE_SYM_TYPE_INT);
476 ECase(IMAGE_SYM_TYPE_LONG);
477 ECase(IMAGE_SYM_TYPE_FLOAT);
478 ECase(IMAGE_SYM_TYPE_DOUBLE);
479 ECase(IMAGE_SYM_TYPE_STRUCT);
480 ECase(IMAGE_SYM_TYPE_UNION);
481 ECase(IMAGE_SYM_TYPE_ENUM);
482 ECase(IMAGE_SYM_TYPE_MOE);
483 ECase(IMAGE_SYM_TYPE_BYTE);
484 ECase(IMAGE_SYM_TYPE_WORD);
485 ECase(IMAGE_SYM_TYPE_UINT);
486 ECase(IMAGE_SYM_TYPE_DWORD);
491 struct ScalarEnumerationTraits<COFF::MachineTypes> {
492 static void enumeration(IO &IO, COFF::MachineTypes &Value) {
493 ECase(IMAGE_FILE_MACHINE_UNKNOWN);
494 ECase(IMAGE_FILE_MACHINE_AM33);
495 ECase(IMAGE_FILE_MACHINE_AMD64);
496 ECase(IMAGE_FILE_MACHINE_ARM);
497 ECase(IMAGE_FILE_MACHINE_ARMV7);
498 ECase(IMAGE_FILE_MACHINE_EBC);
499 ECase(IMAGE_FILE_MACHINE_I386);
500 ECase(IMAGE_FILE_MACHINE_IA64);
501 ECase(IMAGE_FILE_MACHINE_M32R);
502 ECase(IMAGE_FILE_MACHINE_MIPS16);
503 ECase(IMAGE_FILE_MACHINE_MIPSFPU);
504 ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
505 ECase(IMAGE_FILE_MACHINE_POWERPC);
506 ECase(IMAGE_FILE_MACHINE_POWERPCFP);
507 ECase(IMAGE_FILE_MACHINE_R4000);
508 ECase(IMAGE_FILE_MACHINE_SH3);
509 ECase(IMAGE_FILE_MACHINE_SH3DSP);
510 ECase(IMAGE_FILE_MACHINE_SH4);
511 ECase(IMAGE_FILE_MACHINE_SH5);
512 ECase(IMAGE_FILE_MACHINE_THUMB);
513 ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
518 struct ScalarEnumerationTraits<COFF::SectionCharacteristics> {
519 static void enumeration(IO &IO, COFF::SectionCharacteristics &Value) {
520 ECase(IMAGE_SCN_TYPE_NO_PAD);
521 ECase(IMAGE_SCN_CNT_CODE);
522 ECase(IMAGE_SCN_CNT_INITIALIZED_DATA);
523 ECase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
524 ECase(IMAGE_SCN_LNK_OTHER);
525 ECase(IMAGE_SCN_LNK_INFO);
526 ECase(IMAGE_SCN_LNK_REMOVE);
527 ECase(IMAGE_SCN_LNK_COMDAT);
528 ECase(IMAGE_SCN_GPREL);
529 ECase(IMAGE_SCN_MEM_PURGEABLE);
530 ECase(IMAGE_SCN_MEM_16BIT);
531 ECase(IMAGE_SCN_MEM_LOCKED);
532 ECase(IMAGE_SCN_MEM_PRELOAD);
533 ECase(IMAGE_SCN_ALIGN_1BYTES);
534 ECase(IMAGE_SCN_ALIGN_2BYTES);
535 ECase(IMAGE_SCN_ALIGN_4BYTES);
536 ECase(IMAGE_SCN_ALIGN_8BYTES);
537 ECase(IMAGE_SCN_ALIGN_16BYTES);
538 ECase(IMAGE_SCN_ALIGN_32BYTES);
539 ECase(IMAGE_SCN_ALIGN_64BYTES);
540 ECase(IMAGE_SCN_ALIGN_128BYTES);
541 ECase(IMAGE_SCN_ALIGN_256BYTES);
542 ECase(IMAGE_SCN_ALIGN_512BYTES);
543 ECase(IMAGE_SCN_ALIGN_1024BYTES);
544 ECase(IMAGE_SCN_ALIGN_2048BYTES);
545 ECase(IMAGE_SCN_ALIGN_4096BYTES);
546 ECase(IMAGE_SCN_ALIGN_8192BYTES);
547 ECase(IMAGE_SCN_LNK_NRELOC_OVFL);
548 ECase(IMAGE_SCN_MEM_DISCARDABLE);
549 ECase(IMAGE_SCN_MEM_NOT_CACHED);
550 ECase(IMAGE_SCN_MEM_NOT_PAGED);
551 ECase(IMAGE_SCN_MEM_SHARED);
552 ECase(IMAGE_SCN_MEM_EXECUTE);
553 ECase(IMAGE_SCN_MEM_READ);
554 ECase(IMAGE_SCN_MEM_WRITE);
559 struct ScalarEnumerationTraits<COFF::RelocationTypeX86> {
560 static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value) {
561 ECase(IMAGE_REL_I386_ABSOLUTE);
562 ECase(IMAGE_REL_I386_DIR16);
563 ECase(IMAGE_REL_I386_REL16);
564 ECase(IMAGE_REL_I386_DIR32);
565 ECase(IMAGE_REL_I386_DIR32NB);
566 ECase(IMAGE_REL_I386_SEG12);
567 ECase(IMAGE_REL_I386_SECTION);
568 ECase(IMAGE_REL_I386_SECREL);
569 ECase(IMAGE_REL_I386_TOKEN);
570 ECase(IMAGE_REL_I386_SECREL7);
571 ECase(IMAGE_REL_I386_REL32);
572 ECase(IMAGE_REL_AMD64_ABSOLUTE);
573 ECase(IMAGE_REL_AMD64_ADDR64);
574 ECase(IMAGE_REL_AMD64_ADDR32);
575 ECase(IMAGE_REL_AMD64_ADDR32NB);
576 ECase(IMAGE_REL_AMD64_REL32);
577 ECase(IMAGE_REL_AMD64_REL32_1);
578 ECase(IMAGE_REL_AMD64_REL32_2);
579 ECase(IMAGE_REL_AMD64_REL32_3);
580 ECase(IMAGE_REL_AMD64_REL32_4);
581 ECase(IMAGE_REL_AMD64_REL32_5);
582 ECase(IMAGE_REL_AMD64_SECTION);
583 ECase(IMAGE_REL_AMD64_SECREL);
584 ECase(IMAGE_REL_AMD64_SECREL7);
585 ECase(IMAGE_REL_AMD64_TOKEN);
586 ECase(IMAGE_REL_AMD64_SREL32);
587 ECase(IMAGE_REL_AMD64_PAIR);
588 ECase(IMAGE_REL_AMD64_SSPAN32);
595 struct MappingTraits<COFFYAML::Symbol> {
596 static void mapping(IO &IO, COFFYAML::Symbol &S) {
597 IO.mapRequired("SimpleType", S.SimpleType);
598 IO.mapOptional("NumberOfAuxSymbols", S.NumberOfAuxSymbols);
599 IO.mapRequired("Name", S.Name);
600 IO.mapRequired("StorageClass", S.StorageClass);
601 IO.mapOptional("AuxillaryData", S.AuxillaryData); // FIXME: typo
602 IO.mapRequired("ComplexType", S.ComplexType);
603 IO.mapRequired("Value", S.Value);
604 IO.mapRequired("SectionNumber", S.SectionNumber);
609 struct MappingTraits<COFFYAML::Header> {
610 static void mapping(IO &IO, COFFYAML::Header &H) {
611 IO.mapRequired("Machine", H.Machine);
616 struct MappingTraits<COFFYAML::Relocation> {
617 static void mapping(IO &IO, COFFYAML::Relocation &Rel) {
618 IO.mapRequired("Type", Rel.Type);
619 IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
620 IO.mapRequired("SymbolTableIndex", Rel.SymbolTableIndex);
625 struct MappingTraits<COFFYAML::Section> {
626 static void mapping(IO &IO, COFFYAML::Section &Sec) {
627 IO.mapOptional("Relocations", Sec.Relocations);
628 IO.mapRequired("SectionData", Sec.SectionData);
629 IO.mapRequired("Characteristics", Sec.Characteristics);
630 IO.mapRequired("Name", Sec.Name);
635 struct MappingTraits<COFFYAML::Object> {
636 static void mapping(IO &IO, COFFYAML::Object &Obj) {
637 IO.mapRequired("sections", Obj.Sections);
638 IO.mapRequired("header", Obj.HeaderData);
639 IO.mapRequired("symbols", Obj.Symbols);
642 } // end namespace yaml
643 } // end namespace llvm
645 int main(int argc, char **argv) {
646 cl::ParseCommandLineOptions(argc, argv);
647 sys::PrintStackTraceOnErrorSignal();
648 PrettyStackTraceProgram X(argc, argv);
649 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
651 OwningPtr<MemoryBuffer> Buf;
652 if (MemoryBuffer::getFileOrSTDIN(Input, Buf))
655 yaml::Input YIn(Buf->getBuffer());
656 COFFYAML::Object Doc;
659 errs() << "yaml2obj: Failed to parse YAML file!\n";
665 errs() << "yaml2obj: Failed to parse YAML file!\n";
669 if (!layoutCOFF(CP)) {
670 errs() << "yaml2obj: Failed to layout COFF file!\n";
673 writeCOFF(CP, outs());