PATCH COMMITTED: Fix weak aliasing bug

Ian Lance Taylor
Wed Apr 9 22:50:00 GMT 2008

I found a tricky weak aliasing bug in gold.  If gold sees the
following sequence:

1) Shared library S1 defines a weak symbol W.
2) Shared library S2 defines a strong symbol S which happens to have
   the same section index and value as W, although it is a different
   shared library.
3) Regular object O, seen after S1 and S2, also defines symbol the
   weak symbol W.

Then it will bring W into the main executable, as it should, but it
will also incorrectly bring S into the main executable as an alias for
W, which is wrong.

This patch fixes the bug, along with a test case.  The test case is
careful to ensure that W and S have the same section and index by
ensuring that the dynamic symbol table and dynamic string table in S1
and S2 are exactly the same length.  The test case also includes
unrelated tests for the correct behaviour of weak aliases.  These were
already working, but it obviously doesn't hurt to test them.


2008-04-09  Ian Lance Taylor  <>

	* (Symbol_table::add_from_dynobj): Only look for weak
	aliases for symbols defined in the same object.
	* testsuite/ (check_PROGRAMS): Add weak_alias_test.
	(weak_alias_test_SOURCES): New variable.
	(weak_alias_test_DEPENDENCIES): New variable.
	(weak_alias_test_LDFLAGS): New variable.
	(weak_alias_test_LDADD): New variable.
	(weak_alias_test_1_pic.o, New targets.
	(weak_alias_test_2_pic.o, New targets.
	(weak_alias_test_3.o): New target.
	(weak_alias_test_4_pic.o, New targets.
	* testsuite/ New file.
	* testsuite/ New file.
	* testsuite/ New file.
	* testsuite/ New file.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-patch
Size: 12346 bytes
Desc: Fix weak aliasing bug
URL: <>

More information about the Binutils mailing list