From: Ian Lance Taylor Date: Wed, 13 Jun 2018 22:49:52 +0000 (-0700) Subject: cmd/cgo: add import path to hash X-Git-Tag: go1.11beta1~102 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3a7cbfaa40e91e22a8857cfc1132110b2265ce3d;p=gostls13.git cmd/cgo: add import path to hash This avoids name conflicts when two identical packages use cgo. This can happen in practice when the same package is vendored multiple times in a single build. Fixes #23555 Change-Id: I9f0ec6db9165dcf9cdf3d314c668fee8ada18f9c Reviewed-on: https://go-review.googlesource.com/118739 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/misc/cgo/test/issue23555.go b/misc/cgo/test/issue23555.go new file mode 100644 index 0000000000..5fa44e6355 --- /dev/null +++ b/misc/cgo/test/issue23555.go @@ -0,0 +1,11 @@ +// Copyright 2018 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. + +// Test that we can have two identical cgo packages in a single binary. +// No runtime test; just make sure it compiles. + +package cgotest + +import _ "./issue23555a" +import _ "./issue23555b" diff --git a/misc/cgo/test/issue23555a/a.go b/misc/cgo/test/issue23555a/a.go new file mode 100644 index 0000000000..cb6626bb2b --- /dev/null +++ b/misc/cgo/test/issue23555a/a.go @@ -0,0 +1,12 @@ +// Copyright 2018 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. + +package issue23555 + +// #include +import "C" + +func X() { + C.free(C.malloc(10)) +} diff --git a/misc/cgo/test/issue23555b/a.go b/misc/cgo/test/issue23555b/a.go new file mode 100644 index 0000000000..cb6626bb2b --- /dev/null +++ b/misc/cgo/test/issue23555b/a.go @@ -0,0 +1,12 @@ +// Copyright 2018 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. + +package issue23555 + +// #include +import "C" + +func X() { + C.free(C.malloc(10)) +} diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index ce20948cbe..246898ab77 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -17,6 +17,7 @@ import ( "go/ast" "go/printer" "go/token" + "io" "io/ioutil" "os" "path/filepath" @@ -279,6 +280,7 @@ func main() { // concern is other cgo wrappers for the same functions. // Use the beginning of the md5 of the input to disambiguate. h := md5.New() + io.WriteString(h, *importPath) fs := make([]*File, len(goFiles)) for i, input := range goFiles { if *srcDir != "" {