Moved ELF64 relocation functions to x86 arch_elf.cpp.
This commit is contained in:
@@ -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) ]
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "../../../kernel/arch/x86_64/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
|
||||
|
||||
Reference in New Issue
Block a user