objdump --no-addresses

Fangrui Song i@maskray.me
Tue Aug 11 17:07:28 GMT 2020

On 2020-04-16, Alan Modra wrote:
>On Wed, Apr 15, 2020 at 11:49:16PM -0700, Fangrui Song wrote:
>> On 2020-04-16, Alan Modra wrote:
>> > On Wed, Apr 15, 2020 at 12:10:27PM -0700, Fangrui Song wrote:
>> > > In llvm-objdump, --no-leading-addr does this job. I think mentioning
>> > > `leading` may be appropriate here because lots of addresses are not
>> > > hidden by the proposed `--no-addresses` patch.
>> >
>> > I expect that objdump --no-addresses will be extended to remove more.
>> > There are lots of things it could do to make comparing compiler output
>> > easier, for example, removing pc-relative offsets.
>> >
>> > --
>> > Alan Modra
>> > Australia Development Lab, IBM
>> For llvm-objdump, I changed it to display the target address instead of
>> `. + offset` in https://reviews.llvm.org/D76907 and several follow-ups
>> (b, bl, beq (Bcc) need separate changes)
>> (I changed x86 and aarch64 as well.)
>> I guess the `. + offset` form may be more suitable when comparing two -d output.
>> Do you have a suggestion for the option enabling the `. + offset` output
>> or do you other ideas making the output easier for -d comparison?
>No, I haven't really thought about it that much.  I still use a sed
>script to trim off branch instructions, which is the major annoyance
>on powerpc.

Hi Alan, I noticed a relevant patch on llvm-objdump side
(https://reviews.llvm.org/D84191) and I just wanted to inform you about the
feature. I value your feedback and ideally I hope the two tools can find some common land,
or at least, some we can take inspirations from each other.

Current objdump --no-addresses:

% ~/Dev/binutils-gdb/Debug/binutils/objdump -d --no-addresses a

a:     file format elf64-x86-64

Disassembly of section .text:

         50                      push   %rax
         3b 05 05 10 00 00       cmp    0x1005(%rip),%eax        # <symbol>
         7d 02                   jge    <_start+0xb>
         eb f6                   jmp    <_start+0x1>
         c3                      ret

Note that cmp 0x1005(%rip),%eax still leaves an offset, and the jge/jmp instructions are symbolized by label+offset
where 'offset' may change in a differently compiled executable (with minor instruction changes).

There are still some rough corners (att style does not work well; excess spaces in a few places) in llvm-objdump
but here is what the output will look like:

% myllvm-objdump a -d --symbolize-operands --x86-asm-syntax=intel --no-show-raw-insn --no-leading-addr

a:      file format elf64-x86-64

Disassembly of section .text:

                 push    rax
                 cmp     eax, dword ptr  <symbol>
                 jge      <L0>
                 jmp      <L1>

Note that the local labels are synthesized. This inevitably requires a two-pass analysis.

More information about the Binutils mailing list