From owner-svn-src-head@FreeBSD.ORG Fri Dec 7 07:02:40 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A8B47634; Fri, 7 Dec 2012 07:02:40 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 718A98FC14; Fri, 7 Dec 2012 07:02:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qB772eCw040727; Fri, 7 Dec 2012 07:02:40 GMT (envelope-from rpaulo@svn.freebsd.org) Received: (from rpaulo@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qB772ebd040726; Fri, 7 Dec 2012 07:02:40 GMT (envelope-from rpaulo@svn.freebsd.org) Message-Id: <201212070702.qB772ebd040726@svn.freebsd.org> From: Rui Paulo Date: Fri, 7 Dec 2012 07:02:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r243977 - head/sys/boot/i386/efi X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Dec 2012 07:02:40 -0000 Author: rpaulo Date: Fri Dec 7 07:02:39 2012 New Revision: 243977 URL: http://svnweb.freebsd.org/changeset/base/243977 Log: Make this work for 64 bit binaries. Modified: head/sys/boot/i386/efi/reloc.c Modified: head/sys/boot/i386/efi/reloc.c ============================================================================== --- head/sys/boot/i386/efi/reloc.c Fri Dec 7 07:00:31 2012 (r243976) +++ head/sys/boot/i386/efi/reloc.c Fri Dec 7 07:02:39 2012 (r243977) @@ -28,21 +28,31 @@ __FBSDID("$FreeBSD$"); #include -#include +#include #include #include +#ifdef __i386__ +#define ElfW_Rel Elf32_Rel +#define ElfW_Dyn Elf32_Dyn +#define ELFW_R_TYPE ELF32_R_TYPE +#elif __amd64__ +#define ElfW_Rel Elf64_Rel +#define ElfW_Dyn Elf64_Dyn +#define ELFW_R_TYPE ELF64_R_TYPE +#endif + /* - * A simple relocator for IA32 EFI binaries. + * A simple relocator for IA32/AMD64 EFI binaries. */ EFI_STATUS -_reloc(unsigned long ImageBase, Elf32_Dyn *dynamic, EFI_HANDLE image_handle, +_reloc(unsigned long ImageBase, ElfW_Dyn *dynamic, EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) { unsigned long relsz, relent; unsigned long *newaddr; - Elf32_Rel *rel; - Elf32_Dyn *dynp; + ElfW_Rel *rel; + ElfW_Dyn *dynp; /* * Find the relocation address, its size and the relocation entry. @@ -51,14 +61,17 @@ _reloc(unsigned long ImageBase, Elf32_Dy relent = 0; for (dynp = dynamic; dynp->d_tag != DT_NULL; dynp++) { switch (dynp->d_tag) { + case DT_RELA: case DT_REL: - rel = (Elf32_Rel *) ((unsigned long) dynp->d_un.d_ptr + + rel = (ElfW_Rel *) ((unsigned long) dynp->d_un.d_ptr + ImageBase); break; case DT_RELSZ: + case DT_RELASZ: relsz = dynp->d_un.d_val; break; case DT_RELENT: + case DT_RELAENT: relent = dynp->d_un.d_val; break; default: @@ -74,7 +87,7 @@ _reloc(unsigned long ImageBase, Elf32_Dy CTASSERT(R_386_NONE == R_X86_64_NONE); CTASSERT(R_386_RELATIVE == R_X86_64_RELATIVE); for (; relsz > 0; relsz -= relent) { - switch (ELF32_R_TYPE(rel->r_info)) { + switch (ELFW_R_TYPE(rel->r_info)) { case R_386_NONE: /* No relocation needs be performed. */ break; @@ -85,9 +98,9 @@ _reloc(unsigned long ImageBase, Elf32_Dy break; default: /* XXX: do we need other relocations ? */ - return (EFI_LOAD_ERROR); + break; } - rel = (Elf32_Rel *) ((caddr_t) rel + relent); + rel = (ElfW_Rel *) ((caddr_t) rel + relent); } return (EFI_SUCCESS);