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
Transitive shared libraries not added to rpath of otherwise static binaries #578
Comments
Tagging @cjhopman since you already had the answers last time, I hope you don't mind. |
I did some digging and it seems to come from # Only setup a shared library symlink tree when shared linkage or link_groups is used
gnu_use_link_groups = cxx_is_gnu(ctx) and link_group_mappings
shlib_deps = []
if link_strategy == LinkStrategy("shared") or gnu_use_link_groups:
shlib_deps = (
[d.shared_library_info for d in link_deps] +
[d.shared_library_info for d in impl_params.extra_link_roots]
) in Removing the check seems to do what I want, but that might break something elsewhere?
Can I get some context regarding why this check was added? If it's some sort of optimization, I would suggest removing it, unless:
|
Personally I think it's just a bug and would love to see us fix it. But, it's actually more that the behavior in the condition is wrong, but for the shared link case it's less wrong. Okay, what's going on? The d.shared_library_info there ends up being basically a list of all the shared libraries in the graph for every target that can produce a shared library (basically, every target with preferred_linkage = "any" or "shared" ends up with an entry in the shared_library_info). When using link_style = "static" (actually if used anywhere in the graph, not just at the top level like that condition checks) that list of libraries might include a bunch that you don't actually use (because it would include ones from targets with preferred_linkage = any even though you consume those as shared libs). The right way to do this is that we should be tracking up the actual shared lib deps of each shared lib, rather than just stuffing everything into shared_library_info and using that. |
This is sort of a follow up to #571.
When building a target with
link_style = "static"
, where a transitive dependency is a shared library due to its usage ofpreferred_linkage = "shared"
, this shared library does not get added to the rpath of the top-level target.In other words, given
binary
->static.a
->shared.so
,shared.so
will not be available tobinary
.Here is a minimal reproduction on top of a
buck2 init --git
with the latest release:Running
readelf -d $(buck2 build --show-full-simple-output :test)
shows that the resulting binary has no rpath because link_style was set tostatic
. As expected,buck2 run :test
will fail due to the shared library not being found.Is this just a current limitation of the prelude, or is there something fundamentally wrong with my approach here?
The text was updated successfully, but these errors were encountered: