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 committed Oct 14, 2021
1 parent 7c5e28c commit 5a073c1
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 5a073c1

Please sign in to comment.