Skip to content

Commit c2b28f8

Browse files
MaskRaychencha3
authored andcommitted
[llvm-readelf] Print a blank line for the first hex/string dump
GNU readelf prints a blank line before the first hex/string dump, which serves as a separator when there are other dump operations. Port the behavior. Pull Request: llvm#85744
1 parent 78d7683 commit c2b28f8

File tree

10 files changed

+26
-21
lines changed

10 files changed

+26
-21
lines changed

lld/test/ELF/aarch64-tlsdesc-zrel.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// RELA-NEXT: 0x[[#ADDR+16]] R_AARCH64_TLSDESC - 0x4
1414
// RELA-NEXT: }
1515
// RELA-NEXT: ]
16+
// RELA-EMPTY:
1617
// RELA-NEXT: Hex dump of section '.got':
1718
// RELA-NEXT: 0x000[[#ADDR]] 00000000 00000000 00000000 00000000
1819
// RELA-NO-ADDENDS-NEXT: 0x000[[#ADDR+16]] 00000000 00000000 00000000 00000000

lld/test/ELF/pack-dyn-relocs.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@
353353
// RELR64-NEXT: 0000000000030550 0000000000000403 R_AARCH64_RELATIVE
354354
// RELR64-NEXT: 0000000000030558 0000000000000403 R_AARCH64_RELATIVE
355355
// RELR64-NEXT: 0000000000030560 0000000000000403 R_AARCH64_RELATIVE
356+
// RELR64-EMPTY:
356357
// RELR64-NEXT: Hex dump of section '.data':
357358
// RELR64-NEXT: 0x00030490 00000000 00000000 01000000 00000000 .
358359
// RELR64-NEXT: 0x000304a0 02000000 00000000 ffffffff ffffffff .

llvm/test/tools/llvm-readobj/ELF/decompress-zlib-unsupported.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# CHECK-NEXT: [ 18] x.c.
1111
# CHECK-NEXT: [ 1e] .
1212
# CHECK-NEXT: [ 20] .
13+
# CHECK-EMPTY:
1314
# CHECK-NEXT: Hex dump of section '.b':
1415
# CHECK-NEXT: warning: '[[FILE]]': LLVM was not built with LLVM_ENABLE_ZLIB or did not find zlib at build time
1516
# CHECK-NEXT: 0x00000000 01000000 00000000 01000000 00000000 ................

llvm/test/tools/llvm-readobj/ELF/decompress-zlib.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# COMPRESSED: String dump of section '.not_null_terminated':
2929
# COMPRESSED-NEXT: [ 0] no
3030
# COMPRESSED-NEXT: [ 3] null
31+
# COMPRESSED-EMPTY:
3132
# COMPRESSED-NEXT: Hex dump of section '.strings':
3233
# COMPRESSED-NEXT: 0x00000000 01000000 00000000 16000000 00000000 ................
3334
# COMPRESSED-NEXT: 0x00000010 00000000 00000000 789ccb48 2d4a6548 ........x..H-JeH
@@ -39,6 +40,7 @@
3940
# INVALID: String dump of section '.invalid1':
4041
# INVALID-NEXT: warning: '[[FILE]]': corrupted compressed section header
4142
# INVALID-NEXT: [ 0] .
43+
# INVALID-EMPTY:
4244
# INVALID-NEXT: Hex dump of section '.invalid2':
4345
# INVALID-NEXT: warning: '[[FILE]]': zlib error: Z_DATA_ERROR
4446
# INVALID-NEXT: 0x00000000 01000000 00000000 16000000 00000000 ................

llvm/test/tools/llvm-readobj/ELF/decompress-zstd-unsupported.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# CHECK-NEXT: [ 10] .
1010
# CHECK-NEXT: [ 18] (./. ..
1111
# CHECK-NEXT: [ 21] .
12+
# CHECK-EMPTY:
1213
# CHECK-NEXT: Hex dump of section '.b':
1314
# CHECK-NEXT: warning: '[[FILE]]': LLVM was not built with LLVM_ENABLE_ZSTD or did not find zstd at build time
1415
# CHECK-NEXT: 0x00000000 02000000 00000000 01000000 00000000 ................

llvm/test/tools/llvm-readobj/ELF/hex-dump-multi.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# REQUIRES: x86-registered-target
22

33
# RUN: llvm-mc -filetype=obj -triple x86_64 %s -o %t.o
4-
# RUN: llvm-readobj -x .a -x .b %t.o | FileCheck %s
4+
# RUN: llvm-readobj -x .a -x .b %t.o | FileCheck %s --check-prefixes=HEADER,CHECK
55
# RUN: llvm-readelf -x .a -x .b %t.o | FileCheck %s
66

7-
# CHECK: Hex dump of section '.a':
7+
# HEADER: LoadName:
8+
# CHECK: {{^$}}
9+
# CHECK-NEXT: Hex dump of section '.a':
810
# CHECK-NEXT: 0x00000000 00
911
# CHECK-EMPTY:
1012
# CHECK-NEXT: Hex dump of section '.b':

llvm/test/tools/llvm-readobj/ELF/hex-dump.test

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ FileHeader:
4646
# RUN: llvm-readelf --hex-dump=.sec %t2.out1 | \
4747
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SPACES1
4848

49-
# SPACES1:Hex dump of section '.sec':
49+
# SPACES1:{{^$}}
50+
# SPACES1-NEXT:Hex dump of section '.sec':
5051
# SPACES1-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
5152
# SPACES1-NEXT:0x00000010 0000 ..
5253

@@ -55,7 +56,8 @@ FileHeader:
5556
# RUN: llvm-readelf --hex-dump=.sec %t2.out2 | \
5657
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SPACES2
5758

58-
# SPACES2:Hex dump of section '.sec':
59+
# SPACES2:{{^$}}
60+
# SPACES2-NEXT:Hex dump of section '.sec':
5961
# SPACES2-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
6062
# SPACES2-NEXT:0x00000010 00000000 00000000 00000000 0000 ..............
6163

@@ -64,7 +66,8 @@ FileHeader:
6466
# RUN: llvm-readelf --hex-dump=.sec %t2.out3 | \
6567
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SPACES3
6668

67-
# SPACES3:Hex dump of section '.sec':
69+
# SPACES3:{{^$}}
70+
# SPACES3-NEXT:Hex dump of section '.sec':
6871
# SPACES3-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
6972
# SPACES3-NEXT:0x00000010 00000000 00000000 00000000 ............
7073

llvm/test/tools/llvm-readobj/ELF/string-dump-multi.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# REQUIRES: x86-registered-target
22

33
# RUN: llvm-mc -filetype=obj -triple x86_64 %s -o %t.o
4-
# RUN: llvm-readobj -p .a -p .b %t.o | FileCheck %s
4+
# RUN: llvm-readobj -p .a -p .b %t.o | FileCheck %s --check-prefixes=HEADER,CHECK
55
# RUN: llvm-readelf -p .a -p .b %t.o | FileCheck %s
66

7-
# CHECK: String dump of section '.a':
7+
# HEADER: LoadName:
8+
# CHECK: {{^$}}
9+
# CHECK-NEXT: String dump of section '.a':
810
# CHECK-NEXT: [ 0] 0
911
# CHECK-EMPTY:
1012
# CHECK-NEXT: String dump of section '.b':

llvm/test/tools/llvm-readobj/ELF/string-dump.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# RUN: llvm-readobj --string-dump=.strings \
55
# RUN: --string-dump=.not_null_terminated %t > %t.readobj.out
6-
# RUN: FileCheck %s --input-file=%t.readobj.out
6+
# RUN: FileCheck %s --input-file=%t.readobj.out --check-prefixes=HEADER,CHECK
77

88
# Also test the different ways --string-dump can be specified, i.e. as a short
99
# flag (-p), with different prefix modes (-p .foo, -p=.foo, -p.foo), and with
@@ -23,7 +23,9 @@
2323
# RUN: llvm-readelf -hp1 -p2 %t | cmp %t.readelf.out -
2424
# RUN: llvm-readelf -hp 1 -p.not_null_terminated %t | cmp %t.readelf.out -
2525

26-
# CHECK: String dump of section '.strings':
26+
# HEADER: LoadName:
27+
# CHECK: {{^$}}
28+
# CHECK-NEXT: String dump of section '.strings':
2729
# CHECK-NEXT: [ 0] here
2830
# CHECK-NEXT: [ 5] are
2931
# CHECK-NEXT: [ 9] some

llvm/tools/llvm-readobj/ObjDumper.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,10 @@ void ObjDumper::printSectionsAsString(const object::ObjectFile &Obj,
160160
ArrayRef<std::string> Sections,
161161
bool Decompress) {
162162
SmallString<0> Out;
163-
bool First = true;
164163
for (object::SectionRef Section :
165164
getSectionRefsByNameOrIndex(Obj, Sections)) {
166165
StringRef SectionName = unwrapOrError(Obj.getFileName(), Section.getName());
167-
168-
if (!First)
169-
W.startLine() << '\n';
170-
First = false;
171-
W.startLine() << "String dump of section '" << SectionName << "':\n";
166+
W.startLine() << "\nString dump of section '" << SectionName << "':\n";
172167

173168
StringRef SectionContent =
174169
unwrapOrError(Obj.getFileName(), Section.getContents());
@@ -182,15 +177,10 @@ void ObjDumper::printSectionsAsHex(const object::ObjectFile &Obj,
182177
ArrayRef<std::string> Sections,
183178
bool Decompress) {
184179
SmallString<0> Out;
185-
bool First = true;
186180
for (object::SectionRef Section :
187181
getSectionRefsByNameOrIndex(Obj, Sections)) {
188182
StringRef SectionName = unwrapOrError(Obj.getFileName(), Section.getName());
189-
190-
if (!First)
191-
W.startLine() << '\n';
192-
First = false;
193-
W.startLine() << "Hex dump of section '" << SectionName << "':\n";
183+
W.startLine() << "\nHex dump of section '" << SectionName << "':\n";
194184

195185
StringRef SectionContent =
196186
unwrapOrError(Obj.getFileName(), Section.getContents());

0 commit comments

Comments
 (0)