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

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