Skip to content

Keep exports_filter libraries linked in cc_shared_library#694

Open
cameron-martin wants to merge 8 commits intobazelbuild:mainfrom
cameron-martin:fix/cc-shared-library-exports-filter-alwayslink
Open

Keep exports_filter libraries linked in cc_shared_library#694
cameron-martin wants to merge 8 commits intobazelbuild:mainfrom
cameron-martin:fix/cc-shared-library-exports-filter-alwayslink

Conversation

@cameron-martin
Copy link
Copy Markdown

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

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
lilygorsheneva previously approved these changes Apr 20, 2026
@lilygorsheneva lilygorsheneva self-requested a review April 20, 2026 19:33
@lilygorsheneva
Copy link
Copy Markdown
Collaborator

Tests fail on Bazel 7/8, you should disable them
example:

load("@bazel_features//:features.bzl", "bazel_features")

@cameron-martin
Copy link
Copy Markdown
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?

@lilygorsheneva
Copy link
Copy Markdown
Collaborator

Yes.

@cameron-martin
Copy link
Copy Markdown
Author

I've used the example in tests/alwayslink_srcs/BUILD

@cameron-martin
Copy link
Copy Markdown
Author

cameron-martin commented Apr 20, 2026

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?

@lilygorsheneva
Copy link
Copy Markdown
Collaborator

lilygorsheneva commented Apr 20, 2026

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 ?

@lilygorsheneva
Copy link
Copy Markdown
Collaborator

Trybka doesn't know, what about @fmeum ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Libraries exported by cc_shared_library can be dropped by the linker

2 participants