From 90907c35ac51e760221470563fdcd90a9232cc51 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Tue, 3 Jul 2012 08:45:35 +0100 Subject: [PATCH] Moved ELF64 relocation functions to x86 arch_elf.cpp. --- src/system/boot/arch/x86/Jamfile | 7 -- src/system/boot/arch/x86/arch_elf64.cpp | 1 - src/system/kernel/arch/x86/arch_elf.cpp | 95 +++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 8 deletions(-) delete mode 100644 src/system/boot/arch/x86/arch_elf64.cpp diff --git a/src/system/boot/arch/x86/Jamfile b/src/system/boot/arch/x86/Jamfile index 1ef6a979c5..f373212aa7 100644 --- a/src/system/boot/arch/x86/Jamfile +++ b/src/system/boot/arch/x86/Jamfile @@ -2,10 +2,6 @@ SubDir HAIKU_TOP src system boot arch x86 ; DEFINES += _BOOT_MODE ; -local bootArchSources = - arch_elf64.cpp -; - local kernelArchSources = arch_elf.cpp cpuid.S @@ -20,15 +16,12 @@ local librootOsArchSources = ; BootMergeObject boot_arch_$(TARGET_KERNEL_ARCH).o : - $(bootArchSources) $(kernelArchSources) $(kernelLibArchSources) $(librootOsArchSources) : # additional flags ; -SEARCH on [ FGristFiles $(bootArchSources) ] - = [ FDirName $(HAIKU_TOP) src system boot arch x86 ] ; SEARCH on [ FGristFiles $(kernelArchSources) ] = [ FDirName $(HAIKU_TOP) src system kernel arch x86 ] ; SEARCH on [ FGristFiles $(kernelLibArchSources) ] diff --git a/src/system/boot/arch/x86/arch_elf64.cpp b/src/system/boot/arch/x86/arch_elf64.cpp deleted file mode 100644 index 41e0198ea1..0000000000 --- a/src/system/boot/arch/x86/arch_elf64.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "../../../kernel/arch/x86_64/arch_elf.cpp" diff --git a/src/system/kernel/arch/x86/arch_elf.cpp b/src/system/kernel/arch/x86/arch_elf.cpp index 20570527d0..951a33dde5 100644 --- a/src/system/kernel/arch/x86/arch_elf.cpp +++ b/src/system/kernel/arch/x86/arch_elf.cpp @@ -25,6 +25,9 @@ #endif +#if !defined(__x86_64__) || defined(_BOOT_MODE) + + #ifdef TRACE_ARCH_ELF static const char *kRelocations[] = { "R_386_NONE", @@ -178,3 +181,95 @@ arch_elf_relocate_rela(struct elf_image_info *image, dprintf("arch_elf_relocate_rela: not supported on x86\n"); return B_ERROR; } + + +#endif // !__x86_64__ || _BOOT_MODE + + +//#if defined(__x86_64__) || defined(_BOOT_MODE) +#ifdef _BOOT_MODE + + +#ifdef _BOOT_MODE +status_t +boot_arch_elf_relocate_rel(preloaded_elf64_image* image, Elf64_Rel* rel, + int relLength) +//#else +//int +//arch_elf_relocate_rel(struct elf_image_info *image, +// struct elf_image_info *resolveImage, struct Elf32_Rel *rel, int relLength) +//#endif +{ + dprintf("arch_elf_relocate_rel: not supported on x86_64\n"); + return B_ERROR; +} + + +//#ifdef _BOOT_MODE +status_t +boot_arch_elf_relocate_rela(preloaded_elf64_image* image, Elf64_Rela* rel, + int relLength) +//#else +//int +//arch_elf_relocate_rela(struct elf_image_info *image, +// struct elf_image_info *resolveImage, struct Elf32_Rela *rel, int relLength) +//#endif +{ + for (int i = 0; i < relLength / (int)sizeof(Elf64_Rela); i++) { + int type = ELF64_R_TYPE(rel[i].r_info); + int symIndex = ELF64_R_SYM(rel[i].r_info); + Elf64_Addr symAddr = 0; + + // Resolve the symbol, if any. + if (symIndex != 0) { + Elf64_Sym* symbol = SYMBOL(image, symIndex); + + status_t status; +//#ifdef _BOOT_MODE + status = boot_elf_resolve_symbol(image, symbol, &symAddr); +//#else +// status = elf_resolve_symbol(image, symbol, resolveImage, &S); +//#endif + if (status < B_OK) + return status; + } + + // Address of the relocation. + Elf64_Addr relocAddr = image->text_region.delta + rel[i].r_offset; + + // Calculate the relocation value. + Elf64_Addr relocValue; + switch(type) { + case R_X86_64_NONE: + continue; + case R_X86_64_64: + relocValue = symAddr + rel[i].r_addend; + break; + case R_X86_64_PC32: + relocValue = symAddr + rel[i].r_addend - rel[i].r_offset; + break; + case R_X86_64_GLOB_DAT: + case R_X86_64_JUMP_SLOT: + relocValue = symAddr + rel[i].r_addend; + break; + case R_X86_64_RELATIVE: + relocValue = image->text_region.delta + rel[i].r_addend; + break; + default: + dprintf("arch_elf_relocate_rel: unhandled relocation type %d\n", + type); + return B_BAD_DATA; + } +#ifdef _BOOT_MODE + boot_elf64_set_relocation(relocAddr, relocValue); +#else + *(Elf64_Addr *)relocAddr = relocValue; +#endif + } + + return B_OK; +} +#endif + + +#endif // __x86_64__ || _BOOT_MODE