From patchwork Mon Nov 17 07:47:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 124506 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 55CED3858D20 for ; Mon, 17 Nov 2025 07:48:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55CED3858D20 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (sonata.ens-lyon.org [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id B67183858D3C for ; Mon, 17 Nov 2025 07:47:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B67183858D3C 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 B67183858D3C 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=1763365636; cv=none; b=vq3GuHqi0JDWxgkfRO1yEoFEeWXtOJhHGSAFKUiSYuSofUAFHIOoceuUqBhfJ2bxvo38w6zuXEznRSZSqKGUtsjvL2XI6L+bRqRZBP706MSKeT5bWYMQk8/ojEYrvsBY6wwD3UlSW0JuKQkxrzmghmocBLtWxYS6z1wEJjlQpik= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763365636; c=relaxed/simple; bh=5Fr7sYKeOd9U3rwQv0iFf0GwbF5G+zJi8JVth8/OypU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=EP9eMTnRToWzeScHlsrDfkP3xOtt1ubIWlHkw1IcZ3msKutlbFqSwk7mYQ8ocsXd6Svzh0gNk1tP6/j5mJRNaD4bQsNagMYp9yeg7dyUuSHyFqhJGKbinV9Spi841xca1dawd5gZKJK4Xuy9pgh0dA/NrhjJXdjTvQb/+ztuN6Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B67183858D3C Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id E2B1AA20F7; Mon, 17 Nov 2025 08:47:15 +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 kSH0BBonFKEk; Mon, 17 Nov 2025 08:47:15 +0100 (CET) Received: from end (aamiens-653-1-40-48.w83-192.abo.wanadoo.fr [83.192.199.48]) (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 C9003A0387; Mon, 17 Nov 2025 08:47:15 +0100 (CET) Received: from samy by end with local (Exim 4.99) (envelope-from ) id 1vKtxD-0000000CqCE-1Vac; Mon, 17 Nov 2025 08:47:15 +0100 From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] htl: move pthread_create to into libc Date: Mon, 17 Nov 2025 08:47:14 +0100 Message-ID: <20251117074714.3060565-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 This is notably needed for the main thread structure to be always initialized so that some pthread functions can work from the main thread without other threads, e.g. pthread_cancel. --- htl/Makefile | 4 +-- htl/Versions | 12 +++----- htl/pt-create.c | 34 ++++++++++++++------- hurd/hurdsig.c | 6 ++-- sysdeps/htl/pthreadP.h | 7 ++--- sysdeps/mach/hurd/htl/pt-sysdep.c | 14 +++------ sysdeps/mach/hurd/i386/libc.abilist | 2 ++ sysdeps/mach/hurd/i386/libpthread.abilist | 1 - sysdeps/mach/hurd/x86_64/libc.abilist | 2 ++ sysdeps/mach/hurd/x86_64/libpthread.abilist | 1 - 10 files changed, 43 insertions(+), 40 deletions(-) diff --git a/htl/Makefile b/htl/Makefile index f841b33b51..e59a7fff68 100644 --- a/htl/Makefile +++ b/htl/Makefile @@ -25,11 +25,9 @@ SYSDEPS := LCLHDRS := libpthread-routines := \ - pt-create \ pt-spin-inlines \ pt-hurd-cond-wait \ pt-hurd-cond-timedwait \ - pt-sysdep \ pt-spin \ pt-getname-np \ pt-setname-np \ @@ -115,6 +113,7 @@ routines := \ pt-condattr-init \ pt-condattr-setclock \ pt-condattr-setpshared \ + pt-create \ pt-dealloc \ pt-destroy-specific \ pt-detach \ @@ -185,6 +184,7 @@ routines := \ pt-sigstate-init \ pt-stack-alloc \ pt-startup \ + pt-sysdep \ pt-testcancel \ pt-thread-alloc \ pt-thread-start \ diff --git a/htl/Versions b/htl/Versions index 280459c2a6..d46490b3a5 100644 --- a/htl/Versions +++ b/htl/Versions @@ -53,6 +53,7 @@ libc { pthread_condattr_getpshared; pthread_condattr_setclock; pthread_condattr_setpshared; + pthread_create; pthread_detach; pthread_getattr_np; pthread_getconcurrency; @@ -219,6 +220,7 @@ libc { GLIBC_2.43 { pthread_cancel; pthread_clockjoin_np; + pthread_create; pthread_detach; pthread_getattr_np; pthread_getconcurrency; @@ -252,6 +254,7 @@ libc { __pthread_alloc; __pthread_block; __pthread_block_intr; + __pthread_create; __pthread_init_thread; __pthread_init_static_tls; __pthread_default_attr; @@ -279,6 +282,7 @@ libc { __pthread_destroy_specific; __pthread_exit; __pthread_getspecific; + __pthread_initialize_minimal; __pthread_join; __pthread_key_delete; __pthread_max_threads; @@ -316,8 +320,6 @@ libpthread { GLIBC_2.12 { pthread_atfork; - pthread_create; - pthread_spin_destroy; pthread_spin_init; pthread_spin_lock; pthread_spin_trylock; pthread_spin_unlock; __pthread_spin_destroy; __pthread_spin_init; @@ -342,10 +344,4 @@ libpthread { pthread_getname_np; pthread_setname_np; } - - GLIBC_PRIVATE { - __pthread_initialize_minimal; - - __pthread_create; - } } diff --git a/htl/pt-create.c b/htl/pt-create.c index d3fee29d20..820037e8a9 100644 --- a/htl/pt-create.c +++ b/htl/pt-create.c @@ -25,13 +25,14 @@ #include #include #include +#include +#include #include #include -#if IS_IN (libpthread) -# include -#endif +#include + #ifdef HAVE_USELOCALE # include #endif @@ -45,10 +46,9 @@ entry_point (struct __pthread *self, void *(*start_routine) (void *), void *arg) ___pthread_self = self; __resp = &self->res_state; -#if IS_IN (libpthread) /* Initialize pointers to locale data. */ __ctype_init (); -#endif + #ifdef HAVE_USELOCALE /* A fresh thread needs to be bound to the global locale. */ uselocale (LC_GLOBAL_LOCALE); @@ -78,6 +78,24 @@ entry_point (struct __pthread *self, void *(*start_routine) (void *), void *arg) int __pthread_create (pthread_t * thread, const pthread_attr_t * attr, void *(*start_routine) (void *), void *arg) +{ + /* Avoid a data race in the multi-threaded case. */ + if (__libc_single_threaded) + __libc_single_threaded = 0; + + return __libc_pthread_create (thread, attr, start_routine, arg); +} +versioned_symbol (libc, __pthread_create, pthread_create, GLIBC_2_43); +#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_12, GLIBC_2_43) +compat_symbol (libpthread, __pthread_create, pthread_create, GLIBC_2_12); +#endif +hidden_def (__pthread_create) + +/* Version of pthread_create which does not make __libc_single_threaded zero. + This is notably useful for the signal thread. */ +int +__libc_pthread_create (pthread_t * thread, const pthread_attr_t * attr, + void *(*start_routine) (void *), void *arg) { int err; struct __pthread *pthread; @@ -90,8 +108,6 @@ __pthread_create (pthread_t * thread, const pthread_attr_t * attr, return err; } -weak_alias (__pthread_create, pthread_create) -hidden_def (__pthread_create) /* Internal version of pthread_create. See comment in pt-internal.h. */ @@ -106,10 +122,6 @@ __pthread_create_internal (struct __pthread **thread, sigset_t sigset; size_t stacksize; - /* Avoid a data race in the multi-threaded case. */ - if (__libc_single_threaded) - __libc_single_threaded = 0; - /* Allocate a new thread structure. */ err = __pthread_alloc (&pthread); if (err) diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c index 672bc06f88..ab02b1d7e5 100644 --- a/hurd/hurdsig.c +++ b/hurd/hurdsig.c @@ -1519,8 +1519,8 @@ _hurdsig_init (const int *intarray, size_t intarraysize) /* Start the signal thread listening on the message port. */ -#pragma weak __pthread_create - if (!__pthread_create) +#pragma weak __libc_pthread_create + if (!__libc_pthread_create) { err = __thread_create (__mach_task_self (), &_hurd_msgport_thread); assert_perror (err); @@ -1564,7 +1564,7 @@ _hurdsig_init (const int *intarray, size_t intarraysize) #pragma weak __pthread_detach #pragma weak __pthread_getattr_np #pragma weak __pthread_attr_getstack - __pthread_create(&thread, NULL, &_hurd_msgport_receive, NULL); + __libc_pthread_create (&thread, NULL, &_hurd_msgport_receive, NULL); /* Record signal thread stack layout for fork() */ __pthread_getattr_np (thread, &attr); diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h index 471a4cfa43..5fb6469714 100644 --- a/sysdeps/htl/pthreadP.h +++ b/sysdeps/htl/pthreadP.h @@ -24,7 +24,6 @@ #include #include #include -#include /* Attribute to indicate thread creation was issued from C11 thrd_create. */ #define ATTR_C11_THREAD ((void*)(uintptr_t)-1) @@ -170,6 +169,8 @@ libc_hidden_proto (__pthread_setcanceltype); extern int __pthread_sigmask (int, const sigset_t *, sigset_t *); libc_hidden_proto (__pthread_sigmask); +int __libc_pthread_create (pthread_t * thread, const pthread_attr_t * attr, + void *(*start_routine) (void *), void *arg); int __pthread_create (pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); @@ -232,9 +233,7 @@ libc_hidden_proto (__pthread_attr_init) libc_hidden_proto (__pthread_condattr_init) libc_hidden_proto (__pthread_get_cleanup_stack) -#if IS_IN (libpthread) -hidden_proto (__pthread_create) -#endif +libc_hidden_proto (__pthread_create) #define ASSERT_TYPE_SIZE(type, size) \ _Static_assert (sizeof (type) == size, \ diff --git a/sysdeps/mach/hurd/htl/pt-sysdep.c b/sysdeps/mach/hurd/htl/pt-sysdep.c index 43745095bf..4d6a710ca8 100644 --- a/sysdeps/mach/hurd/htl/pt-sysdep.c +++ b/sysdeps/mach/hurd/htl/pt-sysdep.c @@ -26,6 +26,9 @@ #include #include #include +#include +#include +#include static void reset_pthread_total (void) @@ -118,7 +121,7 @@ _init_routine (void *stack) when we return from here) shouldn't be seen as a user thread. */ __pthread_total--; - __pthread_atfork (NULL, NULL, reset_pthread_total); + __register_atfork (NULL, NULL, reset_pthread_total, __dso_handle); GL(dl_init_static_tls) = &__pthread_init_static_tls; @@ -131,12 +134,3 @@ __pthread_initialize_minimal (void) { _init_routine (__libc_stack_end); } - -#ifdef SHARED -__attribute__ ((constructor)) -static void -dynamic_init_routine (void) -{ - _init_routine (__libc_stack_end); -} -#endif diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist index bbd00ed11a..f7c323c834 100644 --- a/sysdeps/mach/hurd/i386/libc.abilist +++ b/sysdeps/mach/hurd/i386/libc.abilist @@ -76,6 +76,7 @@ GLIBC_2.12 pthread_condattr_getpshared F GLIBC_2.12 pthread_condattr_init F GLIBC_2.12 pthread_condattr_setclock F GLIBC_2.12 pthread_condattr_setpshared F +GLIBC_2.12 pthread_create F GLIBC_2.12 pthread_detach F GLIBC_2.12 pthread_equal F GLIBC_2.12 pthread_exit F @@ -2670,6 +2671,7 @@ GLIBC_2.43 memalignment F GLIBC_2.43 memset_explicit F GLIBC_2.43 pthread_cancel F GLIBC_2.43 pthread_clockjoin_np F +GLIBC_2.43 pthread_create F GLIBC_2.43 pthread_detach F GLIBC_2.43 pthread_getattr_np F GLIBC_2.43 pthread_getconcurrency F diff --git a/sysdeps/mach/hurd/i386/libpthread.abilist b/sysdeps/mach/hurd/i386/libpthread.abilist index c55b78b01c..e1844a8f5e 100644 --- a/sysdeps/mach/hurd/i386/libpthread.abilist +++ b/sysdeps/mach/hurd/i386/libpthread.abilist @@ -5,7 +5,6 @@ GLIBC_2.12 __pthread_spin_trylock F GLIBC_2.12 __pthread_spin_unlock F GLIBC_2.12 _pthread_spin_lock F GLIBC_2.12 pthread_atfork F -GLIBC_2.12 pthread_create F GLIBC_2.12 pthread_spin_destroy F GLIBC_2.12 pthread_spin_init F GLIBC_2.12 pthread_spin_lock F diff --git a/sysdeps/mach/hurd/x86_64/libc.abilist b/sysdeps/mach/hurd/x86_64/libc.abilist index 5fb477342e..b482d2d040 100644 --- a/sysdeps/mach/hurd/x86_64/libc.abilist +++ b/sysdeps/mach/hurd/x86_64/libc.abilist @@ -1556,6 +1556,7 @@ GLIBC_2.38 pthread_condattr_getpshared F GLIBC_2.38 pthread_condattr_init F GLIBC_2.38 pthread_condattr_setclock F GLIBC_2.38 pthread_condattr_setpshared F +GLIBC_2.38 pthread_create F GLIBC_2.38 pthread_detach F GLIBC_2.38 pthread_equal F GLIBC_2.38 pthread_exit F @@ -2348,6 +2349,7 @@ GLIBC_2.43 memalignment F GLIBC_2.43 memset_explicit F GLIBC_2.43 pthread_cancel F GLIBC_2.43 pthread_clockjoin_np F +GLIBC_2.43 pthread_create F GLIBC_2.43 pthread_detach F GLIBC_2.43 pthread_getattr_np F GLIBC_2.43 pthread_getconcurrency F diff --git a/sysdeps/mach/hurd/x86_64/libpthread.abilist b/sysdeps/mach/hurd/x86_64/libpthread.abilist index 77d9a6601d..d4ae93df53 100644 --- a/sysdeps/mach/hurd/x86_64/libpthread.abilist +++ b/sysdeps/mach/hurd/x86_64/libpthread.abilist @@ -17,7 +17,6 @@ GLIBC_2.38 mtx_lock F GLIBC_2.38 mtx_timedlock F GLIBC_2.38 mtx_trylock F GLIBC_2.38 mtx_unlock F -GLIBC_2.38 pthread_create F GLIBC_2.38 pthread_hurd_cond_timedwait_np F GLIBC_2.38 pthread_hurd_cond_wait_np F GLIBC_2.38 pthread_spin_destroy F