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

00b3bd
--- binutils.orig/binutils/readelf.c	2021-07-19 12:39:14.206556025 +0100
00b3bd
+++ binutils-2.37/binutils/readelf.c	2021-07-19 12:44:37.712728732 +0100
00b3bd
@@ -21873,45 +21873,52 @@ process_file (char * file_name)
00b3bd
   struct stat statbuf;
00b3bd
   char armag[SARMAG];
00b3bd
   bool ret = true;
00b3bd
+  char * name;
00b3bd
+  char * saved_program_name;
00b3bd
+
00b3bd
+  /* Overload program_name to include file_name.  Doing this means
00b3bd
+     that warning/error messages will positively identify the file
00b3bd
+     concerned even when multiple instances of readelf are running.  */
00b3bd
+  name = xmalloc (strlen (program_name) + strlen (file_name) + 3);
00b3bd
+  sprintf (name, "%s: %s", program_name, file_name);
00b3bd
+  saved_program_name = program_name;
00b3bd
+  program_name = name;
00b3bd
 
00b3bd
   if (stat (file_name, &statbuf) < 0)
00b3bd
     {
00b3bd
       if (errno == ENOENT)
00b3bd
-	error (_("'%s': No such file\n"), file_name);
00b3bd
+	error (_("No such file\n"));
00b3bd
       else
00b3bd
-	error (_("Could not locate '%s'.  System error message: %s\n"),
00b3bd
-	       file_name, strerror (errno));
00b3bd
-      return false;
00b3bd
+	error (_("Could not locate file.  System error message: %s\n"),
00b3bd
+	       strerror (errno));
00b3bd
+      goto done;
00b3bd
     }
00b3bd
 
00b3bd
   if (! S_ISREG (statbuf.st_mode))
00b3bd
     {
00b3bd
-      error (_("'%s' is not an ordinary file\n"), file_name);
00b3bd
-      return false;
00b3bd
+      error (_("Not an ordinary file\n"));
00b3bd
+      goto done;
00b3bd
     }
00b3bd
 
00b3bd
   filedata = calloc (1, sizeof * filedata);
00b3bd
   if (filedata == NULL)
00b3bd
     {
00b3bd
       error (_("Out of memory allocating file data structure\n"));
00b3bd
-      return false;
00b3bd
+      goto done;
00b3bd
     }
00b3bd
 
00b3bd
   filedata->file_name = file_name;
00b3bd
   filedata->handle = fopen (file_name, "rb");
00b3bd
   if (filedata->handle == NULL)
00b3bd
     {
00b3bd
-      error (_("Input file '%s' is not readable.\n"), file_name);
00b3bd
-      free (filedata);
00b3bd
-      return false;
00b3bd
+      error (_("Not readable\n"));
00b3bd
+      goto done;
00b3bd
     }
00b3bd
 
00b3bd
   if (fread (armag, SARMAG, 1, filedata->handle) != 1)
00b3bd
     {
00b3bd
-      error (_("%s: Failed to read file's magic number\n"), file_name);
00b3bd
-      fclose (filedata->handle);
00b3bd
-      free (filedata);
00b3bd
-      return false;
00b3bd
+      error (_("Failed to read file's magic number\n"));
00b3bd
+      goto done;
00b3bd
     }
00b3bd
 
00b3bd
   filedata->file_size = (bfd_size_type) statbuf.st_size;
00b3bd
@@ -21919,33 +21926,39 @@ process_file (char * file_name)
00b3bd
 
00b3bd
   if (memcmp (armag, ARMAG, SARMAG) == 0)
00b3bd
     {
00b3bd
-      if (! process_archive (filedata, false))
00b3bd
-	ret = false;
00b3bd
+      if (process_archive (filedata, false))
00b3bd
+	ret = true;
00b3bd
     }
00b3bd
   else if (memcmp (armag, ARMAGT, SARMAG) == 0)
00b3bd
     {
00b3bd
-      if ( ! process_archive (filedata, true))
00b3bd
-	ret = false;
00b3bd
+      if (process_archive (filedata, true))
00b3bd
+	ret = true;
00b3bd
     }
00b3bd
   else
00b3bd
     {
00b3bd
       if (do_archive_index && !check_all)
00b3bd
-	error (_("File %s is not an archive so its index cannot be displayed.\n"),
00b3bd
-	       file_name);
00b3bd
+	error (_("Not an archive so its index cannot be displayed.\n"));
00b3bd
 
00b3bd
       rewind (filedata->handle);
00b3bd
       filedata->archive_file_size = filedata->archive_file_offset = 0;
00b3bd
 
00b3bd
-      if (! process_object (filedata))
00b3bd
-	ret = false;
00b3bd
+      if (process_object (filedata))
00b3bd
+	ret = true;
00b3bd
     }
00b3bd
 
00b3bd
-  fclose (filedata->handle);
00b3bd
-  free (filedata->section_headers);
00b3bd
-  free (filedata->program_headers);
00b3bd
-  free (filedata->string_table);
00b3bd
-  free (filedata->dump.dump_sects);
00b3bd
-  free (filedata);
00b3bd
+ done:
00b3bd
+  if (filedata)
00b3bd
+    {
00b3bd
+      if (filedata->handle != NULL)
00b3bd
+	fclose (filedata->handle);
00b3bd
+      free (filedata->section_headers);
00b3bd
+      free (filedata->program_headers);
00b3bd
+      free (filedata->string_table);
00b3bd
+      free (filedata->dump.dump_sects);
00b3bd
+      free (filedata);
00b3bd
+    }
00b3bd
+  free (program_name);
00b3bd
+  program_name = saved_program_name;
00b3bd
 
00b3bd
   free (ba_cache.strtab);
00b3bd
   ba_cache.strtab = NULL;
00b3bd
--- binutils.orig/binutils/readelf.c	2021-08-10 10:15:22.088016072 +0100
00b3bd
+++ binutils-2.37/binutils/readelf.c	2021-08-10 10:15:55.567907891 +0100
00b3bd
@@ -21884,7 +21884,7 @@ process_file (char * file_name)
00b3bd
   Filedata * filedata = NULL;
00b3bd
   struct stat statbuf;
00b3bd
   char armag[SARMAG];
00b3bd
-  bool ret = true;
00b3bd
+  bool ret = false;
00b3bd
   char * name;
00b3bd
   char * saved_program_name;
00b3bd