public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Remove one-default-version check when searching an unversioned symbol
@ 2022-05-01  2:06 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2022-05-01  2:06 UTC (permalink / raw)
  To: libc-alpha, Florian Weimer

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-01  2:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-01  2:06 [PATCH] elf: Remove one-default-version check when searching an unversioned symbol Fangrui Song

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