From bcf605142bc91b8e5b625e772194fdee64e21999 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 29 Apr 2005 06:36:32 +0000 Subject: [PATCH] New PowerPC relocation type for dlsyms --- native/factor.h | 4 ---- native/io.c | 8 ++++++++ native/io.h | 1 + native/relocate.c | 22 ++++++++++++++++++---- native/relocate.h | 5 +++-- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/native/factor.h b/native/factor.h index b210473353..e20a326fb5 100644 --- a/native/factor.h +++ b/native/factor.h @@ -80,13 +80,9 @@ typedef signed long long s64; #include #include #include - #include #include - #include - #include #include #include - #include #endif #if !defined(WIN32) diff --git a/native/io.c b/native/io.c index b4791726e4..cbe19d0caa 100644 --- a/native/io.c +++ b/native/io.c @@ -1,5 +1,13 @@ #include "factor.h" +/* This function is used by FFI I/O. Accessing the errno global is +too troublesome... on some libc's its a funky macro that reads +thread-local storage. */ +int factor_errno(void) +{ + return errno; +} + /* Simple wrappers for ANSI C I/O functions, used for bootstrapping. The Factor library provides platform-specific code for Unix and Windows with many more capabilities. diff --git a/native/io.h b/native/io.h index 8ae5741c45..8212532b1f 100644 --- a/native/io.h +++ b/native/io.h @@ -1,3 +1,4 @@ +int factor_errno(void); void init_c_io(void); void c_stream_error(void); void primitive_fopen(void); diff --git a/native/relocate.c b/native/relocate.c index 82410694c6..ef65a1ae89 100644 --- a/native/relocate.c +++ b/native/relocate.c @@ -101,20 +101,31 @@ void relocate_primitive(F_REL* rel, bool relative) - (relative ? rel->offset + CELLS : 0)); } -void relocate_dlsym(F_REL* rel, bool relative) +CELL get_rel_symbol(F_REL* rel) { F_CONS* cons = untag_cons(get(rel->argument)); F_STRING* symbol = untag_string(cons->car); DLL* dll = (cons->cdr == F ? NULL : untag_dll(cons->cdr)); - put(rel->offset,(CELL)ffi_dlsym(dll,symbol) - - (relative ? rel->offset + CELLS : 0)); + return (CELL)ffi_dlsym(dll,symbol); } +void relocate_dlsym(F_REL* rel, bool relative) +{ + CELL addr = get_rel_symbol(rel); + put(rel->offset,addr - (relative ? rel->offset + CELLS : 0)); +} + +/* PowerPC-specific relocations */ void relocate_primitive_16_16(F_REL* rel) { reloc_set_16_16((CELL*)rel->offset,primitive_to_xt(rel->argument)); } +void relocate_dlsym_16_16(F_REL* rel) +{ + reloc_set_16_16((CELL*)rel->offset,get_rel_symbol(rel)); +} + INLINE void code_fixup_16_16(CELL* cell) { CELL difference = (compiling.base - code_relocation_base); @@ -166,6 +177,10 @@ INLINE CELL relocate_code_next(CELL relocating) case F_ABSOLUTE_PRIMITIVE_16_16: relocate_primitive_16_16(rel); break; + case F_ABSOLUTE_DLSYM_16_16: + code_fixup(&rel->argument); + relocate_dlsym_16_16(rel); + break; case F_ABSOLUTE_16_16: code_fixup_16_16((CELL*)rel->offset); break; @@ -187,7 +202,6 @@ void relocate_code() for(;;) { - /* fprintf(stderr,"relocation %d %d\n",relocating,compiling.here); */ if(relocating >= compiling.here) break; diff --git a/native/relocate.h b/native/relocate.h index be32e4ee75..e661a1c94c 100644 --- a/native/relocate.h +++ b/native/relocate.h @@ -20,6 +20,7 @@ typedef enum { /* PowerPC absolute address in the low 16 bits of two consecutive 32-bit words */ F_ABSOLUTE_PRIMITIVE_16_16, + F_ABSOLUTE_DLSYM_16_16, F_ABSOLUTE_16_16 } F_RELTYPE; @@ -49,6 +50,6 @@ INLINE CELL reloc_get_16_16(CELL* cell) INLINE void reloc_set_16_16(CELL* cell, CELL value) { - *cell = ((*cell & ~0xffff) | (value & 0xffff)); - *(cell - 1) = ((*(cell - 1) & ~0xffff) | ((value >> 16) & 0xffff)); + *cell = ((*cell & ~0xffff) | ((value >> 16) & 0xffff)); + *(cell + 1) = ((*(cell + 1) & ~0xffff) | (value & 0xffff)); }