This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

gold patch committed: Check version in archive maps


Symbols in object files may have versions appended with an '@'
character.  It follows that this may happen in symbols in archive maps.
The GNU linker checks for that possibility in
_bfd_elf_archive_symbol_lookup in elflink.c.  I committed this patch to
gold to add support for this, along with a test case.

Ian


2009-03-17  Ian Lance Taylor  <iant@google.com>

	* archive.cc (Archive::add_symbols): Check for a version attached
	to the symbol name in the archive map.
	* testsuite/Makefile.am (check_PROGRAMS): Add ver_test_11.
	(ver_test_11_SOURCES, ver_test_11_DEPENDENCIES): Define.
	(ver_test_11_LDFLAGS, ver_test_11_LDADD): Define.
	(ver_test_11.a): New target.
	* testsuite/Makefile.in: Rebuild.


Index: archive.cc
===================================================================
RCS file: /cvs/src/src/gold/archive.cc,v
retrieving revision 1.41
diff -p -u -r1.41 archive.cc
--- archive.cc	14 Mar 2009 05:56:46 -0000	1.41
+++ archive.cc	18 Mar 2009 05:07:25 -0000
@@ -635,6 +635,8 @@ Archive::add_symbols(Symbol_table* symta
   // Track which symbols in the symbol table we've already found to be
   // defined.
 
+  char* tmpbuf = NULL;
+  size_t tmpbuflen = 0;
   bool added_new_object;
   do
     {
@@ -658,7 +660,40 @@ Archive::add_symbols(Symbol_table* symta
 
 	  const char* sym_name = (this->armap_names_.data()
 				  + this->armap_[i].name_offset);
-	  Symbol* sym = symtab->lookup(sym_name);
+
+	  // In an object file, and therefore in an archive map, an
+	  // '@' in the name separates the symbol name from the
+	  // version name.  If there are two '@' characters, this is
+	  // the default version.
+	  const char* ver = strchr(sym_name, '@');
+	  bool def = false;
+	  if (ver != NULL)
+	    {
+	      size_t symlen = ver - sym_name;
+	      if (symlen + 1 > tmpbuflen)
+		{
+		  tmpbuf = static_cast<char*>(realloc(tmpbuf, symlen + 1));
+		  tmpbuflen = symlen + 1;
+		}
+	      memcpy(tmpbuf, sym_name, symlen);
+	      tmpbuf[symlen] = '\0';
+	      sym_name = tmpbuf;
+
+	      ++ver;
+	      if (*ver == '@')
+		{
+		  ++ver;
+		  def = true;
+		}
+	    }
+
+	  Symbol* sym = symtab->lookup(sym_name, ver);
+	  if (def
+	      && (sym == NULL
+		  || !sym->is_undefined()
+		  || sym->binding() == elfcpp::STB_WEAK))
+	    sym = symtab->lookup(sym_name, NULL);
+
 	  if (sym == NULL)
 	    {
 	      // Check whether the symbol was named in a -u option.
@@ -687,13 +722,20 @@ Archive::add_symbols(Symbol_table* symta
 	  if (!this->include_member(symtab, layout, input_objects,
 				    last_seen_offset, mapfile, sym,
 				    why.c_str()))
-	    return false;
+	    {
+	      if (tmpbuf != NULL)
+		free(tmpbuf);
+	      return false;
+	    }
 
 	  added_new_object = true;
 	}
     }
   while (added_new_object);
 
+  if (tmpbuf != NULL)
+    free(tmpbuf);
+
   input_objects->archive_stop(this);
 
   return true;
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.86
diff -p -u -r1.86 Makefile.am
--- testsuite/Makefile.am	4 Mar 2009 06:46:27 -0000	1.86
+++ testsuite/Makefile.am	18 Mar 2009 05:07:26 -0000
@@ -819,6 +819,14 @@ ver_test_10.syms: ver_test_10.so
 ver_test_10.so: gcctestdir/ld ver_test_2.o ver_test_10.script
 	$(CXXLINK) -Bgcctestdir/ -shared -Wl,--version-script,$(srcdir)/ver_test_10.script ver_test_2.o
 
+check_PROGRAMS += ver_test_11
+ver_test_11_SOURCES = ver_test_main_2.cc
+ver_test_11_DEPENDENCIES = gcctestdir/ld ver_test_11.a
+ver_test_11_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
+ver_test_11_LDADD = ver_test_11.a
+ver_test_11.a: ver_test_1.o ver_test_2.o ver_test_4.o
+	$(TEST_AR) rc $@ $^
+
 check_PROGRAMS += protected_1
 protected_1_SOURCES = \
 	protected_main_1.cc protected_main_2.cc protected_main_3.cc

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