From nobody Wed Jun 05 16:42:12 2024 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 4VvYCT0M4pz5LD6b; Wed, 05 Jun 2024 16:42:13 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VvYCS7306z4MNW; Wed, 5 Jun 2024 16:42:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717605733; 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=7cRzEHtJAz9t+lt6SncLsC6+8d+KLnY/sARRuHOtVhE=; b=q1mYIsRotDxDjviDahVnTHrvFZiw7ubE9aFz01iKHDL6kdI6/BvaeryBKra8uwmRlvcN1V /BCfiKIHVpG4H3OnulbUBFR5QqYyE0Ho2Mxc87v+JjlSeu3CmgDMCLaoInha62jhton52i P8mp9wBWghSK45xHRl0JmINOTk2VyvfxM6M9StdEKcNj4Gte8stck1C+IlUuH+zrSIQF0s ZueRY17EZHRKPpPdEhKXNvyVLByPk3qgihNsh9mmOIONYMjjVIvC2L3xFBjTn74CVbcBS3 Of+BB0THHUvfgIWBM0HeUoIwKjF1aZP1SPKGcSBKD29G56518XYJpZBcw7r0JA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717605733; a=rsa-sha256; cv=none; b=UfK31Am32pA/ljSV7Nxuns/ahCh7m8/NJjojuPhIGXj9Ctx8fx0qDFvVb9MbrRQl1zHoZO Kd5snGk5MfhUGm+L89Vbl84tNwQTE2yqW+AdnH/k1D2pmr+8W9sxKLN0pHfWmnc/1EsAUu Pei0d/oMcd0Sg0E2BHFKyG9uL69MCPATLYK0uMXOS3HpcjZyY+8OJT5DTS5Ej9OQxX6xyy 89Z3QnuC1aoR0unc3CiiQqmb6pQ+DlsHC1bOe+b9tlvIMaqAhkCv8wr56JZbnZDKYZNbEF +3mtHFBqRSbFF8WzWsEWmthcVdE9tC263gSu3RTGReAQagdm4xjFXOe3gotgyQ== 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=1717605733; 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=7cRzEHtJAz9t+lt6SncLsC6+8d+KLnY/sARRuHOtVhE=; b=fG8QeFgbTI8O+BQ5UfKkUZjcfMMEwWuJZjpyTcp3znbSFSjrQZfnRr0OlDlRacJ+tIK8Tw qFtcGB0+X9U6aA2X7Z2Bilhu+BAOpjDpRIB+Zqz6OcjVWsrIVXPkm18jVdgKZtRZItRxuj VU7nFh79I39runKQbeAsvOKuKIFpjIXVxudHFpQl1DxRU5HeXpvXwuXsQtvHl29RXt1fIh ZCzznCkwUA8TFq27ioUTSEZhnbjA6dPxCOR+Oi/y2ZTjOzC4F4ZI8aqvqqGidExFFg4MLn fNbIy86gpWfn+xDfJf64gjsLVai3Y8hdazXIiCigIWxAgKAzFekuHu01APbJdA== 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 4VvYCS6fJqz18Sv; Wed, 5 Jun 2024 16:42:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 455GgCdL069106; Wed, 5 Jun 2024 16:42:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 455GgCo8069103; Wed, 5 Jun 2024 16:42:12 GMT (envelope-from git) Date: Wed, 5 Jun 2024 16:42:12 GMT Message-Id: <202406051642.455GgCo8069103@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: 98200077809a - main - rtld-elf: Use a proper struct type for tlsdesc entries 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: 98200077809a0926ae1775e4d56dd02651131e88 Auto-Submitted: auto-generated The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=98200077809a0926ae1775e4d56dd02651131e88 commit 98200077809a0926ae1775e4d56dd02651131e88 Author: Jessica Clarke AuthorDate: 2024-06-05 16:41:54 +0000 Commit: Jessica Clarke CommitDate: 2024-06-05 16:41:54 +0000 rtld-elf: Use a proper struct type for tlsdesc entries This clarifies the code and makes it less error-prone. It also makes it easier to extend downstream in CheriBSD (where pointer and integer members no longer have the same representation and an additional member is present). Reviewed by: jhb, kib Differential Revision: https://reviews.freebsd.org/D45143 --- libexec/rtld-elf/aarch64/reloc.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/libexec/rtld-elf/aarch64/reloc.c b/libexec/rtld-elf/aarch64/reloc.c index 78e2e2b1aaae..5dfe19e3d4f4 100644 --- a/libexec/rtld-elf/aarch64/reloc.c +++ b/libexec/rtld-elf/aarch64/reloc.c @@ -183,7 +183,7 @@ struct tls_data { Elf_Addr tls_offs; }; -static Elf_Addr +static struct tls_data * reloc_tlsdesc_alloc(int tlsindex, Elf_Addr tlsoffs) { struct tls_data *tlsdesc; @@ -193,18 +193,26 @@ reloc_tlsdesc_alloc(int tlsindex, Elf_Addr tlsoffs) tlsdesc->tls_index = tlsindex; tlsdesc->tls_offs = tlsoffs; - return ((Elf_Addr)tlsdesc); + return (tlsdesc); } +struct tlsdesc_entry { + void *(*func)(void *); + union { + Elf_Ssize addend; + Elf_Size offset; + struct tls_data *data; + }; +}; + static void -reloc_tlsdesc(const Obj_Entry *obj, const Elf_Rela *rela, Elf_Addr *where, - int flags, RtldLockState *lockstate) +reloc_tlsdesc(const Obj_Entry *obj, const Elf_Rela *rela, + struct tlsdesc_entry *where, int flags, RtldLockState *lockstate) { const Elf_Sym *def; const Obj_Entry *defobj; Elf_Addr offs; - offs = 0; if (ELF_R_SYM(rela->r_info) != 0) { def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, flags, @@ -215,8 +223,8 @@ reloc_tlsdesc(const Obj_Entry *obj, const Elf_Rela *rela, Elf_Addr *where, obj = defobj; if (def->st_shndx == SHN_UNDEF) { /* Weak undefined thread variable */ - where[0] = (Elf_Addr)_rtld_tlsdesc_undef; - where[1] = rela->r_addend; + where->func = _rtld_tlsdesc_undef; + where->addend = rela->r_addend; return; } } @@ -224,12 +232,12 @@ reloc_tlsdesc(const Obj_Entry *obj, const Elf_Rela *rela, Elf_Addr *where, if (obj->tlsoffset != 0) { /* Variable is in initialy allocated TLS segment */ - where[0] = (Elf_Addr)_rtld_tlsdesc_static; - where[1] = obj->tlsoffset + offs; + where->func = _rtld_tlsdesc_static; + where->offset = obj->tlsoffset + offs; } else { /* TLS offest is unknown at load time, use dynamic resolving */ - where[0] = (Elf_Addr)_rtld_tlsdesc_dynamic; - where[1] = reloc_tlsdesc_alloc(obj->tlsindex, offs); + where->func = _rtld_tlsdesc_dynamic; + where->data = reloc_tlsdesc_alloc(obj->tlsindex, offs); } } @@ -289,8 +297,8 @@ reloc_plt(Obj_Entry *obj, int flags, RtldLockState *lockstate) } break; case R_AARCH64_TLSDESC: - reloc_tlsdesc(obj, rela, where, SYMLOOK_IN_PLT | flags, - lockstate); + reloc_tlsdesc(obj, rela, (struct tlsdesc_entry *)where, + SYMLOOK_IN_PLT | flags, lockstate); break; case R_AARCH64_IRELATIVE: obj->irelative = true; @@ -549,7 +557,8 @@ reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags, } break; case R_AARCH64_TLSDESC: - reloc_tlsdesc(obj, rela, where, flags, lockstate); + reloc_tlsdesc(obj, rela, (struct tlsdesc_entry *)where, + flags, lockstate); break; case R_AARCH64_TLS_TPREL64: /*