-
Notifications
You must be signed in to change notification settings - Fork 308
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
DynamicLoader attempts to load the library even if already loaded #1811
Comments
I'm looking for direction here — should I implement functionality using dlsym/dladdr and the equivalent on Windows to detect if the library already has been loaded? Or would some alternate mechanism be preferred? |
I assume you don't have the problem you mentioned on Windows. On Linux, the behavior could probably be changed by adapting the flags passed to dlopen. RTDL_LOCAL might be part of the behavior you're seeing and you could force to load symbols from the library you've already loaded. This paragraph from the dlopen manpage could also help you control which paths are searched by Vulkan-hpp's dlopen (in addition to LD_LOAD_PATH)
Is there any reason why you wouldn't want to use a driver/system provided libvulkan.so.1? |
I am experiencing this problem on macOS; I have not tested on Windows yet. This problem will occur whenever the libvulkan libraries are installed in a non-system prefix. If implicit linking is used, the dll should already have been loaded even on Windows.
Why attempt to dlopen at all if the library has already been loaded by the system? I'm proposing to check if the library has already been loaded, and skip the forced dlopen in that case.
In some cases the libvulkan.so.1 or equivalent might be installed in a separate prefix, and in this case if the path to the lib directory of that prefix isn't in PATH or RPATH or the equivalent, the library won't be found when the dlopen is attempted. However, if the executable is already linked to that library, it will have already been loaded by the system dynamic linker. Therefore in this case, attempting to load it is unnecessary and may fail. I'm running into a failure on macOS with Homebrew, which puts libvulkan.dylib in a separate prefix and relies on it being in the executable's library paths to be loaded by the system dynamic linker. But this could happen on any platform. |
The DynamicLoader, at https://github.com/KhronosGroup/Vulkan-Hpp/blob/main/snippets/DynamicLoader.hpp#L11, attempts to load the Vulkan Loader library by name regardless of whether is has already been loaded by the system. If the library path is not in the RPATH, this will fail. In many cases, the library will already have been loaded by the system dynamic loader/linker due to it being in the library paths for the executable. There are some attempts to avoid this, but they are ad-hoc and seem to fail for me.
Is there any reason not to use dladdr or similar functionality to try to detect if the library has already been loaded by the system? See https://stackoverflow.com/a/65216532 for details on how this could be implemented.
The text was updated successfully, but these errors were encountered: