Reentrancy problem in Cygwin/newlib

Corinna Vinschen
Fri Jun 18 09:56:00 GMT 2004


yesterday I came across a problem where data send over a pipe gets
truncated.  Searching for the culprit, I found that a change in newlib
from 2004-06-11 introduced this problem.  My (non-voluntary) testcase
was a configure script which calls

  case `m4 --help` in ...

to look for a specific string in the help output.  It didn't work
anymore due to the truncation.  On the command line, you can simply
observe the behaviour by calling

  echo `m4 --help`

Very interesting is also

  echo `m4 --help` | wc

which prints exactly nothing!

The patch in newlib has been introduced in this thread:

Besides some minor changes, this patch introduces a new global variable
called "_global_reent_ptr" and the include/sys/reent.h file defines
_GLOBAL_REENT as _global_reent_ptr.

I tried several changes, for example substituting _GLOBAL_REENT in
_cygtls::init_thread() by _impure_ptr.  This actually changes the
behaviour slightly.  The above example with `| wc -l' suddenly prints
the output of `wc', but the backtick command still is truncated.

I also tried to add a line

 _global_impure_ptr = &reent_data;

in dll_crt0() in but the truncation still happened.

Another change in the above mentioned patch was to change _cleanup_r()
in newlib/libc/stdio.findfp.c to call fclose instead of fflush.  I also
reverted that change and I changed the next function in that file,
_cleanup(), to call _cleanup_r with _impure_ptr instead of _GLOBAL_REENT
but this also didn't help.

I'm not as fluent in the _impure_ptr stuff as Chris and Thomas, so I'd
like to ask if you could have a look why that change exactly results in
the truncation.  Or a hint where to set a breakpoint would be helpful

For now Jeff reverted the change in include/sys/reent.h so that
_GLOBAL_REENT is defined as _impure_ptr in CVS head again.  If you
want to observe the wrong behaviour, just define _GLOBAL_REENT as
_global_impure_ptr again and recompile newlib as well as Cygwin.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Co-Project Leader
Red Hat, Inc.

More information about the Cygwin-developers mailing list