gold: Properly remove the versioned symbol

When the versioned symbol foo is removed from the shared library,  the
".symver foo,foo@VER" directive provides binary compatibility for foo@VER.
In this case, the unversioned symbol foo should be hidden and shouldn't
generate a multiple definition error.

	PR gold/31830
	* resolve.cc (Symbol_table::resolve): Move symbol version handling
	to ...
	* symtab.cc (Symbol_table::add_from_object): Here. If the hidden
	version from .symver is the same as the default version from the
	unversioned symbol, don't make the unversioned symbol the default
	versioned
	symbol.
	* testsuite/Makefile.am (check_SCRIPTS): Add ver_test_pr31830.sh.
	(check_DATA): ver_test_pr31830_a.syms and ver_test_pr31830_b.syms.
	(ver_test_pr31830_a.syms): New.
	(ver_test_pr31830_b.syms): Likewise.
	(ver_test_pr31830_a.so): Likewise.
	(ver_test_pr31830_b.so): Likewise.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/ver_test_pr31830.script: New file.
	* testsuite/ver_test_pr31830.sh: Likewise.
	* testsuite/ver_test_pr31830_a.c: Likewise.
	* testsuite/ver_test_pr31830_b.c: Likewise.
	* testsuite/ver_test_pr31830_lto.c: Likewise.
	* testsuite/ver_test_pr31830_lto.sh: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
This commit is contained in:
H.J. Lu
2024-05-31 21:30:34 -07:00
parent 2b05f93448
commit 89d801850a
10 changed files with 261 additions and 25 deletions

View File

@@ -250,20 +250,6 @@ Symbol_table::resolve(Sized_symbol<size>* to,
bool to_is_ordinary;
const unsigned int to_shndx = to->shndx(&to_is_ordinary);
// It's possible for a symbol to be defined in an object file
// using .symver to give it a version, and for there to also be
// a linker script giving that symbol the same version. We
// don't want to give a multiple-definition error for this
// harmless redefinition.
if (to->source() == Symbol::FROM_OBJECT
&& to->object() == object
&& to->is_defined()
&& is_ordinary
&& to_is_ordinary
&& to_shndx == st_shndx
&& to->value() == sym.get_st_value())
return;
// Likewise for an absolute symbol defined twice with the same value.
if (!is_ordinary
&& st_shndx == elfcpp::SHN_ABS