public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Jose E. Marchesi" <jose.marchesi@oracle.com>
To: gdb-patches@sourceware.org
Subject: [COMMITTED] bpf: sim: do not overflow instruction immediates in tests
Date: Mon, 31 Jul 2023 11:11:08 +0200	[thread overview]
Message-ID: <20230731091108.10095-1-jose.marchesi@oracle.com> (raw)

This patch fixes some instructions in the BPF tests that overflow the
signed immediates.  Note that this happened to work before by chance,
as GAS would silently truncate.

Tested in bpf-unknown-none.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
---
 sim/testsuite/bpf/alu.s   | 4 ++--
 sim/testsuite/bpf/alu32.s | 6 +++---
 sim/testsuite/bpf/ldabs.s | 8 ++++----
 sim/testsuite/bpf/mem.s   | 2 +-
 sim/testsuite/bpf/mov.s   | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/sim/testsuite/bpf/alu.s b/sim/testsuite/bpf/alu.s
index 4dc37b1f01a..acba7b86cc6 100644
--- a/sim/testsuite/bpf/alu.s
+++ b/sim/testsuite/bpf/alu.s
@@ -59,7 +59,7 @@ main:
     fail_ne     %r2, 0x0000000050000000
 
     ;; or
-    or          %r2, 0xdeadbeef
+    or          %r2, -559038737         ; 0xdeadbeef
     fail_ne     %r2, 0xffffffffdeadbeef ; 0xdeadbeef gets sign extended
     lddw        %r1, 0xdead00000000beef
     lddw        %r2, 0x0000123456780000
@@ -67,7 +67,7 @@ main:
     fail_ne     %r1, 0xdead12345678beef
 
     ;; lsh
-    mov         %r1, 0xdeadbeef
+    mov         %r1, -559038737         ; 0xdeadbeef
     lsh         %r1, 11
     fail_ne     %r1, 0xfffffef56df77800 ; because deadbeef gets sign ext.
     mov         %r2, 21
diff --git a/sim/testsuite/bpf/alu32.s b/sim/testsuite/bpf/alu32.s
index e8d5062476c..d129f0fa7e0 100644
--- a/sim/testsuite/bpf/alu32.s
+++ b/sim/testsuite/bpf/alu32.s
@@ -58,7 +58,7 @@ main:
     lsh32       %r1, 4          ; r1 <<= 4 (r1 = 0xf0)
     mov32       %r2, 24         ; r2 = 24
     lsh32       %r1, %r2
-    fail_ne32   %r1, 0xf0000000
+    fail_ne32   %r1, -268435456 ; 0xf0000000
 
     ;; rsh (right logical shift)
     rsh32       %r1, 2
@@ -67,7 +67,7 @@ main:
 
     ;; arsh (right arithmetic shift)
     arsh32      %r1, 1
-    or32        %r1, 0x80000000
+    or32        %r1, -2147483648 ; 0x80000000
     mov32       %r2, 3
     arsh32      %r1, %r2
     fail_ne     %r1, 0x00000000F0000003
@@ -92,7 +92,7 @@ main:
     ;; xor
     xor32       %r1, %r2
     fail_ne32   %r1, 4
-    xor32       %r1, 0xF000000F
+    xor32       %r1, -268435441 ; 0xF000000F
     fail_ne     %r1, 0xF000000B ; Note: check for (bad) sign-extend
     xor32       %r1, %r1
     fail_ne     %r1, 0
diff --git a/sim/testsuite/bpf/ldabs.s b/sim/testsuite/bpf/ldabs.s
index ae777f1cf54..f54b8054477 100644
--- a/sim/testsuite/bpf/ldabs.s
+++ b/sim/testsuite/bpf/ldabs.s
@@ -34,13 +34,13 @@ main:
     ;; Write the value 0x7eadbeef into memory at 0x2004
     ;; i.e. offset 4 within the data buffer pointed to by
     ;; ((struct sk_buff *)r6)->data
-    stw         [%r6+0x1004], 0xdeadbeef
+    stw         [%r6+0x1004], 0x0eadbeef
 
     ;; Now load data[4] into r0 using the ldabsw instruction
     ldabsw      0x4
 
     ;; ...and compare to what we expect
-    fail_ne32   %r0, 0xdeadbeef
+    fail_ne32   %r0, 0x0eadbeef
 
     ;; Repeat for a half-word (2-bytes)
     sth         [%r6+0x1008], 0x1234
@@ -62,10 +62,10 @@ main:
 
     ;; Now, we do the same for the indirect loads
     mov         %r7, 0x100
-    stw         [%r6+0x1100], 0xfeedbeef
+    stw         [%r6+0x1100], 0x0eedbeef
 
     ldindw      %r7, 0x0
-    fail_ne32   %r0, 0xfeedbeef
+    fail_ne32   %r0, 0x0eedbeef
 
     ;; half-word
     sth         [%r6+0x1104], 0x6789
diff --git a/sim/testsuite/bpf/mem.s b/sim/testsuite/bpf/mem.s
index f9c6a193eab..26931ae5fba 100644
--- a/sim/testsuite/bpf/mem.s
+++ b/sim/testsuite/bpf/mem.s
@@ -20,7 +20,7 @@ main:
 
     stb         [%r2+16], 0x5a
     sth         [%r2+18], 0xcafe
-    stw         [%r2+20], 0xbeefface
+    stw         [%r2+20], -1091568946 ; 0xbeefface
     stdw        [%r2+24], 0x7eadbeef
 
     ldxb        %r1, [%r2+16]
diff --git a/sim/testsuite/bpf/mov.s b/sim/testsuite/bpf/mov.s
index 6665450468c..f7585c1dcb2 100644
--- a/sim/testsuite/bpf/mov.s
+++ b/sim/testsuite/bpf/mov.s
@@ -30,7 +30,7 @@ main:
     mov         %r2, -1
     fail_ne     %r2, 0xffffffffffffffff
 
-    mov         %r3, 0x80000000
+    mov         %r3, -2147483648 ; 0x80000000
 
     ;; should NOT sign extend
     mov32       %r4, %r3
-- 
2.30.2


                 reply	other threads:[~2023-07-31  9:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230731091108.10095-1-jose.marchesi@oracle.com \
    --to=jose.marchesi@oracle.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).