From patchwork Mon May 11 16:42:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 38951 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 12280389367D; Mon, 11 May 2020 16:42:41 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from albireo.enyo.de (albireo.enyo.de [37.24.231.21]) by sourceware.org (Postfix) with ESMTPS id EF491389367A for ; Mon, 11 May 2020 16:42:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EF491389367A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=deneb.enyo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fw@deneb.enyo.de Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1jYBVk-0008IK-Ua for libc-alpha@sourceware.org; Mon, 11 May 2020 16:42:36 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1jYBVk-0000DD-T5 for libc-alpha@sourceware.org; Mon, 11 May 2020 18:42:36 +0200 From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 1/3] ld.so: Turn tls_init_tp_called into global __rtld_tls_init_tp_called In-Reply-To: References: Message-Id: <91b48076cae9824c1b3711d809da61b890a51e8b.1589215037.git.fweimer@redhat.com> Date: Mon, 11 May 2020 18:42:36 +0200 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: , Errors-To: libc-alpha-bounces@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). --- elf/rtld.c | 12 ++++++------ sysdeps/generic/ldsodefs.h | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index 5ccc3c2dbb..7ca286cbcc 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -733,7 +733,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 (void) @@ -799,7 +799,7 @@ cannot allocate TLS data structures for initial thread\n"); const char *lossage = TLS_INIT_TP (tcbp); if (__glibc_unlikely (lossage != NULL)) _dl_fatal_printf ("cannot set up thread-local storage: %s\n", lossage); - tls_init_tp_called = true; + __rtld_tls_init_tp_called = true; return tcbp; } @@ -1916,7 +1916,7 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]); 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 (); @@ -2267,7 +2267,7 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]); _dl_protect_relro (l); /* 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); } } @@ -2312,7 +2312,7 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]); 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); } rtld_timer_stop (&relocate_time, start); @@ -2338,7 +2338,7 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]); _dl_allocate_tls_init (tcbp); /* 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 5ff4a2831b..ef0e339c6b 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1139,6 +1139,9 @@ extern void *_dl_allocate_tls_storage (void) attribute_hidden; extern void *_dl_allocate_tls_init (void *); 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)