Bug 28848 - [2.38 Regression] ld assertion fail ../../bfd/elf32-arm.c:14807
Summary: [2.38 Regression] ld assertion fail ../../bfd/elf32-arm.c:14807
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.38
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 28859 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-02-01 16:16 UTC by Matthias Klose
Modified: 2024-02-15 04:43 UTC (History)
5 users (show)

See Also:
Host:
Target: arm-linux-gnueabihf
Build:
Last reconfirmed:


Attachments
test case (1.31 MB, application/x-xz)
2022-02-01 16:16 UTC, Matthias Klose
Details
Proposed Patch (430 bytes, patch)
2022-02-10 11:47 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2022-02-01 16:16:21 UTC
Created attachment 13947 [details]
test case

seen when building a arm-linux-gnueabihf cross compiler with the 2.38 branch:

$ ./run.sh 
arm-linux-gnueabihf-ld.bfd: BFD (GNU Binutils for Ubuntu) 2.37.90.20220130 assertion fail ../../bfd/elf32-arm.c:14807

The assertion there says it's still needed. Unsure what changed for 2.38, compared to 2.37.
Comment 1 Nick Clifton 2022-02-02 15:01:33 UTC
Hi Matthias,

The issue, as I understand it, is that crti.o has a Tag_ABI_HardFP attribute set
, but no Tag_FP_arch set.  So this results in the initial output file having the same settings.  Then crtbeginS.o is processed and this has a Tag_FP_arch set but no Tag_ABI_HardFP.  So the assertion is triggered as you have seen.

Assuming that the comment in the code is correct then it looks like the crti.o file might be broken.  Ie it should have both of those tags defined (or neither of them).  Is the file produced from assembler source code or is it compiled ?

Cheers
  Nick
Comment 2 Richard Earnshaw 2022-02-03 11:27:48 UTC
Yes, the attributes on crti.o are not as expected, but the reading process should sanitize them in that case, and if really broken emit a sensible user diagnostic.  It should not generate an assertion failure at the point where it does.

The correct fix, I think, is to convert the value 3 into value zero when reading the input object.  This converts the deprecated value into the expected replacement.
Comment 3 Nick Clifton 2022-02-10 11:47:18 UTC
Created attachment 13968 [details]
Proposed Patch

Hi Richard,

  How about this patch ?

  I was unsure what should be done with the other potential values 
  for Tag_ABI_HardFP_use so I left them alone.

Cheers
  Nick
Comment 4 Nick Clifton 2022-02-10 11:48:02 UTC
*** Bug 28859 has been marked as a duplicate of this bug. ***
Comment 5 Richard Earnshaw 2022-02-10 12:29:23 UTC
(In reply to Nick Clifton from comment #3)
> Created attachment 13968 [details]
> Proposed Patch
> 
> Hi Richard,
> 
>   How about this patch ?
> 
>   I was unsure what should be done with the other potential values 
>   for Tag_ABI_HardFP_use so I left them alone.
> 
> Cheers
>   Nick

I need to think about this a bit.  The object file is arguably buggy in that it says that it uses hw fp, but doesn't say which version.  But if we report an error (or a warning) we probably should do that for all input objects, not just the first on the list.

Also, if we agree the object is buggy, we should probably have code in the assembler to fault that when the object is created.  We should also warn if a deprecated tag value is picked, though I'm a little worried that might cause problems with version skew when used with older GCC releases - but perhaps tsktsk is good enough.
Comment 6 Nick Clifton 2022-02-10 16:43:43 UTC
(In reply to Richard Earnshaw from comment #5)

> I need to think about this a bit.  The object file is arguably buggy in that
> it says that it uses hw fp, but doesn't say which version.  But if we report
> an error (or a warning) we probably should do that for all input objects,
> not just the first on the list.

Given that the value of 3 for Tag_ABI_HardFP_use is deprecated, that would
be reasonable.


> Also, if we agree the object is buggy, we should probably have code in the
> assembler to fault that when the object is created.  We should also warn if
> a deprecated tag value is picked, though I'm a little worried that might
> cause problems with version skew when used with older GCC releases - but
> perhaps tsktsk is good enough.

Fair enough.  The thing that worries me is that the problematic file - crti.o - comes from glibc and is going to affect the building of a lot of projects.  So whilst glibc can be fixed, that will take some time, and in the meantime other peoples projects are stuck.  A solution which will allow builds to complete - even if it means ignoring a warning message from the linker, is probably preferable to triggering an assert.
Comment 7 Richard Earnshaw 2022-02-10 16:45:27 UTC
(In reply to Nick Clifton from comment #6)

> Fair enough.  The thing that worries me is that the problematic file -
> crti.o - comes from glibc and is going to affect the building of a lot of
> projects.  So whilst glibc can be fixed, that will take some time, and in
> the meantime other peoples projects are stuck.  A solution which will allow
> builds to complete - even if it means ignoring a warning message from the
> linker, is probably preferable to triggering an assert.

It doesn't come from glibc, it comes from a debian-local patch to glibc, as I understand it.
Comment 8 Matthias Klose 2022-02-11 13:13:29 UTC
that patch is
https://salsa.debian.org/glibc-team/glibc/-/blob/sid/debian/patches/arm/local-vfp-sysdeps.diff

Michael just confirmed that fpc still fails to build without this patch (and builds with the updated patch as suggested by Richard).
Comment 9 peter green 2022-02-18 00:42:25 UTC
Hi.

I applied the patch proposed by Nick Clifton in Raspbian bookworm, that made glibc build, however I am still getting what I am 99% sure is the the same assertion (the line number has changed, but I'm pretty sure that is a result of the patch altering line numbers in the file) when I try to use fpc to build a program that links against libc.

As I understand it, freepascal uses it's own startup code. For pascal programs that do not link against C libaries there is a pascal only startup code (prt0.o) while for pascal programs that link against C libraies there is a "C and pascal" startup code.

The "C and pascal" startup code is stored in cprt0.o, which is built from cprt0.as there are different versions of that file for different architecture/os combinations, the arm linux one can be found at https://gitlab.com/freepascal.org/fpc/source/-/blob/main/rtl/linux/arm/cprt0.as

What I don't get is why things seem to be working on Debian armhf, at least for native builds, does the different arm version or the fact that Debian armhf uses thumb mode by default make a difference?
Comment 10 H.J. Lu 2022-02-18 13:56:19 UTC
This may be a dup of PR 28903.
Comment 11 peter green 2022-02-19 01:23:34 UTC
Doesn't seem related, this assert relates to arm tags (or the lack thereof), PR 28903 was about an issue on x86-64.
Comment 12 Sourceware Commits 2022-03-01 09:53:15 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit 81c9e0f6c48748f4b66fc3b13e12eb68735cf1f9
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Mar 1 09:51:59 2022 +0000

    Prevent an assertion from being triggered when linking an ARM object file with incorrectly set build attributes.
    
            PR 28848
            PR 28859
            * elf32-arm.c (elf32_arm_merge_eabi_attributes): If the first
            input bfd has a Tag_ABI_HardFP_use set to 3 but does not also have
            TAG_FP_arch set then reset the TAG_ABI_HardFP_use.
Comment 13 Alan Modra 2024-02-15 04:43:57 UTC
I'm assuming this one is fixed by Nick's patch