]> granicus.if.org Git - llvm/commitdiff
[llvm-objdump] - Print symbol addressed when dumping disassembly output (-d)
authorGeorge Rimar <grimar@accesssoftek.com>
Wed, 9 Jan 2019 14:43:33 +0000 (14:43 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Wed, 9 Jan 2019 14:43:33 +0000 (14:43 +0000)
When GNU objdump dumps the input with -d it prints the symbol addresses,
for example:

0000000000000031 <foo>:
  31: 00 00                 add    %al,(%rax)
...

llvm-objdump currently does not do that.
Patch changes the behavior to match the GNU objdump.

That is useful for implementing -z/--disassemble-zeroes (D56083),
it allows omitting first zero bytes and keep the information
about the symbol address in the output.

Differential revision: https://reviews.llvm.org/D56123

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350726 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-objdump/X86/print-symbol-addr.s [new file with mode: 0644]
tools/llvm-objdump/llvm-objdump.cpp

diff --git a/test/tools/llvm-objdump/X86/print-symbol-addr.s b/test/tools/llvm-objdump/X86/print-symbol-addr.s
new file mode 100644 (file)
index 0000000..9c5b23e
--- /dev/null
@@ -0,0 +1,29 @@
+// RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t.o
+
+// Check we print the address of `foo` and `bar`.
+// RUN: llvm-objdump -d %t.o | FileCheck %s
+// CHECK:      Disassembly of section .text:
+// CHECK-NEXT: 0000000000000000 foo:
+// CHECK-NEXT:   0: {{.*}}  nop
+// CHECK-NEXT:   1: {{.*}}  nop
+// CHECK:      0000000000000002 bar:
+// CHECK-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:      Disassembly of section .text:
+// NOADDR-NEXT: {{^}}foo:
+// NOADDR-NEXT:   {{.*}} nop
+// NOADDR-NEXT:   {{.*}} nop
+// NOADDR:      {{^}}bar:
+// NOADDR-NEXT:   {{.*}} nop
+
+.text
+.globl  foo
+.type   foo, @function
+foo:
+ nop
+ nop
+
+bar:
+ nop
index f2eb69a2e8ce32d7ec3db50fd1f153cc01bb9024..22fd1eb7dc24421e0f304502a000c12beac91e41 100644 (file)
@@ -1592,6 +1592,9 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
       }
 
       outs() << '\n';
+      if (!NoLeadingAddr)
+        outs() << format("%016" PRIx64 " ", SectionAddr + Start);
+
       StringRef SymbolName = std::get<1>(Symbols[si]);
       if (Demangle)
         outs() << demangle(SymbolName) << ":\n";