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: crash when calling strtod on windows/amd64 #8941

Closed
alexbrainman opened this issue Oct 16, 2014 · 6 comments

Comments

@alexbrainman
Copy link
Member

commented Oct 16, 2014

Running this http://play.golang.org/p/wm5ADXs9KV on windows/amd64 produces: 

C:\go\path\src\t>go run foo.go
sizeof double is: 8
Exception 0xc0000005 0x1 0x0 0x7feff038ee7
PC=0x7feff038ee7
signal arrived during cgo execution

main._Cfunc_foo(0x0)
        command-line-arguments/_obj/_cgo_gotypes.go:24 +0x5e
main.main()
        C:/go/path/src/t/foo.go:36 +0x31

goroutine 2 [runnable]:
runtime.forcegchelper()
        c:/go/root/src/runtime/proc.go:90
runtime.goexit()
        c:/go/root/src/runtime/proc.c:1651

goroutine 3 [runnable]:
runtime.bgsweep()
        c:/go/root/src/runtime/mgc0.go:66
runtime.goexit()
        c:/go/root/src/runtime/proc.c:1651

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        c:/go/root/src/runtime/proc.c:1651

goroutine 4 [runnable]:
runtime.runfinq()
        c:/go/root/src/runtime/malloc.go:705
runtime.goexit()
        c:/go/root/src/runtime/proc.c:1651
rax     0x0
rbx     0x22fb98
rcx     0x7feea97e5720000
rdx     0x0
rdi     0x22fc38
rsi     0xffffffffffffffff
rbp     0x404147ae147ae148
rsp     0x22fb40
r8      0x22ef28
r9      0x0
r10     0x0
r11     0x22f550
r12     0x22fb90
r13     0x4a4e30
r14     0x51d596
r15     0x0
rip     0x7feff038ee7
rflags  0x7fe00010286
cs      0x33
fs      0x53
gs      0x2b
exit status 2

C:\go\path\src\t>hg id -R %GOROOT%
284a98e61e32 tip

C:\go\path\src\t>gcc --version
gcc (GCC) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The program runs fine on windows/386.

Alex
@gopherbot

This comment has been minimized.

Copy link

commented Oct 16, 2014

Comment 1 by nicolas.riesch:

It crashes on my computer with Windows 7 too.
C:\Users\rin01>go version
go version go1.3.3 windows/amd64
C:\Users\rin01>gcc --version
gcc (tdm64-2) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The same problem also exists when         strtoll("9223372036854775808", NULL, 10)   is
used in cgo,
which crashes the following program:
  http://play.golang.org/p/W4wSfzw1X-
@nnemkin

This comment has been minimized.

Copy link

commented Oct 16, 2014

Comment 2:

strtod() crashes inside atexit(), because go linker bypasses CRT initialization
(mainCRTStartup/WinMainCRTStatrup), leaving some globals with incorrect state.
The solution is to use external linking mode, except it's not supported on Windows.
strtoll() crash is a different problem.
MinGW CRT calls errno() (exported from msvcrt.dll) through a stub function _errno, which
indirectly calls __imp__errno (actual imported function pointer).
To overcome 6l limitations, cgo rewrites imports, which results in __imp__errno being
called _errno and the stub _errno called from CRT being discarded. Now strtoll that
called this stub crashes, because _errno symbol has changed its meaning.
Regardless, the solution is the same: use a fully functional linker.
@minux

This comment has been minimized.

Copy link
Member

commented Oct 16, 2014

Comment 3:

i'm surprised to learn that strtod
needs to call atexit.
although it seems we can fix the first
problem by calling the crt initialization
function at program startup when using
cgo.

@bradfitz bradfitz removed the new label Dec 18, 2014

@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented Apr 2, 2015

I believe this is fixed now by latest @minux cmd/ld pe changes.

@minux I can make new test out of this for misc/cgo/test. Do we want that?

Alex

@mikioh mikioh added this to the Go1.5 milestone Apr 2, 2015

@minux

This comment has been minimized.

Copy link
Member

commented Apr 2, 2015

@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented Apr 2, 2015

I didn't know that. So were should I add this test? runtime?

Alex

@golang golang locked and limited conversation to collaborators Jun 25, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants
You can’t perform that action at this time.