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

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