Skip to content

static_link_cpp_runtimes doesn't link the libstdc++ statically #14342

@tomgr

Description

@tomgr

Description of the problem / feature request:

The static_link_cpp_runtimes feature doesn't link libstdc++ statically despite appearing to be intended to as per https://docs.bazel.build/versions/main/cc-toolchain-config-reference.html#well-known-features.

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

Create the following files:

BUILD:

cc_binary(
  name = "test",
  srcs = ["main.cc"],
  features = ["static_link_cpp_runtimes"],
)

main.cc:

#include <iostream>

int main(int argc, char** argv) { 
  std::cout << "Hello" << std::endl;
}

WORKSPACE:

Running bazel build //:test && ldd bazel-bin/test gives:

        linux-vdso.so.1 (0x00007fffccffa000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f3b2a2c9000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3b2a1e5000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3b29fbd000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f3b2a4ea000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f3b29fa3000)

What operating system are you running Bazel on?

Ubuntu 22.04, but observed on several other Linuxes

What's the output of bazel info release?

release 6.0.0-pre.20211110.1. Using last_green with bazelisk also shows the same error (when I ran this last_green was cd4bc7c).

Have you found anything relevant by searching the web?

#8672 has a similar problem with fully_static_link, but this also statically links glibc, which we don't want. The solution there also depends on setting BAZEL_LINKLIBS but we'd like to be able to control which targets link libstdc++ statically individually. static_link_cpp_runtimes is also compiler-independent (if supported by the toolchain), unlike BAZEL_LINKLIBS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3We're not considering working on this, but happy to review a PR. (No assignee)staleIssues or PRs that are stale (no activity for 30 days)team-Rules-CPPIssues for C++ rulestype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions