Skip to content

Commit fc21bb6

Browse files
committed
Revert "[yaml2obj] Move core yaml2obj code into lib and include for use in unit tests"
This reverts commit r368021, it broke tests. llvm-svn: 368035
1 parent bd1721e commit fc21bb6

File tree

16 files changed

+149
-290
lines changed

16 files changed

+149
-290
lines changed

llvm/lib/ObjectYAML/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,15 @@ add_llvm_library(LLVMObjectYAML
33
CodeViewYAMLSymbols.cpp
44
CodeViewYAMLTypeHashing.cpp
55
CodeViewYAMLTypes.cpp
6-
COFFEmitter.cpp
76
COFFYAML.cpp
87
DWARFEmitter.cpp
98
DWARFVisitor.cpp
109
DWARFYAML.cpp
11-
ELFEmitter.cpp
1210
ELFYAML.cpp
13-
MachOEmitter.cpp
1411
MachOYAML.cpp
1512
ObjectYAML.cpp
16-
MinidumpEmitter.cpp
1713
MinidumpYAML.cpp
18-
WasmEmitter.cpp
1914
WasmYAML.cpp
2015
XCOFFYAML.cpp
2116
YAML.cpp
22-
yaml2obj.cpp
23-
24-
ADDITIONAL_HEADER_DIRS
25-
${LLVM_MAIN_INCLUDE_DIR}/llvm/ObjectYAML
2617
)

llvm/lib/ObjectYAML/LLVMBuild.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
type = Library
1111
name = ObjectYAML
1212
parent = Libraries
13-
required_libraries = Object Support DebugInfoCodeView MC
13+
required_libraries = Object Support DebugInfoCodeView

llvm/lib/ObjectYAML/yaml2obj.cpp

Lines changed: 0 additions & 68 deletions
This file was deleted.

llvm/test/tools/yaml2obj/empty-or-invalid-doc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: echo -n "" | not yaml2obj 2>&1 | FileCheck %s
33
# RUN: echo " " | not yaml2obj 2>&1 | FileCheck %s
44
# RUN: echo " " | not yaml2obj 2>&1 | FileCheck %s
5-
# CHECK: yaml2obj: error: Unknown document type!
5+
# CHECK: yaml2obj: Unknown document type!
66

77
# RUN: echo -e -n "\xff" | not yaml2obj 2>&1 | FileCheck %s --check-prefix=INVALID
8-
# INVALID: yaml2obj: error: Failed to parse YAML input!
8+
# INVALID: yaml2obj: Failed to parse YAML file!

llvm/test/tools/yaml2obj/invalid-docnum.test

Lines changed: 0 additions & 22 deletions
This file was deleted.

llvm/test/tools/yaml2obj/missing_document_tag.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ DummyData:
66
...
77

88
# CHECK: YAML:4:1: error: YAML Object File missing document type tag!
9-
# CHECK: yaml2obj: error: Failed to parse YAML input!
9+
# CHECK: yaml2obj: Failed to parse YAML file!

llvm/tools/yaml2obj/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
set(LLVM_LINK_COMPONENTS
2+
DebugInfoCodeView
3+
MC
4+
Object
25
ObjectYAML
36
Support
47
)
58

69
add_llvm_tool(yaml2obj
710
yaml2obj.cpp
11+
yaml2coff.cpp
12+
yaml2elf.cpp
13+
yaml2macho.cpp
14+
yaml2minidump.cpp
15+
yaml2wasm.cpp
816
)

llvm/lib/ObjectYAML/COFFEmitter.cpp renamed to llvm/tools/yaml2obj/yaml2coff.cpp

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
///
1212
//===----------------------------------------------------------------------===//
1313

14+
#include "yaml2obj.h"
1415
#include "llvm/ADT/STLExtras.h"
1516
#include "llvm/ADT/StringExtras.h"
1617
#include "llvm/ADT/StringMap.h"
@@ -19,7 +20,6 @@
1920
#include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
2021
#include "llvm/Object/COFF.h"
2122
#include "llvm/ObjectYAML/ObjectYAML.h"
22-
#include "llvm/ObjectYAML/yaml2obj.h"
2323
#include "llvm/Support/Endian.h"
2424
#include "llvm/Support/MemoryBuffer.h"
2525
#include "llvm/Support/SourceMgr.h"
@@ -29,8 +29,6 @@
2929

3030
using namespace llvm;
3131

32-
namespace {
33-
3432
/// This parses a yaml stream that represents a COFF object file.
3533
/// See docs/yaml2obj for the yaml scheema.
3634
struct COFFParser {
@@ -66,8 +64,7 @@ struct COFFParser {
6664

6765
bool parseSections() {
6866
for (std::vector<COFFYAML::Section>::iterator i = Obj.Sections.begin(),
69-
e = Obj.Sections.end();
70-
i != e; ++i) {
67+
e = Obj.Sections.end(); i != e; ++i) {
7168
COFFYAML::Section &Sec = *i;
7269

7370
// If the name is less than 8 bytes, store it in place, otherwise
@@ -105,8 +102,7 @@ struct COFFParser {
105102

106103
bool parseSymbols() {
107104
for (std::vector<COFFYAML::Symbol>::iterator i = Obj.Symbols.begin(),
108-
e = Obj.Symbols.end();
109-
i != e; ++i) {
105+
e = Obj.Symbols.end(); i != e; ++i) {
110106
COFFYAML::Symbol &Sym = *i;
111107

112108
// If the name is less than 8 bytes, store it in place, otherwise
@@ -117,8 +113,8 @@ struct COFFParser {
117113
} else {
118114
// Add string to the string table and format the index for output.
119115
unsigned Index = getStringIndex(Name);
120-
*reinterpret_cast<support::aligned_ulittle32_t *>(Sym.Header.Name + 4) =
121-
Index;
116+
*reinterpret_cast<support::aligned_ulittle32_t*>(
117+
Sym.Header.Name + 4) = Index;
122118
}
123119

124120
Sym.Header.Type = Sym.SimpleType;
@@ -157,10 +153,6 @@ struct COFFParser {
157153
uint32_t SectionTableSize;
158154
};
159155

160-
enum { DOSStubSize = 128 };
161-
162-
} // end anonymous namespace
163-
164156
// Take a CP and assign addresses and sizes to everything. Returns false if the
165157
// layout is not valid to do.
166158
static bool layoutOptionalHeader(COFFParser &CP) {
@@ -174,6 +166,10 @@ static bool layoutOptionalHeader(COFFParser &CP) {
174166
return true;
175167
}
176168

169+
namespace {
170+
enum { DOSStubSize = 128 };
171+
}
172+
177173
static yaml::BinaryRef
178174
toDebugS(ArrayRef<CodeViewYAML::YAMLDebugSubsection> Subsections,
179175
const codeview::StringsAndChecksums &SC, BumpPtrAllocator &Allocator) {
@@ -275,7 +271,7 @@ static bool layoutCOFF(COFFParser &CP) {
275271
uint32_t NumberOfSymbols = 0;
276272
for (std::vector<COFFYAML::Symbol>::iterator i = CP.Obj.Symbols.begin(),
277273
e = CP.Obj.Symbols.end();
278-
i != e; ++i) {
274+
i != e; ++i) {
279275
uint32_t NumberOfAuxSymbols = 0;
280276
if (i->FunctionDefinition)
281277
NumberOfAuxSymbols += 1;
@@ -302,23 +298,24 @@ static bool layoutCOFF(COFFParser &CP) {
302298
else
303299
CP.Obj.Header.PointerToSymbolTable = 0;
304300

305-
*reinterpret_cast<support::ulittle32_t *>(&CP.StringTable[0]) =
306-
CP.StringTable.size();
301+
*reinterpret_cast<support::ulittle32_t *>(&CP.StringTable[0])
302+
= CP.StringTable.size();
307303

308304
return true;
309305
}
310306

311-
template <typename value_type> struct binary_le_impl {
307+
template <typename value_type>
308+
struct binary_le_impl {
312309
value_type Value;
313310
binary_le_impl(value_type V) : Value(V) {}
314311
};
315312

316313
template <typename value_type>
317-
raw_ostream &operator<<(raw_ostream &OS,
318-
const binary_le_impl<value_type> &BLE) {
314+
raw_ostream &operator <<( raw_ostream &OS
315+
, const binary_le_impl<value_type> &BLE) {
319316
char Buffer[sizeof(BLE.Value)];
320317
support::endian::write<value_type, support::little, support::unaligned>(
321-
Buffer, BLE.Value);
318+
Buffer, BLE.Value);
322319
OS.write(Buffer, sizeof(BLE.Value));
323320
return OS;
324321
}
@@ -338,13 +335,13 @@ raw_ostream &operator<<(raw_ostream &OS, const zeros_impl<NumBytes> &) {
338335
return OS;
339336
}
340337

341-
template <typename T> zeros_impl<sizeof(T)> zeros(const T &) {
338+
template <typename T>
339+
zeros_impl<sizeof(T)> zeros(const T &) {
342340
return zeros_impl<sizeof(T)>();
343341
}
344342

345343
template <typename T>
346-
static uint32_t initializeOptionalHeader(COFFParser &CP, uint16_t Magic,
347-
T Header) {
344+
static uint32_t initializeOptionalHeader(COFFParser &CP, uint16_t Magic, T Header) {
348345
memset(Header, 0, sizeof(*Header));
349346
Header->Magic = Magic;
350347
Header->SectionAlignment = CP.Obj.OptionalHeader->Header.SectionAlignment;
@@ -379,8 +376,10 @@ static uint32_t initializeOptionalHeader(COFFParser &CP, uint16_t Magic,
379376
CP.Obj.OptionalHeader->Header.MajorOperatingSystemVersion;
380377
Header->MinorOperatingSystemVersion =
381378
CP.Obj.OptionalHeader->Header.MinorOperatingSystemVersion;
382-
Header->MajorImageVersion = CP.Obj.OptionalHeader->Header.MajorImageVersion;
383-
Header->MinorImageVersion = CP.Obj.OptionalHeader->Header.MinorImageVersion;
379+
Header->MajorImageVersion =
380+
CP.Obj.OptionalHeader->Header.MajorImageVersion;
381+
Header->MinorImageVersion =
382+
CP.Obj.OptionalHeader->Header.MinorImageVersion;
384383
Header->MajorSubsystemVersion =
385384
CP.Obj.OptionalHeader->Header.MajorSubsystemVersion;
386385
Header->MinorSubsystemVersion =
@@ -424,13 +423,15 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
424423
if (CP.useBigObj()) {
425424
OS << binary_le(static_cast<uint16_t>(COFF::IMAGE_FILE_MACHINE_UNKNOWN))
426425
<< binary_le(static_cast<uint16_t>(0xffff))
427-
<< binary_le(
428-
static_cast<uint16_t>(COFF::BigObjHeader::MinBigObjectVersion))
426+
<< binary_le(static_cast<uint16_t>(COFF::BigObjHeader::MinBigObjectVersion))
429427
<< binary_le(CP.Obj.Header.Machine)
430428
<< binary_le(CP.Obj.Header.TimeDateStamp);
431429
OS.write(COFF::BigObjMagic, sizeof(COFF::BigObjMagic));
432-
OS << zeros(uint32_t(0)) << zeros(uint32_t(0)) << zeros(uint32_t(0))
433-
<< zeros(uint32_t(0)) << binary_le(CP.Obj.Header.NumberOfSections)
430+
OS << zeros(uint32_t(0))
431+
<< zeros(uint32_t(0))
432+
<< zeros(uint32_t(0))
433+
<< zeros(uint32_t(0))
434+
<< binary_le(CP.Obj.Header.NumberOfSections)
434435
<< binary_le(CP.Obj.Header.PointerToSymbolTable)
435436
<< binary_le(CP.Obj.Header.NumberOfSymbols);
436437
} else {
@@ -449,8 +450,7 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
449450
OS.write(reinterpret_cast<char *>(&PEH), sizeof(PEH));
450451
} else {
451452
object::pe32_header PEH;
452-
uint32_t BaseOfData =
453-
initializeOptionalHeader(CP, COFF::PE32Header::PE32, &PEH);
453+
uint32_t BaseOfData = initializeOptionalHeader(CP, COFF::PE32Header::PE32, &PEH);
454454
PEH.BaseOfData = BaseOfData;
455455
OS.write(reinterpret_cast<char *>(&PEH), sizeof(PEH));
456456
}
@@ -472,7 +472,7 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
472472
// Output section table.
473473
for (std::vector<COFFYAML::Section>::iterator i = CP.Obj.Sections.begin(),
474474
e = CP.Obj.Sections.end();
475-
i != e; ++i) {
475+
i != e; ++i) {
476476
OS.write(i->Header.Name, COFF::NameSize);
477477
OS << binary_le(i->Header.VirtualSize)
478478
<< binary_le(i->Header.VirtualAddress)
@@ -514,7 +514,8 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
514514
} else {
515515
SymbolTableIndex = SymbolTableIndexMap[R.SymbolName];
516516
}
517-
OS << binary_le(R.VirtualAddress) << binary_le(SymbolTableIndex)
517+
OS << binary_le(R.VirtualAddress)
518+
<< binary_le(SymbolTableIndex)
518519
<< binary_le(R.Type);
519520
}
520521
}
@@ -523,14 +524,15 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
523524

524525
for (std::vector<COFFYAML::Symbol>::const_iterator i = CP.Obj.Symbols.begin(),
525526
e = CP.Obj.Symbols.end();
526-
i != e; ++i) {
527+
i != e; ++i) {
527528
OS.write(i->Header.Name, COFF::NameSize);
528529
OS << binary_le(i->Header.Value);
529530
if (CP.useBigObj())
530-
OS << binary_le(i->Header.SectionNumber);
531+
OS << binary_le(i->Header.SectionNumber);
531532
else
532-
OS << binary_le(static_cast<int16_t>(i->Header.SectionNumber));
533-
OS << binary_le(i->Header.Type) << binary_le(i->Header.StorageClass)
533+
OS << binary_le(static_cast<int16_t>(i->Header.SectionNumber));
534+
OS << binary_le(i->Header.Type)
535+
<< binary_le(i->Header.StorageClass)
534536
<< binary_le(i->Header.NumberOfAuxSymbols);
535537

536538
if (i->FunctionDefinition) {
@@ -576,7 +578,8 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
576578
OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
577579
}
578580
if (i->CLRToken) {
579-
OS << binary_le(i->CLRToken->AuxType) << zeros(i->CLRToken->unused1)
581+
OS << binary_le(i->CLRToken->AuxType)
582+
<< zeros(i->CLRToken->unused1)
580583
<< binary_le(i->CLRToken->SymbolTableIndex)
581584
<< zeros(i->CLRToken->unused2);
582585
OS.write_zeros(CP.getSymbolSize() - COFF::Symbol16Size);
@@ -589,9 +592,6 @@ static bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
589592
return true;
590593
}
591594

592-
namespace llvm {
593-
namespace yaml {
594-
595595
int yaml2coff(llvm::COFFYAML::Object &Doc, raw_ostream &Out) {
596596
COFFParser CP(Doc);
597597
if (!CP.parse()) {
@@ -614,6 +614,3 @@ int yaml2coff(llvm::COFFYAML::Object &Doc, raw_ostream &Out) {
614614
}
615615
return 0;
616616
}
617-
618-
} // namespace yaml
619-
} // namespace llvm

0 commit comments

Comments
 (0)