Add binary archive support to llvm-nm.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140627 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer 2011-09-27 19:37:18 +00:00
parent a51d7d97b0
commit 9142ae2cf8
4 changed files with 44 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,17 @@
RUN: llvm-nm %p/TestObjectFiles/archive-test.a-coff-i386 \
RUN: | FileCheck %s -check-prefix COFF
RUN: llvm-nm %p/TestObjectFiles/archive-test.a-bitcode \
RUN: | FileCheck %s -check-prefix BITCODE
COFF: trivial-object-test.coff-i386:
COFF-NEXT: 00000000 d .data
COFF-NEXT: 00000000 t .text
COFF-NEXT: 00000000 d L_.str
COFF-NEXT: U _SomeOtherFunction
COFF-NEXT: 00000000 T _main
COFF-NEXT: U _puts
BITCODE: U SomeOtherFunction
BITCODE-NEXT: T main
BITCODE-NEXT: U puts

View File

@ -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"
@ -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.
MemoryBuffer *buff = i->getBuffer();
Module *Result = 0;
if (buff)
Result = ParseBitcodeFile(buff, 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)) {