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

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