[binutils-gdb] objcopy: when an invalid bfd target string is used as a target option, print an error message that r

Nick Clifton nickc@sourceware.org
Tue Sep 9 07:58:32 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3ac272c1f115da7bfbb872bf7ad9aa72f42e0c01

commit 3ac272c1f115da7bfbb872bf7ad9aa72f42e0c01
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Sep 9 08:57:38 2025 +0100

    objcopy: when an invalid bfd target string is used as a target option, print an error message that references the target string, not the file being copied

Diff:
---
 binutils/objcopy.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index a3259f96d35..3c1bcf622ff 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3876,7 +3876,10 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
   ibfd = bfd_openr (input_filename, target);
   if (ibfd == NULL || bfd_stat (ibfd, in_stat) != 0)
     {
-      bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
+      if (bfd_get_error () == bfd_error_invalid_target && target != NULL)
+	bfd_nonfatal_message (target, NULL, NULL, NULL);
+      else
+	bfd_nonfatal_message (input_filename, NULL, NULL, NULL);
       if (ibfd != NULL)
 	bfd_close (ibfd);
       status = 1;
@@ -3951,7 +3954,10 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
 	{
 	  if (ofd >= 0)
 	    close (ofd);
-	  bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
+	  if (force_output_target && bfd_get_error () == bfd_error_invalid_target)
+	    bfd_nonfatal_message (output_target, NULL, NULL, NULL);
+	  else
+	    bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
 	  bfd_close (ibfd);
 	  status = 1;
 	  return;
@@ -4036,7 +4042,10 @@ copy_file (const char *input_filename, const char *output_filename, int ofd,
  	{
 	  if (ofd >= 0)
 	    close (ofd);
- 	  bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
+	  if (bfd_get_error () == bfd_error_invalid_target)
+	    bfd_nonfatal_message (output_target, NULL, NULL, NULL);
+	  else
+	    bfd_nonfatal_message (output_filename, NULL, NULL, NULL);
 	  bfd_close (ibfd);
  	  status = 1;
  	  return;


More information about the Binutils-cvs mailing list