Skip to content

Commit 0991d10

Browse files
authored
Use jl_dlsym with search_deps=1 for ccalls (#59560)
Reverts the behaviour change for ccalls with an explicit library introduced by #58815. This is motivated by libraries like MPI, where the dynamic library that actually defines a symbol is difficult to predict: JuliaParallel/MPI.jl#915 (comment)
1 parent 218f691 commit 0991d10

File tree

4 files changed

+3
-9
lines changed

4 files changed

+3
-9
lines changed

src/jitlayers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ struct JuliaOJIT::DLSymOptimizer {
17481748

17491749
void *lookup_symbol(void *libhandle, const char *fname) JL_NOTSAFEPOINT {
17501750
void *addr;
1751-
jl_dlsym(libhandle, fname, &addr, 0, 0);
1751+
jl_dlsym(libhandle, fname, &addr, 0, 1);
17521752
return addr;
17531753
}
17541754

src/julia.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,11 +2195,7 @@ enum JL_RTLD_CONSTANT {
21952195
/* MacOS X 10.5+: */
21962196
JL_RTLD_FIRST=128U
21972197
};
2198-
#ifdef _OS_DARWIN_
2199-
#define JL_RTLD_DEFAULT (JL_RTLD_LAZY | JL_RTLD_DEEPBIND | JL_RTLD_FIRST)
2200-
#else
22012198
#define JL_RTLD_DEFAULT (JL_RTLD_LAZY | JL_RTLD_DEEPBIND)
2202-
#endif
22032199

22042200
typedef void *jl_libhandle; // compatible with dlopen (void*) / LoadLibrary (HMODULE)
22052201
JL_DLLEXPORT jl_libhandle jl_load_dynamic_library(const char *fname, unsigned flags, int throw_err);

src/runtime_ccall.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void *jl_load_and_lookup(const char *f_lib, const char *f_name, _Atomic(void*) *
5959
if (!handle)
6060
jl_atomic_store_release(hnd, (handle = jl_get_library(f_lib)));
6161
void * ptr;
62-
jl_dlsym(handle, f_name, &ptr, 1, 0);
62+
jl_dlsym(handle, f_name, &ptr, 1, 1);
6363
return ptr;
6464
}
6565

@@ -80,7 +80,7 @@ void *jl_lazy_load_and_lookup(jl_value_t *lib_val, const char *f_name)
8080
} else
8181
jl_type_error("ccall", (jl_value_t*)jl_symbol_type, lib_val);
8282
void *ptr;
83-
jl_dlsym(lib_ptr, f_name, &ptr, 1, 0);
83+
jl_dlsym(lib_ptr, f_name, &ptr, 1, 1);
8484
return ptr;
8585
}
8686

test/ccall.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,8 +1981,6 @@ let llvm = sprint(code_llvm, gc_safe_ccall, ())
19811981
end
19821982

19831983
@testset "jl_dlfind and dlsym" begin
1984-
# We shouldn't be able to call libc functions through libccalltest
1985-
@test_throws ErrorException ccall((:sqrt, libccalltest), Cdouble, (Cdouble,), 2.0)
19861984
# Test that jl_dlfind finds things in the expected places.
19871985
@test ccall(:jl_dlfind, Int, (Cstring,), "doesnotexist") == 0 # not found (RTLD_DEFAULT)
19881986
@static if !Sys.iswindows()

0 commit comments

Comments
 (0)