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
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@willie
Copy link

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

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.

@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Feb 26, 2021
@ianlancetaylor ianlancetaylor added this to the Go1.17 milestone Feb 26, 2021
@willie
Copy link
Author

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

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

@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?

@ianlancetaylor
Copy link
Contributor

Moving to Backlog.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.17, Backlog May 21, 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. help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
Status: Triage Backlog
Development

No branches or pull requests

4 participants