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