Skip to content

Commit

Permalink
When linking mostly-static Linux binaries, link libstdc++.a explicitly.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmillikin-stripe committed Nov 6, 2017
1 parent 67c84b1 commit b2bfb3f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tools/cpp/CROSSTOOL
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,23 @@ toolchain {
tool_path { name: "dwp" path: "/usr/bin/dwp" }
tool_path { name: "gcc" path: "/usr/bin/gcc" }
cxx_flag: "-std=c++0x"
linker_flag: "-lstdc++"
linker_flag: "-B/usr/bin/"

# `-static-libstdc++` is only supported when invoking GCC as `g++`, and
# `-lstdc++` forces dynamic linking of libstdc++. To get desired
# mostly-static behavior, invoke the link by explicitly naming a static
# library archive.
#
# https://github.com/bazelbuild/bazel/issues/2840
linking_mode_flags {
mode: DYNAMIC
linker_flag: "-lstdc++"
}
linking_mode_flags {
mode: MOSTLY_STATIC
linker_flag: "-l:libstdc++.a"
}

# TODO(bazel-team): In theory, the path here ought to exactly match the path
# used by gcc. That works because bazel currently doesn't track files at
# absolute locations and has no remote execution, yet. However, this will need
Expand Down

0 comments on commit b2bfb3f

Please sign in to comment.