From owner-dev-commits-src-main@freebsd.org Wed Jan 20 18:33:17 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 419C04FE966; Wed, 20 Jan 2021 18:33:17 +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 4DLZ0F1Q5Gz3Qsv; Wed, 20 Jan 2021 18:33:17 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 22D5A1E218; Wed, 20 Jan 2021 18:33:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10KIXHaC019299; Wed, 20 Jan 2021 18:33:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10KIXHdV019298; Wed, 20 Jan 2021 18:33:17 GMT (envelope-from git) Date: Wed, 20 Jan 2021 18:33:17 GMT Message-Id: <202101201833.10KIXHdV019298@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: f6f0b849fb26 - main - Reuse the amd64 loader relocation code on arm64 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: f6f0b849fb2683feebf2416a793964be0bd05cc5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jan 2021 18:33:17 -0000 The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=f6f0b849fb2683feebf2416a793964be0bd05cc5 commit f6f0b849fb2683feebf2416a793964be0bd05cc5 Author: Andrew Turner AuthorDate: 2021-01-17 18:11:11 +0000 Commit: Andrew Turner CommitDate: 2021-01-20 17:59:38 +0000 Reuse the amd64 loader relocation code on arm64 There is no need to keep multiple copies of the relocation code. The amd64 code works on arm64 with a few small changes to relocation types. Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D28213 --- stand/common/reloc_elf.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/stand/common/reloc_elf.c b/stand/common/reloc_elf.c index 56b661dc21bd..262091b9f6c6 100644 --- a/stand/common/reloc_elf.c +++ b/stand/common/reloc_elf.c @@ -52,7 +52,8 @@ int __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr, const void *reldata, int reltype, Elf_Addr relbase, Elf_Addr dataaddr, void *data, size_t len) { -#if (defined(__i386__) || defined(__amd64__)) && __ELF_WORD_SIZE == 64 +#if (defined(__aarch64__) || defined(__amd64__) || defined(__i386__)) && \ + __ELF_WORD_SIZE == 64 Elf64_Addr *where, val; Elf_Addr addend, addr; Elf_Size rtype, symidx; @@ -87,12 +88,29 @@ __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr, const void *reldata, if (reltype == ELF_RELOC_REL) addend = *where; +#if defined(__aarch64__) +#define RELOC_RELATIVE R_AARCH64_RELATIVE +#define RELOC_IRELATIVE R_AARCH64_IRELATIVE +#elif defined(__amd64__) || defined(__i386__) /* XXX, definitions not available on i386. */ #define R_X86_64_64 1 #define R_X86_64_RELATIVE 8 #define R_X86_64_IRELATIVE 37 +#define RELOC_RELATIVE R_X86_64_RELATIVE +#define RELOC_IRELATIVE R_X86_64_IRELATIVE +#endif + switch (rtype) { + case RELOC_RELATIVE: + addr = (Elf_Addr)addend + relbase; + val = addr; + memcpy(where, &val, sizeof(val)); + break; + case RELOC_IRELATIVE: + /* leave it to kernel */ + break; +#if defined(__amd64__) || defined(__i386__) case R_X86_64_64: /* S + A */ addr = symaddr(ef, symidx); if (addr == 0) @@ -100,14 +118,7 @@ __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr, const void *reldata, val = addr + addend; *where = val; break; - case R_X86_64_RELATIVE: - addr = (Elf_Addr)addend + relbase; - val = addr; - *where = val; - break; - case R_X86_64_IRELATIVE: - /* leave it to kernel */ - break; +#endif default: printf("\nunhandled relocation type %u\n", (u_int)rtype); return (EFTYPE); @@ -175,7 +186,7 @@ __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr, const void *reldata, } return (0); -#elif defined(__aarch64__) || defined(__powerpc__) || defined(__riscv) +#elif defined(__powerpc__) || defined(__riscv) Elf_Size w; const Elf_Rela *rela; @@ -185,9 +196,7 @@ __elfN(reloc)(struct elf_file *ef, symaddr_fn *symaddr, const void *reldata, if (relbase + rela->r_offset >= dataaddr && relbase + rela->r_offset < dataaddr + len) { switch (ELF_R_TYPE(rela->r_info)) { -#if defined(__aarch64__) - case R_AARCH64_RELATIVE: -#elif defined(__powerpc__) +#if defined(__powerpc__) case R_PPC_RELATIVE: #elif defined(__riscv) case R_RISCV_RELATIVE: