From patchwork Mon Mar 16 08:14:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 131775 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 8558F4BB3BA2 for ; Mon, 16 Mar 2026 08:14:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8558F4BB3BA2 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id 5A7044BAE7DE for ; Mon, 16 Mar 2026 08:14:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A7044BAE7DE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5A7044BAE7DE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.77.166.138 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773648865; cv=none; b=sh24b08WB0re6nPXzhejQaVDKQb2gxTn2kCrw/ME3AS8TjikjMFxWMBJ5xSDSCeGhDxM7gi01uyHMNeyotijumQ5IKVsSWDoP5oC/xjrLzYe63CK2s5LEy9rdP8L9Hbn0JufXjMkQu9+oEmzbKzw2iugHgsjzGwsgBNlqZmUqD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773648865; c=relaxed/simple; bh=+lkew0g4BurPeuptpT3RfMoZYYSj+7wbrQE36DdMBzc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=k8Pn1um/mfqEmyhMT40i0BSDdXHR31Oo726oDKEMKf6OdodBZxa+HsZQ0rqTAZmubysRN3nskIIfiPG95Qsmy120Y6+g8E8D1bkPFKpz3BvIu3TMcvZ0zikT/ri+7eTdwAJuvSdGAlpsChUgYHdYg8SNvmvHaRVdAtxbYBA6kDw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A7044BAE7DE Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 96D4EA491C; Mon, 16 Mar 2026 09:14:22 +0100 (CET) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K1NFHmULGodd; Mon, 16 Mar 2026 09:14:22 +0100 (CET) Received: from end (unknown [212.133.41.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id 6F4A6A1FD1; Mon, 16 Mar 2026 09:14:22 +0100 (CET) Received: from samy by end with local (Exim 4.99.1) (envelope-from ) id 1w235h-0000000BD1K-38VZ; Mon, 16 Mar 2026 09:14:21 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] elf: directly call dl_init_static_tls Date: Mon, 16 Mar 2026 09:14:19 +0100 Message-ID: <20260316081419.2671651-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, PROLO_LEO1, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org 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 #include #include +#include -#if PTHREAD_IN_LIBC +#ifdef __PTHREAD_NPTL # include #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 #include -#include +#include 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 + . */ + +#include +#include + +#include +#include + +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); }