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

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