Skip to content

Commit 265b917

Browse files
author
Jay Conrod
authored
go: add comment on why external linking is needed (bazel-contrib#2630)
For bazel-contrib#2614
1 parent 384d290 commit 265b917

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

go/private/actions/link.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def emit_link(
7777
if ((go.mode.static and not go.mode.pure) or
7878
go.mode.link != LINKMODE_NORMAL or
7979
go.mode.goos == "windows" and (go.mode.race or go.mode.msan)):
80+
# Force external linking for the following conditions:
81+
# * Mode is static but not pure: -static must be passed to the C
82+
# linker if the binary contains cgo code. See #2168, #2216.
83+
# * Non-normal build mode: may not be strictly necessary, especially
84+
# for modes like "pie".
85+
# * Race or msan build for Windows: Go linker has pairwise
86+
# incompatibilities with mingw, and we get link errors in race mode.
87+
# Using the C linker avoids that. Race and msan always require a
88+
# a C toolchain. See #2614.
8089
tool_args.add("-linkmode", "external")
8190
if go.mode.static:
8291
extldflags.append("-static")

0 commit comments

Comments
 (0)