mirror of
https://github.com/golang/go
synced 2024-11-18 03:04:45 -07:00
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>
This commit is contained in:
parent
53e4b8fc02
commit
a6df299e89
@ -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")
|
||||
|
@ -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
|
||||
}
|
||||
|
8
src/cmd/go/testdata/src/cgoasm/p.go
vendored
Normal file
8
src/cmd/go/testdata/src/cgoasm/p.go
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
package p
|
||||
|
||||
/*
|
||||
// hi
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func F() {}
|
2
src/cmd/go/testdata/src/cgoasm/p.s
vendored
Normal file
2
src/cmd/go/testdata/src/cgoasm/p.s
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
TEXT asm(SB),$0
|
||||
RET
|
Loading…
Reference in New Issue
Block a user