public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] bpf: disasemble offsets of value 0 as "+0"
@ 2023-07-21 17:58 David Faust
  2023-07-21 18:11 ` Jose E. Marchesi
  0 siblings, 1 reply; 4+ messages in thread
From: David Faust @ 2023-07-21 17:58 UTC (permalink / raw)
  To: binutils, jose.marchesi

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bpf: disasemble offsets of value 0 as "+0"
  2023-07-21 17:58 [PATCH] bpf: disasemble offsets of value 0 as "+0" David Faust
@ 2023-07-21 18:11 ` Jose E. Marchesi
  2023-07-21 18:54   ` [PATCH v2] " David Faust
  0 siblings, 1 reply; 4+ messages in thread
From: Jose E. Marchesi @ 2023-07-21 18:11 UTC (permalink / raw)
  To: David Faust; +Cc: binutils


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] bpf: disasemble offsets of value 0 as "+0"
  2023-07-21 18:11 ` Jose E. Marchesi
@ 2023-07-21 18:54   ` David Faust
  2023-07-21 19:21     ` Jose E. Marchesi
  0 siblings, 1 reply; 4+ messages in thread
From: David Faust @ 2023-07-21 18:54 UTC (permalink / raw)
  To: jose.marchesi, binutils

[Changes from v1:
 - Also do the same for 32-bit offsets
 - Add gas testsuite updates. ]

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.

opcodes/

	* bpf-dis.c (print_insn_bpf): Print offsets with value 0 as "+0".

gas/

	* testsuite/gas/bpf/mem.s: Add tests with offset 0.
	* testsuite/gas/bpf/mem-pseudoc.s: Likewise.
	* testsuite/gas/bpf/mem.d: Update accordingly.
	* testsuite/gas/bpf/mem-be.d: Likewise.
	* testsuite/gas/bpf/mem-pseudoc.d: Likewise.
	* testsuite/gas/bpf/mem-be-pseudoc.d: Likewise.
---
 gas/testsuite/gas/bpf/mem-be-pseudoc.d | 2 ++
 gas/testsuite/gas/bpf/mem-be.d         | 4 +++-
 gas/testsuite/gas/bpf/mem-pseudoc.d    | 2 ++
 gas/testsuite/gas/bpf/mem-pseudoc.s    | 2 ++
 gas/testsuite/gas/bpf/mem.d            | 4 +++-
 gas/testsuite/gas/bpf/mem.s            | 2 ++
 opcodes/bpf-dis.c                      | 4 ++--
 7 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gas/testsuite/gas/bpf/mem-be-pseudoc.d b/gas/testsuite/gas/bpf/mem-be-pseudoc.d
index 9a1ffc10984..5dff35c225d 100644
--- a/gas/testsuite/gas/bpf/mem-be-pseudoc.d
+++ b/gas/testsuite/gas/bpf/mem-be-pseudoc.d
@@ -32,3 +32,5 @@ Disassembly of section .text:
   a8:	89 21 7e ef 00 00 00 00 	r2=\*\(i16\*\)\(r1\+0x7eef\)
   b0:	91 21 7e ef 00 00 00 00 	r2=\*\(i8\*\)\(r1\+0x7eef\)
   b8:	99 21 7e ef 00 00 00 00 	r2=\*\(i64\*\)\(r1\+0x7eef\)
+  c0:	58 05 00 00 00 00 00 00 	r0=\*\(u64\*\)skb\[r5\+0x0\]
+  c8:	61 21 00 00 00 00 00 00 	r2=\*\(u32\*\)\(r1\+0x0\)
diff --git a/gas/testsuite/gas/bpf/mem-be.d b/gas/testsuite/gas/bpf/mem-be.d
index 5746b6a9485..cd7b35c60a3 100644
--- a/gas/testsuite/gas/bpf/mem-be.d
+++ b/gas/testsuite/gas/bpf/mem-be.d
@@ -31,4 +31,6 @@ Disassembly of section .text:
   a0:	81 21 7e ef 00 00 00 00 	ldxsw %r2,\[%r1\+0x7eef\]
   a8:	89 21 7e ef 00 00 00 00 	ldxsh %r2,\[%r1\+0x7eef\]
   b0:	91 21 7e ef 00 00 00 00 	ldxsb %r2,\[%r1\+0x7eef\]
-  b8:	99 21 7e ef 00 00 00 00 	ldxsdw %r2,\[%r1\+0x7eef\]
\ No newline at end of file
+  b8:	99 21 7e ef 00 00 00 00 	ldxsdw %r2,\[%r1\+0x7eef\]
+  c0:	79 21 00 00 00 00 00 00 	ldxdw %r2,\[%r1\+0x0\]
+  c8:	40 03 00 00 00 00 00 00 	ldindw %r3,0x0
diff --git a/gas/testsuite/gas/bpf/mem-pseudoc.d b/gas/testsuite/gas/bpf/mem-pseudoc.d
index 8481048504d..ca94cef51cf 100644
--- a/gas/testsuite/gas/bpf/mem-pseudoc.d
+++ b/gas/testsuite/gas/bpf/mem-pseudoc.d
@@ -32,3 +32,5 @@ Disassembly of section .text:
   a8:	89 12 ef 7e 00 00 00 00 	r2=\*\(i16\*\)\(r1\+0x7eef\)
   b0:	91 12 ef 7e 00 00 00 00 	r2=\*\(i8\*\)\(r1\+0x7eef\)
   b8:	99 12 ef 7e 00 00 00 00 	r2=\*\(i64\*\)\(r1\+0x7eef\)
+  c0:	58 50 00 00 00 00 00 00 	r0=\*\(u64\*\)skb\[r5\+0x0\]
+  c8:	61 12 00 00 00 00 00 00 	r2=\*\(u32\*\)\(r1\+0x0\)
diff --git a/gas/testsuite/gas/bpf/mem-pseudoc.s b/gas/testsuite/gas/bpf/mem-pseudoc.s
index 1ffa2e25926..4a5e588b91a 100644
--- a/gas/testsuite/gas/bpf/mem-pseudoc.s
+++ b/gas/testsuite/gas/bpf/mem-pseudoc.s
@@ -25,3 +25,5 @@
         r2 = *(i16*)(r1+0x7eef)
         r2 = *(i8*)(r1+0x7eef)
         r2 = *(i64*)(r1+0x7eef)
+	r0 = *(u64 *)skb[r5 + 0]
+	r2 = *(u32 *)(r1 + 0)
diff --git a/gas/testsuite/gas/bpf/mem.d b/gas/testsuite/gas/bpf/mem.d
index 8b7a488ae01..9a1e7095df0 100644
--- a/gas/testsuite/gas/bpf/mem.d
+++ b/gas/testsuite/gas/bpf/mem.d
@@ -31,4 +31,6 @@ Disassembly of section .text:
   a0:	81 12 ef 7e 00 00 00 00 	ldxsw %r2,\[%r1\+0x7eef\]
   a8:	89 12 ef 7e 00 00 00 00 	ldxsh %r2,\[%r1\+0x7eef\]
   b0:	91 12 ef 7e 00 00 00 00 	ldxsb %r2,\[%r1\+0x7eef\]
-  b8:	99 12 ef 7e 00 00 00 00 	ldxsdw %r2,\[%r1\+0x7eef\]
\ No newline at end of file
+  b8:	99 12 ef 7e 00 00 00 00 	ldxsdw %r2,\[%r1\+0x7eef\]
+  c0:	79 12 00 00 00 00 00 00 	ldxdw %r2,\[%r1\+0x0\]
+  c8:	40 30 00 00 00 00 00 00 	ldindw %r3,0x0
diff --git a/gas/testsuite/gas/bpf/mem.s b/gas/testsuite/gas/bpf/mem.s
index 6323cf1ede7..adeda473bb8 100644
--- a/gas/testsuite/gas/bpf/mem.s
+++ b/gas/testsuite/gas/bpf/mem.s
@@ -26,3 +26,5 @@
         ldxsh %r2, [%r1+0x7eef]
         ldxsb %r2, [%r1+0x7eef]
         ldxsdw %r2, [%r1+0x7eef]
+	ldxdw %r2, [%r1+0]
+	ldindw %r3, 0
diff --git a/opcodes/bpf-dis.c b/opcodes/bpf-dis.c
index a4dc3dc2523..4fe0efc2f96 100644
--- a/opcodes/bpf-dis.c
+++ b/opcodes/bpf-dis.c
@@ -215,7 +215,7 @@ print_insn_bpf (bfd_vma pc, disassemble_info *info)
                   if (p[1] == 'I')
                     (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
                                                   "%s",
-                                                  asm_obase != 10 || imm32 > 0 ? "+" : "");
+						  asm_obase != 10 || imm32 >= 0 ? "+" : "");
                   (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
                                                 asm_obase == 10 ? "%" PRIi32
                                                 : asm_obase == 8 ? "%" PRIo32
@@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] bpf: disasemble offsets of value 0 as "+0"
  2023-07-21 18:54   ` [PATCH v2] " David Faust
@ 2023-07-21 19:21     ` Jose E. Marchesi
  0 siblings, 0 replies; 4+ messages in thread
From: Jose E. Marchesi @ 2023-07-21 19:21 UTC (permalink / raw)
  To: David Faust; +Cc: binutils


Hi Faust.

Thanks for the patch.
OK.

> [Changes from v1:
>  - Also do the same for 32-bit offsets
>  - Add gas testsuite updates. ]
>
> 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.
>
> opcodes/
>
> 	* bpf-dis.c (print_insn_bpf): Print offsets with value 0 as "+0".
>
> gas/
>
> 	* testsuite/gas/bpf/mem.s: Add tests with offset 0.
> 	* testsuite/gas/bpf/mem-pseudoc.s: Likewise.
> 	* testsuite/gas/bpf/mem.d: Update accordingly.
> 	* testsuite/gas/bpf/mem-be.d: Likewise.
> 	* testsuite/gas/bpf/mem-pseudoc.d: Likewise.
> 	* testsuite/gas/bpf/mem-be-pseudoc.d: Likewise.
> ---
>  gas/testsuite/gas/bpf/mem-be-pseudoc.d | 2 ++
>  gas/testsuite/gas/bpf/mem-be.d         | 4 +++-
>  gas/testsuite/gas/bpf/mem-pseudoc.d    | 2 ++
>  gas/testsuite/gas/bpf/mem-pseudoc.s    | 2 ++
>  gas/testsuite/gas/bpf/mem.d            | 4 +++-
>  gas/testsuite/gas/bpf/mem.s            | 2 ++
>  opcodes/bpf-dis.c                      | 4 ++--
>  7 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/gas/testsuite/gas/bpf/mem-be-pseudoc.d b/gas/testsuite/gas/bpf/mem-be-pseudoc.d
> index 9a1ffc10984..5dff35c225d 100644
> --- a/gas/testsuite/gas/bpf/mem-be-pseudoc.d
> +++ b/gas/testsuite/gas/bpf/mem-be-pseudoc.d
> @@ -32,3 +32,5 @@ Disassembly of section .text:
>    a8:	89 21 7e ef 00 00 00 00 	r2=\*\(i16\*\)\(r1\+0x7eef\)
>    b0:	91 21 7e ef 00 00 00 00 	r2=\*\(i8\*\)\(r1\+0x7eef\)
>    b8:	99 21 7e ef 00 00 00 00 	r2=\*\(i64\*\)\(r1\+0x7eef\)
> +  c0:	58 05 00 00 00 00 00 00 	r0=\*\(u64\*\)skb\[r5\+0x0\]
> +  c8:	61 21 00 00 00 00 00 00 	r2=\*\(u32\*\)\(r1\+0x0\)
> diff --git a/gas/testsuite/gas/bpf/mem-be.d b/gas/testsuite/gas/bpf/mem-be.d
> index 5746b6a9485..cd7b35c60a3 100644
> --- a/gas/testsuite/gas/bpf/mem-be.d
> +++ b/gas/testsuite/gas/bpf/mem-be.d
> @@ -31,4 +31,6 @@ Disassembly of section .text:
>    a0:	81 21 7e ef 00 00 00 00 	ldxsw %r2,\[%r1\+0x7eef\]
>    a8:	89 21 7e ef 00 00 00 00 	ldxsh %r2,\[%r1\+0x7eef\]
>    b0:	91 21 7e ef 00 00 00 00 	ldxsb %r2,\[%r1\+0x7eef\]
> -  b8:	99 21 7e ef 00 00 00 00 	ldxsdw %r2,\[%r1\+0x7eef\]
> \ No newline at end of file
> +  b8:	99 21 7e ef 00 00 00 00 	ldxsdw %r2,\[%r1\+0x7eef\]
> +  c0:	79 21 00 00 00 00 00 00 	ldxdw %r2,\[%r1\+0x0\]
> +  c8:	40 03 00 00 00 00 00 00 	ldindw %r3,0x0
> diff --git a/gas/testsuite/gas/bpf/mem-pseudoc.d b/gas/testsuite/gas/bpf/mem-pseudoc.d
> index 8481048504d..ca94cef51cf 100644
> --- a/gas/testsuite/gas/bpf/mem-pseudoc.d
> +++ b/gas/testsuite/gas/bpf/mem-pseudoc.d
> @@ -32,3 +32,5 @@ Disassembly of section .text:
>    a8:	89 12 ef 7e 00 00 00 00 	r2=\*\(i16\*\)\(r1\+0x7eef\)
>    b0:	91 12 ef 7e 00 00 00 00 	r2=\*\(i8\*\)\(r1\+0x7eef\)
>    b8:	99 12 ef 7e 00 00 00 00 	r2=\*\(i64\*\)\(r1\+0x7eef\)
> +  c0:	58 50 00 00 00 00 00 00 	r0=\*\(u64\*\)skb\[r5\+0x0\]
> +  c8:	61 12 00 00 00 00 00 00 	r2=\*\(u32\*\)\(r1\+0x0\)
> diff --git a/gas/testsuite/gas/bpf/mem-pseudoc.s b/gas/testsuite/gas/bpf/mem-pseudoc.s
> index 1ffa2e25926..4a5e588b91a 100644
> --- a/gas/testsuite/gas/bpf/mem-pseudoc.s
> +++ b/gas/testsuite/gas/bpf/mem-pseudoc.s
> @@ -25,3 +25,5 @@
>          r2 = *(i16*)(r1+0x7eef)
>          r2 = *(i8*)(r1+0x7eef)
>          r2 = *(i64*)(r1+0x7eef)
> +	r0 = *(u64 *)skb[r5 + 0]
> +	r2 = *(u32 *)(r1 + 0)
> diff --git a/gas/testsuite/gas/bpf/mem.d b/gas/testsuite/gas/bpf/mem.d
> index 8b7a488ae01..9a1e7095df0 100644
> --- a/gas/testsuite/gas/bpf/mem.d
> +++ b/gas/testsuite/gas/bpf/mem.d
> @@ -31,4 +31,6 @@ Disassembly of section .text:
>    a0:	81 12 ef 7e 00 00 00 00 	ldxsw %r2,\[%r1\+0x7eef\]
>    a8:	89 12 ef 7e 00 00 00 00 	ldxsh %r2,\[%r1\+0x7eef\]
>    b0:	91 12 ef 7e 00 00 00 00 	ldxsb %r2,\[%r1\+0x7eef\]
> -  b8:	99 12 ef 7e 00 00 00 00 	ldxsdw %r2,\[%r1\+0x7eef\]
> \ No newline at end of file
> +  b8:	99 12 ef 7e 00 00 00 00 	ldxsdw %r2,\[%r1\+0x7eef\]
> +  c0:	79 12 00 00 00 00 00 00 	ldxdw %r2,\[%r1\+0x0\]
> +  c8:	40 30 00 00 00 00 00 00 	ldindw %r3,0x0
> diff --git a/gas/testsuite/gas/bpf/mem.s b/gas/testsuite/gas/bpf/mem.s
> index 6323cf1ede7..adeda473bb8 100644
> --- a/gas/testsuite/gas/bpf/mem.s
> +++ b/gas/testsuite/gas/bpf/mem.s
> @@ -26,3 +26,5 @@
>          ldxsh %r2, [%r1+0x7eef]
>          ldxsb %r2, [%r1+0x7eef]
>          ldxsdw %r2, [%r1+0x7eef]
> +	ldxdw %r2, [%r1+0]
> +	ldindw %r3, 0
> diff --git a/opcodes/bpf-dis.c b/opcodes/bpf-dis.c
> index a4dc3dc2523..4fe0efc2f96 100644
> --- a/opcodes/bpf-dis.c
> +++ b/opcodes/bpf-dis.c
> @@ -215,7 +215,7 @@ print_insn_bpf (bfd_vma pc, disassemble_info *info)
>                    if (p[1] == 'I')
>                      (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
>                                                    "%s",
> -                                                  asm_obase != 10 || imm32 > 0 ? "+" : "");
> +						  asm_obase != 10 || imm32 >= 0 ? "+" : "");
>                    (*info->fprintf_styled_func) (info->stream, dis_style_immediate,
>                                                  asm_obase == 10 ? "%" PRIi32
>                                                  : asm_obase == 8 ? "%" PRIo32
> @@ -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,

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-21 19:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-21 17:58 [PATCH] bpf: disasemble offsets of value 0 as "+0" David Faust
2023-07-21 18:11 ` Jose E. Marchesi
2023-07-21 18:54   ` [PATCH v2] " David Faust
2023-07-21 19:21     ` Jose E. Marchesi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).