lto: Don't add indirect symbols for versioned aliases in IR

Linker adds indirect symbols for versioned symbol aliases, which are
created by ".symver foo, foo@FOO", by checking symbol type, value and
section so that references to foo will be replaced by references to
foo@FOO if foo and foo@FOO have the same symbol type, value and section.
But in IR, since all symbols of the same type have the same value and
section, we can't tell if a symbol is an alias of another symbol by
their types, values and sections.  We shouldn't add indirect symbols
for versioned symbol aliases in IR.

bfd/

	PR ld/30281
	* elflink.c (elf_link_add_object_symbols): Don't add indirect
	symbols for ".symver foo, foo@FOO" aliases in IR.

ld/

	PR ld/30281
	* testsuite/ld-plugin/lto.exp: Add PR ld/30281 test.
	* testsuite/ld-plugin/pr30281.t: New file.
	* testsuite/ld-plugin/pr30281.c: Likewise.
This commit is contained in:
H.J. Lu
2023-03-29 13:06:26 -07:00
parent 5d49758d2c
commit 79cfb928f5
4 changed files with 25 additions and 1 deletions
+8 -1
View File
@@ -5382,7 +5382,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
h->unique_global = (flags & BSF_GNU_UNIQUE) != 0;
}
if (definition && !dynamic)
/* Don't add indirect symbols for .symver x, x@FOO aliases
in IR. Since all data or text symbols in IR have the
same type, value and section, we can't tell if a symbol
is an alias of another symbol by their types, values and
sections. */
if (definition
&& !dynamic
&& (abfd->flags & BFD_PLUGIN) == 0)
{
char *p = strchr (name, ELF_VER_CHR);
if (p != NULL && p[1] != ELF_VER_CHR)
+9
View File
@@ -530,6 +530,15 @@ set lto_link_elf_tests [list \
{} \
"pr29086" \
] \
[list \
"Build pr30281.so" \
"-shared -Wl,--version-script,pr30281.t \
-O2 -fPIC -flto-partition=max -flto=2" \
"-O2 -fPIC -flto-partition=max -flto=2" \
{pr30281.c} \
"" \
"pr30281.so" \
] \
]
# PR 14918 checks that libgcc is not spuriously included in a shared link of
+4
View File
@@ -0,0 +1,4 @@
extern __inline __attribute__((__gnu_inline__)) void foo(void) {}
__attribute__((__symver__("foo@GLIBC_2.2.5")))
int __collector_foo_2_2(void) {}
void foo(void) {}
+4
View File
@@ -0,0 +1,4 @@
GLIBC_2.2.5 {
global:
foo;
};