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]

Re: A patch for default version and archive


On Wed, Nov 08, 2000 at 11:23:06AM -0800, H . J . Lu wrote:
> 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.
> 

My last patch has a typo. It should be strcpy, not strcat.


H.J.
---
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 21:32:54
@@ -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);
+	      strcpy (&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);
 	    }

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