From: Paul Floyd Date: Sat, 11 Jan 2025 11:28:00 +0000 (+0100) Subject: Bug 498492 - none/tests/amd64/lzcnt64 crashes on FreeBSD compiled with clang X-Git-Tag: VALGRIND_3_25_0~176 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5b2fed0f5a4471d87d0763172f29332cf4cc6abe;p=thirdparty%2Fvalgrind.git Bug 498492 - none/tests/amd64/lzcnt64 crashes on FreeBSD compiled with clang 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. --- diff --git a/NEWS b/NEWS index e25d1d8b8..5c576ff33 100644 --- 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 diff --git a/none/tests/amd64/lzcnt64.c b/none/tests/amd64/lzcnt64.c index 22fa353b8..d2b14d691 100644 --- a/none/tests/amd64/lzcnt64.c +++ b/none/tests/amd64/lzcnt64.c @@ -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];