public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <maskray@google.com>
To: libc-alpha@sourceware.org, Florian Weimer <fweimer@redhat.com>
Subject: [PATCH] elf: Remove one-default-version check when searching an unversioned symbol
Date: Sat, 30 Apr 2022 19:06:43 -0700	[thread overview]
Message-ID: <20220501020643.1538749-1-maskray@google.com> (raw)

When searching an unversioned symbol, a definition of version
VER_NDX_GLOBAL is preferred while a default version symbol is a
fallback. The linker ensures that two default versions cannot be
attached to the same symbol (``multiple definition of `foo'``), so it is
of very little value for the loader to check this corner case. Delete
`num_versions` to simplify code.
---
 elf/dl-lookup.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
index 989b073e4f..5c6b2dc3df 100644
--- a/elf/dl-lookup.c
+++ b/elf/dl-lookup.c
@@ -65,8 +65,7 @@ check_match (const char *const undef_name,
 	     const Elf_Symndx symidx,
 	     const char *const strtab,
 	     const struct link_map *const map,
-	     const ElfW(Sym) **const versioned_sym,
-	     int *const num_versions)
+	     const ElfW(Sym) **const versioned_sym)
 {
   unsigned int stt = ELFW(ST_TYPE) (sym->st_info);
   assert (ELF_RTYPE_CLASS_PLT == 1);
@@ -147,9 +146,7 @@ check_match (const char *const undef_name,
 	      >= ((flags & DL_LOOKUP_RETURN_NEWEST) ? 2 : 3))
 	    {
 	      /* Don't accept hidden symbols.  */
-	      if ((verstab[symidx] & 0x8000) == 0
-		  && (*num_versions)++ == 0)
-		/* No version so far.  */
+	      if ((verstab[symidx] & 0x8000) == 0)
 		*versioned_sym = sym;
 
 	      return NULL;
@@ -380,7 +377,6 @@ do_lookup_x (const char *undef_name, unsigned int new_hash,
 	continue;
 
       Elf_Symndx symidx;
-      int num_versions = 0;
       const ElfW(Sym) *versioned_sym = NULL;
 
       /* The tables for this map.  */
@@ -414,8 +410,7 @@ do_lookup_x (const char *undef_name, unsigned int new_hash,
 			symidx = ELF_MACHINE_HASH_SYMIDX (map, hasharr);
 			sym = check_match (undef_name, ref, version, flags,
 					   type_class, &symtab[symidx], symidx,
-					   strtab, map, &versioned_sym,
-					   &num_versions);
+					   strtab, map, &versioned_sym);
 			if (sym != NULL)
 			  goto found_it;
 		      }
@@ -439,18 +434,17 @@ do_lookup_x (const char *undef_name, unsigned int new_hash,
 	    {
 	      sym = check_match (undef_name, ref, version, flags,
 				 type_class, &symtab[symidx], symidx,
-				 strtab, map, &versioned_sym,
-				 &num_versions);
+				 strtab, map, &versioned_sym);
 	      if (sym != NULL)
 		goto found_it;
 	    }
 	}
 
-      /* If we have seen exactly one versioned symbol while we are
-	 looking for an unversioned symbol and the version is not the
-	 default version we still accept this symbol since there are
-	 no possible ambiguities.  */
-      sym = num_versions == 1 ? versioned_sym : NULL;
+      /* When looking for an unversioned symbol, a default version is a fallback
+	 when VER_NDX_GLOBAL is absent.  We don't repeat the check ensured by
+	 the linker: no two default version can be attached to the same symbol.
+	 */
+      sym = versioned_sym;
 
       if (sym != NULL)
 	{
-- 
2.36.0.464.gb9c8b46e94-goog


                 reply	other threads:[~2022-05-01  2:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220501020643.1538749-1-maskray@google.com \
    --to=maskray@google.com \
    --cc=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).