[go] cmd/cgo: make dummy definition of wrapper for exported function match declaration

22 views
Skip to first unread message

Michael Hudson-Doyle (Gerrit)

unread,
Mar 28, 2021, 6:48:49 PM3/28/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Michael Hudson-Doyle has uploaded this change for review.

View Change

cmd/cgo: make dummy definition of wrapper for exported function match declaration

Currently, if CGO_CFLAGS enables link time optimization, building a
package that exports a Go function to C fails when compiling _cgo_main.c
i(to determine which libraries to link) because of "errors during
merging of translation units". These errors are complaining about the
fact that the definition provided for the wrapper for the to-be-exported
function in _cgo_main.c looks like this:

int _cgoexp_d1f1f4751b13_authCallbackHelper;

but the declaration in _cgo_export.c looks like this:

extern void _cgoexp_d1f1f4751b13_authCallbackHelper(void *);

So make them match. Of course none of this really matters because the
resulting executable is never even executed but this seemed the easiest
way to fix the build.

Fixes #45275

Change-Id: If1f26ebd146da86f66c3801f653633b5d0e7a746
---
M src/cmd/cgo/out.go
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go
index 8e83f02..571092c 100644
--- a/src/cmd/cgo/out.go
+++ b/src/cmd/cgo/out.go
@@ -1028,7 +1028,7 @@
fmt.Fprintf(fgo2, "//go:cgo_export_static _cgoexp%s_%s\n", cPrefix, exp.ExpName)
fmt.Fprintf(fgo2, "func _cgoexp%s_%s(a *%s) {\n", cPrefix, exp.ExpName, gotype)

- fmt.Fprintf(fm, "int _cgoexp%s_%s;\n", cPrefix, exp.ExpName)
+ fmt.Fprintf(fm, "void _cgoexp%s_%s(void *a) {}\n", cPrefix, exp.ExpName)

if gccResult != "void" {
// Write results back to frame.

To view, visit change 305290. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: If1f26ebd146da86f66c3801f653633b5d0e7a746
Gerrit-Change-Number: 305290
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Hudson-Doyle <michael...@canonical.com>
Gerrit-Reviewer: Michael Hudson-Doyle <michael...@canonical.com>
Gerrit-MessageType: newchange

Michael Hudson-Doyle (Gerrit)

unread,
Mar 28, 2021, 8:15:55 PM3/28/21
to goph...@pubsubhelper.golang.org, Go Bot, golang-co...@googlegroups.com

Michael Hudson-Doyle abandoned this change.

View Change

To view, visit change 305290. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: If1f26ebd146da86f66c3801f653633b5d0e7a746
Gerrit-Change-Number: 305290
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Hudson-Doyle <michael...@canonical.com>
Gerrit-Reviewer: Go Bot <go...@golang.org>
Gerrit-Reviewer: Michael Hudson-Doyle <michael...@canonical.com>
Gerrit-MessageType: abandon
Reply all
Reply to author
Forward
0 new messages