From 0deb49f9c09d15bf0e4c5ec843bd374f9a377e97 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 13 Jun 2016 11:55:30 -0700 Subject: [PATCH] cmd/go: include .syso files even if CGO_ENABLED=0 A .syso file may include information that should go into the object file that is not object code, and should be included even if not using cgo. The example in the issue is a Windows manifest file. Fixes #16050. Change-Id: I1f4f3f80bb007e84d153ca2d26e5919213ea4f8d Reviewed-on: https://go-review.googlesource.com/24032 Run-TryBot: Ian Lance Taylor Reviewed-by: Alex Brainman --- src/cmd/go/go_test.go | 22 ++++++++++++++++++++++ src/cmd/go/pkg.go | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index c46e0c7da5..a6c70d97b6 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -2898,3 +2898,25 @@ func TestBinaryOnlyPackages(t *testing.T) { tg.run("run", tg.path("src/p3/p3.go")) tg.grepStdout("hello from p1", "did not see message from p1") } + +// Issue 16050. +func TestAlwaysLinkSysoFiles(t *testing.T) { + tg := testgo(t) + defer tg.cleanup() + tg.parallel() + tg.tempDir("src/syso") + tg.tempFile("src/syso/a.syso", ``) + tg.tempFile("src/syso/b.go", `package syso`) + tg.setenv("GOPATH", tg.path(".")) + + // We should see the .syso file regardless of the setting of + // CGO_ENABLED. + + tg.setenv("CGO_ENABLED", "1") + tg.run("list", "-f", "{{.SysoFiles}}", "syso") + tg.grepStdout("a.syso", "missing syso file with CGO_ENABLED=1") + + tg.setenv("CGO_ENABLED", "0") + tg.run("list", "-f", "{{.SysoFiles}}", "syso") + tg.grepStdout("a.syso", "missing syso file with CGO_ENABLED=0") +} diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go index ee3f403dd6..07aa3ff2bc 100644 --- a/src/cmd/go/pkg.go +++ b/src/cmd/go/pkg.go @@ -1022,9 +1022,10 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package p.MFiles = nil p.SwigFiles = nil p.SwigCXXFiles = nil - p.SysoFiles = nil // Note that SFiles are okay (they go to the Go assembler) // and HFiles are okay (they might be used by the SFiles). + // Also Sysofiles are okay (they might not contain object + // code; see issue #16050). } // The gc toolchain only permits C source files with cgo. -- 2.50.0