aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-07-20 01:14:41 +0000
committerUlrich Drepper <drepper@redhat.com>2002-07-20 01:14:41 +0000
commit739d440d2a748be4b0139d4e5e0a566098abfcec (patch)
tree395d06a998290892d7d92568471adee8e1e4824f
parent9df63767d4078fdaf90307f5aa153422f7ec0722 (diff)
downloadglibc-739d440d2a748be4b0139d4e5e0a566098abfcec.tar.xz
glibc-739d440d2a748be4b0139d4e5e0a566098abfcec.zip
Update.
2002-07-19 Ulrich Drepper <drepper@redhat.com> * configure.in: Add test for __thread support in compiler. * config.h.in: Add HAVE___THREAD. * Makefile (headers): Remove errno.h, sys/errno.h, and bits/errno.h. * include/sys/errno.h: Moved to... * stdlib/sys/errno.h: ...here. New file. * stdlib/errno.h: New file. Moved from... * include/errno.h: ...here. Changed into an internal header defining libc-local things like __set_errno. * stdlib/Makefile (headers): Add errno.h, sys/errno.h, and bits/errno.h. * elf/dl-minimal.c: Include <tls.h>. Define errno as thread-local variable if USE_TLS && HAVE___THREAD. Don't define __errno_location either. * elf/rtld.c (_dl_start): Add code to initialize TLS for ld.so from... (_dl_start_final): ...here. Add code to initialize tls elements from bootstrap_map. * sysdeps/generic/errno-loc.c: Define errno as thread-local variable if USE_TLS && HAVE___THREAD. * sysdeps/generic/bits/errno.h: Remove __set_errno definition. * sysdeps/mach/hurd/bits/errno.h: Likewise. * sysdeps/standalone/arm/bits/errno.h: Likewise. * sysdeps/standalone/bits/errno.h: Likewise. * sysdeps/unix/bsd/bsd4.4/bits/errno.h: Likewise. * sysdeps/unix/sysv/aix/bits/errno.h: Likewise. * sysdeps/unix/sysv/hpux/bits/errno.h: Likewise. * sysdeps/unix/sysv/linux/bits/errno.h: Likewise. * sysdeps/unix/sysv/linux/hppa/bits/errno.h: Likewise. * sysdeps/unix/sysv/linux/mips/bits/errno.h: Likewise. * sysdeps/unix/sysv/sysv4/solaris2/bits/errno.h: Likewise. * sysdeps/i386/dl-machine.c (elf_machine_rel) [RTLD_BOOTSTRAP]: Don't use GL(dl_rtld_map), use map parameter. * sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise. * sysdeps/unix/sysv/linux/i386/sysdep.S: Define errno in .tbss if USE_TLS && HAVE___THREAD. * sysdeps/unix/sysv/linux/i386/sysdep.h: Unify SETUP_PIC_REG definitions. If USE_TLS && HAVE___THREAD store errooor value using TLS code sequence. * sysdeps/unix/sysv/linux/i386/i686/sysdep.h: Likewise. * sysdeps/unix/sysv/linux/getcwd.c: No real need to restore errno. * sysdeps/unix/sysv/linux/grantpt.c: Likewise. * sysdeps/unix/sysv/linux/internal_statvfs.c: Likewise. * sysdeps/unix/sysv/linux/msgctl.c: Likewise. * sysdeps/unix/sysv/linux/readv.c: Likewise. * sysdeps/unix/sysv/linux/writev.c: Likewise.
-rw-r--r--ChangeLog49
-rw-r--r--Makefile5
-rw-r--r--bits/errno.h2
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure45
-rw-r--r--configure.in16
-rw-r--r--elf/dl-minimal.c6
-rw-r--r--elf/rtld.c207
-rw-r--r--include/errno.h76
-rw-r--r--linuxthreads/ChangeLog9
-rw-r--r--linuxthreads/errno.c4
-rw-r--r--linuxthreads/sysdeps/i386/i686/pt-machine.h2
-rw-r--r--linuxthreads/sysdeps/i386/pt-machine.h2
-rw-r--r--linuxthreads/sysdeps/i386/tls.h38
-rw-r--r--linuxthreads/sysdeps/i386/useldt.h4
-rw-r--r--stdlib/Makefile3
-rw-r--r--stdlib/errno.h73
-rw-r--r--stdlib/sys/errno.h1
-rw-r--r--sysdeps/generic/bits/errno.h2
-rw-r--r--sysdeps/generic/errno-loc.c9
-rw-r--r--sysdeps/i386/dl-machine.h2
-rw-r--r--sysdeps/mach/hurd/bits/errno.h1
-rw-r--r--sysdeps/sh/dl-machine.h2
-rw-r--r--sysdeps/standalone/arm/bits/errno.h1
-rw-r--r--sysdeps/standalone/bits/errno.h2
-rw-r--r--sysdeps/unix/bsd/bsd4.4/bits/errno.h2
-rw-r--r--sysdeps/unix/sysv/aix/bits/errno.h4
-rw-r--r--sysdeps/unix/sysv/hpux/bits/errno.h2
-rw-r--r--sysdeps/unix/sysv/linux/bits/errno.h8
-rw-r--r--sysdeps/unix/sysv/linux/getcwd.c11
-rw-r--r--sysdeps/unix/sysv/linux/grantpt.c9
-rw-r--r--sysdeps/unix/sysv/linux/hppa/bits/errno.h8
-rw-r--r--sysdeps/unix/sysv/linux/i386/i686/sysdep.h72
-rw-r--r--sysdeps/unix/sysv/linux/i386/sysdep.S13
-rw-r--r--sysdeps/unix/sysv/linux/i386/sysdep.h72
-rw-r--r--sysdeps/unix/sysv/linux/internal_statvfs.c5
-rw-r--r--sysdeps/unix/sysv/linux/mips/bits/errno.h8
-rw-r--r--sysdeps/unix/sysv/linux/msgctl.c5
-rw-r--r--sysdeps/unix/sysv/linux/readv.c6
-rw-r--r--sysdeps/unix/sysv/linux/writev.c6
-rw-r--r--sysdeps/unix/sysv/sysv4/solaris2/bits/errno.h2
41 files changed, 447 insertions, 350 deletions
diff --git a/ChangeLog b/ChangeLog
index 6eafcb1b64..3c57de72a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,52 @@
+2002-07-19 Ulrich Drepper <drepper@redhat.com>
+
+ * configure.in: Add test for __thread support in compiler.
+ * config.h.in: Add HAVE___THREAD.
+ * Makefile (headers): Remove errno.h, sys/errno.h, and bits/errno.h.
+ * include/sys/errno.h: Moved to...
+ * stdlib/sys/errno.h: ...here. New file.
+ * stdlib/errno.h: New file. Moved from...
+ * include/errno.h: ...here. Changed into an internal header defining
+ libc-local things like __set_errno.
+ * stdlib/Makefile (headers): Add errno.h, sys/errno.h, and
+ bits/errno.h.
+ * elf/dl-minimal.c: Include <tls.h>. Define errno as thread-local
+ variable if USE_TLS && HAVE___THREAD. Don't define __errno_location
+ either.
+ * elf/rtld.c (_dl_start): Add code to initialize TLS for ld.so
+ from...
+ (_dl_start_final): ...here. Add code to initialize tls elements from
+ bootstrap_map.
+ * sysdeps/generic/errno-loc.c: Define errno as thread-local variable
+ if USE_TLS && HAVE___THREAD.
+ * sysdeps/generic/bits/errno.h: Remove __set_errno definition.
+ * sysdeps/mach/hurd/bits/errno.h: Likewise.
+ * sysdeps/standalone/arm/bits/errno.h: Likewise.
+ * sysdeps/standalone/bits/errno.h: Likewise.
+ * sysdeps/unix/bsd/bsd4.4/bits/errno.h: Likewise.
+ * sysdeps/unix/sysv/aix/bits/errno.h: Likewise.
+ * sysdeps/unix/sysv/hpux/bits/errno.h: Likewise.
+ * sysdeps/unix/sysv/linux/bits/errno.h: Likewise.
+ * sysdeps/unix/sysv/linux/hppa/bits/errno.h: Likewise.
+ * sysdeps/unix/sysv/linux/mips/bits/errno.h: Likewise.
+ * sysdeps/unix/sysv/sysv4/solaris2/bits/errno.h: Likewise.
+ * sysdeps/i386/dl-machine.c (elf_machine_rel) [RTLD_BOOTSTRAP]: Don't
+ use GL(dl_rtld_map), use map parameter.
+ * sysdeps/sh/dl-machine.h (elf_machine_rela): Likewise.
+ * sysdeps/unix/sysv/linux/i386/sysdep.S: Define errno in .tbss if
+ USE_TLS && HAVE___THREAD.
+ * sysdeps/unix/sysv/linux/i386/sysdep.h: Unify SETUP_PIC_REG
+ definitions. If USE_TLS && HAVE___THREAD store errooor value using
+ TLS code sequence.
+ * sysdeps/unix/sysv/linux/i386/i686/sysdep.h: Likewise.
+
+ * sysdeps/unix/sysv/linux/getcwd.c: No real need to restore errno.
+ * sysdeps/unix/sysv/linux/grantpt.c: Likewise.
+ * sysdeps/unix/sysv/linux/internal_statvfs.c: Likewise.
+ * sysdeps/unix/sysv/linux/msgctl.c: Likewise.
+ * sysdeps/unix/sysv/linux/readv.c: Likewise.
+ * sysdeps/unix/sysv/linux/writev.c: Likewise.
+
2002-07-17 Ulrich Drepper <drepper@redhat.com>
* sysdeps/unix/sysv/linux/ia64/bits/mman.h: Fix MS_SYNC and
diff --git a/Makefile b/Makefile
index c1568054cd..5cd5460f9f 100644
--- a/Makefile
+++ b/Makefile
@@ -63,9 +63,8 @@ configure: configure.in aclocal.m4; $(autoconf-it)
subdir_testclean \
$(addprefix install-, no-libc.a bin lib data headers others)
-headers := errno.h sys/errno.h bits/errno.h limits.h values.h \
- features.h gnu-versions.h bits/libc-lock.h bits/xopen_lim.h \
- gnu/libc-version.h
+headers := limits.h values.h features.h gnu-versions.h bits/libc-lock.h \
+ bits/xopen_lim.h gnu/libc-version.h
echo-headers: subdir_echo-headers
diff --git a/bits/errno.h b/bits/errno.h
index dbeef5de4f..89a5cfddeb 100644
--- a/bits/errno.h
+++ b/bits/errno.h
@@ -33,5 +33,3 @@
# define Exxxx XXX
...
#endif
-
-#define __set_errno(val) errno = (val)
diff --git a/config.h.in b/config.h.in
index b3dd601f3b..cf4835cbec 100644
--- a/config.h.in
+++ b/config.h.in
@@ -94,6 +94,9 @@
/* Define if the compiler supports __builtin_memset. */
#undef HAVE_BUILTIN_MEMSET
+/* Define if the __thread keyword is supported. */
+#undef HAVE___THREAD
+
/* Define if the regparm attribute shall be used for local functions
(gcc on ix86 only). */
#undef USE_REGPARMS
diff --git a/configure b/configure
index 468b79cd34..0d1981aeda 100755
--- a/configure
+++ b/configure
@@ -3540,8 +3540,33 @@ EOF
fi
+echo $ac_n "checking for __thread""... $ac_c" 1>&6
+echo "configure:3545: 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:3552: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; }; then
+ libc_cv_gcc___thread=yes
+else
+ libc_cv_gcc___thread=no
+fi
+rm -f conftest*
+fi
+
+echo "$ac_t""$libc_cv_gcc___thread" 1>&6
+if test "$libc_cv_gcc___thread" = yes; then
+ cat >> confdefs.h <<\EOF
+#define HAVE___THREAD 1
+EOF
+
+fi
+
+
echo $ac_n "checking for libgd""... $ac_c" 1>&6
-echo "configure:3545: checking for libgd" >&5
+echo "configure:3570: checking for libgd" >&5
if test "$with_gd" != "no"; then
old_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $libgd_include"
@@ -3550,14 +3575,14 @@ if test "$with_gd" != "no"; then
old_LIBS="$LIBS"
LIBS="$LIBS -lgd -lpng -lz -lm"
cat > conftest.$ac_ext <<EOF
-#line 3554 "configure"
+#line 3579 "configure"
#include "confdefs.h"
#include <gd.h>
int main() {
gdImagePng (0, 0)
; return 0; }
EOF
-if { (eval echo configure:3561: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3586: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
LIBGD=yes
else
@@ -3577,7 +3602,7 @@ echo "$ac_t""$LIBGD" 1>&6
echo $ac_n "checking size of long double""... $ac_c" 1>&6
-echo "configure:3581: checking size of long double" >&5
+echo "configure:3606: 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
@@ -3585,7 +3610,7 @@ else
ac_cv_sizeof_long_double=0
else
cat > conftest.$ac_ext <<EOF
-#line 3589 "configure"
+#line 3614 "configure"
#include "confdefs.h"
#include <stdio.h>
int main()
@@ -3596,7 +3621,7 @@ int main()
return(0);
}
EOF
-if { (eval echo configure:3600: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3625: \"$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
@@ -3674,7 +3699,7 @@ if test "$uname" = "sysdeps/generic"; then
fi
echo $ac_n "checking OS release for uname""... $ac_c" 1>&6
-echo "configure:3678: checking OS release for uname" >&5
+echo "configure:3703: 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
@@ -3696,7 +3721,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:3700: checking OS version for uname" >&5
+echo "configure:3725: 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
@@ -3725,7 +3750,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:3729: checking for old glibc 2.0.x headers" >&5
+echo "configure:3754: 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
@@ -3786,7 +3811,7 @@ if test $shared = default; then
fi
echo $ac_n "checking whether -fPIC is default""... $ac_c" 1>&6
-echo "configure:3790: checking whether -fPIC is default" >&5
+echo "configure:3815: 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/configure.in b/configure.in
index 61a13cd147..f120ef41aa 100644
--- a/configure.in
+++ b/configure.in
@@ -1513,6 +1513,22 @@ if test "$libc_cv_gcc_subtract_local_labels" = yes; then
AC_DEFINE(HAVE_SUBTRACT_LOCAL_LABELS)
fi
+dnl Check whether the compiler supports the __thread keyword.
+AC_CACHE_CHECK([for __thread], libc_cv_gcc___thread,
+[cat > conftest.c <<EOF
+__thread int a = 42;
+EOF
+if AC_TRY_COMMAND([${CC-cc} $CFLAGS -c conftest.c >&AC_FD_CC]); then
+ libc_cv_gcc___thread=yes
+else
+ libc_cv_gcc___thread=no
+fi
+rm -f conftest*])
+if test "$libc_cv_gcc___thread" = yes; then
+ AC_DEFINE(HAVE___THREAD)
+fi
+
+
dnl Check whether we have the gd library available.
AC_MSG_CHECKING(for libgd)
if test "$with_gd" != "no"; then
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
index 0f284d0a80..a6c1803b34 100644
--- a/elf/dl-minimal.c
+++ b/elf/dl-minimal.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <limits.h>
#include <string.h>
+#include <tls.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/param.h>
@@ -354,8 +355,12 @@ const char INTUSE(_itoa_lower_digits)[16] attribute_hidden
= "0123456789abcdef";
+
#undef errno
/* The 'errno' in ld.so is not exported. */
+#if USE_TLS && HAVE___THREAD
+extern __thread int errno attribute_hidden;
+#else
extern int errno attribute_hidden;
int *
@@ -363,3 +368,4 @@ __errno_location (void)
{
return &errno;
}
+#endif
diff --git a/elf/rtld.c b/elf/rtld.c
index 9ec250214b..85d8108813 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -130,9 +130,14 @@ _dl_start (void *arg)
{
struct link_map bootstrap_map;
hp_timing_t start_time;
-#ifndef HAVE_BUILTIN_MEMSET
+#if !defined HAVE_BUILTIN_MEMSET || defined USE_TLS
size_t cnt;
#endif
+#ifdef USE_TLS
+ ElfW(Ehdr) *ehdr;
+ ElfW(Phdr) *phdr;
+ dtv_t initdtv[3];
+#endif
/* This #define produces dynamic linking inline functions for
bootstrap relocation instead of general-purpose relocation. */
@@ -166,6 +171,97 @@ _dl_start (void *arg)
bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
elf_get_dynamic_info (&bootstrap_map);
+#if USE_TLS
+# ifndef HAVE___THREAD
+ /* Signal that we have not found TLS data so far. */
+ bootstrap_map.l_tls_modid = 0;
+# endif
+
+ /* Get the dynamic linkers program header. */
+ ehdr = (ElfW(Ehdr) *) bootstrap_map.l_addr;
+ phdr = (ElfW(Phdr) *) (bootstrap_map.l_addr + ehdr->e_phoff);
+ for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
+ if (phdr[cnt].p_type == PT_TLS)
+ {
+ void *tlsblock;
+ size_t max_align = MAX (TLS_INIT_TCB_ALIGN, phdr[cnt].p_align);
+
+ bootstrap_map.l_tls_blocksize = phdr[cnt].p_memsz;
+ bootstrap_map.l_tls_align = phdr[cnt].p_align;
+ assert (bootstrap_map.l_tls_blocksize != 0);
+ bootstrap_map.l_tls_initimage_size = phdr[cnt].p_filesz;
+ bootstrap_map.l_tls_initimage = (void *) (bootstrap_map.l_addr
+ + phdr[cnt].p_offset);
+
+ /* We can now allocate the initial TLS block. This can happen
+ on the stack. We'll get the final memory later when we
+ know all about the various objects loaded at startup
+ time. */
+# if TLS_TCB_AT_TP
+ tlsblock = alloca (roundup (bootstrap_map.l_tls_blocksize,
+ TLS_INIT_TCB_ALIGN)
+ + TLS_INIT_TCB_SIZE
+ + max_align);
+# elif TLS_DTV_AT_TP
+ tlsblock = alloca (roundup (TLS_INIT_TCB_SIZE,
+ bootstrap_map.l_tls_align)
+ + bootstrap_map.l_tls_blocksize
+ + max_align);
+# else
+ /* In case a model with a different layout for the TCB and DTV
+ is defined add another #elif here and in the following #ifs. */
+# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
+# endif
+ /* Align the TLS block. */
+ tlsblock = (void *) (((uintptr_t) tlsblock + max_align - 1)
+ &a