summary refs log tree commit diff
path: root/resolv
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-07-02 11:45:00 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-07-02 11:45:00 +0200
commitdbb949f53d4801b91885b2dfac9875b83a8710bf (patch)
tree9fdfcaeda7ba0f7f2895f45e233757cdfdb1eef3 /resolv
parent813c6ec808556553be9d39e900a3fc97ceb32330 (diff)
downloadglibc-dbb949f53d4801b91885b2dfac9875b83a8710bf.tar.gz
glibc-dbb949f53d4801b91885b2dfac9875b83a8710bf.tar.xz
glibc-dbb949f53d4801b91885b2dfac9875b83a8710bf.zip
resolv: Move libanl into libc (if libpthread is in libc)
The symbols gai_cancel, gai_error, gai_suspend, getaddrinfo_a,
__gai_suspend_time64 were moved using scripts/move-symbol-to-libc.py.

For Hurd (which remains !PTHREAD_IN_LIBC), a few #define redirects
had to be added because several pthread functions are not available
under __.  (Linux uses __ prefixes for most hidden aliases, and has
to in some cases to avoid linknamespace issues.)
Diffstat (limited to 'resolv')
-rw-r--r--resolv/Makefile7
-rw-r--r--resolv/Versions16
-rw-r--r--resolv/gai_cancel.c17
-rw-r--r--resolv/gai_error.c13
-rw-r--r--resolv/gai_misc.c48
-rw-r--r--resolv/gai_misc.h1
-rw-r--r--resolv/gai_notify.c15
-rw-r--r--resolv/gai_sigqueue.c2
-rw-r--r--resolv/gai_suspend.c47
-rw-r--r--resolv/getaddrinfo_a.c21
-rw-r--r--resolv/libanl-compat.c35
11 files changed, 173 insertions, 49 deletions
diff --git a/resolv/Makefile b/resolv/Makefile
index 3fbc320ee1..1d3565d478 100644
--- a/resolv/Makefile
+++ b/resolv/Makefile
@@ -112,8 +112,11 @@ libresolv-routines := res_comp res_debug \
 		      ns_samedomain ns_date res_enable_icmp \
 		      compat-hooks compat-gethnamaddr
 
-libanl-routines := gai_cancel gai_error gai_misc gai_notify gai_suspend \
-		   getaddrinfo_a
+$(libanl-routines-var) += \
+  gai_cancel gai_error gai_misc gai_notify gai_suspend getaddrinfo_a
+
+libanl-routines += libanl-compat
+libanl-shared-only-routines += libanl-compat
 
 subdir-dirs = nss_dns
 vpath %.c nss_dns
diff --git a/resolv/Versions b/resolv/Versions
index 9a82704af7..d4f6b4b819 100644
--- a/resolv/Versions
+++ b/resolv/Versions
@@ -21,8 +21,20 @@ libc {
     # r*
     __res_state; __res_init; __res_nclose; __res_ninit; _res_hconf;
   }
+  GLIBC_2.2.3 {
+%if PTHREAD_IN_LIBC
+    gai_cancel; gai_error; gai_suspend; getaddrinfo_a;
+%endif
+  }
+  GLIBC_2.34 {
+%if PTHREAD_IN_LIBC
+    gai_cancel; gai_error; gai_suspend; getaddrinfo_a;
+%endif
+  }
   GLIBC_PRIVATE {
+%if !PTHREAD_IN_LIBC
     __gai_sigqueue;
+%endif
 
     __h_errno; __resp;
 
@@ -103,6 +115,10 @@ libnss_dns {
 
 libanl {
   GLIBC_2.2.3 {
+%if PTHREAD_IN_LIBC
+    __libanl_version_placeholder;
+%else
     gai_cancel; gai_error; gai_suspend; getaddrinfo_a;
+%endif
   }
 }
diff --git a/resolv/gai_cancel.c b/resolv/gai_cancel.c
index 5d398ffea8..aa6ba03e5a 100644
--- a/resolv/gai_cancel.c
+++ b/resolv/gai_cancel.c
@@ -18,18 +18,18 @@
 
 #include <netdb.h>
 #include <pthread.h>
-
+#include <shlib-compat.h>
 #include <gai_misc.h>
 
 
 int
-gai_cancel (struct gaicb *gaicbp)
+__gai_cancel (struct gaicb *gaicbp)
 {
   int result = 0;
   int status;
 
   /* Request the mutex.  */
-  pthread_mutex_lock (&__gai_requests_mutex);
+  __pthread_mutex_lock (&__gai_requests_mutex);
 
   /* Find the request among those queued but not yet running.  */
   status = __gai_remove_request (gaicbp);
@@ -41,7 +41,16 @@ gai_cancel (struct gaicb *gaicbp)
     result = EAI_ALLDONE;
 
   /* Release the mutex.  */
-  pthread_mutex_unlock (&__gai_requests_mutex);
+  __pthread_mutex_unlock (&__gai_requests_mutex);
 
   return result;
 }
+#if PTHREAD_IN_LIBC
+versioned_symbol (libc, __gai_cancel, gai_cancel, GLIBC_2_34);
+
+# if OTHER_SHLIB_COMPAT (libanl, GLIBC_2_2_3, GLIBC_2_34)
+compat_symbol (libanl, __gai_cancel, gai_cancel, GLIBC_2_2_3);
+# endif
+#else /* !PTHREAD_IN_LIBC */
+strong_alias (__gai_cancel, gai_cancel)
+#endif /* !PTHREAD_IN_LIBC */
diff --git a/resolv/gai_error.c b/resolv/gai_error.c
index 4f9ac557b7..9fe9c400ee 100644
--- a/resolv/gai_error.c
+++ b/resolv/gai_error.c
@@ -17,11 +17,20 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <netdb.h>
-
+#include <shlib-compat.h>
 #include <gai_misc.h>
 
 int
-gai_error (struct gaicb *req)
+__gai_error (struct gaicb *req)
 {
   return req->__return;
 }
+#if PTHREAD_IN_LIBC
+versioned_symbol (libc, __gai_error, gai_error, GLIBC_2_34);
+
+# if OTHER_SHLIB_COMPAT (libanl, GLIBC_2_2_3, GLIBC_2_34)
+compat_symbol (libanl, __gai_error, gai_error, GLIBC_2_2_3);
+# endif
+#else /* !PTHREAD_IN_LIBC */
+strong_alias (__gai_error, gai_error)
+#endif /* !PTHREAD_IN_LIBC */
diff --git a/resolv/gai_misc.c b/resolv/gai_misc.c
index 04be05e109..11cc574320 100644
--- a/resolv/gai_misc.c
+++ b/resolv/gai_misc.c
@@ -24,7 +24,16 @@
 
 #include <gai_misc.h>
 
-
+#if !PTHREAD_IN_LIBC
+/* The available function names differ outside of libc.  (In libc, we
+   need to use hidden aliases to avoid the PLT.)  */
+#define __pthread_attr_init pthread_attr_init
+#define __pthread_attr_setdetachstate pthread_attr_setdetachstate
+#define __pthread_cond_signal pthread_cond_signal
+#define __pthread_cond_timedwait pthread_cond_timedwait
+#define __pthread_create pthread_create
+#define __pthread_exit pthread_exit
+#endif
 
 #ifndef gai_create_helper_thread
 # define gai_create_helper_thread __gai_create_helper_thread
@@ -36,12 +45,12 @@ __gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
   pthread_attr_t attr;
 
   /* Make sure the thread is created detached.  */
-  pthread_attr_init (&attr);
-  pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+  __pthread_attr_init (&attr);
+  __pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
 
-  int ret = pthread_create (threadp, &attr, tf, arg);
+  int ret = __pthread_create (threadp, &attr, tf, arg);
 
-  (void) pthread_attr_destroy (&attr);
+  (void) __pthread_attr_destroy (&attr);
   return ret;
 }
 #endif
@@ -216,13 +225,13 @@ __gai_enqueue_request (struct gaicb *gaicbp)
   struct requestlist *lastp;
 
   /* Get the mutex.  */
-  pthread_mutex_lock (&__gai_requests_mutex);
+  __pthread_mutex_lock (&__gai_requests_mutex);
 
   /* Get a new element for the waiting list.  */
   newp = get_elem ();
   if (newp == NULL)
     {
-      pthread_mutex_unlock (&__gai_requests_mutex);
+      __pthread_mutex_unlock (&__gai_requests_mutex);
       __set_errno (EAGAIN);
       return NULL;
     }
@@ -285,11 +294,11 @@ __gai_enqueue_request (struct gaicb *gaicbp)
       /* If there is a thread waiting for work, then let it know that we
 	 have just given it something to do. */
       if (idle_thread_count > 0)
-	pthread_cond_signal (&__gai_new_request_notification);
+	__pthread_cond_signal (&__gai_new_request_notification);
     }
 
   /* Release the mutex.  */
-  pthread_mutex_unlock (&__gai_requests_mutex);
+  __pthread_mutex_unlock (&__gai_requests_mutex);
 
   return newp;
 }
@@ -309,7 +318,7 @@ handle_requests (void *arg)
 	 "get work off the work queue" part of this loop, which is near the
 	 end. */
       if (runp == NULL)
-	pthread_mutex_lock (&__gai_requests_mutex);
+	__pthread_mutex_lock (&__gai_requests_mutex);
       else
 	{
 	  /* Make the request.  */
@@ -321,7 +330,7 @@ handle_requests (void *arg)
 				       req->ar_request, &req->ar_result);
 
 	  /* Get the mutex.  */
-	  pthread_mutex_lock (&__gai_requests_mutex);
+	  __pthread_mutex_lock (&__gai_requests_mutex);
 
 	  /* Send the signal to notify about finished processing of the
 	     request.  */
@@ -369,8 +378,8 @@ handle_requests (void *arg)
 	      wakeup_time.tv_nsec -= 1000000000;
 	      ++wakeup_time.tv_sec;
 	    }
-	  pthread_cond_timedwait (&__gai_new_request_notification,
-				  &__gai_requests_mutex, &wakeup_time);
+	  __pthread_cond_timedwait (&__gai_new_request_notification,
+				    &__gai_requests_mutex, &wakeup_time);
 	  --idle_thread_count;
 	  runp = requests;
 	  while (runp != NULL && runp->running != 0)
@@ -395,20 +404,21 @@ handle_requests (void *arg)
 		 up for these other work elements; otherwise, we should try
 		 to create a new thread. */
 	      if (idle_thread_count > 0)
-		pthread_cond_signal (&__gai_new_request_notification);
+		__pthread_cond_signal (&__gai_new_request_notification);
 	      else if (nthreads < optim.gai_threads)
 		{
 		  pthread_t thid;
 		  pthread_attr_t attr;
 
 		  /* Make sure the thread is created detached.  */
-		  pthread_attr_init (&attr);
-		  pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+		  __pthread_attr_init (&attr);
+		  __pthread_attr_setdetachstate (&attr,
+						 PTHREAD_CREATE_DETACHED);
 
 		  /* Now try to start a thread. If we fail, no big deal,
 		     because we know that there is at least one thread (us)
 		     that is working on lookup operations. */
-		  if (pthread_create (&thid, &attr, handle_requests, NULL)
+		  if (__pthread_create (&thid, &attr, handle_requests, NULL)
 		      == 0)
 		    ++nthreads;
 		}
@@ -416,11 +426,11 @@ handle_requests (void *arg)
 	}
 
       /* Release the mutex.  */
-      pthread_mutex_unlock (&__gai_requests_mutex);
+      __pthread_mutex_unlock (&__gai_requests_mutex);
     }
   while (runp != NULL);
 
-  pthread_exit (NULL);
+  __pthread_exit (NULL);
 }
 
 
diff --git a/resolv/gai_misc.h b/resolv/gai_misc.h
index 11167a73a1..d3ef00bad7 100644
--- a/resolv/gai_misc.h
+++ b/resolv/gai_misc.h
@@ -96,5 +96,6 @@ extern int __gai_notify_only (struct sigevent *sigev, pid_t caller_pid)
 
 /* Send the signal.  */
 extern int __gai_sigqueue (int sig, const union sigval val, pid_t caller_pid);
+libc_hidden_proto (__gai_sigqueue)
 
 #endif /* gai_misc.h */
diff --git a/resolv/gai_notify.c b/resolv/gai_notify.c
index de104e5560..8fee627f46 100644
--- a/resolv/gai_notify.c
+++ b/resolv/gai_notify.c
@@ -21,6 +21,15 @@
 #include <stdlib.h>
 #include <gai_misc.h>
 
+#if !PTHREAD_IN_LIBC
+/* The available function names differ outside of libc.  (In libc, we
+   need to use hidden aliases to avoid the PLT.)  */
+#define __pthread_attr_init pthread_attr_init
+#define __pthread_attr_setdetachstate pthread_attr_setdetachstate
+#define __pthread_cond_signal pthread_cond_signal
+#define __pthread_cond_timedwait pthread_cond_timedwait
+#define __pthread_create pthread_create
+#endif
 
 struct notify_func
   {
@@ -56,8 +65,8 @@ __gai_notify_only (struct sigevent *sigev, pid_t caller_pid)
       pattr = (pthread_attr_t *) sigev->sigev_notify_attributes;
       if (pattr == NULL)
 	{
-	  pthread_attr_init (&attr);
-	  pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+	  __pthread_attr_init (&attr);
+	  __pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
 	  pattr = &attr;
 	}
 
@@ -75,7 +84,7 @@ __gai_notify_only (struct sigevent *sigev, pid_t caller_pid)
 	{
 	  nf->func = sigev->sigev_notify_function;
 	  nf->value = sigev->sigev_value;
-	  if (pthread_create (&tid, pattr, notify_func_wrapper, nf) < 0)
+	  if (__pthread_create (&tid, pattr, notify_func_wrapper, nf) < 0)
 	    {
 	      free (nf);
 	      result = -1;
diff --git a/resolv/gai_sigqueue.c b/resolv/gai_sigqueue.c
index f7d0dad73d..9b383e2480 100644
--- a/resolv/gai_sigqueue.c
+++ b/resolv/gai_sigqueue.c
@@ -27,5 +27,5 @@ __gai_sigqueue (int sig, const union sigval val, pid_t caller_pid)
   __set_errno (ENOSYS);
   return -1;
 }
-
+libc_hidden_def (__gai_sigqueue)
 stub_warning (__gai_sigqueue)
diff --git a/resolv/gai_suspend.c b/resolv/gai_suspend.c
index a0c3407b00..965bb113a4 100644
--- a/resolv/gai_suspend.c
+++ b/resolv/gai_suspend.c
@@ -25,8 +25,8 @@
 #include <gai_misc.h>
 
 int
-__gai_suspend_time64 (const struct gaicb *const list[], int ent,
-                      const struct __timespec64 *timeout)
+___gai_suspend_time64 (const struct gaicb *const list[], int ent,
+		       const struct __timespec64 *timeout)
 {
   struct waitlist waitlist[ent];
   struct requestlist *requestlist[ent];
@@ -39,7 +39,7 @@ __gai_suspend_time64 (const struct gaicb *const list[], int ent,
   int result;
 
   /* Request the mutex.  */
-  pthread_mutex_lock (&__gai_requests_mutex);
+  __pthread_mutex_lock (&__gai_requests_mutex);
 
   /* There is not yet a finished request.  Signal the request that
      we are working for it.  */
@@ -91,7 +91,7 @@ __gai_suspend_time64 (const struct gaicb *const list[], int ent,
       /* Since `pthread_cond_wait'/`pthread_cond_timedwait' are cancelation
 	 points we must be careful.  We added entries to the waiting lists
 	 which we must remove.  So defer cancelation for now.  */
-      pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
+      __pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
 
 #ifdef DONT_NEED_GAI_MISC_COND
       result = 0;
@@ -121,7 +121,7 @@ __gai_suspend_time64 (const struct gaicb *const list[], int ent,
 	  }
 
       /* Now it's time to restore the cancelation state.  */
-      pthread_setcancelstate (oldstate, NULL);
+      __pthread_setcancelstate (oldstate, NULL);
 
 #ifndef DONT_NEED_GAI_MISC_COND
       /* Release the conditional variable.  */
@@ -145,17 +145,33 @@ __gai_suspend_time64 (const struct gaicb *const list[], int ent,
     }
 
   /* Release the mutex.  */
-  pthread_mutex_unlock (&__gai_requests_mutex);
+  __pthread_mutex_unlock (&__gai_requests_mutex);
 
   return result;
 }
 
-#if __TIMESIZE != 64
-libanl_hidden_def (__gai_suspend_time64)
+#if __TIMESIZE == 64
+# if PTHREAD_IN_LIBC
+versioned_symbol (libc, ___gai_suspend_time64, gai_suspend, GLIBC_2_34);
+#  if OTHER_SHLIB_COMPAT (libanl, GLIBC_2_2_3, GLIBC_2_34)
+compat_symbol (libanl, ___gai_suspend_time64, gai_suspend, GLIBC_2_2_3);
+#  endif
+# endif /* PTHREAD_IN_LIBC */
+
+#else /* __TIMESIZE != 64 */
+# if PTHREAD_IN_LIBC
+libc_hidden_ver (___gai_suspend_time64, __gai_suspend_time64)
+versioned_symbol (libc, ___gai_suspend_time64, __gai_suspend_time64,
+		  GLIBC_2_34);
+# else /* !PTHREAD_IN_LIBC */
+# if IS_IN (libanl)
+hidden_ver (___gai_suspend_time64, __gai_suspend_time64)
+# endif
+#endif /* !PTHREAD_IN_LIBC */
 
 int
-__gai_suspend (const struct gaicb *const list[], int ent,
-	       const struct timespec *timeout)
+___gai_suspend (const struct gaicb *const list[], int ent,
+		const struct timespec *timeout)
 {
   struct __timespec64 ts64;
 
@@ -164,5 +180,12 @@ __gai_suspend (const struct gaicb *const list[], int ent,
 
   return __gai_suspend_time64 (list, ent, timeout != NULL ? &ts64 : NULL);
 }
-#endif
-weak_alias (__gai_suspend, gai_suspend)
+#if PTHREAD_IN_LIBC
+versioned_symbol (libc, ___gai_suspend, gai_suspend, GLIBC_2_34);
+# if OTHER_SHLIB_COMPAT (libanl, GLIBC_2_2_3, GLIBC_2_34)
+compat_symbol (libanl, ___gai_suspend, gai_suspend, GLIBC_2_2_3);
+# endif
+# else
+weak_alias (___gai_suspend, gai_suspend)
+# endif /* !PTHREAD_IN_LIBC */
+#endif /* __TIMESIZE != 64 */
diff --git a/resolv/getaddrinfo_a.c b/resolv/getaddrinfo_a.c
index fca39a8d89..7541f2a9af 100644
--- a/resolv/getaddrinfo_a.c
+++ b/resolv/getaddrinfo_a.c
@@ -35,7 +35,7 @@ struct async_waitlist
 
 
 int
-getaddrinfo_a (int mode, struct gaicb *list[], int ent, struct sigevent *sig)
+__getaddrinfo_a (int mode, struct gaicb *list[], int ent, struct sigevent *sig)
 {
   struct sigevent defsigev;
   struct requestlist *requests[ent];
@@ -57,7 +57,7 @@ getaddrinfo_a (int mode, struct gaicb *list[], int ent, struct sigevent *sig)
     }
 
   /* Request the mutex.  */
-  pthread_mutex_lock (&__gai_requests_mutex);
+  __pthread_mutex_lock (&__gai_requests_mutex);
 
   /* Now we can enqueue all requests.  Since we already acquired the
      mutex the enqueue function need not do this.  */
@@ -85,7 +85,7 @@ getaddrinfo_a (int mode, struct gaicb *list[], int ent, struct sigevent *sig)
       /* Release the mutex.  We do this before raising a signal since the
 	 signal handler might do a `siglongjmp' and then the mutex is
 	 locked forever.  */
-      pthread_mutex_unlock (&__gai_requests_mutex);
+      __pthread_mutex_unlock (&__gai_requests_mutex);
 
       if (mode == GAI_NOWAIT)
 	__gai_notify_only (sig,
@@ -119,7 +119,7 @@ getaddrinfo_a (int mode, struct gaicb *list[], int ent, struct sigevent *sig)
       /* Since `pthread_cond_wait'/`pthread_cond_timedwait' are cancelation
 	 points we must be careful.  We added entries to the waiting lists
 	 which we must remove.  So defer cancelation for now.  */
-      pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
+      __pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
 
       while (total > 0)
 	{
@@ -132,7 +132,7 @@ getaddrinfo_a (int mode, struct gaicb *list[], int ent, struct sigevent *sig)
 	}
 
       /* Now it's time to restore the cancelation state.  */
-      pthread_setcancelstate (oldstate, NULL);
+      __pthread_setcancelstate (oldstate, NULL);
 
 #ifndef DONT_NEED_GAI_MISC_COND
       /* Release the conditional variable.  */
@@ -176,7 +176,16 @@ getaddrinfo_a (int mode, struct gaicb *list[], int ent, struct sigevent *sig)
     }
 
   /* Release the mutex.  */
-  pthread_mutex_unlock (&__gai_requests_mutex);
+  __pthread_mutex_unlock (&__gai_requests_mutex);
 
   return result;
 }
+#if PTHREAD_IN_LIBC
+versioned_symbol (libc, __getaddrinfo_a, getaddrinfo_a, GLIBC_2_34);
+
+# if OTHER_SHLIB_COMPAT (libanl, GLIBC_2_2_3, GLIBC_2_34)
+compat_symbol (libanl, __getaddrinfo_a, getaddrinfo_a, GLIBC_2_2_3);
+# endif
+#else /* !PTHREAD_IN_LIBC */
+strong_alias (__getaddrinfo_a, getaddrinfo_a)
+#endif /* !PTHREAD_IN_LIBC */
diff --git a/resolv/libanl-compat.c b/resolv/libanl-compat.c
new file mode 100644
index 0000000000..29df76f278
--- /dev/null
+++ b/resolv/libanl-compat.c
@@ -0,0 +1,35 @@
+/* Placeholder compatibility symbols for libanl.
+   Copyright (C) 2021 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, see
+   <https://www.gnu.org/licenses/>.  */
+
+#if PTHREAD_IN_LIBC
+# include <shlib-compat.h>
+# include <sys/cdefs.h>
+
+/* This file is used to keep specific symbol versions occupied, so
+   that ld does not generate weak symbol version definitions.  */
+
+void
+attribute_compat_text_section
+__attribute_used__
+__libanl_version_placeholder_1 (void)
+{
+}
+
+compat_symbol (libanl, __libanl_version_placeholder_1,
+               __libanl_version_placeholder, GLIBC_2_2_3);
+#endif