valgrind/SOURCES/0012-Bug-487439-SIGILL-in-JDK11-JDK17.patch

185 lines
6.0 KiB
Diff

From e62c7b4f9ee0a8c20c7211a92ad512f925e9515c Mon Sep 17 00:00:00 2001
From: Paul Floyd <pjfloyd@wanadoo.fr>
Date: Sun, 16 Jun 2024 09:25:51 +0200
Subject: [PATCH 12/15] Bug 487439 - SIGILL in JDK11, JDK17
(cherry picked from commit c19d19d34a6dadaf4a9d590f516f813e9cbacdd0)
---
.gitignore | 1 +
NEWS | 1 +
VEX/priv/guest_amd64_toIR.c | 2 +-
none/tests/amd64/Makefile.am | 3 +
none/tests/amd64/bug487439.cpp | 83 +++++++++++++++++++++++++++
none/tests/amd64/bug487439.stderr.exp | 0
none/tests/amd64/bug487439.stdout.exp | 1 +
none/tests/amd64/bug487439.vgtest | 2 +
8 files changed, 92 insertions(+), 1 deletion(-)
create mode 100644 none/tests/amd64/bug487439.cpp
create mode 100644 none/tests/amd64/bug487439.stderr.exp
create mode 100644 none/tests/amd64/bug487439.stdout.exp
create mode 100644 none/tests/amd64/bug487439.vgtest
diff --git a/NEWS b/NEWS
index c2ad6a207d96..fbe0f012ef0c 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ The following bugs have been fixed or resolved on this branch.
486180 [MIPS] 'VexGuestArchState' has no member named 'guest_IP_AT_SYSCALL'
486293 memccpy false positives
486569 linux inotify_init syscall wrapper missing POST entry in syscall_table
+487439 SIGILL in JDK11, JDK17
n-i-bz aarch64 frinta and frinta vector instructions
To see details of a given bug, visit
diff --git a/VEX/priv/guest_amd64_toIR.c b/VEX/priv/guest_amd64_toIR.c
index f0b1c5516267..28c37f092211 100644
--- a/VEX/priv/guest_amd64_toIR.c
+++ b/VEX/priv/guest_amd64_toIR.c
@@ -14138,7 +14138,7 @@ Long dis_ESC_0F__SSE2 ( Bool* decode_OK,
goto decode_success;
}
/* 66 0F 73 /6 ib = PSLLQ by immediate */
- if (have66noF2noF3(pfx) && sz == 2
+ if (have66noF2noF3(pfx) && (sz == 2 || /* ignore redundant REX.W */ sz == 8)
&& epartIsReg(getUChar(delta))
&& gregLO3ofRM(getUChar(delta)) == 6) {
delta = dis_SSE_shiftE_imm( pfx, delta, "psllq", Iop_ShlN64x2 );
diff --git a/none/tests/amd64/Makefile.am b/none/tests/amd64/Makefile.am
index dc0498018209..83029c15590c 100644
--- a/none/tests/amd64/Makefile.am
+++ b/none/tests/amd64/Makefile.am
@@ -44,6 +44,7 @@ EXTRA_DIST = \
bug156404-amd64.vgtest bug156404-amd64.stdout.exp \
bug156404-amd64.stderr.exp \
bug485148.vgtest bug485148.stdout.exp bug485148.stderr.exp \
+ bug487439.vgtest bug487439.stdout.exp bug487439.stderr.exp \
cet_nops.vgtest cet_nops.stdout.exp cet_nops.stderr.exp \
clc.vgtest clc.stdout.exp clc.stderr.exp \
crc32.vgtest crc32.stdout.exp crc32.stderr.exp \
@@ -107,6 +108,7 @@ check_PROGRAMS = \
amd64locked \
bt_flags \
bug127521-64 bug132813-amd64 bug132918 bug137714-amd64 \
+ bug487439 \
cet_nops \
clc \
cmpxchg \
@@ -204,6 +206,7 @@ amd64locked_CFLAGS = $(AM_CFLAGS) -O
bug132918_LDADD = -lm
bug485148_CXXFLAGS = ${AM_CXXFLAGS} -mfma
bug485148_SOURCES = bug485148.cpp
+bug487439_SOURCES = bug487439.cpp
cmpxchg_CFLAGS = $(AM_CFLAGS) @FLAG_NO_PIE@
fb_test_amd64_CFLAGS = $(AM_CFLAGS) -O -fno-strict-aliasing
fb_test_amd64_LDADD = -lm
diff --git a/none/tests/amd64/bug487439.cpp b/none/tests/amd64/bug487439.cpp
new file mode 100644
index 000000000000..f86bb65ce9eb
--- /dev/null
+++ b/none/tests/amd64/bug487439.cpp
@@ -0,0 +1,83 @@
+// This is more or less a copy/paste from the generated insn_sse2.c
+// I didn't want to mess with the perl generator because
+// GCC and clang don't agree on the asm syntax
+// Using the rex prefix looks like a bug or misfeature in OpenJDK
+// so I'm assuming that this is a one-off and not a general issue
+
+#include <iostream>
+#include <csetjmp>
+#include <csignal>
+
+union reg128_t {
+ char sb[16];
+ unsigned char ub[16];
+ short sw[8];
+ unsigned short uw[8];
+ int sd[4];
+ unsigned int ud[4];
+ long long int sq[2];
+ unsigned long long int uq[2];
+ float ps[4];
+ double pd[2];
+} __attribute__ ((aligned (16)));
+
+static sigjmp_buf catchpoint;
+
+static void handle_sigill(int signum)
+{
+ siglongjmp(catchpoint, 1);
+}
+
+/* with redundant rex.W */
+static void psllq_4(void)
+{
+ reg128_t arg1 = { .uq = { 0x0123456789abcdefULL, 0x0123456789abcdefULL } };
+ reg128_t result0;
+ char state[108];
+
+ if (sigsetjmp(catchpoint, 1) == 0)
+ {
+ asm(
+ "ffree %%st(7)\n"
+ "ffree %%st(6)\n"
+ "ffree %%st(5)\n"
+ "ffree %%st(4)\n"
+ "movlps %2, %%xmm1\n"
+ "movhps %3, %%xmm1\n"
+ // only GCC
+ //".rex.W psllq $12, %%xmm1\n"
+ // only clang
+ //"data16 rex64 psllq $12, %mm1\n"
+ ".byte 0x66,0x48,0x0f,0x73,0xf1,0x0c\n"
+ "movlps %%xmm1, %0\n"
+ "movhps %%xmm1, %1\n"
+ "cld\n"
+ : "=m" (result0.uq[0]), "=m" (result0.uq[1])
+ : "m" (arg1.uq[0]), "m" (arg1.uq[1]), "m" (state[0])
+ : "xmm1"
+ );
+
+ if (result0.uq[0] == 0x3456789abcdef000ULL && result0.uq[1] == 0x3456789abcdef000ULL )
+ {
+ std::cout << "psllq_4 ... ok\n";
+ }
+ else
+ {
+ std::cout << "psllq_4 ... not ok\n";
+ std::cout << " result0.uq[0] = " << result0.uq[0] << " (expected " << 0x3456789abcdef000ULL << ")\n";
+ std::cout << " result0.uq[1] = " << result0.uq[1] << " (expected " << 0x3456789abcdef000ULL << ")\n";
+ }
+ }
+ else
+ {
+ std::cout << "psllq_4 ... failed\n";
+ }
+
+ return;
+}
+
+int main()
+{
+ signal(SIGILL, handle_sigill);
+ psllq_4();
+}
diff --git a/none/tests/amd64/bug487439.stderr.exp b/none/tests/amd64/bug487439.stderr.exp
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/none/tests/amd64/bug487439.stdout.exp b/none/tests/amd64/bug487439.stdout.exp
new file mode 100644
index 000000000000..065b518a27d7
--- /dev/null
+++ b/none/tests/amd64/bug487439.stdout.exp
@@ -0,0 +1 @@
+psllq_4 ... ok
diff --git a/none/tests/amd64/bug487439.vgtest b/none/tests/amd64/bug487439.vgtest
new file mode 100644
index 000000000000..3faa1ed6b014
--- /dev/null
+++ b/none/tests/amd64/bug487439.vgtest
@@ -0,0 +1,2 @@
+prog: bug487439
+vgopts: -q
--
2.45.2