From nobody Wed May 28 20:28:09 2025 X-Original-To: dev-commits-src-main@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 4b71KQ1Rgdz5xCyt; Wed, 28 May 2025 20:28:10 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b71KP5fj9z44g2; Wed, 28 May 2025 20:28:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748464089; 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=Bd5kVBrbLj/o7pIH9BLz/yL68ohI1aSnK6ZQCmoSiXw=; b=hzXskFbeAjiHj72K62woishCanjEy3aNPkrNmct995Wd7zq6F4OuKMsHrihXrmsBwRYX1P ao0+sJfxxIclKFMGnI4AX4WJXiDDc0L/54VbCo8qdUh4Bb/JRjPhsZYqA3WDmoVK70+Y5V 6GuFCmKJNUPgYYNdh36NP64wTQqkTns/O50SJAKwR+nAuLH0Fy3bjqPHWzad5RymuSKfsM jYbfykxH0ZcRML0YxhtRXfGy+eD3pk8fZgeoomBAu94Pj01BOp09cV1o+tvx6SqDXyioXX MetQ6dPS6c7jiqGbiG448bY9Tg9nn+wtHLoWnGKv+Xotar+jgJu6IiVcFe4/Cw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1748464089; a=rsa-sha256; cv=none; b=HXlgTOU7s4EW1DNPPSVSFfP5yA64jNeVok2fQL4gMMzT2gckR+bXRO2d/6HtLHW383pNl3 jGCRnFBBQBg4XhdJaicFWW33QnJGgRCLrWLiCyKQU1/NHpZ9DlVBPt3LbV9pGYvOp/d/r2 BbOG8N7s08wJtS2KkS12aA8nD5gg7Q5XMTTO3s2CeTf8oMZwV/zk084598rn7eQHfe5B2f 2AkRjyRtyz9Wpg8BHMGe8K7nkwmkNeI2/wBptgwUtFdAcpyZrcdMCrkcFHC1Ype13nxVSB hWBbLAO38oWS8AWBMdS8UdsAulY/W+NnENjiJ8QZO5N3Pm0yjXqSubO+1QCrBw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748464089; 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=Bd5kVBrbLj/o7pIH9BLz/yL68ohI1aSnK6ZQCmoSiXw=; b=SyPVh6zhSGW3sFv+TBcGm+1JnlaxK8G7g2S6qGTBou9WIyVpzfEssmohHQOxqmGd4H7//5 f50H/hhnx7Cjm017Fve1QtvHNhhhWR1QFmICjNfCD2wtwdIpVI7qyvwBchzYeR2yqzwZqZ JHJLxlDGFyBC7GX4CUZesxuqxtwdcsSFRyf4VRmZd5npEDkhJmefaAdY5vGfU/WyTUWa3N UIrw6WUf5mEDzqJM7Qv20cvqzoeIEiZQ0NyTvTKjXFFt2rl616ohTdqNde4hYjVhUekHOl M60aUeEJP5Np9h6nJrJBazsxMAEx1qKHiQN7i+1eYSJEx0xwKyAmW+EUBehpBA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4b71KP4kz7zrjF; Wed, 28 May 2025 20:28:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54SKS9Fv087241; Wed, 28 May 2025 20:28:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54SKS9sY087238; Wed, 28 May 2025 20:28:09 GMT (envelope-from git) Date: Wed, 28 May 2025 20:28:09 GMT Message-Id: <202505282028.54SKS9sY087238@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: ccfb1c50e45d - main - Revert "rtld: fix allocate_module_tls() variant I fallback to static allocation" List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: ccfb1c50e45dbb7fcadf7e1932f63cf1702ef13a Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=ccfb1c50e45dbb7fcadf7e1932f63cf1702ef13a commit ccfb1c50e45dbb7fcadf7e1932f63cf1702ef13a Author: Jessica Clarke AuthorDate: 2025-05-28 20:24:52 +0000 Commit: Jessica Clarke CommitDate: 2025-05-28 20:24:52 +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 --- 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 8ef6301fab36..3ba6f4bb5bbe 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -5434,6 +5434,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) @@ -5683,7 +5686,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