]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: detect Go assembly before assembling with gcc
authorRuss Cox <rsc@golang.org>
Thu, 22 Jun 2017 20:11:10 +0000 (16:11 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 23 Jun 2017 00:21:06 +0000 (00:21 +0000)
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>
src/cmd/go/go_test.go
src/cmd/go/internal/work/build.go
src/cmd/go/testdata/src/cgoasm/p.go [new file with mode: 0644]
src/cmd/go/testdata/src/cgoasm/p.s [new file with mode: 0644]

index e7fc5fc1038be56c5c81296d1860805099b05d21..71b34b6ec47a4421b769323fe9431124b4e48299 100644 (file)
@@ -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")
index a7949b6ff35a547623d443c7ecdac4185b2fa040..d03ad3e139bf0a895bfecbbeee7c882de979df27 100644 (file)
@@ -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 (file)
index 0000000..148b47f
--- /dev/null
@@ -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 (file)
index 0000000..aaade03
--- /dev/null
@@ -0,0 +1,2 @@
+TEXT asm(SB),$0
+       RET