Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[yaml2obj] Remove --format option in favor of YAML tags
Summary: Our YAML library's handling of tags isn't perfect, but it is good enough to get rid of the need for the --format argument to yaml2obj. This patch does exactly that. Instead of requiring --format, it infers the format based on the tags found in the object file. The supported tags are: !ELF !COFF !mach-o !fat-mach-o I have a corresponding patch that is quite large that fixes up all the in-tree test cases. Reviewers: rafael, Bigcheese, compnerd, silvas Subscribers: compnerd, llvm-commits Differential Revision: http://reviews.llvm.org/D21711 llvm-svn: 273915
- Loading branch information
Chris Bieneman
committed
Jun 27, 2016
1 parent
f0fa61f
commit 8ff0c11
Showing
76 changed files
with
261 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//===- ObjectYAML.h ---------------------------------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_OBJECTYAML_OBJECTYAML_H | ||
#define LLVM_OBJECTYAML_OBJECTYAML_H | ||
|
||
#include "llvm/Support/YAMLTraits.h" | ||
#include "llvm/ObjectYAML/ELFYAML.h" | ||
#include "llvm/ObjectYAML/COFFYAML.h" | ||
#include "llvm/ObjectYAML/MachOYAML.h" | ||
|
||
namespace llvm { | ||
namespace yaml { | ||
|
||
struct YamlObjectFile { | ||
std::unique_ptr<ELFYAML::Object> Elf; | ||
std::unique_ptr<COFFYAML::Object> Coff; | ||
std::unique_ptr<MachOYAML::Object> MachO; | ||
std::unique_ptr<MachOYAML::UniversalBinary> FatMachO; | ||
}; | ||
|
||
template <> struct MappingTraits<YamlObjectFile> { | ||
static void mapping(IO &IO, YamlObjectFile &ObjectFile); | ||
}; | ||
|
||
} // namespace yaml | ||
} // namespace llvm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ add_llvm_library(LLVMObjectYAML | |
COFFYAML.cpp | ||
ELFYAML.cpp | ||
MachOYAML.cpp | ||
ObjectYAML.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//===- ObjectYAML.cpp - YAML utilities for object files -------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines a wrapper class for handling tagged YAML input | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/ObjectYAML/YAML.h" | ||
#include "llvm/ObjectYAML/ObjectYAML.h" | ||
|
||
using namespace llvm; | ||
using namespace yaml; | ||
|
||
void MappingTraits<YamlObjectFile>::mapping(IO &IO, | ||
YamlObjectFile &ObjectFile) { | ||
if (IO.outputting()) { | ||
if (ObjectFile.Elf) | ||
MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf); | ||
if (ObjectFile.Coff) | ||
MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff); | ||
if (ObjectFile.MachO) | ||
MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO); | ||
if (ObjectFile.FatMachO) | ||
MappingTraits<MachOYAML::UniversalBinary>::mapping(IO, | ||
*ObjectFile.FatMachO); | ||
} else { | ||
if (IO.mapTag("!ELF")) { | ||
ObjectFile.Elf.reset(new ELFYAML::Object()); | ||
MappingTraits<ELFYAML::Object>::mapping(IO, *ObjectFile.Elf); | ||
} else if (IO.mapTag("!COFF")) { | ||
ObjectFile.Coff.reset(new COFFYAML::Object()); | ||
MappingTraits<COFFYAML::Object>::mapping(IO, *ObjectFile.Coff); | ||
} else if (IO.mapTag("!mach-o")) { | ||
ObjectFile.MachO.reset(new MachOYAML::Object()); | ||
MappingTraits<MachOYAML::Object>::mapping(IO, *ObjectFile.MachO); | ||
} else if (IO.mapTag("!fat-mach-o")) { | ||
ObjectFile.FatMachO.reset(new MachOYAML::UniversalBinary()); | ||
MappingTraits<MachOYAML::UniversalBinary>::mapping(IO, | ||
*ObjectFile.FatMachO); | ||
} else { | ||
Input &In = (Input &)IO; | ||
std::string Tag = In.getCurrentNode()->getRawTag(); | ||
if (Tag.empty()) | ||
IO.setError("YAML Object File missing document type tag!"); | ||
else | ||
IO.setError( | ||
llvm::Twine("YAML Object File unsupported document type tag '") + | ||
llvm::Twine(Tag.c_str()) + llvm::Twine("'!")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
!COFF | ||
header: !Header | ||
Machine: IMAGE_FILE_MACHINE_I386 # (0x14c) | ||
Characteristics: [ IMAGE_FILE_DEBUG_STRIPPED ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
--- !COFF | ||
header: | ||
Machine: IMAGE_FILE_MACHINE_ARMNT | ||
Characteristics: [ ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
!COFF | ||
header: !Header | ||
Machine: IMAGE_FILE_MACHINE_AMD64 # (0x8664) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.