diff --git a/go/private/actions/link.bzl b/go/private/actions/link.bzl index e919e3db92..3a1af2863f 100644 --- a/go/private/actions/link.bzl +++ b/go/private/actions/link.bzl @@ -78,7 +78,7 @@ def emit_link( # Exclude -lstdc++ from link options. We don't want to link against it # unless we actually have some C++ code. _cgo_codegen will include it # in archives via CGO_LDFLAGS if it's needed. - extldflags = [f for f in extldflags_from_cc_toolchain(go) if f not in ("-lstdc++", "-lc++")] + extldflags = [f for f in extldflags_from_cc_toolchain(go) if f not in ("-lstdc++", "-lc++", "-static")] if go.coverage_enabled: extldflags.append("--coverage") diff --git a/go/private/actions/stdlib.bzl b/go/private/actions/stdlib.bzl index c80fbeb3ec..1011404e7c 100644 --- a/go/private/actions/stdlib.bzl +++ b/go/private/actions/stdlib.bzl @@ -94,10 +94,11 @@ def _build_env(go): # go std library doesn't use C++, so should not have -lstdc++ # Also drop coverage flags as nothing in the stdlib is compiled with # coverage - we disable it for all CGo code anyway. + # NOTE(#3590): avoid forcing static linking. ldflags = [ option for option in extldflags_from_cc_toolchain(go) - if option not in ("-lstdc++", "-lc++") and option not in COVERAGE_OPTIONS_DENYLIST + if option not in ("-lstdc++", "-lc++", "-static") and option not in COVERAGE_OPTIONS_DENYLIST ] env.update({ "CGO_ENABLED": "1",