From: Fangrui Song Date: Mon, 17 Jun 2019 09:59:55 +0000 (+0000) Subject: [llvm-objdump] Use %08 instead of %016 to print leading addresses for 32-bit binaries X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=400438c3c0fe0d233819a493ccc52d30bffd99cc;p=llvm [llvm-objdump] Use %08 instead of %016 to print leading addresses for 32-bit binaries Reviewed By: grimar Differential Revision: https://reviews.llvm.org/D63398 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363539 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/MC/COFF/cv-loc-unreachable-2.s b/test/MC/COFF/cv-loc-unreachable-2.s index 66e8da4fa14..146158f713a 100644 --- a/test/MC/COFF/cv-loc-unreachable-2.s +++ b/test/MC/COFF/cv-loc-unreachable-2.s @@ -6,7 +6,7 @@ # section afterwards. We had negative label difference assertions when .cv_loc # bound tightly to the next instruction. -# ASM: 0000000000000000 _callit: +# ASM: 00000000 _callit: # begin inline { # ASM-NEXT: 0: e8 00 00 00 00 calll 0 <_callit+0x5> # ASM-NEXT: 5: 85 c0 testl %eax, %eax diff --git a/test/MC/COFF/cv-loc-unreachable.s b/test/MC/COFF/cv-loc-unreachable.s index 7a14a2d6002..5ac73e37742 100644 --- a/test/MC/COFF/cv-loc-unreachable.s +++ b/test/MC/COFF/cv-loc-unreachable.s @@ -17,7 +17,7 @@ # } -# ASM: 0000000000000000 _callit: +# ASM: 00000000 _callit: # begin inline { # ASM-NEXT: 0: e8 00 00 00 00 calll 0 <_callit+0x5> # ASM-NEXT: 5: 85 c0 testl %eax, %eax diff --git a/test/tools/llvm-objdump/PowerPC/branch-offset.s b/test/tools/llvm-objdump/PowerPC/branch-offset.s index b0b3f05f9cd..7843fca1c9b 100644 --- a/test/tools/llvm-objdump/PowerPC/branch-offset.s +++ b/test/tools/llvm-objdump/PowerPC/branch-offset.s @@ -7,10 +7,10 @@ # RUN: llvm-mc -triple=powerpc-unknown-linux -filetype=obj %s -o %t.o # RUN: llvm-objdump -d %t.o | FileCheck %s -# CHECK: 0000000000000000 callee_back: +# CHECK: {{0*}}00000000 callee_back: # CHECK: 18: {{.*}} bl .-24 # CHECK: 20: {{.*}} bl .+16 -# CHECK: 0000000000000030 callee_forward: +# CHECK: {{0*}}00000030 callee_forward: .text .global caller diff --git a/test/tools/llvm-objdump/X86/print-symbol-addr.s b/test/tools/llvm-objdump/X86/print-symbol-addr.s index 41d3b0657f3..322f49f7f49 100644 --- a/test/tools/llvm-objdump/X86/print-symbol-addr.s +++ b/test/tools/llvm-objdump/X86/print-symbol-addr.s @@ -1,20 +1,25 @@ -// RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t.o +# RUN: llvm-mc %s -filetype=obj -triple=i386 -o %t.32.o +# RUN: llvm-mc %s -filetype=obj -triple=x86_64 -o %t.64.o -// Check we print the address of `foo` and `bar`. -// RUN: llvm-objdump -d %t.o | FileCheck %s -// CHECK: 0000000000000000 foo: -// CHECK-NEXT: 0: {{.*}} nop -// CHECK-NEXT: 1: {{.*}} nop -// CHECK: 0000000000000002 bar: -// CHECK-NEXT: 2: {{.*}} nop +## Check we print the address of `foo` and `bar`. +# RUN: llvm-objdump -d %t.32.o | FileCheck --check-prefixes=ADDR32,ADDR %s +# RUN: llvm-objdump -d %t.64.o | FileCheck --check-prefixes=ADDR64,ADDR %s +# ADDR32: 00000000 foo: +# ADDR64: 0000000000000000 foo: +# ADDR-NEXT: 0: {{.*}} nop +# ADDR-NEXT: 1: {{.*}} nop +# ADDR32: 00000002 bar: +# ADDR64: 0000000000000002 bar: +# ADDR-NEXT: 2: {{.*}} nop -// Check we do not print the addresses with -no-leading-addr. -// RUN: llvm-objdump -d --no-leading-addr %t.o | FileCheck %s --check-prefix=NOADDR -// NOADDR: {{^}}foo: -// NOADDR-NEXT: {{.*}} nop -// NOADDR-NEXT: {{.*}} nop -// NOADDR: {{^}}bar: -// NOADDR-NEXT: {{.*}} nop +## Check we do not print the addresses with --no-leading-addr. +# RUN: llvm-objdump -d --no-leading-addr %t.32.o | FileCheck %s --check-prefix=NOADDR +# RUN: llvm-objdump -d --no-leading-addr %t.64.o | FileCheck %s --check-prefix=NOADDR +# NOADDR: {{^}}foo: +# NOADDR-NEXT: {{.*}} nop +# NOADDR-NEXT: {{.*}} nop +# NOADDR: {{^}}bar: +# NOADDR-NEXT: {{.*}} nop .text .globl foo diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 1d211d61611..7305f2bf634 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -612,9 +612,8 @@ static bool isArmElf(const ObjectFile *Obj) { } static void printRelocation(const RelocationRef &Rel, uint64_t Address, - uint8_t AddrSize) { - StringRef Fmt = - AddrSize > 4 ? "\t\t%016" PRIx64 ": " : "\t\t\t%08" PRIx64 ": "; + bool Is64Bits) { + StringRef Fmt = Is64Bits ? "\t\t%016" PRIx64 ": " : "\t\t\t%08" PRIx64 ": "; SmallString<16> Name; SmallString<32> Val; Rel.getTypeName(Name); @@ -704,7 +703,7 @@ public: auto PrintReloc = [&]() -> void { while ((RelCur != RelEnd) && (RelCur->getOffset() <= Address.Address)) { if (RelCur->getOffset() == Address.Address) { - printRelocation(*RelCur, Address.Address, 4); + printRelocation(*RelCur, Address.Address, false); return; } ++RelCur; @@ -1032,6 +1031,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, std::map> RelocMap; if (InlineRelocs) RelocMap = getRelocsMap(*Obj); + bool Is64Bits = Obj->getBytesInAddress() > 4; // Create a mapping from virtual address to symbol name. This is used to // pretty print the symbols while disassembling. @@ -1229,7 +1229,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, outs() << '\n'; if (!NoLeadingAddr) - outs() << format("%016" PRIx64 " ", + outs() << format(Is64Bits ? "%016" PRIx64 " " : "%08" PRIx64 " ", SectionAddr + Start + VMAAdjustment); StringRef SymbolName = std::get<1>(Symbols[SI]); @@ -1401,8 +1401,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, Offset += AdjustVMA; } - printRelocation(*RelCur, SectionAddr + Offset, - Obj->getBytesInAddress()); + printRelocation(*RelCur, SectionAddr + Offset, Is64Bits); ++RelCur; } }