Skip to content

[llvm-readelf] Print a blank line for the first hex/string dump #85744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lld/test/ELF/aarch64-tlsdesc-zrel.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// RELA-NEXT: 0x[[#ADDR+16]] R_AARCH64_TLSDESC - 0x4
// RELA-NEXT: }
// RELA-NEXT: ]
// RELA-EMPTY:
// RELA-NEXT: Hex dump of section '.got':
// RELA-NEXT: 0x000[[#ADDR]] 00000000 00000000 00000000 00000000
// RELA-NO-ADDENDS-NEXT: 0x000[[#ADDR+16]] 00000000 00000000 00000000 00000000
Expand Down
1 change: 1 addition & 0 deletions lld/test/ELF/pack-dyn-relocs.s
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@
// RELR64-NEXT: 0000000000030550 0000000000000403 R_AARCH64_RELATIVE
// RELR64-NEXT: 0000000000030558 0000000000000403 R_AARCH64_RELATIVE
// RELR64-NEXT: 0000000000030560 0000000000000403 R_AARCH64_RELATIVE
// RELR64-EMPTY:
// RELR64-NEXT: Hex dump of section '.data':
// RELR64-NEXT: 0x00030490 00000000 00000000 01000000 00000000 .
// RELR64-NEXT: 0x000304a0 02000000 00000000 ffffffff ffffffff .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# CHECK-NEXT: [ 18] x.c.
# CHECK-NEXT: [ 1e] .
# CHECK-NEXT: [ 20] .
# CHECK-EMPTY:
# CHECK-NEXT: Hex dump of section '.b':
# CHECK-NEXT: warning: '[[FILE]]': LLVM was not built with LLVM_ENABLE_ZLIB or did not find zlib at build time
# CHECK-NEXT: 0x00000000 01000000 00000000 01000000 00000000 ................
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/tools/llvm-readobj/ELF/decompress-zlib.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# COMPRESSED: String dump of section '.not_null_terminated':
# COMPRESSED-NEXT: [ 0] no
# COMPRESSED-NEXT: [ 3] null
# COMPRESSED-EMPTY:
# COMPRESSED-NEXT: Hex dump of section '.strings':
# COMPRESSED-NEXT: 0x00000000 01000000 00000000 16000000 00000000 ................
# COMPRESSED-NEXT: 0x00000010 00000000 00000000 789ccb48 2d4a6548 ........x..H-JeH
Expand All @@ -39,6 +40,7 @@
# INVALID: String dump of section '.invalid1':
# INVALID-NEXT: warning: '[[FILE]]': corrupted compressed section header
# INVALID-NEXT: [ 0] .
# INVALID-EMPTY:
# INVALID-NEXT: Hex dump of section '.invalid2':
# INVALID-NEXT: warning: '[[FILE]]': zlib error: Z_DATA_ERROR
# INVALID-NEXT: 0x00000000 01000000 00000000 16000000 00000000 ................
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# CHECK-NEXT: [ 10] .
# CHECK-NEXT: [ 18] (./. ..
# CHECK-NEXT: [ 21] .
# CHECK-EMPTY:
# CHECK-NEXT: Hex dump of section '.b':
# CHECK-NEXT: warning: '[[FILE]]': LLVM was not built with LLVM_ENABLE_ZSTD or did not find zstd at build time
# CHECK-NEXT: 0x00000000 02000000 00000000 01000000 00000000 ................
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/tools/llvm-readobj/ELF/hex-dump-multi.s
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# REQUIRES: x86-registered-target

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

# CHECK: Hex dump of section '.a':
# HEADER: LoadName:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the HEADER check here actually important to the test? It feels to me like you could do the same as in hex-dump.s and just check the blank line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llvm-readobj -x .a -x .b prints two blank lines before the first Hex dump of section.
We have to test LoadName: to skip the first blank line (not due to hex/string dump).

# CHECK: {{^$}}
# CHECK-NEXT: Hex dump of section '.a':
# CHECK-NEXT: 0x00000000 00
# CHECK-EMPTY:
# CHECK-NEXT: Hex dump of section '.b':
Expand Down
9 changes: 6 additions & 3 deletions llvm/test/tools/llvm-readobj/ELF/hex-dump.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ FileHeader:
# RUN: llvm-readelf --hex-dump=.sec %t2.out1 | \
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=SPACES1

# SPACES1:Hex dump of section '.sec':
# SPACES1:{{^$}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps for consistency, it's worth adding this check to the other cases below?

# SPACES1-NEXT:Hex dump of section '.sec':
# SPACES1-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
# SPACES1-NEXT:0x00000010 0000 ..

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

# SPACES2:Hex dump of section '.sec':
# SPACES2:{{^$}}
# SPACES2-NEXT:Hex dump of section '.sec':
# SPACES2-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
# SPACES2-NEXT:0x00000010 00000000 00000000 00000000 0000 ..............

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

# SPACES3:Hex dump of section '.sec':
# SPACES3:{{^$}}
# SPACES3-NEXT:Hex dump of section '.sec':
# SPACES3-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
# SPACES3-NEXT:0x00000010 00000000 00000000 00000000 ............

Expand Down
6 changes: 4 additions & 2 deletions llvm/test/tools/llvm-readobj/ELF/string-dump-multi.s
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# REQUIRES: x86-registered-target

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

# CHECK: String dump of section '.a':
# HEADER: LoadName:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

# CHECK: {{^$}}
# CHECK-NEXT: String dump of section '.a':
# CHECK-NEXT: [ 0] 0
# CHECK-EMPTY:
# CHECK-NEXT: String dump of section '.b':
Expand Down
6 changes: 4 additions & 2 deletions llvm/test/tools/llvm-readobj/ELF/string-dump.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

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

# CHECK: String dump of section '.strings':
# HEADER: LoadName:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llvm-readobj -x .a -x .b prints two blank lines before the first Hex dump of section.
We have to test LoadName: to skip the first blank line (not due to hex/string dump).

# CHECK: {{^$}}
# CHECK-NEXT: String dump of section '.strings':
# CHECK-NEXT: [ 0] here
# CHECK-NEXT: [ 5] are
# CHECK-NEXT: [ 9] some
Expand Down
14 changes: 2 additions & 12 deletions llvm/tools/llvm-readobj/ObjDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,10 @@ void ObjDumper::printSectionsAsString(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections,
bool Decompress) {
SmallString<0> Out;
bool First = true;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(Obj, Sections)) {
StringRef SectionName = unwrapOrError(Obj.getFileName(), Section.getName());

if (!First)
W.startLine() << '\n';
First = false;
W.startLine() << "String dump of section '" << SectionName << "':\n";
W.startLine() << "\nString dump of section '" << SectionName << "':\n";

StringRef SectionContent =
unwrapOrError(Obj.getFileName(), Section.getContents());
Expand All @@ -182,15 +177,10 @@ void ObjDumper::printSectionsAsHex(const object::ObjectFile &Obj,
ArrayRef<std::string> Sections,
bool Decompress) {
SmallString<0> Out;
bool First = true;
for (object::SectionRef Section :
getSectionRefsByNameOrIndex(Obj, Sections)) {
StringRef SectionName = unwrapOrError(Obj.getFileName(), Section.getName());

if (!First)
W.startLine() << '\n';
First = false;
W.startLine() << "Hex dump of section '" << SectionName << "':\n";
W.startLine() << "\nHex dump of section '" << SectionName << "':\n";

StringRef SectionContent =
unwrapOrError(Obj.getFileName(), Section.getContents());
Expand Down