From patchwork Mon Aug 29 12:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 57137 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 EA141385740D for ; Mon, 29 Aug 2022 12:27:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA141385740D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1661776049; bh=eDBObYUz74IHboEmH9RM1PCFliaordsxahChRtkRQDA=; 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=CZbN+mEHddpKxHa+br+oo/Gce9R5AD2SchX0cAUyxBlCl9fiW+n8UVIyd/6FTfvBL gUpyDjtxEduIm6/lONhEz+A9DNtmJKP7mKVLZJgu5NcVfO6t1AyFvp5jr0mP74P1F8 XVeVf3XGvAfQ9G8e/u0t3anMenbYlXcZOqthT2n8= 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 ESMTPS id 878943858D32 for ; Mon, 29 Aug 2022 12:27:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 878943858D32 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-EyVtHw6RO-2smmJnAA8ujQ-1; Mon, 29 Aug 2022 08:26:56 -0400 X-MC-Unique: EyVtHw6RO-2smmJnAA8ujQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 349AD38041C6 for ; Mon, 29 Aug 2022 12:26:56 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.190]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C544F40B40E4 for ; Mon, 29 Aug 2022 12:26:55 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v4 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called In-Reply-To: References: X-From-Line: 08163a7b1e71d42325dfa3baeec3193268729771 Mon Sep 17 00:00:00 2001 Message-Id: <08163a7b1e71d42325dfa3baeec3193268729771.1661775887.git.fweimer@redhat.com> Date: Mon, 29 Aug 2022 14:26:54 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.2 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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This allows the rest of dynamic loader to check whether the TCB has been set up (and THREAD_GETMEM and THREAD_SETMEM will work). Reviewed-by: Siddhesh Poyarekar --- elf/rtld.c | 10 +++++----- sysdeps/generic/ldsodefs.h | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index cbbaf4a331..714434b21d 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -730,7 +730,7 @@ match_version (const char *string, struct link_map *map) return 0; } -static bool tls_init_tp_called; +bool __rtld_tls_init_tp_called; static void * init_tls (size_t naudit) @@ -800,7 +800,7 @@ cannot allocate TLS data structures for initial thread\n"); if (__glibc_unlikely (lossage != NULL)) _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage); __tls_init_tp (); - tls_init_tp_called = true; + __rtld_tls_init_tp_called = true; return tcbp; } @@ -2050,7 +2050,7 @@ dl_main (const ElfW(Phdr) *phdr, an old kernel that can't perform TLS_INIT_TP, even if no TLS is ever used. Trying to do it lazily is too hairy to try when there could be multiple threads (from a non-TLS-using libpthread). */ - bool was_tls_init_tp_called = tls_init_tp_called; + bool was_tls_init_tp_called = __rtld_tls_init_tp_called; if (tcbp == NULL) tcbp = init_tls (0); @@ -2315,7 +2315,7 @@ dl_main (const ElfW(Phdr) *phdr, consider_profiling); /* Add object to slot information data if necessasy. */ - if (l->l_tls_blocksize != 0 && tls_init_tp_called) + if (l->l_tls_blocksize != 0 && __rtld_tls_init_tp_called) _dl_add_to_slotinfo (l, true); } } @@ -2341,7 +2341,7 @@ dl_main (const ElfW(Phdr) *phdr, _dl_allocate_tls_init (tcbp, false); /* And finally install it for the main thread. */ - if (! tls_init_tp_called) + if (! __rtld_tls_init_tp_called) { const char *lossage = TLS_INIT_TP (tcbp); if (__glibc_unlikely (lossage != NULL)) diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 050a3032de..fc81affed0 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1217,6 +1217,9 @@ extern void *_dl_allocate_tls_storage (void) attribute_hidden; extern void *_dl_allocate_tls_init (void *, bool); rtld_hidden_proto (_dl_allocate_tls_init) +/* True if the TCB has been set up. */ +extern bool __rtld_tls_init_tp_called attribute_hidden; + /* Deallocate memory allocated with _dl_allocate_tls. */ extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb); rtld_hidden_proto (_dl_deallocate_tls)