From patchwork Sat Feb 15 20:18:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 38110 Received: (qmail 674 invoked by alias); 15 Feb 2020 20:18:10 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 574 invoked by uid 89); 15 Feb 2020 20:18:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581797886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=38GAAQlb0hm5vEQCuxlggwdmKcj7wv1MTawgbATzetU=; b=WoJrRGn3Y0DltW8lJgkJKg7JlQT2+31//mXp0keaptVA3bO/bR01Tpv3CtDjtzQnn/7O46 Fihy9JJkicA7fNJQ96ViW1mbulVjyz+CF1uMhOE02cGM9a8AWJoWh/jtJ7MUlTuwEubWtd e/q8U1ZP9qsd5yI71Kd/BCnnPdmo+/c= From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 1/3] ld.so: Export tls_init_tp_called as __rtld_tls_init_tp_called In-Reply-To: References: X-From-Line: d3397c7822cf320281bc5ac297141d9fadb35fd1 Mon Sep 17 00:00:00 2001 Message-Id: Date: Sat, 15 Feb 2020 21:18:01 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 51dfaf966a..15850d3fd9 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -695,7 +695,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) @@ -761,7 +761,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; } @@ -1875,7 +1875,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 (); @@ -2226,7 +2226,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); } } @@ -2271,7 +2271,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); @@ -2297,7 +2297,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 497938ffa2..4b4e26b778 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1122,6 +1122,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)