On Sat, Oct 10, 2015 at 8:13 PM, Tony Kelman <[email protected]> wrote:
> I believe dlsym can get you in trouble with precompilation since the symbol 
> pointers don't have persistent values, so keep an eye out.

Yes, if it is in a (const?) global. The following should work.

julia> const ptr2 = Ref{Ptr{Void}}(cglobal("sin"))
Base.RefValue{Ptr{Void}}(Ptr{Void} @0x00007f54375c15a0)

julia> f() = ccall(ptr2[], Float64, (Float64,), 1.2)
f (generic function with 1 method)

julia> f()
0.9320390859672263

julia> ptr2[] = cglobal("cos")
Ptr{Void} @0x00007f54375c2af0

julia> f()
0.3623577544766736

julia> @code_llvm f()

define double @julia_f_22309() {
top:
  %0 = call i8* @julia_getindex_22277(%jl_value_t* inttoptr (i64
139991084651344 to %jl_value_t*))
  %1 = icmp eq i8* %0, null
  br i1 %1, label %fail, label %pass

fail:                                             ; preds = %top
  %2 = load %jl_value_t*, %jl_value_t** @jl_undefref_exception, align
8
  call void @jl_throw_with_superfluous_argument(%jl_value_t* %2, i32
1)
  unreachable

pass:                                             ; preds = %top
  %3 = bitcast i8* %0 to double (double)*
  %4 = call double %3(double 1.200000e+00)
  ret double %4
}

Reply via email to