Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: missing documentation about "dllexport" redeclaration problem on windows/arm64 #49721

Open
bcmills opened this issue Nov 22, 2021 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Nov 22, 2021

In #46502, we observed build errors on windows/arm64 due to redeclaration warnings about mismatched dllexport attributes.

That was ultimately resolved by CL 327309, for which the commit message states:

This [forward-declaring C-exported Go functions] is not something user code will ever do, so no need to make it work in cgo.

However, we know from #19837 that user code does sometimes need to forward-declare C-exported Go functions, in order to pass the C wrappers as callbacks to other C functions. Absent a fix for that issue, the workaround applied in CL 327309 at least ought to be documented.


The only restriction currently documented for forward-declarations in the C preamble (https://pkg.go.dev/cmd/cgo@master#hdr-C_references_to_Go) is:

Using //export in a file places a restriction on the preamble: since it is copied into two different C output files, it must not contain any definitions, only declarations. If a file contains both definitions and declarations, then the two output files will produce duplicate symbols and the linker will fail. To avoid this, definitions must be placed in preambles in other files, or in C source files.

It does not say anything about avoiding forward-declarations, nor about a need to forward-declare functions exported by Go with any particular attributes or keywords.

@gopherbot
Copy link

Change https://golang.org/cl/366075 mentions this issue: misc/cgo/test: remove unnecessary forward declaration

gopherbot pushed a commit that referenced this issue Nov 22, 2021
This test otherwise fails to build on windows/arm64 as of CL 364774
due to a warning (promoted to an error) about a mismatched dllexport
attribute. Fortunately, it seems not to need the forward-declared
function in this file anyway.

Updates #49633
Updates #49721

Change-Id: Ia4698b85077d0718a55d2cc667a7950f1d8e50ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/366075
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 22, 2021
@bcmills bcmills added this to the Backlog milestone Nov 22, 2021
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
Status: Triage Backlog
Development

No branches or pull requests

2 participants