about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rwxr-xr-xconfigure47
-rw-r--r--include/unistd.h4
-rw-r--r--sysdeps/generic/libc-start.c32
-rw-r--r--sysdeps/unix/sysv/linux/Makefile2
-rw-r--r--sysdeps/unix/sysv/linux/_exit.c38
-rw-r--r--sysdeps/unix/sysv/linux/exit-thread.S23
-rw-r--r--sysdeps/unix/sysv/linux/i386/_exit.S43
8 files changed, 171 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index ca778e0f68..b2a7f941e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-09-14  Ulrich Drepper  <drepper@redhat.com>
+
+	* include/unistd.h: Declare __exit_thread.
+	* sysdeps/generic/libc-start.c: Remove dummy_addr.
+	Wrap call to main in setjmp if HAVE_CANCELBUF is defined.
+	* sysdeps/unix/sysv/linux/exit-thread.S: New file.
+	* sysdeps/unix/sysv/linux/_exit.c: New file.
+	* sysdeps/unix/sysv/linux/i386/_exit.S: New file.
+	* sysdeps/unix/sysv/linux/Makefile [subdir==posix] (sysdep_routines):
+	Add exit-thread.
+
+	* configure.in: Add dl_iterate_phdr to test using -nostdlib.
+
 2002-09-12  Jakub Jelinek  <jakub@redhat.com>
 
 	* sysdeps/i386/dl-machine.h (elf_machine_rel)
diff --git a/configure b/configure
index c3b79b6fbc..470e5b4d1a 100755
--- a/configure
+++ b/configure
@@ -3526,17 +3526,18 @@ memset () {}
 free () {}
 abort () {}
 __bzero () {}
+dl_iterate_phdr () {}
 EOF
 if { ac_try='${CC-cc} $CFLAGS -DCHECK__register_frame_info
 			    -nostdlib -nostartfiles
-			    -o conftest conftest.c -lgcc >&5'; { (eval echo configure:3533: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
+			    -o conftest conftest.c -lgcc >&5'; { (eval echo configure:3534: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
   libc_cv_gcc_dwarf2_unwind_info=static
 else
   libc_cv_gcc_dwarf2_unwind_info=no
 fi
 if { ac_try='${CC-cc} $CFLAGS -DCHECK__register_frame_info
                             -nostdlib -nostartfiles
-                            -o conftest conftest.c -lgcc -lgcc_eh >&5'; { (eval echo configure:3540: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
+                            -o conftest conftest.c -lgcc -lgcc_eh >&5'; { (eval echo configure:3541: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
   if ${CC-cc} $CFLAGS -DCHECK__register_frame_info -nostdlib -nostartfiles \
      -o conftest conftest.c -lgcc -lgcc_eh -v 2>&1 >/dev/null \
      | grep -q -- --eh-frame-hdr; then
@@ -3550,7 +3551,7 @@ fi
 if test $libc_cv_gcc_dwarf2_unwind_info = no; then
   if { ac_try='${CC-cc} $CFLAGS -DCHECK__register_frame
 			      -nostdlib -nostartfiles
-			      -o conftest conftest.c -lgcc >&5'; { (eval echo configure:3554: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
+			      -o conftest conftest.c -lgcc >&5'; { (eval echo configure:3555: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
     libc_cv_gcc_dwarf2_unwind_info=yes
   else
     libc_cv_gcc_dwarf2_unwind_info=no
@@ -3580,12 +3581,12 @@ EOF
 esac
 
 echo $ac_n "checking for __builtin_expect""... $ac_c" 1>&6
-echo "configure:3584: checking for __builtin_expect" >&5
+echo "configure:3585: checking for __builtin_expect" >&5
 if eval "test \"`echo '$''{'libc_cv_gcc_builtin_expect'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
-#line 3589 "configure"
+#line 3590 "configure"
 int foo (int a)
 {
   a = __builtin_expect (a, 10);
@@ -3593,7 +3594,7 @@ int foo (int a)
 }
 EOF
 if { ac_try='${CC-cc} $CFLAGS -nostdlib -nostartfiles
-			    -o conftest conftest.c -lgcc >&5'; { (eval echo configure:3597: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
+			    -o conftest conftest.c -lgcc >&5'; { (eval echo configure:3598: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
   libc_cv_gcc_builtin_expect=yes
 else
   libc_cv_gcc_builtin_expect=no
@@ -3610,7 +3611,7 @@ EOF
 fi
 
 echo $ac_n "checking for __builtin_memset""... $ac_c" 1>&6
-echo "configure:3614: checking for __builtin_memset" >&5
+echo "configure:3615: checking for __builtin_memset" >&5
 if eval "test \"`echo '$''{'libc_cv_gcc_builtin_memset'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3620,7 +3621,7 @@ void zero (void *x)
   __builtin_memset (x, 0, 1000);
 }
 EOF
-if { ac_try='${CC-cc} -O3 -S conftest.c -o - | fgrep "memset" > /dev/null'; { (eval echo configure:3624: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; };
+if { ac_try='${CC-cc} -O3 -S conftest.c -o - | fgrep "memset" > /dev/null'; { (eval echo configure:3625: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; };
 then
   libc_cv_gcc_builtin_memset=no
 else
@@ -3638,12 +3639,12 @@ EOF
 fi
 
 echo $ac_n "checking for local label subtraction""... $ac_c" 1>&6
-echo "configure:3642: checking for local label subtraction" >&5
+echo "configure:3643: checking for local label subtraction" >&5
 if eval "test \"`echo '$''{'libc_cv_gcc_subtract_local_labels'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
-#line 3647 "configure"
+#line 3648 "configure"
 int foo (int a)
 {
   static const int ar[] = { &&l1 - &&l1, &&l2 - &&l1 };
@@ -3656,7 +3657,7 @@ int foo (int a)
 }
 EOF
 if { ac_try='${CC-cc} $CFLAGS -nostdlib -nostartfiles
-			    -o conftest conftest.c -lgcc >&5'; { (eval echo configure:3660: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
+			    -o conftest conftest.c -lgcc >&5'; { (eval echo configure:3661: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
   libc_cv_gcc_subtract_local_labels=yes
 else
   libc_cv_gcc_subtract_local_labels=no
@@ -3673,14 +3674,14 @@ EOF
 fi
 
 echo $ac_n "checking for __thread""... $ac_c" 1>&6
-echo "configure:3677: checking for __thread" >&5
+echo "configure:3678: checking for __thread" >&5
 if eval "test \"`echo '$''{'libc_cv_gcc___thread'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
 __thread int a = 42;
 EOF
-if { ac_try='${CC-cc} $CFLAGS -c conftest.c >&5'; { (eval echo configure:3684: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
+if { ac_try='${CC-cc} $CFLAGS -c conftest.c >&5'; { (eval echo configure:3685: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
   libc_cv_gcc___thread=yes
 else
   libc_cv_gcc___thread=no
@@ -3698,7 +3699,7 @@ fi
 
 
 echo $ac_n "checking for libgd""... $ac_c" 1>&6
-echo "configure:3702: checking for libgd" >&5
+echo "configure:3703: checking for libgd" >&5
 if test "$with_gd" != "no"; then
   old_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS $libgd_include"
@@ -3707,14 +3708,14 @@ if test "$with_gd" != "no"; then
   old_LIBS="$LIBS"
   LIBS="$LIBS -lgd -lpng -lz -lm"
   cat > conftest.$ac_ext <<EOF
-#line 3711 "configure"
+#line 3712 "configure"
 #include "confdefs.h"
 #include <gd.h>
 int main() {
 gdImagePng (0, 0)
 ; return 0; }
 EOF
-if { (eval echo configure:3718: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3719: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   LIBGD=yes
 else
@@ -3734,7 +3735,7 @@ echo "$ac_t""$LIBGD" 1>&6
 
 
 echo $ac_n "checking size of long double""... $ac_c" 1>&6
-echo "configure:3738: checking size of long double" >&5
+echo "configure:3739: checking size of long double" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_long_double'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3742,7 +3743,7 @@ else
   ac_cv_sizeof_long_double=0
 else
   cat > conftest.$ac_ext <<EOF
-#line 3746 "configure"
+#line 3747 "configure"
 #include "confdefs.h"
 #include <stdio.h>
 int main()
@@ -3753,7 +3754,7 @@ int main()
   return(0);
 }
 EOF
-if { (eval echo configure:3757: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3758: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_long_double=`cat conftestval`
 else
@@ -3831,7 +3832,7 @@ if test "$uname" = "sysdeps/generic"; then
   fi
 
   echo $ac_n "checking OS release for uname""... $ac_c" 1>&6
-echo "configure:3835: checking OS release for uname" >&5
+echo "configure:3836: checking OS release for uname" >&5
 if eval "test \"`echo '$''{'libc_cv_uname_release'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3853,7 +3854,7 @@ echo "$ac_t""$libc_cv_uname_release" 1>&6
   uname_release="$libc_cv_uname_release"
 
   echo $ac_n "checking OS version for uname""... $ac_c" 1>&6
-echo "configure:3857: checking OS version for uname" >&5
+echo "configure:3858: checking OS version for uname" >&5
 if eval "test \"`echo '$''{'libc_cv_uname_version'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3882,7 +3883,7 @@ EOF
 # Test for old glibc 2.0.x headers so that they can be removed properly
 # Search only in includedir.
 echo $ac_n "checking for old glibc 2.0.x headers""... $ac_c" 1>&6
-echo "configure:3886: checking for old glibc 2.0.x headers" >&5
+echo "configure:3887: checking for old glibc 2.0.x headers" >&5
 if eval test -f "${includedir}/elfclass.h" -a -f "${includedir}/fcntlbits.h"
 then
   old_glibc_headers=yes
@@ -3943,7 +3944,7 @@ if test $shared = default; then
 fi
 
 echo $ac_n "checking whether -fPIC is default""... $ac_c" 1>&6
-echo "configure:3947: checking whether -fPIC is default" >&5
+echo "configure:3948: checking whether -fPIC is default" >&5
 if eval "test \"`echo '$''{'pic_default'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
diff --git a/include/unistd.h b/include/unistd.h
index 289eb4b740..26993d4dfe 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -140,4 +140,8 @@ extern int __libc_enable_secure_internal attribute_hidden;
 /* Various internal function.  */
 extern void __libc_check_standard_fds (void);
 
+
+/* Special exit function which only terminates the current thread.  */
+extern void __exit_thread (int val) __attribute__ ((noreturn));
+
 #endif
diff --git a/sysdeps/generic/libc-start.c b/sysdeps/generic/libc-start.c
index 8d523e6836..c619341e56 100644
--- a/sysdeps/generic/libc-start.c
+++ b/sysdeps/generic/libc-start.c
@@ -29,8 +29,8 @@ weak_extern (_dl_starting_up)
 extern int __libc_multiple_libcs;
 extern void *__libc_stack_end;
 
+#include <tls.h>
 #ifndef SHARED
-# include <tls.h>
 extern void __pthread_initialize_minimal (void)
 # if !(USE_TLS - 0)
      __attribute__ ((weak))
@@ -63,17 +63,15 @@ BP_SYM (__libc_start_main) (int (*main) (int, char **, char **),
 # define argv ubp_av
 #endif
 
+  /* Result of the 'main' function.  */
+  int result;
+
 #ifndef SHARED
 # ifdef HAVE_AUX_VECTOR
   void *__unbounded *__unbounded auxvec;
 # endif
 
-  /* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
-     If the address would be taken inside the expression the optimizer
-     would try to be too smart and throws it away.  Grrr.  */
-  int *dummy_addr = &_dl_starting_up;
-
-  __libc_multiple_libcs = dummy_addr && !_dl_starting_up;
+  __libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
 #endif
 
   INIT_ARGV_and_ENVIRON;
@@ -137,5 +135,23 @@ BP_SYM (__libc_start_main) (int (*main) (int, char **, char **),
     _dl_debug_printf ("\ntransferring control: %s\n\n", argv[0]);
 #endif
 
-  exit ((*main) (argc, argv, __environ));
+#ifdef HAVE_CANCELBUF
+  if (setjmp (THREAD_SELF->cancelbuf) == 0)
+#endif
+    {
+      /* XXX This is where the try/finally handling must be used.  */
+
+      result = main (argc, argv, __environ);
+    }
+#ifdef HAVE_CANCELBUF
+  else
+    {
+      /* XXX We should free the thread-specific data.  */
+
+      /* Not much left to do but to exit the thread, not the process.  */
+      __exit_thread (0);
+    }
+#endif
+
+  exit (result);
 }
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index cc37196526..13430d1a87 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -88,6 +88,8 @@ endif
 
 ifeq ($(subdir),posix)
 sysdep_headers += bits/pthreadtypes.h bits/initspin.h
+
+sysdep_routines += exit-thread
 endif
 
 ifeq ($(subdir),inet)
diff --git a/sysdeps/unix/sysv/linux/_exit.c b/sysdeps/unix/sysv/linux/_exit.c
new file mode 100644
index 0000000000..3bd6b6db4c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/_exit.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2002 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sysdep.h>
+#include <abort-instr.h>
+
+
+void
+_exit (status)
+     int status;
+{
+  while (1)
+    {
+#ifdef __NR_exit_group
+      INLINE_SYSCALL (exit_group, 1, status);
+#endif
+      INLINE_SYSCALL (exit, 1, status);
+
+      ABORT_INSTRUCTION;
+    }
+}
diff --git a/sysdeps/unix/sysv/linux/exit-thread.S b/sysdeps/unix/sysv/linux/exit-thread.S
new file mode 100644
index 0000000000..bb996fecf7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/exit-thread.S
@@ -0,0 +1,23 @@
+/* Copyright (C) 1991,92,97,99,2002 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+
+PSEUDO (__exit_thread, exit, 1)
+	/* Shouldn't get here.  */
+PSEUDO_END(__exit_thread)
diff --git a/sysdeps/unix/sysv/linux/i386/_exit.S b/sysdeps/unix/sysv/linux/i386/_exit.S
new file mode 100644
index 0000000000..56561e94bb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/_exit.S
@@ -0,0 +1,43 @@
+/* Copyright (C) 2002 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 Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+
+	.text
+	.type	_exit,@function
+	.global	_exit
+_exit:
+	movl	4(%esp), %ebx
+
+	/* Try the new syscall first.  */
+#ifdef __NR_exit_group
+	movl	$__NR_exit_group, %eax
+	int	$0x80
+#endif
+
+	/* Not available.  Now the old one.  */
+	movl	$__NR_exit, %eax
+	int	$0x80
+
+	/* This must not fail.  Be sure we don't return.  */
+	hlt
+	.size	_exit,.-_exit
+
+	.globl	_Exit
+	.weak	_Exit
+_Exit	= _exit