diff --git a/test/Object/archive-symtab.test b/test/Object/archive-symtab.test index 88c9c989dcf..5e5292c86e1 100644 --- a/test/Object/archive-symtab.test +++ b/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/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index cccddb0736d..5221d4d18d9 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/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);