Skip to content

Commit

Permalink
Speed up dlpath() on MacOS (#35630)
Browse files Browse the repository at this point in the history
`dlpath()` on MacOS iterated over all loaded image names, calling
`dlopen()` on them again and comparing returned handles to see if the
given handle matched.  This wasted a lot of time running through the
`dlopen()` machinery, we can bypass much of it by passing `RTLD_NOLOAD`
in to `dlopen()`, as we are assured that all pathnames we are probing
are already loaded.
  • Loading branch information
staticfloat authored Apr 30, 2020
1 parent 5819223 commit 5e1083c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ JL_DLLEXPORT const char *jl_pathname_for_handle(void *handle)
for (int32_t i = _dyld_image_count() - 1; i >= 0 ; i--) {
// dlopen() each image, check handle
const char *image_name = _dyld_get_image_name(i);
void *probe_lib = jl_load_dynamic_library(image_name, JL_RTLD_DEFAULT, 0);
void *probe_lib = jl_load_dynamic_library(image_name, JL_RTLD_DEFAULT | JL_RTLD_NOLOAD, 0);
jl_dlclose(probe_lib);

// If the handle is the same as what was passed in (modulo mode bits), return this image name
Expand Down

0 comments on commit 5e1083c

Please sign in to comment.