VM: merge the compute_dlsym_toc_address() with the

compute_dlsym_address() method

it makes the code slightly more cluttered but you get rid of a lot of
special casing for the ppc platform
db4
Björn Lindqvist 2015-08-18 09:47:11 +02:00 committed by John Benediktsson
parent a53d5be683
commit 4efef7bfd9
3 changed files with 31 additions and 73 deletions

View File

@ -142,74 +142,44 @@ void factor_vm::update_word_references(code_block* compiled,
} }
} }
/* Look up an external library symbol referenced by a compiled code block */ /* Look up an external library symbol referenced by a compiled code
cell factor_vm::compute_dlsym_address(array* parameters, cell index) { block */
cell factor_vm::compute_dlsym_address(array* parameters,
cell index,
bool toc) {
cell symbol = array_nth(parameters, index); cell symbol = array_nth(parameters, index);
cell library = array_nth(parameters, index + 1); cell library = array_nth(parameters, index + 1);
dll* d = to_boolean(library) ? untag<dll>(library) : NULL;
dll* d = (to_boolean(library) ? untag<dll>(library) : NULL); cell undef = (cell)factor::undefined_symbol;
undef = toc ? FUNCTION_TOC_POINTER(undef) : FUNCTION_CODE_POINTER(undef);
cell undefined_symbol = (cell)factor::undefined_symbol;
undefined_symbol = FUNCTION_CODE_POINTER(undefined_symbol);
if (d != NULL && !d->handle) if (d != NULL && !d->handle)
return undefined_symbol; return undef;
switch (tagged<object>(symbol).type()) { cell type = TAG(symbol);
case BYTE_ARRAY_TYPE: { if (type == BYTE_ARRAY_TYPE) {
symbol_char* name = alien_offset(symbol);
cell sym = ffi_dlsym(d, name);
return sym ? sym : undefined_symbol;
}
case ARRAY_TYPE: {
array* names = untag<array>(symbol);
for (cell i = 0; i < array_capacity(names); i++) {
symbol_char* name = alien_offset(array_nth(names, i));
cell sym = ffi_dlsym(d, name);
if (sym) symbol_char* name = alien_offset(symbol);
return sym; cell sym = ffi_dlsym_raw(d, name);
} sym = toc ? FUNCTION_TOC_POINTER(sym) : FUNCTION_CODE_POINTER(sym);
return undefined_symbol; return sym ? sym : undef;
} else if (type == ARRAY_TYPE) {
array* names = untag<array>(symbol);
for (cell i = 0; i < array_capacity(names); i++) {
symbol_char* name = alien_offset(array_nth(names, i));
cell sym = ffi_dlsym_raw(d, name);
sym = toc ? FUNCTION_TOC_POINTER(sym) : FUNCTION_CODE_POINTER(sym);
if (sym)
return sym;
} }
default: return undef;
return -1;
} }
return -1;
} }
#ifdef FACTOR_PPC
cell factor_vm::compute_dlsym_toc_address(array* parameters, cell index) {
cell symbol = array_nth(parameters, index);
cell library = array_nth(parameters, index + 1);
dll* d = (to_boolean(library) ? untag<dll>(library) : NULL);
cell undefined_toc = (cell)factor::undefined_symbol;
undefined_toc = FUNCTION_TOC_POINTER(undefined_toc);
if (d != NULL && !d->handle)
return undefined_toc;
switch (tagged<object>(symbol).type()) {
case BYTE_ARRAY_TYPE: {
symbol_char* name = alien_offset(symbol);
cell toc = ffi_dlsym_toc(d, name);
return toc ? toc : undefined_toc;
}
case ARRAY_TYPE: {
array* names = untag<array>(symbol);
for (cell i = 0; i < array_capacity(names); i++) {
symbol_char* name = alien_offset(array_nth(names, i));
cell toc = ffi_dlsym_toc(d, name);
if (toc)
return toc;
}
return undefined_toc;
}
default:
return -1;
}
}
#endif
cell factor_vm::compute_vm_address(cell arg) { cell factor_vm::compute_vm_address(cell arg) {
return (cell)this + untag_fixnum(arg); return (cell)this + untag_fixnum(arg);
} }
@ -220,7 +190,7 @@ cell factor_vm::lookup_external_address(relocation_type rel_type,
cell index) { cell index) {
switch (rel_type) { switch (rel_type) {
case RT_DLSYM: case RT_DLSYM:
return compute_dlsym_address(parameters, index); return compute_dlsym_address(parameters, index, false);
case RT_THIS: case RT_THIS:
return compiled->entry_point(); return compiled->entry_point();
case RT_MEGAMORPHIC_CACHE_HITS: case RT_MEGAMORPHIC_CACHE_HITS:
@ -237,7 +207,7 @@ cell factor_vm::lookup_external_address(relocation_type rel_type,
#endif #endif
#ifdef FACTOR_PPC #ifdef FACTOR_PPC
case RT_DLSYM_TOC: case RT_DLSYM_TOC:
return compute_dlsym_toc_address(parameters, index); return compute_dlsym_address(parameters, index, true);
#endif #endif
case RT_INLINE_CACHE_MISS: case RT_INLINE_CACHE_MISS:
return (cell)&factor::inline_cache_miss; return (cell)&factor::inline_cache_miss;

View File

@ -47,12 +47,6 @@ cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
return FUNCTION_CODE_POINTER(ffi_dlsym_raw(dll, symbol)); return FUNCTION_CODE_POINTER(ffi_dlsym_raw(dll, symbol));
} }
#ifdef FACTOR_PPC
cell factor_vm::ffi_dlsym_toc(dll* dll, symbol_char* symbol) {
return FUNCTION_TOC_POINTER(ffi_dlsym_raw(dll, symbol));
}
#endif
void factor_vm::ffi_dlclose(dll* dll) { void factor_vm::ffi_dlclose(dll* dll) {
if (dlclose(dll->handle)) if (dlclose(dll->handle))
general_error(ERROR_FFI, false_object, false_object); general_error(ERROR_FFI, false_object, false_object);

View File

@ -576,10 +576,7 @@ struct factor_vm {
cell code_block_owner(code_block* compiled); cell code_block_owner(code_block* compiled);
void update_word_references(code_block* compiled, bool reset_inline_caches); void update_word_references(code_block* compiled, bool reset_inline_caches);
void undefined_symbol(); void undefined_symbol();
cell compute_dlsym_address(array* literals, cell index); cell compute_dlsym_address(array* literals, cell index, bool toc);
#ifdef FACTOR_PPC
cell compute_dlsym_toc_address(array* literals, cell index);
#endif
cell compute_vm_address(cell arg); cell compute_vm_address(cell arg);
cell lookup_external_address(relocation_type rel_type, cell lookup_external_address(relocation_type rel_type,
code_block* compiled, code_block* compiled,
@ -740,9 +737,6 @@ struct factor_vm {
void ffi_dlopen(dll* dll); void ffi_dlopen(dll* dll);
cell ffi_dlsym(dll* dll, symbol_char* symbol); cell ffi_dlsym(dll* dll, symbol_char* symbol);
cell ffi_dlsym_raw(dll* dll, symbol_char* symbol); cell ffi_dlsym_raw(dll* dll, symbol_char* symbol);
#ifdef FACTOR_PPC
cell ffi_dlsym_toc(dll* dll, symbol_char* symbol);
#endif
void ffi_dlclose(dll* dll); void ffi_dlclose(dll* dll);
void c_to_factor_toplevel(cell quot); void c_to_factor_toplevel(cell quot);
void init_signals(); void init_signals();