bdc76f
commit ff3ca3743a00af749258cc242457b648d65a1537
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:10 2018 +0100
bdc76f
bdc76f
    S390: Refactor strlen ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for strlen 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 strlen variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add strlen variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for strlen.
bdc76f
            * sysdeps/s390/multiarch/strlen-c.c: Move to ...
bdc76f
            * sysdeps/s390/strlen-c.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strlen-vx.S: Move to ...
bdc76f
            * sysdeps/s390/strlen-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strlen.c: Move to ...
bdc76f
            * sysdeps/s390/strlen.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-strlen.h: New file.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index 47d606d3d5d99274..600d8e629df7090e 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -36,5 +36,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   mempcpy memcpy memcpy-z900 \
bdc76f
 		   memmove memmove-c \
bdc76f
 		   strstr strstr-vx strstr-c \
bdc76f
-		   memmem memmem-vx memmem-c
bdc76f
+		   memmem memmem-vx memmem-c \
bdc76f
+		   strlen strlen-vx strlen-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-strlen.h b/sysdeps/s390/ifunc-strlen.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..f2070596636f29a9
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-strlen.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* strlen 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_STRLEN_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_STRLEN_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_STRLEN_IFUNC_AND_VX_SUPPORT HAVE_STRLEN_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_STRLEN_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define STRLEN_DEFAULT		STRLEN_Z13
bdc76f
+# define HAVE_STRLEN_C		0
bdc76f
+# define HAVE_STRLEN_Z13	1
bdc76f
+#else
bdc76f
+# define STRLEN_DEFAULT		STRLEN_C
bdc76f
+# define HAVE_STRLEN_C		1
bdc76f
+# define HAVE_STRLEN_Z13	HAVE_STRLEN_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRLEN_C
bdc76f
+# define STRLEN_C		__strlen_c
bdc76f
+#else
bdc76f
+# define STRLEN_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRLEN_Z13
bdc76f
+# define STRLEN_Z13		__strlen_vx
bdc76f
+#else
bdc76f
+# define STRLEN_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index 24949cd3a88b8015..601523919c235f76 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 += strlen strlen-vx strlen-c \
bdc76f
-		   strnlen strnlen-vx strnlen-c \
bdc76f
+sysdep_routines += strnlen strnlen-vx strnlen-c \
bdc76f
 		   strcpy strcpy-vx \
bdc76f
 		   stpcpy stpcpy-vx stpcpy-c \
bdc76f
 		   strncpy strncpy-vx \
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index da8696d917abf51c..c531be4bc7eb3f55 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -26,6 +26,7 @@
bdc76f
 #include <ifunc-memcpy.h>
bdc76f
 #include <ifunc-strstr.h>
bdc76f
 #include <ifunc-memmem.h>
bdc76f
+#include <ifunc-strlen.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -164,6 +165,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_MEMMEM_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_STRLEN_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, strlen,
bdc76f
+# if HAVE_STRLEN_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, strlen,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, STRLEN_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_STRLEN_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, strlen, 1, STRLEN_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_STRLEN_IFUNC  */
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
@@ -172,7 +185,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 			      __##FUNC##_vx)				\
bdc76f
 	      IFUNC_IMPL_ADD (array, i, FUNC, 1, __##FUNC##_c))
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (strlen);
bdc76f
   IFUNC_VX_IMPL (wcslen);
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (strnlen);
bdc76f
diff --git a/sysdeps/s390/multiarch/strlen-c.c b/sysdeps/s390/strlen-c.c
bdc76f
similarity index 78%
bdc76f
rename from sysdeps/s390/multiarch/strlen-c.c
bdc76f
rename to sysdeps/s390/strlen-c.c
bdc76f
index a2c8e43624a9bc91..b4569701af96f4a9 100644
bdc76f
--- a/sysdeps/s390/multiarch/strlen-c.c
bdc76f
+++ b/sysdeps/s390/strlen-c.c
bdc76f
@@ -16,13 +16,17 @@
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 STRLEN  __strlen_c
bdc76f
-# ifdef SHARED
bdc76f
-#  undef libc_hidden_builtin_def
bdc76f
-#  define libc_hidden_builtin_def(name)			\
bdc76f
+#include <ifunc-strlen.h>
bdc76f
+
bdc76f
+#if HAVE_STRLEN_C
bdc76f
+# if HAVE_STRLEN_IFUNC
bdc76f
+#  define STRLEN STRLEN_C
bdc76f
+#  if defined SHARED && IS_IN (libc)
bdc76f
+#   undef libc_hidden_builtin_def
bdc76f
+#   define libc_hidden_builtin_def(name)		\
bdc76f
   __hidden_ver1 (__strlen_c, __GI_strlen, __strlen_c);
bdc76f
-# endif /* SHARED */
bdc76f
+#  endif
bdc76f
+# endif
bdc76f
 
bdc76f
 # include <string/strlen.c>
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strlen-vx.S b/sysdeps/s390/strlen-vx.S
bdc76f
similarity index 90%
bdc76f
rename from sysdeps/s390/multiarch/strlen-vx.S
bdc76f
rename to sysdeps/s390/strlen-vx.S
bdc76f
index 9308b332371dcdaa..39ef43107d11ec73 100644
bdc76f
--- a/sysdeps/s390/multiarch/strlen-vx.S
bdc76f
+++ b/sysdeps/s390/strlen-vx.S
bdc76f
@@ -16,7 +16,8 @@
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-strlen.h>
bdc76f
+#if HAVE_STRLEN_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -34,7 +35,7 @@
bdc76f
    -r5=current_len and return_value
bdc76f
    -v16=part of s
bdc76f
 */
bdc76f
-ENTRY(__strlen_vx)
bdc76f
+ENTRY(STRLEN_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -80,5 +81,13 @@ ENTRY(__strlen_vx)
bdc76f
 	vlgvb	%r2,%v16,7	/* Load byte index of zero.  */
bdc76f
 	algr	%r2,%r5
bdc76f
 	br	%r14
bdc76f
-END(__strlen_vx)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+END(STRLEN_Z13)
bdc76f
+
bdc76f
+# if ! HAVE_STRLEN_IFUNC
bdc76f
+strong_alias (STRLEN_Z13, strlen)
bdc76f
+# endif
bdc76f
+
bdc76f
+# if ! HAVE_STRLEN_C && defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRLEN_Z13, __GI_strlen)
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strlen.c b/sysdeps/s390/strlen.c
bdc76f
similarity index 69%
bdc76f
rename from sysdeps/s390/multiarch/strlen.c
bdc76f
rename to sysdeps/s390/strlen.c
bdc76f
index 0edf8b7d0231cf31..6ba0fe86fe9789f0 100644
bdc76f
--- a/sysdeps/s390/multiarch/strlen.c
bdc76f
+++ b/sysdeps/s390/strlen.c
bdc76f
@@ -16,14 +16,25 @@
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-strlen.h>
bdc76f
+
bdc76f
+#if HAVE_STRLEN_IFUNC
bdc76f
 # define strlen __redirect_strlen
bdc76f
 # include <string.h>
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 # undef strlen
bdc76f
 
bdc76f
-s390_vx_libc_ifunc2_redirected (__redirect_strlen, __strlen, strlen)
bdc76f
+# if HAVE_STRLEN_C
bdc76f
+extern __typeof (__redirect_strlen) STRLEN_C attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+# if HAVE_STRLEN_Z13
bdc76f
+extern __typeof (__redirect_strlen) STRLEN_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
-#else
bdc76f
-# include <string/strlen.c>
bdc76f
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
bdc76f
+s390_libc_ifunc_expr (__redirect_strlen, strlen,
bdc76f
+		      (HAVE_STRLEN_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? STRLEN_Z13
bdc76f
+		      : STRLEN_DEFAULT
bdc76f
+		      )
bdc76f
+#endif