[PATCH] kvx: fix kvx_reassemble_bundle index 8 out of bounds
Paul Iannetta
piannetta@kalrayinc.com
Thu Sep 7 15:27:31 GMT 2023
On Thu, Sep 07, 2023 at 10:16:28PM +0930, Alan Modra wrote:
> On Thu, Aug 24, 2023 at 11:26:49AM +0200, Paul Iannetta wrote:
> > > > * kvx-dis.c (print_insn_kvx): Change the loop condition so that
> > > > wordcount is always less than KVXMAXBUNDLEWORDS.
>
> Hi Paul,
> Does the following patch look good to you, and can you please craft a
> testcase that exercises a maximum size bundle?
>
> While the patch already committed for pr30793 prevents the asan error,
> there is a problem: Now the last element of bundle_words never gets
> written. That's very likely wrong, or KVXMAXBUNDLEWORDS is too big.
> So this patch rearranges things a little to support writing of all of
> bundle_words and does the parallel bit checking only when filling
> bundle_words. In the normal case, kvx_reassemble_bundle will see
> bundle_words[word_count-1] with the parallel bit clear and all other
> words having it set. In the error case where all words in
> bundle_words have the parallel bit set, kvx_reassemble_bundle will be
> passed a wordcount of KVXMAXBUNDLEWORDS + 1. I've also made
> kvx_reassemble_bundle return true for success rather than zero, and
> removed the unnecessary check for zero wordcount.
Hi Alan,
Thank you for catching this, your patch looks good to me. Below is a
patch which adds a test case, you can merge it with yours if you want.
Thanks,
--
Paul
Kalray
commit 8dbb32052cb0e1e5ea1569e3fb708582f8158290
Author: Paul Iannetta <piannetta@kalrayinc.com>
Date: Thu Sep 7 17:10:01 2023 +0200
kvx: Add a testcase for bundles with KVXMAXBUNDLEWORDS syllables
The previous fix (f1917fc) for pr30793 introduced a bug when dealing
with bundles of with KVXMAXBUNDLEWORDS syllables. This adds a test case
to ensure that such bundle are correctly disassembled.
gas/ChangeLog:
2023-09-07 Paul Iannetta <piannetta@kalrayinc.com>
* testsuite/gas/kvx/fat-bundles.s: New test.
* testsuite/gas/kvx/kv3-1-fat-bundles.d: New test.
* testsuite/gas/kvx/kv3-2-fat-bundles.d: New test.
diff --git a/gas/testsuite/gas/kvx/fat-bundles.s b/gas/testsuite/gas/kvx/fat-bundles.s
new file mode 100644
index 00000000000..8119c6043de
--- /dev/null
+++ b/gas/testsuite/gas/kvx/fat-bundles.s
@@ -0,0 +1,13 @@
+# The bundles in this file all have 8 syllables.
+
+ addd $r0 = $r0, 123456789010 # 1 ALU + 2 Immediate Extensions
+ addd $r0 = $r0, 123456789010 # 1 ALU + 2 Immediate Extensions
+ addd $r1 = $r2, 1234 # 1 ALU + 1 Immediate Extension
+ ;;
+ igoto $r0 # 1 BCU
+ xmt44d $a0a1a2a3 = $a0a1a2a3 # 1 TCA
+ addd $r0 = $r0, 1234 # 1 ALU + 1 Immediate Extension
+ addd $r0 = $r0, 12345678901 # 1 ALU + 1 Immediate Extension
+ fmuld $r1 = $r2, $r3 # 1 MAU
+ lwz $r0 = 0[$r0] # 1 LSU
+ ;;
diff --git a/gas/testsuite/gas/kvx/kv3-1-fat-bundles.d b/gas/testsuite/gas/kvx/kv3-1-fat-bundles.d
new file mode 100644
index 00000000000..1f80e0444fd
--- /dev/null
+++ b/gas/testsuite/gas/kvx/kv3-1-fat-bundles.d
@@ -0,0 +1,20 @@
+#as: -march=kv3-1
+#objdump: -d
+#source: fat-bundles.s
+.*\/fat-bundles.o: file format elf64-kvx
+
+
+Disassembly of section .text:
+
+0000000000000000 <.text>:
+ 0: 82 34 04 e1 80 84 00 e1 addd \$r1 = \$r2, 1234 \(0x4d2\)
+ 8: 80 84 00 e1 01 00 00 80 46 a6 2f 8f addd \$r0 = \$r0, 123456789010 \(0x1cbe991a12\)
+ 14: 00 00 00 88 46 a6 2f 97 00 00 00 10 addd \$r0 = \$r0, 123456789010 \(0x1cbe991a12\);;
+
+ 20: 00 00 d8 8f igoto \$r0
+ 24: 00 00 0c 84 xmt44d \$a0a1a2a3 = \$a0a1a2a3
+ 28: 80 34 00 e1 40 0d 00 e1 addd \$r0 = \$r0, 1234 \(0x4d2\)
+ 30: c2 70 05 d8 00 00 00 b0 addd \$r0 = \$r0, 12345678901 \(0x2dfdc1c35\)
+ 38: 01 00 00 80 fmuld \$r1 = \$r2, \$r3
+ 3c: 07 f7 b7 08 lwz \$r0 = 0 \(0x0\)\[\$r0\];;
+
diff --git a/gas/testsuite/gas/kvx/kv3-2-fat-bundles.d b/gas/testsuite/gas/kvx/kv3-2-fat-bundles.d
new file mode 100644
index 00000000000..54717eb55b4
--- /dev/null
+++ b/gas/testsuite/gas/kvx/kv3-2-fat-bundles.d
@@ -0,0 +1,20 @@
+#as: -march=kv3-2
+#objdump: -d
+#source: fat-bundles.s
+.*\/fat-bundles.o: file format elf64-kvx
+
+
+Disassembly of section .text:
+
+0000000000000000 <.text>:
+ 0: 82 34 04 e2 80 84 00 e2 addd \$r1 = \$r2, 1234 \(0x4d2\)
+ 8: 80 84 00 e2 01 00 00 80 46 a6 2f 8f addd \$r0 = \$r0, 123456789010 \(0x1cbe991a12\)
+ 14: 00 00 00 88 46 a6 2f 97 00 00 00 10 addd \$r0 = \$r0, 123456789010 \(0x1cbe991a12\);;
+
+ 20: 00 00 d8 8f igoto \$r0
+ 24: 00 10 05 87 xcopyv.td \$a0a1a2a3 = \$a0a1a2a3
+ 28: 80 34 00 e2 40 0d 00 e2 addd \$r0 = \$r0, 1234 \(0x4d2\)
+ 30: c2 70 05 d8 00 00 00 b0 addd \$r0 = \$r0, 12345678901 \(0x2dfdc1c35\)
+ 38: 01 00 00 80 fmuld \$r1 = \$r2, \$r3
+ 3c: 07 f7 b7 08 lwz \$r0 = 0 \(0x0\)\[\$r0\];;
+
More information about the Binutils
mailing list