From nobody Fri May 17 10:21:51 2024 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 4VgjgN0csRz5KvsS; Fri, 17 May 2024 10:21:52 +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 4VgjgM611cz53Y4; Fri, 17 May 2024 10:21:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715941311; 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=uURwzyIzmsOM7GAqS8P27VrK2W8EVPpL7glr5dP34zw=; b=HsDR5FUs+j1XG9kfdmwNcuz8U9LdIclyvnncueUuF3M9ckGy4V1pFkCEtt0h5zHPsqn5qg cRPLv6gwdloGL+pv495skXCxuavsIWhuSC03LsAPlbdT/2j1DKVY7hYihXmcYunpAoHVqO l10tunW7m+J7QWrlVHtH1D1C6L6Q9fCksCBN0eS8R2AG8k8jqGMM0xZKz9+D0+/yIk14zb ih4E57Kwy/6umLUX3yTL+wQQudVWUhI0/3o9/GL//E5UYAyNT5+9TfViCEM3cphVP1tVIj UUrBJpBeRJeTigj0/Pm4nsuJ5TNjsV0wkp9jTcSd7SOJacqzyQA9V5KwEFk41A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715941311; a=rsa-sha256; cv=none; b=eD+0HS3OFJxdTU70fOmpLbX75X3AYloZ8dM+Oj3r3+ex+fMs2X6ezGTegfmbcFYu9ek134 atUkqJz6xQX8fXKY04LEUUxUQDpICJiPJFHB98q2fgeh8cj+4GJ+RdBbnpc1kS480Dqh98 zM3w/9kgA8MlIr2jnmv4sW5tjzCdgteW4QLvrL3v8rW5dvvkJzDlxgRfSxRXBldFd8EeYa McpSOjG4ZpD4PTEfCk2flAKecLcHfXvZ35Ty9Boj7FDwqMvxvMSH5OYoNF8cIk5gZ1Ijb4 QamotLFxVb4RlIKh3nqT9GCrlmWfBtppOPz8OPq4uWt00f9/m1Wuv9TpMqPIbA== 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=1715941311; 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=uURwzyIzmsOM7GAqS8P27VrK2W8EVPpL7glr5dP34zw=; b=HKwL+H/wWQqitkcuoARzGTyki0n4eYkX4KbV4SiRTyvgTMcS505CzLQSNjyOT2FtAC6FgC e3aJzocCchE6EQD7Ur+1MU+lJEcbeDfFi97mGmFL1q8ZbmDzzlNmULrQpgR5gdOE/SX7sJ XRdP7m7BrmbQfjy2ECjp680bHrVdQCeIXQWKuZLqd3gjKF5I7jixOQevX9oOWnzV0GxGps OwMacHP+uOrS+Y9P98IGchVFkqCvhu05GDpL/tEUrPSPQWlhzblvv94jchwIMjlfCMhgZa ehUm4LOewxQ6KGKfh+/GuXn0acS7sF+F1IGom595SGBIEhWlXwK81lP9x+wN4A== 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 4VgjgM5QrGzfTf; Fri, 17 May 2024 10:21:51 +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 44HALpid069702; Fri, 17 May 2024 10:21:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44HALp5H069699; Fri, 17 May 2024 10:21:51 GMT (envelope-from git) Date: Fri, 17 May 2024 10:21:51 GMT Message-Id: <202405171021.44HALp5H069699@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: d51fa0a9b11d - main - rtld: Add support for arm64 variant pcs 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: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d51fa0a9b11db524a8e872c0019e54846a03d8a9 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=d51fa0a9b11db524a8e872c0019e54846a03d8a9 commit d51fa0a9b11db524a8e872c0019e54846a03d8a9 Author: Andrew Turner AuthorDate: 2024-04-17 15:29:29 +0000 Commit: Andrew Turner CommitDate: 2024-05-17 09:37:23 +0000 rtld: Add support for arm64 variant pcs The aarch64 ELF spec has support for a variant of the normal procedure call standard that doesn't follow the normal register convention, e.g. using more registers as arguments, or different register state is preserved. Add support to rtld to handle this. As we don't know which registers need to be preserved disable lazy binding for these functions. Reviewed by: kib Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D44869 --- libexec/rtld-elf/aarch64/reloc.c | 50 +++++++++++++++++++++++++++++++-- libexec/rtld-elf/aarch64/rtld_machdep.h | 6 ++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/libexec/rtld-elf/aarch64/reloc.c b/libexec/rtld-elf/aarch64/reloc.c index d73982e26b76..78e2e2b1aaae 100644 --- a/libexec/rtld-elf/aarch64/reloc.c +++ b/libexec/rtld-elf/aarch64/reloc.c @@ -54,6 +54,17 @@ void *_rtld_tlsdesc_dynamic(void *); void _exit(int); +bool +arch_digest_dynamic(struct Struct_Obj_Entry *obj, const Elf_Dyn *dynp) +{ + if (dynp->d_tag == DT_AARCH64_VARIANT_PCS) { + obj->variant_pcs = true; + return (true); + } + + return (false); +} + bool arch_digest_note(struct Struct_Obj_Entry *obj __unused, const Elf_Note *note) { @@ -228,19 +239,54 @@ reloc_tlsdesc(const Obj_Entry *obj, const Elf_Rela *rela, Elf_Addr *where, int reloc_plt(Obj_Entry *obj, int flags, RtldLockState *lockstate) { + const Obj_Entry *defobj; const Elf_Rela *relalim; const Elf_Rela *rela; + const Elf_Sym *def, *sym; + bool lazy; relalim = (const Elf_Rela *)((const char *)obj->pltrela + obj->pltrelasize); for (rela = obj->pltrela; rela < relalim; rela++) { - Elf_Addr *where; + Elf_Addr *where, target; where = (Elf_Addr *)(obj->relocbase + rela->r_offset); switch(ELF_R_TYPE(rela->r_info)) { case R_AARCH64_JUMP_SLOT: - *where += (Elf_Addr)obj->relocbase; + lazy = true; + if (obj->variant_pcs) { + sym = &obj->symtab[ELF_R_SYM(rela->r_info)]; + /* + * Variant PCS functions don't follow the + * standard register convention. Because of + * this we can't use lazy relocation and + * need to set the target address. + */ + if ((sym->st_other & STO_AARCH64_VARIANT_PCS) != + 0) + lazy = false; + } + if (lazy) { + *where += (Elf_Addr)obj->relocbase; + } else { + def = find_symdef(ELF_R_SYM(rela->r_info), obj, + &defobj, SYMLOOK_IN_PLT | flags, NULL, + lockstate); + if (def == NULL) + return (-1); + if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC){ + obj->gnu_ifunc = true; + continue; + } + target = (Elf_Addr)(defobj->relocbase + + def->st_value); + /* + * Ignore ld_bind_not as it requires lazy + * binding + */ + *where = target; + } break; case R_AARCH64_TLSDESC: reloc_tlsdesc(obj, rela, where, SYMLOOK_IN_PLT | flags, diff --git a/libexec/rtld-elf/aarch64/rtld_machdep.h b/libexec/rtld-elf/aarch64/rtld_machdep.h index 347ef5f381fe..3cc1339fcad4 100644 --- a/libexec/rtld-elf/aarch64/rtld_machdep.h +++ b/libexec/rtld-elf/aarch64/rtld_machdep.h @@ -37,7 +37,8 @@ struct Struct_Obj_Entry; -#define MD_OBJ_ENTRY +#define MD_OBJ_ENTRY \ + bool variant_pcs : 1; /* Object has a variant pcs function */ /* Return the address of the .dynamic section in the dynamic linker. */ #define rtld_dynamic(obj) \ @@ -47,8 +48,7 @@ struct Struct_Obj_Entry; (const Elf_Dyn *)_dynamic_addr; \ }) -/* No arch-specific dynamic tags */ -#define arch_digest_dynamic(obj, dynp) false +bool arch_digest_dynamic(struct Struct_Obj_Entry *obj, const Elf_Dyn *dynp); bool arch_digest_note(struct Struct_Obj_Entry *obj, const Elf_Note *note);