diff options
Diffstat (limited to 'tools/llvm-nm')
-rw-r--r-- | tools/llvm-nm/Makefile | 8 | ||||
-rw-r--r-- | tools/llvm-nm/llvm-nm.cpp | 45 |
2 files changed, 35 insertions, 18 deletions
diff --git a/tools/llvm-nm/Makefile b/tools/llvm-nm/Makefile index 6bb4cd4..d9cee98 100644 --- a/tools/llvm-nm/Makefile +++ b/tools/llvm-nm/Makefile @@ -6,12 +6,12 @@ # License. See LICENSE.TXT for details. # ##===----------------------------------------------------------------------===## -LEVEL = ../.. -TOOLNAME = llvm-nm -LINK_COMPONENTS = archive bitreader object +LEVEL := ../.. +TOOLNAME := llvm-nm +LINK_COMPONENTS := archive bitreader object # This tool has no plugins, optimize startup time. -TOOL_NO_EXPORTS = 1 +TOOL_NO_EXPORTS := 1 include $(LEVEL)/Makefile.common diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 014cb29..550ca4f 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -20,6 +20,7 @@ #include "llvm/Module.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Bitcode/Archive.h" +#include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" @@ -270,9 +271,9 @@ static void DumpSymbolNamesFromModule(Module *M) { static void DumpSymbolNamesFromObject(ObjectFile *obj) { error_code ec; - for (ObjectFile::symbol_iterator i = obj->begin_symbols(), - e = obj->end_symbols(); - i != e; i.increment(ec)) { + for (symbol_iterator i = obj->begin_symbols(), + e = obj->end_symbols(); + i != e; i.increment(ec)) { if (error(ec)) break; bool internal; if (error(i->isInternal(internal))) break; @@ -285,7 +286,7 @@ static void DumpSymbolNamesFromObject(ObjectFile *obj) { if (error(i->getSize(s.Size))) break; } if (PrintAddress) - if (error(i->getAddress(s.Address))) break; + if (error(i->getOffset(s.Address))) break; if (error(i->getNMTypeChar(s.TypeChar))) break; if (error(i->getName(s.Name))) break; SymbolList.push_back(s); @@ -318,18 +319,34 @@ static void DumpSymbolNamesFromFile(std::string &Filename) { errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n"; } else if (aPath.isArchive()) { - std::string ErrMsg; - Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), Context, - &ErrorMessage); - if (!archive) - errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n"; - std::vector<Module *> Modules; - if (archive->getAllModules(Modules, &ErrorMessage)) { - errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n"; + OwningPtr<Binary> arch; + if (error_code ec = object::createBinary(aPath.str(), arch)) { + errs() << ToolName << ": " << Filename << ": " << ec.message() << ".\n"; return; } - MultipleFiles = true; - std::for_each (Modules.begin(), Modules.end(), DumpSymbolNamesFromModule); + if (object::Archive *a = dyn_cast<object::Archive>(arch.get())) { + for (object::Archive::child_iterator i = a->begin_children(), + e = a->end_children(); i != e; ++i) { + OwningPtr<Binary> child; + if (error_code ec = i->getAsBinary(child)) { + // Try opening it as a bitcode file. + OwningPtr<MemoryBuffer> buff(i->getBuffer()); + Module *Result = 0; + if (buff) + Result = ParseBitcodeFile(buff.get(), Context, &ErrorMessage); + + if (Result) { + DumpSymbolNamesFromModule(Result); + delete Result; + } + continue; + } + if (object::ObjectFile *o = dyn_cast<ObjectFile>(child.get())) { + outs() << o->getFileName() << ":\n"; + DumpSymbolNamesFromObject(o); + } + } + } } else if (aPath.isObjectFile()) { OwningPtr<Binary> obj; if (error_code ec = object::createBinary(aPath.str(), obj)) { |