Skip to content

Commit

Permalink
avoid loading duplicate libraries (#42058)
Browse files Browse the repository at this point in the history
We will not use the duplicate, so best to try to avoid loading it.

(cherry picked from commit c53669f)
  • Loading branch information
vtjnash authored and staticfloat committed Dec 22, 2022
1 parent 6db81b9 commit e9c99fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,27 @@ void jl_loader_print_stderr3(const char * msg1, const char * msg2, const char *

/* Wrapper around dlopen(), with extra relative pathing thrown in*/
static void * load_library(const char * rel_path, const char * src_dir) {
void * handle = NULL;

// See if a handle is already open to the basename
const char *basename = rel_path + strlen(rel_path);
while (basename-- > rel_path)
if (*basename == PATHSEPSTRING[0] || *basename == '/')
break;
basename++;
#if defined(_OS_WINDOWS_)
if ((handle = GetModuleHandleW(basename)))
return handle;
#else
if ((handle = dlopen(basename, RTLD_NOLOAD | RTLD_NOW | RTLD_GLOBAL)))
return handle;
#endif

char path[2*PATH_MAX + 1] = {0};
strncat(path, src_dir, sizeof(path) - 1);
strncat(path, PATHSEPSTRING, sizeof(path) - 1);
strncat(path, rel_path, sizeof(path) - 1);

void * handle = NULL;
#if defined(_OS_WINDOWS_)
wchar_t wpath[2*PATH_MAX + 1] = {0};
if (!utf8_to_wchar(path, wpath, 2*PATH_MAX)) {
Expand Down
2 changes: 1 addition & 1 deletion src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -756,4 +756,4 @@
XX(jl_wakeup_thread) \
XX(jl_xor_int) \
XX(jl_yield) \
XX(jl_zext_int)
XX(jl_zext_int) \

0 comments on commit e9c99fa

Please sign in to comment.