077c9d
commit d1bdbf380908c34f31ba145ec9afebade3f1418f
077c9d
Author: Stefan Liebler <stli@linux.ibm.com>
077c9d
Date:   Tue Dec 18 13:57:11 2018 +0100
077c9d
077c9d
    S390: Refactor strncpy ifunc handling.
077c9d
    
077c9d
    The ifunc handling for strncpy is adjusted in order to omit ifunc
077c9d
    variants if those will never be used as the minimum architecture level
077c9d
    already supports newer CPUs by default.
077c9d
    Glibc internal calls will then also use the "newer" ifunc variant.
077c9d
    
077c9d
    Note: The fallback s390-32/s390-64 ifunc variants are now moved to
077c9d
    the strncpy-z900.S files. The s390-32/s390-64 files multiarch/strncpy.c
077c9d
    and strncpy.S are deleted.
077c9d
    
077c9d
    ChangeLog:
077c9d
    
077c9d
            * sysdeps/s390/multiarch/Makefile
077c9d
            (sysdep_routines): Remove strncpy variants.
077c9d
            * sysdeps/s390/Makefile (sysdep_routines): Add strncpy variants.
077c9d
            * sysdeps/s390/multiarch/ifunc-impl-list.c
077c9d
            (__libc_ifunc_impl_list): Refactor ifunc handling for strncpy.
077c9d
            * sysdeps/s390/multiarch/strncpy-vx.S: Move to ...
077c9d
            * sysdeps/s390/strncpy-vx.S: ... here and adjust ifunc handling.
077c9d
            * sysdeps/s390/multiarch/strncpy.c: Move to ...
077c9d
            * sysdeps/s390/strncpy.c: ... here and adjust ifunc handling.
077c9d
            * sysdeps/s390/ifunc-strncpy.h: New file.
077c9d
            * sysdeps/s390/s390-64/strncpy.S: Move to ...
077c9d
            * sysdeps/s390/s390-64/strncpy-z900.S: ... here
077c9d
            and adjust ifunc handling.
077c9d
            * sysdeps/s390/s390-32/strncpy.S: Move to ...
077c9d
            * sysdeps/s390/s390-32/strncpy-z900.S: ... here
077c9d
            and adjust ifunc handling.
077c9d
            * sysdeps/s390/s390-32/multiarch/strncpy.c: Delete file.
077c9d
            * sysdeps/s390/s390-64/multiarch/strncpy.c: Likewise.
077c9d
077c9d
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
077c9d
index b7e1bc8aecf2f8c9..db060c81aade84ca 100644
077c9d
--- a/sysdeps/s390/Makefile
077c9d
+++ b/sysdeps/s390/Makefile
077c9d
@@ -40,5 +40,6 @@ sysdep_routines += bzero memset memset-z900 \
077c9d
 		   strlen strlen-vx strlen-c \
077c9d
 		   strnlen strnlen-vx strnlen-c \
077c9d
 		   strcpy strcpy-vx strcpy-z900 \
077c9d
-		   stpcpy stpcpy-vx stpcpy-c
077c9d
+		   stpcpy stpcpy-vx stpcpy-c \
077c9d
+		   strncpy strncpy-vx strncpy-z900
077c9d
 endif
077c9d
diff --git a/sysdeps/s390/ifunc-strncpy.h b/sysdeps/s390/ifunc-strncpy.h
077c9d
new file mode 100644
077c9d
index 0000000000000000..31e87e93c529c443
077c9d
--- /dev/null
077c9d
+++ b/sysdeps/s390/ifunc-strncpy.h
077c9d
@@ -0,0 +1,52 @@
077c9d
+/* strncpy variant information on S/390 version.
077c9d
+   Copyright (C) 2018 Free Software Foundation, Inc.
077c9d
+   This file is part of the GNU C Library.
077c9d
+
077c9d
+   The GNU C Library is free software; you can redistribute it and/or
077c9d
+   modify it under the terms of the GNU Lesser General Public
077c9d
+   License as published by the Free Software Foundation; either
077c9d
+   version 2.1 of the License, or (at your option) any later version.
077c9d
+
077c9d
+   The GNU C Library is distributed in the hope that it will be useful,
077c9d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
077c9d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
077c9d
+   Lesser General Public License for more details.
077c9d
+
077c9d
+   You should have received a copy of the GNU Lesser General Public
077c9d
+   License along with the GNU C Library; if not, see
077c9d
+   <http://www.gnu.org/licenses/>.  */
077c9d
+
077c9d
+#if defined USE_MULTIARCH && IS_IN (libc)		\
077c9d
+  && ! defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
077c9d
+# define HAVE_STRNCPY_IFUNC	1
077c9d
+#else
077c9d
+# define HAVE_STRNCPY_IFUNC	0
077c9d
+#endif
077c9d
+
077c9d
+#ifdef HAVE_S390_VX_ASM_SUPPORT
077c9d
+# define HAVE_STRNCPY_IFUNC_AND_VX_SUPPORT HAVE_STRNCPY_IFUNC
077c9d
+#else
077c9d
+# define HAVE_STRNCPY_IFUNC_AND_VX_SUPPORT 0
077c9d
+#endif
077c9d
+
077c9d
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
077c9d
+# define STRNCPY_DEFAULT	STRNCPY_Z13
077c9d
+# define HAVE_STRNCPY_Z900_G5	0
077c9d
+# define HAVE_STRNCPY_Z13	1
077c9d
+#else
077c9d
+# define STRNCPY_DEFAULT	STRNCPY_Z900_G5
077c9d
+# define HAVE_STRNCPY_Z900_G5	1
077c9d
+# define HAVE_STRNCPY_Z13	HAVE_STRNCPY_IFUNC_AND_VX_SUPPORT
077c9d
+#endif
077c9d
+
077c9d
+#if HAVE_STRNCPY_Z900_G5
077c9d
+# define STRNCPY_Z900_G5	__strncpy_default
077c9d
+#else
077c9d
+# define STRNCPY_Z900_G5	NULL
077c9d
+#endif
077c9d
+
077c9d
+#if HAVE_STRNCPY_Z13
077c9d
+# define STRNCPY_Z13		__strncpy_vx
077c9d
+#else
077c9d
+# define STRNCPY_Z13		NULL
077c9d
+#endif
077c9d
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
077c9d
index 9517417dcbe1c701..c5189b556cf3762d 100644
077c9d
--- a/sysdeps/s390/multiarch/Makefile
077c9d
+++ b/sysdeps/s390/multiarch/Makefile
077c9d
@@ -1,6 +1,5 @@
077c9d
 ifeq ($(subdir),string)
077c9d
-sysdep_routines += strncpy strncpy-vx \
077c9d
-		   stpncpy stpncpy-vx stpncpy-c \
077c9d
+sysdep_routines += stpncpy stpncpy-vx stpncpy-c \
077c9d
 		   strcat strcat-vx strcat-c \
077c9d
 		   strncat strncat-vx strncat-c \
077c9d
 		   strcmp strcmp-vx \
077c9d
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
077c9d
index 678ed13833332f11..d598fc5c22050da2 100644
077c9d
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
077c9d
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
077c9d
@@ -30,6 +30,7 @@
077c9d
 #include <ifunc-strnlen.h>
077c9d
 #include <ifunc-strcpy.h>
077c9d
 #include <ifunc-stpcpy.h>
077c9d
+#include <ifunc-strncpy.h>
077c9d
 
077c9d
 /* Maximum number of IFUNC implementations.  */
077c9d
 #define MAX_IFUNC	3
077c9d
@@ -216,6 +217,19 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
077c9d
 		)
077c9d
 #endif /* HAVE_STPCPY_IFUNC  */
077c9d
 
077c9d
+#if HAVE_STRNCPY_IFUNC
077c9d
+    IFUNC_IMPL (i, name, strncpy,
077c9d
+# if HAVE_STRNCPY_Z13
077c9d
+		IFUNC_IMPL_ADD (array, i, strncpy,
077c9d
+				dl_hwcap & HWCAP_S390_VX, STRNCPY_Z13)
077c9d
+# endif
077c9d
+# if HAVE_STRNCPY_Z900_G5
077c9d
+		IFUNC_IMPL_ADD (array, i, strncpy, 1, STRNCPY_Z900_G5)
077c9d
+# endif
077c9d
+		)
077c9d
+#endif /* HAVE_STRNCPY_IFUNC  */
077c9d
+
077c9d
+
077c9d
 #ifdef HAVE_S390_VX_ASM_SUPPORT
077c9d
 
077c9d
 # define IFUNC_VX_IMPL(FUNC)						\
077c9d
@@ -232,7 +246,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
077c9d
 
077c9d
   IFUNC_VX_IMPL (wcpcpy);
077c9d
 
077c9d
-  IFUNC_VX_IMPL (strncpy);
077c9d
   IFUNC_VX_IMPL (wcsncpy);
077c9d
 
077c9d
   IFUNC_VX_IMPL (stpncpy);
077c9d
diff --git a/sysdeps/s390/s390-32/multiarch/strncpy.c b/sysdeps/s390/s390-32/multiarch/strncpy.c
077c9d
deleted file mode 100644
077c9d
index 57f9df18d12c1959..0000000000000000
077c9d
--- a/sysdeps/s390/s390-32/multiarch/strncpy.c
077c9d
+++ /dev/null
077c9d
@@ -1,21 +0,0 @@
077c9d
-/* Multiple versions of strncpy.
077c9d
-   Copyright (C) 2015-2018 Free Software Foundation, Inc.
077c9d
-   This file is part of the GNU C Library.
077c9d
-
077c9d
-   The GNU C Library is free software; you can redistribute it and/or
077c9d
-   modify it under the terms of the GNU Lesser General Public
077c9d
-   License as published by the Free Software Foundation; either
077c9d
-   version 2.1 of the License, or (at your option) any later version.
077c9d
-
077c9d
-   The GNU C Library is distributed in the hope that it will be useful,
077c9d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
077c9d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
077c9d
-   Lesser General Public License for more details.
077c9d
-
077c9d
-   You should have received a copy of the GNU Lesser General Public
077c9d
-   License along with the GNU C Library; if not, see
077c9d
-   <http://www.gnu.org/licenses/>.  */
077c9d
-
077c9d
-/* This wrapper-file is needed, because otherwise file
077c9d
-   sysdeps/s390/s390-[32|64]/strncpy.S will be used.  */
077c9d
-#include <sysdeps/s390/multiarch/strncpy.c>
077c9d
diff --git a/sysdeps/s390/s390-32/strncpy.S b/sysdeps/s390/s390-32/strncpy-z900.S
077c9d
similarity index 89%
077c9d
rename from sysdeps/s390/s390-32/strncpy.S
077c9d
rename to sysdeps/s390/s390-32/strncpy-z900.S
077c9d
index 9086eb1c707bdfb3..ebdaba015214bc59 100644
077c9d
--- a/sysdeps/s390/s390-32/strncpy.S
077c9d
+++ b/sysdeps/s390/s390-32/strncpy-z900.S
077c9d
@@ -24,10 +24,12 @@
077c9d
  * R4 = max of bytes to copy
077c9d
  */
077c9d
 
077c9d
+#include <ifunc-strncpy.h>
077c9d
 #include "sysdep.h"
077c9d
 #include "asm-syntax.h"
077c9d
 
077c9d
-ENTRY(strncpy)
077c9d
+#if HAVE_STRNCPY_Z900_G5
077c9d
+ENTRY(STRNCPY_Z900_G5)
077c9d
 	.text
077c9d
 	st    %r2,24(%r15)          # save dst pointer
077c9d
 	slr   %r2,%r3               # %r3 points to src, %r2+%r3 to dst
077c9d
@@ -75,5 +77,13 @@ ENTRY(strncpy)
077c9d
 	jo    .L9
077c9d
 .Lexit: l     %r2,24(%r15)          # return dst pointer
077c9d
 	br    %r14
077c9d
-END(strncpy)
077c9d
-libc_hidden_builtin_def (strncpy)
077c9d
+END(STRNCPY_Z900_G5)
077c9d
+
077c9d
+# if ! HAVE_STRNCPY_IFUNC
077c9d
+strong_alias (STRNCPY_Z900_G5, strncpy)
077c9d
+# endif
077c9d
+
077c9d
+# if defined SHARED && IS_IN (libc)
077c9d
+strong_alias (STRNCPY_Z900_G5, __GI_strncpy)
077c9d
+# endif
077c9d
+#endif
077c9d
diff --git a/sysdeps/s390/s390-64/multiarch/strncpy.c b/sysdeps/s390/s390-64/multiarch/strncpy.c
077c9d
deleted file mode 100644
077c9d
index 57f9df18d12c1959..0000000000000000
077c9d
--- a/sysdeps/s390/s390-64/multiarch/strncpy.c
077c9d
+++ /dev/null
077c9d
@@ -1,21 +0,0 @@
077c9d
-/* Multiple versions of strncpy.
077c9d
-   Copyright (C) 2015-2018 Free Software Foundation, Inc.
077c9d
-   This file is part of the GNU C Library.
077c9d
-
077c9d
-   The GNU C Library is free software; you can redistribute it and/or
077c9d
-   modify it under the terms of the GNU Lesser General Public
077c9d
-   License as published by the Free Software Foundation; either
077c9d
-   version 2.1 of the License, or (at your option) any later version.
077c9d
-
077c9d
-   The GNU C Library is distributed in the hope that it will be useful,
077c9d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
077c9d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
077c9d
-   Lesser General Public License for more details.
077c9d
-
077c9d
-   You should have received a copy of the GNU Lesser General Public
077c9d
-   License along with the GNU C Library; if not, see
077c9d
-   <http://www.gnu.org/licenses/>.  */
077c9d
-
077c9d
-/* This wrapper-file is needed, because otherwise file
077c9d
-   sysdeps/s390/s390-[32|64]/strncpy.S will be used.  */
077c9d
-#include <sysdeps/s390/multiarch/strncpy.c>
077c9d
diff --git a/sysdeps/s390/s390-64/strncpy.S b/sysdeps/s390/s390-64/strncpy-z900.S
077c9d
similarity index 90%
077c9d
rename from sysdeps/s390/s390-64/strncpy.S
077c9d
rename to sysdeps/s390/s390-64/strncpy-z900.S
077c9d
index be40aa32d5d9a2df..5732e6d83b5e8f30 100644
077c9d
--- a/sysdeps/s390/s390-64/strncpy.S
077c9d
+++ b/sysdeps/s390/s390-64/strncpy-z900.S
077c9d
@@ -23,10 +23,12 @@
077c9d
      %r3 = address of source (src)
077c9d
      %r4 = max of bytes to copy.  */
077c9d
 
077c9d
+#include <ifunc-strncpy.h>
077c9d
 #include "sysdep.h"
077c9d
 #include "asm-syntax.h"
077c9d
 
077c9d
-ENTRY(strncpy)
077c9d
+#if HAVE_STRNCPY_Z900_G5
077c9d
+ENTRY(STRNCPY_Z900_G5)
077c9d
 	.text
077c9d
 	stg   %r2,48(%r15)	    # save dst pointer
077c9d
 	slgr  %r2,%r3		    # %r3 points to src, %r2+%r3 to dst
077c9d
@@ -86,5 +88,13 @@ ENTRY(strncpy)
077c9d
 	jo    .L13
077c9d
 .Lexit: lg    %r2,48(%r15)	    # return dst pointer
077c9d
 	br    %r14
077c9d
-END(strncpy)
077c9d
-libc_hidden_builtin_def (strncpy)
077c9d
+END(STRNCPY_Z900_G5)
077c9d
+
077c9d
+# if ! HAVE_STRNCPY_IFUNC
077c9d
+strong_alias (STRNCPY_Z900_G5, strncpy)
077c9d
+# endif
077c9d
+
077c9d
+# if defined SHARED && IS_IN (libc)
077c9d
+strong_alias (STRNCPY_Z900_G5, __GI_strncpy)
077c9d
+# endif
077c9d
+#endif
077c9d
diff --git a/sysdeps/s390/multiarch/strncpy-vx.S b/sysdeps/s390/strncpy-vx.S
077c9d
similarity index 93%
077c9d
rename from sysdeps/s390/multiarch/strncpy-vx.S
077c9d
rename to sysdeps/s390/strncpy-vx.S
077c9d
index 2a37b7b84e0a2514..be09ddf092388c72 100644
077c9d
--- a/sysdeps/s390/multiarch/strncpy-vx.S
077c9d
+++ b/sysdeps/s390/strncpy-vx.S
077c9d
@@ -16,13 +16,13 @@
077c9d
    License along with the GNU C Library; if not, see
077c9d
    <http://www.gnu.org/licenses/>.  */
077c9d
 
077c9d
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
077c9d
-
077c9d
-# include "sysdep.h"
077c9d
-# include "asm-syntax.h"
077c9d
+#include <ifunc-strncpy.h>
077c9d
+#include "sysdep.h"
077c9d
+#include "asm-syntax.h"
077c9d
 
077c9d
 	.text
077c9d
 
077c9d
+#if HAVE_STRNCPY_Z13
077c9d
 /* char * strncpy (const char *dest, const char *src, size_t n)
077c9d
    Copy at most n characters of string  src to dest.
077c9d
 
077c9d
@@ -40,7 +40,7 @@
077c9d
    -v18=part of src
077c9d
    -v31=register save area for r6, r7
077c9d
 */
077c9d
-ENTRY(__strncpy_vx)
077c9d
+ENTRY(STRNCPY_Z13)
077c9d
 	.machine "z13"
077c9d
 	.machinemode "zarch_nohighgprs"
077c9d
 
077c9d
@@ -196,12 +196,13 @@ ENTRY(__strncpy_vx)
077c9d
 
077c9d
 	vl	%v16,0(%r5,%r3)	/* Load s.  */
077c9d
 	j	.Llt64
077c9d
-END(__strncpy_vx)
077c9d
+END(STRNCPY_Z13)
077c9d
 
077c9d
-# define strncpy __strncpy_c
077c9d
-# undef libc_hidden_builtin_def
077c9d
-# define libc_hidden_builtin_def(name) strong_alias(__strncpy_c, __GI_strncpy)
077c9d
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
077c9d
+# if ! HAVE_STRNCPY_IFUNC
077c9d
+strong_alias (STRNCPY_Z13, strncpy)
077c9d
+# endif
077c9d
 
077c9d
-/* Include strncpy-implementation in s390-32/s390-64 subdirectory.  */
077c9d
-#include <strncpy.S>
077c9d
+# if ! HAVE_STRNCPY_Z900_G5 && defined SHARED && IS_IN (libc)
077c9d
+strong_alias (STRNCPY_Z13, __GI_strncpy)
077c9d
+# endif
077c9d
+#endif
077c9d
diff --git a/sysdeps/s390/multiarch/strncpy.c b/sysdeps/s390/strncpy.c
077c9d
similarity index 71%
077c9d
rename from sysdeps/s390/multiarch/strncpy.c
077c9d
rename to sysdeps/s390/strncpy.c
077c9d
index 2d4c456d96dad0d6..ec8a26471b6536e8 100644
077c9d
--- a/sysdeps/s390/multiarch/strncpy.c
077c9d
+++ b/sysdeps/s390/strncpy.c
077c9d
@@ -16,7 +16,9 @@
077c9d
    License along with the GNU C Library; if not, see
077c9d
    <http://www.gnu.org/licenses/>.  */
077c9d
 
077c9d
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
077c9d
+#include <ifunc-strncpy.h>
077c9d
+
077c9d
+#if HAVE_STRNCPY_IFUNC
077c9d
 # define strncpy __redirect_strncpy
077c9d
 /* Omit the strncpy inline definitions because it would redefine strncpy.  */
077c9d
 # define __NO_STRING_INLINES
077c9d
@@ -24,6 +26,17 @@
077c9d
 # undef strncpy
077c9d
 # include <ifunc-resolve.h>
077c9d
 
077c9d
-s390_vx_libc_ifunc2_redirected (__redirect_strncpy, __strncpy, strncpy);
077c9d
+# if HAVE_STRNCPY_Z900_G5
077c9d
+extern __typeof (__redirect_strncpy) STRNCPY_Z900_G5 attribute_hidden;
077c9d
+# endif
077c9d
+
077c9d
+# if HAVE_STRNCPY_Z13
077c9d
+extern __typeof (__redirect_strncpy) STRNCPY_Z13 attribute_hidden;
077c9d
+# endif
077c9d
 
077c9d
+s390_libc_ifunc_expr (__redirect_strncpy, strncpy,
077c9d
+		      (HAVE_STRNCPY_Z13 && (hwcap & HWCAP_S390_VX))
077c9d
+		      ? STRNCPY_Z13
077c9d
+		      : STRNCPY_DEFAULT
077c9d
+		      )
077c9d
 #endif