[RFC,15/19] riscv: Add ifunc support for strcmp

Message ID 20230207001618.458947-16-christoph.muellner@vrull.eu
State New
Headers
Series riscv: ifunc support with optimized mem*/str*/cpu_relax routines |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Christoph Müllner Feb. 7, 2023, 12:16 a.m. UTC
  From: Christoph Müllner <christoph.muellner@vrull.eu>

This patch adds ifunc support for calls to strcmp to the RISC-V code.
No optimized code is added as part of this patch.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
---
 sysdeps/riscv/multiarch/Makefile          |  4 ++-
 sysdeps/riscv/multiarch/ifunc-impl-list.c |  2 ++
 sysdeps/riscv/multiarch/strcmp.c          | 40 +++++++++++++++++++++++
 sysdeps/riscv/multiarch/strcmp_generic.c  | 32 ++++++++++++++++++
 4 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/riscv/multiarch/strcmp.c
 create mode 100644 sysdeps/riscv/multiarch/strcmp_generic.c
  

Patch

diff --git a/sysdeps/riscv/multiarch/Makefile b/sysdeps/riscv/multiarch/Makefile
index b2247b7326..3017bde75a 100644
--- a/sysdeps/riscv/multiarch/Makefile
+++ b/sysdeps/riscv/multiarch/Makefile
@@ -9,5 +9,7 @@  sysdep_routines += \
 	memset_rv64_unaligned_cboz64 \
 	\
 	strlen_generic \
-	strlen_zbb
+	strlen_zbb \
+	\
+	strcmp_generic
 endif
diff --git a/sysdeps/riscv/multiarch/ifunc-impl-list.c b/sysdeps/riscv/multiarch/ifunc-impl-list.c
index 2b4d2e1c17..64331a4c7f 100644
--- a/sysdeps/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/riscv/multiarch/ifunc-impl-list.c
@@ -58,6 +58,8 @@  __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 	      IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_zbb)
 	      IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic))
 
+  IFUNC_IMPL (i, name, strcmp,
+	      IFUNC_IMPL_ADD (array, i, strcpy, 1, __strcmp_generic))
 
   return i;
 }
diff --git a/sysdeps/riscv/multiarch/strcmp.c b/sysdeps/riscv/multiarch/strcmp.c
new file mode 100644
index 0000000000..8c21a90afd
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strcmp.c
@@ -0,0 +1,40 @@ 
+/* Multiple versions of strcmp. RISC-V version.
+   Copyright (C) 2022 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
+   <https://www.gnu.org/licenses/>.  */
+
+/* Define multiple versions only for the definition in libc.  */
+
+#if IS_IN (libc)
+/* Redefine strcmp so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strcmp
+# define strcmp __redirect_strcmp
+# include <string.h>
+# include <ldsodefs.h>
+# include <sys/auxv.h>
+# include <init-arch.h>
+
+extern __typeof (__redirect_strcmp) __libc_strcmp;
+extern __typeof (__redirect_strcmp) __strcmp_generic attribute_hidden;
+
+libc_ifunc (__libc_strcmp, __strcmp_generic);
+
+# undef strcmp
+strong_alias (__libc_strcmp, strcmp);
+#else
+# include <string/strcmp.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strcmp_generic.c b/sysdeps/riscv/multiarch/strcmp_generic.c
new file mode 100644
index 0000000000..d85cf3940f
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strcmp_generic.c
@@ -0,0 +1,32 @@ 
+/* strcmp for RISC-V, default version for internal use.
+   Copyright (C) 2022 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <string.h>
+
+#define STRCMP __strcmp_generic
+
+#ifdef SHARED
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name) \
+  __hidden_ver1(__strcmp_generic, __GI_strcmp, __strcmp_generic);
+#endif
+
+extern int __strcmp_generic(const char *s1, const char *s2);
+
+#include <string/strcmp.c>