[llvm] df952cb - [llvm-readobj] Print error when executed with no input files

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 20 02:40:49 PDT 2020


Author: Elvina Yakubova
Date: 2020-07-20T10:39:05+01:00
New Revision: df952cb914eae5264603bd9fadffcc7626355c51

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

LOG: [llvm-readobj] Print error when executed with no input files

This patch changes llvm-readelf (and llvm-readobj for consistency)
behavior to print an error when executed with no input files.

Reading from stdin can be achieved via a '-' for the input
object.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46400

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

Reviewed by: jhenderson, MaskRay, sbc, jyknight

Added: 
    

Modified: 
    llvm/docs/CommandGuide/llvm-readelf.rst
    llvm/docs/CommandGuide/llvm-readobj.rst
    llvm/docs/ReleaseNotes.rst
    llvm/test/tools/llvm-readobj/basic.test
    llvm/tools/llvm-readobj/llvm-readobj.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/llvm-readelf.rst b/llvm/docs/CommandGuide/llvm-readelf.rst
index f74f02c9a667..fa54c1dc84dc 100644
--- a/llvm/docs/CommandGuide/llvm-readelf.rst
+++ b/llvm/docs/CommandGuide/llvm-readelf.rst
@@ -14,7 +14,7 @@ DESCRIPTION
 The :program:`llvm-readelf` tool displays low-level format-specific information
 about one or more object files.
 
-If ``input`` is "``-``" or omitted, :program:`llvm-readelf` reads from standard
+If ``input`` is "``-``", :program:`llvm-readelf` reads from standard
 input. Otherwise, it will read from the specified ``filenames``.
 
 OPTIONS

diff  --git a/llvm/docs/CommandGuide/llvm-readobj.rst b/llvm/docs/CommandGuide/llvm-readobj.rst
index 51cd266ff79e..9b1b5ba92bc0 100644
--- a/llvm/docs/CommandGuide/llvm-readobj.rst
+++ b/llvm/docs/CommandGuide/llvm-readobj.rst
@@ -14,7 +14,7 @@ DESCRIPTION
 The :program:`llvm-readobj` tool displays low-level format-specific information
 about one or more object files.
 
-If ``input`` is "``-``" or omitted, :program:`llvm-readobj` reads from standard
+If ``input`` is "``-``", :program:`llvm-readobj` reads from standard
 input. Otherwise, it will read from the specified ``filenames``.
 
 DIFFERENCES TO LLVM-READELF

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index e234965aaa7c..6293c82e3538 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -123,7 +123,9 @@ During this release ...
 Changes to the LLVM tools
 ---------------------------------
 
-During this release ...
+* llvm-readobj and llvm-readelf behavior has changed to report an error when
+  executed with no input files instead of reading an input from stdin.
+  Reading from stdin can still be achieved by specifying `-` as an input file.
 
 Changes to LLDB
 ---------------------------------

diff  --git a/llvm/test/tools/llvm-readobj/basic.test b/llvm/test/tools/llvm-readobj/basic.test
index 89962c3231be..5b317951493b 100644
--- a/llvm/test/tools/llvm-readobj/basic.test
+++ b/llvm/test/tools/llvm-readobj/basic.test
@@ -4,6 +4,11 @@ RUN: not llvm-readelf %t.blah 2>&1 | FileCheck --check-prefix=ENOENT -DTOOL=read
 
 ENOENT: llvm-[[TOOL]]{{(\.exe)?}}: error: '{{.*}}.blah': {{[Nn]}}o such file or directory
 
+# Test case with no input file.
+RUN: not llvm-readobj 2>&1 | FileCheck %s --check-prefix=NO-FILE
+RUN: not llvm-readelf 2>&1  | FileCheck %s --check-prefix=NO-FILE
+NO-FILE: error: no input files specified
+
 # Test case where input file is too small to be a recognised object file.
 RUN: touch %t.empty
 RUN: not llvm-readobj %t.empty 2>&1 | FileCheck --check-prefix=EMPTY %s

diff  --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp
index b9c6ad2256ae..6b8a883af01d 100644
--- a/llvm/tools/llvm-readobj/llvm-readobj.cpp
+++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp
@@ -690,6 +690,11 @@ int main(int argc, const char *argv[]) {
 
   cl::ParseCommandLineOptions(argc, argv, "LLVM Object Reader\n");
 
+  // Default to print error if no filename is specified.
+  if (opts::InputFilenames.empty()) {
+    error("no input files specified");
+  }
+
   if (opts::All) {
     opts::FileHeaders = true;
     opts::ProgramHeaders = true;
@@ -714,10 +719,6 @@ int main(int argc, const char *argv[]) {
     opts::SectionHeaders = true;
   }
 
-  // Default to stdin if no filename is specified.
-  if (opts::InputFilenames.empty())
-    opts::InputFilenames.push_back("-");
-
   ScopedPrinter Writer(fouts());
   for (const std::string &I : opts::InputFilenames)
     dumpInput(I, Writer);


        


More information about the llvm-commits mailing list