-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Regression in cc_binary(linkshared=True)
starting with 6.3.0
#20252
Comments
@bazel-io flag |
@bazel-io fork 7.0.0 |
The culprit commit is doing the right thing as far as I can tell. The logic works by considering the exports of the To guide the logic into placing the
That solution would be more in line with how
In fact, that ship has probably sailed but I should have forbidden |
@layus Sounds like this is an intentional breaking change in Bazel 7, does @oquenchil 's suggestion work for you? |
Thanks @oquenchil, I am not saying that the code is doing the right or the wrong thing. I understand that the point is to provide a better interface, which is a much welcome change. As a colleague of mine suggested, it may be worth explaining the underlying logic and assumptions of cc_shared_library. C/C++ is very old, and there are plenty of usages that a built-in rule set cannot cover by default. It would help if the opinionated view taken here was detailed. And the implementation explained somewhere. We both tried to understand the code of cc_shared_library, but stopped without any good insights. The solution above seems very elegant and simple, but I would never have figured that by myself. My use case relies more on cc_import rules, and I link shared libraries without any corresponding library. It would never have occurred to me to add the same library twice in both deps and dynamic_deps. Even more so given the number of times I hit issues with symbols defined multiple times.
With external rule sets, we do not always control all the code paths. I bet there will be a lot of interactions during the transition.
@meteorcloudy I re-implemented the whole thing in the meantime, which could be considered a good thing. So I have fixed the problem for my use case, and the solutions above probably work. Will see if I get time to test them. However, if you want to know if it is an acceptable solution for me, I would say cc_shared_library introduces it's own model of shared libraries and requires users to get acquainted with it on top of their vanilla c/c++ knowledge. So it definitely deserves a lot of documentation. And this issue contains intel I could not find anywhere else. The solution is thus perfectly acceptable if it gets documented somewhere. |
@layus Thanks for confirming, then I'll remove this as a release blocker for 7.0.0. For cc_shared_library, we do have the user documentation here: https://bazel.build/reference/be/c-cpp#cc_shared_library, but it's definitely going to be helpful to have more docs about the implementation details for more involved use cases . Feel free to send PRs to help us improve it! |
Since this is WAI, I'll close this one. |
I would love to contribute documentation, but I am unable to do so because I do not understand how it works (yet). That is kind of the issue here really. |
Description of the bug:
We have an admittedly very hacky
cc_binary(linkshared=True)
rule that used to produce a valid shared library to be used as a native python module. When updating Bazel (from 7.0.0-pre.20230123.5 to 7.0.0rc2), we discovered that python refused to load it because of undefined symbols. The binary also became 5 times bigger. That binary is based on several static libraries (.a), and a fat, kitchen-sink-and-everything shared library (.so) generated withcc_shared_library
. Let's call itfatlib
.The only change is that the shared library now appears after the static libraries on the command line, while it used to appear first:
I have checked that running the command with the order fixed creates a valid native python module, and that it is the only change needed. I have also bisected bazel itself and found 946777a to be the culprit, and therefore the issues first appears with 6.3.0 for us.
However, this is a backport of many changes. On the main branch, the commit that makes it fail for us is a772452, which is indeed changing the logic around arguments order. I do not know why it used to work, nor why it fails with the new code. I also have found no way to force the order I need in this particular case.
The rule invocation looks like
/cc @oquenchil as these commits are yours, and you are probably the most knowledgeable person around this code.
/cc @sluongng and @fmeum just FYI
Which category does this issue belong to?
C++/Objective-C Rules
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I think the order change should be easy to reproduce, but for that order to have such an impact you probably need our weird setup.
Which operating system are you running Bazel on?
Ubuntu
What is the output of
bazel info release
?No response
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 master; git rev-parse HEAD
?No response
Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
a772452 when bisecting along the
master
branch, but946777a is the one that will appear when bisecting between 6.0.0 and 6.4.0
Have you found anything relevant by searching the web?
#19920 Seemed at first related, but this is a different issue.
See also my discussion about this issue on slack: https://bazelbuild.slack.com/archives/CA31HN1T3/p1700223322017839
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: