summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-07-22 23:10:17 +0000
committerUlrich Drepper <drepper@redhat.com>2003-07-22 23:10:17 +0000
commit0e9d624072fd24ee7d113bcf9325e8fb21d2cf60 (patch)
treec1185e3d74e8db6363798cf48b9b83bd71ef568d
parent11bf8ce1d6c28b4758cedeaea9558f6a071fe7d8 (diff)
Update.
2003-07-22 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.
-rw-r--r--ChangeLog14
-rw-r--r--include/resolv.h5
-rw-r--r--linuxthreads/Makefile14
-rw-r--r--linuxthreads/descr.h2
-rw-r--r--linuxthreads/libc-tls-loc.c2
-rw-r--r--linuxthreads/manager.c4
-rw-r--r--linuxthreads/sysdeps/pthread/res-state.c4
-rw-r--r--linuxthreads/tst-_res1.c69
-rw-r--r--linuxthreads/tst-_res1mod1.c23
-rw-r--r--linuxthreads/tst-_res1mod2.c1
-rw-r--r--nptl/ChangeLog16
-rw-r--r--nptl/Makefile6
-rw-r--r--nptl/descr.h6
-rw-r--r--nptl/pthread_create.c4
-rw-r--r--nptl/res.c10
-rw-r--r--nptl/tst-_res1.c69
-rw-r--r--nptl/tst-_res1mod1.c23
-rw-r--r--nptl/tst-_res1mod2.c1
-rw-r--r--resolv/Versions6
-rw-r--r--resolv/res_libc.c23
-rw-r--r--sysdeps/generic/res-state.c17
21 files changed, 285 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index 42525d6db7..5d37f12141 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2003-07-22 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.
+
2003-07-22 H.J. Lu <hongjiu.lu@intel.com>
* elf/dl-support.c (_dl_hwcap): New variable.
diff --git a/include/resolv.h b/include/resolv.h
index 9d7bb8b9fd..0437753035 100644
--- a/include/resolv.h
+++ b/include/resolv.h
@@ -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
diff --git a/linuxthreads/Makefile b/linuxthreads/Makefile
index 3d45b81f19..9bb38536fc 100644
--- a/linuxthreads/Makefile
+++ b/linuxthreads/Makefile
@@ -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)/libnss_dns.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
diff --git a/linuxthreads/descr.h b/linuxthreads/descr.h
index a9aaa55122..f00278cb51 100644
--- a/linuxthreads/descr.h
+++ b/linuxthreads/descr.h
@@ -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 */
diff --git a/linuxthreads/libc-tls-loc.c b/linuxthreads/libc-tls-loc.c
index a8d1b4e7fd..a0a4b1b07d 100644
--- a/linuxthreads/libc-tls-loc.c
+++ b/linuxthreads/libc-tls-loc.c
@@ -43,7 +43,7 @@ __h_errno_location (void)
struct __res_state *
__res_state (void)
{
- return &_res;
+ return __resp;
}
#endif
diff --git a/linuxthreads/manager.c b/linuxthreads/manager.c
index 91620a2cc4..9620b8b39c 100644
--- a/linuxthreads/manager.c
+++ b/linuxthreads/manager.c
@@ -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) {
diff --git a/linuxthreads/sysdeps/pthread/res-state.c b/linuxthreads/sysdeps/pthread/res-state.c
index 823101819d..016e20b4ef 100644
--- a/linuxthreads/sysdeps/pthread/res-state.c
+++ b/linuxthreads/sysdeps/pthread/res-state.c
@@ -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)
diff --git a/linuxthreads/tst-_res1.c b/linuxthreads/tst-_res1.c
new file mode 100644
index 0000000000..651e3cc40d
--- /dev/null
+++ b/linuxthreads/tst-_res1.c
@@ -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);
+}
diff --git a/linuxthreads/tst-_res1mod1.c b/linuxthreads/tst-_res1mod1.c
new file mode 100644
index 0000000000..73b190e6ba
--- /dev/null
+++ b/linuxthreads/tst-_res1mod1.c
@@ -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;
diff --git a/linuxthreads/tst-_res1mod2.c b/linuxthreads/tst-_res1mod2.c
new file mode 100644
index 0000000000..d2a3509c6d
--- /dev/null
+++ b/linuxthreads/tst-_res1mod2.c
@@ -0,0 +1 @@
+/* Nothing. */
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 12ab1a811e..8d36515b7c 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,19 @@
+2003-07-22 Jakub Jelinek <jakub@redhat.com>
+
+ * res.c (__res_state): Return __resp.
+ * descr.h: Include resolv.h.
+ (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
+ libpthread.
+ * tst-_res1.c: New file.
+ * tst-_res1mod1.c: New file.
+ * tst-_res1mod2.c: New file.
+
2003-07-21 Ulrich Drepper <drepper@redhat.com>
* sysdeps/pthread/createthread.c: Don't define CLONE_STOPPED.
diff --git a/nptl/Makefile b/nptl/Makefile
index 66e33a7c0f..6cf30c440f 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -250,10 +250,10 @@ tests += tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx5 \
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)))
@@ -400,6 +400,8 @@ $(objpfx)tst-cancelx17: $(common-objpfx)rt/librt.so
$(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
diff --git a/nptl/descr.h b/nptl/descr.h
index fb364b95ca..6c7f2317c9 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -35,7 +35,8 @@
#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 +236,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)));
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 7565826997..ae97f4a62d 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -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;
diff --git a/nptl/res.c b/nptl/res.c
index 6c2e3f8867..ba4f81d06f 100644
--- a/nptl/res.c
+++ b/nptl/res.c
@@ -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;
}
diff --git a/nptl/tst-_res1.c b/nptl/tst-_res1.c
new file mode 100644
index 0000000000..651e3cc40d
--- /dev/null
+++ b/nptl/tst-_res1.c
@@ -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);
+}
diff --git a/nptl/tst-_res1mod1.c b/nptl/tst-_res1mod1.c
new file mode 100644
index 0000000000..73b190e6ba
--- /dev/null
+++ b/nptl/tst-_res1mod1.c
@@ -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;
diff --git a/nptl/tst-_res1mod2.c b/nptl/tst-_res1mod2.c
new file mode 100644
index 0000000000..d2a3509c6d
--- /dev/null
+++ b/nptl/tst-_res1mod2.c
@@ -0,0 +1 @@
+/* Nothing. */
diff --git a/resolv/Versions b/resolv/Versions
index fcbaba5a47..ec461d34ac 100644
--- a/resolv/Versions
+++ b/resolv/Versions
@@ -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
}
}
diff --git a/resolv/res_libc.c b/resolv/res_libc.c
index 763a88725a..66da110d5f 100644
--- a/resolv/res_libc.c
+++ b/resolv/res_libc.c
@@ -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>
diff --git a/sysdeps/generic/res-state.c b/sysdeps/generic/res-state.c
index 0c2cb6c948..e327e34f59 100644
--- a/sysdeps/generic/res-state.c
+++ b/sysdeps/generic/res-state.c
@@ -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)