]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
objcopy "Unable to recognise the format of the input file"
authorAlan Modra <amodra@gmail.com>
Tue, 26 Aug 2025 09:49:44 +0000 (19:19 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 27 Aug 2025 12:15:12 +0000 (21:45 +0930)
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
binutils/testsuite/binutils-all/x86-64/x86-64.exp

index c6fc5082ba770fb8d622940c0c0cf0e22f738dce..a3259f96d354dbfe67f3de5a605e4aa2deb2bfba 100644 (file)
@@ -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;
     }
 
index 6d1b308eca60a393781a7db0ea1de7dbf7a6012d..3c98b03fb7cdf8a079abbd304edcc85471794dd0 100644 (file)
@@ -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"