RFC: Annotate immediates in x86 disassembly
H.J. Lu
hjl.tools@gmail.com
Wed Apr 22 09:33:33 GMT 2026
On Wed, Apr 22, 2026 at 5:02 PM Nick Clifton <nickc@redhat.com> wrote:
>
> Hi Guys,
>
> Attached is a small potential patch that adds a new target specific
> option to the x86 and x86_64 disassemblers: "-M annotate-immediates".
> If enabled immediate operands which match a symbol's value will have
> the name of that symbol displayed alongside them.
>
> 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.
>
> What do you think ? Would this be a useful addition to the assembler?
>
> Notes:
> * The feature is only enabled when disassembling executables as
> the symbolic addresses in object files too often match small
> ordinary constants.
>
> * The option parser will accept "-M annotate" or "-M
> annotate-immediates" or "-M annotate<anything>". I could make it
> more strict, but I was not sure if it was worth it.
>
> I did try to make this a generic option, rather than specific to the
> x86/x86_64 architecture, but I quickly ran into problems with how
> different ISAs handle the loading of constant values. Still if this
> kind of feature is considered useful it could be added to more
> backends or a per-architecture basis.
>
> Cheers
> Nick
>
/* Determine if we can display some more information about this immediate. */
+ if (! annotate_immediates
+ /* Don't bother with xero, even if there is symbol associated
with it. */
zero.
+ /* For the next tests we need a BFD. If we do not have one
then do not proceed. */
+ || ins->info->section == NULL
+ || ins->info->section->owner == NULL
+ /* Save time by avoiding immediates that cannot reference part
of the address space. */
+ || imm < ins->info->section->owner->start_address
+ /* Also skip object files as their symbols have not been resolved. */
+ || (ins->info->section->owner->flags & EXEC_P) == 0)
Should it also handle shared libraries?
+ return;
--
H.J.
More information about the Binutils
mailing list