From patchwork Wed Jun 26 16:50:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 92901 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 0BDF43875427 for ; Wed, 26 Jun 2024 16:51:07 +0000 (GMT) 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 7E57B3875409 for ; Wed, 26 Jun 2024 16:50:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E57B3875409 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7E57B3875409 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719420631; cv=none; b=mafoBY3VUdlKczem918QM0womruQQM1qNY9nCC6+IggBOWWTdaSSwceQvWZwplV3CAlfTb0bJMFag3OHKVzlAjzPNub0+nUdgiihO0bPgXvd2Pc9SfJdraUUtfbY1eVGdpuo5PNSd2tS5rkGIvpOpvVo6mcWvTcB0R4VnfYitec= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719420631; c=relaxed/simple; bh=V3HP7IcBBLQnaa/Ia/NZHGDrCmEKfoISe+Vco7Flu8Q=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=E9AT+l7uuB9YXME9ilh/MaT5FyhrWnzZQnHFtfUaKvU3Lwlbx0V1xZJzEQulWI6fa1YyZMuSyuHzxWIjIgLgthFUmgHShlA0gbI032boDEsZXJtgDX8RKOFIT10pa6avzwcGvw2B99KcePN7EdyHCbgcYNDUKtHUMz2tCSXFk/4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719420629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MU/XV0h/KA+6WxuZIJAy2Ax+eVYDWv5sGL2zyNQAJu8=; b=gGNzBnJQVLjeTJzXCMHI6s1Les6sT1IEH1ED2v0LwB/rwPKt1kFg888B7srWN/44PZ53cy lfYS03nqqR9yDVcrfORHyAZZjj/F/5lRgG957rV2eKVsXfd7IbDKvZjWa/JmjfSPMn8Vd0 hVQkw2aSjTLtvIFT7GS3ytOMn60/gDc= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-192-CeOQVoNjNaqtPuwTDZEUcw-1; Wed, 26 Jun 2024 12:50:26 -0400 X-MC-Unique: CeOQVoNjNaqtPuwTDZEUcw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E236C19560B1 for ; Wed, 26 Jun 2024 16:50:25 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.72]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DEB7C1956087 for ; Wed, 26 Jun 2024 16:50:24 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v5 1/2] elf: Clarify and invert second argument of _dl_allocate_tls_init In-Reply-To: Message-ID: <86ff3e8442162298b82734abe00ed28a84f006f2.1719420465.git.fweimer@redhat.com> References: X-From-Line: 86ff3e8442162298b82734abe00ed28a84f006f2 Mon Sep 17 00:00:00 2001 Date: Wed, 26 Jun 2024 18:50:21 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.6 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, 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 --- elf/dl-tls.c | 10 +++------- elf/rtld.c | 2 +- nptl/allocatestack.c | 2 +- sysdeps/generic/ldsodefs.h | 13 ++++++++++++- 4 files changed, 17 insertions(+), 10 deletions(-) Reviewed-by: Carlos O'Donell diff --git a/elf/dl-tls.c b/elf/dl-tls.c index 670dbc42fc..67ce4771e3 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -514,12 +514,8 @@ _dl_resize_dtv (dtv_t *dtv, size_t max_modid) } -/* Allocate initial TLS. RESULT should be a non-NULL pointer to storage - for the TLS space. The DTV may be resized, and so this function may - call malloc to allocate that space. The loader's GL(dl_load_tls_lock) - is taken when manipulating global TLS-related data in the loader. */ void * -_dl_allocate_tls_init (void *result, bool init_tls) +_dl_allocate_tls_init (void *result, bool main_thread) { if (result == NULL) /* The memory allocation failed. */ @@ -598,7 +594,7 @@ _dl_allocate_tls_init (void *result, bool init_tls) because it would already be set by the audit setup. However, subsequent thread creation would need to follow the default behaviour. */ - if (map->l_ns != LM_ID_BASE && !init_tls) + if (map->l_ns != LM_ID_BASE && main_thread) continue; memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size), '\0', @@ -626,7 +622,7 @@ _dl_allocate_tls (void *mem) { return _dl_allocate_tls_init (mem == NULL ? _dl_allocate_tls_storage () - : allocate_dtv (mem), true); + : allocate_dtv (mem), false); } rtld_hidden_def (_dl_allocate_tls) diff --git a/elf/rtld.c b/elf/rtld.c index e9525ea987..da0d115c69 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -2336,7 +2336,7 @@ dl_main (const ElfW(Phdr) *phdr, into the main thread's TLS area, which we allocated above. Note: thread-local variables must only be accessed after completing the next step. */ - _dl_allocate_tls_init (tcbp, false); + _dl_allocate_tls_init (tcbp, true); /* And finally install it for the main thread. */ if (! __rtld_tls_init_tp_called) diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index f35a8369bd..2cb562f8ea 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -139,7 +139,7 @@ get_cached_stack (size_t *sizep, void **memp) memset (dtv, '\0', (dtv[-1].counter + 1) * sizeof (dtv_t)); /* Re-initialize the TLS. */ - _dl_allocate_tls_init (TLS_TPADJ (result), true); + _dl_allocate_tls_init (TLS_TPADJ (result), false); return result; } diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 50f58a60e3..2bccac3f7c 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1203,7 +1203,18 @@ extern void _dl_allocate_static_tls (struct link_map *map) attribute_hidden; /* These are internal entry points to the two halves of _dl_allocate_tls, only used within rtld.c itself at startup time. */ extern void *_dl_allocate_tls_storage (void) attribute_hidden; -extern void *_dl_allocate_tls_init (void *, bool); + + +/* Allocate initial TLS. RESULT should be a non-NULL pointer to storage + for the TLS space. The DTV may be resized, and so this function may + call malloc to allocate that space. The loader's GL(dl_load_tls_lock) + is taken when manipulating global TLS-related data in the loader. + + If MAIN_THREAD, this is the first call during process + initialization. In this case, TLS initialization for secondary + (audit) namespaces is skipped because that has already been handled + by dlopen. */ +extern void *_dl_allocate_tls_init (void *result, bool main_thread); rtld_hidden_proto (_dl_allocate_tls_init) /* True if the TCB has been set up. */