Skip to content

Commit

Permalink
loader: load optional libraries with RTLD_LOCAL (JuliaLang#42631)
Browse files Browse the repository at this point in the history
This prevents global lookups from finding symbols in optional
libraries, since that would only work "sometimes".
  • Loading branch information
JeffBezanson authored and LilithHafner committed Feb 22, 2022
1 parent df8015d commit ff7138a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ static void * load_library(const char * rel_path, const char * src_dir, int err)
break;
basename++;
#if defined(_OS_WINDOWS_)
if ((handle = GetModuleHandleW(basename)))
if ((handle = GetModuleHandleA(basename)))
return handle;
#else
if ((handle = dlopen(basename, RTLD_NOLOAD | RTLD_NOW | RTLD_GLOBAL)))
// if err == 0 the library is optional, so don't allow global lookups to see it
if ((handle = dlopen(basename, RTLD_NOLOAD | RTLD_NOW | (err ? RTLD_GLOBAL : RTLD_LOCAL))))
return handle;
#endif

Expand All @@ -61,7 +62,7 @@ static void * load_library(const char * rel_path, const char * src_dir, int err)
}
handle = (void *)LoadLibraryExW(wpath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
#else
handle = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
handle = dlopen(path, RTLD_NOW | (err ? RTLD_GLOBAL : RTLD_LOCAL));
#endif

if (handle == NULL) {
Expand Down

0 comments on commit ff7138a

Please sign in to comment.