Skip to content

Commit 4e61c51

Browse files
committed
cmd/cgo: fix a problem with 'go build -compiler gccgo'
Port of https://golang.org/cl/154360045 to Git. Original author is Xia Bin <[email protected]> (already a contributor). Fixes #8945. Change-Id: I28bcaf3348794202ca59fbc3466bd7b9670030e4 Reviewed-on: https://go-review.googlesource.com/11658 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 840965f commit 4e61c51

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

misc/cgo/test/issue8945.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 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+
// +build gccgo
6+
7+
package cgotest
8+
9+
//typedef void (*PFunc)();
10+
//PFunc success_cb;
11+
import "C"
12+
13+
//export Test
14+
func Test() {
15+
_ = C.success_cb
16+
}

src/cmd/cgo/out.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ func (p *Package) writeDefs() {
118118
}
119119

120120
if !cVars[n.C] {
121-
fmt.Fprintf(fm, "extern char %s[];\n", n.C)
122-
fmt.Fprintf(fm, "void *_cgohack_%s = %s;\n\n", n.C, n.C)
123121
if *gccgo {
124122
fmt.Fprintf(fc, "extern byte *%s;\n", n.C)
125123
} else {
124+
fmt.Fprintf(fm, "extern char %s[];\n", n.C)
125+
fmt.Fprintf(fm, "void *_cgohack_%s = %s;\n\n", n.C, n.C)
126126
fmt.Fprintf(fgo2, "//go:linkname __cgo_%s %s\n", n.C, n.C)
127127
fmt.Fprintf(fgo2, "//go:cgo_import_static %s\n", n.C)
128128
fmt.Fprintf(fgo2, "var __cgo_%s byte\n", n.C)

0 commit comments

Comments
 (0)