From: H.J. Lu Date: Sat, 18 Sep 2021 16:12:27 +0000 (-0700) Subject: elf: Don't set version info on unversioned symbols X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e4675a5810fc3d0a7d0b1c744f0a1837ccc0507e;p=binutils-gdb.git 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. --- diff --git a/bfd/elflink.c b/bfd/elflink.c index 77450c8fa8d..dc38548b23b 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -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]; diff --git a/ld/testsuite/ld-elf/pr28348.rd b/ld/testsuite/ld-elf/pr28348.rd new file mode 100644 index 00000000000..6e6ac042498 --- /dev/null +++ b/ld/testsuite/ld-elf/pr28348.rd @@ -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 diff --git a/ld/testsuite/ld-elf/pr28348.t b/ld/testsuite/ld-elf/pr28348.t new file mode 100644 index 00000000000..89ea6ef3275 --- /dev/null +++ b/ld/testsuite/ld-elf/pr28348.t @@ -0,0 +1,6 @@ +VERS_2.0 { +global: + foo; bar; +local: + *; +}; diff --git a/ld/testsuite/ld-elf/pr28348a.c b/ld/testsuite/ld-elf/pr28348a.c new file mode 100644 index 00000000000..3d54205ea4d --- /dev/null +++ b/ld/testsuite/ld-elf/pr28348a.c @@ -0,0 +1,5 @@ +__attribute__ ((weak)) +void +foo (void) +{ +} diff --git a/ld/testsuite/ld-elf/pr28348b.c b/ld/testsuite/ld-elf/pr28348b.c new file mode 100644 index 00000000000..b4aab592743 --- /dev/null +++ b/ld/testsuite/ld-elf/pr28348b.c @@ -0,0 +1,5 @@ +void +foo (void) +{ +} +asm (".symver foo,foo@VERS_2.0"); diff --git a/ld/testsuite/ld-elf/pr28348c.c b/ld/testsuite/ld-elf/pr28348c.c new file mode 100644 index 00000000000..cbb9d564d63 --- /dev/null +++ b/ld/testsuite/ld-elf/pr28348c.c @@ -0,0 +1,8 @@ +extern void foo (void); + +int +main () +{ + foo (); + return 0; +} diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index 9224782d234..19a8e49c7de 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -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.