]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Use dl-symbol-redir-ifunc.h instead _dl_strlen master
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 12 Feb 2026 12:48:53 +0000 (09:48 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 18 Feb 2026 12:35:03 +0000 (09:35 -0300)
Also replace the loop with strlen And remove
-fno-tree-loop-distribute-patterns usage.

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

Checked on x86_64-linux-gnu{-v2,v3} and aarch64-linux-gnu with
both gcc-15 and clang-21.

Reviewed-by: DJ Delorie <dj@redhat.com>
elf/Makefile
elf/dl-tunables.c
string/Makefile
sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h
sysdeps/aarch64/multiarch/strlen_generic.S
sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h
sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h

index 396e97b5e73ccf1e2c131ba55e1de373f118219a..1a0ed49bc3b1063cdeffea200970b0c97c77eb4f 100644 (file)
@@ -97,12 +97,6 @@ ifeq (yesyes,$(build-shared)$(run-built-tests))
 tests-special += $(objpfx)list-tunables.out
 endif
 
-# Make sure that the compiler does not insert any library calls in tunables
-# code paths.
-ifeq (yes,$(have-loop-to-function))
-CFLAGS-dl-tunables.c += -fno-tree-loop-distribute-patterns
-endif
-
 all-dl-routines = $(dl-routines) $(sysdep-dl-routines)
 # But they are absent from the shared libc, because that code is in ld.so.
 elide-routines.os = \
index 37ade374c62f957a12bf0f0c0066df6e0f2c110f..bdb1de4ceba40b17fe5e10be246702b8bd25a812 100644 (file)
 #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)
 {
@@ -335,10 +325,8 @@ __tunables_init (char **envp)
          if (tunable_is_name (name, envname))
            {
              /* The environment variable is always null-terminated.  */
-             size_t envvallen = _dl_strlen (envval);
-
              tunables_env_alias[i] =
-               (struct tunable_toset_t) { cur, envval, envvallen };
+               (struct tunable_toset_t) { cur, envval, strlen (envval) };
              break;
            }
        }
index c4423c0437da2b770b360441a60cee3a5b0b842d..aa0b0c2f57a31128155d56e5e539a0294d22ce78 100644 (file)
@@ -286,6 +286,7 @@ CFLAGS-wordcopy.c += $(no-stack-protector)
 # Called during static initialization
 CFLAGS-strncmp.c += $(no-stack-protector)
 CFLAGS-memset.c += $(no-stack-protector)
+CFLAGS-strlen.c += $(no-stack-protector)
 
 ifeq ($(run-built-tests),yes)
 $(objpfx)tst-svc-cmp.out: tst-svc.expect $(objpfx)tst-svc.out
index 647bdd66dde6dc4f1b8bed39cfd2155218f7c99a..9f772614bf60e496fd85c59edf4aee5874439ed2 100644 (file)
@@ -20,5 +20,6 @@
 #define _DL_IFUNC_GENERIC_H
 
 asm ("memset = __memset_generic");
+asm ("strlen = __strlen_generic");
 
 #endif
index cb9d5759acf04e73e98b68187c9b548517313a26..a362328142cf1fa66a858e869194fe8ad558f588 100644 (file)
@@ -40,3 +40,7 @@
 #endif
 
 #include "../strlen.S"
+
+#if IS_IN (rtld)
+strong_alias (strlen, __strlen_generic)
+#endif
index 9fdd039da0faf977377c155c763c4fcdc1d0fac8..8af00d2846b3dc3042bb4d8121c2fb57a9717a45 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef SHARED
 asm ("memset = __memset_aligned");
 asm ("memcmp = __memcmp_aligned");
+asm ("strlen = __strlen_aligned");
 #endif
 
 #endif
index 1d26966dedf6749a18d0f01ae730d7d6f3af7314..a865090a539b98b9c42a6f08973df0ed9941d80e 100644 (file)
@@ -9,4 +9,6 @@ sysdep_routines += \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
+# Called during static initialization
+CFLAGS-memset-generic.c += $(no-stack-protector)
 endif
index 04b6c1e6a3a773e7d038387e80ce27f9926c5d1a..b607e525f2ce8f48a5468a4347055eec4349d0ee 100644 (file)
@@ -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