summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorEyal Soha <eyalsoha@google.com>2020-03-20 18:22:49 -0700
committergVisor bot <gvisor-bot@google.com>2020-03-20 18:24:00 -0700
commitfed59953aad40d89730ebfc6f33b17116c42abcf (patch)
tree38976c8f7d58071cb3184dabc47a824c50aacc41 /tools
parentd5fe1ce0c1c551c3165632eecc0ea5589c049bd5 (diff)
Statically link libpthread for static c++ binaries.
The posix_server works fine when run in locally or in docker but fails in the kokoro GCP build environment. Linking libpthread statically fixes it. PiperOrigin-RevId: 302139082
Diffstat (limited to 'tools')
-rw-r--r--tools/bazeldefs/defs.bzl15
1 files changed, 11 insertions, 4 deletions
diff --git a/tools/bazeldefs/defs.bzl b/tools/bazeldefs/defs.bzl
index 64171ad8d..0a74370a6 100644
--- a/tools/bazeldefs/defs.bzl
+++ b/tools/bazeldefs/defs.bzl
@@ -65,10 +65,17 @@ def cc_binary(name, static = False, **kwargs):
**kwargs: the rest of the args.
"""
if static:
- if "linkopts" in kwargs:
- kwargs["linkopts"] += ["-static", "-lstdc++"]
- else:
- kwargs["linkopts"] = ["-static", "-lstdc++"]
+ # How to statically link a c++ program that uses threads, like for gRPC:
+ # https://gcc.gnu.org/legacy-ml/gcc-help/2010-05/msg00029.html
+ if "linkopts" not in kwargs:
+ kwargs["linkopts"] = []
+ kwargs["linkopts"] += [
+ "-static",
+ "-lstdc++",
+ "-Wl,--whole-archive",
+ "-lpthread",
+ "-Wl,--no-whole-archive",
+ ]
_cc_binary(
name = name,
**kwargs