[PATCH] elf: Use dl-symbol-redir-ifunc.h instead _dl_strlen

Adhemerval Zanella adhemerval.zanella@linaro.org
Wed Feb 11 13:50:27 GMT 2026


It requires redirect the strlen to the baseline implementation
for x86_64 and aarch64.

Checked on x86_64-linux-gnu{-v2,v3} and aarch64-linux-gnu with
both gcc-15 and clang-21.
---
 elf/dl-tunables.c                                 | 13 ++-----------
 sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h |  1 +
 sysdeps/aarch64/multiarch/strlen_generic.S        |  4 ++++
 sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h  | 10 ++++++++++
 4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index 37ade374c6..518f44eca6 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -37,16 +37,6 @@
 #define TUNABLES_INTERNAL 1
 #include "dl-tunables.h"
 
-/* The function might be called before the process is self-relocated.  */
-static size_t
-__attribute_optimization_barrier__
-_dl_strlen (const char *s)
-{
-  const char *p = s;
-  for (; *s != '\0'; s++);
-  return s - p;
-}
-
 static char **
 get_next_env (char **envp, char **name, char **val, char ***prev_envp)
 {
@@ -334,8 +324,9 @@ __tunables_init (char **envp)
 
 	  if (tunable_is_name (name, envname))
 	    {
+	      size_t envvallen = 0;
 	      /* The environment variable is always null-terminated.  */
-	      size_t envvallen = _dl_strlen (envval);
+	      for (const char *p = envval; *p != '\0'; p++, envvallen++);
 
 	      tunables_env_alias[i] =
 		(struct tunable_toset_t) { cur, envval, envvallen };
diff --git a/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h
index 647bdd66dd..9f772614bf 100644
--- a/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h
+++ b/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h
@@ -20,5 +20,6 @@
 #define _DL_IFUNC_GENERIC_H
 
 asm ("memset = __memset_generic");
+asm ("strlen = __strlen_generic");
 
 #endif
diff --git a/sysdeps/aarch64/multiarch/strlen_generic.S b/sysdeps/aarch64/multiarch/strlen_generic.S
index cb9d5759ac..a362328142 100644
--- a/sysdeps/aarch64/multiarch/strlen_generic.S
+++ b/sysdeps/aarch64/multiarch/strlen_generic.S
@@ -40,3 +40,7 @@
 #endif
 
 #include "../strlen.S"
+
+#if IS_IN (rtld)
+strong_alias (strlen, __strlen_generic)
+#endif
diff --git a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h
index 04b6c1e6a3..b607e525f2 100644
--- a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h
+++ b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h
@@ -44,6 +44,16 @@ asm ("memset = " HAVE_MEMSET_IFUNC_GENERIC);
 
 asm ("memcmp = " HAVE_MEMCMP_IFUNC_GENERIC);
 
+#if MINIMUM_X86_ISA_LEVEL >= 4
+# define HAVE_STRCMP_IFUNC_GENERIC "__strlen_evex"
+#elif MINIMUM_X86_ISA_LEVEL == 3
+# define HAVE_STRCMP_IFUNC_GENERIC "__strlen_avx2"
+#else
+# define HAVE_STRCMP_IFUNC_GENERIC "__strlen_sse2"
+#endif
+
+asm ("strlen = " HAVE_STRCMP_IFUNC_GENERIC);
+
 #endif /* SHARED */
 
 #endif
-- 
2.43.0



More information about the Libc-alpha mailing list