From 26646108c93ca43b226060052fcae0aacba70ea0 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Fri, 20 Jun 2014 21:29:27 +0000 Subject: [PATCH] Fix some double printing of filenames for archives in llvm-nm when the tool is given multiple files. Also fix the same issue with Mach-O universal files. And fix the newline spacing to separate the output in these cases. llvm-svn: 211405 --- llvm/test/Object/archive-symtab.test | 6 ++++-- llvm/tools/llvm-nm/llvm-nm.cpp | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/llvm/test/Object/archive-symtab.test b/llvm/test/Object/archive-symtab.test index 88c9c98..5e5292c8 100644 --- a/llvm/test/Object/archive-symtab.test +++ b/llvm/test/Object/archive-symtab.test @@ -12,7 +12,8 @@ CHECK: trivial-object-test.elf-x86-64: CHECK-NEXT: U SomeOtherFunction CHECK-NEXT: 0000000000000000 T main CHECK-NEXT: U puts -CHECK-NEXT: trivial-object-test2.elf-x86-64: + +CHECK: trivial-object-test2.elf-x86-64: CHECK-NEXT: 0000000000000000 t bar CHECK-NEXT: 0000000000000006 T foo CHECK-NEXT: 0000000000000016 T main @@ -40,7 +41,8 @@ CORRUPT: trivial-object-test.elf-x86-64: CORRUPT-NEXT: U SomeOtherFunction CORRUPT-NEXT: 0000000000000000 T main CORRUPT-NEXT: U puts -CORRUPT-NEXT: trivial-object-test2.elf-x86-64: + +CORRUPT: trivial-object-test2.elf-x86-64: CORRUPT-NEXT: 0000000000000000 t bar CORRUPT-NEXT: 0000000000000006 T foo CORRUPT-NEXT: 0000000000000016 T main diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index cccddb0..5221d4d 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -370,7 +370,7 @@ static void darwinPrintSymbol(MachOObjectFile *MachO, SymbolListT::iterator I, outs() << "\n"; } -static void sortAndPrintSymbolList(SymbolicFile *Obj) { +static void sortAndPrintSymbolList(SymbolicFile *Obj, bool printName) { if (!NoSort) { if (NumericSort) std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolAddress); @@ -380,9 +380,9 @@ static void sortAndPrintSymbolList(SymbolicFile *Obj) { std::sort(SymbolList.begin(), SymbolList.end(), compareSymbolName); } - if (OutputFormat == posix && MultipleFiles) { + if (OutputFormat == posix && MultipleFiles && printName) { outs() << '\n' << CurrentFilename << ":\n"; - } else if (OutputFormat == bsd && MultipleFiles) { + } else if (OutputFormat == bsd && MultipleFiles && printName) { outs() << "\n" << CurrentFilename << ":\n"; } else if (OutputFormat == sysv) { outs() << "\n\nSymbols from " << CurrentFilename << ":\n\n" @@ -664,7 +664,7 @@ static char getNMTypeChar(SymbolicFile *Obj, basic_symbol_iterator I) { return Ret; } -static void dumpSymbolNamesFromObject(SymbolicFile *Obj) { +static void dumpSymbolNamesFromObject(SymbolicFile *Obj, bool printName) { basic_symbol_iterator IBegin = Obj->symbol_begin(); basic_symbol_iterator IEnd = Obj->symbol_end(); if (DynamicSyms) { @@ -717,7 +717,7 @@ static void dumpSymbolNamesFromObject(SymbolicFile *Obj) { } CurrentFilename = Obj->getFileName(); - sortAndPrintSymbolList(Obj); + sortAndPrintSymbolList(Obj, printName); } static void dumpSymbolNamesFromFile(std::string &Filename) { @@ -757,12 +757,13 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { if (ChildOrErr.getError()) continue; if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) { + outs() << "\n"; if (isa(O)) { outs() << Filename << "(" << O->getFileName() << ")"; } else outs() << O->getFileName(); outs() << ":\n"; - dumpSymbolNamesFromObject(O); + dumpSymbolNamesFromObject(O, false); } } return; @@ -775,11 +776,13 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { std::unique_ptr Obj; std::unique_ptr A; if (!I->getAsObjectFile(Obj)) { + if (moreThanOneArch) + outs() << "\n"; outs() << Obj->getFileName(); if (isa(Obj.get()) && moreThanOneArch) outs() << " (for architecture " << I->getArchTypeName() << ")"; outs() << ":\n"; - dumpSymbolNamesFromObject(Obj.get()); + dumpSymbolNamesFromObject(Obj.get(), false); } else if (!I->getAsArchive(A)) { for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end(); @@ -789,7 +792,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { if (ChildOrErr.getError()) continue; if (SymbolicFile *O = dyn_cast(&*ChildOrErr.get())) { - outs() << A->getFileName(); + outs() << "\n" << A->getFileName(); if (isa(O)) { outs() << "(" << O->getFileName() << ")"; if (moreThanOneArch) @@ -797,7 +800,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { } else outs() << ":" << O->getFileName(); outs() << ":\n"; - dumpSymbolNamesFromObject(O); + dumpSymbolNamesFromObject(O, false); } } } @@ -805,7 +808,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { return; } if (SymbolicFile *O = dyn_cast(Bin.get())) { - dumpSymbolNamesFromObject(O); + dumpSymbolNamesFromObject(O, true); return; } error("unrecognizable file type", Filename); -- 2.7.4