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

e0bdd4
--- binutils.orig/binutils/readelf.c	2020-07-24 14:55:25.163647522 +0100
e0bdd4
+++ binutils-2.35/binutils/readelf.c	2020-07-24 15:02:39.613851369 +0100
e0bdd4
@@ -20729,79 +20729,92 @@ process_file (char * file_name)
e0bdd4
   Filedata * filedata = NULL;
e0bdd4
   struct stat statbuf;
e0bdd4
   char armag[SARMAG];
e0bdd4
-  bfd_boolean ret = TRUE;
e0bdd4
+  bfd_boolean ret = FALSE;
e0bdd4
+  char * name;
e0bdd4
+  char * saved_program_name;
e0bdd4
+
e0bdd4
+  /* Overload program_name to include file_name.  Doing this means
e0bdd4
+     that warning/error messages will positively identify the file
e0bdd4
+     concerned even when multiple instances of readelf are running.  */
e0bdd4
+  name = xmalloc (strlen (program_name) + strlen (file_name) + 3);
e0bdd4
+  sprintf (name, "%s: %s", program_name, file_name);
e0bdd4
+  saved_program_name = program_name;
e0bdd4
+  program_name = name;
e0bdd4
 
e0bdd4
   if (stat (file_name, &statbuf) < 0)
e0bdd4
     {
e0bdd4
       if (errno == ENOENT)
e0bdd4
-	error (_("'%s': No such file\n"), file_name);
e0bdd4
+	error (_("No such file\n"));
e0bdd4
       else
e0bdd4
-	error (_("Could not locate '%s'.  System error message: %s\n"),
e0bdd4
-	       file_name, strerror (errno));
e0bdd4
-      return FALSE;
e0bdd4
+	error (_("Could not locate file.  System error message: %s\n"),
e0bdd4
+	       strerror (errno));
e0bdd4
+      goto done;
e0bdd4
     }
e0bdd4
 
e0bdd4
   if (! S_ISREG (statbuf.st_mode))
e0bdd4
     {
e0bdd4
-      error (_("'%s' is not an ordinary file\n"), file_name);
e0bdd4
-      return FALSE;
e0bdd4
+      error (_("Not an ordinary file\n"));
e0bdd4
+      goto done;
e0bdd4
     }
e0bdd4
 
e0bdd4
   filedata = calloc (1, sizeof * filedata);
e0bdd4
   if (filedata == NULL)
e0bdd4
     {
e0bdd4
       error (_("Out of memory allocating file data structure\n"));
e0bdd4
-      return FALSE;
e0bdd4
+      goto done;
e0bdd4
     }
e0bdd4
 
e0bdd4
   filedata->file_name = file_name;
e0bdd4
   filedata->handle = fopen (file_name, "rb");
e0bdd4
   if (filedata->handle == NULL)
e0bdd4
     {
e0bdd4
-      error (_("Input file '%s' is not readable.\n"), file_name);
e0bdd4
-      free (filedata);
e0bdd4
-      return FALSE;
e0bdd4
+      error (_("Not readable\n"));
e0bdd4
+      goto done;
e0bdd4
     }
e0bdd4
 
e0bdd4
   if (fread (armag, SARMAG, 1, filedata->handle) != 1)
e0bdd4
     {
e0bdd4
-      error (_("%s: Failed to read file's magic number\n"), file_name);
e0bdd4
+      error (_("Failed to read file's magic number\n"));
e0bdd4
       fclose (filedata->handle);
e0bdd4
-      free (filedata);
e0bdd4
-      return FALSE;
e0bdd4
+      goto done;
e0bdd4
     }
e0bdd4
 
e0bdd4
   filedata->file_size = (bfd_size_type) statbuf.st_size;
e0bdd4
 
e0bdd4
   if (memcmp (armag, ARMAG, SARMAG) == 0)
e0bdd4
     {
e0bdd4
-      if (! process_archive (filedata, FALSE))
e0bdd4
-	ret = FALSE;
e0bdd4
+      if (process_archive (filedata, FALSE))
e0bdd4
+	ret = TRUE;
e0bdd4
     }
e0bdd4
   else if (memcmp (armag, ARMAGT, SARMAG) == 0)
e0bdd4
     {
e0bdd4
-      if ( ! process_archive (filedata, TRUE))
e0bdd4
-	ret = FALSE;
e0bdd4
+      if (process_archive (filedata, TRUE))
e0bdd4
+	ret = TRUE;
e0bdd4
     }
e0bdd4
   else
e0bdd4
     {
e0bdd4
       if (do_archive_index && !check_all)
e0bdd4
-	error (_("File %s is not an archive so its index cannot be displayed.\n"),
e0bdd4
-	       file_name);
e0bdd4
+	error (_("Not an archive so its index cannot be displayed.\n"));
e0bdd4
 
e0bdd4
       rewind (filedata->handle);
e0bdd4
       filedata->archive_file_size = filedata->archive_file_offset = 0;
e0bdd4
 
e0bdd4
-      if (! process_object (filedata))
e0bdd4
-	ret = FALSE;
e0bdd4
+      if (process_object (filedata))
e0bdd4
+	ret = TRUE;
e0bdd4
     }
e0bdd4
 
e0bdd4
-  fclose (filedata->handle);
e0bdd4
-  free (filedata->section_headers);
e0bdd4
-  free (filedata->program_headers);
e0bdd4
-  free (filedata->string_table);
e0bdd4
-  free (filedata->dump.dump_sects);
e0bdd4
-  free (filedata);
e0bdd4
+ done:
e0bdd4
+  if (filedata)
e0bdd4
+    {
e0bdd4
+      fclose (filedata->handle);
e0bdd4
+      free (filedata->section_headers);
e0bdd4
+      free (filedata->program_headers);
e0bdd4
+      free (filedata->string_table);
e0bdd4
+      free (filedata->dump.dump_sects);
e0bdd4
+      free (filedata);
e0bdd4
+    }
e0bdd4
+  free (program_name);
e0bdd4
+  program_name = saved_program_name;
e0bdd4
 
e0bdd4
   free (ba_cache.strtab);
e0bdd4
   ba_cache.strtab = NULL;