]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Fix tunable handing with clang
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 17 Oct 2025 19:13:22 +0000 (16:13 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 21 Oct 2025 12:26:04 +0000 (09:26 -0300)
Recent clang version optimizes some loops contructions to strlen [1],
which might generate function calls when self-relocation is not
already done (on tunable parsing).  Use an out-of-line function
with __attribute_optimization_barrier__ to avoid this.

[1] https://github.com/llvm/llvm-project/pull/132572/commits/facd7dfc80d655fe49baf4bf27e144a4c890a149

Reviewed-by: Sam James <sam@gentoo.org>
elf/dl-printf.c
elf/dl-tunables.c

index ebfc7eee86afb071ca260bcecc5878526cc50669..77551f99eb7c184d62a0a74e4a6c86457266e678 100644 (file)
@@ -35,6 +35,7 @@
 
 /* The function might be called before the process is self-relocated.  */
 static size_t
+__attribute_optimization_barrier__
 _dl_debug_strlen (const char *s)
 {
   const char *p = s;
index f65480690a6cba8a21152e52787f7d230fcde76d..f145481d554a898077b14694de8ff26b121c056e 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)
 {
@@ -324,9 +334,8 @@ __tunables_init (char **envp)
 
          if (tunable_is_name (name, envname))
            {
-             size_t envvallen = 0;
              /* The environment variable is always null-terminated.  */
-             for (const char *p = envval; *p != '\0'; p++, envvallen++);
+             size_t envvallen = _dl_strlen (envval);
 
              tunables_env_alias[i] =
                (struct tunable_toset_t) { cur, envval, envvallen };