bdc76f
commit 8e5a0afbbf0a96fb873e27aa064c9bacc9cfd9c6
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:12 2018 +0100
bdc76f
bdc76f
    S390: Refactor strcat ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for strcat 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 strcat variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add strcat variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for strcat.
bdc76f
            * sysdeps/s390/multiarch/strcat-c.c: Move to ...
bdc76f
            * sysdeps/s390/strcat-c.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strcat-vx.S: Move to ...
bdc76f
            * sysdeps/s390/strcat-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strcat.c: Move to ...
bdc76f
            * sysdeps/s390/strcat.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-strcat.h: New file.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index a9882b3996c30322..de2d5e5652dde412 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -42,5 +42,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   strcpy strcpy-vx strcpy-z900 \
bdc76f
 		   stpcpy stpcpy-vx stpcpy-c \
bdc76f
 		   strncpy strncpy-vx strncpy-z900 \
bdc76f
-		   stpncpy stpncpy-vx stpncpy-c
bdc76f
+		   stpncpy stpncpy-vx stpncpy-c \
bdc76f
+		   strcat strcat-vx strcat-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-strcat.h b/sysdeps/s390/ifunc-strcat.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..6fd2f7dd31fff64f
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-strcat.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* strcat 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_STRCAT_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_STRCAT_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_STRCAT_IFUNC_AND_VX_SUPPORT HAVE_STRCAT_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_STRCAT_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define STRCAT_DEFAULT		STRCAT_Z13
bdc76f
+# define HAVE_STRCAT_C		0
bdc76f
+# define HAVE_STRCAT_Z13	1
bdc76f
+#else
bdc76f
+# define STRCAT_DEFAULT		STRCAT_C
bdc76f
+# define HAVE_STRCAT_C		1
bdc76f
+# define HAVE_STRCAT_Z13	HAVE_STRCAT_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRCAT_C
bdc76f
+# define STRCAT_C		__strcat_c
bdc76f
+#else
bdc76f
+# define STRCAT_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRCAT_Z13
bdc76f
+# define STRCAT_Z13		__strcat_vx
bdc76f
+#else
bdc76f
+# define STRCAT_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index 3d97d21da1fc852b..9b66237aaf9eb47e 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 += strcat strcat-vx strcat-c \
bdc76f
-		   strncat strncat-vx strncat-c \
bdc76f
+sysdep_routines += strncat strncat-vx strncat-c \
bdc76f
 		   strcmp strcmp-vx \
bdc76f
 		   strncmp strncmp-vx strncmp-c \
bdc76f
 		   strchr strchr-vx strchr-c \
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index 021e9f247fff44df..1b7f3df3a3cfe561 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -32,6 +32,7 @@
bdc76f
 #include <ifunc-stpcpy.h>
bdc76f
 #include <ifunc-strncpy.h>
bdc76f
 #include <ifunc-stpncpy.h>
bdc76f
+#include <ifunc-strcat.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -242,6 +243,17 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_STPNCPY_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_STRCAT_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, strcat,
bdc76f
+# if HAVE_STRCAT_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, strcat,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, STRCAT_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_STRCAT_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, strcat, 1, STRCAT_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_STRCAT_IFUNC  */
bdc76f
 
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
@@ -263,7 +275,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wcpncpy);
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (strcat);
bdc76f
   IFUNC_VX_IMPL (wcscat);
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (strncat);
bdc76f
diff --git a/sysdeps/s390/multiarch/strcat-c.c b/sysdeps/s390/strcat-c.c
bdc76f
similarity index 73%
bdc76f
rename from sysdeps/s390/multiarch/strcat-c.c
bdc76f
rename to sysdeps/s390/strcat-c.c
bdc76f
index f871faa7b563e74b..7accc6c7ef80ecf2 100644
bdc76f
--- a/sysdeps/s390/multiarch/strcat-c.c
bdc76f
+++ b/sysdeps/s390/strcat-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 STRCAT  __strcat_c
bdc76f
-# ifdef SHARED
bdc76f
-#  undef libc_hidden_builtin_def
bdc76f
-#  define libc_hidden_builtin_def(name)				\
bdc76f
-     __hidden_ver1 (__strcat_c, __GI_strcat, __strcat_c);
bdc76f
-# endif /* SHARED */
bdc76f
+#include <ifunc-strcat.h>
bdc76f
+
bdc76f
+#if HAVE_STRCAT_C
bdc76f
+# if HAVE_STRCAT_IFUNC
bdc76f
+# define STRCAT STRCAT_C
bdc76f
+#  if defined SHARED && IS_IN (libc)
bdc76f
+#   undef libc_hidden_builtin_def
bdc76f
+#   define libc_hidden_builtin_def(name)		\
bdc76f
+  __hidden_ver1 (__strcat_c, __GI_strcat, __strcat_c);
bdc76f
+#  endif
bdc76f
+# endif
bdc76f
 
bdc76f
 # include <string/strcat.c>
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strcat-vx.S b/sysdeps/s390/strcat-vx.S
bdc76f
similarity index 94%
bdc76f
rename from sysdeps/s390/multiarch/strcat-vx.S
bdc76f
rename to sysdeps/s390/strcat-vx.S
bdc76f
index 3abbbcccedad0eb4..218e301f10c6abe3 100644
bdc76f
--- a/sysdeps/s390/multiarch/strcat-vx.S
bdc76f
+++ b/sysdeps/s390/strcat-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-strcat.h>
bdc76f
+#if HAVE_STRCAT_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -37,7 +38,7 @@
bdc76f
    -v17=index of zero
bdc76f
    -v18=part of src
bdc76f
 */
bdc76f
-ENTRY(__strcat_vx)
bdc76f
+ENTRY(STRCAT_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -157,5 +158,13 @@ ENTRY(__strcat_vx)
bdc76f
 	vstl	%v16,%r5,0(%r2)	/* Copy characters including zero.  */
bdc76f
 	lgr	%r2,%r0		/* Load saved dest-ptr.  */
bdc76f
 	br	%r14
bdc76f
-END(__strcat_vx)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+END(STRCAT_Z13)
bdc76f
+
bdc76f
+# if ! HAVE_STRCAT_IFUNC
bdc76f
+strong_alias (STRCAT_Z13, strcat)
bdc76f
+# endif
bdc76f
+
bdc76f
+# if ! HAVE_STRCAT_C && defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRCAT_Z13, __GI_strcat)
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strcat.c b/sysdeps/s390/strcat.c
bdc76f
similarity index 69%
bdc76f
rename from sysdeps/s390/multiarch/strcat.c
bdc76f
rename to sysdeps/s390/strcat.c
bdc76f
index 7d4126b44f23679a..d378519c8af59620 100644
bdc76f
--- a/sysdeps/s390/multiarch/strcat.c
bdc76f
+++ b/sysdeps/s390/strcat.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-strcat.h>
bdc76f
+
bdc76f
+#if HAVE_STRCAT_IFUNC
bdc76f
 # define strcat __redirect_strcat
bdc76f
 # include <string.h>
bdc76f
 # undef strcat
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 
bdc76f
-s390_vx_libc_ifunc2_redirected (__redirect_strcat, __strcat, strcat)
bdc76f
+# if HAVE_STRCAT_C
bdc76f
+extern __typeof (__redirect_strcat) STRCAT_C attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+# if HAVE_STRCAT_Z13
bdc76f
+extern __typeof (__redirect_strcat) STRCAT_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
-#else
bdc76f
-# include <string/strcat.c>
bdc76f
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
bdc76f
+s390_libc_ifunc_expr (__redirect_strcat, strcat,
bdc76f
+		      (HAVE_STRCAT_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? STRCAT_Z13
bdc76f
+		      : STRCAT_DEFAULT
bdc76f
+		      )
bdc76f
+#endif