]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 498492 - none/tests/amd64/lzcnt64 crashes on FreeBSD compiled with clang
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sat, 11 Jan 2025 11:28:00 +0000 (12:28 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sat, 11 Jan 2025 11:28:00 +0000 (12:28 +0100)
Using push in inline asm is a bit risky. It worked by luck with
GCC. Fix it by shifting down RSP by 1024 and before the test
and restoring it after.

NEWS
none/tests/amd64/lzcnt64.c

diff --git a/NEWS b/NEWS
index e25d1d8b81cdcafc763479452aa169cef70cf961..5c576ff33e4c6679126dcf5305ba38df936a0c05 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 498317  FdBadUse is not a valid CoreError type in a suppression
         even though it's generated by --gen-suppressions=yes
 498143  False positive on EVIOCGRAB ioctl
+498492  none/tests/amd64/lzcnt64 crashes on FreeBSD compiled with clang
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
index 22fa353b8dd51221dce08df9937524c101738001..d2b14d6911d3f475b12783e735967a3d8da1a838 100644 (file)
@@ -9,12 +9,14 @@ void do_lzcnt64 ( /*OUT*/UInt* flags, /*OUT*/ULong* res, ULong arg )
 {
   ULong block[3] = { arg, 0ULL, 0ULL };
   __asm__ __volatile__(
+    "subq $1024, %%rsp\n\t"
     "movabsq $0x5555555555555555, %%r11" "\n\t"
     "lzcntq 0(%0), %%r11"     "\n\t"
     "movq %%r11, 8(%0)"       "\n\t"
     "pushfq"                  "\n\t"
     "popq %%r11"              "\n\t"
-    "movq %%r11, 16(%0)"      "\n"
+    "movq %%r11, 16(%0)"      "\n\t"
+    "addq $1024, %%rsp"       "\n"
     : : "r"(&block[0]) : "r11","cc","memory"
   );
   *res = block[1];
@@ -26,12 +28,14 @@ void do_lzcnt32 ( /*OUT*/UInt* flags, /*OUT*/ULong* res, ULong arg )
 {
   ULong block[3] = { arg, 0ULL, 0ULL };
   __asm__ __volatile__(
+    "subq $1024, %%rsp\n\t"
     "movabsq $0x5555555555555555, %%r11" "\n\t"
     "lzcntl 0(%0), %%r11d"    "\n\t"
     "movq %%r11, 8(%0)"       "\n\t"
     "pushfq"                  "\n\t"
     "popq %%r11"              "\n\t"
-    "movq %%r11, 16(%0)"      "\n"
+    "movq %%r11, 16(%0)"      "\n\t"
+    "addq $1024, %%rsp"       "\n"
     : : "r"(&block[0]) : "r11","cc","memory"
   );
   *res = block[1];
@@ -43,12 +47,14 @@ void do_lzcnt16 ( /*OUT*/UInt* flags, /*OUT*/ULong* res, ULong arg )
 {
   ULong block[3] = { arg, 0ULL, 0ULL };
   __asm__ __volatile__(
+    "subq $1024, %%rsp\n\t"
     "movabsq $0x5555555555555555, %%r11" "\n\t"
     "lzcntw 0(%0), %%r11w"    "\n\t"
     "movq %%r11, 8(%0)"       "\n\t"
     "pushfq"                  "\n\t"
     "popq %%r11"              "\n\t"
-    "movq %%r11, 16(%0)"      "\n"
+    "movq %%r11, 16(%0)"      "\n\t"
+    "addq $1024, %%rsp"       "\n"
     : : "r"(&block[0]) : "r11","cc","memory"
   );
   *res = block[1];