Skip to content

Commit df952cb

Browse files
ElvinaYakubovajh7370
authored andcommitted
[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
1 parent b36a3e6 commit df952cb

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

llvm/docs/CommandGuide/llvm-readelf.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DESCRIPTION
1414
The :program:`llvm-readelf` tool displays low-level format-specific information
1515
about one or more object files.
1616

17-
If ``input`` is "``-``" or omitted, :program:`llvm-readelf` reads from standard
17+
If ``input`` is "``-``", :program:`llvm-readelf` reads from standard
1818
input. Otherwise, it will read from the specified ``filenames``.
1919

2020
OPTIONS

llvm/docs/CommandGuide/llvm-readobj.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DESCRIPTION
1414
The :program:`llvm-readobj` tool displays low-level format-specific information
1515
about one or more object files.
1616

17-
If ``input`` is "``-``" or omitted, :program:`llvm-readobj` reads from standard
17+
If ``input`` is "``-``", :program:`llvm-readobj` reads from standard
1818
input. Otherwise, it will read from the specified ``filenames``.
1919

2020
DIFFERENCES TO LLVM-READELF

llvm/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ During this release ...
123123
Changes to the LLVM tools
124124
---------------------------------
125125

126-
During this release ...
126+
* llvm-readobj and llvm-readelf behavior has changed to report an error when
127+
executed with no input files instead of reading an input from stdin.
128+
Reading from stdin can still be achieved by specifying `-` as an input file.
127129

128130
Changes to LLDB
129131
---------------------------------

llvm/test/tools/llvm-readobj/basic.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ RUN: not llvm-readelf %t.blah 2>&1 | FileCheck --check-prefix=ENOENT -DTOOL=read
44

55
ENOENT: llvm-[[TOOL]]{{(\.exe)?}}: error: '{{.*}}.blah': {{[Nn]}}o such file or directory
66

7+
# Test case with no input file.
8+
RUN: not llvm-readobj 2>&1 | FileCheck %s --check-prefix=NO-FILE
9+
RUN: not llvm-readelf 2>&1 | FileCheck %s --check-prefix=NO-FILE
10+
NO-FILE: error: no input files specified
11+
712
# Test case where input file is too small to be a recognised object file.
813
RUN: touch %t.empty
914
RUN: not llvm-readobj %t.empty 2>&1 | FileCheck --check-prefix=EMPTY %s

llvm/tools/llvm-readobj/llvm-readobj.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,11 @@ int main(int argc, const char *argv[]) {
690690

691691
cl::ParseCommandLineOptions(argc, argv, "LLVM Object Reader\n");
692692

693+
// Default to print error if no filename is specified.
694+
if (opts::InputFilenames.empty()) {
695+
error("no input files specified");
696+
}
697+
693698
if (opts::All) {
694699
opts::FileHeaders = true;
695700
opts::ProgramHeaders = true;
@@ -714,10 +719,6 @@ int main(int argc, const char *argv[]) {
714719
opts::SectionHeaders = true;
715720
}
716721

717-
// Default to stdin if no filename is specified.
718-
if (opts::InputFilenames.empty())
719-
opts::InputFilenames.push_back("-");
720-
721722
ScopedPrinter Writer(fouts());
722723
for (const std::string &I : opts::InputFilenames)
723724
dumpInput(I, Writer);

0 commit comments

Comments
 (0)