-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Possibly wrong link order / devtoolset-8 libstdc++ unknown symbols #10327
Comments
/cc @hlopko @oquenchil |
The following Dockerfile seems to reproduce the same issue. FROM centos:7
ADD https://copr.fedorainfracloud.org/coprs/vbatts/bazel/repo/epel-7/vbatts-bazel-epel-7.repo /etc/yum.repos.d
RUN yum install -y centos-release-scl
RUN yum install -y \
devtoolset-8 \
git \
wget \
bazel
SHELL [ "scl", "enable", "devtoolset-8"]
RUN git clone https://github.com/google/verible
RUN gcc --version; cd verible; bazel build --cxxopt='-std=c++17' //... The following workaround is effective.
|
Making P2 since there is a workaround. |
There is one more work around which doesn't require statically linking libstdc++. Use a linker script. $ cat > /tmp/linker_hack_for_bazel <<EOF
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
INPUT ( -lstdc++ )
EOF
$ export BAZEL_LINKLIBS="/tmp/linker_hack_for_bazel" This makes sure that |
solve this problem with: |
I do not believe this is fixed: With devtoolset-9, which has the same libstdc++ linker script trickery, it is impossible to build bazel itself, and a look at the link params file for the failing invocation reveals that libstdc++ is still in the wrong order. Steps to repro:
I just verified this with bazel 3.7.2. |
Another egregious hack memorialized: https://github.com/stellaraccident/manylinux-bazel |
@stellaraccident : thank you, you saved my day :D |
You are probably not going to like this one that much.
It seems that bazel + binutils + gcc + redhats devtoolset-8 gets angry regarding
-lstdc++
, this appears to be related to https://bugzilla.redhat.com/show_bug.cgi?id=1570853Recording of the bug
The following is a (long) recording of the bug, and workaround, the following documents it outright
Bazel issues with devtoolset-8 regarding libstdc++
It appears that bazel is adding
-lstdc++
into the linker arguments early in the command line for gcc.This freaks out oddball environments (such as the one provided by the software collections library).
SCL from RedHat provides a linker script in place of
libstdc++
which does some trickery to fake out having an oldlibstdc++
installed on the system, but needing newer symbols for newer C++ features, versions and ABIs. This is seemingly done to allow for cross ABI compatibilityReproducing
I have tested this in the environment we must compile for at
$DAYJOB
, I have not tested using stock RHEL or Centos but I suspect it might be an issue. It could also be a more general problem with link ordering.Any bazel build using C++ will break including bootstrapping bazel itself
Setup a test env with docker
The following should give a test env that can reproduce the issue
... After a while bazel will fail to compile with some C++ linker error, normally complaining about some undefined symbol. The undef symbol will be something deep in
libstdc++
What I think causes this
Looking at a failed link, we find that bazel produces linker args something like so
-o bazel-out/host/bin/external/com_google_protobuf/protoc -Wl,-S -fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/opt/rh/devtoolset-8/root/usr/bin -pass-exit-codes -lstdc++ -lm -Wl,--gc-sections bazel-out/host/bin/external/com_google_protobuf/_objs/protoc/main.o -Wl,--start-lib bazel-out/host/bin/external/com_google_protobuf/_objs/protoc_lib/code_generator.o SNIP SNIP %< ... -Wl,--end-lib -lpthread -lm -lpthread -lm -lpthread -lm
Looking at the file
libstdc++.so
under devtoolkit-8 it looks like soWhich is trickery to, as mentioned above, use ABI hacks, this confuses
ld
and I think removes the special handling forlibstdc++
Moving
libstdc++
to the bottom like so-o bazel-out/host/bin/external/com_google_protobuf/protoc -Wl,-S -fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/opt/rh/devtoolset-8/root/usr/bin -pass-exit-codes -Wl,--gc-sections bazel-out/host/bin/external/com_google_protobuf/_objs/protoc/main.o -Wl,--start-lib bazel-out/host/bin/external/com_google_protobuf/_objs/protoc_lib/code_generator.o SNIP SNIP %< ... -Wl,--end-lib -lpthread -lm -lpthread -lm -lpthread -lm -lstdc++ -lm
Allows for linking
Workaround
A workaround we have found is to export the following
... technically this statically links
libstdc++
and is probably not what some people wantThe text was updated successfully, but these errors were encountered: