This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH COMMITTED: Common symbol vs. shared library versioned symbol
- From: Ian Lance Taylor <iant at google dot com>
- To: binutils at sourceware dot org
- Date: Thu, 27 Mar 2008 11:22:24 -0700
- Subject: PATCH COMMITTED: Common symbol vs. shared library versioned symbol
gold had a bug when the main program defined a common symbol which had
the same name as a symbol in a shared library, when common symbol has
no version and the symbol in the shared library had a default version.
(I found this bug by running the gcc testsuite with gold.)
I committed this patch to fix the problem, with a test case.
Ian
2008-03-27 Ian Lance Taylor <iant@google.com>
* symtab.cc (Symbol_table::add_from_object): Handle saw_undefined_
and commons_ correctly when NAME/VERSION does not override
NAME/NULL.
* testsuite/ver_test_6.c: New file.
* testsuite/Makefile.am (check_PROGRAMS): Add ver_test_6
(ver_test_6_SOURCES, ver_test_6_DEPENDENCIES): New variables.
(ver_test_6_LDFLAGS, ver_test_6_LDADD): New variables.
Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.84
diff -p -u -r1.84 symtab.cc
--- symtab.cc 27 Mar 2008 06:11:57 -0000 1.84
+++ symtab.cc 27 Mar 2008 18:16:30 -0000
@@ -584,19 +584,23 @@ Symbol_table::add_from_object(Object* ob
// This is the first time we have seen NAME/VERSION.
gold_assert(ins.first->second == NULL);
- was_undefined = false;
- was_common = false;
-
if (def && !insdef.second)
{
// We already have an entry for NAME/NULL. If we override
// it, then change it to NAME/VERSION.
ret = this->get_sized_symbol<size>(insdef.first->second);
+
+ was_undefined = ret->is_undefined();
+ was_common = ret->is_common();
+
this->resolve(ret, sym, orig_sym, object, version);
ins.first->second = ret;
}
else
{
+ was_undefined = false;
+ was_common = false;
+
Sized_target<size, big_endian>* target =
object->sized_target<size, big_endian>();
if (!target->has_make_symbol())
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.48
diff -p -u -r1.48 Makefile.am
--- testsuite/Makefile.am 27 Mar 2008 06:11:57 -0000 1.48
+++ testsuite/Makefile.am 27 Mar 2008 18:16:30 -0000
@@ -562,6 +562,12 @@ ver_test_5.syms: ver_test_5.so
endif
+check_PROGRAMS += ver_test_6
+ver_test_6_SOURCES = ver_test_6.c
+ver_test_6_DEPENDENCIES = gcctestdir/ld ver_test_2.so
+ver_test_6_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
+ver_test_6_LDADD = ver_test_2.so
+
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_6.c
===================================================================
RCS file: testsuite/ver_test_6.c
diff -N testsuite/ver_test_6.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/ver_test_6.c 27 Mar 2008 18:16:31 -0000
@@ -0,0 +1,33 @@
+/* ver_test_6.c -- test common symbol with shared library 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 is a test of a common symbol in the main program and a
+ versioned symbol in a shared library. The common symbol in the
+ main program should override the shared library symbol. */
+
+int t3_2;
+
+int
+main()
+{
+ return t3_2;
+}