From: Petr Hosek Date: Fri, 5 Oct 2018 21:10:03 +0000 (+0000) Subject: [llvm-nm] Write "no symbol" output to stderr X-Git-Tag: llvmorg-8.0.0-rc1~7130 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=62f6462bf931693792743cf61d655bb644bd72b3;p=platform%2Fupstream%2Fllvm.git [llvm-nm] Write "no symbol" output to stderr 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 llvm-svn: 343887 --- diff --git a/clang/test/CodeGen/thinlto_backend.ll b/clang/test/CodeGen/thinlto_backend.ll index be7a6fe..2dd919d 100644 --- a/clang/test/CodeGen/thinlto_backend.ll +++ b/clang/test/CodeGen/thinlto_backend.ll @@ -25,7 +25,7 @@ ; be empty file. ; RUN: opt -o %t5.o %s ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc -; RUN: llvm-nm %t4.o | FileCheck %s -check-prefix=NO-SYMBOLS +; RUN: llvm-nm %t4.o 2>&1 | FileCheck %s -check-prefix=NO-SYMBOLS ; NO-SYMBOLS: no symbols ; Ensure f2 was imported. Check for all 3 flavors of -save-temps[=cwd|obj]. diff --git a/lld/test/ELF/lto/thinlto-obj-path.ll b/lld/test/ELF/lto/thinlto-obj-path.ll index 934b505..2806d16 100644 --- a/lld/test/ELF/lto/thinlto-obj-path.ll +++ b/lld/test/ELF/lto/thinlto-obj-path.ll @@ -7,7 +7,7 @@ ; RUN: rm -f %t4.o ; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o %t3 ; RUN: llvm-readobj -h %t4.o | FileCheck %s -; RUN: llvm-nm %t4.o | FileCheck %s -check-prefix=NO-SYMBOLS +; RUN: llvm-nm %t4.o 2>&1 | FileCheck %s -check-prefix=NO-SYMBOLS ; NO-SYMBOLS: no symbols ; CHECK: Format: ELF64-x86-64 diff --git a/llvm/test/Object/nm-shared-object.test b/llvm/test/Object/nm-shared-object.test index 678e871..9865383 100644 --- a/llvm/test/Object/nm-shared-object.test +++ b/llvm/test/Object/nm-shared-object.test @@ -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 diff --git a/llvm/test/ThinLTO/X86/empty-module.ll b/llvm/test/ThinLTO/X86/empty-module.ll index 63a09fb..285e1bc 100644 --- a/llvm/test/ThinLTO/X86/empty-module.ll +++ b/llvm/test/ThinLTO/X86/empty-module.ll @@ -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 diff --git a/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test b/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test index 1ae8308..808a9b1 100644 --- a/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test +++ b/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test @@ -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: diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index 01d21cc..7e1fd86 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -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) {