resolver broken in NPTL build

Denys Vlasenko vda.linux at googlemail.com
Sun May 16 05:20:33 UTC 2010


On Sunday 16 May 2010 06:23, Denys Vlasenko wrote:
> On Sunday 16 May 2010 06:00, Denys Vlasenko wrote:
> > It looks very complex. Can we just use a shared _res structure?
> > That will be simple and small.
> > 
> > Anyone objects to this?
> 
> Here's the RFC patch.

This is the fixed one (resolv.conf had broken indentation which fooled me).


diff -d -urpN uClibc.5/include/resolv.h uClibc.6/include/resolv.h
--- uClibc.5/include/resolv.h	2010-05-16 06:36:56.000000000 +0200
+++ uClibc.6/include/resolv.h	2010-05-16 07:17:49.000000000 +0200
@@ -420,24 +420,6 @@ int		res_nsend (res_state, const u_char 
 void		res_nclose (res_state) __THROW;
 __END_DECLS
 
-# if _LIBC
-#  ifdef __UCLIBC_HAS_THREADS__
-#   if defined __UCLIBC_HAS_TLS__ \
-	       && (!defined NOT_IN_libc || defined IS_IN_libpthread)
-#    undef _res
-#    ifndef NOT_IN_libc
-#     define __resp __libc_resp
-#    endif
-#    define _res (*__resp)
-extern __thread struct __res_state *__resp attribute_tls_model_ie;
-#   endif
-#  else
-#   undef _res
-#   define _res (*__resp)
-extern struct __res_state *__resp;
-#  endif /* __UCLIBC_HAS_THREADS__ */
-# endif /* _LIBC */
-
 #endif /* _RESOLV_H_ */
 
 #endif /* !_RESOLV_H_ */
diff -d -urpN uClibc.5/libc/inet/resolv.c uClibc.6/libc/inet/resolv.c
--- uClibc.5/libc/inet/resolv.c	2010-05-16 06:01:59.000000000 +0200
+++ uClibc.6/libc/inet/resolv.c	2010-05-16 06:17:17.000000000 +0200
@@ -3043,54 +3043,22 @@ void res_close(void)
 /* This needs to be after the use of _res in res_init, above.  */
 #undef _res
 
-#ifndef __UCLIBC_HAS_THREADS__
-/* The resolver state for use by single-threaded programs.
-   This differs from plain `struct __res_state _res;' in that it doesn't
+/* 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")));
-struct __res_state *__resp = &_res;
-#else //__UCLIBC_HAS_THREADS__
-struct __res_state _res __attribute__((section (".bss"))) attribute_hidden;
-
-# if defined __UCLIBC_HAS_TLS__
-#  undef __resp
-__thread struct __res_state *__resp = &_res;
-/*
- * FIXME: Add usage of hidden attribute for this when used in the shared
- *        library. It currently crashes the linker when doing section
- *        relocations.
- */
-extern __thread struct __res_state *__libc_resp
-       __attribute__ ((alias ("__resp"))) attribute_hidden;
-# else
-#  undef __resp
-struct __res_state *__resp = &_res;
-# endif
-#endif
 
 #endif /* L_res_init */
 
 #ifdef L_res_state
-# if defined __UCLIBC_HAS_TLS__
-struct __res_state *
-__res_state (void)
-{
-       return __resp;
-}
-# else
-#  undef _res
+# undef _res
 extern struct __res_state _res;
-
-/* When threaded, _res may be a per-thread variable.  */
 struct __res_state *
 weak_const_function
 __res_state (void)
 {
-       return &_res;
+	return &_res;
 }
-# endif
-
 #endif
 
 
diff -d -urpN uClibc.5/libpthread/linuxthreads/descr.h uClibc.6/libpthread/linuxthreads/descr.h
--- uClibc.5/libpthread/linuxthreads/descr.h	2010-04-06 03:24:22.000000000 +0200
+++ uClibc.6/libpthread/linuxthreads/descr.h	2010-05-16 06:09:38.000000000 +0200
@@ -15,7 +15,6 @@
 #ifndef _DESCR_H
 #define _DESCR_H	1
 
-#define __need_res_state
 #include <resolv.h>
 #include <sched.h>
 #include <setjmp.h>
@@ -163,9 +162,7 @@ struct _pthread_descr_struct
   int p_errno;                  /* error returned by last system call */
   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 */
 #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 -d -urpN uClibc.5/libpthread/linuxthreads/errno.c uClibc.6/libpthread/linuxthreads/errno.c
--- uClibc.5/libpthread/linuxthreads/errno.c	2010-04-06 03:24:22.000000000 +0200
+++ uClibc.6/libpthread/linuxthreads/errno.c	2010-05-16 06:06:33.000000000 +0200
@@ -35,14 +35,4 @@ __h_errno_location (void)
   pthread_descr self = thread_self();
   return THREAD_GETMEM (self, p_h_errnop);
 }
-
-#if 0
-/* Return thread specific resolver state.  */
-struct __res_state *
-__res_state (void)
-{
-  pthread_descr self = thread_self();
-  return THREAD_GETMEM (self, p_resp);
-}
-#endif
 #endif
diff -d -urpN uClibc.5/libpthread/linuxthreads/manager.c uClibc.6/libpthread/linuxthreads/manager.c
--- uClibc.5/libpthread/linuxthreads/manager.c	2010-04-06 03:24:22.000000000 +0200
+++ uClibc.6/libpthread/linuxthreads/manager.c	2010-05-16 06:17:32.000000000 +0200
@@ -28,7 +28,6 @@
 #include <sys/time.h>
 #include <sys/wait.h>           /* for waitpid macros */
 #include <locale.h>		/* for __uselocale */
-#include <resolv.h>		/* for __resp */
 
 #include "pthread.h"
 #include "internals.h"
@@ -293,9 +292,6 @@ 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_res;
 #endif
   /* Make gdb aware of new thread */
   if (__pthread_threads_debug && __pthread_sig_debug > 0) {
@@ -671,7 +667,6 @@ static int pthread_handle_create(pthread
 #if !(USE_TLS && HAVE___THREAD)
   new_thread->p_errnop = &new_thread->p_errno;
   new_thread->p_h_errnop = &new_thread->p_h_errno;
-  new_thread->p_resp = &new_thread->p_res;
 #endif
   new_thread->p_guardaddr = guardaddr;
   new_thread->p_guardsize = guardsize;
diff -d -urpN uClibc.5/libpthread/linuxthreads/pthread.c uClibc.6/libpthread/linuxthreads/pthread.c
--- uClibc.5/libpthread/linuxthreads/pthread.c	2010-05-16 06:01:59.000000000 +0200
+++ uClibc.6/libpthread/linuxthreads/pthread.c	2010-05-16 06:05:45.000000000 +0200
@@ -45,14 +45,6 @@ extern __typeof(sigaction) __libc_sigact
 extern int _errno;
 extern int _h_errno;
 
-# if defined __UCLIBC_HAS_IPv4__ || defined __UCLIBC_HAS_IPV6__
-/* We need the global/static resolver state here.  */
-# include <resolv.h>
-# undef _res
-extern struct __res_state _res;
-# endif
-#endif
-
 #ifdef USE_TLS
 
 /* We need only a few variables.  */
@@ -73,9 +65,6 @@ struct _pthread_descr_struct __pthread_i
 #if !(USE_TLS && HAVE___THREAD)
   .p_errnop = &_errno,
   .p_h_errnop = &_h_errno,
-# if defined __UCLIBC_HAS_IPv4__ || defined __UCLIBC_HAS_IPV6__
-  .p_resp = &_res,
-# endif
 #endif
   .p_userstack = 1,
   .p_resume_count = __ATOMIC_INITIALIZER,
@@ -542,17 +531,9 @@ static void pthread_initialize(void)
 #ifdef USE_TLS
   /* Update the descriptor for the initial thread. */
   THREAD_SETMEM (((pthread_descr) NULL), p_pid, __getpid());
-# if !defined HAVE___THREAD && (defined __UCLIBC_HAS_IPv4__ || defined __UCLIBC_HAS_IPV6__)
-  /* Likewise for the resolver state _res.  */
-  THREAD_SETMEM (((pthread_descr) NULL), p_resp, &_res);
-# endif
 #else
   /* Update the descriptor for the initial thread. */
   __pthread_initial_thread.p_pid = __getpid();
-# if defined __UCLIBC_HAS_IPv4__ || defined __UCLIBC_HAS_IPV6__
-  /* Likewise for the resolver state _res.  */
-  __pthread_initial_thread.p_resp = &_res;
-# endif
 #endif
 #if !__ASSUME_REALTIME_SIGNALS
   /* Initialize real-time signals. */
@@ -1128,9 +1109,6 @@ void __pthread_reset_main_thread(void)
   /* Now this thread modifies the global variables.  */
   THREAD_SETMEM(self, p_errnop, &_errno);
   THREAD_SETMEM(self, p_h_errnop, &_h_errno);
-# if defined __UCLIBC_HAS_IPv4__ || defined __UCLIBC_HAS_IPV6__
-  THREAD_SETMEM(self, p_resp, &_res);
-# endif
 #endif
 
 #ifndef FLOATING_STACKS
diff -d -urpN uClibc.5/libpthread/linuxthreads/sysdeps/pthread/res-state.c uClibc.6/libpthread/linuxthreads/sysdeps/pthread/res-state.c
--- uClibc.5/libpthread/linuxthreads/sysdeps/pthread/res-state.c	2010-04-06 03:24:22.000000000 +0200
+++ uClibc.6/libpthread/linuxthreads/sysdeps/pthread/res-state.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,47 +0,0 @@
-/* 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
-   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>
-#include <tls.h>
-#include <linuxthreads/internals.h>
-#include <sysdep-cancel.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)
-{
-#if ! USE___THREAD
-  if (! SINGLE_THREAD_P)
-    {
-      pthread_descr self = thread_self();
-      return LIBC_THREAD_GETMEM (self, p_resp);
-    }
-  return &_res;
-#else
-  return __resp;
-#endif
-}
-libc_hidden_def (__res_state)
diff -d -urpN uClibc.5/libpthread/nptl/descr.h uClibc.6/libpthread/nptl/descr.h
--- uClibc.5/libpthread/nptl/descr.h	2010-05-16 06:01:59.000000000 +0200
+++ uClibc.6/libpthread/nptl/descr.h	2010-05-16 06:10:04.000000000 +0200
@@ -34,7 +34,6 @@
 #ifdef HAVE_FORCED_UNWIND
 # include <unwind.h>
 #endif
-#define __need_res_state
 #include <resolv.h>
 #include <bits/kernel-features.h>
 #include "uClibc-glue.h"
@@ -363,9 +362,6 @@ struct pthread
   /* Thread Priority Protection data.  */
   struct priority_protection_data *tpp;
 
-  /* Resolver state.  */
-  struct __res_state res;
-
   /* This member must be last.  */
   char end_padding[];
 
diff -d -urpN uClibc.5/libpthread/nptl/Makefile.in uClibc.6/libpthread/nptl/Makefile.in
--- uClibc.5/libpthread/nptl/Makefile.in	2010-05-16 06:01:59.000000000 +0200
+++ uClibc.6/libpthread/nptl/Makefile.in	2010-05-16 06:10:44.000000000 +0200
@@ -95,7 +95,7 @@ libpthread-routines = init vars events v
 		      pt-raise pt-system \
 		      flockfile ftrylockfile funlockfile \
 		      sigaction \
-		      herrno res \
+		      herrno \
 		      pthread_kill_other_threads \
 		      pthread_getaffinity pthread_setaffinity \
 		      pthread_attr_getaffinity pthread_attr_setaffinity \
diff -d -urpN uClibc.5/libpthread/nptl/pthread_create.c uClibc.6/libpthread/nptl/pthread_create.c
--- uClibc.5/libpthread/nptl/pthread_create.c	2010-05-16 06:01:59.000000000 +0200
+++ uClibc.6/libpthread/nptl/pthread_create.c	2010-05-16 06:17:25.000000000 +0200
@@ -234,9 +234,6 @@ start_thread (void *arg)
   THREAD_SETMEM (pd, cpuclock_offset, now);
 #endif
 
-  /* Initialize resolver state pointer.  */
-  __resp = &pd->res;
-
 #ifdef __NR_set_robust_list
 # ifndef __ASSUME_SET_ROBUST_LIST
   if (__set_robust_list_avail >= 0)
diff -d -urpN uClibc.5/libpthread/nptl/res.c uClibc.6/libpthread/nptl/res.c
--- uClibc.5/libpthread/nptl/res.c	2010-05-16 06:01:59.000000000 +0200
+++ uClibc.6/libpthread/nptl/res.c	1970-01-01 01:00:00.000000000 +0100
@@ -1,27 +0,0 @@
-/* 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
-   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 <features.h>
-#include <tls.h>
-#include <resolv.h>
-
-struct __res_state *
-__res_state (void)
-{
-  return __resp;
-}


More information about the uClibc mailing list