Common/ELF Loader - Debug fixes and detection for no-relocated binaries
authorJohn Hodge <[email protected]>
Thu, 14 Jun 2012 08:46:19 +0000 (16:46 +0800)
committerJohn Hodge <[email protected]>
Thu, 14 Jun 2012 08:46:19 +0000 (16:46 +0800)
KernelLand/Kernel/bin/elf.c
Usermode/Libraries/ld-acess.so_src/elf.c

index 16da915..41e0982 100644 (file)
@@ -7,7 +7,7 @@
 #include <binary.h>\r
 \r
 #define _COMMON_H\r
-#define SysDebug(...)  LOG(v)\r
+#define SysDebug(v...) LOG(v)\r
 #define DISABLE_ELF64\r
 void   *GetSymbol(const char *Name, size_t *Size);\r
 void   *GetSymbol(const char *Name, size_t *Size) { Uint val; Binary_GetSymbol(Name, &val); if(Size)*Size=0; return (void*)val; };\r
index bbe45d6..92237ea 100644 (file)
@@ -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 <stdint.h>
@@ -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;

UCC git Repository :: git.ucc.asn.au