From patchwork Tue Jun 9 13:25:45 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 136746 X-Patchwork-Delegate: fweimer@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D34834C31851 for ; Tue, 9 Jun 2026 13:26:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D34834C31851 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=GN7dG0kh X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ua1-x930.google.com (mail-ua1-x930.google.com [IPv6:2607:f8b0:4864:20::930]) by sourceware.org (Postfix) with ESMTPS id 4634B4C3186E for ; Tue, 9 Jun 2026 13:25:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4634B4C3186E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4634B4C3186E Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::930 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781011553; cv=none; b=VKP6GhBzmUHRCz6reYovdNHM5IDQipp2eByhksudOcYJdzAioLWRFIMbwaQHHNPeAeC6fL/W9WLylguJAhLk+2ZoRPzqyx+lrznlpnK52lObEdkbwPmDoHYDo9XtAytK1xjc3W9Vi2aumsiGYLERMf1Z0qc6Fbn6W/09TY99AnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781011553; c=relaxed/simple; bh=fpnYp5fM5Ctq0CUlSK6yrSHjn2lqExjZU4fGU0oYMRM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=g6+Xf6/LSpZrawyL2L0W5GDyFcOe2dWPmYrw0hdQqjIoXMd0jG3EcjKbnvXt6AunCV9MbGnbWEkdJSW7UjWggkpEJYiKi19HXW0LRi27mh6Oho5Jz3mmhYn0ntCtROwXAMj1GBaNhcnpubCqBT3lrKjVSenvgNCGSx4PGyTP6H8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=GN7dG0kh DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4634B4C3186E Received: by mail-ua1-x930.google.com with SMTP id a1e0cc1a2514c-963b248ef0fso2567892241.2 for ; Tue, 09 Jun 2026 06:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1781011553; x=1781616353; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=TBOioIJniRbFfM768QUkazmZxGRS0xXQLwi1KkYsVpQ=; b=GN7dG0khqcCH2+S8d5JcoRnzxpNaAaqFkRF2pyMDt+WFm3viIX9G2pnM/C83omwR5A ufGGC8FbD3DIuzmD+vHTn5427ll54OMBfzLoNS4ri+VvaIYmjfBjKvx2Z+VqvPTDgt7l kyhC+yfwWIdwtqh5z18bBPLLUZTmEbqNaeToV7t2bPMlKCmQK5ijV/UP8SEPObWwp0Ic AzJc64mQadByINsA3SZcuhVrxkf76iZOOjabsA3gtZn8HaQjL6s1KOaSY1l4teq+gvRS n+m1nWL9NShZT+A3fiq/p5/ldp/xfDeaLIKoddi/py3NZB5HF/1Xmd0iWTIQ9/Jnb+jc DZfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781011553; x=1781616353; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TBOioIJniRbFfM768QUkazmZxGRS0xXQLwi1KkYsVpQ=; b=b+412n5pLIZqO7UJcE/Yoz9xgSUfKcc8XZI3K5wjLt3UdGN5CjhTHoa3jxLdo9sFU3 4AMjD6CRcBpPK7h4E6qXkR3UtCEJLhQbkNX6AEaBjOist0IhAZZDc98i1mRxTB2eCvV8 O9Kcg5uUWdqOHg9l+eBzxfR1OF2xqHPUPj0bcOwvLvLCgk/mcKryeiroeQ4ONQBTwUea et+roHDlyJUmL9omVbxxvz7w175gK6MCo4EPXXf+al8ciiISfujy+IerF+KJycmQ1zY3 j2nWNhBg8i6zwFy6GX8szCwgaeb0ojGfVKHg5lT7WJTyOnhFddcIub5fpY/nV53aOkk6 Xecw== X-Gm-Message-State: AOJu0YyE0vfCPU/r1bZbjmOrZ/yNnx2VpDRv/jqCVzhLgtiUZiRd+PKv F/k9fYlihyYHM3P3weOv/W9LDOFE/DlKJ1k1jul0ZTdYCT2NXuAq6U/DlgjrcFtrafUZQ7DuBWZ ncIj7 X-Gm-Gg: Acq92OEjnKFfGL44+CnZNPwcxm0Wm7SeBh2WMwb8130zkfLuBPmMsah9m92L7U8imvU lxrf+2lEiAO99T+4pwqgsdzWyaBFnHgtWavPQ+JnmCRDroYhyx+/R7McJLOKZzkSSv3jNKCyaxh HmMdYz+xUmQE4WadBNZaDdC4enZS4QAzpAu4iUwJJb/6OKksWyZ6eBiTZHUTZ75jwI9VhsxxCZH 4RZWmLSLLje2Zdu3s5aXJJmvH9mtCjnA1YhRcaT3mLVuz8+jRjTutjsKUCeuecyo0qF2OLf4/Us BkKDTePK1yhIBvPVSuHwMrIC9Ik08dBEp1MGTMVRC2Yy8Uv+8Rr002gvZ3wp95dagkuamVUIRHU 4vBxAqcO74edcOaUeZuuzFW4aDD1z++XWZxNj6Tfrjkm9DHUSuEnxiL9jGA66O8qdp7qaPhbTKi 3pY46ZLgw+wZhgwJzDWuJ7OpSbmerhYiGxrO1zeff4bPK95w== X-Received: by 2002:a05:6102:cc8:b0:62f:3abe:907f with SMTP id ada2fe7eead31-6feed1adbffmr12335838137.4.1781011552521; Tue, 09 Jun 2026 06:25:52 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:86e2:c8a6:66b8:397c:e9d0]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-6eb55494b46sm17002942137.1.2026.06.09.06.25.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 06:25:51 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] elf: Remove dead l_need_tls_init static-TLS init path Date: Tue, 9 Jun 2026 10:25:45 -0300 Message-ID: <20260609132547.1577550-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 Since af34b1376a3 ("elf: Initialize static TLS before relocation processing", BZ 34164) dropped the 'defer-if-not-relocated' branch in _dl_try_allocate_static_tls, nothing sets l_need_tls_init any more. The second pass in update_tls_slotinfo, guarded by l_need_tls_init, is therefore dead: its _dl_update_slotinfo / _dl_init_static_tls calls never run, and the static TLS image is initialised inline during relocation (IE model) or lazily on first dynamic-TLS access instead. Remove the dead loop, the now write-only l_need_tls_init field and its clear in _dl_allocate_tls_init. No functional change. Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also run the elf tests on armv7-a, alpha, loongarch64, mips64le, powerpc, riscv, and s390x using qemu system. --- elf/dl-open.c | 50 +++++++++++--------------------------------------- elf/dl-tls.c | 9 +++------ include/link.h | 3 --- 3 files changed, 14 insertions(+), 48 deletions(-) diff --git a/elf/dl-open.c b/elf/dl-open.c index cf4749694f9..ba06e837bae 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -382,36 +382,6 @@ update_tls_slotinfo (struct link_map *new) TLS generation counter wrapped! Please report this.")); /* Can be read concurrently. */ atomic_store_release (&GL(dl_tls_generation), newgen); - - /* We need a second pass for static tls data, because - _dl_update_slotinfo must not be run while calls to - _dl_add_to_slotinfo are still pending. */ - for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i) - { - struct link_map *imap = new->l_searchlist.r_list[i]; - - if (imap->l_need_tls_init && imap->l_tls_blocksize > 0) - { - /* For static TLS we have to allocate the memory here and - now, but we can delay updating the DTV. */ - imap->l_need_tls_init = 0; -#ifdef SHARED - /* Update the slot information data for the current - generation. */ - - /* FIXME: This can terminate the process on memory - allocation failure. It is not possible to raise - exceptions from this context; to fix this bug, - _dl_update_slotinfo would have to be split into two - operations, similar to resize_scopes and update_scopes - above. This is related to bug 16134. */ - _dl_update_slotinfo (imap->l_tls_modid, newgen); -#endif - - _dl_init_static_tls (imap); - assert (imap->l_need_tls_init == 0); - } - } } /* Mark the objects as NODELETE if required. This is delayed until @@ -671,16 +641,18 @@ dl_open_worker_begin (void *a) if (mode & RTLD_GLOBAL) add_to_global_resize (new); - /* Install the new modules in the DTV slotinfo and initialise their - static TLS *before* relocation, so an IFUNC resolver firing during - the relocation loop below can reach its DSO's __thread storage via - __tls_get_addr / TLSDESC. Without this, the resolver's TLS access - for a just-loaded module would index into an unallocated DTV slot - and crash. If relocation later fails, the subsequent _dl_close_worker - cleans up these slotinfo entries via remove_slotinfo. */ + /* Register the new modules in the DTV slotinfo and bump the TLS + generation counter *before* relocation, so an IFUNC resolver firing + during the relocation loop below can reach its DSO's __thread storage + via __tls_get_addr / TLSDESC. Without this, the new module is not yet + in GL(dl_tls_dtv_slotinfo_list), so the resolver's dynamic-TLS lookup + fails to find it and faults. The static-TLS image itself is copied + lazily on first access; for the initial-exec model the static-TLS + offset is reserved inline during relocation (see + _dl_try_allocate_static_tls), not here. If relocation later fails, + the subsequent _dl_close_worker cleans up these slotinfo entries via + remove_slotinfo. */ if (any_tls) - /* FIXME: This calls _dl_update_slotinfo, which aborts the process - on memory allocation failure. See bug 16134. */ update_tls_slotinfo (new); /* Perform relocation. This can trigger lazy binding in IFUNC diff --git a/elf/dl-tls.c b/elf/dl-tls.c index 1380bd70831..f2a99e8edb5 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -697,17 +697,14 @@ _dl_allocate_tls_init (void *result, bool main_thread) For audit modules or dependencies with initial-exec TLS, we can not set the initial TLS image on default loader initialization because it would already be set by the - audit setup, which uses the dlopen code and already - clears l_need_tls_init. Calls with !main_thread from - pthread_create need to initialize TLS for the current - thread regardless of namespace. */ + audit setup, which uses the dlopen code. Calls with + !main_thread from pthread_create need to initialize TLS + for the current thread regardless of namespace. */ if (map->l_ns != LM_ID_BASE && main_thread) continue; memset (__mempcpy (dest, map->l_tls_initimage, map->l_tls_initimage_size), '\0', map->l_tls_blocksize - map->l_tls_initimage_size); - if (main_thread) - map->l_need_tls_init = 0; } total += cnt; diff --git a/include/link.h b/include/link.h index 8f851d2212d..e299ca35fd4 100644 --- a/include/link.h +++ b/include/link.h @@ -194,9 +194,6 @@ struct link_map the l_libname list. */ unsigned int l_faked:1; /* Nonzero if this is a faked descriptor without associated file. */ - unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls) - should be called on this link map - when relocation finishes. */ unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */ unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module is interested in the PLT interception.*/