public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* fstream::open crashes if first file it ever opening is in /proc
@ 2021-07-08  5:41 Max Mikhanosha
  2021-07-08  8:53 ` Csaba Raduly
  0 siblings, 1 reply; 4+ messages in thread
From: Max Mikhanosha @ 2021-07-08  5:41 UTC (permalink / raw)
  To: cygwin

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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-09  9:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08  5:41 fstream::open crashes if first file it ever opening is in /proc Max Mikhanosha
2021-07-08  8:53 ` Csaba Raduly
2021-07-08 14:42   ` Max Mikhanosha
2021-07-09  9:08     ` Csaba Raduly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).