Make llvm-nm return 1 on error.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 3 Jul 2013 15:46:03 +0000 (15:46 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 3 Jul 2013 15:46:03 +0000 (15:46 +0000)
This is a small compatibility improvement with gnu nm and makes llvm-nm more
useful as a testing tool.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185546 91177308-0d34-0410-b5e6-96231b3b80d8

test/Object/nm-error.test [new file with mode: 0644]
tools/llvm-nm/llvm-nm.cpp

diff --git a/test/Object/nm-error.test b/test/Object/nm-error.test
new file mode 100644 (file)
index 0000000..146b887
--- /dev/null
@@ -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
index cb465207631456fa7f78f5de7c46ca31e9d9d3c2..c33289bd875c76727b131cf3f8beb730c92253d9 100644 (file)
@@ -121,6 +121,8 @@ namespace {
 
   bool MultipleFiles = false;
 
+  bool HadError = false;
+
   std::string ToolName;
 }
 
@@ -132,6 +134,7 @@ static void error(Twine message, Twine path = Twine()) {
 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::string &Filename) {
   } 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;
 }