summaryrefslogtreecommitdiffstats
path: root/llvm/tools/obj2yaml/macho2yaml.cpp
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2016-06-24 20:42:28 +0000
committerChris Bieneman <beanz@apple.com>2016-06-24 20:42:28 +0000
commit93e711938050e35f5275a1b36fae25226c25fc63 (patch)
tree92e6e7e0739f0c986b8d7c821aa0b374ce1a0f0c /llvm/tools/obj2yaml/macho2yaml.cpp
parent2e6d2d48205f272c39a50ae93ae4c700888e11e3 (diff)
downloadbcm5719-llvm-93e711938050e35f5275a1b36fae25226c25fc63.tar.gz
bcm5719-llvm-93e711938050e35f5275a1b36fae25226c25fc63.zip
[obj2yaml] [yaml2obj] Support for MachO Universal binaries
This patch adds round-trip support for MachO Universal binaries to obj2yaml and yaml2obj. Universal binaries have a header and list of architecture structures, followed by a the individual object files at specified offsets. llvm-svn: 273719
Diffstat (limited to 'llvm/tools/obj2yaml/macho2yaml.cpp')
-rw-r--r--llvm/tools/obj2yaml/macho2yaml.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp
index 24bd6a60da4..060a2b82726 100644
--- a/llvm/tools/obj2yaml/macho2yaml.cpp
+++ b/llvm/tools/obj2yaml/macho2yaml.cpp
@@ -473,23 +473,52 @@ Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) {
}
Error macho2yaml(raw_ostream &Out, const object::MachOUniversalBinary &Obj) {
- return make_error<Obj2YamlError>(obj2yaml_error::not_implemented);
+ MachOYAML::MachFile YAMLFile;
+ YAMLFile.isFat = true;
+ MachOYAML::UniversalBinary &YAML = YAMLFile.FatFile;
+ YAML.Header.magic = Obj.getMagic();
+ YAML.Header.nfat_arch = Obj.getNumberOfObjects();
+
+ for (auto Slice : Obj.objects()) {
+ MachOYAML::FatArch arch;
+ arch.cputype = Slice.getCPUType();
+ arch.cpusubtype = Slice.getCPUSubType();
+ arch.offset = Slice.getOffset();
+ arch.size = Slice.getSize();
+ arch.align = Slice.getAlign();
+ arch.reserved = Slice.getReserved();
+ YAML.FatArchs.push_back(arch);
+
+ auto SliceObj = Slice.getAsObjectFile();
+ if (!SliceObj)
+ return SliceObj.takeError();
+
+ MachODumper Dumper(*SliceObj.get());
+ Expected<std::unique_ptr<MachOYAML::Object>> YAMLObj = Dumper.dump();
+ if (!YAMLObj)
+ return YAMLObj.takeError();
+ YAML.Slices.push_back(*YAMLObj.get());
+ }
+
+ yaml::Output Yout(Out);
+ Yout << YAML;
+ return Error::success();
}
-std::error_code macho2yaml(raw_ostream &Out, const object::ObjectFile &Obj) {
- if (const auto *MachOObj = dyn_cast<object::MachOUniversalBinary>(&Obj)) {
+std::error_code macho2yaml(raw_ostream &Out, const object::Binary &Binary) {
+ if (const auto *MachOObj = dyn_cast<object::MachOUniversalBinary>(&Binary)) {
if (auto Err = macho2yaml(Out, *MachOObj)) {
return errorToErrorCode(std::move(Err));
}
return obj2yaml_error::success;
}
- if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Obj)) {
+ if (const auto *MachOObj = dyn_cast<object::MachOObjectFile>(&Binary)) {
if (auto Err = macho2yaml(Out, *MachOObj)) {
return errorToErrorCode(std::move(Err));
}
return obj2yaml_error::success;
}
-
+
return obj2yaml_error::unsupported_obj_file_format;
}
OpenPOWER on IntegriCloud