Skip to content

depend: fix library path resolution in POSIX non-ldconfig branches - #8422

Merged
rokm merged 2 commits into
pyinstaller:developfrom
rokm:bindepend-so-suffix-search
Apr 22, 2024
Merged

rokm merged 2 commits into
pyinstaller:developfrom
rokm:bindepend-so-suffix-search

Conversation

@rokm

@rokm rokm commented Apr 20, 2024

Copy link
Copy Markdown
Member

When resolving library path on POSIX systems and we do not have ldconfig cache available (e.g., Alpine linux), use _resolve_library_path_in_search_paths instead of _which_library, because the former expects the name to have (versioned) .so suffix (which is usually the case), and the latter expects the name to not have suffix. For backwards compatibility reasons, keep using _which_library in case we are given a name without suffix.

See pyinstaller/pyinstaller-hooks-contrib#724 (comment).

While we're at it, remove the replacement of resolved library's filename with its soname; because either it is the same and it is a no-op (most of the cases), or it will end up pointing to incorrect name (i.e., the other binary is referring to the library via the name we were given, so it expects to find the library under that name) which may not even exist (e.g., if the library was renamed to its current name, that differs from its soname, for whatever reason).

rokm added 2 commits April 20, 2024 17:11
The `resolve_library_path` helper in `PyInstaller.depend.bindepend`
expects to be given a full library name; on POSIX systems, this
includes `lib` prefix and `.so` suffix - typically versioned,
as it appears in the soname.

This means that in `_resolve_library_path_unix` codepaths that do
not use `ldconfig` cache but rather search for the library in
given search locations, we should not be using `_which_library`
helper (which expects basename without suffix), but rather
`_resolve_library_path_in_search_paths` helper (which expects
full library name).

However, because it was previously possible to pass a basename
without suffix and because some hooks in contrib hooks repository
rely on this behavior, implement support for both; if the given
name has .so suffix, use  `_resolve_library_path_in_search_paths`
to find exact match, and if name has no suffix, use `_which_library`
to find matching basename instead.
In `_resolve_library_path_unix` helper, remove the part at the
end where we read the soname of the resolved library and replace
the name in returned path with the soname.

In most cases, this was effectively no-op, because we use this
function to resolve dependencies of binaries that we analyze,
and those refer to those dependencies via their sonames.

However, in the unlikely case that we are trying to resolve a
library with soname that differs from its true (file)name, we
would need to collect it under that true (file)name; first, because
whoever was referring to it expects to find it under the true
(file)name, and second, becase in such case, the file with
corresponding soname might not actually exist at all.
@rokm
rokm merged commit ba3ccc6 into pyinstaller:develop Apr 22, 2024
@rokm
rokm deleted the bindepend-so-suffix-search branch April 22, 2024 21:13
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants