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.
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 @@
iarch = bed->arch;
imach = 0;
}
- if (!bfd_set_arch_mach (obfd, iarch, imach)
- && (ibfd->target_defaulted
- || bfd_get_arch (ibfd) != bfd_get_arch (obfd)))
+ if (iarch == bfd_arch_unknown
+ && bfd_get_flavour (ibfd) == bfd_target_elf_flavour
+ && ibfd->target_defaulted)
{
- 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 (_("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)
+ && iarch != bfd_arch_unknown)
+ {
+ 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 @@
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"