From 0e9d624072fd24ee7d113bcf9325e8fb21d2cf60 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 22 Jul 2003 23:10:17 +0000 Subject: Update. 2003-07-22 Jakub Jelinek * 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/Makefile | 14 +++++++ linuxthreads/descr.h | 2 +- linuxthreads/libc-tls-loc.c | 2 +- linuxthreads/manager.c | 4 ++ linuxthreads/sysdeps/pthread/res-state.c | 4 +- linuxthreads/tst-_res1.c | 69 ++++++++++++++++++++++++++++++++ linuxthreads/tst-_res1mod1.c | 23 +++++++++++ linuxthreads/tst-_res1mod2.c | 1 + 8 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 linuxthreads/tst-_res1.c create mode 100644 linuxthreads/tst-_res1mod1.c create mode 100644 linuxthreads/tst-_res1mod2.c (limited to 'linuxthreads') 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 #include /* for waitpid macros */ #include /* for __uselocale */ +#include /* for __resp */ #include #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 , 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 +#include +#include +#include + +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 , 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 +#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. */ -- cgit v1.2.3