public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH 08/10] elf: Do not load libpthread for PTHREAD_IN_LIBC
Date: Tue, 18 May 2021 16:25:30 +0200	[thread overview]
Message-ID: <e3ad0aceca81d9db786582382b0a3ce4a7b2221c.1621347402.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1621347402.git.fweimer@redhat.com>

---
 elf/dl-load.c    | 19 +++++++++++++++++--
 elf/dl-version.c |  9 +++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 918ec7546c..f97cb140f4 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -2029,12 +2029,26 @@ open_path (const char *name, size_t namelen, int mode,
 
 /* Map in the shared object file NAME.  */
 
+static inline const char *
+object_real_name (const char *name)
+{
+  /* If libpthread is integrated into libc, treat a request to load
+     libpthread as a request to load libc (because libc was a
+     dependency of libpthread).  */
+#if PTHREAD_IN_LIBC
+  if (strcmp (name, LIBPTHREAD_SO) == 0)
+    return LIBC_SO;
+#endif
+  return name;
+}
+
 struct link_map *
 _dl_map_object (struct link_map *loader, const char *name,
 		int type, int trace_mode, int mode, Lmid_t nsid)
 {
   int fd;
   const char *origname = NULL;
+  const char *implementation_name = object_real_name (name);
   char *realname;
   char *name_copy;
   struct link_map *l;
@@ -2051,7 +2065,7 @@ _dl_map_object (struct link_map *loader, const char *name,
 	 yet been opened.  */
       if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0))
 	continue;
-      if (!_dl_name_match_p (name, l))
+      if (!_dl_name_match_p (implementation_name, l))
 	{
 	  const char *soname;
 
@@ -2061,7 +2075,7 @@ _dl_map_object (struct link_map *loader, const char *name,
 
 	  soname = ((const char *) D_PTR (l, l_info[DT_STRTAB])
 		    + l->l_info[DT_SONAME]->d_un.d_val);
-	  if (strcmp (name, soname) != 0)
+	  if (strcmp (implementation_name, soname) != 0)
 	    continue;
 
 	  /* We have a match on a new name -- cache it.  */
@@ -2106,6 +2120,7 @@ _dl_map_object (struct link_map *loader, const char *name,
 		  if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
 		    _dl_debug_printf ("audit changed filename %s -> %s\n",
 				      before, name);
+		  implementation_name = object_real_name (name);
 
 		  if (origname == NULL)
 		    origname = before;
diff --git a/elf/dl-version.c b/elf/dl-version.c
index 914955c2a8..932cffda09 100644
--- a/elf/dl-version.c
+++ b/elf/dl-version.c
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <ldsodefs.h>
 #include <_itoa.h>
+#include <gnu/lib-names.h>
 
 #include <assert.h>
 
@@ -200,6 +201,14 @@ _dl_check_map_versions (struct link_map *map, int verbose, int trace_mode)
 	  ElfW(Vernaux) *aux;
 	  struct link_map *needed = find_needed (strtab + ent->vn_file, map);
 
+#if PTHREAD_IN_LIBC
+	  /* With an integrated libpthread, check libpthread
+	     references against libc instead.  */
+	  if (needed == NULL
+	      && strcmp (strtab + ent->vn_file, LIBPTHREAD_SO) == 0)
+	    needed = find_needed (LIBC_SO, map);
+#endif
+
 	  /* If NEEDED is NULL this means a dependency was not found
 	     and no stub entry was created.  This should never happen.  */
 	  assert (needed != NULL);
-- 
2.31.1



  parent reply	other threads:[~2021-05-18 14:26 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 14:24 [PATCH 00/10] nptl: Complete libpthread removal Florian Weimer
2021-05-18 14:24 ` [PATCH 01/10] nptl: Perform signal initialization upon pthread_create Florian Weimer
2021-05-20 19:15   ` Adhemerval Zanella
2021-05-20 19:41     ` Florian Weimer
2021-05-20 19:57       ` Adhemerval Zanella
2021-05-20 20:05         ` Florian Weimer
2021-05-20 20:32           ` Adhemerval Zanella
2021-05-21  9:58             ` Florian Weimer
2021-05-21 11:31               ` Adhemerval Zanella
2021-05-21 12:40                 ` Adhemerval Zanella
2021-05-18 14:24 ` [PATCH 02/10] nptl: Eliminate the __static_tls_size, __static_tls_align_m1 variables Florian Weimer
2021-05-18 14:25 ` [PATCH 03/10] nptl: Move semi-public __pthread_get_minstack symbol into libc Florian Weimer
2021-05-18 14:25 ` [PATCH 04/10] elf: Use custom NODELETE DSO for tst-dlopenfail, tst-dlopenfail-2 Florian Weimer
2021-05-20 20:36   ` Adhemerval Zanella
2021-05-18 14:25 ` [PATCH 05/10] nptl: Move pthread_create, thrd_create into libc Florian Weimer
2021-05-20 20:44   ` Adhemerval Zanella
2021-05-18 14:25 ` [PATCH 06/10] nptl: Remove unused __libc_pthread_init function Florian Weimer
2021-05-18 14:49   ` Andreas Schwab
2021-05-18 14:25 ` [PATCH 07/10] nptl: Remove remaining code from libpthread Florian Weimer
2021-05-20 20:49   ` Adhemerval Zanella
2021-05-18 14:25 ` Florian Weimer [this message]
2021-05-20 20:53   ` [PATCH 08/10] elf: Do not load libpthread for PTHREAD_IN_LIBC Adhemerval Zanella
2021-05-21 19:15     ` Florian Weimer
2021-05-18 14:25 ` [PATCH 09/10] elf: Add facility to create stub DSOs in elf/stub-dsos Florian Weimer
2021-05-24 18:24   ` Adhemerval Zanella
2021-05-24 18:25     ` Adhemerval Zanella
2021-05-18 14:25 ` [PATCH 10/10] nptl: Stop building libpthread Florian Weimer
2021-05-18 14:56 ` [PATCH 00/10] nptl: Complete libpthread removal Andreas Schwab
2021-05-18 15:04   ` Florian Weimer
2021-05-18 15:26     ` Andreas Schwab
2021-05-18 15:51       ` Florian Weimer
2021-05-18 16:27         ` Andreas Schwab
2021-05-18 16:31           ` Florian Weimer
2021-05-18 16:47             ` Andreas Schwab
2021-05-20 13:27               ` Florian Weimer
2021-05-20 13:50                 ` Andreas Schwab
2021-05-20 13:54                   ` Florian Weimer
2021-05-20 14:01                     ` Andreas Schwab
2021-05-20 15:09                     ` H.J. Lu
2021-05-20 15:13                       ` Florian Weimer
2021-05-20 15:17                       ` Andreas Schwab
2021-05-20 15:35                         ` H.J. Lu
2021-05-20 15:39                           ` Florian Weimer
2021-05-20 15:57                             ` H.J. Lu
2021-05-19 11:57 ` Szabolcs Nagy
2021-05-19 12:35   ` Florian Weimer
2021-05-19 13:14     ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3ad0aceca81d9db786582382b0a3ce4a7b2221c.1621347402.git.fweimer@redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).