-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: rt0_go failure on Windows when using zig cc #43886
Comments
This comment has been minimized.
This comment has been minimized.
@andrewrk does anything change if you add the |
no- still get a segfault at:
was go/cgo expecting the linker to do something that perhaps didn't get done here? it looks like one of these: Lines 123 to 124 in d047c91
looks like writing to this memory is segfaulting: Lines 1095 to 1096 in d047c91
so my question would be: in what way does go emit an object for runtime2.go, and how is the address for those variables computed in the object for asm_amd64.s? |
@ianlancetaylor would be the best person to talk to about this but I'm not too sure if this should be discussed here cause the issue tracker is normally for bugs and zig isn't exactly the intended/expected compiler/linker. |
hmm I think this may be an issue with cgo though; is that in scope for this issue tracker? |
Let's keep this issue open until we know if this is a bug in zig or in Go. |
I don't have any familiarity with using zig. Can you give instructions on how to easily reproduce this issue from a clean Linux install? A docker image would be ideal. |
Reproduced with go 1.15.6 linux/amd64, full output here: https://pastebin.com/BmVtawS1 @mdempsky Assuming you have go installed already, all you should need is a master copy of zig. For you this probably means getting a binary from https://ziglang.org/download/ and adding it to your path (shouldn't need any more setup than this). Personally I get my version from the "zig-git" aur package. |
Also tested on go 1.15.7 linux/amd64; same problem https://pastebin.com/wHw49gWf. |
I thought maybe filtering out the zlib-gnu invocation from Go might fix it, which I did with using this for the shell wrapper: #!/bin/bash
INVOKE=${@/-Wl,--compress-debug-sections=zlib-gnu/}
echo $INVOKE
zig cc -target x86_64-windows-gnu $INVOKE (set invoke to $@ to see the full invocation that CGo does) and that does seem to solve the error, but I'm not sure if the resulting binary is as expected, adding it here, cannot test because compiled on Linux ARM64: zigandgotest.zip |
Update: found a Windows machine to test on, running that binary doesn't give any errors but doesn't produce the desired result (fyne hello world) either. |
Likely fixed by https://go-review.googlesource.com/c/go/+/291630 |
Context to @zx2c4's reference (correct me if I'm wrong...): LLVM builds seem to have been broken for Windows with CGo before, but it wasn't really an issue until trying to get ARM64 on Windows to work. Fixes are applied now to get Windows/ARM64 working, and those should fix Windows builds across the board. |
Those fixes haven't been applied yet. I'm hoping @rsc will submit them with the rest of the windows/arm64 series in the near future. |
Yeah, the patch you refer to is still stuck in trybot-hell atm xD. If you have a branch with these fixes applied I would love to test that for the purpose of this bug. |
Here's what I'm building with at the moment: https://download.wireguard.com/windows-toolchain/distfiles/go1.16-2021-02-18.zip It's 1.16 plus a bunch of extras. Cgo works with Clang but I haven't tried zig's wrapper yet. Let me know how it goes. |
$ CC="zcc" CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build
# fyne-hello
warning: unsupported linker arg: --compress-debug-sections=zlib-gnu |
Tested with wine on my amd64 system: works. Might need to file the unsupported linker arg thing separately. So it's very likely that this bug will be fixed when the Windows/ARM64 patches are in. |
The argument order patch should fix the zlib-gnu warning, @zx2c4 said to check out that patch and with a bit of luck I will be able to test that too. |
@zx2c4 as we found that your version works, maybe link/mention the relevant bugs here so Github can help us keep track if we can close this bug? |
Doesn't seem to be an order patch yet? Current master seems to fix issue otherwise 👍 (while still needing the workaround) |
CL 291630 fixed this issue. Closing. |
Hello, any Go developers interested in working with Zig developers on this use case?
Upstream issue: ziglang/zig#7874
Tested with go 1.15.5.
main.go
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="zcc" CXX="zc++" go build main.go
zcc
zc++
output:
It produces
main.exe
but when run it segfaults inruntime.rt0_go()
(called from main()). Expected output is to print "30" to the console when run in cmd.exe.Happy to chat on IRC or Discord if anyone has some ideas to try.
The text was updated successfully, but these errors were encountered: