Use cc_import on shared libraries with dependencies #24477
Labels
P3
We're not considering working on this, but happy to review a PR. (No assignee)
team-Rules-CPP
Issues for C++ rules
type: bug
Description of the bug:
There are a few third-party pre-compiled shared libraries in our use case, we place them inside our workspace and use
cc_import
to import them. Some of them depend on others, for example,libX.so
depends onlibY.so
, so in ourBUILD
there are targets like below and it was working fine.However, recently we made some changes in
main
's sources, and it starts to use something provided bylibY.so
directly, so thedeps
ofmain
becomes[":imp-X", ":imp-Y"]
, but we found it not working as expected because there are some symbol resolution ordering issues betweenlibX.so
andlibY.so
---- whenmain
directly uses certain functions inlibY.so
, in order to make things correct,libY.so
must come beforelibX.so
inDT_NEEDED
section ofmain
.But, because of topological sorting on dependencies done by Bazel,
libY.so
is always coming afterlibX.so
, and we can not letimp-Y
depends onimp-X
which would form a circular dependency issue.We had several attempts to workaround this, but nothing ideal found.
imp-Y2
as a copy ofimp-Y
and use it instead ofimp-Y
inmain
'sdeps
.This works for now but is apparently not a good solution, and it actually stores two copies of
libY.so
in the deployment runfiles (after dereferenced copying). Also,libY.so
doesn't have to depend onlibX.so
, and we have othercc_binary
using onlylibY.so
, a global replacement would like to introduce unnecessary dependencies to some of them.imp-X
as a tricky pair like below.But this doesn't work (or being too complicated) when there is another
libZ.so
having the same issue likelibY.so
, and also suffers multiple copies problem like above. Moreover, it smells too insane thatimp-X
's direct library islibY.so
.libX.so
, and use it instead (relying on ELF loader's Breadth-First Search behavior to makelibY.so
load beforelibX.so
).But we haven't found a way to use "imp-thin-X" with
libX.so
put intomain
's runfiles (in mangled subdirectory) and not inmain
'sDT_NEEDED
. Do we really have a way to put a.so
into the mangled subdirectory in runfiles (and link with correctRPATH
orRUNPATH
) but not actually link the.so
?Any suggested alternatives on the situation I mentioned above?
Thanks!
Which category does this issue belong to?
C++ Rules
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
As described above.
Which operating system are you running Bazel on?
Ubuntu 22.04
What is the output of
bazel info release
?6.3.2
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse HEAD
?No response
If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
No response
Have you found anything relevant by searching the web?
No clear hit.
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: