This came up in our distro build when updating to binutils 2.33 (2.32 was still fine) which then fails building GCC. But it can actually be reproduced by the testcases included in binutils itself, when using both fix-arrata options at the same time: (on an aarch64 system, from a binutils checkout 2.33 branch): % ../configure --disable-gold; make CFLAGS=-g -j8 % cd ld % gcc -c -o bla.o ../../ld/testsuite/ld-aarch64/erratum835769.s % ld bla.o ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078 (i.e. works) % ./ld-new --fix-cortex-a53-835769 --fix-cortex-a53-843419=full bla.o ./ld-new: can not size stub section: invalid operation ./ld-new: warning: cannot find entry symbol _start; defaulting to 0000000000400078 ./ld-new: linker stubs: file class ELFCLASSNONE incompatible with ELFCLASS64 ./ld-new: final link failed: file in wrong format This might be related to the fix for PR24373, as that seems the only relevant change re linker stubs on aarch64 between 2.32 and 2.33. I haven't checked if master has the same problem. I've debugged this a little bit, and the error happens because elf64_aarch64_size_stubs iterates over all input_bfds, and over all sections and tries to determine if it needs the fixes; while doing so it calls (of course) bfd_malloc_and_get_section, which breaks because one of the input bfds doesn't have an iovec. This bfd is precisely the one created for the stubs. So the iteration over all input BFDs is confused when it inspects the stub_bfd for needing stubs. I.e. this patch helps the immediate cause: --- ../../bfd/elfnn-aarch64.c.mm 2019-09-09 13:19:43.000000000 +0000 +++ ../../bfd/elfnn-aarch64.c 2019-11-20 11:44:00.000000000 +0000 @@ -4312,7 +4312,8 @@ elfNN_aarch64_size_stubs (bfd *output_bf for (input_bfd = info->input_bfds; input_bfd != NULL; input_bfd = input_bfd->link.next) - if (!_bfd_aarch64_erratum_835769_scan (input_bfd, info, + if (input_bfd != stub_bfd + && !_bfd_aarch64_erratum_835769_scan (input_bfd, info, &num_erratum_835769_fixes)) return FALSE; @@ -4327,6 +4328,7 @@ elfNN_aarch64_size_stubs (bfd *output_bf for (input_bfd = info->input_bfds; input_bfd != NULL; input_bfd = input_bfd->link.next) + if (input_bfd != stub_bfd) { asection *section; But I'm not sure if this is complete, or the correct place; or if perhaps the check should be based on sections being linker created, though I think the above is better.
FWIW, master still has the same problem and the same patch helps.
> ./ld-new: linker stubs: file class ELFCLASSNONE incompatible with ELFCLASS64 See bfd/elf64ppc.c ppc64_elf_init_stub_bfd. elf64-ppc.c size_stubs avoids looking at the stub bfd by excluding any bfd with symtab_hdr->sh_info zero. No symbols, not even locals, is generally an uninteresting file. Also, I'd say elfNN_aarch64_size_stubs ought to be checking that the input bfds are aarch64-elf.
By bisecting, I found this in fact related to the fix of PR24753 , which introduced an external SEC_LINKER_CREATED flag to the stub section. This change seems bogus (at least not related to the problem reported in PR24753 ).
The master branch has been updated by Tamar Christina <tnfchris@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0db131fb835e4c4f6a024e86743467e7e01c965e commit 0db131fb835e4c4f6a024e86743467e7e01c965e Author: Tamar Christina <tamar.christina@arm.com> Date: Thu Jan 2 14:06:01 2020 +0000 AArch64: Set the correct ELF class for AArch64 stubs (PR/25210) This fixes PR 25210 by specifying the the correct ELF class for AArch64 stubs. After doing this the stub section starts behaving like a normal object file loaded from disk. That is SEC_LINKER_CREATED causes us to have to write the section manually. This flag was added as a fix for PR 24753. I believe that fix to still be correct as linker created sections don't have a size on disk and it fixes the Arm bootstrap regression. But in this case specifying the correct section class also makes the stub section not be considered by compress.c. So I'm partially revert this change so that we don't have to manage the section manually as implied by SEC_LINKER_CREATED. bfd/ChangeLog: PR 25210 PR 24753 * elfnn-aarch64.c (_bfd_aarch64_create_stub_section): Set ELF class. ld/ChangeLog: PR 25210 PR 24753 * emultempl/aarch64elf.em (elf${ELFSIZE}_aarch64_add_stub_section): Remove SEC_LINKER_CREATED. * testsuite/ld-aarch64/aarch64-elf.exp: Add erratum835769-843419. * testsuite/ld-aarch64/erratum835769-843419.d: New test.
The master branch has been updated by Tamar Christina <tnfchris@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8cd0e5e93145699736a370b271ff03f3f41670b0 commit 8cd0e5e93145699736a370b271ff03f3f41670b0 Author: Tamar Christina <tamar.christina@arm.com> Date: Fri Jan 10 13:48:57 2020 +0000 AArch64: Revert setting of elf class in linker stub. This changes the fix to PR 25210 by removing the ELF class change. As it turns out the correct change was only the change in compress.c. Everything else is unneeded and setting the elf class is making the linker behave very oddly under LTO. The first stub is correctly written out but for the rest the suddenly don't have a pointer to the stub section anymore. This caused SPEC to fail as the program would branch to the stub and it wouldn't be filled in. Committed to master under the trivial rule as this is partially reverting a previous commit. bfd/ChangeLog: PR 25210 * elfnn-aarch64.c (_bfd_aarch64_create_stub_section): Remove elfclass.
The binutils-2_33-branch branch has been updated by Tamar Christina <tnfchris@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=69a29b6e0642a98df15e65c0d5acfcb9c9cad2cb commit 69a29b6e0642a98df15e65c0d5acfcb9c9cad2cb Author: Tamar Christina <tamar.christina@arm.com> Date: Thu Jan 2 14:06:01 2020 +0000 AArch64: Revert SEC_LINKER_CREATED for AArch64 stubs (PR/25210) The SEC_LINKER_CREATED flag was added as a fix for PR 24753. I believe that part of the fix in compress.c to still be correct as linker created sections don't have a size on disk and it fixes the Arm bootstrap regression. So I'm partially revert this change so that we don't have to manage the section manually as implied by SEC_LINKER_CREATED as it's causing an error when both errata workarounds are used together and it wasn't needed. This can also be seen from that the arm bootstrap was fixed and no flag was added to it's stubs. ld/ChangeLog: PR 25210 PR 24753 * emultempl/aarch64elf.em (elf${ELFSIZE}_aarch64_add_stub_section): Remove SEC_LINKER_CREATED. * testsuite/ld-aarch64/aarch64-elf.exp: Add erratum835769-843419. * testsuite/ld-aarch64/erratum835769-843419.d: New test. (cherry picked from commit 0db131fb835e4c4f6a024e86743467e7e01c965e) Signed-off-by: Tamar Christina <tamar.christina@arm.com>
Fixed on master and backported