[patch] inline __getreent in newlib

Brian Dessent brian@dessent.net
Fri Sep 7 23:19:00 GMT 2007


Brian Dessent wrote:

> Done.  I added the following comment to config.h to hopefully clarify
> the situation:
> 
> /* The following provides an inline version of __getreent() for newlib,
>    which will be used throughout the library whereever there is a _r
>    version of a function that takes _REENT.  This saves the overhead
>    of a function call for what amounts to a simple computation.
> 
>    The definition below is essentially equivalent to the one in cygtls.h
>    (&_my_tls.local_clib) however it uses a fixed precomputed
>    offset rather than dereferencing a field of a structure.
> 
>    Including tlsoffets.h here in order to get this constant offset
>    tls_local_clib is a bit of a hack, but the alternative would require
>    dragging the entire definition of struct _cygtls (a large and complex
>    Cygwin internal data structure) into newlib.  The machinery to
>    compute these offsets already exists for the sake of gendef so
>    we might as well just use it here.  */

Turns out that <sys/config.h> includes <cygwin/config.h>, which leads to
this breakage when the winsup headers are installed in the system
location:

$ echo "#include <math.h>" | gcc -x c -
In file included from /usr/include/sys/config.h:180,
                 from /usr/include/_ansi.h:16,
                 from /usr/include/sys/reent.h:13,
                 from /usr/include/math.h:5,
                 from <stdin>:1:
/usr/include/cygwin/config.h:22:27: ../tlsoffsets.h: No such file or
directory

Attached patch fixes the situation by only exposing this when
_COMPILING_NEWLIB.  Ok?

Brian
-------------- next part --------------
2007-09-07  Brian Dessent  <brian@dessent.net>

	* include/cygwin/config.h: Conditionalize inline __getreent()
	definition on _COMPILING_NEWLIB.

Index: include/cygwin/config.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/cygwin/config.h,v
retrieving revision 1.6
diff -u -p -r1.6 config.h
--- include/cygwin/config.h	7 Sep 2007 00:44:27 -0000	1.6
+++ include/cygwin/config.h	7 Sep 2007 23:15:23 -0000
@@ -37,9 +37,11 @@ extern "C" {
    compute these offsets already exists for the sake of gendef so
    we might as well just use it here.  */
 
+#ifdef _COMPILING_NEWLIB
 #include "../tlsoffsets.h"
 extern char *_tlsbase __asm__ ("%fs:4");
 #define __getreent() (struct _reent *)(_tlsbase + tls_local_clib)
+#endif  /* _COMPILING_NEWLIB */
 
 #define __FILENAME_MAX__ (260 - 1 /* NUL */)
 #define _READ_WRITE_RETURN_TYPE _ssize_t


More information about the Cygwin-patches mailing list