Skip to content

Commit

Permalink
fix jl_load_dynamic_library with NULL argument
Browse files Browse the repository at this point in the history
This was supposed to return a handle for libjulia, but on unix
systems was returning a handle for the main executable.
  • Loading branch information
JeffBezanson committed Apr 13, 2017
1 parent b91b411 commit 653fb16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ static void *jl_load_dynamic_library_(const char *modname, unsigned flags, int t
jl_error("could not load base module");
}
#else
handle = dlopen(NULL, RTLD_NOW);
Dl_info info;
if (!dladdr(&jl_load_dynamic_library, &info) || !info.dli_fname)
jl_error("could not load base module");
handle = dlopen(info.dli_fname, RTLD_NOW);
#endif
goto done;
}
Expand Down
14 changes: 8 additions & 6 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ void jl_get_builtins(void);

JL_DLLEXPORT void *jl_dl_handle;
void *jl_RTLD_DEFAULT_handle;
#ifdef _OS_WINDOWS_
JL_DLLEXPORT void *jl_exe_handle;
#ifdef _OS_WINDOWS_
void *jl_ntdll_handle;
void *jl_kernel32_handle;
void *jl_crtdll_handle;
Expand Down Expand Up @@ -541,11 +541,6 @@ void _julia_init(JL_IMAGE_SEARCH rel)
jl_arr_xtralloc_limit = total_mem / 100; // Extra allocation limited to 1% of total RAM
jl_find_stack_bottom();
jl_dl_handle = jl_load_dynamic_library(NULL, JL_RTLD_DEFAULT);
#ifdef RTLD_DEFAULT
jl_RTLD_DEFAULT_handle = RTLD_DEFAULT;
#else
jl_RTLD_DEFAULT_handle = jl_dl_handle;
#endif
#ifdef _OS_WINDOWS_
jl_ntdll_handle = jl_dlopen("ntdll.dll", 0); // bypass julia's pathchecking for system dlls
jl_kernel32_handle = jl_dlopen("kernel32.dll", 0);
Expand All @@ -564,6 +559,13 @@ void _julia_init(JL_IMAGE_SEARCH rel)
HMODULE jl_dbghelp = (HMODULE) jl_dlopen("dbghelp.dll", 0);
if (jl_dbghelp)
hSymRefreshModuleList = (BOOL (WINAPI*)(HANDLE)) jl_dlsym(jl_dbghelp, "SymRefreshModuleList");
#else
jl_exe_handle = jl_dlopen(NULL, JL_RTLD_NOW);
#ifdef RTLD_DEFAULT
jl_RTLD_DEFAULT_handle = RTLD_DEFAULT;
#else
jl_RTLD_DEFAULT_handle = jl_exe_handle;
#endif
#endif

#if defined(JL_USE_INTEL_JITEVENTS)
Expand Down

0 comments on commit 653fb16

Please sign in to comment.