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.
This commit is contained in:
Ulrich Drepper 2003-07-22 23:10:17 +00:00
parent 11bf8ce1d6
commit 0e9d624072
21 changed files with 285 additions and 34 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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 */

View File

@ -43,7 +43,7 @@ __h_errno_location (void)
struct __res_state *
__res_state (void)
{
return &_res;
return __resp;
}
#endif

View File

@ -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) {

View File

@ -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)

69
linuxthreads/tst-_res1.c Normal file
View File

@ -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);
}

View File

@ -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;

View File

@ -0,0 +1 @@
/* Nothing. */

View File

@ -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.

View File

@ -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

View File

@ -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)));

View File

@ -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;

View File

@ -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;
}

69
nptl/tst-_res1.c Normal file
View File

@ -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);
}

23
nptl/tst-_res1mod1.c Normal file
View File

@ -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;

1
nptl/tst-_res1mod2.c Normal file
View File

@ -0,0 +1 @@
/* Nothing. */

View File

@ -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
}
}

View File

@ -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>

View File

@ -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)