From: John Hodge Date: Thu, 14 Jun 2012 08:46:19 +0000 (+0800) Subject: Common/ELF Loader - Debug fixes and detection for no-relocated binaries X-Git-Tag: rel0.15~611^2~58 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=700d4228ad14b3a7406eefc9a58735748c254d42;p=tpg%2Facess2.git Common/ELF Loader - Debug fixes and detection for no-relocated binaries --- diff --git a/KernelLand/Kernel/bin/elf.c b/KernelLand/Kernel/bin/elf.c index 16da915e..41e09820 100644 --- a/KernelLand/Kernel/bin/elf.c +++ b/KernelLand/Kernel/bin/elf.c @@ -7,7 +7,7 @@ #include #define _COMMON_H -#define SysDebug(...) LOG(v) +#define SysDebug(v...) LOG(v) #define DISABLE_ELF64 void *GetSymbol(const char *Name, size_t *Size); void *GetSymbol(const char *Name, size_t *Size) { Uint val; Binary_GetSymbol(Name, &val); if(Size)*Size=0; return (void*)val; }; diff --git a/Usermode/Libraries/ld-acess.so_src/elf.c b/Usermode/Libraries/ld-acess.so_src/elf.c index bbe45d62..92237eaa 100644 --- a/Usermode/Libraries/ld-acess.so_src/elf.c +++ b/Usermode/Libraries/ld-acess.so_src/elf.c @@ -5,7 +5,9 @@ * elf.c * - ELF32/ELF64 relocation */ -#define DEBUG 0 +#ifndef DEBUG // This code is #include'd from the kernel, so DEBUG may already be defined +# define DEBUG 0 +#endif #include "common.h" #include @@ -481,11 +483,20 @@ int Elf32GetSymbol(void *Base, const char *Name, void **ret, size_t *Size) return 0; } + // ... ok... maybe they haven't been relocated + if( (uintptr_t)symtab < (uintptr_t)Base ) + { + symtab = (void*)( (uintptr_t)symtab + iBaseDiff ); + pBuckets = (void*)( (uintptr_t)pBuckets + iBaseDiff ); + dynstrtab = (void*)( (uintptr_t)dynstrtab + iBaseDiff ); + SysDebug("Executable not yet relocated"); + } + nbuckets = pBuckets[0]; // iSymCount = pBuckets[1]; pBuckets = &pBuckets[2]; pChains = &pBuckets[ nbuckets ]; - + // Get hash iNameHash = ElfHashString(Name); iNameHash %= nbuckets;