Keep exports_filter libraries linked in cc_shared_library#694
Open
cameron-martin wants to merge 8 commits intobazelbuild:mainfrom
Open
Keep exports_filter libraries linked in cc_shared_library#694cameron-martin wants to merge 8 commits intobazelbuild:mainfrom
cameron-martin wants to merge 8 commits intobazelbuild:mainfrom
Conversation
Libraries claimed via exports_filter are expected to be provided by the producing cc_shared_library even when they are otherwise unused by that shared library's own objects. Without special handling they can still be wrapped in start-lib/end-lib and dropped by the linker, which breaks downstream shared libraries that rely on those exported symbols through dynamic_deps. Treat libraries matched by exports_filter like other top-level static link inputs for this purpose and wrap them as alwayslink before linking. Add a regression test that covers an exported transitive library used only by a downstream cc_shared_library through dynamic_deps.
lilygorsheneva
previously approved these changes
Apr 20, 2026
Collaborator
|
Tests fail on Bazel 7/8, you should disable them |
Author
|
Why do they fail on Bazel 7/8? Is it because they use a version of cc_shared_library that is shipped with Bazel? |
Collaborator
|
Yes. |
Author
|
I've used the example in tests/alwayslink_srcs/BUILD |
Author
|
I attempted to fix this test on windows too but I don't really know enough about how linking & shared libraries on windows works, so is it okay to leave the test nix-only? |
Collaborator
|
I'm not sure to what extent we care about that (I know we have a lot of tests disabled for windows but I assumed the underlying feature doesn't work there); @trybka ? |
Collaborator
|
Trybka doesn't know, what about @fmeum ? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Libraries exposed via exports_filter are expected to be provided by the producing cc_shared_library even when they are otherwise unused by that shared library's own objects. Without special handling they can still be wrapped in start-lib/end-lib and dropped by the linker, which breaks downstream shared libraries that rely on those exported symbols through dynamic_deps.
Any libraries covered by exports_filter are now treated as alwayslink, to avoid this issue.
Fixes bazelbuild/bazel#20428