-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fully_static_link is broken #8672
Comments
cc @hlopko |
@hlopko We're also having this problem. We need fully static binaries because of sandbox policies. My repro case, slightly modified
|
One way to link this with the C compiler is to wrap libstdc++ with the |
gcc is not a problem, you'll get your libstdc++ linked statically when you pass -static-libstdc++ and -l:libstdc++.a. The problem is how to put these flags in the right places on the command line. With Bazel 0.28 you'll be able to use BAZEL_LINKLIBS env var to set flags that will go after default link flags, after libraries to link, and after user link flags. That will allow you to link libstdc++ statically for the entire build. If you need to decide on a per |
Ok, but then I can't easily switch compilers to Clang, for example.
This is actually not what I'm after. I only need a few targets to be fully statically linked.
How so? It did seem to work (at least for us) in earlier releases (0.25.0 IIRC). Are there examples for using |
|
Re 3., kinda. Our build broke, once I updated our Docker container to the latest Bazel :) Ok, so for now I'll work around the issue. I just really want people to be able to clone our repo (Sandboxed API) and just do a |
This is tracked at bazelbuild/bazel#8672 and should only affect the tests for now. PiperOrigin-RevId: 254943708 Change-Id: Iee18a3b8c1b570c7d04d09d533ecff33c3de7d57
Interesting. And are you sure libstdc++ was linked statically before? |
Yes. Full example: touch WORKSPACE
cat <<EOF> BUILD.bazel
[cc_binary(
name = "with" + ("out" if not opt else "") + "_linkopts",
srcs = ["a.cc"],
features = [
"-pie",
"fully_static_link", # link libc statically
],
linkopts = ["-l:libstdc++.a"] if not opt else [],
linkstatic = 1, # prefer static libraries
) for opt in [
True,
False,
]]
EOF
printf '#include <cstdio>\nint main() { new int; printf("hi!\\n"); }\n' > a.cc Then, to reproduce with Bazelisk: for ver in 0.25.0 0.26.0 0.27.0; do
echo "$ver ========================="
USE_BAZEL_VERSION=$ver bazelisk clean
USE_BAZEL_VERSION=$ver bazelisk build :all
ldd bazel-bin/with{_,out_}linkopts
done Output is:
|
Does this example help? |
I didn't have time to look into it, and I'll be out of office for a month soon. So unless @scentini or @oquenchil won't investigate in the meantime our of their own interest, I'll only take a look after the leave. I'm sorry for that. Since you already have a nice repro test, would you mind bisecting Bazel commits to find the culprit? That would speed up fixing this tremendously. |
Just wondering what the status of this issue. Is there a plan to fix it. |
For who has the same problem, I put the following flags in
This will statically link libc++ and libgcc, dynamically link libc and libm, and be ABI compatible with most linux distros. |
It seems odd that this is a P3 when there is a significant number of projects affected by this, including Envoy (they have a local workaround). I was able to build statically with this:
It should be straightforward to fix |
(To be clear, my proprietary project is also affected. We have a case where we'd like to link statically and I just spent ~an hour to figure out how to do it.) |
I thought this was fixed by |
Cool! Yeah, that seems to work. Rollout bug is #10905, which seems to be scheduled for 4.0. |
If this is still an issue, please re-open. |
This is tracked at bazelbuild/bazel#8672 and should only affect the tests for now. PiperOrigin-RevId: 254943708 Change-Id: Iee18a3b8c1b570c7d04d09d533ecff33c3de7d57
Description of the problem / feature request:
fully_static_link
is broken.Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
WORKSPACE
BUILD
a.cc
Build command and output:
What operating system are you running Bazel on?
Linux
What's the output of
bazel info release
?release 0.27.0
Any other information, logs, or outputs that you want to share?
Could you also share the state-of-the-art way of doing mostly static build? That is, linking
libc
andlibm
dynamically while linking other libraries (includinglibstdc++
) statically?The text was updated successfully, but these errors were encountered: