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/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/time.h>
#include <netdb.h>
#endif
#if !defined(WIN32)

View File

@ -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.

View File

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

View File

@ -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;

View File

@ -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));
}