Skip to content

Commit 3a7cbfa

Browse files
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 <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 7bc99ff commit 3a7cbfa

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

misc/cgo/test/issue23555.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Test that we can have two identical cgo packages in a single binary.
6+
// No runtime test; just make sure it compiles.
7+
8+
package cgotest
9+
10+
import _ "./issue23555a"
11+
import _ "./issue23555b"

misc/cgo/test/issue23555a/a.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package issue23555
6+
7+
// #include <stdlib.h>
8+
import "C"
9+
10+
func X() {
11+
C.free(C.malloc(10))
12+
}

misc/cgo/test/issue23555b/a.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package issue23555
6+
7+
// #include <stdlib.h>
8+
import "C"
9+
10+
func X() {
11+
C.free(C.malloc(10))
12+
}

src/cmd/cgo/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"go/ast"
1818
"go/printer"
1919
"go/token"
20+
"io"
2021
"io/ioutil"
2122
"os"
2223
"path/filepath"
@@ -279,6 +280,7 @@ func main() {
279280
// concern is other cgo wrappers for the same functions.
280281
// Use the beginning of the md5 of the input to disambiguate.
281282
h := md5.New()
283+
io.WriteString(h, *importPath)
282284
fs := make([]*File, len(goFiles))
283285
for i, input := range goFiles {
284286
if *srcDir != "" {

0 commit comments

Comments
 (0)