]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: fix a problem with 'go build -compiler gccgo'
authorRuss Cox <rsc@golang.org>
Mon, 29 Jun 2015 03:04:05 +0000 (23:04 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 29 Jun 2015 15:15:59 +0000 (15:15 +0000)
Port of https://golang.org/cl/154360045 to Git.
Original author is Xia Bin <snyh@snyh.org> (already a contributor).

Fixes #8945.

Change-Id: I28bcaf3348794202ca59fbc3466bd7b9670030e4
Reviewed-on: https://go-review.googlesource.com/11658
Reviewed-by: Ian Lance Taylor <iant@golang.org>
misc/cgo/test/issue8945.go [new file with mode: 0644]
src/cmd/cgo/out.go

diff --git a/misc/cgo/test/issue8945.go b/misc/cgo/test/issue8945.go
new file mode 100644 (file)
index 0000000..572b815
--- /dev/null
@@ -0,0 +1,16 @@
+// 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 gccgo
+
+package cgotest
+
+//typedef void (*PFunc)();
+//PFunc success_cb;
+import "C"
+
+//export Test
+func Test() {
+       _ = C.success_cb
+}
index 0308242c5f3d4f4134d426a0f7610f1bb73d055a..3edb70345d337d045b0d97fdae44c840b4e68f17 100644 (file)
@@ -118,11 +118,11 @@ func (p *Package) writeDefs() {
                }
 
                if !cVars[n.C] {
-                       fmt.Fprintf(fm, "extern char %s[];\n", n.C)
-                       fmt.Fprintf(fm, "void *_cgohack_%s = %s;\n\n", n.C, n.C)
                        if *gccgo {
                                fmt.Fprintf(fc, "extern byte *%s;\n", n.C)
                        } else {
+                               fmt.Fprintf(fm, "extern char %s[];\n", n.C)
+                               fmt.Fprintf(fm, "void *_cgohack_%s = %s;\n\n", n.C, n.C)
                                fmt.Fprintf(fgo2, "//go:linkname __cgo_%s %s\n", n.C, n.C)
                                fmt.Fprintf(fgo2, "//go:cgo_import_static %s\n", n.C)
                                fmt.Fprintf(fgo2, "var __cgo_%s byte\n", n.C)