public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* YALIOP
@ 1997-10-11 18:35 Richard Henderson
  0 siblings, 0 replies; only message in thread
From: Richard Henderson @ 1997-10-11 18:35 UTC (permalink / raw)
  To: egcs

                       Yet Another LibIO Patch

Ho hum.  It seems that glibc 1.98 on RH linux alpha _was_ compiled
with _IO_MTSAFE_IO, but somehow some of the headers weren't installed.
Which meant that the vtable wasn't in the right place, which was 
what was causing the crashes between iostreams and stdio.

This includes HJ's latest (or at least that dated 10 Oct 1997 13:41:05),
as I made a few changes to some of the generic bits.


r~



Sat Oct 11 18:25:12 1997  Richard Henderson  <rth@cygnus.com>

	* configure.in (target frags): Add alpha*-linux-gnulibc1.
	(pic frags): Its alpha*- not alpha-.
	(stdio-lock): Kill everything.  Add alpha*-linux-gnulibc1.
	* libio.h: Check __GLIBC_MINOR__ to find stdio-lock.h.  If not
	_IO_MTSAFE_IO & GLIBC, make sure the lock pointer is still there.
	* libioP.h: Check __GLIBC_MINOR__ to find libc-lock.h.

	* config/linuxaxp1-libc-lock.h: New file.
	* config/linuxaxp1-stdio-lock.h: New file.
	* config/linuxaxp1.mt: New file.

	* gen-params (va_list): Check for and use __gnuc_va_list.
	(NULL): Work around some linux kernel headers and redefine NULL.

	* Makefile.in: Undo last change; it isn't needed.
	* iofclose.c: Protect #pragma with __linux__
	* iovsprintf.c, iovscanf.c: Likewise.

Thu Oct  9 07:08:41 1997  H.J. Lu  (hjl@gnu.ai.mit.edu)

        * Makefile.in (empty.c): New target for an empty C file.
        (libio.a): Also depend on empty.o. If $(LIBIO_OBJECTS) is
        empty, create libio.a with empty.o.

        * configure.in (EXTRA_DISTCLEAN): New. set to dummy.c.

        * filedoalloc.c (_IO_file_doallocate): Don't call
        _IO_cleanup_registration_needed if __linux__ is defined.

        * iofclose.c (fclose): Make it weak alias of _IO_fclose if
        __ELF__ is defined.

        * iovsprintf.c (vsprintf): Make it weak alias of _IO_vsprintf
        if __ELF__ is defined.

        * iovsscanf.c (vsscanf): Make it weak alias of _IO_vsscanf if
        __ELF__ is defined.

        * config/linuxlibc1.mt (MT_CFLAGS): Defined as -D_G_HAVE_MMAP.
        (IO_OBJECTS): Add filedoalloc.o fileops.o genops.o iofclose.o
        iovsprintf.o iovsscanf.o strops.o.

? config/linuxaxp1.mt
? config/linuxaxp1-libc-lock.h
? config/linuxaxp1-stdio-lock.h
Index: configure.in
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/configure.in,v
retrieving revision 1.4
diff -u -p -d -r1.4 configure.in
--- configure.in	1997/09/27 04:06:54	1.4
+++ configure.in	1997/10/12 00:29:26
@@ -16,6 +16,8 @@ frags=
 
 case "${target}" in
   *-hpux*)       frags=hpux.mt ;;
+  alpha*-*-linux-gnulibc1)
+		 frags="linux.mt linuxaxp1.mt mtsafe.mt" ;;
   *-linux-gnulibc1)
 		 frags=linuxlibc1.mt ;;
   *-linux-gnu)   frags="linux.mt mtsafe.mt" ;;
@@ -36,7 +38,7 @@ if [ "${shared}" = "yes" ]; then
   case "${target}" in
     hppa*-*)	 frags="${frags} ../../config/mh-papic" ;;
     i[3456]86-*) frags="${frags} ../../config/mh-x86pic" ;;
-    alpha-*-linux*)
+    alpha*-*-linux*)
 		 frags="${frags} ../../config/mh-elfalphapic" ;;
     *)	         frags="${frags} ../../config/mh-${target_cpu}pic" ;;
   esac
@@ -44,23 +46,13 @@ fi
 
 # Make a link for the correct stdio-lock.h file.
 case "${target}" in
-  *-linux-gnu)
-    # We have a correct file in glibc but the libioP.h file is written
-    # with glibc 2.1 in mind which has the internals headers in special
-    # directory while glibc 2.0 has them in /usr/include.  Create a wrapper
-    # if necessary.
-    (echo "#include <bits/libc-lock.h>" | ${CC-cc} -E -) >/dev/null 2>&1 ||
-      {
-	rm -fr bits
-        mkdir bits
-        echo "#include <libc-lock.h>" > bits/libc-lock.h
-        echo "#include <stdio-lock.h>" > bits/stdio-lock.h
-      }
-    ;;
-  *)
-    rm -fr bits
-    mkdir bits
-    ln -s ${srcdir}/include/empty.h bits/stdio-lock.h
+  alpha*-*-linux-gnulibc1)
+    # For some reason stdio-lock.h is not installed on Red Hat systems.
+    # Further, libc-lock.h needs to define the pthreads stuff weak, and
+    # fails to do this for other than _LIBC.  Install our own versions
+    # of these files.
+    cp ${srcdir}/config/linuxaxp1-libc-lock.h libc-lock.h
+    cp ${srcdir}/config/linuxaxp1-stdio-lock.h stdio-lock.h
     ;;
 esac
 
@@ -82,6 +74,7 @@ ALL='$(_G_CONFIG_H) libio.a libiostream.
 XCINCLUDES='-I. -I$(srcdir)'
 XCXXINCLUDES='-I. -I$(srcdir)'
 MOSTLYCLEAN='*.o pic stamp-picdir core iostream.list'
+EXTRA_DISTCLEAN=dummy.c
 DISTCLEAN='config.status Makefile *~ Make.pack target-mkfrag multilib.out'
 CLEAN='_G_config.h *.a'
 INFO_FILES=iostream
Index: filedoalloc.c
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/filedoalloc.c,v
retrieving revision 1.2
diff -u -p -d -r1.2 filedoalloc.c
--- filedoalloc.c	1997/09/06 07:42:50	1.2
+++ filedoalloc.c	1997/10/12 00:29:26
@@ -75,7 +75,7 @@ _IO_file_doallocate (fp)
   char *p;
   struct stat st;
 
-#ifndef _LIBC
+#if !defined(_LIBC) && !defined(__linux__)
   /* If _IO_cleanup_registration_needed is non-zero, we should call the
      function it points to.  This is to make sure _IO_cleanup gets called
      on exit.  We call it from _IO_file_doallocate, since that is likely
Index: gen-params
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/gen-params,v
retrieving revision 1.3
diff -u -p -d -r1.3 gen-params
--- gen-params	1997/10/02 17:39:35	1.3
+++ gen-params	1997/10/12 00:29:27
@@ -488,8 +488,18 @@ if ${CXX} -c dummy.C >/dev/null 2>&1 ; t
   echo "typedef ${va_list-char* /* default */} ${macro_prefix}va_list;"
 else
   # No, it breaks.  Indicate that <stdarg.h> must be included.
-  echo "#define ${macro_prefix}NEED_STDARG_H
-#define ${macro_prefix}va_list va_list"
+  echo "#define ${macro_prefix}NEED_STDARG_H"
+  # Check and see if we have __gnuc_va_list, as we might set up define
+  # loops if we use va_list.
+  cat >dummy.C <<!EOF!
+#include <stdarg.h>
+long foo(__gnuc_va_list ap) { return va_arg(ap, long); }
+!EOF!
+  if ${CXX} -c dummy.C >/dev/null 2>&1 ; then
+    echo "#define ${macro_prefix}va_list __gnuc_va_list"
+  else
+    echo "#define ${macro_prefix}va_list va_list"
+  fi
 fi
 
 cat >dummy.c <<!EOF!
@@ -712,5 +722,25 @@ fi
 # echo "#define ${macro_prefix}NO_TEMPLATES"
 
 rm -f dummy.C dummy.o dummy.c dummy.out TMP core a.out
+
+# On some versions of Linux we can collect NULL = ((void *)0) from 
+# kernel header files despite __cplusplus.
+# Take the easy way out and just undef any existing definition.
+
+cat <<!EOF!
+#undef NULL
+#ifndef NULL
+# if defined __GNUG__ && \
+    (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+#  define NULL (__null)
+# else
+#  if !defined(__cplusplus)
+#   define NULL ((void*)0)
+#  else
+#   define NULL (0)
+#  endif
+# endif
+#endif
+!EOF!
 
 echo "#endif /* !${macro_prefix}config_h */"
Index: iofclose.c
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/iofclose.c,v
retrieving revision 1.2
diff -u -p -d -r1.2 iofclose.c
--- iofclose.c	1997/09/06 07:42:53	1.2
+++ iofclose.c	1997/10/12 00:29:27
@@ -55,4 +55,8 @@ _IO_fclose (fp)
 
 #ifdef weak_alias
 weak_alias (_IO_fclose, fclose)
+#else
+#if defined(__linux__) && defined(__ELF__)
+#pragma weak fclose = _IO_fclose
+#endif
 #endif
Index: iovsprintf.c
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/iovsprintf.c,v
retrieving revision 1.2
diff -u -p -d -r1.2 iovsprintf.c
--- iovsprintf.c	1997/09/06 07:43:39	1.2
+++ iovsprintf.c	1997/10/12 00:29:27
@@ -54,4 +54,8 @@ _IO_vsprintf (string, format, args)
 
 #ifdef weak_alias
 weak_alias (_IO_vsprintf, vsprintf)
+#else
+#if defined(__linux__) && defined(__ELF__)
+#pragma weak vsprintf = _IO_vsprintf
+#endif
 #endif
Index: iovsscanf.c
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/iovsscanf.c,v
retrieving revision 1.2
diff -u -p -d -r1.2 iovsscanf.c
--- iovsscanf.c	1997/09/06 07:43:41	1.2
+++ iovsscanf.c	1997/10/12 00:29:27
@@ -51,4 +51,8 @@ _IO_vsscanf (string, format, args)
 #ifdef weak_alias
 weak_alias (_IO_vsscanf, __vsscanf)
 weak_alias (_IO_vsscanf, vsscanf)
+#else
+#if defined(__linux__) && defined(__ELF__)
+#pragma weak vsscanf = _IO_vsscanf
+#endif
 #endif
Index: libio.h
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/libio.h,v
retrieving revision 1.8
diff -u -p -d -r1.8 libio.h
--- libio.h	1997/10/03 17:14:05	1.8
+++ libio.h	1997/10/12 00:29:27
@@ -150,22 +150,27 @@ struct _IO_jump_t;  struct _IO_FILE;
 /* Handle lock.  */
 #ifdef _IO_MTSAFE_IO
 # if defined __GLIBC__ && __GLIBC__ >= 2
-#  include <bits/stdio-lock.h>
+#  if __GLIBC_MINOR__ > 0
+#   include <bits/stdio-lock.h>
+#  else
+#   include <stdio-lock.h>
+#  endif
 #  define _IO_LOCK_T _IO_lock_t *
 # else
 /*# include <comthread.h>*/
 # endif
 #else
-/* XXX This will go away as soon as comthread is finished.  */
-# ifdef __linux__
-struct _IO_lock_t {
-  void *ptr;
-  short int field1;
-  short int field2;
-};
-#  define _IO_LOCK_T struct _IO_lock_t
+# if defined(__GLIBC__) && __GLIBC__ >= 2
+   typedef void _IO_lock_t;
+#  define _IO_LOCK_T void *
 # else
-typedef void _IO_lock_t;
+   /* XXX This will go away as soon as comthread is finished.  */
+#  ifdef __linux__
+    struct _IO_lock_t { void *ptr; short int field1, field2; };
+#   define _IO_LOCK_T struct _IO_lock_t
+#  else
+    typedef void _IO_lock_t;
+#  endif
 # endif
 #endif
 
Index: libioP.h
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/libioP.h,v
retrieving revision 1.4
diff -u -p -d -r1.4 libioP.h
--- libioP.h	1997/09/17 00:54:02	1.4
+++ libioP.h	1997/10/12 00:29:27
@@ -28,7 +28,11 @@
 # define __set_errno(Val) errno = (Val)
 #endif
 #if defined __GLIBC__ && __GLIBC__ >= 2
-# include <bits/libc-lock.h>
+# if __GLIBC_MINOR__ > 0
+#  include <bits/libc-lock.h>
+# else
+#  include <libc-lock.h>
+# endif
 #else
 /*# include <comthread.h>*/
 #endif
Index: config/linuxlibc1.mt
===================================================================
RCS file: /cvs/cvsfiles/egcs/libio/config/linuxlibc1.mt,v
retrieving revision 1.3
diff -u -p -d -r1.3 linuxlibc1.mt
--- linuxlibc1.mt	1997/10/02 17:39:40	1.3
+++ linuxlibc1.mt	1997/10/12 00:29:27
@@ -9,7 +9,9 @@
 LIBIO_INCLUDE=
 
 # We have those in libc.a.
-IO_OBJECTS=iogetc.o ioputc.o iofeof.o ioferror.o
+IO_OBJECTS=iogetc.o ioputc.o iofeof.o ioferror.o \
+       filedoalloc.o fileops.o genops.o iofclose.o \
+       iovsprintf.o iovsscanf.o strops.o
 STDIO_WRAP_OBJECTS=
 OSPRIM_OBJECTS=
 STDIO_OBJECTS=
*** /dev/null	Wed Aug 13 13:41:06 1997
--- config/linuxaxp1-libc-lock.h	Sat Oct 11 15:06:42 1997
***************
*** 0 ****
--- 1,111 ----
+ /* libc-internal interface for mutex locks.  LinuxThreads version.
+    Copyright (C) 1996 Free Software Foundation, Inc.
+    This file is part of the GNU C Library.
+ 
+    The GNU C Library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+ 
+    The GNU C Library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+ 
+    You should have received a copy of the GNU Library General Public
+    License along with the GNU C Library; see the file COPYING.LIB.  If not,
+    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.  */
+ 
+ #ifndef _LIBC_LOCK_H
+ #define _LIBC_LOCK_H 1
+ 
+ #include <pthread.h>
+ #define __libc_lock_t pthread_mutex_t
+ 
+ /* Define a lock variable NAME with storage class CLASS.  The lock must be
+    initialized with __libc_lock_init before it can be used (or define it
+    with __libc_lock_define_initialized, below).  Use `extern' for CLASS to
+    declare a lock defined in another module.  In public structure
+    definitions you must use a pointer to the lock structure (i.e., NAME
+    begins with a `*'), because its storage size will not be known outside
+    of libc.  */
+ #define __libc_lock_define(CLASS,NAME) \
+   CLASS __libc_lock_t NAME;
+ 
+ /* Define an initialized lock variable NAME with storage class CLASS.  */
+ #define __libc_lock_define_initialized(CLASS,NAME) \
+   CLASS __libc_lock_t NAME = PTHREAD_MUTEX_INITIALIZER;
+ 
+ /* Initialize the named lock variable, leaving it in a consistent, unlocked
+    state.  */
+ #define __libc_lock_init(NAME) \
+   (__pthread_mutex_init != NULL ? __pthread_mutex_init (&(NAME), NULL) : 0);
+ 
+ /* Same as last but this time we initialize a recursive mutex.  */
+ #define __libc_lock_init_recursive(NAME) \
+   do {									      \
+     if (__pthread_mutex_init != NULL)					      \
+       {									      \
+ 	pthread_mutexattr_t __attr;					      \
+ 	__pthread_mutexattr_init (&__attr);				      \
+ 	__pthread_mutexattr_setkind_np (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \
+ 	__pthread_mutex_init (&(NAME), &__attr);			      \
+ 	__pthread_mutexattr_destroy (&__attr);				      \
+       }									      \
+   } while (0);
+ 
+ /* Finalize the named lock variable, which must be locked.  It cannot be
+    used again until __libc_lock_init is called again on it.  This must be
+    called on a lock variable before the containing storage is reused.  */
+ #define __libc_lock_fini(NAME) \
+   (__pthread_mutex_destroy != NULL ? __pthread_mutex_destroy (&(NAME)) : 0);
+ 
+ /* Lock the named lock variable.  */
+ #define __libc_lock_lock(NAME) \
+   (__pthread_mutex_lock != NULL ? __pthread_mutex_lock (&(NAME)) : 0);
+ 
+ /* Try to lock the named lock variable.  */
+ #define __libc_lock_trylock(NAME) \
+   (__pthread_mutex_trylock != NULL ? __pthread_mutex_trylock (&(NAME)) : 0);
+ 
+ /* Unlock the named lock variable.  */
+ #define __libc_lock_unlock(NAME) \
+   (__pthread_mutex_unlock != NULL ? __pthread_mutex_unlock (&(NAME)) : 0);
+ 
+ /* Start critical region with cleanup.  */
+ #define __libc_cleanup_region_start(FCT, ARG) \
+   { struct _pthread_cleanup_buffer _buffer;				      \
+     if (_pthread_cleanup_push_defer != NULL) {				      \
+       _pthread_cleanup_push_defer (&_buffer, (FCT), (ARG));		      \
+     }
+ 
+ /* End critical region with cleanup.  */
+ #define __libc_cleanup_region_end(DOIT) \
+     if (_pthread_cleanup_push_defer != NULL) {				      \
+       _pthread_cleanup_pop_restore (&_buffer, (DOIT));			      \
+     }									      \
+   }
+ 
+ /* Make the pthread functions weak so that we can elide them from
+    single-threaded processes.  */
+ #pragma weak __pthread_mutex_init
+ #pragma weak __pthread_mutex_destroy
+ #pragma weak __pthread_mutex_lock
+ #pragma weak __pthread_mutex_trylock
+ #pragma weak __pthread_mutex_unlock
+ #pragma weak __pthread_mutexattr_init
+ #pragma weak __pthread_mutexattr_destroy
+ #pragma weak __pthread_mutexattr_setkind_np
+ #pragma weak __pthread_key_create
+ #pragma weak __pthread_setspecific
+ #pragma weak __pthread_getspecific
+ #pragma weak __pthread_initialize
+ #pragma weak _pthread_cleanup_push_defer
+ #pragma weak _pthread_cleanup_pop_restore
+ 
+ /* We need portable names for some functions.  E.g., when they are
+    used as argument to __libc_cleanup_region_start.  */
+ #define __libc_mutex_unlock __pthread_mutex_unlock
+ 
+ #endif	/* libc-lock.h */
*** /dev/null	Wed Aug 13 13:41:06 1997
--- config/linuxaxp1-stdio-lock.h	Sat Oct 11 15:06:51 1997
***************
*** 0 ****
--- 1,35 ----
+ /* Thread package specific definitions of stream lock type.
+    Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+    This file is part of the GNU C Library.
+ 
+    The GNU C Library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.
+ 
+    The GNU C Library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+ 
+    You should have received a copy of the GNU Library General Public
+    License along with the GNU C Library; see the file COPYING.LIB.  If not,
+    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+    Boston, MA 02111-1307, USA.  */
+ 
+ #include <pthread.h>
+ 
+ typedef pthread_mutex_t _IO_lock_t;
+ 
+ /* We need recursive (counting) mutexes.  */
+ #define _IO_lock_initializer PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+ 
+ 
+ #define _IO_cleanup_region_start(_fct, _fp) \
+      __libc_cleanup_region_start (_fct, _fp)
+ #define _IO_cleanup_region_end(_doit) \
+      __libc_cleanup_region_end (_doit)
+ #define _IO_lock_init(_name) \
+      __libc_lock_init_recursive (_name)
+ #define _IO_lock_fini(_name) \
+      __libc_lock_fini_recursive (_name)
*** /dev/null	Wed Aug 13 13:41:06 1997
--- config/linuxaxp1.mt	Sat Oct 11 17:25:56 1997
***************
*** 0 ****
--- 1,10 ----
+ # We _do_ need a new _G_config.h
+ _G_CONFIG_H=_G_config.h
+ 
+ # And the two bits files.
+ all:
+ install: install-axp-mt-headers
+ 
+ install-axp-mt-headers:
+ 	$(INSTALL_DATA) libc-lock.h $(gxx_includedir)/libc-lock.h
+ 	$(INSTALL_DATA) stdio-lock.h $(gxx_includedir)/stdio-lock.h

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-10-11 18:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-11 18:35 YALIOP Richard Henderson

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