bdc76f
commit de10e44dda686e3ed6a7a1463869df846ea39825
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:10 2018 +0100
bdc76f
bdc76f
    S390: Refactor strnlen ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for strnlen is adjusted in order to omit ifunc
bdc76f
    variants if those will never be used as the minimum architecture level
bdc76f
    already supports newer CPUs by default.
bdc76f
    Glibc internal calls will then also use the "newer" ifunc variant.
bdc76f
    
bdc76f
    ChangeLog:
bdc76f
    
bdc76f
            * sysdeps/s390/multiarch/Makefile
bdc76f
            (sysdep_routines): Remove strnlen variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add strnlen variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for strnlen.
bdc76f
            * sysdeps/s390/multiarch/strnlen-c.c: Move to ...
bdc76f
            * sysdeps/s390/strnlen-c.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strnlen-vx.S: Move to ...
bdc76f
            * sysdeps/s390/strnlen-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strnlen.c: Move to ...
bdc76f
            * sysdeps/s390/strnlen.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-strnlen.h: New file.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index 600d8e629df7090e..f092355743e3908f 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -37,5 +37,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   memmove memmove-c \
bdc76f
 		   strstr strstr-vx strstr-c \
bdc76f
 		   memmem memmem-vx memmem-c \
bdc76f
-		   strlen strlen-vx strlen-c
bdc76f
+		   strlen strlen-vx strlen-c \
bdc76f
+		   strnlen strnlen-vx strnlen-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-strnlen.h b/sysdeps/s390/ifunc-strnlen.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..e92329888773304d
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-strnlen.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* strnlen variant information on S/390 version.
bdc76f
+   Copyright (C) 2018 Free Software Foundation, Inc.
bdc76f
+   This file is part of the GNU C Library.
bdc76f
+
bdc76f
+   The GNU C Library is free software; you can redistribute it and/or
bdc76f
+   modify it under the terms of the GNU Lesser General Public
bdc76f
+   License as published by the Free Software Foundation; either
bdc76f
+   version 2.1 of the License, or (at your option) any later version.
bdc76f
+
bdc76f
+   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
+   Lesser General Public License for more details.
bdc76f
+
bdc76f
+   You should have received a copy of the GNU Lesser General Public
bdc76f
+   License along with the GNU C Library; if not, see
bdc76f
+   <http://www.gnu.org/licenses/>.  */
bdc76f
+
bdc76f
+#if defined USE_MULTIARCH && IS_IN (libc)		\
bdc76f
+  && ! defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define HAVE_STRNLEN_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_STRNLEN_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_STRNLEN_IFUNC_AND_VX_SUPPORT HAVE_STRNLEN_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_STRNLEN_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define STRNLEN_DEFAULT	STRNLEN_Z13
bdc76f
+# define HAVE_STRNLEN_C		0
bdc76f
+# define HAVE_STRNLEN_Z13	1
bdc76f
+#else
bdc76f
+# define STRNLEN_DEFAULT	STRNLEN_C
bdc76f
+# define HAVE_STRNLEN_C		1
bdc76f
+# define HAVE_STRNLEN_Z13	HAVE_STRNLEN_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRNLEN_C
bdc76f
+# define STRNLEN_C		__strnlen_c
bdc76f
+#else
bdc76f
+# define STRNLEN_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRNLEN_Z13
bdc76f
+# define STRNLEN_Z13		__strnlen_vx
bdc76f
+#else
bdc76f
+# define STRNLEN_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index 601523919c235f76..35ba223c5d4fb52f 100644
bdc76f
--- a/sysdeps/s390/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/multiarch/Makefile
bdc76f
@@ -1,6 +1,5 @@
bdc76f
 ifeq ($(subdir),string)
bdc76f
-sysdep_routines += strnlen strnlen-vx strnlen-c \
bdc76f
-		   strcpy strcpy-vx \
bdc76f
+sysdep_routines += strcpy strcpy-vx \
bdc76f
 		   stpcpy stpcpy-vx stpcpy-c \
bdc76f
 		   strncpy strncpy-vx \
bdc76f
 		   stpncpy stpncpy-vx stpncpy-c \
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index c531be4bc7eb3f55..680e5b738bfb7f32 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -27,6 +27,7 @@
bdc76f
 #include <ifunc-strstr.h>
bdc76f
 #include <ifunc-memmem.h>
bdc76f
 #include <ifunc-strlen.h>
bdc76f
+#include <ifunc-strnlen.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -177,6 +178,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_STRLEN_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_STRNLEN_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, strnlen,
bdc76f
+# if HAVE_STRNLEN_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, strnlen,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, STRNLEN_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_STRNLEN_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, strnlen, 1, STRNLEN_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_STRNLEN_IFUNC  */
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
@@ -187,7 +200,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wcslen);
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (strnlen);
bdc76f
   IFUNC_VX_IMPL (wcsnlen);
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (strcpy);
bdc76f
diff --git a/sysdeps/s390/multiarch/strnlen-c.c b/sysdeps/s390/strnlen-c.c
bdc76f
similarity index 81%
bdc76f
rename from sysdeps/s390/multiarch/strnlen-c.c
bdc76f
rename to sysdeps/s390/strnlen-c.c
bdc76f
index 353e83ed356ca080..c2d887f1e4f504e8 100644
bdc76f
--- a/sysdeps/s390/multiarch/strnlen-c.c
bdc76f
+++ b/sysdeps/s390/strnlen-c.c
bdc76f
@@ -16,15 +16,19 @@
bdc76f
    License along with the GNU C Library; if not, see
bdc76f
    <http://www.gnu.org/licenses/>.  */
bdc76f
 
bdc76f
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
bdc76f
-# define STRNLEN  __strnlen_c
bdc76f
-# ifdef SHARED
bdc76f
-#  undef libc_hidden_def
bdc76f
-#  define libc_hidden_def(name)					\
bdc76f
+#include <ifunc-strnlen.h>
bdc76f
+
bdc76f
+#if HAVE_STRNLEN_C
bdc76f
+# if HAVE_STRNLEN_IFUNC
bdc76f
+#  define STRNLEN STRNLEN_C
bdc76f
+#  if defined SHARED && IS_IN (libc)
bdc76f
+#   undef libc_hidden_def
bdc76f
+#   define libc_hidden_def(name)					\
bdc76f
   __hidden_ver1 (__strnlen_c, __GI_strnlen, __strnlen_c);	\
bdc76f
   strong_alias (__strnlen_c, __strnlen_c_1);			\
bdc76f
   __hidden_ver1 (__strnlen_c_1, __GI___strnlen, __strnlen_c_1);
bdc76f
-# endif /* SHARED */
bdc76f
+#  endif
bdc76f
+# endif
bdc76f
 
bdc76f
 # include <string/strnlen.c>
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strnlen-vx.S b/sysdeps/s390/strnlen-vx.S
bdc76f
similarity index 90%
bdc76f
rename from sysdeps/s390/multiarch/strnlen-vx.S
bdc76f
rename to sysdeps/s390/strnlen-vx.S
bdc76f
index fc659a956cfc1fa1..0b8fe3da342f6803 100644
bdc76f
--- a/sysdeps/s390/multiarch/strnlen-vx.S
bdc76f
+++ b/sysdeps/s390/strnlen-vx.S
bdc76f
@@ -16,7 +16,9 @@
bdc76f
    License along with the GNU C Library; if not, see
bdc76f
    <http://www.gnu.org/licenses/>.  */
bdc76f
 
bdc76f
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
bdc76f
+#include <ifunc-strnlen.h>
bdc76f
+
bdc76f
+#if HAVE_STRNLEN_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -34,7 +36,7 @@
bdc76f
    -r5=current_len and return_value
bdc76f
    -v16=part of s
bdc76f
 */
bdc76f
-ENTRY(__strnlen_vx)
bdc76f
+ENTRY(STRNLEN_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -130,5 +132,16 @@ ENTRY(__strnlen_vx)
bdc76f
 	clgrjl	%r1,%r3,.Lloop64
bdc76f
 
bdc76f
 	j	.Llt64
bdc76f
-END(__strnlen_vx)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+END(STRNLEN_Z13)
bdc76f
+
bdc76f
+# if ! HAVE_STRNLEN_IFUNC
bdc76f
+strong_alias (STRNLEN_Z13, __strnlen)
bdc76f
+weak_alias (__strnlen, strnlen)
bdc76f
+# endif
bdc76f
+
bdc76f
+# if ! HAVE_STRNLEN_C && defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRNLEN_Z13, __GI_strnlen)
bdc76f
+strong_alias (STRNLEN_Z13, __GI___strnlen)
bdc76f
+# endif
bdc76f
+
bdc76f
+#endif /* HAVE_STRNLEN_Z13  */
bdc76f
diff --git a/sysdeps/s390/multiarch/strnlen.c b/sysdeps/s390/strnlen.c
bdc76f
similarity index 69%
bdc76f
rename from sysdeps/s390/multiarch/strnlen.c
bdc76f
rename to sysdeps/s390/strnlen.c
bdc76f
index 0f9cff5d69b017ae..aa4953d5035bc2fc 100644
bdc76f
--- a/sysdeps/s390/multiarch/strnlen.c
bdc76f
+++ b/sysdeps/s390/strnlen.c
bdc76f
@@ -16,7 +16,9 @@
bdc76f
    License along with the GNU C Library; if not, see
bdc76f
    <http://www.gnu.org/licenses/>.  */
bdc76f
 
bdc76f
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
bdc76f
+#include <ifunc-strnlen.h>
bdc76f
+
bdc76f
+#if HAVE_STRNLEN_IFUNC
bdc76f
 # define strnlen __redirect_strnlen
bdc76f
 # define __strnlen __redirect___strnlen
bdc76f
 # include <string.h>
bdc76f
@@ -24,9 +26,18 @@
bdc76f
 # undef __strnlen
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 
bdc76f
-s390_vx_libc_ifunc_redirected (__redirect___strnlen, __strnlen)
bdc76f
-weak_alias (__strnlen, strnlen)
bdc76f
+# if HAVE_STRNLEN_C
bdc76f
+extern __typeof (__redirect_strnlen) STRNLEN_C attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
-#else
bdc76f
-# include <string/strnlen.c>
bdc76f
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
bdc76f
+# if HAVE_STRNLEN_Z13
bdc76f
+extern __typeof (__redirect_strnlen) STRNLEN_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+s390_libc_ifunc_expr (__redirect___strnlen, __strnlen,
bdc76f
+		      (HAVE_STRNLEN_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? STRNLEN_Z13
bdc76f
+		      : STRNLEN_DEFAULT
bdc76f
+		      )
bdc76f
+weak_alias (__strnlen, strnlen)
bdc76f
+#endif /* HAVE_STRNLEN_IFUNC  */