bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/29649] New: ld: Insufficient checking that BFD backend is suitab


From: acoplan at gcc dot gnu.org
Subject: [Bug ld/29649] New: ld: Insufficient checking that BFD backend is suitable for ld emulation on aarch64
Date: Mon, 03 Oct 2022 17:02:46 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=29649

            Bug ID: 29649
           Summary: ld: Insufficient checking that BFD backend is suitable
                    for ld emulation on aarch64
           Product: binutils
           Version: 2.40 (HEAD)
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

Configuring with --target=aarch64-none-elf --enable-targets=all --disable-gdb,
I see:

$ cat t.s
.global _start
_start:
nop
$ gas/as-new t.s -o t.o
$ ld/ld-new t.o --oformat pei-aarch64-little
ld/ld-new: BFD (GNU Binutils) 2.39.50.20221003 assertion fail
elfnn-aarch64.c:4829

The assertion failing here is:

BFD_ASSERT (is_aarch64_elf (output_bfd));

the problem is we call the AArch64 ELF backend function
bfd_elfNN_aarch64_set_options from the emulation hook
aarch64_elf_create_output_section_statements, but the actual BFD backend in use
for the output BFD is the pei-aarch64-little backend.

I think we need to be stricter about ensuring we only allow valid combinations
of BFD backend and ld emulation. If we instead set the BFD backend to
mach-o-arm64, we reject it with this error:

$ ld/ld-new t.o --oformat mach-o-arm64
ld/ld-new: error: cannot change output format whilst linking AArch64 binaries

but it seems this is only by accident, since the check that handles this is
looking specifically for the string "aarch64" in the BFD target, but this
target uses "arm64" instead. The check in ld/emultempl/aarch64elf.em is:

/* This is a convenient point to tell BFD about target specific flags.
   After the output has been created, but before inputs are read.  */
static void
aarch64_elf_create_output_section_statements (void)
{
  if (strstr (bfd_get_target (link_info.output_bfd), "aarch64") == NULL)
    {
      /* The arm backend needs special fields in the output hash structure.
         These will only be created if the output format is an arm format,
         hence we do not support linking and changing output formats at the
         same time.  Use a link followed by objcopy to change output formats. 
*/
      einfo (_("%F%P: error: cannot change output format "
               "whilst linking %s binaries\n"), "AArch64");
      return;
    }

Overall it seems we need to tidy up how non-ELF object formats are handled on
AArch64 (specifically the relationship between ld emulations and BFD backends).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]