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
This commit is contained in:
Ian Lepore 2015-05-10 13:24:26 +00:00
parent 9d8b66868a
commit 5b1c03fd13
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=282727
7 changed files with 16 additions and 21 deletions

View File

@ -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 *dynamic, EFI_HANDLE image_handle,
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 *dynamic, EFI_HANDLE image_handle,
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 *dynamic, EFI_HANDLE image_handle,
}
rel = (ElfW_Rel *) ((caddr_t) rel + relent);
}
return (EFI_SUCCESS);
}

View File

@ -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

View File

@ -20,7 +20,7 @@ SRCS= autoload.c \
copy.c \
devicename.c \
main.c \
reloc.c \
self_reloc.c \
smbios.c \
vers.c

View File

@ -53,7 +53,7 @@ _start:
popq %rdx
pushq %rcx
pushq %rdx
call _reloc
call self_reloc
popq %rdi
popq %rsi

View File

@ -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

View File

@ -156,7 +156,7 @@ _start:
adr x0, ImageBase
adr x1, _DYNAMIC
bl _reloc
bl self_reloc
ldp x0, x1, [sp], #16

View File

@ -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 */