or1k: Fix issue with plt link failure for local calls
authorStafford Horne <shorne@gmail.com>
Thu, 6 May 2021 11:51:24 +0000 (20:51 +0900)
committerStafford Horne <shorne@gmail.com>
Thu, 6 May 2021 11:51:24 +0000 (20:51 +0900)
When building protobuf we were seeing the assert failure:

    /home/giuliobenetti/git/upstream/or1k-binutils-2.36.1/host/lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld:
    BFD (GNU Binutils) 2.36.1 assertion fail elf32-or1k.c:2377
    /home/giuliobenetti/git/upstream/or1k-binutils-2.36.1/host/lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld:
    BFD (GNU Binutils) 2.36.1 assertion fail elf32-or1k.c:2377
    /home/giuliobenetti/git/upstream/or1k-binutils-2.36.1/host/lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld:
    BFD (GNU Binutils) 2.36.1 assertion fail elf32-or1k.c:2377
    collect2: error: ld returned 1 exit status

This failure happens while writing out PLT entries, there is a check
"BFD_ASSERT (h->dynindx != -1)" to confirm all plt entries have dynamic
symbol attributes.  This was failing for symbols that were
"forced_local" in previous linking code.

The fix adds logic to or1k_elf_adjust_dynamic_symbol to identify
"forced_local" symbols and exclude them from the the PLT.

bfd/ChangeLog:

PR 27624
* elf32-or1k.c (or1k_elf_adjust_dynamic_symbol): Change
condition used to cleanup plt entries to cleanup forced local
entries.

Cc: Giulio Benetti <giulio.benetti@benettiengineering.com>
bfd/ChangeLog
bfd/elf32-or1k.c

index e481c1b0a25e363bb30c0d7b6efed107d9099f43..7a6b9a14422b40b904737232297dd090eda0bb99 100644 (file)
@@ -1,3 +1,10 @@
+2021-05-06  Stafford Horne  <shorne@gmail.com>
+
+       PR 27624
+       * elf32-or1k.c (or1k_elf_adjust_dynamic_symbol): Change
+       condition used to cleanup plt entries to cleanup forced local
+       entries.
+
 2021-05-05  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/27825
index 013deb406f89ed347b28d61ab9df230ed7726f6a..cc6c51220e502de6f317363050b6e298ed227e3e 100644 (file)
@@ -2566,11 +2566,10 @@ or1k_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   if (h->type == STT_FUNC
       || h->needs_plt)
     {
-      if (! bfd_link_pic (info)
-         && !h->def_dynamic
-         && !h->ref_dynamic
-         && h->root.type != bfd_link_hash_undefweak
-         && h->root.type != bfd_link_hash_undefined)
+      if (h->plt.refcount <= 0
+         || (SYMBOL_CALLS_LOCAL (info, h)
+         || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+             && h->root.type == bfd_link_hash_undefweak)))
        {
          /* This case can occur if we saw a PLT reloc in an input
             file, but the symbol was never referred to by a dynamic