diff options
author | Chris Bieneman <beanz@apple.com> | 2016-06-02 22:54:06 +0000 |
---|---|---|
committer | Chris Bieneman <beanz@apple.com> | 2016-06-02 22:54:06 +0000 |
commit | 07bb3c84a2d1eff7f3577cce023dca517aa7c3ed (patch) | |
tree | bfc2fb2bb090b8a0c9f2a6869fddbf2abe4c31bf /llvm/tools/obj2yaml/macho2yaml.cpp | |
parent | 172bf6edd13aa0c8e117db4d50f295c74b7dc4fd (diff) | |
download | bcm5719-llvm-07bb3c84a2d1eff7f3577cce023dca517aa7c3ed.tar.gz bcm5719-llvm-07bb3c84a2d1eff7f3577cce023dca517aa7c3ed.zip |
[obj2yaml] [yaml2obj] Support for MachO nlist and string table
This commit adds round tripping for MachO symbol data. Symbols are entries in the name list, that contain offsets into the string table which is at the end of the __LINKEDIT segment.
llvm-svn: 271604
Diffstat (limited to 'llvm/tools/obj2yaml/macho2yaml.cpp')
-rw-r--r-- | llvm/tools/obj2yaml/macho2yaml.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/tools/obj2yaml/macho2yaml.cpp b/llvm/tools/obj2yaml/macho2yaml.cpp index be584f2ffe7..24bd6a60da4 100644 --- a/llvm/tools/obj2yaml/macho2yaml.cpp +++ b/llvm/tools/obj2yaml/macho2yaml.cpp @@ -33,6 +33,7 @@ class MachODumper { void dumpBindOpcodes(std::vector<MachOYAML::BindOpcode> &BindOpcodes, ArrayRef<uint8_t> OpcodeBuffer, bool Lazy = false); void dumpExportTrie(std::unique_ptr<MachOYAML::Object> &Y); + void dumpSymbols(std::unique_ptr<MachOYAML::Object> &Y); public: MachODumper(const object::MachOObjectFile &O) : Obj(O) {} @@ -210,6 +211,7 @@ void MachODumper::dumpLinkEdit(std::unique_ptr<MachOYAML::Object> &Y) { dumpBindOpcodes(Y->LinkEdit.LazyBindOpcodes, Obj.getDyldInfoLazyBindOpcodes(), true); dumpExportTrie(Y); + dumpSymbols(Y); } void MachODumper::dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y) { @@ -424,6 +426,41 @@ void MachODumper::dumpExportTrie(std::unique_ptr<MachOYAML::Object> &Y) { processExportNode(ExportsTrie.begin(), ExportsTrie.end(), LEData.ExportTrie); } +template <typename nlist_t> +MachOYAML::NListEntry constructNameList(const nlist_t &nlist) { + MachOYAML::NListEntry NL; + NL.n_strx = nlist.n_strx; + NL.n_type = nlist.n_type; + NL.n_sect = nlist.n_sect; + NL.n_desc = nlist.n_desc; + NL.n_value = nlist.n_value; + return NL; +} + +void MachODumper::dumpSymbols(std::unique_ptr<MachOYAML::Object> &Y) { + MachOYAML::LinkEditData &LEData = Y->LinkEdit; + + for (auto Symbol : Obj.symbols()) { + MachOYAML::NListEntry NLE = + Obj.is64Bit() ? constructNameList<MachO::nlist_64>( + *reinterpret_cast<const MachO::nlist_64 *>( + Symbol.getRawDataRefImpl().p)) + : constructNameList<MachO::nlist>( + *reinterpret_cast<const MachO::nlist *>( + Symbol.getRawDataRefImpl().p)); + LEData.NameList.push_back(NLE); + } + + StringRef RemainingTable = Obj.getStringTableData(); + while (RemainingTable.size() > 0) { + auto SymbolPair = RemainingTable.split('\0'); + RemainingTable = SymbolPair.second; + if (SymbolPair.first.empty()) + break; + LEData.StringTable.push_back(SymbolPair.first); + } +} + Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) { MachODumper Dumper(Obj); Expected<std::unique_ptr<MachOYAML::Object>> YAML = Dumper.dump(); |