]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
S390: Refactor strncpy ifunc handling.
authorStefan Liebler <stli@linux.ibm.com>
Tue, 18 Dec 2018 12:57:11 +0000 (13:57 +0100)
committerStefan Liebler <stli@linux.ibm.com>
Tue, 18 Dec 2018 12:57:11 +0000 (13:57 +0100)
The ifunc handling for strncpy is adjusted in order to omit ifunc
variants if those will never be used as the minimum architecture level
already supports newer CPUs by default.
Glibc internal calls will then also use the "newer" ifunc variant.

Note: The fallback s390-32/s390-64 ifunc variants are now moved to
the strncpy-z900.S files. The s390-32/s390-64 files multiarch/strncpy.c
and strncpy.S are deleted.

ChangeLog:

* sysdeps/s390/multiarch/Makefile
(sysdep_routines): Remove strncpy variants.
* sysdeps/s390/Makefile (sysdep_routines): Add strncpy variants.
* sysdeps/s390/multiarch/ifunc-impl-list.c
(__libc_ifunc_impl_list): Refactor ifunc handling for strncpy.
* sysdeps/s390/multiarch/strncpy-vx.S: Move to ...
* sysdeps/s390/strncpy-vx.S: ... here and adjust ifunc handling.
* sysdeps/s390/multiarch/strncpy.c: Move to ...
* sysdeps/s390/strncpy.c: ... here and adjust ifunc handling.
* sysdeps/s390/ifunc-strncpy.h: New file.
* sysdeps/s390/s390-64/strncpy.S: Move to ...
* sysdeps/s390/s390-64/strncpy-z900.S: ... here
and adjust ifunc handling.
* sysdeps/s390/s390-32/strncpy.S: Move to ...
* sysdeps/s390/s390-32/strncpy-z900.S: ... here
and adjust ifunc handling.
* sysdeps/s390/s390-32/multiarch/strncpy.c: Delete file.
* sysdeps/s390/s390-64/multiarch/strncpy.c: Likewise.

ChangeLog
sysdeps/s390/Makefile
sysdeps/s390/ifunc-strncpy.h [new file with mode: 0644]
sysdeps/s390/multiarch/Makefile
sysdeps/s390/multiarch/ifunc-impl-list.c
sysdeps/s390/s390-32/multiarch/strncpy.c [deleted file]
sysdeps/s390/s390-32/strncpy-z900.S [moved from sysdeps/s390/s390-32/strncpy.S with 89% similarity]
sysdeps/s390/s390-64/multiarch/strncpy.c [deleted file]
sysdeps/s390/s390-64/strncpy-z900.S [moved from sysdeps/s390/s390-64/strncpy.S with 90% similarity]
sysdeps/s390/strncpy-vx.S [moved from sysdeps/s390/multiarch/strncpy-vx.S with 93% similarity]
sysdeps/s390/strncpy.c [moved from sysdeps/s390/multiarch/strncpy.c with 71% similarity]

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