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: CGO compilation fails as of Go version 1.15.3 #43146

Closed
ae6rt opened this issue Dec 12, 2020 · 3 comments
Closed

cmd/cgo: CGO compilation fails as of Go version 1.15.3 #43146

ae6rt opened this issue Dec 12, 2020 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@ae6rt
Copy link

ae6rt commented Dec 12, 2020

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

$ go version
go version go1.15.3 linux/amd64

Does this issue reproduce with the latest release?

Yes. The problem exists in every version of Go since 1.15.3 through 1.15.6.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xoom/.cache/go-build"
GOENV="/home/xoom/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/src/go/pkg/mod"
GONOPROXY=""
GONOSUMDB="git.xoom.com"
GOOS="linux"
GOPATH="/usr/src/go"
GOPRIVATE=""
GOPROXY=value elided - we are using Artifactory GoCenter
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/t/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build875776243=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Prior to Go 1.15.3, our CGO application builds and runs as intended. Starting with Go version 1.15.3 and through Go version 1.15.6, the application fails to compile.

What did you expect to see?

A successful compilation.

What did you see instead?

Starting with Go 1.15.3, compilation fails with

hsm/hsm.go:275:16: _Ctype_struct__O_Session can't be allocated in Go; it is incomplete (or unallocatable)

hsm.go is our application code. Line 275 is this

hsm.session = &C.struct__O_Session{}
@ianlancetaylor
Copy link
Contributor

This is an intentional change. This happens when cgo is unable to determine the fields of the C struct type. In earlier versions this could allocate a zero-sized struct, which is almost never correct. Now it gives an error, telling you that the code is not going to work as you expect.

If you think this code is correct, please tell us why, and tell us how to reproduce the problem.

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Dec 12, 2020
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Dec 12, 2020
@ianlancetaylor ianlancetaylor changed the title CGO compilation fails as of Go version 1.15.3 cmd/cgo: CGO compilation fails as of Go version 1.15.3 Dec 12, 2020
@ianlancetaylor
Copy link
Contributor

I sent https://golang.org/cl/277432 to add a note to the Go 1.15 release notes. Better late than never.

@ae6rt
Copy link
Author

ae6rt commented Dec 12, 2020

I see.

Here is the empty struct, for posterity reading along, in the 3rd party library I am linking to (and do not control):

typedef struct _O_Session * I_O_Session;

Not sure what the intent of an empty struct is, but this is clearly and ultimately my problem.

Thanks for clearing this up.

@ae6rt ae6rt closed this as completed Dec 12, 2020
@golang golang locked and limited conversation to collaborators Dec 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants