Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Dec 2012 07:02:40 +0000 (UTC)
From:      Rui Paulo <rpaulo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r243977 - head/sys/boot/i386/efi
Message-ID:  <201212070702.qB772ebd040726@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/types.h>
-#include <sys/elf32.h>
+#include <elf.h>
 #include <efi.h>
 #include <bootstrap.h>
 
+#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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212070702.qB772ebd040726>