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]

PATCH COMMITTED: Fix gold bug accidentally unhiding version


While investigating a g++ testsuite failure, I discovered that gold
was incorrectly emitting some symbols with a visible version which
should have been hidden.  This turned out to happen when there was an
object which defined versions for a symbol using .symver, and the
versions also appeared in a version script, and there was a later
object in the link which defined the symbol again, this time without a
version.  The second definition had to be weak, to avoid a multiple
definition error.  In this case the second definition picked up a
version from the version script, and then incorrectly wound up making
that version be globally visible even though the weak symbol was not
used.

This patch fixes the problem, and adds a test case for it.

Ian


2008-03-29  Ian Lance Taylor  <iant@google.com>

	* symtab.cc (Symbol_table::add_from_object): If we don't use the
	new symbol when resolving, don't call set_is_default.
	* testsuite/ver_test_7.cc: New file.
	* testsuite/ver_test_7.sh: New file.
	* testsuite/Makefile.am (ver_test_7.so): New target.
	(ver_test_7.o): New target.
	(check_SCRIPTS): Add ver_test_7.sh.
	(check_DATA): Add ver_test_7.syms.
	(ver_test_7.syms): New target.


Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.85
diff -p -u -r1.85 symtab.cc
--- symtab.cc	27 Mar 2008 18:19:09 -0000	1.85
+++ symtab.cc	29 Mar 2008 07:12:47 -0000
@@ -577,6 +577,8 @@ Symbol_table::add_from_object(Object* ob
 	      this->make_forwarder(insdef.first->second, ret);
 	      insdef.first->second = ret;
 	    }
+	  else
+	    def = false;
 	}
     }
   else
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.51
diff -p -u -r1.51 Makefile.am
--- testsuite/Makefile.am	28 Mar 2008 22:42:34 -0000	1.51
+++ testsuite/Makefile.am	29 Mar 2008 07:12:47 -0000
@@ -582,6 +582,19 @@ ver_test_6_DEPENDENCIES = gcctestdir/ld 
 ver_test_6_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
 ver_test_6_LDADD = ver_test_2.so
 
+if READELF
+
+ver_test_7.so: ver_test_4.o $(srcdir)/ver_test_4.script ver_test_7.o gcctestdir/ld
+	$(CXXLINK) -Bgcctestdir/ -shared -Wl,--version-script,$(srcdir)/ver_test_4.script ver_test_4.o ver_test_7.o
+ver_test_7.o: ver_test_7.cc
+	$(CXXCOMPILE) -c -fpic -o $@ $<
+check_SCRIPTS += ver_test_7.sh
+check_DATA += ver_test_7.syms
+ver_test_7.syms: ver_test_7.so
+	readelf -s $< >$@ 2>/dev/null
+
+endif
+
 check_PROGRAMS += script_test_1
 script_test_1_SOURCES = script_test_1.cc
 script_test_1_DEPENDENCIES = gcctestdir/ld script_test_1.t
Index: testsuite/ver_test_7.cc
===================================================================
RCS file: testsuite/ver_test_7.cc
diff -N testsuite/ver_test_7.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/ver_test_7.cc	29 Mar 2008 07:12:48 -0000
@@ -0,0 +1,37 @@
+// ver_test_7.cc -- test weak duplicate symbol with version
+
+// Copyright 2008 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+#include "ver_test.h"
+
+// This tests having a weak symbol which matches an entry in the
+// version script following a hidden definition from .symver.  There
+// was a bug in which the weak symbol would cause the earlier symbol
+// to become globally visible when it should have been hidden.
+
+extern "C" int t2_2() __attribute__ ((weak));
+
+extern "C"
+int
+t2_2()
+{
+  return 23;
+}
Index: testsuite/ver_test_7.sh
===================================================================
RCS file: testsuite/ver_test_7.sh
diff -N testsuite/ver_test_7.sh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/ver_test_7.sh	29 Mar 2008 07:12:48 -0000
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# ver_test_7.sh -- test that symbol has correct version
+
+# Copyright 2008 Free Software Foundation, Inc.
+# Written by Ian Lance Taylor <iant@google.com>.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+# This file goes with ver_test_4.script and ver_test_5.script.  The
+# symbol t2_2 is not defined when ver_test_5.script is used.
+
+check()
+{
+    if ! grep -q "$2" "$1"
+    then
+	echo "Did not find expected symbol in $1:"
+	echo "   $2"
+	echo ""
+	echo "Actual output below:"
+	cat "$1"
+	exit 1
+    fi
+}
+
+check ver_test_7.syms "t2_2@@VER2"
+check ver_test_7.syms "t2_2@VER1"
+
+exit 0

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