diff options
author | Chris Bieneman <beanz@apple.com> | 2016-05-13 17:41:41 +0000 |
---|---|---|
committer | Chris Bieneman <beanz@apple.com> | 2016-05-13 17:41:41 +0000 |
commit | 8b5906ea7fc47e5d10f6688d24c10e27ffb1442e (patch) | |
tree | e4902179e6b04bf7c5a0a50d0d38d58b85998477 /llvm/tools/obj2yaml/macho2yaml.cpp | |
parent | 8db5174395a3b145c14c8bb5bf01382281a6a10c (diff) | |
download | bcm5719-llvm-8b5906ea7fc47e5d10f6688d24c10e27ffb1442e.tar.gz bcm5719-llvm-8b5906ea7fc47e5d10f6688d24c10e27ffb1442e.zip |
[obj2yaml] [yaml2obj] Basic support for MachO::load_command
This patch adds basic support for MachO::load_command. Load command types and sizes are encoded in the YAML and expanded back into MachO.
The YAML doesn't yet support load command structs, that is coming next. In the meantime as a temporary measure when writing MachO files the load commands are padded with zeros so that the generated binary is valid.
llvm-svn: 269442
Diffstat (limited to 'llvm/tools/obj2yaml/macho2yaml.cpp')
-rw-r--r-- | llvm/tools/obj2yaml/macho2yaml.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp index b787a3e0c24..e71f467e794 100644 --- a/llvm/tools/obj2yaml/macho2yaml.cpp +++ b/llvm/tools/obj2yaml/macho2yaml.cpp @@ -21,10 +21,10 @@ class MachODumper { public: MachODumper(const object::MachOObjectFile &O) : Obj(O) {} - Expected<std::unique_ptr<MachOYAML::Object> > dump(); + Expected<std::unique_ptr<MachOYAML::Object>> dump(); }; -Expected<std::unique_ptr<MachOYAML::Object> > MachODumper::dump() { +Expected<std::unique_ptr<MachOYAML::Object>> MachODumper::dump() { auto Y = make_unique<MachOYAML::Object>(); Y->Header.magic = Obj.getHeader().magic; Y->Header.cputype = Obj.getHeader().cputype; @@ -34,12 +34,19 @@ Expected<std::unique_ptr<MachOYAML::Object> > MachODumper::dump() { Y->Header.sizeofcmds = Obj.getHeader().sizeofcmds; Y->Header.flags = Obj.getHeader().flags; + for (auto load_command : Obj.load_commands()) { + auto LC = make_unique<MachOYAML::LoadCommand>(); + LC->cmd = static_cast<MachO::LoadCommandType>(load_command.C.cmd); + LC->cmdsize = load_command.C.cmdsize; + Y->LoadCommands.push_back(std::move(LC)); + } + return std::move(Y); } Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) { MachODumper Dumper(Obj); - Expected<std::unique_ptr<MachOYAML::Object> > YAML = Dumper.dump(); + Expected<std::unique_ptr<MachOYAML::Object>> YAML = Dumper.dump(); if (!YAML) return YAML.takeError(); |