aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2014-04-29 08:53:38 -0400
committerIan Lance Taylor <iant@golang.org>2014-04-29 08:53:38 -0400
commitfee51f45ab37c77ad8b7967b091ddf19d4e259a3 (patch)
treea6150c46b0afc1acf267f60376a8ea5f9eb1434f /src
parent382cc8cb398c011a1701c410b747f1e80fa66687 (diff)
downloadgo-fee51f45ab37c77ad8b7967b091ddf19d4e259a3.tar.xz
cmd/cgo: for gccgo add #define to cgo_export.h for expected name
For gccgo we rename exported functions so that the compiler will make them visible. This CL adds a #define so that C functions that #include "cgo_export.h" can use the expected names of the function. The test for this is the existing issue6833 test in misc/cgo/test. Without this CL it fails when using -compiler=gccgo. LGTM=minux.ma, rsc R=golang-codereviews, gobot, rsc, minux.ma CC=golang-codereviews https://golang.org/cl/91830046
Diffstat (limited to 'src')
-rw-r--r--src/cmd/cgo/out.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go
index 3f04f13611..a1fc2bd4ff 100644
--- a/src/cmd/cgo/out.go
+++ b/src/cmd/cgo/out.go
@@ -880,10 +880,24 @@ func (p *Package) writeGccgoExports(fgo2, fc, fm *os.File) {
fmt.Fprintf(cdeclBuf, ")")
cParams := cdeclBuf.String()
+ // We need to use a name that will be exported by the
+ // Go code; otherwise gccgo will make it static and we
+ // will not be able to link against it from the C
+ // code.
goName := "Cgoexp_" + exp.ExpName
fmt.Fprintf(fgcch, `extern %s %s %s __asm__("%s.%s");`, cRet, goName, cParams, gccgoSymbolPrefix, goName)
fmt.Fprint(fgcch, "\n")
+ // Use a #define so that the C code that includes
+ // cgo_export.h will be able to refer to the Go
+ // function using the expected name.
+ fmt.Fprintf(fgcch, "#define %s %s\n", exp.ExpName, goName)
+
+ // Use a #undef in _cgo_export.c so that we ignore the
+ // #define from cgo_export.h, since here we are
+ // defining the real function.
+ fmt.Fprintf(fgcc, "#undef %s\n", exp.ExpName)
+
fmt.Fprint(fgcc, "\n")
fmt.Fprintf(fgcc, "%s %s %s {\n", cRet, exp.ExpName, cParams)
fmt.Fprint(fgcc, "\t")