[lld] [llvm] [llvm-readelf] Print a blank line for the first hex/string dump (PR #85744)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 00:35:58 PDT 2024
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/85744
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.
>From fdec94ad7c735303b85fa29db924a88d409dcf3c Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Tue, 19 Mar 2024 00:35:49 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
lld/test/ELF/aarch64-tlsdesc-zrel.s | 1 +
lld/test/ELF/pack-dyn-relocs.s | 1 +
.../tools/llvm-readobj/ELF/decompress-zlib.test | 2 ++
llvm/test/tools/llvm-readobj/ELF/hex-dump-multi.s | 6 ++++--
llvm/test/tools/llvm-readobj/ELF/hex-dump.test | 3 ++-
.../tools/llvm-readobj/ELF/string-dump-multi.s | 6 ++++--
llvm/test/tools/llvm-readobj/ELF/string-dump.test | 6 ++++--
llvm/tools/llvm-readobj/ObjDumper.cpp | 14 ++------------
8 files changed, 20 insertions(+), 19 deletions(-)
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());
More information about the llvm-commits
mailing list