Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ LLVM_TAR=llvm-$(LLVM_VER).tar.gz
else
LLVM_TAR=llvm-$(LLVM_VER).src.tar.gz
endif
endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change doesn't seem necessary / related

ifeq ($(BUILD_LLVM_CLANG),1)
ifeq ($(LLVM_VER), 3.0)
Expand All @@ -202,6 +201,7 @@ LLVM_CLANG_TAR=
LLVM_COMPILER_RT_TAR=
LLVM_LIBCXX_TAR=
endif
endif

LLVM_TARGET_FLAGS= --enable-targets=host
LLVM_FLAGS = --disable-profiling --enable-shared --enable-static $(LLVM_TARGET_FLAGS) --disable-bindings --disable-docs
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FLAGS = \
-I$(call exec,$(LLVM_CONFIG) --includedir) \
-I$(LIBUV_INC) -I$(JULIAHOME)/usr/include -DLIBRARY_EXPORTS

LLVMLINK = $(call exec,$(LLVM_CONFIG) --libs)
LLVMLINK = $(call exec,$(LLVM_CONFIG) --libs) $(call exec,$(LLVM_CONFIG) --system-libs 2> /dev/null)
ifeq ($(USE_LLVM_SHLIB),1)
LLVMLINK = -lLLVM-$(LLVM_VER)
endif
Expand Down
54 changes: 39 additions & 15 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,19 @@ static Value *runtime_sym_lookup(PointerType *funcptype, char *f_lib, char *f_na
bool runtime_lib = false;
GlobalVariable *libptrgv;
#ifdef _OS_WINDOWS_
if ((intptr_t)f_lib == 1)
libptrgv = jlexe_var;
else if ((intptr_t)f_lib == 2)
libptrgv = jldll_var;
if ((intptr_t)f_lib == 1) {
libptrgv = prepare_global(jlexe_var);
libsym = jl_exe_handle;
}
else if ((intptr_t)f_lib == 2) {
libptrgv = prepare_global(jldll_var);
libsym = jl_dll_handle;
}
else
#endif
if (f_lib == NULL) {
libptrgv = jlRTLD_DEFAULT_var;
libptrgv = prepare_global(jlRTLD_DEFAULT_var);
libsym = jl_RTLD_DEFAULT_handle;
}
else {
runtime_lib = true;
Expand All @@ -142,20 +147,39 @@ static Value *runtime_sym_lookup(PointerType *funcptype, char *f_lib, char *f_na
initnul, f_lib);
libMapGV[f_lib] = libptrgv;
libsym = get_library(f_lib);
assert(libsym != NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible that libsym is NULL here (if the library wasn't found). the existing code shouldn't have had a problem with it

#ifdef USE_MCJIT
llvm_to_jl_value[libptrgv] = libsym;
#else
*((uv_lib_t**)jl_ExecutionEngine->getPointerToGlobal(libptrgv)) = libsym;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are using a shadow module, can't you just leave everything uninitialized? (here, at worst, it would incur a second runtime lookup)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind

#endif
}
}
if (libsym == NULL) {
#ifdef USE_MCJIT
libsym = (uv_lib_t*)llvm_to_jl_value[libptrgv];
#else
libsym = *((uv_lib_t**)jl_ExecutionEngine->getPointerToGlobal(libptrgv));
#endif
}

assert(libsym != NULL);

GlobalVariable *llvmgv = symMapGV[f_name];
if (llvmgv == NULL) {
// MCJIT forces this to have external linkage eventually, so we would clobber
// the symbol of the actual function.
std::string name = f_name;
name = "ccall_" + name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's getting external linkage, it should probably have a name like jl_ccall_ or julia_ccall_. I though I heard somewhere that linkers used to be faster if the names were unique in the first few characters -- so maybe it should be jl_<f_name>_ccall?

llvmgv = new GlobalVariable(*jl_Module, T_pint8,
false, GlobalVariable::PrivateLinkage,
initnul, f_name);
initnul, name);
symMapGV[f_name] = llvmgv;
#ifdef USE_MCJIT
llvm_to_jl_value[llvmgv] = jl_dlsym_e(libsym, f_name);
#else
*((void**)jl_ExecutionEngine->getPointerToGlobal(llvmgv)) = jl_dlsym_e(libsym, f_name);
#endif
}

BasicBlock *dlsym_lookup = BasicBlock::Create(getGlobalContext(), "dlsym"),
Expand All @@ -171,7 +195,7 @@ static Value *runtime_sym_lookup(PointerType *funcptype, char *f_lib, char *f_na
else {
libname = literal_static_pointer_val(f_lib, T_pint8);
}
Value *llvmf = builder.CreateCall3(jldlsym_func, libname, builder.CreateGlobalStringPtr(f_name), libptrgv);
Value *llvmf = builder.CreateCall3(prepare_call(jldlsym_func), libname, builder.CreateGlobalStringPtr(f_name), libptrgv);
builder.CreateStore(llvmf, llvmgv);
builder.CreateBr(ccall_bb);

Expand Down Expand Up @@ -354,7 +378,7 @@ static Value *julia_to_native(Type *ty, jl_value_t *jt, Value *jv,
return builder.CreateBitCast(emit_nthptr_addr(jv, (size_t)1), ty); // skip type tag field
}
*mightNeedTempSpace = true;
Value *p = builder.CreateCall4(value_to_pointer_func,
Value *p = builder.CreateCall4(prepare_call(value_to_pointer_func),
literal_pointer_val(jl_tparam0(jt)), jv,
ConstantInt::get(T_int32, argn),
ConstantInt::get(T_int32, (int)addressOf));
Expand Down Expand Up @@ -758,10 +782,10 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
msg << f_lib;
}
msg << "\n";
builder.CreateCall2(jlputs_func,
builder.CreateCall2(prepare_call(jlputs_func),
builder.CreateGEP(stringConst(msg.str()),
ArrayRef<Value*>(zeros)),
jlstderr_var);
prepare_global(jlstderr_var));
}

// emit arguments
Expand All @@ -770,7 +794,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
if (sret) {
assert(jl_is_structtype(rt));
result = builder.CreateCall(
jlallocobj_func,
prepare_call(jlallocobj_func),
ConstantInt::get(T_size,
sizeof(void*)+((jl_datatype_t*)rt)->size));
//TODO: Fill type pointer fields with C_NULL's
Expand Down Expand Up @@ -894,7 +918,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
if (needTempSpace) {
// save temp argument area stack pointer
// TODO: inline this
saveloc = CallInst::Create(save_arg_area_loc_func);
saveloc = CallInst::Create(prepare_call(save_arg_area_loc_func));
if (savespot)
instList.insertAfter(savespot, (Instruction*)saveloc);
else
Expand All @@ -912,7 +936,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)

// the actual call
Value *ret = builder.CreateCall(
llvmf,
prepare_call(llvmf),
ArrayRef<Value*>(&argvals[0],(nargs-3)/2+sret));

attr_type attributes;
Expand Down Expand Up @@ -944,7 +968,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
if (needTempSpace) {
// restore temp argument area stack pointer
assert(saveloc != NULL);
builder.CreateCall(restore_arg_area_loc_func, saveloc);
builder.CreateCall(prepare_call(restore_arg_area_loc_func), saveloc);
}
ctx->argDepth = last_depth;
if (0) { // Enable this to turn on SSPREQ (-fstack-protector) on the function containing this ccall
Expand All @@ -962,7 +986,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
//fprintf(stderr, "ccall rt: %s -> %s\n", f_name, ((jl_tag_type_t*)rt)->name->name->name);
assert(jl_is_structtype(rt));
Value *strct =
builder.CreateCall(jlallocobj_func,
builder.CreateCall(prepare_call(jlallocobj_func),
ConstantInt::get(T_size,
sizeof(void*)+((jl_datatype_t*)rt)->size));
builder.CreateStore(literal_pointer_val((jl_value_t*)rt),
Expand Down
Loading