From nobody Mon Dec 15 17:00:28 2025 X-Original-To: dev-commits-src-all@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 4dVRC13Kgsz6L1bj for ; Mon, 15 Dec 2025 17:00:29 +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 4dVRC05Wkbz3ptx for ; Mon, 15 Dec 2025 17:00:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765818028; 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=HgrYFK2Xs2w4LUEr7yft8tPGCqvuSgCwZ8gB0/bkEAA=; b=erf267T8P16mfx4/t+hHBFF64P2NLWBO5OjGuKDwEqVxADn80ocS86XYNIWlmUVfqk+qSW ob1e9QNcKnVzRK49xH1lZIguz8W9b219TUaS4Fkhg5vZ1vHD/EsEG4O2FStU17sJWa6ehO I45TWTOVA/INuAzhqu+OxtFUu33A/1OzxMtpMfOse60jy0l1wLwvFYZwOHjGzy/abwcsPq MXRR0pLHte9lA7DhHWGU2JP/pc3/1NJWMn5Ff8/k2a20DlLKngbYxoptJfkaZPvBna3rWP ba/Jv3cmmoFOWId31UyU1DCH4ZNsXJjspsH3zFcJFz56EmzPe5bhQXxxdScsTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765818028; 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=HgrYFK2Xs2w4LUEr7yft8tPGCqvuSgCwZ8gB0/bkEAA=; b=LvHWOv2l4aF0LBkpeXHm0EhWKTufEpM+sfNXaHOiaLaeL77l+VHpxukDeSCOwQ236YwF5y 2y/tXTdx/2OIFdELzug7EIMULp0cWa7QyNcH93KF8Z0uUMWnm6pzl/d5bKdp+jp2Bp7HlE tjXxafkPwM457nRSOfETEbDZEZzf6iDARe1XJvDa6jxoDL6yBIastWhIf6jSr3bDr5uVqV dgUSrWWhnOYd3WTeQ4Kjzt/8/ctrbZie9KpMzILA/NA/Ujk0fPCh5vByWy03NfAsCw/Urv a/JjMw4wS/vpQfDDPANkpYetEWZe7juXn4XGe2UYoMw8QQXLVrLXQdRLhyn4Ug== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765818028; a=rsa-sha256; cv=none; b=RSlO0ZmDfMt3kgHGTYOdxdEDTMKKRaAzaAsB/Thp/sdGT6zigyVmfvRQxPClH1mXBDpmpd ZU9g1wdTlIUI4IlyjzCimfzKMv+gy9SrKUotvuNP4bMkchQEu1decQCBsTQrpTma10w2Ww YcSea4XiWlWx1BtQ7gsdNCyoYI9rRUwDa1kYhhyG6WwI+cVvoy/W/V4FnNXICEbtveXqWG Z11ET3TDd63bM76J46rSi28kPB7JrCYJ8CnUvrFo9bN9NzRbxA9b4M74fws61pelPa6xzH w4lxKC8DiHZAKbUybHSwt5+x7oMqzH429BqwKrjuveJtSPsGN8zaXBUcGdeyfg== 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 4dVRC0574szCkp for ; Mon, 15 Dec 2025 17:00:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id de25 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 15 Dec 2025 17:00:28 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: d07b82ecbe64 - stable/14 - libc/riscv: Fix initial exec TLS mode for dynamically loaded shared objects List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: d07b82ecbe64e29668b457019081846518c0e4b5 Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 17:00:28 +0000 Message-Id: <69403eac.de25.29fbfe77@gitrepo.freebsd.org> The branch stable/14 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=d07b82ecbe64e29668b457019081846518c0e4b5 commit d07b82ecbe64e29668b457019081846518c0e4b5 Author: Jessica Clarke AuthorDate: 2025-05-28 20:23:10 +0000 Commit: Jessica Clarke CommitDate: 2025-12-15 16:58:45 +0000 libc/riscv: Fix initial exec TLS mode for dynamically loaded shared objects The offset here is relative to the TCB, not whatever the thread pointer points to, so as with powerpc and powerpc64 we need to account for that. However, rather than using hard-coded offsets as they did, due to predating machine/tls.h, we can just re-use _tcb_get(). Note that if libthr is used, and its initialiser has been called, it will take a different path that uses _get_static_tls_base, which works just fine on riscv (adding the offset to thr->tcb). This only affects programs that aren't linked against libthr (or that are but manage to dlopen before the initialiser is called, if that's even possible). In future this code should be made MI by just reusing _tcb_get() and checking the TLS variant (since the offset here is positive even for variant II, where it should be subtracted), but this is a targeted fix that makes it clear what's changing. Reviewed by: kib Fixes: 5d00c5a6571c ("Fix initial exec TLS mode for dynamically loaded shared objects.") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50564 (cherry picked from commit 0e3dbc64d9f6c95cbb16dba60a32136ae116dada) --- lib/libc/riscv/static_tls.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libc/riscv/static_tls.h b/lib/libc/riscv/static_tls.h index ce9fa23338a6..40e9abd685e3 100644 --- a/lib/libc/riscv/static_tls.h +++ b/lib/libc/riscv/static_tls.h @@ -31,12 +31,14 @@ #ifndef _LIBC_RISCV_STATIC_TLS_H #define _LIBC_RISCV_STATIC_TLS_H +#include + static __inline uintptr_t _libc_get_static_tls_base(size_t offset) { uintptr_t tlsbase; - __asm __volatile("mv %0, tp" : "=r"(tlsbase)); + tlsbase = (uintptr_t)_tcb_get(); tlsbase += offset; return (tlsbase); }