From nobody Mon Dec 15 17:00:29 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dVRC22nblz6L1sg for ; Mon, 15 Dec 2025 17:00:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dVRC16YS6z3pxX for ; Mon, 15 Dec 2025 17:00:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765818030; 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; bh=3+TTTOwSONQc19pwOWuah1r+MxSxCe9vz0dK8cAeePo=; b=iiszouTAuP5NsU2rl9Fc2kOIzEJGmHjRHVghl2U7GBk9xE1ybE9vFUgWh8vjmIhss1xU4+ X1B1gdBCs72JdKCiMkXZcqsdx98zoDN7eAC8rv167PBSfzw7VQH9jbtg4HlFwqLkbx78ng BRbYh4OTcHR9t+A2orot6wwLIsrOUekwqz3Ww7DTpUxSdK+xJIxkzlj5H+sUhdoOLys5Jw Q9itSv7b7KQuHuOpTyAla0BO611bjKLLZ7liJ6ztSyjl5B5VaapTmrAE1CsWpahC43kPoJ 4fTbV6pBxV8sw022cmHNUHbRUEnU0uqlUEph7aFr1TsdeauW1kv86KK1IYrjcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765818029; 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; bh=3+TTTOwSONQc19pwOWuah1r+MxSxCe9vz0dK8cAeePo=; b=WnfRjSJfsMsDy48UTvAEI+ZEUgHEZUzGzni0Hn8HkDQLQR09qCCE1ckOzMYyUxW/O9xRhc DU0j42hul8xKFZTYgj3yNmoYQWqH4kouF2v9C+yWB400mVGbEFgPoNeu6JHeRX4uA6cKDz vCoS3LR91suKdsz6oateXAummJGdV3nbQjQ0WQ7KfYTSQmm46am0F8xJyFT9Y3KUy48Uh0 bNXorOWHLh2KeBMRISnJPmmbFkkq0VdQ/Ja1BLa/nyLG9gRemd7rVPyVuGwuAx+2FS9Rbn vzhaTxFWIagc4r7jMoztMRPXPfel3/Brr1wRhUTWPA1SqMZpUNU2n06ANv68vQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765818029; a=rsa-sha256; cv=none; b=hg40bug2nI3LPK8+SHSSHswh2w/WwthgSwpB6nhTlydSP0wK6nHCQf0oCp2ULT/O+AiX/T oS4w7dgi2FyKWx7AC2w0hOkaLD/sfKGnHHVC6cDPI1AxwX0CgU/VojKmITLuJHBkMKD16Y +993NQGEKOJIDbAYFMQZJZJK5WCD8gTEaeeJxAFVKl70tntPmf/7DAxGhePTng6fnVY8Bn VyrjOyPHs46XaEpe7qGSYelDObgLGXGDC4FcAjhdpxSbXnuRr+biBfyG8cMnhUmswjyMZi g4W3sRw8C7dNmjTNRaRwGaGma+KLQ5ycXt38qxXsR4cvZ4WM9ir7CdmEO55F6w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dVRC15yJHzCWG for ; Mon, 15 Dec 2025 17:00:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id e540 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 15 Dec 2025 17:00:29 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: 02cb2f8094ba - stable/14 - Revert "rtld: fix allocate_module_tls() variant I fallback to static allocation" List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 02cb2f8094baab0b4299e5fcd1694d9193be14b3 Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 17:00:29 +0000 Message-Id: <69403ead.e540.47a2d651@gitrepo.freebsd.org> The branch stable/14 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=02cb2f8094baab0b4299e5fcd1694d9193be14b3 commit 02cb2f8094baab0b4299e5fcd1694d9193be14b3 Author: Jessica Clarke AuthorDate: 2025-05-28 20:24:52 +0000 Commit: Jessica Clarke CommitDate: 2025-12-15 16:58:45 +0000 Revert "rtld: fix allocate_module_tls() variant I fallback to static allocation" This was applying a NetBSD fix to FreeBSD. However, the original code was correct for FreeBSD. NetBSD's obj->tlsoffset is relative to the end of the TCB, not the TCB itself, whilst ours is relative to the TCB[1] itself. For example, our allocate_tls uses (char *)tcb + obj->tlsoffset for the memcpy and memset calls. Without this reverted, for dynamically loaded shared objects, Initial Exec accesses to TLS variables on variant I architectures (non-x86) use the correct address, whilst General Dynamic and dlsym(3) use the incorrect address (TLS_TCB_SIZE past the start). Note that, on arm64, LLVM only supports TLSDESC (including LLD) and TLSDESC will use the static resolver if the variable ends up allocated to the static TLS block, even in the presence of dlopen(3), so only dlsym(3) shows the discrepancy there. Whilst here, add a comment to explain this difference to try and avoid the same mistake being made in future. [1] In the case of variant II, it's the amount to subtract, so still positive This reverts commit e9a38ed2fa61fd264a80f24ceb35f39b0ac6463d. Reviewed by: kib (prior version) Fixes: e9a38ed2fa61 ("rtld: fix allocate_module_tls() variant I fallback to static allocation") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50565 (cherry picked from commit ccfb1c50e45dbb7fcadf7e1932f63cf1702ef13a) --- libexec/rtld-elf/rtld.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index a7fdc153eca8..5117448a0d28 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -5378,6 +5378,9 @@ get_tls_block_ptr(void *tcb, size_t tcbsize) * it is based on tls_last_offset, and TLS offsets here are really TCB * offsets, whereas libc's tls_static_space is just the executable's static * TLS segment. + * + * NB: This differs from NetBSD's ld.elf_so, where TLS offsets are relative to + * the end of the TCB. */ void * allocate_tls(Obj_Entry *objs, void *oldtcb, size_t tcbsize, size_t tcbalign) @@ -5612,7 +5615,7 @@ allocate_module_tls(int index) if (obj->tls_static) { #ifdef TLS_VARIANT_I - p = (char *)_tcb_get() + obj->tlsoffset + TLS_TCB_SIZE; + p = (char *)_tcb_get() + obj->tlsoffset; #else p = (char *)_tcb_get() - obj->tlsoffset; #endif