From nobody Wed May 28 20:28:08 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 4b71KN67Mlz5xCmj; Wed, 28 May 2025 20:28:08 +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 4b71KN4LJtz44lV; Wed, 28 May 2025 20:28:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748464088; 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=fVEx0xJ9uAyGleTBYfxcVjoQSit9hGosAo46yP91Ilc=; b=fzHMbiFTu1cFbasd8Sg8Ot1fmofYpL5XuAfMKYc0H72/9mtGCvZVX+7G2bkHnaFEkcw+1r Z6F0gvsspPwfJybZuBJk14Y4gygbRfjuJpUepDH8Tn/P7sx2+z1F1H/HHLE066gONXg1vI ZU6jREgs8Gn4I5snLdFNgHDbaMHc3lFPbxS2JrA+Nj2l4pB5yzF+dIrgPYU/K70RjXUWyk n88IuUFTJmSXKR1A7pi7sa+iIbDjTJr6vVkYYF4kJtpwgdPx0qLlqIl1HohHJlAFC6WiRt MEC8bBhHNVzv0coQTyGQMi3wb6taZVg3Vt3th8xoFGwlUbw/Mo+7vGxa4neWew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1748464088; a=rsa-sha256; cv=none; b=DDzHSHQtDCRzAB94u9WpDYYp375vjpZX4okBKLXwaobrqiG8DgcSngHRnW9AdIPK/bSqOZ AfO/0eJQphGcci63mSrEI90cy3jWetmmwbZ9ssmM1pzthzfFwL9out+wYeB8ySTzvWCyPK BhgmC5QSMQPz+EmOxNQCR8Y4WeHWHaX4GhkB3ji5++z0t7ZQPi+5dFnSctDoGu8xEG97mh FlfKhalnBLk5e0+iuQPhtkSWjQimas4tdlJGFF8y3lDoqJn50p0lObgWkH3ZOR3EMo8NQw Xb4HvppkBSkWUL+di+HLV1LoMWuwkkNCSyth9xMVdHJDT/y0ytvevWmX3ECfAg== 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=1748464088; 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=fVEx0xJ9uAyGleTBYfxcVjoQSit9hGosAo46yP91Ilc=; b=E4xZdwr6WKdTj9XsEKlbQPEbvAmNafJO/Z/48JsgGbuuN/mzYcg8sU3WZEekIrjt+uebAQ CNlo3/4PJxw9vDHuvzycEjJ8n/myBBMHEhXHyrd2iiiKe6bQ4mHol1u4Jv6bgwu6/ZH9Xl mOGZrTM7xvw67UIqmN0E5+5Dzmhk12mvLsl1RpegdXFxZg7mzzumhV4p3KUjnR0Vtjg7b6 J7FYQqYLOtA5HUBwUhjc4wY9/Nb/dRBC0HnJcKZBaFXnmisFufkChmJUyHVCeoGsYZBqnT 4lCuCHF1OKyD/9QTg2++EwaIZIRKxkcyw9QcBngmOzijQ0j+9cONtverTVdR+A== 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 4b71KN3p2jzsw5; Wed, 28 May 2025 20:28:08 +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 54SKS8gg087209; Wed, 28 May 2025 20:28:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54SKS88t087206; Wed, 28 May 2025 20:28:08 GMT (envelope-from git) Date: Wed, 28 May 2025 20:28:08 GMT Message-Id: <202505282028.54SKS88t087206@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: 0e3dbc64d9f6 - main - libc/riscv: Fix initial exec TLS mode for dynamically loaded shared objects 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: 0e3dbc64d9f6c95cbb16dba60a32136ae116dada Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=0e3dbc64d9f6c95cbb16dba60a32136ae116dada commit 0e3dbc64d9f6c95cbb16dba60a32136ae116dada Author: Jessica Clarke AuthorDate: 2025-05-28 20:23:10 +0000 Commit: Jessica Clarke CommitDate: 2025-05-28 20:23:10 +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 --- 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); }