From nobody Mon Dec 15 18:18:56 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 4dVSxX50KTz6L7fv for ; Mon, 15 Dec 2025 18:18:56 +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 4dVSxX1QfKz4LkV for ; Mon, 15 Dec 2025 18:18:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765822736; 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=hkl1VA2OEVBIQirpSAYmovVeMOD4jDx1jHfhp22Cc/Y=; b=HQU/4GFRkFx84d2gOOcyL2RjV/G9V1tzcQ9rVnXv1o2mVAPfpR1NuYEP0fGCLJ93rmE+oj S+vczcqexDAzPbzcq9P58rkRNC2i53XPMEGzBvvI0ykP23dIIPDePP2nw2P6y30nmg8DEG xtUfrDFaoAVTCvaPKtXcEN0dud6qYgINypwM+LY7tGootsoE5xn5o87z92MrQUBY78twi6 TXssFZyk4oxMBYzlVMDH0sGnYIxr5i6yW5dE+UhDR2pHYKH6lBWBmNPidRwaQw6/sjT0Ii COuvvjVLYk1psfFsykXpd73yuaeHkSvdQ0IMD/lgfKVQKkHZRnCrWknDBPxaHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765822736; 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=hkl1VA2OEVBIQirpSAYmovVeMOD4jDx1jHfhp22Cc/Y=; b=DOF8CO5NZXqXSK1ZvZLpYsfpzMl0EEkl6eg+2mbsPUPF/fcxRJo6ZWO0cqqK/3ddorOKvI IYT2thCwhgYg6cte98H0cjfYYxpel2px+CZ2EOKtNbZyA1u4uVW0SL2659ohFcDJCmTeta C1r8aXxboNEQP1LjQFoN85pSPV+Hz8y7lQyoFffJ4Aeivt1RDuXH+Cny+5hE8+XGSmUrwJ jKTCXBpmV7h1pOxanbfTVry7EddmqDYWbNSh6FhXzBgh9CEroYtBPzadAGI0b1lc+eswOU p/vuLmZbZhIoP9N/1ekzKAHuiLfS9YJNksMQDtAazqtEMzWhzUn0pRPuP3yARA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765822736; a=rsa-sha256; cv=none; b=gMARRde3OZismXsyarNHP2xfjSKBIcfGBx+goDvmc0xTmrPT0wev6cBUqmhhIdJDDg2wae 3Pbpop7gVoOdBgT6s84Yxwxk51FXkycrzHPFu1enieAXbM4cYnVjKpyFblRPBEWX159jyI rnfcNTr8lpcZhtcqDVCRNTjH6QI81wdQ5tZNjyV1JHEMybpjUlWWU0fUMZT3x6haD+z8z/ XEWP0U6mc/ikqZZzr8l79SWNz2AAsSNB3kBjLg6VZxYZjsH6Mv7Jei/e2xNDFSnzX8xpFL LK5+xxvpoX9dprgX2aCplOWy04GGMiu9+whDPygQEgkSub+VI8aLdV2RP/d2/g== 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 4dVSxX0vMfzWnF for ; Mon, 15 Dec 2025 18:18:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 237e9 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 15 Dec 2025 18:18:56 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jessica Clarke Subject: git: c668cd775b29 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: c668cd775b2964ca17e14be032c40f1a4ed77c45 Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 18:18:56 +0000 Message-Id: <69405110.237e9.1b956d0d@gitrepo.freebsd.org> The branch stable/13 has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=c668cd775b2964ca17e14be032c40f1a4ed77c45 commit c668cd775b2964ca17e14be032c40f1a4ed77c45 Author: Jessica Clarke AuthorDate: 2025-05-28 20:23:10 +0000 Commit: Jessica Clarke CommitDate: 2025-12-15 17:56:36 +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); }