-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-static-libstdc++ -static-libgcc does not work with MOSTLY STATIC linking #2840
Comments
…c static linking. We import cc_configure.bzl from https://github.com/bazelbuild/bazel at d6fec93 in this patch. This allows us to workaround bazelbuild/bazel#2840 (see the header comment for further details).
…c static linking. (#782) We import cc_configure.bzl from https://github.com/bazelbuild/bazel at d6fec93 in this patch. This allows us to workaround bazelbuild/bazel#2840 (see the header comment for further details).
over to our C++ expert, to triage further |
FTR, our workaround was to fork |
Here's a smaller reproduction than building all of Envoy: #!/bin/bash
set -e
touch WORKSPACE
cat >hello.cc <<EOF
#include <iostream>
int main() {
std::cout << "hello world!\n";
return 0;
}
EOF
cat >BUILD <<EOF
cc_binary(
name="hello",
srcs=["hello.cc"],
linkstatic=1,
linkopts=[
"-static-libstdc++",
"-static-libgcc",
],
)
EOF
bazel build :hello
cp bazel-bin/hello hello-bazel
gcc -c hello.cc -o hello-gcc.o
gcc -o hello-gcc hello-gcc.o -static-libstdc++ -static-libgcc -lstdc++
g++ -o hello-g++ hello-gcc.o -static-libstdc++ -static-libgcc
ldd hello-{bazel,g++,gcc} $ ./test.sh
.
INFO: Found 1 target...
Target //:hello up-to-date:
bazel-bin/hello
INFO: Elapsed time: 4.187s, Critical Path: 0.02s
hello-bazel:
linux-vdso.so.1 => (0x00007ffe0bfda000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f3fb5cb4000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3fb59ab000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3fb55e0000)
/lib64/ld-linux-x86-64.so.2 (0x00005652fdb8e000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f3fb53ca000)
hello-g++:
linux-vdso.so.1 => (0x00007fff9dadc000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f480aea6000)
/lib64/ld-linux-x86-64.so.2 (0x000055c2a4dcf000)
hello-gcc:
linux-vdso.so.1 => (0x00007ffe4f8f1000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe7ae568000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe7ae19e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe7ade94000)
/lib64/ld-linux-x86-64.so.2 (0x0000559b6e494000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe7adc7e000) We can see that Explicitly referencing $ gcc -o hello-gcc-2 hello-gcc.o -static-libgcc -l:libstdc++.a
$ ldd hello-gcc-2
linux-vdso.so.1 => (0x00007ffdc5fdf000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb4b0789000)
/lib64/ld-linux-x86-64.so.2 (0x00005581b559b000) |
This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes bazelbuild#2840 See envoyproxy/envoy#415 for additional background and context.
This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes bazelbuild#2840 See envoyproxy/envoy#415 for additional background and context.
This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes bazelbuild#2840 See envoyproxy/envoy#415 for additional background and context.
This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes bazelbuild#2840 See envoyproxy/envoy#415 for additional background and context.
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: #4474) Fixes #4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes #2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
Can we re-open this, since the fix got rolled back? |
*** Reason for rollback *** Breaks C++ on gcc 4.8.4 (specifically, TensorFlow: bazelbuild#4474) Fixes bazelbuild#4474 *** Original change description *** When linking mostly-static Linux binaries, link libstdc++.a explicitly. This allows libstdc++ to be statically linked, which is normally only possible when invoking GCC as `g++` with the `-static-libstdc++` flag. Fixes bazelbuild#2840 See envoyproxy/envoy#415 for additional background and context. cc @htuch (for Envoy) and @calpeyser @hlopko (who I talked to earlier about this)... *** RELNOTES: None. PiperOrigin-RevId: 182519445
What was the reason for the rollback, and is it something we can resolve soon? |
#4474 was the main culprit. I don't think I will have time in Q2 to fix this. |
I opened PR #6360 with a fix. However, not surprisingly, it breaks several CI tests. If anyone has time to help triage / fix the failures that would be greatly appreciated. |
The PR is merged, I'm closing this issue. Thank you Mark! |
Using this variable is will be possible to specify system libraries that should be added after default linker flags, after libraries to link, and after user link flags (i.e. after --linkopt and `linkopts` rule attribute). Flag separator is `:`, similarly to `BAZEL_LINKOPTS`. Escaping is done by `%`. Default value is empty string. With this it's possible to force Bazel to statically link `libstdc++` by using: ``` BAZEL_LINKOPTS=-static-libstdc++ BAZEL_LINKLIBS=-l%:libstdc++.a bazel build //foo ``` Fixes #2840. Relevant for #8652. RELNOTES: Bazel's C++ autoconfiguration now understands `BAZEL_LINKLIBS` environment variable to specify system libraries that should be appended to the link command line. Closes #8660. PiperOrigin-RevId: 253946433
Using this variable is will be possible to specify system libraries that should be added after default linker flags, after libraries to link, and after user link flags (i.e. after --linkopt and `linkopts` rule attribute). Flag separator is `:`, similarly to `BAZEL_LINKOPTS`. Escaping is done by `%`. Default value is empty string. With this it's possible to force Bazel to statically link `libstdc++` by using: ``` BAZEL_LINKOPTS=-static-libstdc++ BAZEL_LINKLIBS=-l%:libstdc++.a bazel build //foo ``` Fixes bazelbuild#2840. Relevant for bazelbuild#8652. RELNOTES: Bazel's C++ autoconfiguration now understands `BAZEL_LINKLIBS` environment variable to specify system libraries that should be appended to the link command line. Closes bazelbuild#8660. PiperOrigin-RevId: 253946433
Using this variable is will be possible to specify system libraries that should be added after default linker flags, after libraries to link, and after user link flags (i.e. after --linkopt and `linkopts` rule attribute). Flag separator is `:`, similarly to `BAZEL_LINKOPTS`. Escaping is done by `%`. Default value is empty string. With this it's possible to force Bazel to statically link `libstdc++` by using: ``` BAZEL_LINKOPTS=-static-libstdc++ BAZEL_LINKLIBS=-l%:libstdc++.a bazel build //foo ``` Fixes bazelbuild#2840. Relevant for bazelbuild#8652. RELNOTES: Bazel's C++ autoconfiguration now understands `BAZEL_LINKLIBS` environment variable to specify system libraries that should be appended to the link command line. Closes bazelbuild#8660. PiperOrigin-RevId: 253946433
When the
-static-libstdc++ -static-libgcc
flags are supplied aslinkopts
tocc_binary
andlinkstatic = 1
, the resulting binary is still dynamically linked against libgcc/libc++, witness:From the compiler man page, it looks like these flags are only supposed to work under the g++ driver. Even manually rerunning the command under
g++
doesn't fix this. I had to modifybazel-out/local-fastbuild/bin/source/exe/envoy-static-2.params
to remove the-lstdc++
.The Envoy (https://github.com/lyft/envoy/) Bazel build needs this mostly static link, where the Envoy libraries, external deps and standard C/C++ libs are statically linked, but the rest of the system libs are dynamically linked.
Looks like this requires some additional Bazel implementation work to properly support (at least as far as CROSSTOOLS goes, maybe another kind of pseudo-static link type). Are there any suggested workarounds in the meanwhile?
CC: @mattklein123 envoyproxy/envoy#415
The text was updated successfully, but these errors were encountered: