From 3fa891a80c5faba051afb0e6607f6b347bf61f9a Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 26 Aug 2025 19:19:44 +0930 Subject: objcopy "Unable to recognise the format of the input file" This bogus error comes up when trying something like objcopy -O binary .../binutils/testsuite/binutils-all/tek2.obj xxx This is an annoying message, as HJ said in https://sourceware.org/pipermail/binutils/2002-August/021354.html and removed it for some cases, eg. I can make it go away by specifying -I tekhex. The message is also untrue, as objcopy does in fact know the format of the input file. I think the message should be limited to ELF input files that are being handled by the elf64-little, elf64-big, elf32-little or elf32-big targets, due to libbfd being compiled with limited target support. I'm also changing the message a litle. * objcopy.c (copy_object): Change "Unable to recognise format" message to "Unable to recognise architecture" and only report this error for ELF objects lacking their proper target support. * testsuite/binutils-all/x86-64/x86-64.exp: Update to suit. --- binutils/objcopy.c | 21 ++++++++++++--------- binutils/testsuite/binutils-all/x86-64/x86-64.exp | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/binutils/objcopy.c b/binutils/objcopy.c index c6fc508..a3259f9 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -2804,17 +2804,20 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) iarch = bed->arch; imach = 0; } + if (iarch == bfd_arch_unknown + && bfd_get_flavour (ibfd) == bfd_target_elf_flavour + && ibfd->target_defaulted) + { + non_fatal (_("Unable to recognise the architecture of the input file `%s'"), + bfd_get_archive_filename (ibfd)); + return false; + } if (!bfd_set_arch_mach (obfd, iarch, imach) - && (ibfd->target_defaulted - || bfd_get_arch (ibfd) != bfd_get_arch (obfd))) + && iarch != bfd_arch_unknown) { - if (bfd_get_arch (ibfd) == bfd_arch_unknown) - non_fatal (_("Unable to recognise the format of the input file `%s'"), - bfd_get_archive_filename (ibfd)); - else - non_fatal (_("Output file cannot represent architecture `%s'"), - bfd_printable_arch_mach (bfd_get_arch (ibfd), - bfd_get_mach (ibfd))); + non_fatal (_("Output file cannot represent architecture `%s'"), + bfd_printable_arch_mach (bfd_get_arch (ibfd), + bfd_get_mach (ibfd))); return false; } diff --git a/binutils/testsuite/binutils-all/x86-64/x86-64.exp b/binutils/testsuite/binutils-all/x86-64/x86-64.exp index 6d1b308..3c98b03 100644 --- a/binutils/testsuite/binutils-all/x86-64/x86-64.exp +++ b/binutils/testsuite/binutils-all/x86-64/x86-64.exp @@ -295,7 +295,7 @@ proc run_pr33230_test { testname obj strip_flags run_readelf } { fail "$testname (${obj}.strip)" return } - } elseif { ![regexp "Unable to recognise the format" $got] } then { + } elseif { ![regexp "Unable to recognise the architecture" $got] } then { send_log "$got\n" verbose "$got" 1 fail "$testname" -- cgit v1.1