diff --git a/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test b/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test --- a/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test +++ b/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test @@ -9,3 +9,6 @@ Machine: EM_X86_64 # CHECK: [[FILE]]: no symbols{{$}} + +# RUN: llvm-nm -no-warning-for-no-symbols %t.o 2>&1 | FileCheck %s -DFILE=%t.o --check-prefix NO-WARNING --allow-empty +# NO-WARNING-NOT: no symbols diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -153,6 +153,11 @@ cl::aliasopt(PrintSize), cl::Grouping); bool MachOPrintSizeWarning = false; +cl::opt NoWarningForNoSymbols( + "no-warning-for-no-symbols", + cl::desc("Don't print a warning when an object doesn't contain symbols"), + cl::cat(NMCat)); + cl::opt SizeSort("size-sort", cl::desc("Sort symbols by size"), cl::cat(NMCat)); @@ -1749,7 +1754,7 @@ CurrentFilename = Obj.getFileName(); - if (Symbols.empty() && SymbolList.empty()) { + if (Symbols.empty() && SymbolList.empty() && !NoWarningForNoSymbols) { writeFileName(errs(), ArchiveName, ArchitectureName); errs() << "no symbols\n"; }