It does. You need to launch it from a dos prompt or the file browser. I just discovered that If you launch it from mingw terminal it works fine. The expected output is "i". The actual output (windows 7) is a dialog window:
test.exe has stopped working
Windows is collecting more information about the problem.
This might take several minutes.
Last edit: Fabio DallaLibera 2016-12-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Guys, unless you are trying to illustrate a graphical effect, no screenshot is helpful, ever. Copy and paste your terminal output, with appropriate markup, directly into the report dialogue.
Even less helpful, is any idiotic suggestion that because one of you is seeing a crash, and one is not, one of you must be confused. The only confusion I see here is a reference to a MinGW terminal, (since there is no meaningful definition for any such thing); perhaps you mean a distinction between running from an MSYS shell vs. a cmd.exe shell, (in whatever console container you happen to have chosen)? In any case, that should have no bearing on the issue.
FWIW, I can consistently reproduce this issue: when cross-compiling the original test case with GCC-4.8.2, GCC-4.9.3, and GCC-5.3.0, and running in WinXP VM cmd.exe, or MSYS shell, or under Wine on the Linux host, it segfaults (apparently) when this method:
(defined within GCC's <typeinfo> header) attempts to dereference a NULL this pointer, (or just a NULL reference to the __name property itself). It also fails, when compiled natively by GCC-5.3.0 on the WinXP VM; it runs successfully, when cross-compiled by GCC-3.4.5.
In any case, to be pragmatic, this appears to be a GCC implementation issue; you should raise it directly with the GCC maintainers, either via their mailing list, or GCC bugzilla.
Last edit: Keith Marshall 2016-12-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Note that, immediately prior to the call to std::type_info::name() const, at 0x0040145b, GCC has emitted code to explicitly zero the ECX register. Single stepping into the method, and up to the point of the segfault at 0x00408ddc:
Note the indirect transfer of the zero from ECX to EAX, which is then dereferenced as a pointer, with a (likely too small) offset of only 4; this results in the segfault. At this point, the register contents are:
Interestingly, the test case runs just fine, if I compile using the static libstdc++, rather than the default dynamic version:
$g++-O0-g-static-libstdc++foo.cc-ofoo.exe
$./foo
i
This is looking increasingly like a initialization bug, in the DLL variant of libstdc++. It may, apparently, be circumvented by linking with the static variant, but that may then introduce other problems, (e.g. with exception handling). You will still need to seek a resolution from the upstream maintainers of GCC, (specifically, those who maintain libstdc++).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In any case, to be pragmatic, this appears to be a GCC implementation issue; you should raise it directly with the GCC maintainers, either via their mailing list, or GCC bugzilla.
Or maybe a binutils issue? Or a defect in my cross-compiler build environment? (The MinGW packages were created from a cross-native build). Or maybe something got stripped too zealously? (GCC's install-strip make goal is broken, so I stripped everything manually, after a regular install from the default -g -O2 build).
Anyway, I rebuilt my cross-compiler tool chain, (including binutils-2.25.1 this time, instead of the binutils-2.26.20160125 I had installed previously), and recompiled the test case; it now runs fine under wine:
$rm*.dll
$lnmingw32-gcc-5.3.0/mingw32/lib/*.dll.
$mingw32-g++-O3-sfoo.cc-ofoo.exe
$./foo.exe
i
I then proceeded to rebuild the cross-native tool chain, and installed that into a WinXP-VM, where once again, the test case now compiles and runs just fine:
$g++-O3-sfoo.cc-ofoo.exe
$./foo
i
I'll get replacement packages uploaded to FRS, and listed in the mingw-get catalogue, just as soon as time permits.
Last edit: Keith Marshall 2016-12-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you very much for your work!
If it can help, I used only precompiled MinGW binaries downloaded from the official websites.
And, If you run the exact same .exe from
GNU bash, version 4.3.46(2)-release (i686-pc-msys)
it prints "i" as expected, while if you run it by cmd.exe it crashes.
Last edit: Fabio DallaLibera 2016-12-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you run the exact same .exe from GNU bash, version 4.3.46(2)-release (i686-pc-msys) it prints "i" as expected, while if you run it by cmd.exe it crashes.
That makes absolutely no sense at all. My compilations of your test case, when run under GDB, show a NULL pointer dereference compiled directly into the (dynamically) linked image. This reference remains explicitly NULL, after all runtime relocations have been resolved, so must cause a segmentation fault irrespective of the shell under which you run it. That's exactly what I see: it crashes under bothMSYS bashandcmd.exe.
I don't know why the references, (in this case to the symbol _ZTIi in libstdc++-6.dll), were improperly resolved; after rebuilding the entire tool chain package set, from scratch, that reference is now correctly resolved, (for me). The rebuilt packages are now available in FRS, for direct download or installation/upgrade via mingw-get.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are you sure it crashes?
It works fine on my environment.
What is the expected output?
It does. You need to launch it from a dos prompt or the file browser. I just discovered that If you launch it from mingw terminal it works fine. The expected output is "i". The actual output (windows 7) is a dialog window:
test.exe has stopped working
Windows is collecting more information about the problem.
This might take several minutes.
Last edit: Fabio DallaLibera 2016-12-06
Are you sure? You seem confused (See attachment)
It works fine from either 'prompt' window.
Here is a screenshot...
That screenshot doesn't help much, does it?
Where do you think the problem lies and how it can be fixed?
Guys, unless you are trying to illustrate a graphical effect, no screenshot is helpful, ever. Copy and paste your terminal output, with appropriate markup, directly into the report dialogue.
Even less helpful, is any idiotic suggestion that because one of you is seeing a crash, and one is not, one of you must be confused. The only confusion I see here is a reference to a MinGW terminal, (since there is no meaningful definition for any such thing); perhaps you mean a distinction between running from an MSYS shell vs. a
cmd.exeshell, (in whatever console container you happen to have chosen)? In any case, that should have no bearing on the issue.FWIW, I can consistently reproduce this issue: when cross-compiling the original test case with GCC-4.8.2, GCC-4.9.3, and GCC-5.3.0, and running in WinXP VM
cmd.exe, or MSYS shell, or under Wine on the Linux host, it segfaults (apparently) when this method:(defined within GCC's
<typeinfo>header) attempts to dereference a NULLthispointer, (or just a NULL reference to the__nameproperty itself). It also fails, when compiled natively by GCC-5.3.0 on the WinXP VM; it runs successfully, when cross-compiled by GCC-3.4.5.In any case, to be pragmatic, this appears to be a GCC implementation issue; you should raise it directly with the GCC maintainers, either via their mailing list, or GCC bugzilla.
Last edit: Keith Marshall 2016-12-09
Some further information, from GCC-5.3.0 compile on WinXP VM:
Note that, immediately prior to the call to
std::type_info::name() const, at0x0040145b, GCC has emitted code to explicitly zero theECXregister. Single stepping into the method, and up to the point of the segfault at0x00408ddc:Note the indirect transfer of the zero from
ECXtoEAX, which is then dereferenced as a pointer, with a (likely too small) offset of only 4; this results in the segfault. At this point, the register contents are:Interestingly, the test case runs just fine, if I compile using the static
libstdc++, rather than the default dynamic version:This is looking increasingly like a initialization bug, in the DLL variant of
libstdc++. It may, apparently, be circumvented by linking with the static variant, but that may then introduce other problems, (e.g. with exception handling). You will still need to seek a resolution from the upstream maintainers of GCC, (specifically, those who maintainlibstdc++).Or maybe a binutils issue? Or a defect in my cross-compiler build environment? (The MinGW packages were created from a cross-native build). Or maybe something got stripped too zealously? (GCC's
install-stripmake goal is broken, so I stripped everything manually, after a regularinstallfrom the default-g -O2build).Anyway, I rebuilt my cross-compiler tool chain, (including binutils-2.25.1 this time, instead of the binutils-2.26.20160125 I had installed previously), and recompiled the test case; it now runs fine under wine:
I then proceeded to rebuild the cross-native tool chain, and installed that into a WinXP-VM, where once again, the test case now compiles and runs just fine:
I'll get replacement packages uploaded to FRS, and listed in the
mingw-getcatalogue, just as soon as time permits.Last edit: Keith Marshall 2016-12-12
Thank you very much for your work!
If it can help, I used only precompiled MinGW binaries downloaded from the official websites.
And, If you run the exact same .exe from
GNU bash, version 4.3.46(2)-release (i686-pc-msys)
it prints "i" as expected, while if you run it by cmd.exe it crashes.
Last edit: Fabio DallaLibera 2016-12-12
That makes absolutely no sense at all. My compilations of your test case, when run under GDB, show a NULL pointer dereference compiled directly into the (dynamically) linked image. This reference remains explicitly NULL, after all runtime relocations have been resolved, so must cause a segmentation fault irrespective of the shell under which you run it. That's exactly what I see: it crashes under both
MSYS bashandcmd.exe.I don't know why the references, (in this case to the symbol
_ZTIiinlibstdc++-6.dll), were improperly resolved; after rebuilding the entire tool chain package set, from scratch, that reference is now correctly resolved, (for me). The rebuilt packages are now available in FRS, for direct download or installation/upgrade viamingw-get.In the absence of any further dialogue, I assume this has been resolved; closing accordingly.