From nobody Wed May 07 19:22:09 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 4Zt4ry3ZsSz5v9Jx; Wed, 07 May 2025 19:22: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 4Zt4ry04kVz49k7; Wed, 07 May 2025 19:22:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746645730; 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=J1QsXaWDS9JqkqnhkEjArM1abrPEWHxY3e4QCuI++2M=; b=MJfPamNsIBgNd0eGAvql5KuJujQn1nEoGEpSjEIQf8c1P2EEGnFGwpw6GIVQIBHtvBlKVd 8MPknSrO6dFfiqo6hFdxr1spP6N2qpeMKQa0Tt7aWk0n14pE4jlAIIPR/EsI0FuSnr7ReQ 5Y9PZLlmzygEvoZxh8wEuYdGVxbHqZdgr4w1uwelaxWIyayPoTgoNNkO9gKAjZ0fw2+kiK Zw4aq1p06OnE6ZscpODgIsvng9kWUlA3fID7wvTZ70Wnccs+0qBnzAR/v41iCfrdUWrexI ti9VuT3YrpNKMhOyzSDtqSsuto8hnbjXPH83YU4+YAjZ23xErNgQxCCT5jhEIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746645730; 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=J1QsXaWDS9JqkqnhkEjArM1abrPEWHxY3e4QCuI++2M=; b=CxMhqZKdzys+dGh0HYrIsTqLtdzieq5rflLqB/LMjlhsdrwC762CsJ2yUvJkFJwdDIY4XE JEHXnl42JuAUhHd9Ck+uFqe4oil0zK7DPCozyFtEGlwth3XdvOzSx08tQimsroYUMi+PZa 4i1Uat2gy6z2a/je4/X55OA2D6b7jIXvD2P6mXzrNPB2ORVvlGGR1ktL/8IhCGij4vtc7r z7gv0w3Woq5hXTDfITwGQHL5jxdd7k3kWOvs3eSEE5KdOwP2rsE0izUxvgwVVq7paEIugB ozbpTghuvD6uEbiy/iV0ypChdkVWAxHe0gl3WlwUTPhBeOJEZSytloBv3K4fCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746645730; a=rsa-sha256; cv=none; b=WUduYZuyGcktNimQDabwkegRNtPSd1hSPJMztj4bIQtwQI9NTCFBfhQou/QscksJQkirhO rrGdZXvGcePuxIfbmP4jnAl9hpTYC959WGQA2AseTXclDhOCyYtCH0bYUdvZYLCWhSm+8R cj19k+f3/XzSt/nkOgTpAIYrp2oIYd2iYRcnx6RMXd/FhAGYrA6zOAC4w+2Sc1ZuY329ly Se34Daem73Hs/1R9kFTaEvHvhXJkPvTGum060mOIe3sNnKbZ904rrv5JP92C0Mm/4aIXa+ mCZZsINu0NvBABCXIZq2AhVPvhGYMPRdMA8Q6PR9/qFO0ymKzge45IbXAoa1WA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4Zt4rx5RN5zjyc; Wed, 07 May 2025 19:22: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 547JM9Om043058; Wed, 7 May 2025 19:22:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 547JM9aO043055; Wed, 7 May 2025 19:22:09 GMT (envelope-from git) Date: Wed, 7 May 2025 19:22:09 GMT Message-Id: <202505071922.547JM9aO043055@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: 14c534eaef41 - main - rtld-elf: Use variables more consistent with Variant I for Variant II TLS 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/main X-Git-Reftype: branch X-Git-Commit: 14c534eaef41247053cd71e0021a0fa05e17aae7 Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=14c534eaef41247053cd71e0021a0fa05e17aae7 commit 14c534eaef41247053cd71e0021a0fa05e17aae7 Author: Jessica Clarke AuthorDate: 2025-05-07 19:20:05 +0000 Commit: Jessica Clarke CommitDate: 2025-05-07 19:20:05 +0000 rtld-elf: Use variables more consistent with Variant I for Variant II TLS Firstly, the second argument to allocate_tls is the old TCB (versus oldtls, which has less of a clear meaning), so rename it to oldtcb like Variant I. Secondly, segbase and oldsegbase are oriented towards what ends up in the segment registers, but that's not the main concern here, and those don't convey what they actually point to. Instead, rename segbase to tcb and change it to a uintptr_t **, and remove oldsegbase as it's always equal to oldtcb, again both matching Variant I. Thirdly, rename tls to tls_block, again both matching Variant I. Finally, similarly rename tls to tcb in free_tls, and oldtls to oldtcb in the common _rtld_allocate_tls. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50232 --- libexec/rtld-elf/rtld.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 4376b67aa4a9..8234efdecf53 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -5544,13 +5544,13 @@ free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused) * Allocate Static TLS using the Variant II method. */ void * -allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign) +allocate_tls(Obj_Entry *objs, void *oldtcb, size_t tcbsize, size_t tcbalign) { Obj_Entry *obj; size_t size, ralign; - char *tls; + char *tls_block; uintptr_t *dtv, *olddtv; - uintptr_t segbase, oldsegbase; + uintptr_t **tcb; char *addr; size_t i; @@ -5560,33 +5560,32 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign) size = roundup(tls_static_space, ralign) + roundup(tcbsize, ralign); assert(tcbsize >= 2 * sizeof(uintptr_t)); - tls = xmalloc_aligned(size, ralign, 0 /* XXX */); + tls_block = xmalloc_aligned(size, ralign, 0 /* XXX */); dtv = xcalloc(tls_max_index + 2, sizeof(uintptr_t)); - segbase = (uintptr_t)(tls + roundup(tls_static_space, ralign)); - ((uintptr_t *)segbase)[0] = segbase; - ((uintptr_t *)segbase)[1] = (uintptr_t)dtv; + tcb = (uintptr_t **)(tls_block + roundup(tls_static_space, ralign)); + tcb[0] = (uintptr_t *)tcb; + tcb[1] = dtv; dtv[0] = tls_dtv_generation; dtv[1] = tls_max_index; - if (oldtls != NULL) { + if (oldtcb != NULL) { /* * Copy the static TLS block over whole. */ - oldsegbase = (uintptr_t)oldtls; - memcpy((void *)(segbase - tls_static_space), - (const void *)(oldsegbase - tls_static_space), + memcpy((char *)tcb - tls_static_space, + (const char *)oldtcb - tls_static_space, tls_static_space); /* * If any dynamic TLS blocks have been created tls_get_addr(), * move them over. */ - olddtv = ((uintptr_t **)oldsegbase)[1]; + olddtv = ((uintptr_t **)oldtcb)[1]; for (i = 0; i < olddtv[1]; i++) { - if (olddtv[i + 2] < oldsegbase - size || - olddtv[i + 2] > oldsegbase) { + if (olddtv[i + 2] < (uintptr_t)oldtcb - size || + olddtv[i + 2] > (uintptr_t)oldtcb) { dtv[i + 2] = olddtv[i + 2]; olddtv[i + 2] = 0; } @@ -5596,12 +5595,12 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign) * We assume that this block was the one we created with * allocate_initial_tls(). */ - free_tls(oldtls, 2 * sizeof(uintptr_t), sizeof(uintptr_t)); + free_tls(oldtcb, 2 * sizeof(uintptr_t), sizeof(uintptr_t)); } else { for (obj = objs; obj != NULL; obj = TAILQ_NEXT(obj, next)) { if (obj->marker || obj->tlsoffset == 0) continue; - addr = (char *)segbase - obj->tlsoffset; + addr = (char *)tcb - obj->tlsoffset; memset(addr + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize); if (obj->tlsinit) { @@ -5612,11 +5611,11 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign) } } - return ((void *)segbase); + return (tcb); } void -free_tls(void *tls, size_t tcbsize __unused, size_t tcbalign) +free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign) { uintptr_t *dtv; size_t size, ralign; @@ -5632,9 +5631,9 @@ free_tls(void *tls, size_t tcbsize __unused, size_t tcbalign) ralign = tls_static_max_align; size = roundup(tls_static_space, ralign); - dtv = ((uintptr_t **)tls)[1]; + dtv = ((uintptr_t **)tcb)[1]; dtvsize = dtv[1]; - tlsend = (uintptr_t)tls; + tlsend = (uintptr_t)tcb; tlsstart = tlsend - size; for (i = 0; i < dtvsize; i++) { if (dtv[i + 2] != 0 && (dtv[i + 2] < tlsstart || @@ -5755,13 +5754,13 @@ free_tls_offset(Obj_Entry *obj) } void * -_rtld_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) +_rtld_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign) { void *ret; RtldLockState lockstate; wlock_acquire(rtld_bind_lock, &lockstate); - ret = allocate_tls(globallist_curr(TAILQ_FIRST(&obj_list)), oldtls, + ret = allocate_tls(globallist_curr(TAILQ_FIRST(&obj_list)), oldtcb, tcbsize, tcbalign); lock_release(rtld_bind_lock, &lockstate); return (ret);