Skip to content

Commit

Permalink
avoid loading duplicate libraries
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.
  • Loading branch information
vtjnash committed Aug 30, 2021
1 parent 915a212 commit f2ec633
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ JULIA_SYSIMG_release := $(build_private_libdir)/sys.$(SHLIB_EXT)
JULIA_SYSIMG := $(JULIA_SYSIMG_$(JULIA_BUILD_MODE))

define dep_lib_path
$$($(PYTHON) $(call python_cygpath,$(JULIAHOME)/contrib/relative_path.py) $(1) $(2))
./$$($(PYTHON) $(call python_cygpath,$(JULIAHOME)/contrib/relative_path.py) $(1) $(2))
endef

LIBJULIAINTERNAL_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_shlibdir)/libjulia-internal.$(JL_MAJOR_SHLIB_EXT))
Expand Down
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
1 change: 1 addition & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,4 @@
XX(jl_vprintf) \
XX(jl_wakeup_thread) \
XX(jl_yield) \

0 comments on commit f2ec633

Please sign in to comment.