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: building c-archive with function pointer works with Go 1.14, but not 1.15 and beyond #44648

Open
willie opened this issue Feb 26, 2021 · 4 comments

Comments

@willie
Copy link

@willie willie commented Feb 26, 2021

What version of Go are you using (go version)?

$ go version
go version go1.15 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/willie/Library/Caches/go-build"
GOENV="/Users/willie/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/willie/pkg/mod"
GONOPROXY="github.com/vitalsource/*"
GONOSUMDB="github.com/vitalsource/*"
GOOS="darwin"
GOPATH="/Users/willie"
GOPRIVATE="github.com/vitalsource/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/willie/.asdf/installs/golang/1.15/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/willie/.asdf/installs/golang/1.15/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/willie/willie/cgotest/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4z/2t7q40b14znb__08yd_p_znw0000gn/T/go-build009670235=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I build a Go c-archive static library to use in several C/C++ programs. Building c-archives with cgo broke in a way that I don't understand in Go 1.15 and later. Building with Go 1.14 works fine. I put together a simple example here: https://github.com/willie/cgotest

What did you expect to see?

I expected to be able to build a c-archive static library with no errors.

What did you see instead?

# command-line-arguments
_cgo_export.c:29:3: error: unknown type name 'writeFunc'
@ianlancetaylor ianlancetaylor changed the title building c-archive with function pointer works with Go 1.14, but not 1.15 and beyond cmd/cgo: building c-archive with function pointer works with Go 1.14, but not 1.15 and beyond Feb 26, 2021
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 26, 2021

The problem here is

func HTTPGet(url *C.char, writeFunc C.writeFunc, writeFuncData unsafe.Pointer) (read int64) {

Note that writeFunc is both the Go parameter name and the C type name. This leads to confusion in the generated C code.

Loading

@willie
Copy link
Author

@willie willie commented Feb 26, 2021

YES! Changing the Go parameter name fixed the problem. Such a relief and an easy change. Thank you for the help @ianlancetaylor

Loading

willie added a commit to willie/cgotest that referenced this issue Feb 26, 2021
golang/go#44648 (comment)

Leaving this on this branch for now, so it's easy to test.
@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented May 21, 2021

@ianlancetaylor Ian, is there something to do here for Go 1.17, or is it appropriate to move it to Backlog until it becomes more clear what the timeline of a fix might be?

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 21, 2021

Moving to Backlog.

Loading

@ianlancetaylor ianlancetaylor removed this from the Go1.17 milestone May 21, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants