htl can now have it directly in ld.so
---
 elf/dl-open.c                       |  2 +-
 elf/dl-reloc.c                      | 23 +----------
 elf/dl-support.c                    |  3 --
 elf/dl-tls.c                        |  7 ++--
 elf/dl-tls_init_tp.c                |  3 --
 htl/Versions                        |  1 -
 htl/pt-alloc.c                      | 30 --------------
 sysdeps/generic/ldsodefs.h          | 23 ++---------
 sysdeps/htl/Makefile                |  4 ++
 sysdeps/htl/dl-thread_gscope_wait.c |  2 +-
 {htl => sysdeps/htl}/pt-internal.h  |  0
 sysdeps/htl/pt-static-tls.c         | 64 +++++++++++++++++++++++++++++
 sysdeps/htl/pthreadP.h              |  3 --
 sysdeps/mach/hurd/htl/pt-sysdep.c   |  2 -
 14 files changed, 78 insertions(+), 89 deletions(-)
 rename {htl => sysdeps/htl}/pt-internal.h (100%)
 create mode 100644 sysdeps/htl/pt-static-tls.c

diff --git a/elf/dl-open.c b/elf/dl-open.c
index da0e8512cf..ee25d4d42b 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -408,7 +408,7 @@ TLS generation counter wrapped!  Please report this."));
          _dl_update_slotinfo (imap->l_tls_modid, newgen);
 #endif
 
-         dl_init_static_tls (imap);
+         _dl_init_static_tls (imap);
          assert (imap->l_need_tls_init == 0);
        }
     }
diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c
index 26a1e7adfc..f1a432ac09 100644
--- a/elf/dl-reloc.c
+++ b/elf/dl-reloc.c
@@ -119,7 +119,7 @@ _dl_try_allocate_static_tls (struct link_map *map, bool 
optional)
        (void) _dl_update_slotinfo (map->l_tls_modid, GL(dl_tls_generation));
 #endif
 
-      dl_init_static_tls (map);
+      _dl_init_static_tls (map);
     }
   else
     map->l_need_tls_init = 1;
@@ -142,27 +142,6 @@ cannot allocate memory in static TLS block"));
     }
 }
 
-#if !PTHREAD_IN_LIBC
-/* Initialize static TLS area and DTV for current (only) thread.
-   libpthread implementations should provide their own hook
-   to handle all threads.  */
-void
-_dl_nothread_init_static_tls (struct link_map *map)
-{
-#if TLS_TCB_AT_TP
-  void *dest = (char *) THREAD_SELF - map->l_tls_offset;
-#elif TLS_DTV_AT_TP
-  void *dest = (char *) THREAD_SELF + map->l_tls_offset + TLS_PRE_TCB_SIZE;
-#else
-# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
-#endif
-
-  /* Initialize the memory.  */
-  memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
-         '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
-}
-#endif /* !PTHREAD_IN_LIBC */
-
 static __always_inline lookup_t
 resolve_map (lookup_t l, struct r_scope_elem *scope[], const ElfW(Sym) **ref,
             const struct r_found_version *version, unsigned long int r_type)
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 7505e149e2..a782c09c94 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -177,9 +177,6 @@ size_t _dl_stack_cache_actsize;
 uintptr_t _dl_in_flight_stack;
 int _dl_stack_cache_lock;
 #endif
-#if !PTHREAD_IN_LIBC
-void (*_dl_init_static_tls) (struct link_map *) = 
&_dl_nothread_init_static_tls;
-#endif
 struct dl_scope_free_list *_dl_scope_free_list;
 
 #ifdef NEED_DL_SYSINFO
diff --git a/elf/dl-tls.c b/elf/dl-tls.c
index 5bfcb184ed..21fb5b5ed7 100644
--- a/elf/dl-tls.c
+++ b/elf/dl-tls.c
@@ -29,8 +29,9 @@
 #include <dl-tls.h>
 #include <ldsodefs.h>
 #include <dl-tls_block_align.h>
+#include <pthreadP.h>
 
-#if PTHREAD_IN_LIBC
+#ifdef __PTHREAD_NPTL
 # include <list.h>
 #endif
 
@@ -1300,7 +1301,7 @@ cannot create TLS data structures"));
   return true;
 }
 
-#if PTHREAD_IN_LIBC
+#ifdef __PTHREAD_NPTL
 static inline void __attribute__((always_inline))
 init_one_static_tls (struct pthread *curp, struct link_map *map)
 {
@@ -1333,4 +1334,4 @@ _dl_init_static_tls (struct link_map *map)
 
   lll_unlock (GL (dl_stack_cache_lock), LLL_PRIVATE);
 }
-#endif /* PTHREAD_IN_LIBC */
+#endif /* __PTHREAD_NPTL */
diff --git a/elf/dl-tls_init_tp.c b/elf/dl-tls_init_tp.c
index 3ab262ae31..fc97e8a744 100644
--- a/elf/dl-tls_init_tp.c
+++ b/elf/dl-tls_init_tp.c
@@ -21,9 +21,6 @@
 void
 __tls_pre_init_tp (void)
 {
-#if !PTHREAD_IN_LIBC
-  GL(dl_init_static_tls) = &_dl_nothread_init_static_tls;
-#endif
 }
 
 void
diff --git a/htl/Versions b/htl/Versions
index cac34e623b..6b77fe21f7 100644
--- a/htl/Versions
+++ b/htl/Versions
@@ -307,7 +307,6 @@ libc {
     __pthread_block_intr;
     __pthread_create;
     __pthread_init_thread;
-    __pthread_init_static_tls;
     __pthread_default_attr;
     __pthread_attr_init;
     __pthread_attr_getstacksize;
diff --git a/htl/pt-alloc.c b/htl/pt-alloc.c
index 53833d3f20..f23d9d3e5b 100644
--- a/htl/pt-alloc.c
+++ b/htl/pt-alloc.c
@@ -204,33 +204,3 @@ retry:
   return 0;
 }
 libc_hidden_def (__pthread_alloc)
-
-void
-attribute_hidden
-__pthread_init_static_tls (struct link_map *map)
-{
-  int i;
-
-  __mach_rwlock_wrlock (GL (dl_pthread_threads_lock));
-  for (i = 0; i < GL (dl_pthread_num_threads); ++i)
-    {
-      struct __pthread *t = GL (dl_pthread_threads)[i];
-
-      if (t == NULL)
-       continue;
-
-# if TLS_TCB_AT_TP
-      void *dest = (char *) t->tcb - map->l_tls_offset;
-# elif TLS_DTV_AT_TP
-      void *dest = (char *) t->tcb + map->l_tls_offset + TLS_PRE_TCB_SIZE;
-# else
-#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
-# endif
-
-      /* Initialize the memory.  */
-      memset (__mempcpy (dest, map->l_tls_initimage, 
map->l_tls_initimage_size),
-             '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
-    }
-  __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
-}
-libc_hidden_def (__pthread_init_static_tls)
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 46a7119b3a..cbb8273a7d 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -441,10 +441,6 @@ struct rtld_global
   /* Generation counter for the dtv.  */
   EXTERN size_t _dl_tls_generation;
 
-#if !PTHREAD_IN_LIBC
-  EXTERN void (*_dl_init_static_tls) (struct link_map *);
-#endif
-
   /* Scopes to free after next THREAD_GSCOPE_WAIT ().  */
   EXTERN struct dl_scope_free_list
   {
@@ -1239,8 +1235,6 @@ extern bool __rtld_tls_init_tp_called attribute_hidden;
 extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb);
 rtld_hidden_proto (_dl_deallocate_tls)
 
-extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden;
-
 /* Get a pointer to _dl_main_map.  */
 extern struct link_map * _dl_get_dl_main_map (void) attribute_hidden;
 
@@ -1321,21 +1315,10 @@ extern void _dl_aux_init (ElfW(auxv_t) *av)
      attribute_hidden;
 
 /* Initialize the static TLS space for the link map in all existing
-   threads. */
-#if PTHREAD_IN_LIBC
+   threads.
+   The stack list is available to ld.so, so the initialization can
+   be handled within ld.so directly.  */
 void _dl_init_static_tls (struct link_map *map) attribute_hidden;
-#endif
-static inline void
-dl_init_static_tls (struct link_map *map)
-{
-#if PTHREAD_IN_LIBC
-  /* The stack list is available to ld.so, so the initialization can
-     be handled within ld.so directly.  */
-  _dl_init_static_tls (map);
-#else
-  GL (dl_init_static_tls) (map);
-#endif
-}
 
 #ifndef SHARED
 /* Called before relocating ld.so during static dlopen.  This can be
diff --git a/sysdeps/htl/Makefile b/sysdeps/htl/Makefile
index 624d1be7b6..f71e003bb7 100644
--- a/sysdeps/htl/Makefile
+++ b/sysdeps/htl/Makefile
@@ -5,3 +5,7 @@ endif
 ifeq ($(subdir),posix)
 CFLAGS-confstr.c += -DLIBPTHREAD_VERSION='"HTL $(version)"'
 endif
+
+ifeq ($(subdir),elf)
+sysdep-dl-routines += pt-static-tls
+endif
diff --git a/sysdeps/htl/dl-thread_gscope_wait.c 
b/sysdeps/htl/dl-thread_gscope_wait.c
index d8428d4491..e2a008112c 100644
--- a/sysdeps/htl/dl-thread_gscope_wait.c
+++ b/sysdeps/htl/dl-thread_gscope_wait.c
@@ -18,7 +18,7 @@
 
 #include <ldsodefs.h>
 #include <pthread.h>
-#include <htl/pt-internal.h>
+#include <pt-internal.h>
 
 static inline int *
 thread_gscope_flag (struct __pthread *t)
diff --git a/htl/pt-internal.h b/sysdeps/htl/pt-internal.h
similarity index 100%
rename from htl/pt-internal.h
rename to sysdeps/htl/pt-internal.h
diff --git a/sysdeps/htl/pt-static-tls.c b/sysdeps/htl/pt-static-tls.c
new file mode 100644
index 0000000000..d627fbd684
--- /dev/null
+++ b/sysdeps/htl/pt-static-tls.c
@@ -0,0 +1,64 @@
+/* Initialize the static TLS space for the link map in all existing threads.
+   Copyright (C) 2000-2026 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 <pthread.h>
+#include <string.h>
+
+#include <pt-internal.h>
+#include <ldsodefs.h>
+
+static inline void __attribute__((always_inline))
+init_one_static_tls (tcbhead_t *curp, struct link_map *map)
+{
+# if TLS_TCB_AT_TP
+  void *dest = (char *) curp - map->l_tls_offset;
+# elif TLS_DTV_AT_TP
+  void *dest = (char *) curp + map->l_tls_offset + TLS_PRE_TCB_SIZE;
+# else
+#  error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
+# endif
+
+  /* Initialize the memory.  */
+  memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size),
+         '\0', map->l_tls_blocksize - map->l_tls_initimage_size);
+}
+
+
+void
+_dl_init_static_tls (struct link_map *map)
+{
+  int i;
+
+  if (!GL (dl_pthread_num_threads))
+    {
+      init_one_static_tls (THREAD_SELF, map);
+      return;
+    }
+
+  __mach_rwlock_wrlock (GL (dl_pthread_threads_lock));
+  for (i = 0; i < GL (dl_pthread_num_threads); ++i)
+    {
+      struct __pthread *t = GL (dl_pthread_threads)[i];
+
+      if (t == NULL)
+       continue;
+
+      init_one_static_tls (t->tcb, map);
+    }
+  __mach_rwlock_unlock (GL (dl_pthread_threads_lock));
+}
diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
index d6e669abf8..2ae24074e9 100644
--- a/sysdeps/htl/pthreadP.h
+++ b/sysdeps/htl/pthreadP.h
@@ -28,9 +28,6 @@
 /* Attribute to indicate thread creation was issued from C11 thrd_create.  */
 #define ATTR_C11_THREAD ((void*)(uintptr_t)-1)
 
-extern void __pthread_init_static_tls (struct link_map *);
-libc_hidden_proto (__pthread_init_static_tls)
-
 /* These represent the interface used by glibc itself.  */
 
 extern int __pthread_barrier_destroy (pthread_barrier_t *__barrier);
diff --git a/sysdeps/mach/hurd/htl/pt-sysdep.c 
b/sysdeps/mach/hurd/htl/pt-sysdep.c
index 3d7907e051..8f89b69f4b 100644
--- a/sysdeps/mach/hurd/htl/pt-sysdep.c
+++ b/sysdeps/mach/hurd/htl/pt-sysdep.c
@@ -123,8 +123,6 @@ _init_routine (void *stack)
 
   __register_atfork (NULL, NULL, reset_pthread_total, __dso_handle);
 
-  GL(dl_init_static_tls) = &__pthread_init_static_tls;
-
   /* Make MiG code thread aware.  */
   __mig_init (thread->stackaddr);
 }
-- 
2.51.0


Reply via email to