-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Distinguish between dynamic library not found and can't be opened. #86682
Merged
akien-mga
merged 1 commit into
godotengine:master
from
Daylily-Zeleen:daylily-zeleen/distinguish_between_dynamic_libaray_not_found_and_can't_open
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this breaks dynamic library loading on Android since on that platform the original path may be inaccessible which requires moving the library around (see logic below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverting the change for Android in #86792
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I reviewed this a bit fast, this may also fail on other platforms. So the whole PR might need to be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eep, sorry, guys! I thought it would be fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we could report a different error code if the file doesn't exist on Android too, it would just need to be handled later, I guess as an
else
on the 2ndif (internal_so_file_exists)
check?EDIT: No, that doesn't make sense. I'm actually a little confused as to why the current version causes problems. The copying branch only happens if
so_file_exists
istrue
, so it doesn't sound like missing that branch is what's causing the problem? Is there some case where loading a library should work even whenso_file_exists
isfalse
?EDIT 2: Ah, looking at this PR #68362 I think I understand this better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my worry here is that this function is currently only used for GDExtension, OpenXR (for Android), and .NET (using absolute paths), so we might be forgetting about the fact that dynamic libraries can be in
C:\Windows\System32
or/usr/lib
//usr/lib64
.We don't use it currently (Linux does a bunch of dynamic loading but doesn't seem to rely on this method, it uses
dlopen
directly), but in theory I would expect this function to succeed if I doOS::get_singleton()->open_dynamic_library("libSDL2.so", sdl_handle);
on Linux to load/usr/lib64/libSDL2.so
on my system (with/usr/lib64
being part of my distro's default library paths).While I feel we're treating it more as a
open_gdextension_library
currently, and only taking this use case into account.Am I missing something?
CC @bruvzg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually looking further at the
OS_Unix
implementation I see it's not the generic wrapper arounddlopen
I thought it would be. It does seem focused only on trying to load a library next to the binary or in the parent../lib
folder if it exists.So I guess the other checks added for Unix/Windows are ok. But there should likely be an explicit
_MSG
that refers back to the originalp_path
and not just the generic error that would mention the modifiedpath
.Because currently trying to open
mylib.so
if it doesn't exist will fail with an error referring to../lib/mylib.so
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, (for GDExtension and, .NET) it is OK to assume we are using full path, but for something like #85741 it won't be, also GDExtension can try using it to load its dependencies.
Maybe we should check if path is absolute path and only do this check (and path substitution). So
open_dynamic_library("res://libSDL2.so")
will check do it andopen_dynamic_library("libSDL2.so")
will skip the checks and let system look for the lib.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, we probably should try substituting path for the expected one, like on macOS it's trying to replace executable folder with
../Frameworks/
if lib is not found.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something like PR #86794? It could certainly be improved with a message, but I think it should give the correct error code when the file doesn't exist.