Skip to content

Commit 653fb16

Browse files
committed
fix jl_load_dynamic_library with NULL argument
This was supposed to return a handle for libjulia, but on unix systems was returning a handle for the main executable.
1 parent b91b411 commit 653fb16

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/dlload.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ static void *jl_load_dynamic_library_(const char *modname, unsigned flags, int t
139139
jl_error("could not load base module");
140140
}
141141
#else
142-
handle = dlopen(NULL, RTLD_NOW);
142+
Dl_info info;
143+
if (!dladdr(&jl_load_dynamic_library, &info) || !info.dli_fname)
144+
jl_error("could not load base module");
145+
handle = dlopen(info.dli_fname, RTLD_NOW);
143146
#endif
144147
goto done;
145148
}

src/init.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ void jl_get_builtins(void);
299299

300300
JL_DLLEXPORT void *jl_dl_handle;
301301
void *jl_RTLD_DEFAULT_handle;
302-
#ifdef _OS_WINDOWS_
303302
JL_DLLEXPORT void *jl_exe_handle;
303+
#ifdef _OS_WINDOWS_
304304
void *jl_ntdll_handle;
305305
void *jl_kernel32_handle;
306306
void *jl_crtdll_handle;
@@ -541,11 +541,6 @@ void _julia_init(JL_IMAGE_SEARCH rel)
541541
jl_arr_xtralloc_limit = total_mem / 100; // Extra allocation limited to 1% of total RAM
542542
jl_find_stack_bottom();
543543
jl_dl_handle = jl_load_dynamic_library(NULL, JL_RTLD_DEFAULT);
544-
#ifdef RTLD_DEFAULT
545-
jl_RTLD_DEFAULT_handle = RTLD_DEFAULT;
546-
#else
547-
jl_RTLD_DEFAULT_handle = jl_dl_handle;
548-
#endif
549544
#ifdef _OS_WINDOWS_
550545
jl_ntdll_handle = jl_dlopen("ntdll.dll", 0); // bypass julia's pathchecking for system dlls
551546
jl_kernel32_handle = jl_dlopen("kernel32.dll", 0);
@@ -564,6 +559,13 @@ void _julia_init(JL_IMAGE_SEARCH rel)
564559
HMODULE jl_dbghelp = (HMODULE) jl_dlopen("dbghelp.dll", 0);
565560
if (jl_dbghelp)
566561
hSymRefreshModuleList = (BOOL (WINAPI*)(HANDLE)) jl_dlsym(jl_dbghelp, "SymRefreshModuleList");
562+
#else
563+
jl_exe_handle = jl_dlopen(NULL, JL_RTLD_NOW);
564+
#ifdef RTLD_DEFAULT
565+
jl_RTLD_DEFAULT_handle = RTLD_DEFAULT;
566+
#else
567+
jl_RTLD_DEFAULT_handle = jl_exe_handle;
568+
#endif
567569
#endif
568570

569571
#if defined(JL_USE_INTEL_JITEVENTS)

0 commit comments

Comments
 (0)