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