bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.07k stars 4.04k forks source link

Transitive `cc_shared_library` doesn't work with inline functions #21819

Open brians-neptune opened 6 months ago

brians-neptune commented 6 months ago

Description of the bug:

cc_shared_library and dynamic_deps deliberately link the shared libraries for only direct dependencies, while excluding the corresponding static libraries transitively. If any of the direct dependencies have inline functions which use transitive dependencies, this can result in linking failures. This is common with C++ code, it's less common but I think it's still possible with C.

Having to specify all the transitive dependencies in dynamic_deps is not good. It's even worse because sometimes with some compilers and some optimization settings it's necessary, and other times it's not (it depends on what gets inlined where).

Linking all of the transitive shared libraries seems low-cost. They're going to be needed at runtime anyways. Would that be an acceptable change?

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.

https://github.com/brians-neptune/bazel-cc_shared_library-transitive-deps has a main_dynamic target which fails to link, but I think it should. main_static is the same thing without dynamic_deps, which does link.

Which operating system are you running Bazel on?

Ubuntu 22.04

What is the output of bazel info release?

release 7.0.2

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 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

comius commented 6 months ago

cc @pzembrod for triage cc @oquenchil for potential insights

oquenchil commented 6 months ago

Can you post the error?

brians-neptune commented 6 months ago
ERROR: /home/brian/Desktop/bazel-cc_shared_library-transitive-deps/BUILD:24:10: Linking main_dynamic failed: (Exit 1): cc_wrapper.sh failed: error executing CppLink command (from target //:main_dynamic) external/llvm_toolchain/bin/cc_wrapper.sh @bazel-out/k8-fastbuild/bin/main_dynamic-2.params

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
ld.lld: error: undefined symbol: transitive_return42()
>>> referenced by main.cc
>>>               bazel-out/k8-fastbuild/bin/_objs/main_dynamic/main.pic.o:(dep_return42())
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Use --verbose_failures to see the command lines of failed build steps.