From 469a6f6d983bccffa88972ecfd65fe30500b772c Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 10 Apr 2015 09:15:35 +0000 Subject: [PATCH] Port the EFI reloc codeto work on arm64. This used the rela relocation table so wiill need the addend included in the relocation calculation. Sponsored by: The FreeBSD Foundation --- sys/boot/efi/loader/reloc.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sys/boot/efi/loader/reloc.c b/sys/boot/efi/loader/reloc.c index 0aa56b48ed63..fbe20431edf4 100644 --- a/sys/boot/efi/loader/reloc.c +++ b/sys/boot/efi/loader/reloc.c @@ -32,7 +32,12 @@ __FBSDID("$FreeBSD$"); #include #include -#if defined(__arm__) || defined(__i386__) +#if defined(__aarch64__) +#define ElfW_Rel Elf64_Rela +#define ElfW_Dyn Elf64_Dyn +#define ELFW_R_TYPE ELF64_R_TYPE +#define ELF_RELA +#elif defined(__arm__) || defined(__i386__) #define ElfW_Rel Elf32_Rel #define ElfW_Dyn Elf32_Dyn #define ELFW_R_TYPE ELF32_R_TYPE @@ -43,7 +48,10 @@ __FBSDID("$FreeBSD$"); #else #error architecture not supported #endif -#if defined(__amd64__) +#if defined(__aarch64__) +#define RELOC_TYPE_NONE R_AARCH64_NONE +#define RELOC_TYPE_RELATIVE R_AARCH64_RELATIVE +#elif defined(__amd64__) #define RELOC_TYPE_NONE R_X86_64_NONE #define RELOC_TYPE_RELATIVE R_X86_64_RELATIVE #elif defined(__arm__) @@ -104,6 +112,10 @@ _reloc(unsigned long ImageBase, ElfW_Dyn *dynamic, EFI_HANDLE image_handle, /* Address relative to the base address. */ newaddr = (unsigned long *)(ImageBase + rel->r_offset); *newaddr += ImageBase; + /* Add the addend when the ABI uses them */ +#ifdef ELF_RELA + *newaddr += rel->r_addend; +#endif break; default: /* XXX: do we need other relocations ? */