diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index 51fb442..d66cacf 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -2985,6 +2985,14 @@
flagSources := []string{"CGO_CFLAGS", "CGO_CXXFLAGS", "CGO_FFLAGS"}
flagLists := [][]string{cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS}
notCompatibleWithInternalLinking := flagsNotCompatibleWithInternalLinking(flagSources, flagLists)
+ if !notCompatibleWithInternalLinking {
+ for _, f := range cgoLDFLAGS {
+ if f == "-static" {
+ notCompatibleWithInternalLinking = true
+ break
+ }
+ }
+ }
if cfg.BuildMSan {
cgoCFLAGS = append([]string{"-fsanitize=memory"}, cgoCFLAGS...)
diff --git a/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt b/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt
index b4b2d14..3e6e989 100644
--- a/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt
+++ b/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt
@@ -91,6 +91,12 @@
! stderr preferlinkext
env CGO_CFLAGS=
+# CGO_LDFLAGS=-static is not compatible with internal linking.
+env CGO_LDFLAGS=-static
+go build -x -n -o dummy.exe ./usesInternalCgo
+stderr preferlinkext
+env CGO_LDFLAGS=
+
[short] skip
# In the remaining tests below we do actual builds (without -n) to