Skip to content

In arm64 environment, c# calls go dll exception #66833

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

Closed
yunhaolsh opened this issue Apr 15, 2024 · 3 comments
Closed

In arm64 environment, c# calls go dll exception #66833

yunhaolsh opened this issue Apr 15, 2024 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@yunhaolsh
Copy link

Go version

go version go1.22.1 windows/amd64

Output of go env in your module/workspace:

$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\84903\AppData\Local\go-build
set GOENV=C:\Users\84903\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\84903\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\84903\go
set GOPRIVATE=
set GOPROXY=https://goproxy.cn
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=zig cc -target arm64-windows
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\code\TestGoDll\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=arm64-windows -I . -m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\84903\AppData\Local\Temp\go-build3360823872=/tmp/go-build -gno-record-gcc-switches

What did you do?

import/pathIn the arm64 environment, I use c# code to call the DLL generated by go code, and the program always exits abnormally. The same code works fine in an x64 environment. I tried to compile the go dll that generated the arm64 version, but couldn't find a cross-compile tool from windows x64 to windows arm64.: issue title
Snipaste_2024-04-12_10-25-53

https://github.com/golang/go/assets/52696274/1514ffda-f290-4692-889d-08449ffb55e6
arm_windbg.txt
x64_windbg.txt

What did you see happen?

Program exit exception

What did you expect to see?

Under the arm64 environment, the program can normally call the dll generated by go, and tell me how to cross-compile cgo under the windows x64 environment to generate the dll under windows arm64, thanks a lot.

@yunhaolsh
Copy link
Author

When I compile with the following instructions, I get an error:
CGO_ENABLED=1 GOOS=windows GOARCH=arm6464 CC="zig cc -target arm-windows" CXX="zig c++ -target arm-windows" go build --tags extended
error:

runtime/cgo

In file included from _cgo_export.c:4:
cgo-gcc-export-header-prolog:31:55: error: '_check_for_64_bit_pointer_matching_GoInt' declared as an array with a negative size
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

@cherrymui
Copy link
Member

You'll need a C (cross) compiler that targets Windows ARM64. Are you sure that the CC you specified targets 64-bit ARM? The error looks like the C compiler sees void* not 64-bit, i.e. it is not a 64-bit target.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 16, 2024
@yunhaolsh
Copy link
Author

Thanks for your reply. When I changed CC to aarch64-w64-mingw32-gcc, the dll can be generated. Then I compiled my c# code with arm64 to call this dll, and everything went well. Now I need to check that all DLLS used by my project must be compiled by arm64. That's a lot of work.
I just can't figure out why x64 c# code can not call x64 go dll on arm64, the same code works fine on x64 environment, in addition c++ x64 calls the same go dll on arm64 is all good.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants