RFC: Annotate immediates in x86 disassembly
Michael Matz
matz@suse.de
Tue May 12 13:38:37 GMT 2026
Hello,
On Tue, 12 May 2026, Jan Beulich wrote:
> > I guess that there is a balancing act here. The heuristic already skips
> > any immediates that are less than the starting address of the binary. It
> > could probably be extended to skip immediates that are larger than the
> > end address of the binary as well. Other than that though I am not sure
> > how we could make a better determination that an immediate value might
> > correspond to a symbolic value.
>
> Insn operands may want to indicate whether they may express addresses.
> Plus as indicated mere (immediate) operand sizes may already provide a
> hint.
I don't think we should obsess overly about trying to avoid false
positives here. After all, in small binaries even a 16bit number can be a
meaningful address. If the hint after the comment sign is wrong, then so
be it. The human reading it may simply discard it with brain power.
After all, if the disassembler _knows_ that number is a
symbol value, aka. address, (e.g. by the presence of relocations, or by
the presence of specific addressing modes) then we can (and do) print it
different. Otherwise it remains a hint that may or may not add value
to a human reader (and doesn't realistically remove value). So, in
something like:
0: 66 b8 92 10 mov $0x1092,%ax
I think it's fairly well acceptable to also hint at what 0x1092 resolves
to, when it _does_ resolve to anything interesting.
This is actually how some other disassemblers I know work: they try hard
to give a possible symbolic hint for all random numbers they encounter in
instructions and data (as commentary hints). I think it works well.
Ciao,
Michael.
More information about the Binutils
mailing list