MINGW-packages: C++ hello world is causing a segmentation fault

I just updated all MSYS2 packages on one of my machines, then tried to recompile some of my C++ programs, and noticed that several of them are giving a segmentation fault. I was able to simplify the issue a lot. Here is a shell session in a MinGW-w64 64-bit Shell showing how I can recreate the problem by trying to compile a simple C++ program. Can anyone else reproduce this?

$ cat prog.cpp
#include <iostream>

int main(int argc, char ** argv)
{
    std::cout << "Hello world." << std::endl;
    return 1;
}

$ g++ prog.cpp -o prog.exe

$ ./prog.exe
Segmentation fault

$ gdb ./prog.exe
GNU gdb (GDB) 7.10.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./prog.exe...done.
(gdb) run
Starting program: C:\Users\David\Documents\scraps\test_c++\prog.exe
[New Thread 116908.0x1c420]

Program received signal SIGSEGV, Segmentation fault.
0x000000006fcae829 in ?? () from D:\msys64\mingw64\bin\libstdc++-6.dll
(gdb) where
#0  0x000000006fcae829 in ?? () from D:\msys64\mingw64\bin\libstdc++-6.dll
#1  0x000000006fcfb2a9 in ?? () from D:\msys64\mingw64\bin\libstdc++-6.dll
#2  0x000000006fd00317 in ?? () from D:\msys64\mingw64\bin\libstdc++-6.dll
#3  0x00000000004015e7 in main ()
(gdb)

If I comment out the line that writes to std::cout, the problem goes away and the executable works.

Some of my C++ programs were able to write to their output without having a segmentation fault, so I might look into this further to see what the difference is between a working program and a failing program.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 28 (19 by maintainers)

Most upvoted comments

@Kwizatz I’ve just checked on Ryzen and it works fine. Is your environment fully upgraded (pacman -Syuu)?