OSDN Git Service

[llvm-nm] Write "no symbol" output to stderr
authorPetr Hosek <phosek@chromium.org>
Fri, 5 Oct 2018 21:10:03 +0000 (21:10 +0000)
committerPetr Hosek <phosek@chromium.org>
Fri, 5 Oct 2018 21:10:03 +0000 (21:10 +0000)
This matches the output of binutils' nm and ensures that any scripts
or tools that use nm and expect empty output in case there no symbols
don't break.

Differential Revision: https://reviews.llvm.org/D52943

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343887 91177308-0d34-0410-b5e6-96231b3b80d8

test/Object/nm-shared-object.test
test/ThinLTO/X86/empty-module.ll
test/tools/llvm-nm/X86/nm-no-symbols.test
tools/llvm-nm/llvm-nm.cpp

index 678e871..9865383 100644 (file)
@@ -30,5 +30,6 @@ RUN:         | FileCheck %s -check-prefix ERROR
 
 ERROR: File format has no dynamic symbol table.
 
-RUN: llvm-nm -D %p/Inputs/trivial-object-test.elf-i386 | FileCheck %s -check-prefix=NO-SYMBOLS
+RUN: llvm-nm -D %p/Inputs/trivial-object-test.elf-i386 2>&1 \
+RUN:         | FileCheck %s -check-prefix=NO-SYMBOLS
 NO-SYMBOLS: no symbols
index 63a09fb..285e1bc 100644 (file)
@@ -3,7 +3,7 @@
 ; RUN: rm -f %t2.0
 ; RUN: llvm-lto2 run  %t.bc -r %t.bc,foo,pl -o %t2 -thinlto-distributed-indexes
 ; RUN: llvm-readobj -h %t2.0 | FileCheck %s
-; RUN: llvm-nm %t2.0 | FileCheck %s -check-prefix=NO-SYMBOLS
+; RUN: llvm-nm %t2.0 2>&1 | FileCheck %s -check-prefix=NO-SYMBOLS
 ; NO-SYMBOLS: no symbols
 
 ; CHECK: Format: ELF64-x86-64
index 1ae8308..808a9b1 100644 (file)
@@ -1,6 +1,6 @@
 # RUN: yaml2obj %s > %t.o
-# RUN: llvm-nm %t.o | FileCheck %s
-# RUN: llvm-nm --print-file-name %t.o | FileCheck %s --check-prefix=CHECK-PRINT-FILE-NAME
+# RUN: llvm-nm %t.o 2>&1 | FileCheck %s
+# RUN: llvm-nm --print-file-name %t.o 2>&1 | FileCheck %s --check-prefix=CHECK-PRINT-FILE-NAME
 
 !ELF
 FileHeader:
index 01d21cc..7e1fd86 100644 (file)
@@ -757,22 +757,22 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
     }
   }
 
-  auto writeFileName = [&]() {
+  auto writeFileName = [&](raw_ostream &S) {
     if (!ArchitectureName.empty())
-      outs() << "(for architecture " << ArchitectureName << "):";
+      S << "(for architecture " << ArchitectureName << "):";
     if (OutputFormat == posix && !ArchiveName.empty())
-      outs() << ArchiveName << "[" << CurrentFilename << "]: ";
+      S << ArchiveName << "[" << CurrentFilename << "]: ";
     else {
       if (!ArchiveName.empty())
-        outs() << ArchiveName << ":";
-      outs() << CurrentFilename << ": ";
+        S << ArchiveName << ":";
+      S << CurrentFilename << ": ";
     }
   };
 
   if (SymbolList.empty()) {
     if (PrintFileName)
-      writeFileName();
-    outs() << "no symbols\n";
+      writeFileName(errs());
+    errs() << "no symbols\n";
   }
 
   for (SymbolListT::iterator I = SymbolList.begin(), E = SymbolList.end();
@@ -797,7 +797,7 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
         (Weak && NoWeakSymbols))
       continue;
     if (PrintFileName)
-      writeFileName();
+      writeFileName(outs());
     if ((JustSymbolName ||
          (UndefinedOnly && MachO && OutputFormat != darwin)) &&
         OutputFormat != posix) {