From: Christoph Müllner <christoph.muellner@vrull.eu>
This patch adds ifunc support for calls to strncmp 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 | 3 +-
sysdeps/riscv/multiarch/ifunc-impl-list.c | 2 ++
sysdeps/riscv/multiarch/strncmp.c | 40 +++++++++++++++++++++++
sysdeps/riscv/multiarch/strncmp_generic.c | 32 ++++++++++++++++++
4 files changed, 76 insertions(+), 1 deletion(-)
create mode 100644 sysdeps/riscv/multiarch/strncmp.c
create mode 100644 sysdeps/riscv/multiarch/strncmp_generic.c
@@ -13,5 +13,6 @@ sysdep_routines += \
\
strcmp_generic \
strcmp_zbb \
- strcmp_zbb_unaligned
+ strcmp_zbb_unaligned \
+ strncmp_generic
endif
@@ -63,5 +63,7 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_zbb)
IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic))
+ IFUNC_IMPL (i, name, strncmp,
+ IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_generic))
return i;
}
new file mode 100644
@@ -0,0 +1,40 @@
+/* Multiple versions of strncmp. 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 strncmp so that the compiler won't complain about the type
+ mismatch with the IFUNC selector in strong_alias, below. */
+# undef strncmp
+# define strncmp __redirect_strncmp
+# include <string.h>
+# include <ldsodefs.h>
+# include <sys/auxv.h>
+# include <init-arch.h>
+
+extern __typeof (__redirect_strncmp) __libc_strncmp;
+extern __typeof (__redirect_strncmp) __strncmp_generic attribute_hidden;
+
+libc_ifunc (__libc_strncmp, __strncmp_generic);
+
+# undef strncmp
+strong_alias (__libc_strncmp, strncmp);
+#else
+# include <string/strncmp.c>
+#endif
new file mode 100644
@@ -0,0 +1,32 @@
+/* strncmp 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 STRNCMP __strncmp_generic
+
+#ifdef SHARED
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name) \
+ __hidden_ver1(__strncmp_generic, __GI_strncmp, __strncmp_generic);
+#endif
+
+extern int __strncmp_generic(const char *s1, const char *s2, size_t n);
+
+#include <string/strncmp.c>