Skip to content

Commit f2ec633

Browse files
committed
avoid loading duplicate libraries
We will not use the duplicate, so best to try to avoid loading it.
1 parent 915a212 commit f2ec633

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Make.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ JULIA_SYSIMG_release := $(build_private_libdir)/sys.$(SHLIB_EXT)
14891489
JULIA_SYSIMG := $(JULIA_SYSIMG_$(JULIA_BUILD_MODE))
14901490

14911491
define dep_lib_path
1492-
$$($(PYTHON) $(call python_cygpath,$(JULIAHOME)/contrib/relative_path.py) $(1) $(2))
1492+
./$$($(PYTHON) $(call python_cygpath,$(JULIAHOME)/contrib/relative_path.py) $(1) $(2))
14931493
endef
14941494

14951495
LIBJULIAINTERNAL_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_shlibdir)/libjulia-internal.$(JL_MAJOR_SHLIB_EXT))

cli/loader_lib.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,27 @@ void jl_loader_print_stderr3(const char * msg1, const char * msg2, const char *
3131

3232
/* Wrapper around dlopen(), with extra relative pathing thrown in*/
3333
static void * load_library(const char * rel_path, const char * src_dir) {
34+
void * handle = NULL;
35+
36+
// See if a handle is already open to the basename
37+
const char *basename = rel_path + strlen(rel_path);
38+
while (basename-- > rel_path)
39+
if (*basename == PATHSEPSTRING[0] || *basename == '/')
40+
break;
41+
basename++;
42+
#if defined(_OS_WINDOWS_)
43+
if ((handle = GetModuleHandleW(basename)))
44+
return handle;
45+
#else
46+
if ((handle = dlopen(basename, RTLD_NOLOAD | RTLD_NOW | RTLD_GLOBAL)))
47+
return handle;
48+
#endif
49+
3450
char path[2*PATH_MAX + 1] = {0};
3551
strncat(path, src_dir, sizeof(path) - 1);
3652
strncat(path, PATHSEPSTRING, sizeof(path) - 1);
3753
strncat(path, rel_path, sizeof(path) - 1);
3854

39-
void * handle = NULL;
4055
#if defined(_OS_WINDOWS_)
4156
wchar_t wpath[2*PATH_MAX + 1] = {0};
4257
if (!utf8_to_wchar(path, wpath, 2*PATH_MAX)) {

src/jl_exported_funcs.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,4 @@
551551
XX(jl_vprintf) \
552552
XX(jl_wakeup_thread) \
553553
XX(jl_yield) \
554+

0 commit comments

Comments
 (0)