Friday, December 21, 2018

Re: qtbase-5.9.6p1 fails to build on -stable/loongson

Jeremie Courreges-Anglas writes:

> On Wed, Dec 19 2018, Xiyue Deng <manphiz@gmail.com> wrote:
>> Xiyue Deng writes:
>>
>>> Hi,
>>>
>>> As title suggests, qtbase on -stable fails to build. Relevant part from
>>> build log:
>>>
>>> /usr/bin/ld: BFD 2.17 assertion fail /usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-mips.c:2254
>>> /usr/bin/ld: BFD 2.17 internal error, aborting at /usr/src/gnu/usr.bin/binutils-2.17/bfd/reloc.c line 445 in bfd_get_reloc_size
>>>
>>> /usr/bin/ld: Please report this bug.
>>>
>>> clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
>>>
>>> Full build log is also attached. Please advice on how to fix. Thanks!
>>
>> Hi,
>>
>> Any updates on this issue?
>
> Your initial mail was two/three days ago. I would not expect someone to
> jump on obscure binutils problems on a non-mainstream arch. ;)
>
> Now, you got me curious. Tentative analysis below, take with a grain of
> salt.
>
> Here's the code at
> /usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-mips.c:2254:
> --8<--
> /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */
>
> static reloc_howto_type *
> mips_elf64_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p)
> {
> switch (r_type)
> {
> case R_MIPS_GNU_VTINHERIT:
> return &elf_mips_gnu_vtinherit_howto;
> case R_MIPS_GNU_VTENTRY:
> return &elf_mips_gnu_vtentry_howto;
> case R_MIPS_GNU_REL16_S2:
> if (rela_p)
> return &elf_mips_gnu_rela16_s2;
> else
> return &elf_mips_gnu_rel16_s2;
> default:
> if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
> {
> if (rela_p)
> return &mips16_elf64_howto_table_rela[r_type - R_MIPS16_min];
> else
> return &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
> }
> BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
> if (rela_p)
> return &mips_elf64_howto_table_rela[r_type];
> else
> return &mips_elf64_howto_table_rel[r_type];
> break;
> }
> }
> -->8--
>
> As far as binutils-2.17 know, R_MIPS_max is 51:
>
> include/elf/mips.h
> 90: FAKE_RELOC (R_MIPS_max, 51)
>
> But llvm/clang adds support for additional relocation types, at least:
> --8<--
> ELF_RELOC(R_MIPS_PC21_S2, 60)
> ELF_RELOC(R_MIPS_PC26_S2, 61)
> ELF_RELOC(R_MIPS_PC18_S3, 62)
> ELF_RELOC(R_MIPS_PC19_S2, 63)
> ELF_RELOC(R_MIPS_PCHI16, 64)
> ELF_RELOC(R_MIPS_PCLO16, 65)
> -->8--
> listed in /usr/src/gnu/llvm/include/llvm/BinaryFormat/ELFRelocs/Mips.def
> for base clang.
>
> To make llvm more useful on mips64 one should either try to somehow
> avoid using those relocations, or add support for those relocations to
> binutils-2.17.
>
> You could try applying this diff to see which relocation triggers the
> assert.
>
> My two cents,
>
>
> Index: elf64-mips.c
> ===================================================================
> RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/bfd/elf64-mips.c,v
> retrieving revision 1.1.1.1
> diff -u -p -p -u -r1.1.1.1 elf64-mips.c
> --- elf64-mips.c 24 Apr 2011 20:14:42 -0000 1.1.1.1
> +++ elf64-mips.c 19 Dec 2018 17:22:29 -0000
> @@ -2252,6 +2252,8 @@ mips_elf64_rtype_to_howto (unsigned int
> return &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
> }
> BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
> + if (!(r_type < (unsigned int) R_MIPS_max))
> + fprintf(stderr, "BFD:%s: relocation type %u\n", __func__, r_type);
> if (rela_p)
> return &mips_elf64_howto_table_rela[r_type];
> else

With the patch from Jeremie applied, the error message shows exact type
of relocation:


--8<--
/usr/bin/ld: BFD 2.17 assertion fail /usr/src/gnu/usr.bin/binutils-2.17/bfd/elf64-mips.c:2254
BFD:mips_elf64_rtype_to_howto: relocation type 248
/usr/bin/ld: BFD 2.17 internal error, aborting at /usr/src/gnu/usr.bin/binutils-2.17/bfd/reloc.c line 445 in bfd_get_reloc_size

/usr/bin/ld: Please report this bug.

clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
-->8--

Hope this is helpful for MIPS people to properly fix this.

--
manphiz

No comments:

Post a Comment