fstream::open crashes if first file it ever opening is in /proc
Max Mikhanosha
max.mikhanosha@protonmail.com
Thu Jul 8 05:41:40 GMT 2021
Fully updated Windows 10, with freshly downloaded Cygwin.
trying to compile google/benchmark does not work coz it can't read /proc/cpuinfo
Reduced test test program
#include <iostream>
#include <fstream>
int main (int argc, char **argv)
{
if (argc > 1)
{
std::fstream booya ("whatever");
}
std::fstream f("/proc/cpuinfo");
if (!f.is_open ()){
std::cout << "Unable to open /proc/cpuinfo" << std::endl;
}
return 0;
}
Repro log
user@MARS ~
$ g++ blah.cc
user@MARS ~
$ ./a.exe # this does not work
Unable to open /proc/cpuinfo
user@MARS ~
$ ./a.exe foobar # this works
user@MARS ~
$ ldd a.exe
ntdll.dll => /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffa5c790000)
KERNEL32.DLL => /cygdrive/c/WINDOWS/System32/KERNEL32.DLL (0x7ffa5ab20000)
KERNELBASE.dll => /cygdrive/c/WINDOWS/System32/KERNELBASE.dll (0x7ffa5a000000)
cygwin1.dll => /usr/bin/cygwin1.dll (0x180040000)
cyggcc_s-seh-1.dll => /usr/bin/cyggcc_s-seh-1.dll (0x3e6ea0000)
cygstdc++-6.dll => /usr/bin/cygstdc++-6.dll (0x3be3a0000)
user@MARS ~
$ cygcheck -f /usr/bin/cyggcc_s-seh-1.dll /usr/bin/cygstdc++-6.dll /usr/bin/cygwin1.dll
cygwin-3.2.0-1
libgcc1-10.2.0-1
libstdc++6-10.2.0-1
gdb shows that it crashes inside _newlib_flockfile_start(fp) as shown below
Thread 1 "a" hit Breakpoint 1, _fopen_r (ptr=0xffffd680,
file=0x10040300a <std::piecewise_construct+10> "/proc/cpuinfo", mode=0x3be4a17bb "r+")
at /usr/src/debug/cygwin-3.2.0-1/newlib/libc/stdio/fopen.c:119
119 {
(gdb) n
124 if ((flags = __sflags (ptr, mode, &oflags)) == 0)
(gdb) n
126 if ((fp = __sfp (ptr)) == NULL)
(gdb) n
129 if ((f = _open_r (ptr, file, oflags, 0666)) < 0)
(gdb) n
140 _newlib_flockfile_start (fp);
(gdb) n
0 [main] a 4876 cygwin_exception::open_stackdumpfile: Dumping stack trace to a.exe.stackdump
[Thread 8800.0x4220 exited with code 35584]
[Thread 8800.0x1100 exited with code 35584]
[Thread 8800.0x1230 exited with code 35584]
[Thread 8800.0x3cc4 exited with code 35584]
Googling around found this https://sourceware.org/pipermail/newlib/2015/012649.html which gave me idea to try opening normal file first to see if this fixes it, and it does, so likely this patch will fix this problem
More information about the Cygwin
mailing list