]> sourceware.org Git - glibc.git/commitdiff
x86: Fallback {str|wcs}cmp RTM in the ncmp overflow case [BZ #28896]
authorNoah Goldstein <goldstein.w.n@gmail.com>
Tue, 15 Feb 2022 14:18:15 +0000 (08:18 -0600)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 18 Feb 2022 18:57:38 +0000 (10:57 -0800)
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>
(cherry picked from commit c6272098323153db373f2986c67786ea8c85f1cf)

sysdeps/x86/Makefile
sysdeps/x86/tst-strncmp-rtm.c
sysdeps/x86_64/multiarch/strcmp-avx2.S
sysdeps/x86_64/multiarch/strncmp-avx2-rtm.S
sysdeps/x86_64/multiarch/strncmp-avx2.S
sysdeps/x86_64/multiarch/wcsncmp-avx2-rtm.S
sysdeps/x86_64/multiarch/wcsncmp-avx2.S

index 6cf708335c169f128e33bab944c1e94d70fa6571..d110f7b7f2a437013f03cde545e3455e8049c5bf 100644 (file)
@@ -109,7 +109,7 @@ CFLAGS-tst-memset-rtm.c += -mrtm
 CFLAGS-tst-strchr-rtm.c += -mrtm
 CFLAGS-tst-strcpy-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
 endif
 
index 09ed6fa0d66cab30b4e157fbf2aed18f19680b11..9e20abaaccfd57791dbc69066c13d82e01dffb96 100644 (file)
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <stdint.h>
 #include <tst-string-rtm.h>
 
 #define LOOP 3000
@@ -45,8 +46,22 @@ function (void)
     return 1;
 }
 
+__attribute__ ((noinline, noclone))
+static int
+function_overflow (void)
+{
+  if (strncmp (string1, string2, SIZE_MAX) == 0)
+    return 0;
+  else
+    return 1;
+}
+
 static int
 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;
 }
index 9c73b5899d55a72b292f21b52593284cd513d2a3..cdcb3c5a269a49db948bcd456141ae6eaf7a1f3e 100644 (file)
@@ -95,7 +95,7 @@ ENTRY (STRCMP)
           length to bound a valid memory region. In these cases just use
           'wcscmp'.  */
        shrq    $56, %rcx
-       jnz     __wcscmp_avx2
+       jnz     OVERFLOW_STRCMP
 #  endif
        /* Convert units: from wide to byte char.  */
        shl     $2, %RDX_LP
index 37d1224bb9b7056bbfd47e3ac2bc3675aee3f1f4..68bad365ba728eecc879a847341ba7eb7e700be7 100644 (file)
@@ -1,3 +1,4 @@
 #define STRCMP __strncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP        __strcmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
index 1678bcc235a4bc6a1c9715aa6a225a85d035df6b..f138e9f1fdcf277c35fd8fc54faf950a33464efb 100644 (file)
@@ -1,3 +1,4 @@
 #define STRCMP __strncmp_avx2
 #define USE_AS_STRNCMP 1
+#define OVERFLOW_STRCMP __strcmp_avx2
 #include "strcmp-avx2.S"
index 4e88c70cc696b82d411b120b765a9e4532b05a41..f467582cbedd45357be8f4e37b66edf8ed4bd4c5 100644 (file)
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2_rtm
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP        __wcscmp_avx2_rtm
 #include "strcmp-avx2-rtm.S"
index 4fa1de4d3f1f97ff666164153c14ae3caa6d60aa..e9ede522b8bde27d1ebea2ad12aeca5b23442710 100644 (file)
@@ -1,5 +1,5 @@
 #define STRCMP __wcsncmp_avx2
 #define USE_AS_STRNCMP 1
 #define USE_AS_WCSCMP 1
-
+#define OVERFLOW_STRCMP        __wcscmp_avx2
 #include "strcmp-avx2.S"
This page took 0.053899 seconds and 5 git commands to generate.