go: add comment on why external linking is needed (#2630)
For #2614
diff --git a/go/private/actions/link.bzl b/go/private/actions/link.bzl
index 1b38350..afbd64d 100644
--- a/go/private/actions/link.bzl
+++ b/go/private/actions/link.bzl
@@ -77,6 +77,15 @@
if ((go.mode.static and not go.mode.pure) or
go.mode.link != LINKMODE_NORMAL or
go.mode.goos == "windows" and (go.mode.race or go.mode.msan)):
+ # Force external linking for the following conditions:
+ # * Mode is static but not pure: -static must be passed to the C
+ # linker if the binary contains cgo code. See #2168, #2216.
+ # * Non-normal build mode: may not be strictly necessary, especially
+ # for modes like "pie".
+ # * Race or msan build for Windows: Go linker has pairwise
+ # incompatibilities with mingw, and we get link errors in race mode.
+ # Using the C linker avoids that. Race and msan always require a
+ # a C toolchain. See #2614.
tool_args.add("-linkmode", "external")
if go.mode.static:
extldflags.append("-static")