Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 May 2015 13:24:27 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r282727 - in head/sys/boot: common efi/boot1 efi/loader efi/loader/arch/amd64 efi/loader/arch/arm efi/loader/arch/arm64 efi/loader/arch/i386
Message-ID:  <201505101324.t4ADORtJ031632@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Sun May 10 13:24:26 2015
New Revision: 282727
URL: https://svnweb.freebsd.org/changeset/base/282727

Log:
  The self-relocation code is not efi-specific, move it to boot/common.
  
  The function was defined as taking 4 parameters and returning EFI_STATUS,
  but all existing callers (in asm code) passed only two parameters and don't
  use the return value. The function signature now matches that usage, and
  doesn't refer to efi-specific types.
  
  Parameters and variables now use the cannonical typenames set up by elf.h
  (Elf_Word, Elf_Addr, etc) instead of raw C types. Hopefully this will
  prevent suprises as new platforms come along and use this code.
  
  The function was renamed from _reloc() to self_reloc() to emphasize its
  difference from the other elf relocation code found in boot/common.
  
  Differential Revision:	https://reviews.freebsd.org/D2490

Added:
  head/sys/boot/common/self_reloc.c
     - copied, changed from r282653, head/sys/boot/efi/loader/reloc.c
Deleted:
  head/sys/boot/efi/loader/reloc.c
Modified:
  head/sys/boot/efi/boot1/Makefile
  head/sys/boot/efi/loader/Makefile
  head/sys/boot/efi/loader/arch/amd64/start.S
  head/sys/boot/efi/loader/arch/arm/start.S
  head/sys/boot/efi/loader/arch/arm64/start.S
  head/sys/boot/efi/loader/arch/i386/start.S

Copied and modified: head/sys/boot/common/self_reloc.c (from r282653, head/sys/boot/efi/loader/reloc.c)
==============================================================================
--- head/sys/boot/efi/loader/reloc.c	Fri May  8 17:53:44 2015	(r282653, copy source)
+++ head/sys/boot/common/self_reloc.c	Sun May 10 13:24:26 2015	(r282727)
@@ -29,7 +29,6 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/types.h>
 #include <elf.h>
-#include <efi.h>
 #include <bootstrap.h>
 
 #if defined(__aarch64__)
@@ -38,11 +37,11 @@ __FBSDID("$FreeBSD$");
 #define	ELFW_R_TYPE	ELF64_R_TYPE
 #define	ELF_RELA
 #elif defined(__arm__) || defined(__i386__)
-#define ElfW_Rel	Elf32_Rel
+#define	ElfW_Rel	Elf32_Rel
 #define	ElfW_Dyn	Elf32_Dyn
 #define	ELFW_R_TYPE	ELF32_R_TYPE
 #elif defined(__amd64__)
-#define ElfW_Rel	Elf64_Rel
+#define	ElfW_Rel	Elf64_Rel
 #define	ElfW_Dyn	Elf64_Dyn
 #define	ELFW_R_TYPE	ELF64_R_TYPE
 #else
@@ -63,14 +62,13 @@ __FBSDID("$FreeBSD$");
 #endif
 
 /*
- * A simple relocator for EFI binaries.
+ * A simple elf relocator.
  */
-EFI_STATUS
-_reloc(unsigned long ImageBase, ElfW_Dyn *dynamic, EFI_HANDLE image_handle,
-    EFI_SYSTEM_TABLE *system_table)
+void
+self_reloc(Elf_Addr baseaddr, ElfW_Dyn *dynamic)
 {
-	unsigned long relsz, relent;
-	unsigned long *newaddr;
+	Elf_Word relsz, relent;
+	Elf_Addr *newaddr;
 	ElfW_Rel *rel;
 	ElfW_Dyn *dynp;
 
@@ -83,8 +81,7 @@ _reloc(unsigned long ImageBase, ElfW_Dyn
 		switch (dynp->d_tag) {
 		case DT_REL:
 		case DT_RELA:
-			rel = (ElfW_Rel *) ((unsigned long) dynp->d_un.d_ptr +
-			    ImageBase);
+			rel = (ElfW_Rel *)(dynp->d_un.d_ptr + baseaddr);
 			break;
 		case DT_RELSZ:
 		case DT_RELASZ:
@@ -110,8 +107,8 @@ _reloc(unsigned long ImageBase, ElfW_Dyn
 
 		case RELOC_TYPE_RELATIVE:
 			/* Address relative to the base address. */
-			newaddr = (unsigned long *)(ImageBase + rel->r_offset);
-			*newaddr += ImageBase;
+			newaddr = (Elf_Addr *)(rel->r_offset + baseaddr);
+			*newaddr += baseaddr;
 			/* Add the addend when the ABI uses them */ 
 #ifdef ELF_RELA
 			*newaddr += rel->r_addend;
@@ -123,6 +120,4 @@ _reloc(unsigned long ImageBase, ElfW_Dyn
 		}
 		rel = (ElfW_Rel *) ((caddr_t) rel + relent);
 	}
-
-	return (EFI_SUCCESS);
 }

Modified: head/sys/boot/efi/boot1/Makefile
==============================================================================
--- head/sys/boot/efi/boot1/Makefile	Sun May 10 13:21:36 2015	(r282726)
+++ head/sys/boot/efi/boot1/Makefile	Sun May 10 13:24:26 2015	(r282727)
@@ -13,7 +13,7 @@ PROG=		loader.sym
 INTERNALPROG=
 
 # architecture-specific loader code
-SRCS=	boot1.c reloc.c start.S
+SRCS=	boot1.c self_reloc.c start.S
 
 CFLAGS+=	-I.
 CFLAGS+=	-I${.CURDIR}/../include

Modified: head/sys/boot/efi/loader/Makefile
==============================================================================
--- head/sys/boot/efi/loader/Makefile	Sun May 10 13:21:36 2015	(r282726)
+++ head/sys/boot/efi/loader/Makefile	Sun May 10 13:24:26 2015	(r282727)
@@ -20,7 +20,7 @@ SRCS=	autoload.c \
 	copy.c \
 	devicename.c \
 	main.c \
-	reloc.c \
+	self_reloc.c \
 	smbios.c \
 	vers.c
 

Modified: head/sys/boot/efi/loader/arch/amd64/start.S
==============================================================================
--- head/sys/boot/efi/loader/arch/amd64/start.S	Sun May 10 13:21:36 2015	(r282726)
+++ head/sys/boot/efi/loader/arch/amd64/start.S	Sun May 10 13:24:26 2015	(r282727)
@@ -53,7 +53,7 @@ _start:
 	popq %rdx
 	pushq %rcx
 	pushq %rdx
-	call _reloc
+	call self_reloc
 
 	popq %rdi
 	popq %rsi

Modified: head/sys/boot/efi/loader/arch/arm/start.S
==============================================================================
--- head/sys/boot/efi/loader/arch/arm/start.S	Sun May 10 13:21:36 2015	(r282726)
+++ head/sys/boot/efi/loader/arch/arm/start.S	Sun May 10 13:24:26 2015	(r282727)
@@ -153,7 +153,7 @@ _start:
 	ldr	r1, .Ldynamic
 	add	r1, r1, r5
 
-	bl	_C_LABEL(_reloc)
+	bl	_C_LABEL(self_reloc)
 
 	/* Zero the BSS, _reloc fixed the values for us */
 	ldr	r0, .Lbss

Modified: head/sys/boot/efi/loader/arch/arm64/start.S
==============================================================================
--- head/sys/boot/efi/loader/arch/arm64/start.S	Sun May 10 13:21:36 2015	(r282726)
+++ head/sys/boot/efi/loader/arch/arm64/start.S	Sun May 10 13:24:26 2015	(r282727)
@@ -156,7 +156,7 @@ _start:
 	adr	x0, ImageBase
 	adr	x1, _DYNAMIC
 
-	bl	_reloc
+	bl	self_reloc
 
 	ldp	x0, x1, [sp], #16
 

Modified: head/sys/boot/efi/loader/arch/i386/start.S
==============================================================================
--- head/sys/boot/efi/loader/arch/i386/start.S	Sun May 10 13:21:36 2015	(r282726)
+++ head/sys/boot/efi/loader/arch/i386/start.S	Sun May 10 13:24:26 2015	(r282727)
@@ -53,7 +53,7 @@ ENTRY(_start)
 	addl	$_DYNAMIC-0b, %ebx
 	pushl	%ebx		/* dynamic */
 	pushl	%eax		/* ImageBase */
-	call	_reloc
+	call	self_reloc
 	cmpl	$EFI_SUCCESS, %eax
 	jne	1f
 	popl	%ebx		/* remove ImageBase from the stack */



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