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: "'_check_for_64_bit_pointer_matching_GoInt' declared as an array with a negative size" on darwin/arm64 #43842

Closed
Hywan opened this issue Jan 22, 2021 · 8 comments
Labels
arch-arm64 FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Milestone

Comments

@Hywan
Copy link

Hywan commented Jan 22, 2021

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

$ go version
go version go1.16beta1 darwin/arm64

Does this issue reproduce with the latest release?

Yup. The beta.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/hwhost/Library/Caches/go-build"
GOENV="/Users/hwhost/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/hwhost/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/hwhost/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16beta1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="[hidden]"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vh/wyys3cl57jz0qp5t79vhrd200000gn/T/go-build952033984=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I tried to compile the following file with go build main.go:

package foo

import "C"

func main() { }

What did you expect to see?

A successful built.

What did you see instead?

In file included from _cgo_export.c:4:
cgo-gcc-export-header-prolog:25:55: error: '_check_for_64_bit_pointer_matching_GoInt' declared as an array with a negative size

Extra

It could be related to #38693.
The GOARCH and GOOS are OK in this case.

@Hywan
Copy link
Author

Hywan commented Jan 22, 2021

_check_for_64_bit_pointer_matchin_GoInt is defined as:

typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

Let's evaluate this super quickly in C:

int main() {
  printf(">> %lu\n", sizeof(void*));
  printf(">> %d\n", 64/8);
}

Execute it:

$ clang a.c -o a && ./a
>> 8
>> 8

I don't know how cgo calls clang, but it seems something is wrong in how it invokes it.

@bcmills
Copy link
Contributor

bcmills commented Jan 22, 2021

CC @cherrymui @ianlancetaylor

@bcmills bcmills added arch-arm64 OS-Darwin NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 22, 2021
@bcmills bcmills added this to the Backlog milestone Jan 22, 2021
@bcmills bcmills changed the title cgo on darwin/arm64: _check_for_64_bit_pointer_matching_GoIntdeclared as an array with a negative size cmd/cgo: "'_check_for_64_bit_pointer_matching_GoInt' declared as an array with a negative size" on darwin/arm64 Jan 22, 2021
@bcmills
Copy link
Contributor

bcmills commented Jan 22, 2021

Depending on how you were invoking go build, this looks like it may be a duplicate of #43692.

@cherrymui
Copy link
Member

Weird. What is the output for go build -x? That should include how C compiler is invoked to compile C code.

it may be a duplicate of #43692.

Could be. Does setting CGO_CFLAGS="-arch arm64" CGO_LDFLAGS="-arch arm64" help?

It is still weird in that even if it defaults to x86_64, it is still 64-bit and the pointer size should still be 8.

@bcmills
Copy link
Contributor

bcmills commented Jan 22, 2021

Is it possible that the user's shell is a 32-bit binary, causing clang to default to some 32-bit arch?

@cherrymui
Copy link
Member

I don't think ARM64 Mac supports 32-bit binary.

@Hywan
Copy link
Author

Hywan commented Jan 25, 2021

Running CGO_CFLAGS="-arch arm64" CGO_LDFLAGS="-arch arm64" go build main.go solves the problem. That's weird.

clang and the shell, everything is 64-bit.

@Hywan
Copy link
Author

Hywan commented Jan 25, 2021

Thanks :-)

@Hywan Hywan closed this as completed Jan 25, 2021
@golang golang locked and limited conversation to collaborators Jan 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-arm64 FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Projects
None yet
Development

No branches or pull requests

4 participants