[llvm] b42fb68 - [llvm-nm] Support the -V option, print that the tool is compatible with GNU nm

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu May 13 12:36:46 PDT 2021


Author: Martin Storsjö
Date: 2021-05-13T22:36:25+03:00
New Revision: b42fb6811e25322f7e55d3f76fe13a6829202219

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

LOG: [llvm-nm] Support the -V option, print that the tool is compatible with GNU nm

This unlocks some codepaths in libtool.

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

Added: 
    llvm/test/tools/llvm-nm/libtool-version.test

Modified: 
    llvm/docs/CommandGuide/llvm-nm.rst
    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 20779b17fdde..cdb1fd3c2492 100644
--- a/llvm/docs/CommandGuide/llvm-nm.rst
+++ b/llvm/docs/CommandGuide/llvm-nm.rst
@@ -230,10 +230,10 @@ OPTIONS
 
  Print only undefined symbols.
 
-.. option:: --version
+.. option:: --version, -V
 
- Display the version of the :program:`llvm-nm` executable. Does not stack with
- other commands.
+ Display the version of the :program:`llvm-nm` executable, then exit. Does not
+ stack with other commands.
 
 .. option:: --without-aliases
 

diff  --git a/llvm/test/tools/llvm-nm/libtool-version.test b/llvm/test/tools/llvm-nm/libtool-version.test
new file mode 100644
index 000000000000..ee53d0be39f3
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/libtool-version.test
@@ -0,0 +1,8 @@
+# Check that the output of llvm-nm -V (and --version) contains the text
+# "GNU" somewhere, to let libtool know that it is compatible with GNU nm.
+# Also check that it contains the LLVM version.
+
+RUN: llvm-nm -V | FileCheck %s
+RUN: llvm-nm --version | FileCheck %s
+CHECK: LLVM version
+CHECK: GNU

diff  --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 3f52a2204c42..e21f18a37149 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -229,6 +229,8 @@ cl::opt<bool> AddInlinedInfo("add-inlinedinfo",
                                       "TBD(Mach-O) only"),
                              cl::cat(NMCat));
 
+cl::opt<bool> Version("V", cl::desc("Print version info"), cl::cat(NMCat));
+
 cl::extrahelp HelpResponse("\nPass @FILE as argument to read options from FILE.\n");
 
 bool PrintAddress = true;
@@ -2235,11 +2237,23 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
   }
 }
 
+static void printExtraVersionInfo(raw_ostream &Outs) {
+  // This needs to contain the word "GNU", libtool looks for that string.
+  Outs << "llvm-nm, compatible with GNU nm\n";
+}
+
 int main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   cl::HideUnrelatedOptions(NMCat);
+  cl::AddExtraVersionPrinter(printExtraVersionInfo);
   cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
 
+  if (Version) {
+    cl::PrintVersionMessage();
+    printExtraVersionInfo(outs());
+    return 0;
+  }
+
   // llvm-nm only reads binary files.
   if (error(sys::ChangeStdinToBinary()))
     return 1;


        


More information about the llvm-commits mailing list