bdc76f
commit b935335155d65971fe2a54e32c0eb74303d4e4fc
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:12 2018 +0100
bdc76f
bdc76f
    S390: Refactor strncat ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for strncat 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 strncat variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add strncat variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for strncat.
bdc76f
            * sysdeps/s390/multiarch/strncat-c.c: Move to ...
bdc76f
            * sysdeps/s390/strncat-c.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strncat-vx.S: Move to ...
bdc76f
            * sysdeps/s390/strncat-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strncat.c: Move to ...
bdc76f
            * sysdeps/s390/strncat.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-strncat.h: New file.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index de2d5e5652dde412..cb5dc1d4f95fd11c 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -43,5 +43,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   stpcpy stpcpy-vx stpcpy-c \
bdc76f
 		   strncpy strncpy-vx strncpy-z900 \
bdc76f
 		   stpncpy stpncpy-vx stpncpy-c \
bdc76f
-		   strcat strcat-vx strcat-c
bdc76f
+		   strcat strcat-vx strcat-c \
bdc76f
+		   strncat strncat-vx strncat-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-strncat.h b/sysdeps/s390/ifunc-strncat.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..bb164dcc32905b18
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-strncat.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* strncat 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_STRNCAT_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_STRNCAT_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_STRNCAT_IFUNC_AND_VX_SUPPORT HAVE_STRNCAT_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_STRNCAT_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define STRNCAT_DEFAULT	STRNCAT_Z13
bdc76f
+# define HAVE_STRNCAT_C		0
bdc76f
+# define HAVE_STRNCAT_Z13	1
bdc76f
+#else
bdc76f
+# define STRNCAT_DEFAULT	STRNCAT_C
bdc76f
+# define HAVE_STRNCAT_C		1
bdc76f
+# define HAVE_STRNCAT_Z13	HAVE_STRNCAT_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRNCAT_C
bdc76f
+# define STRNCAT_C		__strncat_c
bdc76f
+#else
bdc76f
+# define STRNCAT_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRNCAT_Z13
bdc76f
+# define STRNCAT_Z13		__strncat_vx
bdc76f
+#else
bdc76f
+# define STRNCAT_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index 9b66237aaf9eb47e..24be3eac5131fd4a 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 += strncat strncat-vx strncat-c \
bdc76f
-		   strcmp strcmp-vx \
bdc76f
+sysdep_routines += strcmp strcmp-vx \
bdc76f
 		   strncmp strncmp-vx strncmp-c \
bdc76f
 		   strchr strchr-vx strchr-c \
bdc76f
 		   strchrnul strchrnul-vx strchrnul-c \
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index 1b7f3df3a3cfe561..3abcaf08e0ccd385 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -33,6 +33,7 @@
bdc76f
 #include <ifunc-strncpy.h>
bdc76f
 #include <ifunc-stpncpy.h>
bdc76f
 #include <ifunc-strcat.h>
bdc76f
+#include <ifunc-strncat.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -255,6 +256,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_STRCAT_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_STRNCAT_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, strncat,
bdc76f
+# if HAVE_STRNCAT_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, strncat,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, STRNCAT_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_STRNCAT_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, strncat, 1, STRNCAT_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_STRNCAT_IFUNC  */
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
@@ -277,7 +290,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wcscat);
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (strncat);
bdc76f
   IFUNC_VX_IMPL (wcsncat);
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (strcmp);
bdc76f
diff --git a/sysdeps/s390/multiarch/strncat-c.c b/sysdeps/s390/strncat-c.c
bdc76f
similarity index 86%
bdc76f
rename from sysdeps/s390/multiarch/strncat-c.c
bdc76f
rename to sysdeps/s390/strncat-c.c
bdc76f
index 9e6c245ccbbc2e23..86df89887c7b6293 100644
bdc76f
--- a/sysdeps/s390/multiarch/strncat-c.c
bdc76f
+++ b/sysdeps/s390/strncat-c.c
bdc76f
@@ -16,8 +16,12 @@
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 STRNCAT  __strncat_c
bdc76f
-# define STRNCAT_PRIMARY
bdc76f
+#include <ifunc-strncat.h>
bdc76f
+
bdc76f
+#if HAVE_STRNCAT_C
bdc76f
+# if HAVE_STRNCAT_IFUNC
bdc76f
+#  define STRNCAT STRNCAT_C
bdc76f
+#  define STRNCAT_PRIMARY
bdc76f
+# endif
bdc76f
 # include <string/strncat.c>
bdc76f
 #endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strncat-vx.S b/sysdeps/s390/strncat-vx.S
bdc76f
similarity index 94%
bdc76f
rename from sysdeps/s390/multiarch/strncat-vx.S
bdc76f
rename to sysdeps/s390/strncat-vx.S
bdc76f
index e6584d0f438f0e38..76345e7dd702dd85 100644
bdc76f
--- a/sysdeps/s390/multiarch/strncat-vx.S
bdc76f
+++ b/sysdeps/s390/strncat-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-strncat.h>
bdc76f
+#if HAVE_STRNCAT_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -40,7 +41,7 @@
bdc76f
    -v18=part of src
bdc76f
    -v31=register save area for r6, r7
bdc76f
 */
bdc76f
-ENTRY(__strncat_vx)
bdc76f
+ENTRY(STRNCAT_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -235,5 +236,17 @@ ENTRY(__strncat_vx)
bdc76f
 
bdc76f
 	vl	%v16,0(%r5,%r3)	/* Load s.  */
bdc76f
 	j	.Lcpy_lt64
bdc76f
-END(__strncat_vx)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+END(STRNCAT_Z13)
bdc76f
+
bdc76f
+# if ! HAVE_STRNCAT_IFUNC
bdc76f
+strong_alias (STRNCAT_Z13, strncat)
bdc76f
+# endif
bdc76f
+
bdc76f
+# if ! HAVE_STRNCAT_C
bdc76f
+/* See string/strncat.c and define STRNCAT_PRIMARY.  */
bdc76f
+strong_alias (STRNCAT_Z13, __strncat)
bdc76f
+#  if defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (__strncat, __GI___strncat)
bdc76f
+#  endif
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strncat.c b/sysdeps/s390/strncat.c
bdc76f
similarity index 69%
bdc76f
rename from sysdeps/s390/multiarch/strncat.c
bdc76f
rename to sysdeps/s390/strncat.c
bdc76f
index 94b8dffa85420cfa..b4b3656c5ae9c535 100644
bdc76f
--- a/sysdeps/s390/multiarch/strncat.c
bdc76f
+++ b/sysdeps/s390/strncat.c
bdc76f
@@ -16,12 +16,23 @@
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-strncat.h>
bdc76f
+
bdc76f
+#if HAVE_STRNCAT_IFUNC
bdc76f
 # include <string.h>
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 
bdc76f
-s390_vx_libc_ifunc2 (__strncat, strncat)
bdc76f
+# if HAVE_STRNCAT_C
bdc76f
+extern __typeof (__strncat) STRNCAT_C attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+# if HAVE_STRNCAT_Z13
bdc76f
+extern __typeof (__strncat) STRNCAT_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
-#else
bdc76f
-# include <string/strncat.c>
bdc76f
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
bdc76f
+s390_libc_ifunc_expr (__strncat, strncat,
bdc76f
+		      (HAVE_STRNCAT_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? STRNCAT_Z13
bdc76f
+		      : STRNCAT_DEFAULT
bdc76f
+		      )
bdc76f
+#endif