[llvm] r368435 - [llvm-readelf]Print filename for multiple inputs and fix formatting regression
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 05:30:08 PDT 2019
Author: jhenderson
Date: Fri Aug 9 05:30:08 2019
New Revision: 368435
URL: http://llvm.org/viewvc/llvm-project?rev=368435&view=rev
Log:
[llvm-readelf]Print filename for multiple inputs and fix formatting regression
This patch addresses two closely related bugs:
https://bugs.llvm.org/show_bug.cgi?id=42930 and
https://bugs.llvm.org/show_bug.cgi?id=42931.
GNU readelf prints the file name for every input unless there is only
one input and that input is not an archive. This patch adds the printing
for multiple inputs. A previous change did it for archives, but
introduced a regression with GNU compatibility for single-output
formatting, resulting in a spurious initial blank line. This is fixed in
this patch too.
Reviewed by: grimar, MaskRay
Differential Revision: https://reviews.llvm.org/D65953
Added:
llvm/trunk/test/tools/llvm-readobj/file-name.test
Modified:
llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test
llvm/trunk/test/tools/llvm-readobj/stack-sizes.test
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
Modified: llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test?rev=368435&r1=368434&r2=368435&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test Fri Aug 9 05:30:08 2019
@@ -20,7 +20,6 @@
# WARN-GNU-NOT: warning
# WARN-GNU: warning: invalid section size (4) or entity size (16)
-# WARN-GNU-EMPTY:
# WARN-GNU-NEXT: ELF Header:
# WARN-GNU: Symbol table '.symtab' contains 1 entries:
# WARN-GNU: 0:
Added: llvm/trunk/test/tools/llvm-readobj/file-name.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/file-name.test?rev=368435&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/file-name.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/file-name.test Fri Aug 9 05:30:08 2019
@@ -0,0 +1,42 @@
+## This test shows that the name of the file is printed under the right
+## circumstances and with the correct formatting for object inputs.
+
+# RUN: yaml2obj %s -o %t1
+# RUN: cp %t1 %t2
+
+## Show that the file name is not printed for a single input for GNU output.
+# RUN: llvm-readelf --file-headers %t1 \
+# RUN: | FileCheck %s --implicit-check-not=File: --check-prefix=GNU-SINGLE
+
+## Show that the very first line of the output is the one with "ELF Header" on.
+# GNU-SINGLE: {{^}}
+# GNU-SINGLE-SAME: ELF Header:
+
+## Show that the file names are printed for all inputs for GNU output.
+# RUN: llvm-readelf --file-headers %t1 %t2 \
+# RUN: | FileCheck %s --check-prefixes=NAME1,GNU,NAME2 -DFILE1=%t1 -DFILE2=%t2
+
+## Show that the file name is printed for a single input for LLVM output.
+# RUN: llvm-readobj --file-headers %t1 | FileCheck %s --check-prefix=NAME1 -DFILE1=%t1
+
+## Show that the file name is printed with correct spacing for multiple inputs
+## with LLVM output.
+# RUN: llvm-readobj --file-headers %t1 %t2 \
+# RUN: | FileCheck %s --check-prefixes=NAME1,LLVM,NAME2 -DFILE1=%t1 -DFILE2=%t2
+
+## The very first line should be blank. CHECK-EMPTY isn't allowed on the first line.
+# NAME1: {{^$}}
+# NAME1-NEXT: {{^}}File: [[FILE1]]{{$}}
+
+# GNU: Section header string table index:
+# LLVM: StringTableSectionIndex:
+# LLVM-NEXT: }
+# NAME2-EMPTY:
+# NAME2-NEXT: {{^}}File: [[FILE2]]{{$}}
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
Modified: llvm/trunk/test/tools/llvm-readobj/stack-sizes.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/stack-sizes.test?rev=368435&r1=368434&r2=368435&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/stack-sizes.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/stack-sizes.test Fri Aug 9 05:30:08 2019
@@ -322,11 +322,13 @@ Sections:
## tables.
# RUN: llvm-ar rc %t1.a %t01 %t02
-# RUN: llvm-readelf --stack-sizes %t01 %t02 | FileCheck %s --check-prefix=MULTIPLE
+# RUN: llvm-readelf --stack-sizes %t01 %t02 \
+# RUN: | FileCheck %s --check-prefixes=MULTIPLE,OBJECT -DFILE1=%t01 -DFILE2=%t02
# RUN: llvm-readelf --stack-sizes %t1.a \
-# RUN: | FileCheck %s --check-prefix=MULTIPLE --check-prefix=ARCHIVE --strict-whitespace\
+# RUN: | FileCheck %s --check-prefixes=MULTIPLE,ARCHIVE --strict-whitespace\
# RUN: --match-full-lines -DFILE=%t1.a
+# OBJECT:File: [[FILE1]]
# ARCHIVE:File: [[FILE]]({{.*01}})
# MULTIPLE:Stack Sizes:
# MULTIPLE-NEXT: Size Function
@@ -334,6 +336,7 @@ Sections:
# MULTIPLE-NEXT: 32 referenced_via_section_bar
# MULTIPLE-NEXT: 8 separate_text_section_baz
# MULTIPLE-EMPTY:
+# OBJECT:File: [[FILE2]]
# ARCHIVE:File: [[FILE]]({{.*02}})
# MULTIPLE-EMPTY:
# MULTIPLE-NEXT:Stack Sizes:
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=368435&r1=368434&r2=368435&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Fri Aug 9 05:30:08 2019
@@ -484,17 +484,17 @@ static void dumpObject(const ObjectFile
if (std::error_code EC = createDumper(Obj, Writer, Dumper))
reportError(FileStr, EC);
- Writer.startLine() << "\n";
- if (opts::Output == opts::LLVM) {
+ if (opts::Output == opts::LLVM || opts::InputFilenames.size() > 1 || A) {
+ Writer.startLine() << "\n";
Writer.printString("File", FileStr);
+ }
+ if (opts::Output == opts::LLVM) {
Writer.printString("Format", Obj->getFileFormatName());
Writer.printString("Arch", Triple::getArchTypeName(
(llvm::Triple::ArchType)Obj->getArch()));
Writer.printString("AddressSize",
formatv("{0}bit", 8 * Obj->getBytesInAddress()));
Dumper->printLoadName();
- } else if (opts::Output == opts::GNU && A) {
- Writer.printString("File", FileStr);
}
if (opts::FileHeaders)
More information about the llvm-commits
mailing list