objdump: z80: show symbol names for addresses in disassembly

Message ID 6cf637c4-16c7-4014-9993-3c2bf20e1a20@zeal8bit.com
State New
Headers
Series objdump: z80: show symbol names for addresses in disassembly |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Zeal8bit March 25, 2026, 10:12 a.m. UTC
  Hello,

While using objdump to disassemble Z80 ELF binaries, the output shows 
addresses for relative (`prt_e`), absolute (`prt_nn`) jumps/calls and 
memory load, but no symbol, even if symbol information is available.
For example, objdump would output:

00000000 <software_reset>:
    0:   f3              di
    1:   c3 31 01        jp 0x0131

instead of:

00000000 <software_reset>:
    0:   f3              di
    1:   c3 31 01        jp 0x0131 <os_entry>

With this patch, the disassembly output will now include any existing 
symbol corresponding to the addresses as shown above.

---
  opcodes/z80-dis.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
        while (i--)
          nn = nn * 0x100 + p[i];
        info->fprintf_func (info->stream, txt, nn);
+      if (info->symbol_at_address_func)
+        {
+          s = info->symbol_at_address_func (nn, info);
+          if (s && s->name)
+            info->fprintf_func (info->stream, " <%s>", s->name);
+        }
        buf->n_used = buf->n_fetch;
      }
    else
--
2.43.0
  

Comments

Jan Beulich March 27, 2026, 2:22 p.m. UTC | #1
On 25.03.2026 11:12, Zeal8bit wrote:
> --- a/opcodes/z80-dis.c
> +++ b/opcodes/z80-dis.c
> @@ -117,6 +117,12 @@ prt_e (struct buffer *buf, disassemble_info * info, const char *txt)
>         int target_addr = (buf->base + 2 + e) & 0xffff;
>         buf->n_used = buf->n_fetch;
>         info->fprintf_func (info->stream, "%s0x%04x", txt, target_addr);
> +      if (info->symbol_at_address_func)
> +        {
> +          asymbol *s = info->symbol_at_address_func (target_addr, info);
> +          if (s && s->name)
> +            info->fprintf_func (info->stream, " <%s>", s->name);
> +        }
>       }
>     else
>       buf->n_used = -1;
> @@ -139,6 +145,7 @@ prt_nn (struct buffer *buf, disassemble_info * info, const char *txt)
>     int nn;
>     unsigned char *p;
>     int i;
> +  asymbol *s;
>     p = (unsigned char*) buf->data + buf->n_fetch;
>     if (fetch_data (buf, info, buf->nn_len))
> @@ -148,6 +155,12 @@ prt_nn (struct buffer *buf, disassemble_info * info, const char *txt)
>         while (i--)
>           nn = nn * 0x100 + p[i];
>         info->fprintf_func (info->stream, txt, nn);
> +      if (info->symbol_at_address_func)
> +        {
> +          s = info->symbol_at_address_func (nn, info);
> +          if (s && s->name)
> +            info->fprintf_func (info->stream, " <%s>", s->name);
> +        }
>         buf->n_used = buf->n_fetch;
>       }
>     else

The vast majority or opcodes/*-dis*.c use info->print_address_func() as the
higher level interface (aiui). Is there a particular reason you need to use
info->symbol_at_address_func() here? If there is, it wants providing in the
description, and then the new variables you introduce also want to be
pointer-to-const.

Jan
  
Jan Beulich March 27, 2026, 2:23 p.m. UTC | #2
On 25.03.2026 11:12, Zeal8bit wrote:
> Hello,
> 
> While using objdump to disassemble Z80 ELF binaries, the output shows 
> addresses for relative (`prt_e`), absolute (`prt_nn`) jumps/calls and 
> memory load, but no symbol, even if symbol information is available.
> For example, objdump would output:
> 
> 00000000 <software_reset>:
>     0:   f3              di
>     1:   c3 31 01        jp 0x0131
> 
> instead of:
> 
> 00000000 <software_reset>:
>     0:   f3              di
>     1:   c3 31 01        jp 0x0131 <os_entry>
> 
> With this patch, the disassembly output will now include any existing 
> symbol corresponding to the addresses as shown above.
> 
> ---
>   opcodes/z80-dis.c | 13 +++++++++++++
>   1 file changed, 13 insertions(+)

Oh, also - unless you have a copyright assignment in place, you will also
want to sign-off on your change.

Jan
  

Patch

diff --git a/opcodes/z80-dis.c b/opcodes/z80-dis.c
index d5b4c421..d074cadd 100644
--- a/opcodes/z80-dis.c
+++ b/opcodes/z80-dis.c
@@ -117,6 +117,12 @@  prt_e (struct buffer *buf, disassemble_info * info, const char *txt)
        int target_addr = (buf->base + 2 + e) & 0xffff;
        buf->n_used = buf->n_fetch;
        info->fprintf_func (info->stream, "%s0x%04x", txt, target_addr);
+      if (info->symbol_at_address_func)
+        {
+          asymbol *s = info->symbol_at_address_func (target_addr, info);
+          if (s && s->name)
+            info->fprintf_func (info->stream, " <%s>", s->name);
+        }
      }
    else
      buf->n_used = -1;
@@ -139,6 +145,7 @@  prt_nn (struct buffer *buf, disassemble_info * info, const char *txt)
    int nn;
    unsigned char *p;
    int i;
+  asymbol *s;
    p = (unsigned char*) buf->data + buf->n_fetch;
    if (fetch_data (buf, info, buf->nn_len))
@@ -148,6 +155,12 @@  prt_nn (struct buffer *buf, disassemble_info * info, const char *txt)