This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Hi!
We missed the fact that #define _res (*__res_state()) was introduced in
glibc 2.2, not glibc 2.1, so there are symbol versioned properly built
programs/libraries using _res@GLIBC_2.0.
As, unlike errno, _res is not that performance sensitive, the following
patch adds an indirection, so that _res in the initial thread is the
_res@GLIBC_2.0 variable (doesn't matter if in libc.so or in program's .dynbss)
and _res in the other threads is unique to those threads.
Unfortunately, this patch is more complicated, because adding the huge
struct __res_state into NPTL struct pthread made NPTL struct pthread
larger than linuxthreads --without-__thread struct _pthread_descr_struct
(it was on the other side removed from PT_TLS).
When a single (linuxthreads --with-tls --without-__thread) ld.so is used
for loading both linuxthreads --with-tls --without-__thread and
NPTL libraries, things worked in the past because linuxthreads pthread
structure was larger. This patch makes TLS_TCB_SIZE (resp. TLS_PRE_TCB_SIZE)
in linuxthreads in ld.so as big to accomodate both linuxthreads and NPTL
pthread structs.
2003-07-18 Jakub Jelinek <jakub@redhat.com>
* include/resolv.h (__resp): Declare. Define to __libc_resp
if in libc.so.
(_res): If USE___THREAD, define to (*__resp).
* resolv/res_libc.c (_res): Normal .bss variable with compat_symbol
even if USE___THREAD.
(__resp): New __thread variable.
(__libc_resp): New alias.
* resolv/Versions (libc): Export _res@GLIBC_2.0 even if
USE_TLS && HAVE___THREAD. Export __resp@@GLIBC_PRIVATE.
* sysdeps/generic/res-state.c (__res_state): Return __resp
if USE___THREAD.
linuxthreads/
* descr.h (struct _pthread_descr_struct): Provide p_res member
even if USE_TLS && HAVE___THREAD.
* sysdeps/alpha/tls.h (TLS_INIT_TCB_SIZE, TLS_TCB_SIZE): Change to 0.
(TLS_INIT_TCB_ALIGN, TLS_TCB_ALIGN): Alignment of struct
_pthread_descr_struct.
(TLS_PRE_TCB_SIZE): Add sizeof (tcbhead_t) and pad to align.
If in ld.so and NPTL struct pthread is bigger than struct
_pthread_descr_struct, use NPTL struct pthread size.
(TLS_TCB_OFFSET): Define.
(INSTALL_DTV, INSTALL_NEW_DTV, GET_DTV, TLS_INIT_TP, THREAD_DTV,
THREAD_SELF, INIT_THREAD_SELF): Changed to match NPTL tls.h
definitions.
* sysdeps/i386/tls.h (TLS_TCB_SIZE): If in ld.so and NPTL struct
pthread is bigger than struct _pthread_descr_struct, use NPTL struct
pthread size.
* sysdeps/ia64/tls.h (TLS_PRE_TCB_SIZE): Likewise.
* sysdeps/powerpc/tls.h (TLS_PRE_TCB_SIZE): Likewise.
* sysdeps/s390/tls.h (TLS_TCB_SIZE): Likewise.
* sysdeps/sh/tls.h (TLS_PRE_TCB_SIZE): Likewise.
* sysdeps/x86_64/tls.h (TLS_TCB_SIZE): Likewise.
* sysdeps/pthread/res-state.c (__res_state): Return __resp
if USE___THREAD.
* sysdeps/pthread/Makefile (gen-as-const-headers): Add
nptl-struct-pthread.sym if nptl tree is present.
(before-compile): Add $(common-objpfx)nptl-struct-pthread.h
if nptl tree is not present.
(common-generated): Add nptl-struct-pthread.h.
($(common-objpfx)nptl-struct-pthread.h): New rule.
* sysdeps/pthread/nptl-struct-pthread.sym: New file.
* manager.c: Include resolv.h.
(pthread_start_thread): Initialize __resp.
* libc-tls-loc.c (__res_state): Return __resp.
* Makefile (tests): Add tst-_res1.
(modules-names, extra-objs, test-extras, test-modules): Add support
for test modules.
($(objpfx)tst-_res1mod2.so): Depend on $(objpfx)tst-_res1mod1.so.
($(objpfx)tst-_res1): Depend on $(objpfx)tst-_res1mod2.so and
-lpthread.
* tst-_res1.c: New test.
* tst-_res1mod1.c: New test.
* tst-_res1mod2.c: New test.
nptl/
* res.c (__res_state): Return __resp.
* descr.h: Include resolv.h.
Don't include lowlevellock.h, pthreaddef.h and dl-sysdep.h if
__need_struct_pthread_size, instead define lll_lock_t.
(struct pthread): Add res field.
* pthread_create.c: Include resolv.h.
(start_thread): Initialize __resp.
* Makefile (tests): Add tst-_res1.
(module-names): Add tst-_res1mod1, tst-_res1mod2.
($(objpfx)tst-_res1mod2.so): Depend on $(objpfx)tst-_res1mod1.so.
($(objpfx)tst-_res1): Depend on $(objpfx)tst-_res1mod2.so and
* tst-_res1.c: New test.
* tst-_res1mod1.c: New test.
* tst-_res1mod2.c: New test.
--- libc/nptl/res.c.jj 2002-11-26 17:50:04.000000000 -0500
+++ libc/nptl/res.c 2003-07-17 08:31:58.000000000 -0400
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 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
@@ -18,16 +18,10 @@
#include <features.h>
#include <resolv.h>
-#undef _res
-
#include <tls.h>
-/* With __thread support, this per-thread variable is used in all cases. */
-extern __thread struct __res_state _res;
-
-
struct __res_state *
__res_state (void)
{
- return &_res;
+ return __resp;
}
--- libc/nptl/descr.h.jj 2003-07-08 09:54:08.000000000 -0400
+++ libc/nptl/descr.h 2003-07-17 13:58:42.000000000 -0400
@@ -27,15 +27,20 @@
#include <sys/types.h>
#include <hp-timing.h>
#include <list.h>
+#ifdef __need_struct_pthread_size
+#define lll_lock_t int
+#else
#include <lowlevellock.h>
#include <pthreaddef.h>
#include <dl-sysdep.h>
+#endif
#include "../nptl_db/thread_db.h"
#include <tls.h>
#ifdef HAVE_FORCED_UNWIND
# include <unwind.h>
#endif
-
+#define __need_res_state
+#include <resolv.h>
#ifndef TCB_ALIGNMENT
# define TCB_ALIGNMENT sizeof (double)
@@ -235,6 +240,9 @@ struct pthread
size_t stackblock_size;
/* Size of the included guard area. */
size_t guardsize;
+
+ /* Resolver state. */
+ struct __res_state res;
} __attribute ((aligned (TCB_ALIGNMENT)));
--- libc/nptl/pthread_create.c.jj 2003-04-12 15:06:08.000000000 -0400
+++ libc/nptl/pthread_create.c 2003-07-17 08:31:58.000000000 -0400
@@ -26,6 +26,7 @@
#include <ldsodefs.h>
#include <atomic.h>
#include <libc-internal.h>
+#include <resolv.h>
#include <shlib-compat.h>
@@ -238,6 +239,9 @@ start_thread (void *arg)
THREAD_SETMEM (pd, cpuclock_offset, now);
#endif
+ /* Initialize resolver state pointer. */
+ __resp = &pd->res;
+
/* This is where the try/finally block should be created. For
compilers without that support we do use setjmp. */
struct pthread_unwind_buf unwind_buf;
--- libc/nptl/tst-_res1.c.jj 2003-07-18 06:18:48.000000000 -0400
+++ libc/nptl/tst-_res1.c 2003-07-18 06:22:21.000000000 -0400
@@ -0,0 +1,69 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+ 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. */
+
+/* Test whether _res in glibc 2.1.x and earlier (before __res_state()
+ was introduced) works. Portable programs should never do the
+ dirty things below. */
+
+#include <pthread.h>
+#include <resolv.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void *tf (void *resp)
+{
+ if (resp == &_res || resp == __res_state ())
+ abort ();
+ _res.retry = 24;
+ return NULL;
+}
+
+void do_test (struct __res_state *resp)
+{
+ if (resp != &_res || resp != __res_state ())
+ abort ();
+ if (_res.retry != 12)
+ abort ();
+}
+
+int main (void)
+{
+#undef _res
+ extern struct __res_state _res;
+ pthread_t th;
+
+ _res.retry = 12;
+ if (pthread_create (&th, NULL, tf, &_res) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ do_test (&_res);
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ do_test (&_res);
+
+ exit (0);
+}
--- libc/nptl/tst-_res1mod2.c.jj 2003-07-18 06:27:44.000000000 -0400
+++ libc/nptl/tst-_res1mod2.c 2003-07-18 06:27:40.000000000 -0400
@@ -0,0 +1 @@
+/* Nothing. */
--- libc/nptl/Makefile.jj 2003-07-15 14:05:05.000000000 -0400
+++ libc/nptl/Makefile 2003-07-18 06:30:53.000000000 -0400
@@ -249,10 +249,10 @@ tests += tst-cancelx2 tst-cancelx3 tst-c
tst-oncex3 tst-oncex4
endif
ifeq ($(build-shared),yes)
-tests += tst-atfork2 tst-tls3
+tests += tst-atfork2 tst-tls3 tst-_res1
endif
-modules-names = tst-atfork2mod tst-tls3mod
+modules-names = tst-atfork2mod tst-tls3mod tst-_res1mod1 tst-_res1mod2
extra-objs += $(addsuffix .os,$(strip $(modules-names)))
test-extras += $(modules-names)
test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
@@ -396,6 +396,8 @@ $(objpfx)tst-cancelx17: $(common-objpfx)
$(objpfx)tst-cancel18: $(common-objpfx)rt/librt.so
$(objpfx)tst-cancelx18: $(common-objpfx)rt/librt.so
$(objpfx)tst-clock2: $(common-objpfx)rt/librt.so
+$(objpfx)tst-_res1mod2.so: $(objpfx)tst-_res1mod1.so
+$(objpfx)tst-_res1: $(objpfx)tst-_res1mod2.so $(shared-thread-library)
else
$(objpfx)tst-cond11: $(common-objpfx)rt/librt.a
$(objpfx)tst-cancel17: $(common-objpfx)rt/librt.a
--- libc/nptl/tst-_res1mod1.c.jj 2003-07-18 06:22:35.000000000 -0400
+++ libc/nptl/tst-_res1mod1.c 2003-07-18 06:22:52.000000000 -0400
@@ -0,0 +1,23 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+ 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 <resolv.h>
+#undef _res
+
+struct __res_state _res;
--- libc/include/resolv.h.jj 2003-07-17 07:42:15.000000000 -0400
+++ libc/include/resolv.h 2003-07-17 08:31:58.000000000 -0400
@@ -17,9 +17,10 @@
# if USE___THREAD
# undef _res
# ifndef NOT_IN_libc
-# define _res __libc_res
+# define __resp __libc_resp
# endif
-extern __thread struct __res_state _res attribute_tls_model_ie;
+# define _res (*__resp)
+extern __thread struct __res_state *__resp attribute_tls_model_ie;
# endif
# else
# ifndef __BIND_NOSTATIC
--- libc/linuxthreads/descr.h.jj 2003-07-17 07:42:15.000000000 -0400
+++ libc/linuxthreads/descr.h 2003-07-17 08:31:58.000000000 -0400
@@ -163,8 +163,8 @@ struct _pthread_descr_struct
int * p_h_errnop; /* pointer to used h_errno variable */
int p_h_errno; /* error returned by last netdb function */
struct __res_state *p_resp; /* Pointer to resolver state */
- struct __res_state p_res; /* per-thread resolver state */
#endif
+ struct __res_state p_res; /* per-thread resolver state */
int p_userstack; /* nonzero if the user provided the stack */
void *p_guardaddr; /* address of guard area or NULL */
size_t p_guardsize; /* size of guard area */
--- libc/linuxthreads/sysdeps/alpha/tls.h.jj 2003-01-30 16:03:40.000000000 -0500
+++ libc/linuxthreads/sysdeps/alpha/tls.h 2003-07-18 05:43:09.000000000 -0400
@@ -53,54 +53,77 @@ typedef struct
# include <sysdep.h>
/* This is the size of the initial TCB. */
-# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
+# define TLS_INIT_TCB_SIZE 0
/* Alignment requirements for the initial TCB. */
-# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
+# define TLS_INIT_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
/* This is the size of the TCB. */
-# define TLS_TCB_SIZE sizeof (tcbhead_t)
+# define TLS_TCB_SIZE 0
/* Alignment requirements for the TCB. */
-# define TLS_TCB_ALIGN __alignof__ (tcbhead_t)
+# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
/* This is the size we need before TCB. */
-# define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# ifndef IS_IN_rtld
+# define TLS_PRE_TCB_SIZE \
+ (sizeof (struct _pthread_descr_struct) \
+ + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
+# else
+# include <nptl-struct-pthread.h>
+# define TLS_PRE_TCB_SIZE \
+ ((sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
+ ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE) \
+ + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
+# endif
/* The DTV is allocated at the TP; the TCB is placed elsewhere. */
# define TLS_DTV_AT_TP 1
+/* The following assumes that TP (R2 or R13) points to the end of the
+ TCB + 0x7000 (per the ABI). This implies that TCB address is
+ TP - 0x7000. As we define TLS_DTV_AT_TP we can
+ assume that the pthread struct is allocated immediately ahead of the
+ TCB. This implies that the pthread_descr address is
+ TP - (TLS_PRE_TCB_SIZE + 0x7000). */
+/* ??? PPC uses offset 0x7000; seems like a good idea for alpha too,
+ but binutils not yet changed to match. */
+# define TLS_TCB_OFFSET 0
+
/* Install the dtv pointer. The pointer passed is to the element with
index -1 which contain the length. */
# define INSTALL_DTV(TCBP, DTVP) \
- (((tcbhead_t *) (TCBP))->dtv = (DTVP) + 1)
+ (((tcbhead_t *) (TCBP))[-1].dtv = (DTVP) + 1)
/* Install new dtv for current thread. */
# define INSTALL_NEW_DTV(DTV) \
- (((tcbhead_t *)__builtin_thread_pointer ())->dtv = (DTV))
+ (THREAD_DTV() = (DTV))
/* Return dtv of given thread descriptor. */
# define GET_DTV(TCBP) \
- (((tcbhead_t *) (TCBP))->dtv)
+ (((tcbhead_t *) (TCBP))[-1].dtv)
/* Code to initially initialize the thread pointer. This might need
special attention since 'errno' is not yet available and if the
operation can cause a failure 'errno' must not be touched. */
# define TLS_INIT_TP(TCBP, SECONDCALL) \
- (__builtin_set_thread_pointer (TCBP), 0)
+ (__builtin_set_thread_pointer ((void *) (tcbp) + TLS_TCB_OFFSET), NULL)
/* Return the address of the dtv for the current thread. */
# define THREAD_DTV() \
- (((tcbhead_t *)__builtin_thread_pointer ())->dtv)
+ (((tcbhead_t *) (__builtin_thread_pointer () - TLS_TCB_OFFSET))[-1].dtv)
/* Return the thread descriptor for the current thread. */
# undef THREAD_SELF
# define THREAD_SELF \
+ ((pthread_descr) (__builtin_thread_pointer () \
+ - TLS_TCB_OFFSET - TLS_PRE_TCB_SIZE))
((pthread_descr)__builtin_thread_pointer () - 1)
# undef INIT_THREAD_SELF
# define INIT_THREAD_SELF(DESCR, NR) \
- __builtin_set_thread_pointer ((struct _pthread_descr_struct *)(DESCR) + 1)
+ __builtin_set_thread_pointer ((char *)(DESCR) \
+ + TLS_TCB_OFFSET + TLS_PRE_TCB_SIZE)
/* Get the thread descriptor definition. */
# include <linuxthreads/descr.h>
--- libc/linuxthreads/sysdeps/i386/tls.h.jj 2003-05-06 01:43:42.000000000 -0400
+++ libc/linuxthreads/sysdeps/i386/tls.h 2003-07-18 05:29:09.000000000 -0400
@@ -81,7 +81,14 @@ typedef struct
# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
/* This is the size of the TCB. */
-# define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# ifndef IS_IN_rtld
+# define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# else
+# include <nptl-struct-pthread.h>
+# define TLS_TCB_SIZE \
+ (sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
+ ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE)
+# endif
/* Alignment requirements for the TCB. */
# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
--- libc/linuxthreads/sysdeps/ia64/tls.h.jj 2003-03-02 06:44:20.000000000 -0500
+++ libc/linuxthreads/sysdeps/ia64/tls.h 2003-07-18 05:30:37.000000000 -0400
@@ -59,7 +59,14 @@ typedef struct
# define TLS_TCB_SIZE sizeof (tcbhead_t)
/* This is the size we need before TCB. */
-# define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# ifndef IS_IN_rtld
+# define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# else
+# include <nptl-struct-pthread.h>
+# define TLS_PRE_TCB_SIZE \
+ (sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
+ ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE)
+# endif
/* Alignment requirements for the TCB. */
# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
--- libc/linuxthreads/sysdeps/powerpc/tls.h.jj 2003-04-25 18:29:27.000000000 -0400
+++ libc/linuxthreads/sysdeps/powerpc/tls.h 2003-07-18 05:46:40.000000000 -0400
@@ -64,11 +64,19 @@ typedef struct
# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
/* This is the size we need before TCB. */
-# define TLS_PRE_TCB_SIZE \
+# ifndef IS_IN_rtld
+# define TLS_PRE_TCB_SIZE \
(sizeof (struct _pthread_descr_struct) \
+ ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
+# else
+# include <nptl-struct-pthread.h>
+# define TLS_PRE_TCB_SIZE \
+ ((sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
+ ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE) \
+ + ((sizeof (tcbhead_t) + TLS_TCB_ALIGN - 1) & ~(TLS_TCB_ALIGN - 1)))
+# endif
-/* The following assumes that TP (R2 or R13) is points to the end of the
+/* The following assumes that TP (R2 or R13) points to the end of the
TCB + 0x7000 (per the ABI). This implies that TCB address is
TP - 0x7000. As we define TLS_DTV_AT_TP we can
assume that the pthread_descr is allocated immediately ahead of the
--- libc/linuxthreads/sysdeps/pthread/res-state.c.jj 2003-07-17 07:42:15.000000000 -0400
+++ libc/linuxthreads/sysdeps/pthread/res-state.c 2003-07-17 08:31:58.000000000 -0400
@@ -39,7 +39,9 @@ __res_state (void)
pthread_descr self = thread_self();
return LIBC_THREAD_GETMEM (self, p_resp);
}
-#endif
return &_res;
+#else
+ return __resp;
+#endif
}
libc_hidden_def (__res_state)
--- libc/linuxthreads/sysdeps/pthread/Makefile.jj 2003-03-19 12:57:45.000000000 -0500
+++ libc/linuxthreads/sysdeps/pthread/Makefile 2003-07-18 06:04:42.000000000 -0400
@@ -11,3 +11,15 @@ endif
ifeq ($(subdir),posix)
CFLAGS-confstr.c += -DLIBPTHREAD_VERSION="\"$(shell sed 's/\(.*\) by .*/\1/' ../linuxthreads/Banner)\""
endif
+
+ifeq ($(subdir),csu)
+# Find out the size of NPTL struct pthread
+ifneq (,$(wildcard $(..)nptl/descr.h))
+gen-as-const-headers += nptl-struct-pthread.sym
+else
+before-compile += $(common-objpfx)nptl-struct-pthread.h
+common-generated += nptl-struct-pthread.h
+$(common-objpfx)nptl-struct-pthread.h:
+ @echo '#define NPTL_STRUCT_PTHREAD_SIZE 0' > $@
+endif
+endif
--- libc/linuxthreads/sysdeps/pthread/nptl-struct-pthread.sym.jj 2003-07-17 13:12:30.000000000 -0400
+++ libc/linuxthreads/sysdeps/pthread/nptl-struct-pthread.sym 2003-07-18 05:16:42.000000000 -0400
@@ -0,0 +1,13 @@
+#ifdef HAVE_TLS_SUPPORT
+# ifndef HAVE_FORCED_UNWIND
+# define HAVE_FORCED_UNWIND 1
+# endif
+# define __need_struct_pthread_size
+# include <nptl/descr.h>
+#endif
+
+--
+
+#ifdef HAVE_TLS_SUPPORT
+NPTL_STRUCT_PTHREAD_SIZE sizeof (struct pthread)
+#endif
--- libc/linuxthreads/sysdeps/s390/tls.h.jj 2003-01-30 13:34:11.000000000 -0500
+++ libc/linuxthreads/sysdeps/s390/tls.h 2003-07-18 05:48:00.000000000 -0400
@@ -72,7 +72,14 @@ typedef struct
# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
/* This is the size of the TCB. */
-# define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# ifndef IS_IN_rtld
+# define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# else
+# include <nptl-struct-pthread.h>
+# define TLS_TCB_SIZE \
+ (sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
+ ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE)
+# endif
/* Alignment requirements for the TCB. */
# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
--- libc/linuxthreads/sysdeps/sh/tls.h.jj 2003-03-02 06:44:20.000000000 -0500
+++ libc/linuxthreads/sysdeps/sh/tls.h 2003-07-18 05:54:45.000000000 -0400
@@ -64,7 +64,14 @@ typedef struct
# define TLS_TCB_SIZE sizeof (tcbhead_t)
/* This is the size we need before TCB. */
-# define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# ifndef IS_IN_rtld
+# define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# else
+# include <nptl-struct-pthread.h>
+# define TLS_PRE_TCB_SIZE \
+ (sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
+ ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE)
+# endif
/* Alignment requirements for the TCB. */
# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
--- libc/linuxthreads/sysdeps/x86_64/tls.h.jj 2003-06-17 18:24:45.000000000 -0400
+++ libc/linuxthreads/sysdeps/x86_64/tls.h 2003-07-18 05:53:37.000000000 -0400
@@ -63,7 +63,14 @@ typedef struct
# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
/* This is the size of the TCB. */
-# define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# ifndef IS_IN_rtld
+# define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
+# else
+# include <nptl-struct-pthread.h>
+# define TLS_TCB_SIZE \
+ (sizeof (struct _pthread_descr_struct) > NPTL_STRUCT_PTHREAD_SIZE \
+ ? sizeof (struct _pthread_descr_struct) : NPTL_STRUCT_PTHREAD_SIZE)
+# endif
/* Alignment requirements for the TCB. */
# define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
--- libc/linuxthreads/manager.c.jj 2003-07-17 07:42:15.000000000 -0400
+++ libc/linuxthreads/manager.c 2003-07-17 08:31:58.000000000 -0400
@@ -28,6 +28,7 @@
#include <sys/time.h>
#include <sys/wait.h> /* for waitpid macros */
#include <locale.h> /* for __uselocale */
+#include <resolv.h> /* for __resp */
#include <ldsodefs.h>
#include "pthread.h"
@@ -287,6 +288,9 @@ pthread_start_thread(void *arg)
/* Initialize thread-locale current locale to point to the global one.
With __thread support, the variable's initializer takes care of this. */
__uselocale (LC_GLOBAL_LOCALE);
+#else
+ /* Initialize __resp. */
+ __resp = &self->p_resp;
#endif
/* Make gdb aware of new thread */
if (__pthread_threads_debug && __pthread_sig_debug > 0) {
--- libc/linuxthreads/libc-tls-loc.c.jj 2003-07-17 07:42:15.000000000 -0400
+++ libc/linuxthreads/libc-tls-loc.c 2003-07-17 08:31:58.000000000 -0400
@@ -43,7 +43,7 @@ __h_errno_location (void)
struct __res_state *
__res_state (void)
{
- return &_res;
+ return __resp;
}
#endif
--- libc/linuxthreads/tst-_res1.c.jj 2003-07-18 06:18:48.000000000 -0400
+++ libc/linuxthreads/tst-_res1.c 2003-07-18 06:22:21.000000000 -0400
@@ -0,0 +1,69 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+ 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. */
+
+/* Test whether _res in glibc 2.1.x and earlier (before __res_state()
+ was introduced) works. Portable programs should never do the
+ dirty things below. */
+
+#include <pthread.h>
+#include <resolv.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void *tf (void *resp)
+{
+ if (resp == &_res || resp == __res_state ())
+ abort ();
+ _res.retry = 24;
+ return NULL;
+}
+
+void do_test (struct __res_state *resp)
+{
+ if (resp != &_res || resp != __res_state ())
+ abort ();
+ if (_res.retry != 12)
+ abort ();
+}
+
+int main (void)
+{
+#undef _res
+ extern struct __res_state _res;
+ pthread_t th;
+
+ _res.retry = 12;
+ if (pthread_create (&th, NULL, tf, &_res) != 0)
+ {
+ puts ("create failed");
+ exit (1);
+ }
+
+ do_test (&_res);
+
+ if (pthread_join (th, NULL) != 0)
+ {
+ puts ("join failed");
+ exit (1);
+ }
+
+ do_test (&_res);
+
+ exit (0);
+}
--- libc/linuxthreads/tst-_res1mod1.c.jj 2003-07-18 06:22:35.000000000 -0400
+++ libc/linuxthreads/tst-_res1mod1.c 2003-07-18 06:22:52.000000000 -0400
@@ -0,0 +1,23 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+ 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 <resolv.h>
+#undef _res
+
+struct __res_state _res;
--- libc/linuxthreads/tst-_res1mod2.c.jj 2003-07-18 06:27:44.000000000 -0400
+++ libc/linuxthreads/tst-_res1mod2.c 2003-07-18 06:27:40.000000000 -0400
@@ -0,0 +1 @@
+/* Nothing. */
--- libc/linuxthreads/Makefile.jj 2003-06-09 22:19:43.000000000 -0400
+++ libc/linuxthreads/Makefile 2003-07-18 06:53:13.000000000 -0400
@@ -119,8 +119,17 @@ endif
ifeq (yes,$(build-shared))
tests-nodelete-yes = unload
+tests += tst-_res1
endif
+modules-names = tst-_res1mod1 tst-_res1mod2
+extra-objs += $(addsuffix .os,$(strip $(modules-names)))
+test-extras += $(modules-names)
+test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
+
+$(test-modules): $(objpfx)%.so: $(objpfx)%.os $(common-objpfx)shlib.lds
+ $(build-module)
+
all: # Make this the default target; it will be defined in Rules.
# What we install as libpthread.so for programs to link against is in fact a
@@ -288,6 +297,11 @@ otherlibs += $(nssobjdir)/libnss_files.a
$(resolvobjdir)/libresolv.a
endif
+ifeq (yes,$(build-shared))
+$(objpfx)tst-_res1mod2.so: $(objpfx)tst-_res1mod1.so
+$(objpfx)tst-_res1: $(objpfx)tst-_res1mod2.so $(shared-thread-library)
+endif
+
ifeq (no,$(cross-compiling))
ifeq (yes,$(build-shared))
tests: $(objpfx)tst-signal.out $(objpfx)tst-cancel-wrappers.out
--- libc/resolv/res_libc.c.jj 2003-07-17 07:42:15.000000000 -0400
+++ libc/resolv/res_libc.c 2003-07-17 08:31:58.000000000 -0400
@@ -68,27 +68,26 @@ res_init(void) {
/* This needs to be after the use of _res in res_init, above. */
#undef _res
-#include <tls.h>
-
-#if USE___THREAD
-/* With __thread support, this per-thread variable is used in all cases. */
-__thread struct __res_state _res;
-extern __thread struct __res_state __libc_res __attribute__ ((alias ("_res")))
- attribute_hidden;
-# define _res __libc_res
-#else
/* The resolver state for use by single-threaded programs.
This differs from plain `struct __res_state _res;' in that it doesn't
create a common definition, but a plain symbol that resides in .bss,
which can have an alias. */
struct __res_state _res __attribute__((section (".bss")));
+#include <tls.h>
+
+#if USE___THREAD
+#undef __resp
+__thread struct __res_state *__resp = &_res;
+extern __thread struct __res_state *__libc_resp
+ __attribute__ ((alias ("__resp"))) attribute_hidden;
+#endif
+
/* We declare this with compat_symbol so that it's not
visible at link time. Programs must use the accessor functions. */
-# if defined HAVE_ELF && defined SHARED && defined DO_VERSIONING
-# include <shlib-compat.h>
+#if defined HAVE_ELF && defined SHARED && defined DO_VERSIONING
+# include <shlib-compat.h>
compat_symbol (libc, _res, _res, GLIBC_2_0);
-# endif
#endif
#include <shlib-compat.h>
--- libc/resolv/Versions.jj 2003-07-17 07:42:15.000000000 -0400
+++ libc/resolv/Versions 2003-07-17 08:31:58.000000000 -0400
@@ -4,9 +4,11 @@ libc {
GLIBC_2.0 {
%if !(USE_TLS && HAVE___THREAD)
# global variables
- _h_errno; _res;
+ _h_errno;
%endif
+ _res;
+
# helper functions
__h_errno_location;
@@ -34,7 +36,7 @@ libc {
%if USE_TLS && HAVE___THREAD
# This version is for the TLS symbol, GLIBC_2.0 is the old object symbol.
- h_errno; _res;
+ h_errno; __resp;
%endif
}
}
--- libc/sysdeps/generic/res-state.c.jj 2003-07-17 07:42:15.000000000 -0400
+++ libc/sysdeps/generic/res-state.c 2003-07-17 08:31:58.000000000 -0400
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 97, 98, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 97, 98, 2002, 2003 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
@@ -20,17 +20,26 @@
#include <tls.h>
#if ! USE___THREAD
+
# undef _res
extern struct __res_state _res;
-#endif
/* When threaded, _res may be a per-thread variable. */
struct __res_state *
-#if ! USE___THREAD
weak_const_function
-#endif
__res_state (void)
{
return &_res;
}
+
+#else
+
+struct __res_state *
+__res_state (void)
+{
+ return __resp;
+}
+
+#endif
+
libc_hidden_def (__res_state)
Jakub
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |