]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: prohibit C sources files unless using cgo
authorRuss Cox <rsc@golang.org>
Wed, 24 Sep 2014 19:10:38 +0000 (15:10 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 24 Sep 2014 19:10:38 +0000 (15:10 -0400)
Those C files would have been compiled with 6c.
It's close to impossible to use C correctly anymore,
and the C compilers are going away eventually.
Make them unavailable now.

go1.4.txt change in CL 145890046

LGTM=iant
R=iant
CC=golang-codereviews, r
https://golang.org/cl/149720043

misc/cgo/test/backdoor/backdoor.go
misc/cgo/test/backdoor/backdoor_gccgo.go [deleted file]
misc/cgo/test/backdoor/runtime.c [deleted file]
misc/cgo/test/issue7695_test.go [deleted file]
src/cmd/go/pkg.go
src/cmd/go/test.bash
src/cmd/go/testdata/src/badc/x.c [new file with mode: 0644]
src/cmd/go/testdata/src/badc/x.go [new file with mode: 0644]
src/net/empty.s [moved from src/net/empty.c with 100% similarity]
src/runtime/debug/debug.s [moved from src/runtime/debug/debug.c with 100% similarity]

index 7398772bd27484597c12b9a071d3bada1f629b9f..3a973494bc1b611cd62ad5f3459f2ef8aab6790e 100644 (file)
@@ -4,5 +4,4 @@
 
 package backdoor
 
-func LockedOSThread() bool // in runtime.c
-func Issue7695(x1, x2, x3, x4, x5, x6, x7, x8 uintptr)
+func LockedOSThread() bool // in thunk.s
diff --git a/misc/cgo/test/backdoor/backdoor_gccgo.go b/misc/cgo/test/backdoor/backdoor_gccgo.go
deleted file mode 100644 (file)
index 514f76e..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2014 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This is the gccgo version of the stub in runtime.c.
-
-// +build gccgo
-
-package backdoor
-
-func Issue7695(x1, x2, x3, x4, x5, x6, x7, x8 uintptr) {}
diff --git a/misc/cgo/test/backdoor/runtime.c b/misc/cgo/test/backdoor/runtime.c
deleted file mode 100644 (file)
index 87ee44e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2011 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// Expose some runtime functions for testing.
-// Must be in a non-cgo-using package so that
-// the go command compiles this file with 6c, not gcc.
-
-// +build gc
-
-typedef char bool;
-
-// This is what a cgo-compiled stub declaration looks like.
-void
-·Issue7695(struct{void *y[8*sizeof(void*)];}p)
-{
-       USED(p);
-}
diff --git a/misc/cgo/test/issue7695_test.go b/misc/cgo/test/issue7695_test.go
deleted file mode 100644 (file)
index de2fc03..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2014 The Go Authors.  All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build ignore
-// This test depends on running C code on Go stacks. Not allowed anymore.
-
-// Demo of deferred C function with untrue prototype
-// breaking stack copying. See golang.org/issue/7695.
-
-package cgotest
-
-import (
-       "testing"
-
-       "./backdoor"
-)
-
-func TestIssue7695(t *testing.T) {
-       defer backdoor.Issue7695(1, 0, 2, 0, 0, 3, 0, 4)
-       recurse(100)
-}
-
-func recurse(n int) {
-       var x [128]int
-       n += x[0]
-       if n > 0 {
-               recurse(n - 1)
-       }
-}
index 63875aed5a96b56bca697b4dce0989a5f68a9a9a..4bbcc2b97174e3cb1726e842bd76147374efd4d1 100644 (file)
@@ -614,6 +614,16 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
        }
        p.Target = p.target
 
+       // Check for C code compiled with Plan 9 C compiler.
+       // No longer allowed except in runtime and runtime/cgo, for now.
+       if len(p.CFiles) > 0 && !p.usesCgo() && (!p.Standard || p.ImportPath != "runtime") {
+               p.Error = &PackageError{
+                       ImportStack: stk.copy(),
+                       Err:         fmt.Sprintf("C source files not allowed when not using cgo: %s", strings.Join(p.CFiles, " ")),
+               }
+               return p
+       }
+
        // In the absence of errors lower in the dependency tree,
        // check for case-insensitive collisions of import paths.
        if len(p.DepsErrors) == 0 {
index 13886e158b9ad46d400f2461e8f2a6a68c667cf6..9ae17e1054598d7049b72d93206fe2b931cf18de 100755 (executable)
@@ -157,6 +157,20 @@ fi
 rm -f ./testdata/err
 unset GOPATH
 
+export GOPATH=$(pwd)/testdata/src
+TEST disallowed C source files
+export GOPATH=$(pwd)/testdata
+if ./testgo build badc 2>testdata/err; then
+       echo 'go build badc succeeded'
+       ok=false
+elif ! grep 'C source files not allowed' testdata/err >/dev/null; then
+       echo 'go test did not say C source files not allowed:'
+       cat testdata/err
+       ok=false
+fi
+rm -f ./testdata/err
+unset GOPATH
+
 TEST error message for syntax error in test go file says FAIL
 export GOPATH=$(pwd)/testdata
 if ./testgo test syntaxerror 2>testdata/err; then
diff --git a/src/cmd/go/testdata/src/badc/x.c b/src/cmd/go/testdata/src/badc/x.c
new file mode 100644 (file)
index 0000000..f6cbf69
--- /dev/null
@@ -0,0 +1 @@
+// C code!
diff --git a/src/cmd/go/testdata/src/badc/x.go b/src/cmd/go/testdata/src/badc/x.go
new file mode 100644 (file)
index 0000000..bfa1de2
--- /dev/null
@@ -0,0 +1 @@
+package badc
similarity index 100%
rename from src/net/empty.c
rename to src/net/empty.s