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))
-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)
// === 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 ===
\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
--- /dev/null
+/*
+ * 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]);
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 = .;
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];
{
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;
{
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;
}
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;
}
}\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