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: SIGSEGV using C++ files in package on Windows #10023

Closed
neclepsio opened this issue Feb 27, 2015 · 2 comments
Closed

cmd/cgo: SIGSEGV using C++ files in package on Windows #10023

neclepsio opened this issue Feb 27, 2015 · 2 comments

Comments

@neclepsio
Copy link

Hi,

this seems to me the same as #5629. Under Linux, if I compile the following files it runs fine.

test.go:

package main

// #include "test.h"
import "C"

func main() {
    C.cpptest()
}

test.h:

#ifdef __cplusplus
extern "C" {
#endif
    void cpptest(void);
#ifdef __cplusplus
}
#endif

test.cpp:

#include "test.h"
#include <iostream>

void cpptest (void) {
    std::cerr << "ctest!\n";
}

Under Windows, using mingw-w64, it crashes:

Exception 0xc0000005 0x0 0xffffffffffffffff 0x6fc8da99
PC=0x6fc8da99
signal arrived during cgo execution

main._Cfunc_cpptest()
    _/F_/Home-Mirror/Programming/Go-Workspace/src/_obj/_cgo_gotypes.go:22 +0x4c
main.main()
    F:/Home-Mirror/Programming/Go-Workspace/src/test.go:7 +0x22

goroutine 2 [runnable]:
runtime.forcegchelper()
    c:/go/src/runtime/proc.go:90
runtime.goexit()
    c:/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 3 [runnable]:
runtime.bgsweep()
    c:/go/src/runtime/mgc0.go:82
runtime.goexit()
    c:/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    c:/go/src/runtime/asm_amd64.s:2232 +0x1
rax     0x47db90
rbx     0x47db90
rcx     0x22fe60
rdx     0x900047e0102524ff
rdi     0xc082025f90
rsi     0x22fe60
rbp     0x482220
rsp     0x22fdf0
r8      0x7
r9      0xc082025f38
r10     0x28
r11     0x449360
r12     0x7
r13     0x22fe60
r14     0x0
r15     0x460750
rip     0x6fc8da99
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b

In the mentioned issue #5629 @ianlancetaylor suggest: "My guess is that the global constructors are not being run, but I have no idea why that would be happening."

I'm a C++ newbie, but this sounds to me a good guess. I found this issue while debugging go-qml, where I got some crashes under Windows:

  • using dynamic_cast (see go-qml issue #19) -- maybe RTTI is not initialized?
  • using a static local variable (see go-qml issue #142) -- maybe "globals" are not initialized?

I'm using versions:

> go version
go version go1.4.2 windows/amd64
> gcc -v
Using built-in specs.
COLLECT_GCC=F:\Windows\Go\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=F:/Windows/Go/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.9.2/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.9.2/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw492/x86_64-492-posix-seh-rt_v3-rev0/mingw64 --with-gxx-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw492/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw492/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw492/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw492/prerequisites/x86_64-w64-mingw32-static --with-cloog=/c/mingw492/prerequisites/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw492/x86_64-492-posix-seh-rt_v3-rev0/mingw64/opt/include -I/c/mingw492/prerequisites/x86_64-zlib-static/include -I/c/mingw492/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw492/x86_64-492-posix-seh-rt_v3-rev0/mingw64/opt/include -I/c/mingw492/prerequisites/x86_64-zlib-static/include -I/c/mingw492/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw492/x86_64-492-posix-seh-rt_v3-rev0/mingw64/opt/lib -L/c/mingw492/prerequisites/x86_64-zlib-static/lib -L/c/mingw492/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 4.9.2 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 
@minux
Copy link
Member

minux commented Mar 3, 2015 via email

@minux minux closed this as completed Mar 3, 2015
neclepsio added a commit to neclepsio/qml that referenced this issue Mar 4, 2015
Removes all dynamic_cast, in order to make it work without RTTI. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#19.
neclepsio added a commit to neclepsio/qml that referenced this issue Mar 4, 2015
Make it work without global variable initialization. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#142.
@neclepsio
Copy link
Author

Thank you for your reply. I'm leaving this comment to help who has this problem I had, since searching was very hard for me and many had no clue for the go-qml issues.

If you get Exception 0xc0000005 under Windows while using global variable initialization depending feature, like static variables, global constructors, cerr or cout, or feature relying on RTTI such as dynamic_cast or typeof, this could be the reason.

KellyLSB pushed a commit to HexxedUS/qml that referenced this issue May 28, 2016
Removes all dynamic_cast, in order to make it work without RTTI. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#19.
KellyLSB pushed a commit to HexxedUS/qml that referenced this issue May 28, 2016
Make it work without global variable initialization. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#142.
@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
Development

No branches or pull requests

3 participants