[llvm] r185546 - Make llvm-nm return 1 on error.

Rafael Espindola rafael.espindola at gmail.com
Wed Jul 3 08:46:04 PDT 2013


Author: rafael
Date: Wed Jul  3 10:46:03 2013
New Revision: 185546

URL: http://llvm.org/viewvc/llvm-project?rev=185546&view=rev
Log:
Make llvm-nm return 1 on error.

This is a small compatibility improvement with gnu nm and makes llvm-nm more
useful as a testing tool.

Added:
    llvm/trunk/test/Object/nm-error.test
Modified:
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp

Added: llvm/trunk/test/Object/nm-error.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/nm-error.test?rev=185546&view=auto
==============================================================================
--- llvm/trunk/test/Object/nm-error.test (added)
+++ llvm/trunk/test/Object/nm-error.test Wed Jul  3 10:46:03 2013
@@ -0,0 +1,17 @@
+Test that llvm-nm returns an error because of the unknown file type, but
+keeps processing subsequent files.
+
+Note: We use a temporary file since the tests don't run with pipefail.
+
+RUN: touch %t
+RUN: not llvm-nm %p/Inputs/trivial-object-test.elf-i386 %t \
+RUN:             %p/Inputs/trivial-object-test.elf-i386 > %t.log
+RUN: FileCheck %s < %t.log
+
+CHECK:          U SomeOtherFunction
+CHECK: 00000000 T main
+CHECK:          U puts
+
+CHECK:          U SomeOtherFunction
+CHECK: 00000000 T main
+CHECK:          U puts

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=185546&r1=185545&r2=185546&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Jul  3 10:46:03 2013
@@ -121,6 +121,8 @@ namespace {
 
   bool MultipleFiles = false;
 
+  bool HadError = false;
+
   std::string ToolName;
 }
 
@@ -132,6 +134,7 @@ static void error(Twine message, Twine p
 static bool error(error_code ec, Twine path = Twine()) {
   if (ec) {
     error(ec.message(), path);
+    HadError = true;
     return true;
   }
   return false;
@@ -429,6 +432,7 @@ static void DumpSymbolNamesFromFile(std:
   } else {
     errs() << ToolName << ": " << Filename << ": "
            << "unrecognizable file type\n";
+    HadError = true;
     return;
   }
 }
@@ -463,5 +467,9 @@ int main(int argc, char **argv) {
 
   std::for_each(InputFilenames.begin(), InputFilenames.end(),
                 DumpSymbolNamesFromFile);
+
+  if (HadError)
+    return 1;
+
   return 0;
 }





More information about the llvm-commits mailing list