From nobody Wed May 7 19:22:06 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 4Zt4rt6Q1jz5v92V; Wed, 07 May 2025 19:22:06 +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 4Zt4rt37Hnz49XS; Wed, 07 May 2025 19:22:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746645726; 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=yhY/i6a03Cq9qkz4uaV1/7eUCx+kzqbMyettZgH2X2U=; b=tssAi2HQaE9EKvwiyBUMDyyAaRBupAMsTdrMq8TVNlkVAAKzJV4s9Zb/+CyCTXA4Txm6Uu SUyKwIn2K2rli863VXFxm1UuqSxMTy/iG9gDVO8T30wxwLI8e91/QHO2XB9L2eHwHaQgfg zPAEyHXdBBgBDD3hr9K/8C366ERg83ALZ1EY66v9cIntW0MVANrj4fw1BheT2uJ2hHeuEo 0llrftIdk/eBGQ4AVLRs+v0iYAL48Mb3y3q7Yl82LbdzLOF5XABAKOuwU1v5d+Ny3CcOGr VyM9p6XZzRlEGwwljgLNmYIqrQQXhMMa/t+mopjZoLO6+8TLv778fCykqhyvpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746645726; 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=yhY/i6a03Cq9qkz4uaV1/7eUCx+kzqbMyettZgH2X2U=; b=MaRpW0PPxF1BtCY6/a8wEZbX0sSPE10Kb/QD0JSv9EHRIvp4/67TZAjLYN06Ch1lHlr6nQ LTYSF7iHo9Z6hJV2GdpVqzkwbam7++c3zMjmOpSLqsNpdge1k3FsLVjBYW/0IIkJZpvEAX 8KkF590hvBlscJGILTgUgVtXEmVCPnkkZHQVdoLtvPEUE5uVpI8qBSz8OwuaOjeO0GBUIG LJEgOIqj2l/DzaGtTtcZ3UhBRp+4GsKce2gMHjlz2UbMjZUvJgC0U1ezNdJ+7uyTrQ68ZK Dxeif1oPjb0lHgZOtbEaIR6lNp/N72J37dIyvXC0o68zp4ZO8auCuzDX+n5qzQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746645726; a=rsa-sha256; cv=none; b=jMW4O7BvYydbCp4DrzIS8Zmul1s1h4JkjqaTG04NVLp3/q+YgjuD9giVLPtJOK78zmD+Ah wMJwny40USXXxI8f6s7aGYZU2ac5254INkBQFX0rqbQ0XSI3Ct6S2gM+X2CigIzclGbkoj M0IR88SJiFyKd7bwXFv02140Xv5fIBLAtPClV6t7+Rbg/AAr2SUdfK52Dymh+9rV7hoSgI XVUXQHfI9pour9sZOgyh/vwCJ93L7qTNskBxWT2kZEJ9XcOqtDvmcqG2OEf5D6lil9Gj0/ UHnVTS6MCQhSqY3AqjjgmSthldw/WTP+vh1Kklb0iz+dCbCYLldS4hv0bA1xbA== 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 4Zt4rt2WyzzjkP; Wed, 07 May 2025 19:22:06 +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 547JM671042960; Wed, 7 May 2025 19:22:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 547JM6YN042957; Wed, 7 May 2025 19:22:06 GMT (envelope-from git) Date: Wed, 7 May 2025 19:22:06 GMT Message-Id: <202505071922.547JM6YN042957@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: 1ef9f0371e2d - main - libc: Consistently use uintptr_t for TLS implementation 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: 1ef9f0371e2dce8bc53bd43d6c95f0acba987853 Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=1ef9f0371e2dce8bc53bd43d6c95f0acba987853 commit 1ef9f0371e2dce8bc53bd43d6c95f0acba987853 Author: Jessica Clarke AuthorDate: 2025-05-07 19:19:49 +0000 Commit: Jessica Clarke CommitDate: 2025-05-07 19:19:49 +0000 libc: Consistently use uintptr_t for TLS implementation Elf_Addr is the format of addresses in the ELF file with the current ABI's default class. This is normally the same as the format of an address at run time, though technically exceptions do exist outside of FreeBSD's currently-supported architectures (for example, IA-64's LP64 supports both ELFCLASS32 and ELFCLASS64 file formats; LP64 vs ILP32 is an orthogonal EF_IA_64_ABI64 flag). On traditional architectures, including all currently-supported FreeBSD architectures, addresses and pointers are synonymous, but on CHERI they are not, as pointers are capabilities that contain metadata alongside the address. In the cases here, the quantities are run-time pointers, not addresses (and definitely not ELF file addresses), so we should use pointer-ish types. Note that we already use uintptr_t in struct tcb (both Variant I and Variant II) but still use Elf_Addr in various places here. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50225 --- lib/libc/gen/tls.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c index 218cd1da92df..ad6f43eb3534 100644 --- a/lib/libc/gen/tls.c +++ b/lib/libc/gen/tls.c @@ -200,10 +200,10 @@ get_tls_block_ptr(void *tcb, size_t tcbsize) void __libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused) { - Elf_Addr *dtv; - Elf_Addr **tls; + uintptr_t *dtv; + uintptr_t **tls; - tls = (Elf_Addr **)tcb; + tls = (uintptr_t **)tcb; dtv = tls[0]; __je_bootstrap_free(dtv); libc_free_aligned(get_tls_block_ptr(tcb, tcbsize)); @@ -232,7 +232,7 @@ __libc_free_tls(void *tcb, size_t tcbsize, size_t tcbalign __unused) void * __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign) { - Elf_Addr *dtv, **tcb; + uintptr_t *dtv, **tcb; char *tls_block, *tls; size_t extra_size, maxalign, post_size, pre_size, tls_block_size; @@ -261,7 +261,7 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign) abort(); } memset(tls_block, 0, tls_block_size); - tcb = (Elf_Addr **)(tls_block + pre_size + extra_size); + tcb = (uintptr_t **)(tls_block + pre_size + extra_size); tls = (char *)tcb + TLS_TCB_SIZE + post_size; if (oldtcb != NULL) { @@ -271,9 +271,9 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign) /* Adjust the DTV. */ dtv = tcb[0]; - dtv[2] = (Elf_Addr)tls; + dtv[2] = (uintptr_t)tls; } else { - dtv = __je_bootstrap_malloc(3 * sizeof(Elf_Addr)); + dtv = __je_bootstrap_malloc(3 * sizeof(uintptr_t)); if (dtv == NULL) { tls_msg("__libc_allocate_tls: Out of memory.\n"); abort(); @@ -282,7 +282,7 @@ __libc_allocate_tls(void *oldtcb, size_t tcbsize, size_t tcbalign) tcb[0] = dtv; dtv[0] = 1; /* Generation. */ dtv[1] = 1; /* Segments count. */ - dtv[2] = (Elf_Addr)tls; + dtv[2] = (uintptr_t)tls; if (libc_tls_init_size > 0) memcpy(tls, libc_tls_init, libc_tls_init_size); @@ -302,8 +302,8 @@ void __libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign) { size_t size; - Elf_Addr* dtv; - Elf_Addr tlsstart, tlsend; + uintptr_t *dtv; + uintptr_t tlsstart, tlsend; /* * Figure out the size of the initial TLS block so that we can @@ -312,8 +312,8 @@ __libc_free_tls(void *tcb, size_t tcbsize __unused, size_t tcbalign) tcbalign = MAX(tcbalign, libc_tls_init_align); size = roundup2(libc_tls_static_space, tcbalign); - dtv = ((Elf_Addr**)tcb)[1]; - tlsend = (Elf_Addr) tcb; + dtv = ((uintptr_t **)tcb)[1]; + tlsend = (uintptr_t)tcb; tlsstart = tlsend - size; libc_free_aligned((void*)tlsstart); __je_bootstrap_free(dtv); @@ -327,29 +327,29 @@ __libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) { size_t size; char *tls; - Elf_Addr *dtv; - Elf_Addr segbase, oldsegbase; + uintptr_t *dtv; + uintptr_t segbase, oldsegbase; tcbalign = MAX(tcbalign, libc_tls_init_align); size = roundup2(libc_tls_static_space, tcbalign); - if (tcbsize < 2 * sizeof(Elf_Addr)) - tcbsize = 2 * sizeof(Elf_Addr); + if (tcbsize < 2 * sizeof(uintptr_t)) + tcbsize = 2 * sizeof(uintptr_t); tls = libc_malloc_aligned(size + tcbsize, tcbalign); if (tls == NULL) { tls_msg("__libc_allocate_tls: Out of memory.\n"); abort(); } memset(tls, 0, size + tcbsize); - dtv = __je_bootstrap_malloc(3 * sizeof(Elf_Addr)); + dtv = __je_bootstrap_malloc(3 * sizeof(uintptr_t)); if (dtv == NULL) { tls_msg("__libc_allocate_tls: Out of memory.\n"); abort(); } - segbase = (Elf_Addr)(tls + size); - ((Elf_Addr*)segbase)[0] = segbase; - ((Elf_Addr*)segbase)[1] = (Elf_Addr) dtv; + segbase = (uintptr_t)(tls + size); + ((uintptr_t *)segbase)[0] = segbase; + ((uintptr_t *)segbase)[1] = (uintptr_t)dtv; dtv[0] = 1; dtv[1] = 1; @@ -359,7 +359,7 @@ __libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) /* * Copy the static TLS block over whole. */ - oldsegbase = (Elf_Addr) oldtls; + oldsegbase = (uintptr_t)oldtls; memcpy((void *)(segbase - libc_tls_static_space), (const void *)(oldsegbase - libc_tls_static_space), libc_tls_static_space); @@ -368,7 +368,8 @@ __libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) * We assume that this block was the one we created with * allocate_initial_tls(). */ - _rtld_free_tls(oldtls, 2*sizeof(Elf_Addr), sizeof(Elf_Addr)); + _rtld_free_tls(oldtls, 2 * sizeof(uintptr_t), + sizeof(uintptr_t)); } else { memcpy((void *)(segbase - libc_tls_static_space), libc_tls_init, libc_tls_init_size);