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

* Re: fstream::open crashes if first file it ever opening is in /proc
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Csaba Raduly @ 2021-07-08  8:53 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: cygwin

On Thu, 8 Jul 2021 at 07:42, Max Mikhanosha via Cygwin
<cygwin@cygwin.com> wrote:
>
> 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
>

Works just fine for me (I added code to read the first word from the
stream and print it)

Csaba@AMDAHL ~
$ ./a.exe
processor
Csaba@AMDAHL ~
$ ./a.exe  foobar
processor

Csaba
-- 
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformant way
to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)

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

* Re: fstream::open crashes if first file it ever opening is in /proc
  2021-07-08  8:53 ` Csaba Raduly
@ 2021-07-08 14:42   ` Max Mikhanosha
  2021-07-09  9:08     ` Csaba Raduly
  0 siblings, 1 reply; 4+ messages in thread
From: Max Mikhanosha @ 2021-07-08 14:42 UTC (permalink / raw)
  To: Csaba Raduly; +Cc: cygwin

You have same versions of cygwin1.dll and libstdc++ dll?

Wonder if it has something to do with machine, its 64 core amd threadripper box, (128 logical cpu's with hyperthreading

Some other observations:

1) Compiling the test program on other box with older Cygwin, where problem does not happen, and copying the .exe, still reproduces

2) With older cygwin problem goes away (I did not reinstall older cygwin, but moved just made a directory with older cygwin1.dll and two other DLL's and the executable and set path to it)

3) if I use fopen() problem also reproduces, but only if I include <iostream>.  The difference between executable that includes <iostream> vs one that does not, is that the one including <iostream> links cygstdc++.6.dll and cyggcc_s-seh-1.dll but one without does not

So problem I'm having is related to some static initialization code thats triggered by presence of cygstdc++.6.dll, likely in the area of ios_base::sync_with_stdio logic.

For now I'll just let this go and workaround by adding dummy fstream("whatever") on top of my main program, if there is a real bug I'm sure other people will hit it too sooner or later

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

* Re: fstream::open crashes if first file it ever opening is in /proc
  2021-07-08 14:42   ` Max Mikhanosha
@ 2021-07-09  9:08     ` Csaba Raduly
  0 siblings, 0 replies; 4+ messages in thread
From: Csaba Raduly @ 2021-07-09  9:08 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: cygwin

On Thu, 8 Jul 2021 at 16:42, Max Mikhanosha  wrote:
>
> You have same versions of cygwin1.dll and libstdc++ dll?
>

Csaba@AMDAHL ~
$ uname -a
CYGWIN_NT-10.0 AMDAHL 3.2.0(0.340/5/3) 2021-03-29 08:42 x86_64 Cygwin

Csaba@AMDAHL ~
$ 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



Csaba
-- 
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformant way
to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)

^ 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).