objdump: z80: show symbol names for addresses in disassembly
Checks
Commit Message
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
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
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
@@ -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)