Skip to content

Commit 0c2e2f8

Browse files
committed
[llvm-objdump] Improve newline consistency between different pieces of information
When dumping multiple pieces of information (e.g. --all-headers), there is sometimes no separator between two pieces. This patch uses the "\nheader:\n" style, which generally improves compatibility with GNU objdump. Note: objdump -t/-T does not add a newline before "SYMBOL TABLE:" and "DYNAMIC SYMBOL TABLE:". We add a newline to be consistent with other information. `objdump -d` prints two empty lines before the first 'Disassembly of section'. We print just one with this patch. Differential Revision: https://reviews.llvm.org/D101796
1 parent a617e20 commit 0c2e2f8

17 files changed

+63
-52
lines changed

lld/test/MachO/arm64-32-reloc-got-load.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# DYLIB-NEXT: adrp x8, [[#]] ; 0x[[#GOT]]
2929
# DYLIB-NEXT: ldr w8, [x8]
3030
# DYLIB-NEXT: ret
31+
# DYLIB-EMPTY:
3132
# DYLIB-NEXT: Sections:
3233
# DYLIB-NEXT: Idx Name Size VMA Type
3334
# DYLIB: [[#]] __got 00000008 [[#%.8x,GOT]] DATA

lld/test/MachO/arm64-reloc-got-load.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# DYLIB-NEXT: adrp x8, [[#]] ; 0x[[#GOT]]
2929
# DYLIB-NEXT: ldr x8, [x8] ; literal pool symbol address: _bar
3030
# DYLIB-NEXT: ret
31+
# DYLIB-EMPTY:
3132
# DYLIB-NEXT: Sections:
3233
# DYLIB-NEXT: Idx Name Size VMA Type
3334
# DYLIB: [[#]] __got 00000010 {{0*}}[[#GOT]] DATA

lld/test/MachO/arm64-reloc-tlv-load.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# DYLIB-NEXT: adrp x8, [[#]] ; 0x[[#TLV]]
2929
# DYLIB-NEXT: ldr x8, [x8] ; literal pool symbol address: _bar
3030
# DYLIB-NEXT: ret
31+
# DYLIB-EMPTY:
3132
# DYLIB-NEXT: Sections:
3233
# DYLIB-NEXT: Idx Name Size VMA Type
3334
# DYLIB: [[#]] __thread_ptrs 00000010 {{0*}}[[#TLV]] DATA

llvm/test/tools/llvm-objdump/ELF/AMDGPU/kd-failure.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
; RUN: printf ".type my_kernel.kd, @object \nmy_kernel.kd:\n.size my_kernel.kd, 64\n" > %t1.sym_info
88
; RUN: llvm-objdump --disassemble-symbols=my_kernel.kd %t.o \
9-
; RUN: | tail -n +9 > %t1.sym_content
9+
; RUN: | tail -n +8 > %t1.sym_content
1010
; RUN: cat %t1.sym_info %t1.sym_content > %t1.s
1111

1212
; RUN: llvm-mc %t1.s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -filetype=obj -o %t-re-assemble.o

llvm/test/tools/llvm-objdump/ELF/AMDGPU/kd-sgpr.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
; RUN: split-file %s %t.dir
44

55
; RUN: llvm-mc %t.dir/1.s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t1
6-
; RUN: llvm-objdump --disassemble-symbols=my_kernel_1.kd %t1 | tail -n +8 \
6+
; RUN: llvm-objdump --disassemble-symbols=my_kernel_1.kd %t1 | tail -n +7 \
77
; RUN: | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t1-re-assemble
88
; RUN: diff %t1 %t1-re-assemble
99

1010
; RUN: llvm-mc %t.dir/2.s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t2
11-
; RUN: llvm-objdump --disassemble-symbols=my_kernel_2.kd %t2 | tail -n +8 \
11+
; RUN: llvm-objdump --disassemble-symbols=my_kernel_2.kd %t2 | tail -n +7 \
1212
; RUN: | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t2-re-assemble
1313
; RUN: diff %t2 %t2-re-assemble
1414

1515
; RUN: llvm-mc %t.dir/3.s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t3
16-
; RUN: llvm-objdump --disassemble-symbols=my_kernel_3.kd %t3 | tail -n +8 \
16+
; RUN: llvm-objdump --disassemble-symbols=my_kernel_3.kd %t3 | tail -n +7 \
1717
; RUN: | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t3-re-assemble
1818
; RUN: diff %t3 %t3-re-assemble
1919

llvm/test/tools/llvm-objdump/ELF/AMDGPU/kd-vgpr.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
; RUN: split-file %s %t.dir
44

55
; RUN: llvm-mc %t.dir/1.s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t1
6-
; RUN: llvm-objdump --disassemble-symbols=my_kernel_1.kd %t1 | tail -n +8 \
6+
; RUN: llvm-objdump --disassemble-symbols=my_kernel_1.kd %t1 | tail -n +7 \
77
; RUN: | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t1-re-assemble
88
; RUN: diff %t1 %t1-re-assemble
99

1010
; RUN: llvm-mc %t.dir/2.s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t2
11-
; RUN: llvm-objdump --disassemble-symbols=my_kernel_2.kd %t2 | tail -n +8 \
11+
; RUN: llvm-objdump --disassemble-symbols=my_kernel_2.kd %t2 | tail -n +7 \
1212
; RUN: | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t2-re-assemble
1313
; RUN: diff %t2 %t2-re-assemble
1414

1515
; RUN: llvm-mc %t.dir/3.s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t3
16-
; RUN: llvm-objdump --disassemble-symbols=my_kernel_3.kd %t3 | tail -n +8 \
16+
; RUN: llvm-objdump --disassemble-symbols=my_kernel_3.kd %t3 | tail -n +7 \
1717
; RUN: | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t3-re-assemble
1818
; RUN: diff %t3 %t3-re-assemble
1919

llvm/test/tools/llvm-objdump/ELF/AMDGPU/kd-zeroed-gfx9.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
; RUN: llvm-mc %s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t1
44
; RUN: llvm-objdump --disassemble-symbols=my_kernel.kd %t1 \
5-
; RUN: | tail -n +8 | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t2
5+
; RUN: | tail -n +7 | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t2
66
; RUN: diff %t1 %t2
77

88
; RUN: llvm-objdump -s -j .text %t1 | FileCheck --check-prefix=OBJDUMP %s

llvm/test/tools/llvm-objdump/ELF/AMDGPU/kd-zeroed-raw.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: llvm-mc %s --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t1
22
; RUN: llvm-objdump --disassemble-symbols=my_kernel.kd %t1 \
3-
; RUN: | tail -n +8 | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t2
3+
; RUN: | tail -n +7 | llvm-mc --triple=amdgcn-amd-amdhsa -mcpu=gfx908 -mattr=-xnack -filetype=obj -o %t2
44
; RUN: llvm-objdump -s -j .text %t2 | FileCheck --check-prefix=OBJDUMP %s
55

66
;; Not running lit-test over gfx10 (see kd-zeroed-gfx10.s for details).

llvm/test/tools/llvm-objdump/ELF/symbol-table.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
# RUN: llvm-objdump -t %t | cmp - %t.txt
55
# RUN: FileCheck %s --input-file=%t.txt --match-full-lines --strict-whitespace
66

7-
# CHECK:SYMBOL TABLE:
7+
# CHECK:{{.*}}file format elf64-x86-64
8+
#CHECK-EMPTY:
9+
# CHECK-NEXT:SYMBOL TABLE:
810
# CHECK-NEXT:0000000000000000 l df *ABS* 0000000000000000 a.c
911
# CHECK-NEXT:0000000000000000 l d .text 0000000000000000 .text
1012
# CHECK-NEXT:0000000000002000 l O .data 0000000000000000 local_object

llvm/test/tools/llvm-objdump/ELF/verdef.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# RUN: yaml2obj %s -o %t
22
# RUN: llvm-objdump -p %t | FileCheck --strict-whitespace %s
33

4-
# CHECK: Version definitions:
4+
# CHECK: Dynamic Section:
5+
# CHECK-EMPTY:
6+
# CHECK-NEXT: Version definitions:
57
# CHECK-NEXT: 1 0x01 0x075bcd15 foo
68
# CHECK-NEXT: 2 0x02 0x3ade68b1 VERSION_1
79
# CHECK-NEXT: VERSION_2

llvm/test/tools/llvm-objdump/ELF/verneed.test

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# RUN: yaml2obj %s -o %t
2-
# RUN: llvm-objdump -p %t | FileCheck %s
2+
# RUN: llvm-objdump -p %t | FileCheck %s --strict-whitespace --match-full-lines
33

4-
# CHECK: Version References:
5-
# CHECK-NEXT: required from dso.so.0:
6-
# CHECK-NEXT: 0x000004d2 0x0a 03 v1
7-
# CHECK-NEXT: 0x0000162e 0x0b 04 v2
8-
# CHECK-NEXT: required from dso.so.1:
9-
# CHECK-NEXT: 0x000011d7 0x0c 02 v3
4+
# CHECK:Dynamic Section:
5+
# CHECK-EMPTY:
6+
# CHECK-NEXT:Version References:
7+
# CHECK-NEXT: required from dso.so.0:
8+
# CHECK-NEXT: 0x000004d2 0x0a 03 v1
9+
# CHECK-NEXT: 0x0000162e 0x0b 04 v2
10+
# CHECK-NEXT: required from dso.so.1:
11+
# CHECK-NEXT: 0x000011d7 0x0c 02 v3
1012

1113
--- !ELF
1214
FileHeader:
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
RUN: llvm-objdump --macho -h %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s
1+
RUN: llvm-objdump --macho -h %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s --strict-whitespace --match-full-lines
22

3-
CHECK: Sections:
4-
CHECK: Idx Name Size VMA Type
5-
CHECK: 0 __text 0000003b 0000000000000000 TEXT
6-
CHECK: 1 __cstring 0000000d 000000000000003b DATA
7-
CHECK: 2 __compact_unwind 00000020 0000000000000048 DATA
8-
CHECK: 3 __eh_frame 00000040 0000000000000068 DATA
3+
CHECK:{{^$}}
4+
CHECK-NEXT:Sections:
5+
CHECK-NEXT:Idx Name Size VMA Type
6+
CHECK-NEXT: 0 __text 0000003b 0000000000000000 TEXT
7+
CHECK-NEXT: 1 __cstring 0000000d 000000000000003b DATA
8+
CHECK-NEXT: 2 __compact_unwind 00000020 0000000000000048 DATA
9+
CHECK-NEXT: 3 __eh_frame 00000040 0000000000000068 DATA

llvm/test/tools/llvm-objdump/X86/disassemble-section-name.s

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
# CHECK: : file format elf64-x86-64
55
# CHECK-EMPTY:
6-
# CHECK-EMPTY:
76
# CHECK-NEXT: Disassembly of section .text:
87
# CHECK-EMPTY:
98
# CHECK-NEXT: 0000000000000000 <foo>:

llvm/test/tools/llvm-objdump/X86/elf-dynamic-symbols.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
# RUN: llvm-objdump -T %t1 | \
66
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix=DYNSYM
77

8-
# DYNSYM:DYNAMIC SYMBOL TABLE:
8+
# DYNSYM:{{.*}}file format elf64-x86-64
9+
# DYNSYM-EMPTY:
10+
# DYNSYM-NEXT:DYNAMIC SYMBOL TABLE:
911
# DYNSYM-NEXT:0000000000000000 l DO .data 0000000000000000 localsym
1012
# DYNSYM-NEXT:0000000000000000 g DO .data 0000000000000000 globalsym
1113
# DYNSYM-NEXT:0000000000000000 u DO .data 0000000000000000 uniqueglobalsym

llvm/test/tools/llvm-objdump/all-headers.test

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77
## in the following order which provides GNU objdump compatability.
88

99
# CHECK: file format elf64-x86-64
10-
# CHECK-EMPTY:
1110
# CHECK-NEXT: architecture: x86_64
1211
# CHECK-NEXT: start address: 0x0000000000000000
1312
# CHECK-EMPTY:
14-
# CHECK-NEXT: Program Header:
15-
# CHECK: Dynamic Section:
16-
# CHECK: Sections:
17-
# CHECK: SYMBOL TABLE:
18-
# CHECK: RELOCATION RECORDS FOR [.text]:
13+
# CHECK-NEXT: Program Header:
14+
# CHECK-EMPTY:
15+
# CHECK-NEXT: Dynamic Section:
16+
# CHECK: INIT
17+
# CHECK-EMPTY:
18+
# CHECK-NEXT: Sections:
19+
# CHECK: 6 .shstrtab 0000002e 0000000000000000
20+
# CHECK-EMPTY:
21+
# CHECK-NEXT: SYMBOL TABLE:
22+
# CHECK-NEXT: 0000000000000000 l .text 0000000000000000 foo
23+
# CHECK-EMPTY:
24+
# CHECK-NEXT: RELOCATION RECORDS FOR [.text]:
1925

2026
## Check how we dump the archives.
2127
## Check we dump the appropriate headers for each file in the archive.

llvm/tools/llvm-objdump/ELFDump.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static void printDynamicSection(const ELFFile<ELFT> &Elf, StringRef Filename) {
180180
MaxLen = std::max(MaxLen, Elf.getDynamicTagAsString(Dyn.d_tag).size());
181181
std::string TagFmt = " %-" + std::to_string(MaxLen) + "s ";
182182

183-
outs() << "Dynamic Section:\n";
183+
outs() << "\nDynamic Section:\n";
184184
for (const typename ELFT::Dyn &Dyn : DynamicEntries) {
185185
if (Dyn.d_tag == ELF::DT_NULL)
186186
continue;
@@ -208,7 +208,7 @@ static void printDynamicSection(const ELFFile<ELFT> &Elf, StringRef Filename) {
208208

209209
template <class ELFT>
210210
static void printProgramHeaders(const ELFFile<ELFT> &Obj, StringRef FileName) {
211-
outs() << "Program Header:\n";
211+
outs() << "\nProgram Header:\n";
212212
auto ProgramHeaderOrError = Obj.program_headers();
213213
if (!ProgramHeaderOrError) {
214214
reportWarning("unable to read program headers: " +
@@ -275,13 +275,12 @@ static void printProgramHeaders(const ELFFile<ELFT> &Obj, StringRef FileName) {
275275
<< ((Phdr.p_flags & ELF::PF_W) ? "w" : "-")
276276
<< ((Phdr.p_flags & ELF::PF_X) ? "x" : "-") << "\n";
277277
}
278-
outs() << "\n";
279278
}
280279

281280
template <class ELFT>
282281
static void printSymbolVersionDependency(ArrayRef<uint8_t> Contents,
283282
StringRef StrTab) {
284-
outs() << "Version References:\n";
283+
outs() << "\nVersion References:\n";
285284

286285
const uint8_t *Buf = Contents.data();
287286
while (Buf) {
@@ -307,7 +306,7 @@ template <class ELFT>
307306
static void printSymbolVersionDefinition(const typename ELFT::Shdr &Shdr,
308307
ArrayRef<uint8_t> Contents,
309308
StringRef StrTab) {
310-
outs() << "Version definitions:\n";
309+
outs() << "\nVersion definitions:\n";
311310

312311
const uint8_t *Buf = Contents.data();
313312
uint32_t VerdefIndex = 1;

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ void objdump::printRelocations(const ObjectFile *Obj) {
16561656

16571657
for (std::pair<SectionRef, std::vector<SectionRef>> &P : SecToRelSec) {
16581658
StringRef SecName = unwrapOrError(P.first.getName(), Obj->getFileName());
1659-
outs() << "RELOCATION RECORDS FOR [" << SecName << "]:\n";
1659+
outs() << "\nRELOCATION RECORDS FOR [" << SecName << "]:\n";
16601660
uint32_t OffsetPadding = (Obj->getBytesInAddress() > 4 ? 16 : 8);
16611661
uint32_t TypePadding = 24;
16621662
outs() << left_justify("OFFSET", OffsetPadding) << " "
@@ -1679,7 +1679,6 @@ void objdump::printRelocations(const ObjectFile *Obj) {
16791679
<< "\n";
16801680
}
16811681
}
1682-
outs() << "\n";
16831682
}
16841683
}
16851684

@@ -1739,16 +1738,13 @@ void objdump::printSectionHeaders(const ObjectFile *Obj) {
17391738
size_t NameWidth = getMaxSectionNameWidth(Obj);
17401739
size_t AddressWidth = 2 * Obj->getBytesInAddress();
17411740
bool HasLMAColumn = shouldDisplayLMA(Obj);
1741+
outs() << "\nSections:\n";
17421742
if (HasLMAColumn)
1743-
outs() << "Sections:\n"
1744-
"Idx "
1745-
<< left_justify("Name", NameWidth) << " Size "
1743+
outs() << "Idx " << left_justify("Name", NameWidth) << " Size "
17461744
<< left_justify("VMA", AddressWidth) << " "
17471745
<< left_justify("LMA", AddressWidth) << " Type\n";
17481746
else
1749-
outs() << "Sections:\n"
1750-
"Idx "
1751-
<< left_justify("Name", NameWidth) << " Size "
1747+
outs() << "Idx " << left_justify("Name", NameWidth) << " Size "
17521748
<< left_justify("VMA", AddressWidth) << " Type\n";
17531749

17541750
uint64_t Idx;
@@ -1777,7 +1773,6 @@ void objdump::printSectionHeaders(const ObjectFile *Obj) {
17771773
Name.str().c_str(), Size)
17781774
<< format_hex_no_prefix(VMA, AddressWidth) << " " << Type << "\n";
17791775
}
1780-
outs() << "\n";
17811776
}
17821777

17831778
void objdump::printSectionContents(const ObjectFile *Obj) {
@@ -1833,21 +1828,21 @@ void objdump::printSectionContents(const ObjectFile *Obj) {
18331828
void objdump::printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
18341829
StringRef ArchitectureName, bool DumpDynamic) {
18351830
if (O->isCOFF() && !DumpDynamic) {
1836-
outs() << "SYMBOL TABLE:\n";
1831+
outs() << "\nSYMBOL TABLE:\n";
18371832
printCOFFSymbolTable(cast<const COFFObjectFile>(O));
18381833
return;
18391834
}
18401835

18411836
const StringRef FileName = O->getFileName();
18421837

18431838
if (!DumpDynamic) {
1844-
outs() << "SYMBOL TABLE:\n";
1839+
outs() << "\nSYMBOL TABLE:\n";
18451840
for (auto I = O->symbol_begin(); I != O->symbol_end(); ++I)
18461841
printSymbol(O, *I, FileName, ArchiveName, ArchitectureName, DumpDynamic);
18471842
return;
18481843
}
18491844

1850-
outs() << "DYNAMIC SYMBOL TABLE:\n";
1845+
outs() << "\nDYNAMIC SYMBOL TABLE:\n";
18511846
if (!O->isELF()) {
18521847
reportWarning(
18531848
"this operation is not currently supported for this file format",
@@ -2119,7 +2114,7 @@ static void printFileHeaders(const ObjectFile *O) {
21192114

21202115
StringRef Fmt = O->getBytesInAddress() > 4 ? "%016" PRIx64 : "%08" PRIx64;
21212116
outs() << "start address: "
2122-
<< "0x" << format(Fmt.data(), Address) << "\n\n";
2117+
<< "0x" << format(Fmt.data(), Address) << "\n";
21232118
}
21242119

21252120
static void printArchiveChild(StringRef Filename, const Archive::Child &C) {
@@ -2216,7 +2211,7 @@ static void dumpObject(ObjectFile *O, const Archive *A = nullptr,
22162211
outs() << A->getFileName() << "(" << O->getFileName() << ")";
22172212
else
22182213
outs() << O->getFileName();
2219-
outs() << ":\tfile format " << O->getFileFormatName().lower() << "\n\n";
2214+
outs() << ":\tfile format " << O->getFileFormatName().lower() << "\n";
22202215
}
22212216

22222217
if (HasStartAddressFlag || HasStopAddressFlag)

0 commit comments

Comments
 (0)