PATCH to support libio default, V3 testsuite results, on FreeBSD 3+

Loren James Rittle rittle@latour.rsch.comm.mot.com
Thu Nov 16 02:57:00 GMT 2000


With the libtool configuration patches I posted earlier
( http://sources.redhat.com/ml/libstdc++/2000-11/msg00225.html ) and the
patches below (which were in my tree at the time I reported the
requirement of those patches but I have now changed my configuration
back to libio), I see even fewer libstdc++-v3 testsuite failures
(currently 2 run-time and 3 build-time with --enable-cstdio\=libio)
both with -static and without on FreeBSD against both the threaded and
non-threaded C library and `make check-g++' continues to look as
expected (for the record, I have this simple patch in my tree as well:
http://sources.redhat.com/ml/libstdc++/2000-11/msg00226.html ).

I have not fully exercised the threading support yet (other than to
ensure that one thread can't hang itself ;-).  However, given the
trouble I had getting --enable-threads=posix up and running, I must
conclude that no one else, using fake libio support on a non-glibc
machine, is configuring with it yet.  If you are the porter for such a
platform that has pthread support, you might want to take a look at
what I did for the time being.  See my code comments on what we might
consider doing instead of leaving this up to each port's os_defines.h.

This also uncovers a broader issue.  I can confirm that BSD only needs
most of what is in os_defines.h during the actual building of
libstdc++.  User code building against the library doesn't need it
all.  In fact, it might be dangerous to include it all (e.g. exposing
symbols from pthreads.h and stat64 might not be nice things to do).
There may be a need for macro symbols that can be tested inside
os_defines.h for the following:

- threads enabled? (unless uncoupled from os_defines.h)
- thread type? (unless uncoupled from os_defines.h)
- building library or application code? (may not be important if
  threading issues are uncoupled from os_defines.h)
- fake libio or stdio targeted? (may not be important if threading
  issues are uncoupled from os_defines.h)

BTW, it is obviously not OK to include c++threads.h, c++config.h or
even plain config.h to get access to that information inside
os_defines.h.  We might still need to consider not leaking stat64
(fake libio could use __stat64 instead this keeps in line with other
required defines and/or typedefs).

Current testsuite failures (--enable-cstdio=stdio --enable-shared
--enable-threads\=posix):

-b      -b      20_util/auto_ptr.cc
-r      -r      21_strings/inserters_extractors.cc
-r      -r      22_locale/codecvt_wchar_t_char.cc
-b      -b      23_containers/map_operators.cc
-b      -b      23_containers/set_operators.cc
-r      -r      27_io/filebuf.cc
-r      -r      27_io/filebuf_members.cc
-r      -r      27_io/istream_seeks.cc
-r      -r      27_io/ostream_inserter_arith.cc

Current testsuite failures (--enable-cstdio=libio --enable-shared
--enable-threads\=posix):

-b      -b      20_util/auto_ptr.cc
-r      -r      22_locale/codecvt_wchar_t_char.cc
-b      -b      23_containers/map_operators.cc
-b      -b      23_containers/set_operators.cc
-r      -r      27_io/ostream_inserter_arith.cc

Current `make check-g++ (-pthread -fpic)' results (--enable-cstdio=libio
--enable-shared --enable-threads\=posix) with comments:

FAIL: g++.eh/badalloc1.C  Execution test (failing against V2)
FAIL: g++.law/profile1.C  Execution test (new failure:
	appears to be a conflict between -pg and my mutex configuration)
FAIL: g++.other/crash18.C (test for excess errors) (failing against V2)
FAIL: g++.other/loop2.C caused compiler crash (failing against V2)
XPASS: g++.robertl/eb55.C (test for excess errors) (new success)

Since many things are now resolved, even with the remaining issues, I
would like this configuration file to be installed so that other BSD
users can begin testing libstdc++-v3.  Let me put it this way: I don't
think I am possibly breaking anyone's current configuration... ;-)

As described above, fully regression tested on i686-unknown-freebsd3.4
against V2.  Expected to work on other FreeBSD releases, NetBSD and
OpenBSD (I did look closely at recent versions of required NetBSD
system headers).

Final warning to would be users of this beta support for BSD: you
*must* configure with either --enable-threads=posix or
--enable-cstdio\=stdio or else you will see this message during your
bootstrap:

[...]/egcs/libstdc++-v3/libio/libio.h:164: conflicting types for `_IO_lock_t'
../include/bits/os_defines.h:123: previous declaration of `_IO_lock_t'

Sorry, I have no way to fix that issue until:

- we uncouple threading support issues for fake libio from
  os_defines.h;
- we hack up libio.h a little bit more; or
- I have macro symbols to key off within os_defines.h as described
above.

Regards,
Loren

2000-11-16  Loren J. Rittle  <ljrittle@acm.org>

	* libio/libio.h: Protect function prototypes from macro expansion.
	* config/os/bsd/bits/os_defines.h: New file (basically).

Index: libstdc++-v3/libio/libio.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libio/libio.h,v
retrieving revision 1.11
diff -c -r1.11 libio.h
*** libio.h	2000/10/29 21:52:54	1.11
--- libio.h	2000/11/16 08:32:03
***************
*** 438,445 ****
  #define _IO_PENDING_OUTPUT_COUNT(_fp)	\
  	((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
  
! extern void _IO_flockfile (_IO_FILE *) __THROW;
! extern void _IO_funlockfile (_IO_FILE *) __THROW;
  extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
  
  #ifdef _IO_MTSAFE_IO
--- 438,445 ----
  #define _IO_PENDING_OUTPUT_COUNT(_fp)	\
  	((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
  
! extern void (_IO_flockfile) (_IO_FILE *) __THROW;
! extern void (_IO_funlockfile) (_IO_FILE *) __THROW;
  extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
  
  #ifdef _IO_MTSAFE_IO
Index: libstdc++-v3/config/os/bsd/bits/os_defines.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/os/bsd/bits/os_defines.h,v
retrieving revision 1.3
diff -c -r1.3 os_defines.h
*** os_defines.h	2000/10/25 12:50:05	1.3
--- os_defines.h	2000/11/16 08:32:03
***************
*** 35,41 ****
  /* System-specific #define, typedefs, corrections, etc, go here.  This
     file will come before all others. */
  
! 
  #endif
  
  
--- 35,153 ----
  /* System-specific #define, typedefs, corrections, etc, go here.  This
     file will come before all others. */
  
! /* BSD system headers traditionally define the __P macro in
!    /usr/include/sys/cdefs.h, which is eventually included in any
!    compilations that include standard headers (luckily, for a similar
!    purpose, however libio/libio.h's exact definition breaks our system
!    headers), thus we need to explicitly, and preemptively, resolve the
!    conflict between libio/libio.h and our system headers.  We need to
!    define the other macros defined in libio/libio.h since they won't
!    be defined when __P is already defined. */
! #include <sys/cdefs.h>
! #ifdef __P
! # define __PMT(p) p
! # ifdef __cplusplus
! #  define __THROW throw ()
! # else 
! #  define __THROW 
! # endif
  #endif
  
+ /* This is a pure hack (BTW, I attempted to key this section off
+    _GLIBCPP_USE_THREADS as seen in config.h - bad idea since it works
+    in the build tree but not in the install tree).  Since this issue
+    seems orthogonal to platform selection, the correct move would
+    appear to be to extend the include/bits/c++threads.h model and
+    allow that to setup threads for fake libio use.  However, since gcc
+    already provides an abstraction layer for mutexs, it might be
+    better to slightly extend gcc/gthr-*.h and junk
+    include/bits/c++threads.h altogether and force fake libio to use
+    the model provided by that interface unless running on a machine
+    that already has the libio thread support. */
+ #include <pthread.h>
+ 
+ /* The following supports --enable-threads\=posix (some code adapted
+    and extended from gcc/gthr-posix.h).  Mutex overhead is only
+    incurred when pthread library is linked in. */
+ #pragma weak pthread_mutex_init
+ #pragma weak pthread_mutex_destroy
+ #pragma weak pthread_mutex_lock
+ #pragma weak pthread_mutex_unlock
+ 
+ static void *__gthread_active_ptr = (void *) &pthread_mutex_init;
+ 
+ static inline int
+ __gthread_active_p (void)
+ {
+   return __gthread_active_ptr != 0;
+ }
+ 
+ static inline int
+ __gthread_mutex_init (pthread_mutex_t *mutex)
+ {
+   if (__gthread_active_p ())
+     return pthread_mutex_init (mutex, NULL);
+   else
+     return 0;
+ }
+ 
+ static inline int
+ __gthread_mutex_destroy (pthread_mutex_t *mutex)
+ {
+   if (__gthread_active_p ())
+     return pthread_mutex_destroy (mutex);
+   else
+     return 0;
+ }
+ 
+ static inline int
+ __gthread_mutex_lock (pthread_mutex_t *mutex)
+ {
+   if (__gthread_active_p ())
+     return pthread_mutex_lock (mutex);
+   else
+     return 0;
+ }
+ 
+ static inline int
+ __gthread_mutex_unlock (pthread_mutex_t *mutex)
+ {
+   if (__gthread_active_p ())
+     return pthread_mutex_unlock (mutex);
+   else
+     return 0;
+ }
  
+ /* The following supports --enable-threads\=posix (some code taken
+    from /usr/include/bits/stdio-lock.h). */
+ typedef pthread_mutex_t _IO_lock_t;
+ 
+ /* We need recursive (counting) mutexes.  Thus _IO_lock_initializer
+    and _IO_lock_init might be wrong. */
+ #define _IO_lock_initializer PTHREAD_MUTEX_INITIALIZER
+ 
+ #define _IO_lock_init(_name) __gthread_mutex_init (&_name)
+ #define _IO_lock_fini(_name) __gthread_mutex_destroy (&_name)
+ #define _IO_lock_lock(_name) __gthread_mutex_lock (&_name)
+ #define _IO_lock_unlock(_name) __gthread_mutex_unlock (&_name)
+ 
+ #define _IO_flockfile(_fp)
+ #define _IO_funlockfile(_fp)
+ #define _IO_cleanup_region_start(_fct, _fp)
+ #define _IO_cleanup_region_end(_doit)
+ 
+ #ifdef __FreeBSD__
+ /* Warning to other BSD maintainers: GCC *does* use thunks on FreeBSD;
+    it probably doesn't on your BSD. */
+ # undef _G_USING_THUNKS
+ # define _G_USING_THUNKS 1
+ 
+ typedef off_t __off_t;
+ typedef off_t __off64_t;
+ typedef ssize_t __ssize_t;
+ # define stat64 stat
+ #else
+ # error Must add support for your BSD box here.
+ #endif
+ 
+ #endif


More information about the Libstdc++ mailing list