Bug 27624 - OpenRisc BFD (GNU Binutils) 2.36.1 assertion fail elf32-or1k.c:2377
Summary: OpenRisc BFD (GNU Binutils) 2.36.1 assertion fail elf32-or1k.c:2377
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: ---
Assignee: Stafford Horne
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-22 15:52 UTC by Giulio Benetti
Modified: 2022-06-22 06:31 UTC (History)
1 user (show)

See Also:
Host:
Target: or1k-*-*
Build:
Last reconfirmed: 2021-03-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giulio Benetti 2021-03-22 15:52:38 UTC
this bug still shows up with binutils 2.36.1 like:
/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

To reproduce it:
# git clone git://git.busybox.net/buildroot
# wget https://git.busybox.net/buildroot-test/tree/utils/br-reproduce-build

- modify BASE_GIT=... with your buildroot path in br-reproduce-build then:
# chmod a+x br-reproduce-build
# ./br-reproduce-build 6c87be004adf03955c832be72c0c59749f311f71

And I still can't find a workaround.

By mistake I've confused this bug with bug 21464:
https://sourceware.org/bugzilla/show_bug.cgi?id=21464

And this bug is fixed by Stafford Horne suggestion:
'''
diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index 38406eda3d6..f1cfed230a1 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -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

--
'''
Comment 1 Stafford Horne 2021-03-22 20:54:32 UTC
I confirm this is an issue, I will submit my patch to the list for review.  So far with my testing it works.
Comment 2 Sourceware Commits 2021-05-06 11:52:54 UTC
The or1k-large-fixes branch has been updated by Stafford Horne <shorne@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a76ef689b60405e494cb99e198acf3c82f467f7d

commit a76ef689b60405e494cb99e198acf3c82f467f7d
Author: Stafford Horne <shorne@gmail.com>
Date:   Thu May 6 20:51:24 2021 +0900

    or1k: Fix issue with plt link failure for local calls
    
    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>
Comment 3 Sourceware Commits 2021-05-06 11:53:40 UTC
The master branch has been updated by Stafford Horne <shorne@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a76ef689b60405e494cb99e198acf3c82f467f7d

commit a76ef689b60405e494cb99e198acf3c82f467f7d
Author: Stafford Horne <shorne@gmail.com>
Date:   Thu May 6 20:51:24 2021 +0900

    or1k: Fix issue with plt link failure for local calls
    
    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>
Comment 4 Stafford Horne 2021-05-06 20:25:44 UTC
The latest commit comment should have fixed this.