-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Lookup ccall symbols in internal libraries first
#49010
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,7 @@ JL_DLLEXPORT JL_NO_SANITIZE void *jl_dlopen(const char *filename, unsigned flags | |
| if (!dlopen) | ||
| return NULL; | ||
| void *libdl_handle = dlopen("libdl.so", RTLD_NOW | RTLD_NOLOAD); | ||
| assert(libdl_handle); | ||
| dlopen = (dlopen_prototype*)dlsym(libdl_handle, "dlopen"); | ||
| dlclose(libdl_handle); | ||
| assert(dlopen); | ||
|
|
@@ -239,6 +240,25 @@ JL_DLLEXPORT int jl_dlclose(void *handle) JL_NOTSAFEPOINT | |
| #endif | ||
| } | ||
|
|
||
| void *jl_find_dynamic_library_by_addr(void *symbol) { | ||
| void *handle; | ||
| #ifdef _OS_WINDOWS_ | ||
| if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | ||
| (LPCWSTR)symbol, | ||
| (HMODULE*)&handle)) { | ||
| jl_error("could not load base module"); | ||
| } | ||
| #else | ||
| Dl_info info; | ||
| if (!dladdr(symbol, &info) || !info.dli_fname) { | ||
| jl_error("could not load base module"); | ||
| } | ||
| handle = dlopen(info.dli_fname, RTLD_NOW | RTLD_NOLOAD); | ||
| dlclose(handle); // Undo ref count increment from `dlopen` | ||
| #endif | ||
| return handle; | ||
| } | ||
|
|
||
| JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags, int throw_err) | ||
| { | ||
| char path[PATHBUF], relocated[PATHBUF]; | ||
|
|
@@ -255,26 +275,6 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags, | |
| int n_extensions = endswith_extension(modname) ? 1 : N_EXTENSIONS; | ||
| int ret; | ||
|
|
||
| /* | ||
| this branch returns handle of libjulia-internal | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was actually trying to trigger this case however, which is not as much of a trick and not quite what it claimed to be doing. I assume we could put this back? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it, yes. Putting it back makes CBinding work again, as expected. @topolarity what was the reason to remove this functionality? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a mistake and assumed that downstream code would not end up here after all of the runtime-internal uses were re-factored into PR open to fix: #49611 |
||
| */ | ||
| if (modname == NULL) { | ||
| #ifdef _OS_WINDOWS_ | ||
| if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | ||
| (LPCWSTR)(uintptr_t)(&jl_load_dynamic_library), | ||
| (HMODULE*)&handle)) { | ||
| jl_error("could not load base module"); | ||
| } | ||
| #else | ||
| Dl_info info; | ||
| if (!dladdr((void*)(uintptr_t)&jl_load_dynamic_library, &info) || !info.dli_fname) { | ||
| jl_error("could not load base module"); | ||
| } | ||
| handle = dlopen(info.dli_fname, RTLD_NOW); | ||
| #endif | ||
| goto done; | ||
| } | ||
|
|
||
| abspath = jl_isabspath(modname); | ||
| is_atpath = 0; | ||
|
|
||
|
|
@@ -421,9 +421,8 @@ JL_DLLEXPORT int jl_dlsym(void *handle, const char *symbol, void ** value, int t | |
| return symbol_found; | ||
| } | ||
|
|
||
| #ifdef _OS_WINDOWS_ | ||
| //Look for symbols in win32 libraries | ||
| JL_DLLEXPORT const char *jl_dlfind_win32(const char *f_name) | ||
| // Look for symbols in internal libraries | ||
| JL_DLLEXPORT const char *jl_dlfind(const char *f_name) | ||
| { | ||
| void * dummy; | ||
| if (jl_dlsym(jl_exe_handle, f_name, &dummy, 0)) | ||
|
|
@@ -432,6 +431,7 @@ JL_DLLEXPORT const char *jl_dlfind_win32(const char *f_name) | |
| return JL_LIBJULIA_INTERNAL_DL_LIBNAME; | ||
| if (jl_dlsym(jl_libjulia_handle, f_name, &dummy, 0)) | ||
| return JL_LIBJULIA_DL_LIBNAME; | ||
| #ifdef _OS_WINDOWS_ | ||
| if (jl_dlsym(jl_kernel32_handle, f_name, &dummy, 0)) | ||
| return "kernel32"; | ||
| if (jl_dlsym(jl_crtdll_handle, f_name, &dummy, 0)) // Prefer crtdll over ntdll | ||
|
|
@@ -440,6 +440,7 @@ JL_DLLEXPORT const char *jl_dlfind_win32(const char *f_name) | |
| return "ntdll"; | ||
| if (jl_dlsym(jl_winsock_handle, f_name, &dummy, 0)) | ||
| return "ws2_32"; | ||
| #endif | ||
| // additional common libraries (libc?) could be added here, but in general, | ||
| // it is better to specify the library explicitly in the code. This exists | ||
| // mainly to ease compatibility with linux, and for libraries that don't | ||
|
|
@@ -451,7 +452,6 @@ JL_DLLEXPORT const char *jl_dlfind_win32(const char *f_name) | |
| // which defaults to jl_libjulia_internal_handle, where we won't find it, and | ||
| // will throw the appropriate error. | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.