Index: llvm/trunk/test/Object/nm-shared-object.test =================================================================== --- llvm/trunk/test/Object/nm-shared-object.test +++ llvm/trunk/test/Object/nm-shared-object.test @@ -30,4 +30,5 @@ ERROR: File format has no dynamic symbol table. -RUN: llvm-nm -D %p/Inputs/trivial-object-test.elf-i386 | count 0 +RUN: llvm-nm -D %p/Inputs/trivial-object-test.elf-i386 | FileCheck %s -check-prefix=NO-SYMBOLS +NO-SYMBOLS: no symbols Index: llvm/trunk/test/ThinLTO/X86/empty-module.ll =================================================================== --- llvm/trunk/test/ThinLTO/X86/empty-module.ll +++ llvm/trunk/test/ThinLTO/X86/empty-module.ll @@ -3,7 +3,8 @@ ; 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 | count 0 +; RUN: llvm-nm %t2.0 | FileCheck %s -check-prefix=NO-SYMBOLS +; NO-SYMBOLS: no symbols ; CHECK: Format: ELF64-x86-64 Index: llvm/trunk/test/tools/gold/X86/bcsection.ll =================================================================== --- llvm/trunk/test/tools/gold/X86/bcsection.ll +++ llvm/trunk/test/tools/gold/X86/bcsection.ll @@ -2,7 +2,9 @@ ; RUN: llvm-as -o %t/bcsection.bc %s ; RUN: llvm-mc -I=%t -filetype=obj -triple=x86_64-unknown-unknown -o %t/bcsection.bco %p/Inputs/bcsection.s -; RUN: llvm-nm -no-llvm-bc %t/bcsection.bco | count 0 +; RUN: llvm-nm -no-llvm-bc %t/bcsection.bco | FileCheck %s -check-prefix=NO-SYMBOLS +; NO-SYMBOLS: no symbols + ; RUN: %gold -r -o %t/bcsection.o -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext %t/bcsection.bco ; RUN: llvm-nm -no-llvm-bc %t/bcsection.o | FileCheck %s Index: llvm/trunk/test/tools/gold/X86/thinlto.ll =================================================================== --- llvm/trunk/test/tools/gold/X86/thinlto.ll +++ llvm/trunk/test/tools/gold/X86/thinlto.ll @@ -83,7 +83,8 @@ ; RUN: --plugin-opt=obj-path=%t5.o \ ; RUN: -shared %t.o %t2.o -o %t4 ; RUN: llvm-readobj -h %t5.o | FileCheck %s --check-prefix=FORMAT -; RUN: llvm-nm %t5.o | count 0 +; RUN: llvm-nm %t5.o | FileCheck %s -check-prefix=NO-SYMBOLS +; NO-SYMBOLS: no symbols ; NM: T f ; NM2: T {{f|g}} Index: llvm/trunk/test/tools/llvm-nm/X86/nm-no-symbols.test =================================================================== --- llvm/trunk/test/tools/llvm-nm/X86/nm-no-symbols.test +++ llvm/trunk/test/tools/llvm-nm/X86/nm-no-symbols.test @@ -0,0 +1,14 @@ +# 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 + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + +# CHECK: {{^}}no symbols{{$}} + +# CHECK-PRINT-FILE-NAME: nm-no-symbols.test{{.*}}.o: no symbols{{$}} Index: llvm/trunk/tools/llvm-nm/llvm-nm.cpp =================================================================== --- llvm/trunk/tools/llvm-nm/llvm-nm.cpp +++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp @@ -757,6 +757,24 @@ } } + auto writeFileName = [&]() { + if (!ArchitectureName.empty()) + outs() << "(for architecture " << ArchitectureName << "):"; + if (OutputFormat == posix && !ArchiveName.empty()) + outs() << ArchiveName << "[" << CurrentFilename << "]: "; + else { + if (!ArchiveName.empty()) + outs() << ArchiveName << ":"; + outs() << CurrentFilename << ": "; + } + }; + + if (SymbolList.empty()) { + if (PrintFileName) + writeFileName(); + outs() << "no symbols\n"; + } + for (SymbolListT::iterator I = SymbolList.begin(), E = SymbolList.end(); I != E; ++I) { uint32_t SymFlags; @@ -778,17 +796,8 @@ (!Global && ExternalOnly) || (SizeSort && !PrintAddress) || (Weak && NoWeakSymbols)) continue; - if (PrintFileName) { - if (!ArchitectureName.empty()) - outs() << "(for architecture " << ArchitectureName << "):"; - if (OutputFormat == posix && !ArchiveName.empty()) - outs() << ArchiveName << "[" << CurrentFilename << "]: "; - else { - if (!ArchiveName.empty()) - outs() << ArchiveName << ":"; - outs() << CurrentFilename << ": "; - } - } + if (PrintFileName) + writeFileName(); if ((JustSymbolName || (UndefinedOnly && MachO && OutputFormat != darwin)) && OutputFormat != posix) {