ld-acess - Fixed bugs due to not testing from AcessNative changes
authorJohn Hodge <[email protected]>
Tue, 25 Jan 2011 13:39:59 +0000 (21:39 +0800)
committerJohn Hodge <[email protected]>
Tue, 25 Jan 2011 13:39:59 +0000 (21:39 +0800)
- Possibly some edge cases left in if someone tries to link against
  libld-acess.so or ld-acess.so and the name does not match the
  hard coded value.

Usermode/Libraries/Makefile.tpl
Usermode/Libraries/ld-acess.so_src/Makefile
Usermode/Libraries/ld-acess.so_src/common.h
Usermode/Libraries/ld-acess.so_src/elf.c
Usermode/Libraries/ld-acess.so_src/export.c [new file with mode: 0644]
Usermode/Libraries/ld-acess.so_src/link.ld
Usermode/Libraries/ld-acess.so_src/loadlib.c
Usermode/Libraries/ld-acess.so_src/main.c

index 9712bf8..51e404d 100644 (file)
@@ -5,16 +5,17 @@
 DEPFILES := $(addsuffix .d,$(OBJ))
 
 _BIN := $(OUTPUTDIR)Libs/$(BIN)
+_XBIN := $(addprefix $(OUTPUTDIR)Libs/,$(EXTRABIN))
 
 .PHONY: all clean install postbuild
 
-all: $(_BIN) postbuild
+all: $(_BIN) $(_XBIN)
 
 clean:
-       $(RM) $(_BIN) $(OBJ) $(_BIN).dsm $(DEPFILES)
+       $(RM) $(_BIN) $(_XBIN) $(OBJ) $(_BIN).dsm $(DEPFILES)
 
 install: all
-       $(xCP) $(_BIN) $(DISTROOT)/Libs/
+       $(xCP) $(_BIN) $(_XBIN) $(DISTROOT)/Libs/
 
 $(_BIN): $(OBJ)
        @mkdir -p $(dir $(_BIN))
index 3c02d3d..668460a 100644 (file)
@@ -4,18 +4,19 @@
 
 -include ../Makefile.cfg
 
-OBJ := main.o lib.o loadlib.o elf.o pe.o
+OBJ := main.o lib.o loadlib.o export.o elf.o pe.o
 OBJ += core.ao vfs.ao mm.ao
 BIN = ld-acess.so
+EXTRABIN := libld-acess.so
 
 CFLAGS   = -Wall -fno-builtin -fno-leading-underscore -fno-stack-protector
+CFLAGS  += $(CPPFLAGS)
 ASFLAGS  = -felf
-LDFLAGS  = -T link.ld -Map map.txt -Bstatic -shared
+LDFLAGS  = -T link.ld -Map map.txt --export-dynamic
 
 include ../Makefile.tpl
 
-postbuild: $(OUTPUTDIR)Libs/libld-acess.so
-
-$(OUTPUTDIR)Libs/libld-acess.so:
-       ln -s $(_BIN) $(OUTPUTDIR)Libs/libld-acess.so
+$(_XBIN): $(_BIN)
+       @echo [LD] -o -shared libld-acess.so
+       @$(LD) $(LDFLAGS) -shared -o $@ $(OBJ)
 
index 3356a27..fad0344 100644 (file)
@@ -54,12 +54,12 @@ extern int  file_exists(char *filename);
 
 // === System Calls ===
 extern void    _exit(int retval);
-extern void    SysDebug(char *fmt, ...);       //!< Now implemented in main.c
-extern void    SysDebugV(char *fmt, ...);
-extern Uint    SysLoadBin(char *path, Uint *entry);
+extern void    SysDebug(const char *fmt, ...); //!< Now implemented in main.c
+extern void    SysDebugV(const char *fmt, ...);
+extern Uint    SysLoadBin(const char *path, Uint *entry);
 extern Uint    SysUnloadBin(Uint Base);
 extern void    SysSetFaultHandler(int (*Hanlder)(int));
-extern int     open(char *filename, int flags);
+extern int     open(const char *filename, int flags);
 extern void    close(int fd);
 
 // === ELF Loader ===
index e1fcd2d..dcde746 100644 (file)
@@ -315,6 +315,49 @@ int ElfGetSymbol(Uint Base, char *Name, Uint *ret)
 \r
        //DEBUGS("ElfGetSymbol: (Base=0x%x, Name='%s')\n", Base, Name);\r
 \r
+       // Catch the current executable\r
+       #if 0\r
+       if( !hdr->misc.HashTable )\r
+       {\r
+               Elf32_Phdr      *phtab;\r
+               Elf32_Dyn       *dynTab = NULL;\r
+                int    j;\r
+               \r
+               // Locate the tables\r
+               phtab = (void*)( Base + hdr->phoff );\r
+               for( i = 0; i < hdr->phentcount; i ++ )\r
+               {\r
+                       if( phtab[i].Type == PT_DYNAMIC ) {\r
+                               dynTab = (void*)phtab[i].VAddr;\r
+                               break ;\r
+                       }\r
+               }\r
+               if( !dynTab ) {\r
+                       SysDebug("ERROR - Unable to find DYNAMIC segment in %p", (void*)Base);\r
+                       return 0;\r
+               }\r
+               \r
+               for( j = 0; dynTab[j].d_tag != DT_NULL; j++)\r
+               {\r
+                       switch(dynTab[j].d_tag)\r
+                       {\r
+                       // --- Symbol Table ---\r
+                       case DT_SYMTAB:\r
+                               hdr->misc.SymTable = dynTab[j].d_val;\r
+                               break;\r
+                       // --- Hash Table --\r
+                       case DT_HASH:\r
+                               hdr->misc.HashTable = dynTab[j].d_val;\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       #endif\r
+       \r
+       if( !hdr->misc.SymTable || !hdr->misc.HashTable ) {\r
+               return 0;\r
+       }\r
+\r
        pBuckets = (void *) hdr->misc.HashTable;\r
        symtab = (void *) hdr->misc.SymTable;\r
        
diff --git a/Usermode/Libraries/ld-acess.so_src/export.c b/Usermode/Libraries/ld-acess.so_src/export.c
new file mode 100644 (file)
index 0000000..867e17f
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Acess2 Dynamic Linker
+ */
+#include "common.h"
+#include <acess/sys.h>
+
+#define _STR(x)        #x
+#define STR(x) _STR(x)
+#define EXP(sym)       {(Uint)&sym, STR(sym)}
+
+// === CONSTANTS ===
+const struct {
+       Uint    Value;
+       char    *Name;
+}      caLocalExports[] = {
+       EXP(gLoadedLibraries),
+       EXP(_exit),
+       EXP(clone),
+       EXP(kill),
+       EXP(yield),
+       EXP(sleep),
+       EXP(waittid),
+       EXP(gettid),
+       EXP(getpid),
+       EXP(getuid),
+       EXP(getgid),
+
+       EXP(setuid),
+       EXP(setgid),
+
+       EXP(SysSetName),
+       //EXP(SysGetName),
+
+       //EXP(SysSetPri),
+
+       EXP(SysSendMessage),
+       EXP(SysGetMessage),
+
+       //EXP(SysSpawn),
+       EXP(execve),
+       EXP(SysLoadBin),
+       EXP(SysUnloadBin),
+
+       EXP(_SysSetFaultHandler),
+       
+       EXP(open),
+       EXP(reopen),
+       EXP(close),
+       EXP(read),
+       EXP(write),
+       EXP(seek),
+       EXP(tell),
+       EXP(finfo),
+       EXP(readdir),
+       EXP(_SysGetACL),
+       EXP(chdir),
+       EXP(ioctl),
+       EXP(_SysMount),
+
+       EXP(_SysOpenChild),
+       
+       EXP(_SysGetPhys),
+       EXP(_SysAllocate)
+
+};
+
+const int      ciNumLocalExports = sizeof(caLocalExports)/sizeof(caLocalExports[0]);
index c318850..3ab4f1a 100644 (file)
@@ -4,6 +4,45 @@ OUTPUT_FORMAT(elf32-i386)
 SECTIONS {
     . = 0xBBFF0000;
     gLinkedBase = .;
+       . += SIZEOF_HEADERS;
+       .interp         : { *(.interp) }
+       .note.gnu.build-id : { *(.note.gnu.build-id) }
+       .hash           : { *(.hash) }
+       .gnu.hash       : { *(.gnu.hash) }
+       .dynsym         : { *(.dynsym) }
+       .dynstr         : { *(.dynstr) }
+       .gnu.version    : { *(.gnu.version) }
+       .gnu.version_d  : { *(.gnu.version_d) }
+       .gnu.version_r  : { *(.gnu.version_r) }
+       .rel.dyn        :
+       {
+               *(.rel.init)
+               *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
+               *(.rel.fini)
+               *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
+               *(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)
+               *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
+               *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
+               *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
+               *(.rel.ctors)
+               *(.rel.dtors)
+               *(.rel.got)
+               *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
+       }
+       .rela.dyn       :
+       {
+               *(.rela.init)
+               *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
+               *(.rela.fini)
+               *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
+               *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
+               *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
+               *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
+               *(.rela.ctors)
+               *(.rela.dtors)
+               *(.rela.got)
+               *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
+       }
 
    .text : AT(ADDR(.text)) {
         code = .;
index e5090dd..a5f0bc2 100644 (file)
 Uint   IsFileLoaded(char *file);
  int   GetSymbolFromBase(Uint base, char *name, Uint *ret);
 
-// === CONSTANTS ===
-const struct {
+// === IMPORTS ===
+extern const struct {
        Uint    Value;
        char    *Name;
-}      caLocalExports[] = {
-       {(Uint)gLoadedLibraries, "gLoadedLibraries"}
-};
+}      caLocalExports[];
+extern const int       ciNumLocalExports;
 
 // === GLOABLS ===
 tLoadedLib     gLoadedLibraries[MAX_LOADED_LIBRARIES];
@@ -200,7 +199,9 @@ Uint GetSymbol(char *name)
 {
         int    i;
        Uint    ret;
-       for(i=0;i<sizeof(caLocalExports)/sizeof(caLocalExports[0]);i++)
+       
+       //SysDebug("ciNumLocalExports = %i", ciNumLocalExports);
+       for(i=0;i<ciNumLocalExports;i++)
        {
                if( strcmp(caLocalExports[i].Name, name) == 0 )
                        return caLocalExports[i].Value;
@@ -210,11 +211,11 @@ Uint GetSymbol(char *name)
        {
                if(gLoadedLibraries[i].Base == 0)       break;
                
-               //SysDebug(" GetSymbol: Trying 0x%x, '%s'\n",
+               //SysDebug(" GetSymbol: Trying 0x%x, '%s'",
                //      gLoadedLibraries[i].Base, gLoadedLibraries[i].Name);
                if(GetSymbolFromBase(gLoadedLibraries[i].Base, name, &ret))     return ret;
        }
-       SysDebug("GetSymbol: === Symbol '%s' not found ===\n", name);
+       SysDebug("GetSymbol: === Symbol '%s' not found ===", name);
        return 0;
 }
 
@@ -228,6 +229,7 @@ int GetSymbolFromBase(Uint base, char *name, Uint *ret)
                return ElfGetSymbol(base, name, ret);
        if(*(Uint16*)base == ('M'|('Z'<<8)))
                return PE_GetSymbol(base, name, ret);
+       SysDebug("Unknown type at %p", base);
        return 0;
 }
 
index 4f2ef88..85fbc74 100644 (file)
@@ -38,7 +38,7 @@ int SoMain(Uint base, int arg1)
        }\r
 \r
        gLoadedLibraries[0].Base = (Uint)&gLinkedBase;\r
-       gLoadedLibraries[0].Name = "ld-acess.so";\r
+       gLoadedLibraries[0].Name = "/Acess/Libs/libld-acess.so";\r
        \r
        // Otherwise do relocations\r
        //ret = DoRelocate( base, envp, "Executable" );\r

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