[lld] [llvm] [llvm-readelf] Print a blank line before the first hex/string dump (PR #85744)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 00:36:27 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-elf
@llvm/pr-subscribers-llvm-binary-utilities
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/85744.diff
8 Files Affected:
- (modified) lld/test/ELF/aarch64-tlsdesc-zrel.s (+1)
- (modified) lld/test/ELF/pack-dyn-relocs.s (+1)
- (modified) llvm/test/tools/llvm-readobj/ELF/decompress-zlib.test (+2)
- (modified) llvm/test/tools/llvm-readobj/ELF/hex-dump-multi.s (+4-2)
- (modified) llvm/test/tools/llvm-readobj/ELF/hex-dump.test (+2-1)
- (modified) llvm/test/tools/llvm-readobj/ELF/string-dump-multi.s (+4-2)
- (modified) llvm/test/tools/llvm-readobj/ELF/string-dump.test (+4-2)
- (modified) llvm/tools/llvm-readobj/ObjDumper.cpp (+2-12)
``````````diff
diff --git a/lld/test/ELF/aarch64-tlsdesc-zrel.s b/lld/test/ELF/aarch64-tlsdesc-zrel.s
index 1b35e0d29a26f8..e2e560bd13f574 100644
--- a/lld/test/ELF/aarch64-tlsdesc-zrel.s
+++ b/lld/test/ELF/aarch64-tlsdesc-zrel.s
@@ -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
diff --git a/lld/test/ELF/pack-dyn-relocs.s b/lld/test/ELF/pack-dyn-relocs.s
index 9de5bee2e747f0..733ddd4ecad396 100644
--- a/lld/test/ELF/pack-dyn-relocs.s
+++ b/lld/test/ELF/pack-dyn-relocs.s
@@ -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 .
diff --git a/llvm/test/tools/llvm-readobj/ELF/decompress-zlib.test b/llvm/test/tools/llvm-readobj/ELF/decompress-zlib.test
index ea7a8854eb1a0c..c1d12a6d560ec8 100644
--- a/llvm/test/tools/llvm-readobj/ELF/decompress-zlib.test
+++ b/llvm/test/tools/llvm-readobj/ELF/decompress-zlib.test
@@ -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
@@ -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 ................
diff --git a/llvm/test/tools/llvm-readobj/ELF/hex-dump-multi.s b/llvm/test/tools/llvm-readobj/ELF/hex-dump-multi.s
index 33ef534e81e138..942bfc4b7fb026 100644
--- a/llvm/test/tools/llvm-readobj/ELF/hex-dump-multi.s
+++ b/llvm/test/tools/llvm-readobj/ELF/hex-dump-multi.s
@@ -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:
+# CHECK: {{^$}}
+# CHECK-NEXT: Hex dump of section '.a':
# CHECK-NEXT: 0x00000000 00
# CHECK-EMPTY:
# CHECK-NEXT: Hex dump of section '.b':
diff --git a/llvm/test/tools/llvm-readobj/ELF/hex-dump.test b/llvm/test/tools/llvm-readobj/ELF/hex-dump.test
index 7829944806f34f..548cc8b26422d8 100644
--- a/llvm/test/tools/llvm-readobj/ELF/hex-dump.test
+++ b/llvm/test/tools/llvm-readobj/ELF/hex-dump.test
@@ -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:{{^$}}
+# SPACES1-NEXT:Hex dump of section '.sec':
# SPACES1-NEXT:0x00000000 00000000 00000000 00000000 00000000 ................
# SPACES1-NEXT:0x00000010 0000 ..
diff --git a/llvm/test/tools/llvm-readobj/ELF/string-dump-multi.s b/llvm/test/tools/llvm-readobj/ELF/string-dump-multi.s
index 29d7ef011005e5..36a115bd259a96 100644
--- a/llvm/test/tools/llvm-readobj/ELF/string-dump-multi.s
+++ b/llvm/test/tools/llvm-readobj/ELF/string-dump-multi.s
@@ -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:
+# CHECK: {{^$}}
+# CHECK-NEXT: String dump of section '.a':
# CHECK-NEXT: [ 0] 0
# CHECK-EMPTY:
# CHECK-NEXT: String dump of section '.b':
diff --git a/llvm/test/tools/llvm-readobj/ELF/string-dump.test b/llvm/test/tools/llvm-readobj/ELF/string-dump.test
index c06b274d25288d..1d7a177b32de12 100644
--- a/llvm/test/tools/llvm-readobj/ELF/string-dump.test
+++ b/llvm/test/tools/llvm-readobj/ELF/string-dump.test
@@ -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
@@ -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:
+# CHECK: {{^$}}
+# CHECK-NEXT: String dump of section '.strings':
# CHECK-NEXT: [ 0] here
# CHECK-NEXT: [ 5] are
# CHECK-NEXT: [ 9] some
diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index 0d3fea71aafd42..0980d2ad3a852b 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -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());
@@ -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());
``````````
</details>
https://github.com/llvm/llvm-project/pull/85744
More information about the llvm-commits
mailing list