Blame SOURCES/binutils-filename-in-error-messages.patch

82154a
diff -rupN --no-dereference binutils-2.39/binutils/readelf.c binutils-2.39-new/binutils/readelf.c
82154a
--- binutils-2.39/binutils/readelf.c	2022-07-08 11:46:47.000000000 +0200
82154a
+++ binutils-2.39-new/binutils/readelf.c	2022-10-30 12:41:25.339023741 +0100
82154a
@@ -22710,46 +22710,53 @@ process_file (char * file_name)
fcd040
   Filedata * filedata = NULL;
e89428
   struct stat statbuf;
e89428
   char armag[SARMAG];
fcd040
-  bool ret = true;
fcd040
+  bool ret = false;
e89428
+  char * name;
e89428
+  char * saved_program_name;
e89428
+
e89428
+  /* Overload program_name to include file_name.  Doing this means
e89428
+     that warning/error messages will positively identify the file
e89428
+     concerned even when multiple instances of readelf are running.  */
e89428
+  name = xmalloc (strlen (program_name) + strlen (file_name) + 3);
e89428
+  sprintf (name, "%s: %s", program_name, file_name);
e89428
+  saved_program_name = program_name;
e89428
+  program_name = name;
e89428
 
e89428
   if (stat (file_name, &statbuf) < 0)
e89428
     {
e89428
       if (errno == ENOENT)
e89428
-	error (_("'%s': No such file\n"), file_name);
e89428
+	error (_("No such file\n"));
e89428
       else
e89428
-	error (_("Could not locate '%s'.  System error message: %s\n"),
e89428
-	       file_name, strerror (errno));
e89428
-      return false;
e89428
+	error (_("Could not locate file.  System error message: %s\n"),
e89428
+	       strerror (errno));
e89428
+      goto done;
e89428
     }
e89428
 
e89428
   if (! S_ISREG (statbuf.st_mode))
e89428
     {
e89428
-      error (_("'%s' is not an ordinary file\n"), file_name);
e89428
-      return false;
e89428
+      error (_("Not an ordinary file\n"));
e89428
+      goto done;
e89428
     }
e89428
 
e89428
   filedata = calloc (1, sizeof * filedata);
e89428
   if (filedata == NULL)
e89428
     {
e89428
       error (_("Out of memory allocating file data structure\n"));
e89428
-      return false;
e89428
+      goto done;
e89428
     }
e89428
 
e89428
   filedata->file_name = file_name;
e89428
   filedata->handle = fopen (file_name, "rb");
e89428
   if (filedata->handle == NULL)
e89428
     {
e89428
-      error (_("Input file '%s' is not readable.\n"), file_name);
e89428
-      free (filedata);
e89428
-      return false;
e89428
+      error (_("Not readable\n"));
e89428
+      goto done;
e89428
     }
e89428
 
e89428
   if (fread (armag, SARMAG, 1, filedata->handle) != 1)
e89428
     {
e89428
-      error (_("%s: Failed to read file's magic number\n"), file_name);
e89428
-      fclose (filedata->handle);
e89428
-      free (filedata);
e89428
-      return false;
e89428
+      error (_("Failed to read file's magic number\n"));
e89428
+      goto done;
e89428
     }
e89428
 
e89428
   filedata->file_size = (bfd_size_type) statbuf.st_size;
82154a
@@ -22757,33 +22764,39 @@ process_file (char * file_name)
e89428
 
e89428
   if (memcmp (armag, ARMAG, SARMAG) == 0)
e89428
     {
e89428
-      if (! process_archive (filedata, false))
e89428
-	ret = false;
e89428
+      if (process_archive (filedata, false))
e89428
+	ret = true;
e89428
     }
e89428
   else if (memcmp (armag, ARMAGT, SARMAG) == 0)
e89428
     {
e89428
-      if ( ! process_archive (filedata, true))
e89428
-	ret = false;
e89428
+      if (process_archive (filedata, true))
e89428
+	ret = true;
e89428
     }
e89428
   else
e89428
     {
e89428
       if (do_archive_index && !check_all)
e89428
-	error (_("File %s is not an archive so its index cannot be displayed.\n"),
e89428
-	       file_name);
e89428
+	error (_("Not an archive so its index cannot be displayed.\n"));
e89428
 
e89428
       rewind (filedata->handle);
e89428
       filedata->archive_file_size = filedata->archive_file_offset = 0;
e89428
 
e89428
-      if (! process_object (filedata))
e89428
-	ret = false;
e89428
+      if (process_object (filedata))
e89428
+	ret = true;
e89428
     }
e89428
 
e89428
-  fclose (filedata->handle);
e89428
-  free (filedata->section_headers);
e89428
-  free (filedata->program_headers);
e89428
-  free (filedata->string_table);
e89428
-  free (filedata->dump.dump_sects);
e89428
-  free (filedata);
e89428
+ done:
e89428
+  if (filedata)
e89428
+    {
e89428
+      if (filedata->handle != NULL)
e89428
+	fclose (filedata->handle);
e89428
+      free (filedata->section_headers);
e89428
+      free (filedata->program_headers);
e89428
+      free (filedata->string_table);
e89428
+      free (filedata->dump.dump_sects);
e89428
+      free (filedata);
e89428
+    }
e89428
+  free (program_name);
e89428
+  program_name = saved_program_name;
e89428
 
e89428
   free (ba_cache.strtab);
e89428
   ba_cache.strtab = NULL;