reebsd.org; s=dkim; t=1765822737; 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=/q3vMK0hHe2tUiHHUC/IqLZ4JmpOFFVdLDRPBtSSQMM=; b=u/84uRVKk77uDhwDkpqNU5Agk+2v1R7+SWQ6JT+Mby/JyXkgevd3E3RTw7HTd+e8T5F0pE d55g91glrsMpeWLJqNw673M5iSzZxhvE9ny/x7Wql45WIPrnzxsxA/1qnqe5W3TR3m+6tK x4bew2sudazWSKwOM9+utlM3kRnglO3J42G3Pjcd1KQgytuMmWea0bl4a8QnK7GpWWhwKu 9f9JDHB3Job7pnXdrvAO35oLf4oOEXMf+/ham0rX9BbVY80fUE6SVBulRzk1Tg0WkzlMm7 BqXMom70D/MvHx92ZysICLErlw4Ti1o7Nzil30uh8JXyF/xQ2wk9WBWEhsMv9g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765822737; a=rsa-sha256; cv=none; b=vNTt6BmUjsuVJyr4VzLtJZlM3vMxTsAn/2PP+v3IM8z5FgBzLlqzbSKj48/Bo8tQKO5hFB D94W3+fKOQL1kStrnhTcS2S4ayLjhIHKRTfubgv9bc66UE3cKt/APgJsIsEXu1FY4q6RMc 5NFPKD975H/PhNvQAU5OlBCN4m4ZfDVVw2HPZVUWlzRRX3skaruDtMYuUxHvHqZnSlSm4N +Nn8KuifGWjq+oxPJwKGXOboQ0SPnuveHu/zDThU1e+3y0AIGXB7js3GkgQxtNri+Hfq14 Iu9QSNBu6CIYL1mx3+kwjXM3PPWftUO7P2/we5jzvDG8VM8a6cshyLEku7DZeQ== 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 4dVSxY21mWzWdw for ; Mon, 15 Dec 2025 18:18:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 24d7c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 15 Dec 2025 18:18:57 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: 749af7d9d89f - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 749af7d9d89f45057357c8f10cf836007e13c3ba Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 18:18:57 +0000 Message-Id: <69405111.24d7c.73495192@gitrepo.freebsd.org> The branch stable/13 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=749af7d9d89f45057357c8f10cf836007e13c3ba commit 749af7d9d89f45057357c8f10cf836007e13c3ba Author: Jessica Clarke AuthorDate: 2025-05-28 20:24:52 +0000 Commit: Jessica Clarke CommitDate: 2025-12-15 17:56:36 +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 9725dcdd805f..7ebef4ef2444 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -5350,6 +5350,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) @@ -5584,7 +5587,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