RFC: Annotate immediates in x86 disassembly

Michael Matz matz@suse.de
Wed Apr 22 16:28:56 GMT 2026


Hello,

On Wed, 22 Apr 2026, Nick Clifton wrote:

>    For example, without the new option a line of disassembly might look
>    like this:
> 
>       400419:	bf 18 30 40 00       	mov    $0x403018,%edi
> 
>    whereas with the option enabled it could look like this:
> 
>       400419:	bf 18 30 40 00       	mov    $0x403018 [func1],%edi
> 
>    I find this helpful when looking at code that loads function
>    addresses into registers for example.

I think it's helpful, but may I use the bike-shed opportunity here?  I 
would prefer if the disassembler output (even with the option, but with 
--no-addresses --show-raw-insn) would be roughly copy-n-pastable to the 
assembler.  That would mean putting any annotations (and there may be more 
in the future?) after a comment-introducer.  Like:

  400419: bf 18 30 40 00          mov    $0x403018,%edi   # [func1]

There are only so many immediates^Wmagic numbers per instruction that 
warrant a comment, so I don't think we'd lose much by doing all annotation 
postfix instead of infix.  Plus: we already do output such after-comment 
hints for certain magic numbers:

  16:   8b 05 00 00 00 00       mov    0x0(%rip),%eax        # 1c <f+0x1c>

(that is for the expression 0x0+%rip).

Oh, and about .o files: their magic numbers are usually all associated 
with a relocation, so a symbol name hint could still be generated.  Like I 
now usually disassemble .o files with -r to see exactly that.  The above 
line is (with -r):

  16:   8b 05 00 00 00 00       mov    0x0(%rip),%eax        # 1c <f+0x1c>
                        18: R_X86_64_PC32       foo-0x4

I wouldn't mind it saying (with the new option, or even by default):

  16:   8b 05 00 00 00 00       mov    0x0(%rip),%eax        # [foo]


Ciao,
Michael.


More information about the Binutils mailing list