Skip to content

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

Closed
@neclepsio

Description

@neclepsio

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) 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions