llvm-nm: add flag to suppress no symbols warning
authorKeith Smiley <keithbsmiley@gmail.com>
Tue, 9 Feb 2021 16:35:25 +0000 (08:35 -0800)
committerKeith Smiley <keithbsmiley@gmail.com>
Mon, 8 Mar 2021 00:20:13 +0000 (16:20 -0800)
This spelling matches binutils https://sourceware.org/bugzilla/show_bug.cgi?id=27408

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

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

index 607c871..747192a 100644 (file)
@@ -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),
index 83bc0a0..e8c3b74 100644 (file)
@@ -9,3 +9,5 @@ FileHeader:
   Machine:         EM_X86_64
 
 # CHECK: [[FILE]]: no symbols{{$}}
+
+# RUN: llvm-nm --quiet %t.o 2>&1 | count 0
index bf5a431..b978eaf 100644 (file)
@@ -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";
   }