elf: Don't set version info on unversioned symbols

Don't set version info on unversioned symbols when seeing a hidden
versioned symbol after an unversioned definition and the default
versioned symbol.

bfd/

	PR ld/28348
	* elflink.c (elf_link_add_object_symbols): Don't set version info
	on unversioned symbols.

ld/

	PR ld/28348
	* testsuite/ld-elf/pr28348.rd: New file.
	* testsuite/ld-elf/pr28348.t: Likewise.
	* testsuite/ld-elf/pr28348a.c: Likewise.
	* testsuite/ld-elf/pr28348b.c: Likewise.
	* testsuite/ld-elf/pr28348c.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run PR ld/28348 tests.
This commit is contained in:
H.J. Lu 2021-09-18 09:12:27 -07:00
parent 034ce7b42a
commit e4675a5810
7 changed files with 73 additions and 1 deletions

View File

@ -4987,7 +4987,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
|| h->root.type == bfd_link_hash_warning)
h = (struct elf_link_hash_entry *) h->root.u.i.link;
if (elf_tdata (abfd)->verdef != NULL
if (h->versioned != unversioned
&& elf_tdata (abfd)->verdef != NULL
&& vernum > 1
&& definition)
h->verinfo.verdef = &elf_tdata (abfd)->verdef[vernum - 1];

View File

@ -0,0 +1,8 @@
#ld: -shared
#readelf: --dyn-syms --wide
#target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
#xfail: ![check_shared_lib_support]
#...
+[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +FUNC +WEAK +DEFAULT (\[NOPV\]|) +[0-9]+ +_?foo
#pass

View File

@ -0,0 +1,6 @@
VERS_2.0 {
global:
foo; bar;
local:
*;
};

View File

@ -0,0 +1,5 @@
__attribute__ ((weak))
void
foo (void)
{
}

View File

@ -0,0 +1,5 @@
void
foo (void)
{
}
asm (".symver foo,foo@VERS_2.0");

View File

@ -0,0 +1,8 @@
extern void foo (void);
int
main ()
{
foo ();
return 0;
}

View File

@ -868,6 +868,45 @@ run_cc_link_tests [list \
{} \
"pr26590" \
] \
[list \
"Build libpr28348a.so" \
"-shared -Wl,--version-script=pr28348.t" \
"-fPIC" \
{pr28348a.c} \
{} \
"libpr28348a.so" \
] \
[list \
"Build pr28348b.o" \
"" \
"-fPIC" \
{pr28348b.c} \
] \
[list \
"Build pr28348c.o" \
"" \
"" \
{pr28348c.c} \
] \
[list \
"Build libpr28348b.so" \
"-shared -Wl,--version-script=pr28348.t \
-Wl,--no-as-needed tmpdir/pr28348b.o tmpdir/libpr28348a.so" \
"-fPIC" \
{dummy.c} \
{} \
"libpr28348b.so" \
] \
[list \
"Build pr28348" \
"-Wl,--no-as-needed tmpdir/pr28348c.o \
tmpdir/pr28348a.o tmpdir/libpr28348a.so tmpdir/libpr28348b.so \
tmpdir/libpr28348a.so" \
"" \
{dummy.c} \
{{readelf {--dyn-syms --wide} pr28348.rd}} \
"pr28348" \
] \
]
# pr19073.s uses .set, which has a different meaning on alpha.