From patchwork Thu May 6 18:10:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 43273 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 560E13AAB459; Thu, 6 May 2021 18:09:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 560E13AAB459 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620324592; bh=1tt5nnXylsVpXucqfb/vaKWc3kIgQqi4BurImgJlD78=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=sbzEz5uyPP5Fq+xd6BcVsn/0XoW3pqWSlbUyAmlQVsx89b6ORBIU5+ShTAMZzE9ne YCkxODSpgXp+xiEy82BQfsCoesH0XexGGyoF/D8irQyDZbatbnxuh2Oy7MbQKi98aT I7TUeiOBQeU+/Iienu7mRIx4OYCcKsk9zWKGrKQo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id BB5A73AAB446 for ; Thu, 6 May 2021 18:09:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BB5A73AAB446 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-9asiPleZOquEsCUuhx9KzQ-1; Thu, 06 May 2021 14:09:47 -0400 X-MC-Unique: 9asiPleZOquEsCUuhx9KzQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 364F418B9EEE for ; Thu, 6 May 2021 18:09:47 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-137.ams2.redhat.com [10.36.112.137]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5BE6760871 for ; Thu, 6 May 2021 18:09:46 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 03/13] nptl: Export __libc_multiple_threads from libc as an internal symbol In-Reply-To: References: Message-Id: <01385e388d7d2659f3562229d5cd61d27683f40a.1620323953.git.fweimer@redhat.com> Date: Thu, 06 May 2021 20:10:05 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This allows the elimination of the __libc_multiple_threads_ptr variable in libpthread and its initialization procedure. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell --- nptl/Versions | 1 + nptl/allocatestack.c | 4 ++-- nptl/libc_multiple_threads.c | 3 ++- nptl/libc_pthread_init.c | 11 ----------- nptl/nptl-init.c | 10 +--------- nptl/pthreadP.h | 6 +----- nptl/pthread_cancel.c | 2 +- sysdeps/unix/sysv/linux/single-thread.h | 6 +++++- 8 files changed, 13 insertions(+), 30 deletions(-) diff --git a/nptl/Versions b/nptl/Versions index f950b77969..fb15a7e8eb 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -305,6 +305,7 @@ libc { __libc_cleanup_pop_restore; __libc_cleanup_push_defer; __libc_dl_error_tsd; + __libc_multiple_threads; __libc_pthread_init; __lll_clocklock_elision; __lll_lock_elision; diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index 8aaba088b1..059786192e 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -477,7 +477,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* This is at least the second thread. */ pd->header.multiple_threads = 1; #ifndef TLS_MULTIPLE_THREADS_IN_TCB - __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1; + __pthread_multiple_threads = __libc_multiple_threads = 1; #endif #ifdef NEED_DL_SYSINFO @@ -598,7 +598,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* This is at least the second thread. */ pd->header.multiple_threads = 1; #ifndef TLS_MULTIPLE_THREADS_IN_TCB - __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1; + __pthread_multiple_threads = __libc_multiple_threads = 1; #endif #ifdef NEED_DL_SYSINFO diff --git a/nptl/libc_multiple_threads.c b/nptl/libc_multiple_threads.c index 60328023cd..a0e7932c26 100644 --- a/nptl/libc_multiple_threads.c +++ b/nptl/libc_multiple_threads.c @@ -23,6 +23,7 @@ /* Variable set to a nonzero value either if more than one thread runs or ran, or if a single-threaded process is trying to cancel itself. See nptl/descr.h for more context on the single-threaded process case. */ -int __libc_multiple_threads attribute_hidden; +int __libc_multiple_threads __attribute__ ((nocommon)); +libc_hidden_data_def (__libc_multiple_threads) # endif #endif diff --git a/nptl/libc_pthread_init.c b/nptl/libc_pthread_init.c index 397b83beb6..75f5d28ed6 100644 --- a/nptl/libc_pthread_init.c +++ b/nptl/libc_pthread_init.c @@ -27,20 +27,9 @@ #include #include - -#ifdef TLS_MULTIPLE_THREADS_IN_TCB void -#else -extern int __libc_multiple_threads attribute_hidden; - -int * -#endif __libc_pthread_init (void (*reclaim) (void)) { /* Called by a child after fork. */ __register_atfork (NULL, NULL, reclaim, NULL); - -#ifndef TLS_MULTIPLE_THREADS_IN_TCB - return &__libc_multiple_threads; -#endif } diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c index 2724770533..2fb1117f3e 100644 --- a/nptl/nptl-init.c +++ b/nptl/nptl-init.c @@ -37,11 +37,6 @@ #include #include -#ifndef TLS_MULTIPLE_THREADS_IN_TCB -/* Pointer to the corresponding variable in libc. */ -int *__libc_multiple_threads_ptr attribute_hidden; -#endif - /* Size and alignment of static TLS block. */ size_t __static_tls_size; size_t __static_tls_align_m1; @@ -183,10 +178,7 @@ __pthread_initialize_minimal_internal (void) #endif /* Register the fork generation counter with the libc. */ -#ifndef TLS_MULTIPLE_THREADS_IN_TCB - __libc_multiple_threads_ptr = -#endif - __libc_pthread_init (__reclaim_stacks); + __libc_pthread_init (__reclaim_stacks); } strong_alias (__pthread_initialize_minimal_internal, __pthread_initialize_minimal) diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index 6b52ca158e..dd6d6c6342 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -368,17 +368,13 @@ extern unsigned long int __fork_generation attribute_hidden; extern unsigned long int *__fork_generation_pointer attribute_hidden; /* Register the generation counter in the libpthread with the libc. */ -#ifdef TLS_MULTIPLE_THREADS_IN_TCB extern void __libc_pthread_init (void (*reclaim) (void)); -#else -extern int *__libc_pthread_init (void (*reclaim) (void)); +#ifndef TLS_MULTIPLE_THREADS_IN_TCB /* Variable set to a nonzero value either if more than one thread runs or ran, or if a single-threaded process is trying to cancel itself. See nptl/descr.h for more context on the single-threaded process case. */ extern int __pthread_multiple_threads attribute_hidden; -/* Pointer to the corresponding variable in libc. */ -extern int *__libc_multiple_threads_ptr attribute_hidden; #endif extern size_t __pthread_get_minstack (const pthread_attr_t *attr); diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c index 060484cdc8..2cab8f0a34 100644 --- a/nptl/pthread_cancel.c +++ b/nptl/pthread_cancel.c @@ -90,7 +90,7 @@ __pthread_cancel (pthread_t th) points get executed. */ THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1); #ifndef TLS_MULTIPLE_THREADS_IN_TCB - __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1; + __pthread_multiple_threads = __libc_multiple_threads = 1; #endif } /* Mark the thread as canceled. This has to be done diff --git a/sysdeps/unix/sysv/linux/single-thread.h b/sysdeps/unix/sysv/linux/single-thread.h index a28aaed04d..841f8c69d5 100644 --- a/sysdeps/unix/sysv/linux/single-thread.h +++ b/sysdeps/unix/sysv/linux/single-thread.h @@ -27,9 +27,13 @@ The ABI might define SINGLE_THREAD_BY_GLOBAL to enable the single thread check to use global variables instead of the pthread_t field. */ +#ifndef __ASSEMBLER__ +extern int __libc_multiple_threads; +libc_hidden_proto (__libc_multiple_threads) +#endif + #ifdef SINGLE_THREAD_BY_GLOBAL # if IS_IN (libc) -extern int __libc_multiple_threads; # define SINGLE_THREAD_P \ __glibc_likely (__libc_multiple_threads == 0) # elif IS_IN (libpthread)