bpf: disasemble offsets of value 0 as "+0"

Message ID 20230721175855.6460-1-david.faust@oracle.com
State Unresolved
Headers
Series bpf: disasemble offsets of value 0 as "+0" |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

David Faust July 21, 2023, 5:58 p.m. UTC
  This tiny patch makes the BPF disassembler to emit, e.g.

  ldxdw %r1, [%r0+0]

instead of

  ldxdw %r1, [%r00]

when the offset is 0, to avoid confusion.

Tested on bpf-unknown-none.
Maybe obvious, but.. OK?

Thanks.

opcodes/

	* bpf-dis.c (print_insn_bpf): Print 16-bit offsets with value 0
	as "+0".
---
 opcodes/bpf-dis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Jose E. Marchesi July 21, 2023, 6:11 p.m. UTC | #1
> This tiny patch makes the BPF disassembler to emit, e.g.
>
>   ldxdw %r1, [%r0+0]
>
> instead of
>
>   ldxdw %r1, [%r00]

Damn, /me dumb 8-)
Thanks for picking this up.

Yeah, but the fix should be done for %I32 as well.  Also, we would need
these cases in the mem.s test.

> when the offset is 0, to avoid confusion.
>
> Tested on bpf-unknown-none.
> Maybe obvious, but.. OK?
>
> Thanks.
>
> opcodes/
>
> 	* bpf-dis.c (print_insn_bpf): Print 16-bit offsets with value 0
> 	as "+0".
> ---
>  opcodes/bpf-dis.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/opcodes/bpf-dis.c b/opcodes/bpf-dis.c
> index a4dc3dc2523..bb63119e813 100644
> --- a/opcodes/bpf-dis.c
> +++ b/opcodes/bpf-dis.c
> @@ -231,7 +231,7 @@ print_insn_bpf (bfd_vma pc, disassemble_info *info)
>                    if (p[1] == 'o')
>                      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
>                                                    "%s",
> -                                                  asm_obase != 10 || offset16 > 0 ? "+" : "");
> +						  asm_obase != 10 || offset16 >= 0 ? "+" : "");
>                    if (asm_obase == 16 || asm_obase == 8)
>                      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
>                                                    asm_obase == 8 ? "0%" PRIo16 : "0x%" PRIx16,
  

Patch

diff --git a/opcodes/bpf-dis.c b/opcodes/bpf-dis.c
index a4dc3dc2523..bb63119e813 100644
--- a/opcodes/bpf-dis.c
+++ b/opcodes/bpf-dis.c
@@ -231,7 +231,7 @@  print_insn_bpf (bfd_vma pc, disassemble_info *info)
                   if (p[1] == 'o')
                     (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
                                                   "%s",
-                                                  asm_obase != 10 || offset16 > 0 ? "+" : "");
+						  asm_obase != 10 || offset16 >= 0 ? "+" : "");
                   if (asm_obase == 16 || asm_obase == 8)
                     (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
                                                   asm_obase == 8 ? "0%" PRIo16 : "0x%" PRIx16,