[PATCH] bpf: disasemble offsets of value 0 as "+0"

David Faust david.faust@oracle.com
Fri Jul 21 17:58:55 GMT 2023


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(-)

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,
-- 
2.40.1



More information about the Binutils mailing list