New PowerPC relocation type for dlsyms

cvs
Slava Pestov 2005-04-29 06:36:32 +00:00
parent e6f0d2e014
commit bcf605142b
5 changed files with 30 additions and 10 deletions

View File

@ -80,13 +80,9 @@ typedef signed long long s64;
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <netdb.h>
#endif #endif
#if !defined(WIN32) #if !defined(WIN32)

View File

@ -1,5 +1,13 @@
#include "factor.h" #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. /* Simple wrappers for ANSI C I/O functions, used for bootstrapping.
The Factor library provides platform-specific code for Unix and Windows The Factor library provides platform-specific code for Unix and Windows
with many more capabilities. with many more capabilities.

View File

@ -1,3 +1,4 @@
int factor_errno(void);
void init_c_io(void); void init_c_io(void);
void c_stream_error(void); void c_stream_error(void);
void primitive_fopen(void); void primitive_fopen(void);

View File

@ -101,20 +101,31 @@ void relocate_primitive(F_REL* rel, bool relative)
- (relative ? rel->offset + CELLS : 0)); - (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_CONS* cons = untag_cons(get(rel->argument));
F_STRING* symbol = untag_string(cons->car); F_STRING* symbol = untag_string(cons->car);
DLL* dll = (cons->cdr == F ? NULL : untag_dll(cons->cdr)); DLL* dll = (cons->cdr == F ? NULL : untag_dll(cons->cdr));
put(rel->offset,(CELL)ffi_dlsym(dll,symbol) return (CELL)ffi_dlsym(dll,symbol);
- (relative ? rel->offset + CELLS : 0));
} }
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) void relocate_primitive_16_16(F_REL* rel)
{ {
reloc_set_16_16((CELL*)rel->offset,primitive_to_xt(rel->argument)); 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) INLINE void code_fixup_16_16(CELL* cell)
{ {
CELL difference = (compiling.base - code_relocation_base); CELL difference = (compiling.base - code_relocation_base);
@ -166,6 +177,10 @@ INLINE CELL relocate_code_next(CELL relocating)
case F_ABSOLUTE_PRIMITIVE_16_16: case F_ABSOLUTE_PRIMITIVE_16_16:
relocate_primitive_16_16(rel); relocate_primitive_16_16(rel);
break; break;
case F_ABSOLUTE_DLSYM_16_16:
code_fixup(&rel->argument);
relocate_dlsym_16_16(rel);
break;
case F_ABSOLUTE_16_16: case F_ABSOLUTE_16_16:
code_fixup_16_16((CELL*)rel->offset); code_fixup_16_16((CELL*)rel->offset);
break; break;
@ -187,7 +202,6 @@ void relocate_code()
for(;;) for(;;)
{ {
/* fprintf(stderr,"relocation %d %d\n",relocating,compiling.here); */
if(relocating >= compiling.here) if(relocating >= compiling.here)
break; break;

View File

@ -20,6 +20,7 @@ typedef enum {
/* PowerPC absolute address in the low 16 bits of two consecutive /* PowerPC absolute address in the low 16 bits of two consecutive
32-bit words */ 32-bit words */
F_ABSOLUTE_PRIMITIVE_16_16, F_ABSOLUTE_PRIMITIVE_16_16,
F_ABSOLUTE_DLSYM_16_16,
F_ABSOLUTE_16_16 F_ABSOLUTE_16_16
} F_RELTYPE; } F_RELTYPE;
@ -49,6 +50,6 @@ INLINE CELL reloc_get_16_16(CELL* cell)
INLINE void reloc_set_16_16(CELL* cell, CELL value) INLINE void reloc_set_16_16(CELL* cell, CELL value)
{ {
*cell = ((*cell & ~0xffff) | (value & 0xffff)); *cell = ((*cell & ~0xffff) | ((value >> 16) & 0xffff));
*(cell - 1) = ((*(cell - 1) & ~0xffff) | ((value >> 16) & 0xffff)); *(cell + 1) = ((*(cell + 1) & ~0xffff) | (value & 0xffff));
} }