mirror of
https://sourceware.org/git/glibc.git
synced 2025-10-27 12:15:39 +03:00
x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
In the overflow fallback strncmp-avx2-rtm and wcsncmp-avx2-rtm would call strcmp-avx2 and wcscmp-avx2 respectively. This would have not checks around vzeroupper and would trigger spurious aborts. This commit fixes that. test-strcmp, test-strncmp, test-wcscmp, and test-wcsncmp all pass on AVX2 machines with and without RTM. Co-authored-by: H.J. Lu <hjl.tools@gmail.com>
This commit is contained in:
@@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
|
|||||||
CFLAGS-tst-strchr-rtm.c += -mrtm
|
CFLAGS-tst-strchr-rtm.c += -mrtm
|
||||||
CFLAGS-tst-strcpy-rtm.c += -mrtm
|
CFLAGS-tst-strcpy-rtm.c += -mrtm
|
||||||
CFLAGS-tst-strlen-rtm.c += -mrtm
|
CFLAGS-tst-strlen-rtm.c += -mrtm
|
||||||
CFLAGS-tst-strncmp-rtm.c += -mrtm
|
CFLAGS-tst-strncmp-rtm.c += -mrtm -Wno-error
|
||||||
CFLAGS-tst-strrchr-rtm.c += -mrtm
|
CFLAGS-tst-strrchr-rtm.c += -mrtm
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <tst-string-rtm.h>
|
#include <tst-string-rtm.h>
|
||||||
|
|
||||||
#define LOOP 3000
|
#define LOOP 3000
|
||||||
@@ -45,8 +46,22 @@ function (void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__ ((noinline, noclone))
|
||||||
|
static int
|
||||||
|
function_overflow (void)
|
||||||
|
{
|
||||||
|
if (strncmp (string1, string2, SIZE_MAX) == 0)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_test (void)
|
do_test (void)
|
||||||
{
|
{
|
||||||
return do_test_1 ("strncmp", LOOP, prepare, function);
|
int status = do_test_1 ("strncmp", LOOP, prepare, function);
|
||||||
|
if (status != EXIT_SUCCESS)
|
||||||
|
return status;
|
||||||
|
status = do_test_1 ("strncmp", LOOP, prepare, function_overflow);
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,10 +193,10 @@ L(ret_zero):
|
|||||||
.p2align 4,, 5
|
.p2align 4,, 5
|
||||||
L(one_or_less):
|
L(one_or_less):
|
||||||
jb L(ret_zero)
|
jb L(ret_zero)
|
||||||
# ifdef USE_AS_WCSCMP
|
|
||||||
/* 'nbe' covers the case where length is negative (large
|
/* 'nbe' covers the case where length is negative (large
|
||||||
unsigned). */
|
unsigned). */
|
||||||
jnbe __wcscmp_avx2
|
jnbe OVERFLOW_STRCMP
|
||||||
|
# ifdef USE_AS_WCSCMP
|
||||||
movl (%rdi), %edx
|
movl (%rdi), %edx
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
cmpl (%rsi), %edx
|
cmpl (%rsi), %edx
|
||||||
@@ -205,10 +205,6 @@ L(one_or_less):
|
|||||||
negl %eax
|
negl %eax
|
||||||
orl $1, %eax
|
orl $1, %eax
|
||||||
# else
|
# else
|
||||||
/* 'nbe' covers the case where length is negative (large
|
|
||||||
unsigned). */
|
|
||||||
|
|
||||||
jnbe __strcmp_avx2
|
|
||||||
movzbl (%rdi), %eax
|
movzbl (%rdi), %eax
|
||||||
movzbl (%rsi), %ecx
|
movzbl (%rsi), %ecx
|
||||||
subl %ecx, %eax
|
subl %ecx, %eax
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
#define STRCMP __strncmp_avx2_rtm
|
#define STRCMP __strncmp_avx2_rtm
|
||||||
#define USE_AS_STRNCMP 1
|
#define USE_AS_STRNCMP 1
|
||||||
|
#define OVERFLOW_STRCMP __strcmp_avx2_rtm
|
||||||
#include "strcmp-avx2-rtm.S"
|
#include "strcmp-avx2-rtm.S"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
#define STRCMP __strncmp_avx2
|
#define STRCMP __strncmp_avx2
|
||||||
#define USE_AS_STRNCMP 1
|
#define USE_AS_STRNCMP 1
|
||||||
|
#define OVERFLOW_STRCMP __strcmp_avx2
|
||||||
#include "strcmp-avx2.S"
|
#include "strcmp-avx2.S"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#define STRCMP __wcsncmp_avx2_rtm
|
#define STRCMP __wcsncmp_avx2_rtm
|
||||||
#define USE_AS_STRNCMP 1
|
#define USE_AS_STRNCMP 1
|
||||||
#define USE_AS_WCSCMP 1
|
#define USE_AS_WCSCMP 1
|
||||||
|
#define OVERFLOW_STRCMP __wcscmp_avx2_rtm
|
||||||
#include "strcmp-avx2-rtm.S"
|
#include "strcmp-avx2-rtm.S"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#define STRCMP __wcsncmp_avx2
|
#define STRCMP __wcsncmp_avx2
|
||||||
#define USE_AS_STRNCMP 1
|
#define USE_AS_STRNCMP 1
|
||||||
#define USE_AS_WCSCMP 1
|
#define USE_AS_WCSCMP 1
|
||||||
|
#define OVERFLOW_STRCMP __wcscmp_avx2
|
||||||
#include "strcmp-avx2.S"
|
#include "strcmp-avx2.S"
|
||||||
|
|||||||
Reference in New Issue
Block a user