Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable DL_LOAD_PATH prepending for @-paths on Darwin #42721

Merged
merged 3 commits into from
Oct 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
uv_stat_t stbuf;
void *handle;
int abspath;
int is_atpath;
// number of extensions to try — if modname already ends with the
// standard extension, then we don't try adding additional extensions
int n_extensions = endswith_extension(modname) ? 1 : N_EXTENSIONS;
Expand All @@ -181,16 +182,30 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
}

abspath = jl_isabspath(modname);
is_atpath = 0;

// Detect if our `modname` is something like `@rpath/libfoo.dylib`
#ifdef _OS_DARWIN_
size_t nameLen = strlen(modname);
const char * atPaths = {"@executable_path", "@loader_path", "@rpath"};
for (i=0; i<sizeof(atPaths)/sizeof(char *); ++i) {
size_t atLen = strlen(atPaths[i]);
if (nameLen >= atLen && 0 == strncmp(modname, atPaths[i], atLen)) {
is_atpath = 1;
}
}
#endif

/*
this branch permutes all base paths in DL_LOAD_PATH with all extensions
note: skip when !jl_base_module to avoid UndefVarError(:DL_LOAD_PATH),
and also skip for absolute paths
and also skip for `@`-paths on macOS
We also do simple string replacement here for elements starting with `@executable_path/`.
While these exist as OS concepts on Darwin, we want to use them on other platforms
such as Windows, so we emulate them here.
*/
if (!abspath && jl_base_module != NULL) {
if (!abspath && !is_atpath && jl_base_module != NULL) {
jl_binding_t *b = jl_get_module_binding(jl_base_module, jl_symbol("DL_LOAD_PATH"));
jl_array_t *DL_LOAD_PATH = (jl_array_t*)(b ? jl_atomic_load_relaxed(&b->value) : NULL);
if (DL_LOAD_PATH != NULL) {
Expand Down