This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

A patch for default version and archive


When we have default version in an archive, we fail to resolve the
reference with only one `@':

# make
gcc  -O   -c -o test.o test.c
gcc  -O   -c -o foo.o foo.c
gcc  -o test1 test.o foo.o
ar rv libfoo.a foo.o
r - foo.o
gcc  -o test2 test.o libfoo.a
test.o: In function `main':
test.o(.text+0x7): undefined reference to `foo@GLIBC_2.0'
collect2: ld returned 1 exit status

I am enclosing a patch and a testcae here.


-- 
H.J. Lu (hjl@gnu.org)
---
2000-11-08  H.J. Lu  <hjl@gnu.org>

	* elflink.h (elf_link_add_archive_symbols): For the default
	version, check references with only one `@' first.

Index: elflink.h
===================================================================
RCS file: /work/cvs/gnu/binutils/bfd/elflink.h,v
retrieving revision 1.45
diff -u -p -r1.45 elflink.h
--- elflink.h	2000/10/15 01:08:18	1.45
+++ elflink.h	2000/11/08 19:12:01
@@ -308,23 +308,35 @@ elf_link_add_archive_symbols (abfd, info
 	      char *p, *copy;
 
 	      /* If this is a default version (the name contains @@),
-		 look up the symbol again without the version.  The
-		 effect is that references to the symbol without the
-		 version will be matched by the default symbol in the
-		 archive.  */
+		 look up the symbol again with only one `@' as well
+		 as without the version.  The effect is that references
+		 to the symbol with and without the version will be
+		 matched by the default symbol in the archive.  */
 
 	      p = strchr (symdef->name, ELF_VER_CHR);
 	      if (p == NULL || p[1] != ELF_VER_CHR)
 		continue;
 
-	      copy = bfd_alloc (abfd, p - symdef->name + 1);
+	      /* First check with only one `@'.  */
+	      copy = bfd_alloc (abfd, strlen (symdef->name));
 	      if (copy == NULL)
 		goto error_return;
-	      memcpy (copy, symdef->name, p - symdef->name);
-	      copy[p - symdef->name] = '\0';
+	      memcpy (copy, symdef->name, p - symdef->name + 1);
+	      strcat (&copy [p - symdef->name + 1],
+		      &symdef->name [p - symdef->name + 2]);
 
 	      h = elf_link_hash_lookup (elf_hash_table (info), copy,
 					false, false, false);
+
+	      if (h == NULL)
+	        {
+		  /* We also need to check references to the symbol
+		     without the version.  */
+
+		  copy[p - symdef->name] = '\0';
+		  h = elf_link_hash_lookup (elf_hash_table (info),
+					    copy, false, false, false);
+		}
 
 	      bfd_release (abfd, copy);
 	    }

archive.tar.gz


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]