]> granicus.if.org Git - llvm/commitdiff
[llvm-objdump] Use %08 instead of %016 to print leading addresses for 32-bit binaries
authorFangrui Song <maskray@google.com>
Mon, 17 Jun 2019 09:59:55 +0000 (09:59 +0000)
committerFangrui Song <maskray@google.com>
Mon, 17 Jun 2019 09:59:55 +0000 (09:59 +0000)
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

test/MC/COFF/cv-loc-unreachable-2.s
test/MC/COFF/cv-loc-unreachable.s
test/tools/llvm-objdump/PowerPC/branch-offset.s
test/tools/llvm-objdump/X86/print-symbol-addr.s
tools/llvm-objdump/llvm-objdump.cpp

index 66e8da4fa140d225af3130a2bc436d384140b2de..146158f713ac671251bb8ed84c18dcd167cfb986 100644 (file)
@@ -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
index 7a14a2d6002f521173eb5249647304d07dfdc066..5ac73e3774240db76ccb9cb5d79c0936a3e0da9a 100644 (file)
@@ -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
index b0b3f05f9cdb5e7a3a8c0bd6c16a7e59d5a9ca74..7843fca1c9ba288ea267598d3e79d63307e06dc8 100644 (file)
@@ -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
index 41d3b0657f3f5545e57bea0353ebdc663eb9f308..322f49f7f49406a45d65dbc95922d0354a6f3120 100644 (file)
@@ -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
index 1d211d6161191b254880f33edca2981b982197cb..7305f2bf634fd25453d46c034132f03d604053df 100644 (file)
@@ -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<SectionRef, std::vector<RelocationRef>> 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;
           }
         }