From: John Hodge Date: Thu, 20 Oct 2011 11:13:22 +0000 (+0800) Subject: Usermode/ld-acess - Fixed ARM relocations X-Git-Tag: rel0.13~24 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=27822fe0044a63eeab04efd76519b354f7ad3425;p=tpg%2Facess2.git Usermode/ld-acess - Fixed ARM relocations --- diff --git a/Usermode/Libraries/ld-acess.so_src/elf.c b/Usermode/Libraries/ld-acess.so_src/elf.c index 582c67ae..77dac9db 100644 --- a/Usermode/Libraries/ld-acess.so_src/elf.c +++ b/Usermode/Libraries/ld-acess.so_src/elf.c @@ -2,13 +2,13 @@ * AcessOS 1 - Dynamic Loader * By thePowersGang */ +#define DEBUG 0 + #include "common.h" #include #include "elf32.h" #include "elf64.h" -#define DEBUG 0 - #if DEBUG # define DEBUGS(v...) SysDebug("ld-acess - " v) #else @@ -100,7 +100,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) Elf32_Dyn *dynamicTab = NULL; // Dynamic Table Pointer char *dynstrtab = NULL; // .dynamic String Table Elf32_Sym *dynsymtab; - void (*do_relocate)(uint32_t t_info, uint32_t *ptr, Elf32_Addr addend, int Type, const char *Sym); + void (*do_relocate)(uint32_t t_info, uint32_t *ptr, Elf32_Addr addend, int Type, int bRela, const char *Sym); DEBUGS("ElfRelocate: (Base=0x%x)", Base); @@ -237,7 +237,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) DEBUGS(" elf_relocate: Beginning Relocation"); - void elf_doRelocate_386(uint32_t r_info, uint32_t *ptr, Elf32_Addr addend, int type, const char *Sym) + void elf_doRelocate_386(uint32_t r_info, uint32_t *ptr, Elf32_Addr addend, int type, int bRela, const char *Sym) { Uint32 val; switch( type ) @@ -278,7 +278,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) case R_386_COPY: { size_t size; void *src = GetSymbol(Sym, &size); - DEBUGS(" elf_doRelocate_386: R_386_COPY (%p, %p, %i)", ptr, val, size); + DEBUGS(" elf_doRelocate_386: R_386_COPY (%p, %p, %i)", ptr, src, size); memcpy(ptr, src, size); break; } @@ -288,14 +288,20 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) } } - void elf_doRelocate_arm(uint32_t r_info, uint32_t *ptr, Elf32_Addr addend, int type, const char *Sym) + void elf_doRelocate_arm(uint32_t r_info, uint32_t *ptr, Elf32_Addr addend, int type, int bRela, const char *Sym) { uint32_t val; switch(type) { // (S + A) | T case R_ARM_GLOB_DAT: + DEBUGS(" elf_doRelocate_arm: R_ARM_GLOB_DAT %p (%s + %x)", ptr, Sym, addend); + val = (intptr_t)GetSymbol(Sym, NULL); + *ptr = val + addend; + break; case R_ARM_JUMP_SLOT: + if(!bRela) addend = 0; + DEBUGS(" elf_doRelocate_arm: R_ARM_JUMP_SLOT %p (%s + %x)", ptr, Sym, addend); val = (intptr_t)GetSymbol(Sym, NULL); *ptr = val + addend; break; @@ -305,12 +311,12 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) } } - void _doRelocate(uint32_t r_info, uint32_t *ptr, Elf32_Addr addend) + void _doRelocate(uint32_t r_info, uint32_t *ptr, int bRela, Elf32_Addr addend) { int type = ELF32_R_TYPE(r_info); int sym = ELF32_R_SYM(r_info); const char *symname = dynstrtab + dynsymtab[sym].nameOfs; - do_relocate(r_info, ptr, addend, type, symname); + do_relocate(r_info, ptr, addend, type, bRela, symname); } switch(hdr->machine) @@ -336,7 +342,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) { //DEBUGS(" Rel %i: 0x%x+0x%x", i, iBaseDiff, rel[i].r_offset); ptr = (void*)(iBaseDiff + rel[i].r_offset); - _doRelocate(rel[i].r_info, ptr, *ptr); + _doRelocate(rel[i].r_info, ptr, 0, *ptr); } } // Parse Relocation Entries @@ -348,7 +354,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) for( i = 0; i < j; i++ ) { ptr = (void*)(iBaseDiff + rela[i].r_offset); - _doRelocate(rel[i].r_info, ptr, rela[i].r_addend); + _doRelocate(rel[i].r_info, ptr, 1, rela[i].r_addend); } } @@ -365,7 +371,7 @@ void *Elf32Relocate(void *Base, char **envp, const char *Filename) for(i=0;ientrypoint + iBaseDiff); + DEBUGS("ElfRelocate: RETURN 0x%x to %p", hdr->entrypoint + iBaseDiff, __builtin_return_address(0)); return (void*)(intptr_t)( hdr->entrypoint + iBaseDiff ); }