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

deDynamicLibrary_open intentionally(?) truncates its argument when LD_LIBRARY_PATH is set. #479

Open
eddyb opened this issue Aug 9, 2024 · 2 comments

Comments

@eddyb
Copy link

eddyb commented Aug 9, 2024

deDynamicLibrary *deDynamicLibrary_open(const char *fileName)
{
deDynamicLibrary *library = (deDynamicLibrary *)deCalloc(sizeof(deDynamicLibrary));
if (!library)
return NULL;
if (getenv("LD_LIBRARY_PATH"))
library->libHandle = dlopen(basename((char *)fileName), RTLD_LAZY);
else
library->libHandle = dlopen(fileName, RTLD_LAZY);

I don't understand the purpose of such code in production - it looks like a testing hack that got accidentally committed?

The environment variable LD_LIBRARY_PATH, just like PATH, can contain arbitrary entries that should be ignored whenever they are irrelevant to the program itself.

Only way I could see this kind of logic making sense is trying both dlopen(basename((char *)fileName), RTLD_LAZY) and dlopen(fileName, RTLD_LAZY), when LD_LIBRARY_PATH is set (because, yes, they can pick different libraries).

But which one should you prefer? If the user explicitly passed e.g.:
--deqp-vk-library-path=/my/local/build/of/vulkan-loader/lib/libvulkan.so
Why would that full path be ignored in favor of just libvulkan.so?

Also, even with LD_LIBRARY_PATH unset, there is a hardcoded list of search directories built into libdl, so dlopen("libfoo.so") could still succeed even then.
(think /lib64, but also e.g. automatically appending subpaths like glibc-hwcaps/x86-64-v3/ etc.)


Personally, I had deqp-vk work before, and it so happens that LD_LIBRARY_PATH isn't set for me normally (e.g. in Konsole), but something or other leads to it being set in VSCode, and I was running deqp-vk from inside VSCode this time.

@eddyb
Copy link
Author

eddyb commented Aug 9, 2024

I don't understand the purpose of such code in production - it looks like a testing hack that got accidentally committed?

Maybe I was right about this, I didn't go back further in time once I saw that the last time I used deqp-vk the code would've been the same.

But apparently this started with 5aa5b08 (Vulkan Video tests).

Flakebi added a commit to Flakebi/VK-GL-CTS that referenced this issue Oct 29, 2024
Commit 5aa5b08 changed the way
libraries are dynamically loaded when `LD_LIBRARY_PATH` is set to only
take the filename into account and not the complete path. This seems to
be overlooked code meant for testing as the commit is about video
testing and not library loading.

Revert the file to its previous state to fix loading libraries that are
specified with absolute paths.

Fixes GitHub issue KhronosGroup#479.
@Flakebi
Copy link

Flakebi commented Oct 29, 2024

I opened #495 to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants