[PATCH] D56123: [llvm-objdump] - Print symbol addressed when dumping disassembly output (-d)

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 28 02:22:48 PST 2018


grimar created this revision.
grimar added reviewers: echristo, dblaikie, davide, jhenderson.

When GNU `objdump` dumps the input with `-d` it prints the symbol addresses,
for example:

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

when `llvm-objdump` dumps the same object, it doesn't do that:

  foo:
  		...
        39:	00 00 	addb	%al, (%rax)
  
  bar:
  		...
        39:	00 00 	addb	%al, (%rax)
        3b:	00 00 	addb	%al, (%rax)

The reason to do the same is the following:
I am working on a D56083 <https://reviews.llvm.org/D56083>, which implements -z/--disassemble-zeroes.
Normally the disassembly output will skip blocks of zeroes. Currently, by default GNU objdump
skip them, but `llvm-objdump` does not. And the issue is shown in the sample above. 
If we omit the bytes at the beginning of the section (see `bar` above), then the first
address (`0x0000000000000035`) is not printed and it is inconvenient and makes the output
not so useful as we do not see the start address of the symbol then.

So I suggest to follow the GNU `objdump` behavior and also print the address unless the
-no-leading-addr flag is set.


https://reviews.llvm.org/D56123

Files:
  test/tools/llvm-objdump/X86/print-symbol-addr.s
  tools/llvm-objdump/llvm-objdump.cpp


Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -1592,6 +1592,9 @@
       }
 
       outs() << '\n';
+      if (!NoLeadingAddr)
+        outs() << format("%016" PRIx64 " ", SectionAddr + Start);
+
       StringRef SymbolName = std::get<1>(Symbols[si]);
       if (Demangle)
         outs() << demangle(SymbolName) << ":\n";
Index: test/tools/llvm-objdump/X86/print-symbol-addr.s
===================================================================
--- /dev/null
+++ test/tools/llvm-objdump/X86/print-symbol-addr.s
@@ -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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56123.179612.patch
Type: text/x-patch
Size: 1479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181228/cc834d76/attachment.bin>


More information about the llvm-commits mailing list