@@ -663,22 +663,18 @@ static jl_cgval_t emit_cglobal(jl_codectx_t &ctx, jl_value_t **args, size_t narg
663
663
}
664
664
else {
665
665
void *symaddr;
666
- if (!jl_dlsym (jl_get_library (sym.f_lib ), sym.f_name , &symaddr, 0 )) {
667
- std::stringstream msg;
668
- msg << " cglobal: could not find symbol " ;
669
- msg << sym.f_name ;
670
- if (sym.f_lib != NULL ) {
671
- #ifdef _OS_WINDOWS_
672
- assert (sym.f_lib != JL_EXE_LIBNAME && sym.f_lib != JL_DL_LIBNAME);
673
- #endif
674
- msg << " in library " ;
675
- msg << sym.f_lib ;
676
- }
677
- emit_error (ctx, msg.str ());
666
+
667
+ void * libsym = jl_get_library_ (sym.f_lib , 0 );
668
+ if (!libsym || !jl_dlsym (libsym, sym.f_name , &symaddr, 0 )) {
669
+ // Error mode, either the library or the symbol couldn't be find during compiletime.
670
+ // Fallback to a runtime symbol lookup.
671
+ res = runtime_sym_lookup (ctx, cast<PointerType>(T_pint8), sym.f_lib , sym.f_name , ctx.f );
672
+ res = ctx.builder .CreatePtrToInt (res, lrt);
673
+ } else {
674
+ // since we aren't saving this code, there's no sense in
675
+ // putting anything complicated here: just JIT the address of the cglobal
676
+ res = ConstantInt::get (lrt, (uint64_t )symaddr);
678
677
}
679
- // since we aren't saving this code, there's no sense in
680
- // putting anything complicated here: just JIT the address of the cglobal
681
- res = ConstantInt::get (lrt, (uint64_t )symaddr);
682
678
}
683
679
}
684
680
@@ -1877,23 +1873,17 @@ jl_cgval_t function_sig_t::emit_a_ccall(
1877
1873
}
1878
1874
else {
1879
1875
void *symaddr;
1880
- if (!jl_dlsym (jl_get_library (symarg.f_lib ), symarg.f_name , &symaddr, 0 )) {
1881
- std::stringstream msg;
1882
- msg << " ccall: could not find function " ;
1883
- msg << symarg.f_name ;
1884
- if (symarg.f_lib != NULL ) {
1885
- #ifdef _OS_WINDOWS_
1886
- assert (symarg.f_lib != JL_EXE_LIBNAME && symarg.f_lib != JL_DL_LIBNAME);
1887
- #endif
1888
- msg << " in library " ;
1889
- msg << symarg.f_lib ;
1890
- }
1891
- emit_error (ctx, msg.str ());
1892
- return jl_cgval_t ();
1876
+
1877
+ void * libsym = jl_get_library_ (symarg.f_lib , 0 );
1878
+ if (!libsym || !jl_dlsym (libsym, symarg.f_name , &symaddr, 0 )) {
1879
+ // either the library or the symbol could not be found, place a runtime
1880
+ // lookup here instead.
1881
+ llvmf = runtime_sym_lookup (ctx, funcptype, symarg.f_lib , symarg.f_name , ctx.f );
1882
+ } else {
1883
+ // since we aren't saving this code, there's no sense in
1884
+ // putting anything complicated here: just JIT the function address
1885
+ llvmf = literal_static_pointer_val (ctx, symaddr, funcptype);
1893
1886
}
1894
- // since we aren't saving this code, there's no sense in
1895
- // putting anything complicated here: just JIT the function address
1896
- llvmf = literal_static_pointer_val (ctx, symaddr, funcptype);
1897
1887
}
1898
1888
}
1899
1889
0 commit comments