bdc76f
commit d1bdbf380908c34f31ba145ec9afebade3f1418f
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:11 2018 +0100
bdc76f
bdc76f
    S390: Refactor strncpy ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for strncpy 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
    Note: The fallback s390-32/s390-64 ifunc variants are now moved to
bdc76f
    the strncpy-z900.S files. The s390-32/s390-64 files multiarch/strncpy.c
bdc76f
    and strncpy.S are deleted.
bdc76f
    
bdc76f
    ChangeLog:
bdc76f
    
bdc76f
            * sysdeps/s390/multiarch/Makefile
bdc76f
            (sysdep_routines): Remove strncpy variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add strncpy variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for strncpy.
bdc76f
            * sysdeps/s390/multiarch/strncpy-vx.S: Move to ...
bdc76f
            * sysdeps/s390/strncpy-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strncpy.c: Move to ...
bdc76f
            * sysdeps/s390/strncpy.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-strncpy.h: New file.
bdc76f
            * sysdeps/s390/s390-64/strncpy.S: Move to ...
bdc76f
            * sysdeps/s390/s390-64/strncpy-z900.S: ... here
bdc76f
            and adjust ifunc handling.
bdc76f
            * sysdeps/s390/s390-32/strncpy.S: Move to ...
bdc76f
            * sysdeps/s390/s390-32/strncpy-z900.S: ... here
bdc76f
            and adjust ifunc handling.
bdc76f
            * sysdeps/s390/s390-32/multiarch/strncpy.c: Delete file.
bdc76f
            * sysdeps/s390/s390-64/multiarch/strncpy.c: Likewise.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index b7e1bc8aecf2f8c9..db060c81aade84ca 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -40,5 +40,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   strlen strlen-vx strlen-c \
bdc76f
 		   strnlen strnlen-vx strnlen-c \
bdc76f
 		   strcpy strcpy-vx strcpy-z900 \
bdc76f
-		   stpcpy stpcpy-vx stpcpy-c
bdc76f
+		   stpcpy stpcpy-vx stpcpy-c \
bdc76f
+		   strncpy strncpy-vx strncpy-z900
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-strncpy.h b/sysdeps/s390/ifunc-strncpy.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..31e87e93c529c443
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-strncpy.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* strncpy 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_STRNCPY_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_STRNCPY_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_STRNCPY_IFUNC_AND_VX_SUPPORT HAVE_STRNCPY_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_STRNCPY_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define STRNCPY_DEFAULT	STRNCPY_Z13
bdc76f
+# define HAVE_STRNCPY_Z900_G5	0
bdc76f
+# define HAVE_STRNCPY_Z13	1
bdc76f
+#else
bdc76f
+# define STRNCPY_DEFAULT	STRNCPY_Z900_G5
bdc76f
+# define HAVE_STRNCPY_Z900_G5	1
bdc76f
+# define HAVE_STRNCPY_Z13	HAVE_STRNCPY_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRNCPY_Z900_G5
bdc76f
+# define STRNCPY_Z900_G5	__strncpy_default
bdc76f
+#else
bdc76f
+# define STRNCPY_Z900_G5	NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRNCPY_Z13
bdc76f
+# define STRNCPY_Z13		__strncpy_vx
bdc76f
+#else
bdc76f
+# define STRNCPY_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index 9517417dcbe1c701..c5189b556cf3762d 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 += strncpy strncpy-vx \
bdc76f
-		   stpncpy stpncpy-vx stpncpy-c \
bdc76f
+sysdep_routines += stpncpy stpncpy-vx stpncpy-c \
bdc76f
 		   strcat strcat-vx strcat-c \
bdc76f
 		   strncat strncat-vx strncat-c \
bdc76f
 		   strcmp strcmp-vx \
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index 678ed13833332f11..d598fc5c22050da2 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -30,6 +30,7 @@
bdc76f
 #include <ifunc-strnlen.h>
bdc76f
 #include <ifunc-strcpy.h>
bdc76f
 #include <ifunc-stpcpy.h>
bdc76f
+#include <ifunc-strncpy.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -216,6 +217,19 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_STPCPY_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_STRNCPY_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, strncpy,
bdc76f
+# if HAVE_STRNCPY_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, strncpy,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, STRNCPY_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_STRNCPY_Z900_G5
bdc76f
+		IFUNC_IMPL_ADD (array, i, strncpy, 1, STRNCPY_Z900_G5)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_STRNCPY_IFUNC  */
bdc76f
+
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
@@ -232,7 +246,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wcpcpy);
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (strncpy);
bdc76f
   IFUNC_VX_IMPL (wcsncpy);
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (stpncpy);
bdc76f
diff --git a/sysdeps/s390/s390-32/multiarch/strncpy.c b/sysdeps/s390/s390-32/multiarch/strncpy.c
bdc76f
deleted file mode 100644
bdc76f
index 57f9df18d12c1959..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-32/multiarch/strncpy.c
bdc76f
+++ /dev/null
bdc76f
@@ -1,21 +0,0 @@
bdc76f
-/* Multiple versions of strncpy.
bdc76f
-   Copyright (C) 2015-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
-/* This wrapper-file is needed, because otherwise file
bdc76f
-   sysdeps/s390/s390-[32|64]/strncpy.S will be used.  */
bdc76f
-#include <sysdeps/s390/multiarch/strncpy.c>
bdc76f
diff --git a/sysdeps/s390/s390-32/strncpy.S b/sysdeps/s390/s390-32/strncpy-z900.S
bdc76f
similarity index 89%
bdc76f
rename from sysdeps/s390/s390-32/strncpy.S
bdc76f
rename to sysdeps/s390/s390-32/strncpy-z900.S
bdc76f
index 9086eb1c707bdfb3..ebdaba015214bc59 100644
bdc76f
--- a/sysdeps/s390/s390-32/strncpy.S
bdc76f
+++ b/sysdeps/s390/s390-32/strncpy-z900.S
bdc76f
@@ -24,10 +24,12 @@
bdc76f
  * R4 = max of bytes to copy
bdc76f
  */
bdc76f
 
bdc76f
+#include <ifunc-strncpy.h>
bdc76f
 #include "sysdep.h"
bdc76f
 #include "asm-syntax.h"
bdc76f
 
bdc76f
-ENTRY(strncpy)
bdc76f
+#if HAVE_STRNCPY_Z900_G5
bdc76f
+ENTRY(STRNCPY_Z900_G5)
bdc76f
 	.text
bdc76f
 	st    %r2,24(%r15)          # save dst pointer
bdc76f
 	slr   %r2,%r3               # %r3 points to src, %r2+%r3 to dst
bdc76f
@@ -75,5 +77,13 @@ ENTRY(strncpy)
bdc76f
 	jo    .L9
bdc76f
 .Lexit: l     %r2,24(%r15)          # return dst pointer
bdc76f
 	br    %r14
bdc76f
-END(strncpy)
bdc76f
-libc_hidden_builtin_def (strncpy)
bdc76f
+END(STRNCPY_Z900_G5)
bdc76f
+
bdc76f
+# if ! HAVE_STRNCPY_IFUNC
bdc76f
+strong_alias (STRNCPY_Z900_G5, strncpy)
bdc76f
+# endif
bdc76f
+
bdc76f
+# if defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRNCPY_Z900_G5, __GI_strncpy)
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/s390-64/multiarch/strncpy.c b/sysdeps/s390/s390-64/multiarch/strncpy.c
bdc76f
deleted file mode 100644
bdc76f
index 57f9df18d12c1959..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-64/multiarch/strncpy.c
bdc76f
+++ /dev/null
bdc76f
@@ -1,21 +0,0 @@
bdc76f
-/* Multiple versions of strncpy.
bdc76f
-   Copyright (C) 2015-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
-/* This wrapper-file is needed, because otherwise file
bdc76f
-   sysdeps/s390/s390-[32|64]/strncpy.S will be used.  */
bdc76f
-#include <sysdeps/s390/multiarch/strncpy.c>
bdc76f
diff --git a/sysdeps/s390/s390-64/strncpy.S b/sysdeps/s390/s390-64/strncpy-z900.S
bdc76f
similarity index 90%
bdc76f
rename from sysdeps/s390/s390-64/strncpy.S
bdc76f
rename to sysdeps/s390/s390-64/strncpy-z900.S
bdc76f
index be40aa32d5d9a2df..5732e6d83b5e8f30 100644
bdc76f
--- a/sysdeps/s390/s390-64/strncpy.S
bdc76f
+++ b/sysdeps/s390/s390-64/strncpy-z900.S
bdc76f
@@ -23,10 +23,12 @@
bdc76f
      %r3 = address of source (src)
bdc76f
      %r4 = max of bytes to copy.  */
bdc76f
 
bdc76f
+#include <ifunc-strncpy.h>
bdc76f
 #include "sysdep.h"
bdc76f
 #include "asm-syntax.h"
bdc76f
 
bdc76f
-ENTRY(strncpy)
bdc76f
+#if HAVE_STRNCPY_Z900_G5
bdc76f
+ENTRY(STRNCPY_Z900_G5)
bdc76f
 	.text
bdc76f
 	stg   %r2,48(%r15)	    # save dst pointer
bdc76f
 	slgr  %r2,%r3		    # %r3 points to src, %r2+%r3 to dst
bdc76f
@@ -86,5 +88,13 @@ ENTRY(strncpy)
bdc76f
 	jo    .L13
bdc76f
 .Lexit: lg    %r2,48(%r15)	    # return dst pointer
bdc76f
 	br    %r14
bdc76f
-END(strncpy)
bdc76f
-libc_hidden_builtin_def (strncpy)
bdc76f
+END(STRNCPY_Z900_G5)
bdc76f
+
bdc76f
+# if ! HAVE_STRNCPY_IFUNC
bdc76f
+strong_alias (STRNCPY_Z900_G5, strncpy)
bdc76f
+# endif
bdc76f
+
bdc76f
+# if defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRNCPY_Z900_G5, __GI_strncpy)
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strncpy-vx.S b/sysdeps/s390/strncpy-vx.S
bdc76f
similarity index 93%
bdc76f
rename from sysdeps/s390/multiarch/strncpy-vx.S
bdc76f
rename to sysdeps/s390/strncpy-vx.S
bdc76f
index 2a37b7b84e0a2514..be09ddf092388c72 100644
bdc76f
--- a/sysdeps/s390/multiarch/strncpy-vx.S
bdc76f
+++ b/sysdeps/s390/strncpy-vx.S
bdc76f
@@ -16,13 +16,13 @@
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
-
bdc76f
-# include "sysdep.h"
bdc76f
-# include "asm-syntax.h"
bdc76f
+#include <ifunc-strncpy.h>
bdc76f
+#include "sysdep.h"
bdc76f
+#include "asm-syntax.h"
bdc76f
 
bdc76f
 	.text
bdc76f
 
bdc76f
+#if HAVE_STRNCPY_Z13
bdc76f
 /* char * strncpy (const char *dest, const char *src, size_t n)
bdc76f
    Copy at most n characters of string  src to dest.
bdc76f
 
bdc76f
@@ -40,7 +40,7 @@
bdc76f
    -v18=part of src
bdc76f
    -v31=register save area for r6, r7
bdc76f
 */
bdc76f
-ENTRY(__strncpy_vx)
bdc76f
+ENTRY(STRNCPY_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -196,12 +196,13 @@ ENTRY(__strncpy_vx)
bdc76f
 
bdc76f
 	vl	%v16,0(%r5,%r3)	/* Load s.  */
bdc76f
 	j	.Llt64
bdc76f
-END(__strncpy_vx)
bdc76f
+END(STRNCPY_Z13)
bdc76f
 
bdc76f
-# define strncpy __strncpy_c
bdc76f
-# undef libc_hidden_builtin_def
bdc76f
-# define libc_hidden_builtin_def(name) strong_alias(__strncpy_c, __GI_strncpy)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+# if ! HAVE_STRNCPY_IFUNC
bdc76f
+strong_alias (STRNCPY_Z13, strncpy)
bdc76f
+# endif
bdc76f
 
bdc76f
-/* Include strncpy-implementation in s390-32/s390-64 subdirectory.  */
bdc76f
-#include <strncpy.S>
bdc76f
+# if ! HAVE_STRNCPY_Z900_G5 && defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRNCPY_Z13, __GI_strncpy)
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strncpy.c b/sysdeps/s390/strncpy.c
bdc76f
similarity index 71%
bdc76f
rename from sysdeps/s390/multiarch/strncpy.c
bdc76f
rename to sysdeps/s390/strncpy.c
bdc76f
index 2d4c456d96dad0d6..ec8a26471b6536e8 100644
bdc76f
--- a/sysdeps/s390/multiarch/strncpy.c
bdc76f
+++ b/sysdeps/s390/strncpy.c
bdc76f
@@ -16,7 +16,9 @@
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-strncpy.h>
bdc76f
+
bdc76f
+#if HAVE_STRNCPY_IFUNC
bdc76f
 # define strncpy __redirect_strncpy
bdc76f
 /* Omit the strncpy inline definitions because it would redefine strncpy.  */
bdc76f
 # define __NO_STRING_INLINES
bdc76f
@@ -24,6 +26,17 @@
bdc76f
 # undef strncpy
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 
bdc76f
-s390_vx_libc_ifunc2_redirected (__redirect_strncpy, __strncpy, strncpy);
bdc76f
+# if HAVE_STRNCPY_Z900_G5
bdc76f
+extern __typeof (__redirect_strncpy) STRNCPY_Z900_G5 attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+# if HAVE_STRNCPY_Z13
bdc76f
+extern __typeof (__redirect_strncpy) STRNCPY_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
+s390_libc_ifunc_expr (__redirect_strncpy, strncpy,
bdc76f
+		      (HAVE_STRNCPY_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? STRNCPY_Z13
bdc76f
+		      : STRNCPY_DEFAULT
bdc76f
+		      )
bdc76f
 #endif