aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2017-06-22 16:11:10 -0400
committerRuss Cox <rsc@golang.org>2017-06-23 00:21:06 +0000
commita6df299e89f6ba56d71571f694fb7327294ae72e (patch)
tree9a70d2647950e1eb046ee52234e2cf61ca0ebedc
parent53e4b8fc02bb9440a35b20f383c0bc86eece80a6 (diff)
downloadgo-a6df299e89f6ba56d71571f694fb7327294ae72e.tar.gz
go-a6df299e89f6ba56d71571f694fb7327294ae72e.zip
cmd/go: detect Go assembly before assembling with gcc
Avoids confusing errors from the GNU assembler processing Go assembly source code. Fixes #19448. Change-Id: Ic2c68b2521847cca5a3d078a092e5c60ec340840 Reviewed-on: https://go-review.googlesource.com/46423 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r--src/cmd/go/go_test.go13
-rw-r--r--src/cmd/go/internal/work/build.go10
-rw-r--r--src/cmd/go/testdata/src/cgoasm/p.go8
-rw-r--r--src/cmd/go/testdata/src/cgoasm/p.s2
4 files changed, 33 insertions, 0 deletions
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index e7fc5fc103..71b34b6ec4 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -2310,6 +2310,19 @@ func TestCoverageWithCgo(t *testing.T) {
}
}
+func TestCgoAsmError(t *testing.T) {
+ if !canCgo {
+ t.Skip("skipping because cgo not enabled")
+ }
+
+ tg := testgo(t)
+ tg.parallel()
+ defer tg.cleanup()
+ tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+ tg.runFail("build", "cgoasm")
+ tg.grepBoth("package using cgo has Go assembly file", "did not detect Go assembly file")
+}
+
func TestCgoDependsOnSyscall(t *testing.T) {
if testing.Short() {
t.Skip("skipping test that removes $GOROOT/pkg/*_race in short mode")
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index a7949b6ff3..d03ad3e139 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -1333,6 +1333,16 @@ func (b *Builder) build(a *Action) (err error) {
}
sfiles, gccfiles = filter(sfiles, sfiles[:0], gccfiles)
} else {
+ for _, sfile := range sfiles {
+ data, err := ioutil.ReadFile(filepath.Join(a.Package.Dir, sfile))
+ if err == nil {
+ if bytes.HasPrefix(data, []byte("TEXT")) || bytes.Contains(data, []byte("\nTEXT")) ||
+ bytes.HasPrefix(data, []byte("DATA")) || bytes.Contains(data, []byte("\nDATA")) ||
+ bytes.HasPrefix(data, []byte("GLOBL")) || bytes.Contains(data, []byte("\nGLOBL")) {
+ return fmt.Errorf("package using cgo has Go assembly file %s", sfile)
+ }
+ }
+ }
gccfiles = append(gccfiles, sfiles...)
sfiles = nil
}
diff --git a/src/cmd/go/testdata/src/cgoasm/p.go b/src/cmd/go/testdata/src/cgoasm/p.go
new file mode 100644
index 0000000000..148b47f6a5
--- /dev/null
+++ b/src/cmd/go/testdata/src/cgoasm/p.go
@@ -0,0 +1,8 @@
+package p
+
+/*
+// hi
+*/
+import "C"
+
+func F() {}
diff --git a/src/cmd/go/testdata/src/cgoasm/p.s b/src/cmd/go/testdata/src/cgoasm/p.s
new file mode 100644
index 0000000000..aaade03a43
--- /dev/null
+++ b/src/cmd/go/testdata/src/cgoasm/p.s
@@ -0,0 +1,2 @@
+TEXT asm(SB),$0
+ RET