summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-24 15:10:38 -0400
committerRuss Cox <rsc@golang.org>2014-09-24 15:10:38 -0400
commit4e8210feb144f2ebb74c56815059c69b5b629f4e (patch)
tree56598ace354e0b5fec90c62e24701d5adc7e3c16
parent12704ddfa78b72fba74cac169f421cb6c61197be (diff)
downloadgo-4e8210feb144f2ebb74c56815059c69b5b629f4e.tar.gz
cmd/go: prohibit C sources files unless using cgo
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://codereview.appspot.com/149720043
-rw-r--r--misc/cgo/test/backdoor/backdoor.go3
-rw-r--r--misc/cgo/test/backdoor/backdoor_gccgo.go11
-rw-r--r--misc/cgo/test/backdoor/runtime.c18
-rw-r--r--misc/cgo/test/issue7695_test.go30
-rw-r--r--src/cmd/go/pkg.go10
-rwxr-xr-xsrc/cmd/go/test.bash14
-rw-r--r--src/cmd/go/testdata/src/badc/x.c1
-rw-r--r--src/cmd/go/testdata/src/badc/x.go1
-rw-r--r--src/net/empty.s (renamed from src/net/empty.c)0
-rw-r--r--src/runtime/debug/debug.s (renamed from src/runtime/debug/debug.c)0
10 files changed, 27 insertions, 61 deletions
diff --git a/misc/cgo/test/backdoor/backdoor.go b/misc/cgo/test/backdoor/backdoor.go
index 7398772bd..3a973494b 100644
--- a/misc/cgo/test/backdoor/backdoor.go
+++ b/misc/cgo/test/backdoor/backdoor.go
@@ -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
index 514f76ec5..000000000
--- a/misc/cgo/test/backdoor/backdoor_gccgo.go
+++ /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
index 87ee44eb6..000000000
--- a/misc/cgo/test/backdoor/runtime.c
+++ /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
index de2fc03d4..000000000
--- a/misc/cgo/test/issue7695_test.go
+++ /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)
- }
-}
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index 63875aed5..4bbcc2b97 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -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 {
diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash
index 13886e158..9ae17e105 100755
--- a/src/cmd/go/test.bash
+++ b/src/cmd/go/test.bash
@@ -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
index 000000000..f6cbf6924
--- /dev/null
+++ b/src/cmd/go/testdata/src/badc/x.c
@@ -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
index 000000000..bfa1de28b
--- /dev/null
+++ b/src/cmd/go/testdata/src/badc/x.go
@@ -0,0 +1 @@
+package badc
diff --git a/src/net/empty.c b/src/net/empty.s
index a515c2fe2..a515c2fe2 100644
--- a/src/net/empty.c
+++ b/src/net/empty.s
diff --git a/src/runtime/debug/debug.c b/src/runtime/debug/debug.s
index a7292c477..a7292c477 100644
--- a/src/runtime/debug/debug.c
+++ b/src/runtime/debug/debug.s