elf: Don't set version info on unversioned symbols
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 18 Sep 2021 16:12:27 +0000 (09:12 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 19 Sep 2021 14:19:39 +0000 (07:19 -0700)
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.

bfd/elflink.c
ld/testsuite/ld-elf/pr28348.rd [new file with mode: 0644]
ld/testsuite/ld-elf/pr28348.t [new file with mode: 0644]
ld/testsuite/ld-elf/pr28348a.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr28348b.c [new file with mode: 0644]
ld/testsuite/ld-elf/pr28348c.c [new file with mode: 0644]
ld/testsuite/ld-elf/shared.exp

index 77450c8fa8d80d32e60c0e298909a7d5660f1a27..dc38548b23b07a394ef131c34aa2206cd6730562 100644 (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];
diff --git a/ld/testsuite/ld-elf/pr28348.rd b/ld/testsuite/ld-elf/pr28348.rd
new file mode 100644 (file)
index 0000000..6e6ac04
--- /dev/null
@@ -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 (file)
index 0000000..89ea6ef
--- /dev/null
@@ -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 (file)
index 0000000..3d54205
--- /dev/null
@@ -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 (file)
index 0000000..b4aab59
--- /dev/null
@@ -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 (file)
index 0000000..cbb9d56
--- /dev/null
@@ -0,0 +1,8 @@
+extern void foo (void);
+
+int
+main ()
+{
+  foo ();
+  return 0;
+}
index 9224782d234d14dbfab553c232cf5ae9bea864b9..19a8e49c7de2e222d8262a5e5733c933dd5a798c 100644 (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.