bazelbuild/bazel

Libraries exported by cc_shared_library can be dropped by the linker

Open

#20,428 建立於 2023年12月4日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)Java (4,465 fork)batch import
P3help wantedteam-Rules-CPPtype: feature request

倉庫指標

Star
 (25,384 star)
PR 合併指標
 (平均合併 22天 20小時) (30 天內合併 77 個 PR)

描述

Description of the bug:

If a library (without alwayslink = True) is exported by a cc_shared_library but unused, the linker drops the library. This is problematic since if a shared library (A) depends on a shared library (B), it expects any of its dependencies that are exported by B to be fulfilled by B, and therefore does not link them into A. The only way of avoiding this is to specify this dropped library in deps.

I would expect libraries that match the exports filter to be treated as if they were alwayslink, i.e. not put them inside -Wl,--start-lib and -Wl,--end-lib.

There is a slack thread about this here: https://bazelbuild.slack.com/archives/CGA9QFQ8H/p1701702759075819

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I have created a reproducer of this issue here: https://github.com/cameron-martin/bazel-7-cc-shared-library-dropping-exported

Running bazel build //:bin reproduces this error, getting a linker error due to the dropped library.

Which operating system are you running Bazel on?

Ubuntu 20.04

What is the output of bazel info release?

release 7.0.0rc5

If bazel info release returns development 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.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

貢獻者指南