From 7ea56fecf1e40c344510e16a89f43409223d49f0 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Thu, 23 Apr 2020 10:30:56 -0700 Subject: [PATCH] Speed up `dlpath()` on MacOS `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. --- src/sys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys.c b/src/sys.c index 4ccdfad421095..c8fc622e10a46 100644 --- a/src/sys.c +++ b/src/sys.c @@ -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