[llvm] 64240f8 - llvm-nm: add flag to suppress no symbols warning

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 7 16:20:46 PST 2021


Author: Keith Smiley
Date: 2021-03-07T16:20:13-08:00
New Revision: 64240f8138f55cbc1d0451d776f481762f7db0ab

URL: https://github.com/llvm/llvm-project/commit/64240f8138f55cbc1d0451d776f481762f7db0ab
DIFF: https://github.com/llvm/llvm-project/commit/64240f8138f55cbc1d0451d776f481762f7db0ab.diff

LOG: llvm-nm: add flag to suppress no symbols warning

This spelling matches binutils https://sourceware.org/bugzilla/show_bug.cgi?id=27408

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

Added: 
    

Modified: 
    llvm/docs/CommandGuide/llvm-nm.rst
    llvm/test/tools/llvm-nm/X86/nm-no-symbols.test
    llvm/tools/llvm-nm/llvm-nm.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-nm.rst b/llvm/docs/CommandGuide/llvm-nm.rst
index 607c871ff7a1..747192a9d924 100644
--- a/llvm/docs/CommandGuide/llvm-nm.rst
+++ b/llvm/docs/CommandGuide/llvm-nm.rst
@@ -204,6 +204,10 @@ OPTIONS
 
  Show symbol size as well as address (not applicable for Mach-O).
 
+.. option:: --quiet
+
+ Suppress 'no symbols' diagnostic.
+
 .. option:: --radix=<RADIX>, -t
 
  Specify the radix of the symbol address(es). Values accepted are *d* (decimal),

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 83bc0a00699b..e8c3b74e180d 100644
--- 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,5 @@ FileHeader:
   Machine:         EM_X86_64
 
 # CHECK: [[FILE]]: no symbols{{$}}
+
+# RUN: llvm-nm --quiet %t.o 2>&1 | count 0

diff  --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index bf5a43107a25..b978eafcbda7 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -117,6 +117,9 @@ cl::alias PrintFileNameA("A", cl::desc("Alias for --print-file-name"),
 cl::alias PrintFileNameo("o", cl::desc("Alias for --print-file-name"),
                          cl::aliasopt(PrintFileName), cl::Grouping);
 
+cl::opt<bool> Quiet("quiet", cl::desc("Suppress 'no symbols' diagnostic"),
+                    cl::cat(NMCat));
+
 cl::opt<bool> DebugSyms("debug-syms",
                         cl::desc("Show all symbols, even debugger only"),
                         cl::cat(NMCat));
@@ -1861,7 +1864,7 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
 
   CurrentFilename = Obj.getFileName();
 
-  if (Symbols.empty() && SymbolList.empty()) {
+  if (Symbols.empty() && SymbolList.empty() && !Quiet) {
     writeFileName(errs(), ArchiveName, ArchitectureName);
     errs() << "no symbols\n";
   }


        


More information about the llvm-commits mailing list