mirror of https://github.com/golang/go.git
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://golang.org/cl/149720043
This commit is contained in:
parent
6f219e8b84
commit
a0785a53ad
|
|
@ -4,5 +4,4 @@
|
||||||
|
|
||||||
package backdoor
|
package backdoor
|
||||||
|
|
||||||
func LockedOSThread() bool // in runtime.c
|
func LockedOSThread() bool // in thunk.s
|
||||||
func Issue7695(x1, x2, x3, x4, x5, x6, x7, x8 uintptr)
|
|
||||||
|
|
|
||||||
|
|
@ -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) {}
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -614,6 +614,16 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
|
||||||
}
|
}
|
||||||
p.Target = p.target
|
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,
|
// In the absence of errors lower in the dependency tree,
|
||||||
// check for case-insensitive collisions of import paths.
|
// check for case-insensitive collisions of import paths.
|
||||||
if len(p.DepsErrors) == 0 {
|
if len(p.DepsErrors) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,20 @@ fi
|
||||||
rm -f ./testdata/err
|
rm -f ./testdata/err
|
||||||
unset GOPATH
|
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
|
TEST error message for syntax error in test go file says FAIL
|
||||||
export GOPATH=$(pwd)/testdata
|
export GOPATH=$(pwd)/testdata
|
||||||
if ./testgo test syntaxerror 2>testdata/err; then
|
if ./testgo test syntaxerror 2>testdata/err; then
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
// C code!
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
package badc
|
||||||
Loading…
Reference in New Issue