2018-02-21 09:31:35 +00:00
|
|
|
--- binutils.orig/binutils/readelf.c 2018-01-22 15:48:10.450701702 +0000
|
|
|
|
+++ binutils-2.30.0/binutils/readelf.c 2018-01-22 15:55:26.739588657 +0000
|
|
|
|
@@ -19019,75 +19019,85 @@ process_file (char * file_name)
|
|
|
|
Filedata * filedata = NULL;
|
2017-01-16 13:01:22 +00:00
|
|
|
struct stat statbuf;
|
|
|
|
char armag[SARMAG];
|
2018-02-21 09:31:35 +00:00
|
|
|
- bfd_boolean ret = TRUE;
|
|
|
|
+ bfd_boolean ret = FALSE;
|
|
|
|
+ char * name;
|
|
|
|
+ char * saved_program_name;
|
|
|
|
+
|
2017-01-16 13:01:22 +00:00
|
|
|
+ /* Overload program_name to include file_name. Doing this means
|
|
|
|
+ that warning/error messages will positively identify the file
|
|
|
|
+ concerned even when multiple instances of readelf are running. */
|
|
|
|
+ name = xmalloc (strlen (program_name) + strlen (file_name) + 3);
|
|
|
|
+ sprintf (name, "%s: %s", program_name, file_name);
|
|
|
|
+ saved_program_name = program_name;
|
|
|
|
+ program_name = name;
|
2018-02-21 09:31:35 +00:00
|
|
|
|
2017-01-16 13:01:22 +00:00
|
|
|
if (stat (file_name, &statbuf) < 0)
|
|
|
|
{
|
|
|
|
if (errno == ENOENT)
|
|
|
|
- error (_("'%s': No such file\n"), file_name);
|
|
|
|
+ error (_("No such file\n"));
|
|
|
|
else
|
|
|
|
- error (_("Could not locate '%s'. System error message: %s\n"),
|
|
|
|
- file_name, strerror (errno));
|
2017-07-24 15:48:39 +00:00
|
|
|
- return FALSE;
|
2017-01-16 13:01:22 +00:00
|
|
|
+ error (_("Could not locate file. System error message: %s\n"),
|
|
|
|
+ strerror (errno));
|
|
|
|
+ goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! S_ISREG (statbuf.st_mode))
|
|
|
|
{
|
|
|
|
- error (_("'%s' is not an ordinary file\n"), file_name);
|
2017-07-24 15:48:39 +00:00
|
|
|
- return FALSE;
|
2017-01-16 13:01:22 +00:00
|
|
|
+ error (_("Not an ordinary file\n"));
|
|
|
|
+ goto done;
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:31:35 +00:00
|
|
|
filedata = calloc (1, sizeof * filedata);
|
|
|
|
if (filedata == NULL)
|
|
|
|
{
|
|
|
|
error (_("Out of memory allocating file data structure\n"));
|
|
|
|
- return FALSE;
|
|
|
|
+ goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
filedata->file_name = file_name;
|
|
|
|
filedata->handle = fopen (file_name, "rb");
|
|
|
|
if (filedata->handle == NULL)
|
2017-01-16 13:01:22 +00:00
|
|
|
{
|
|
|
|
- error (_("Input file '%s' is not readable.\n"), file_name);
|
2018-02-21 09:31:35 +00:00
|
|
|
- free (filedata);
|
2017-07-24 15:48:39 +00:00
|
|
|
- return FALSE;
|
2017-01-16 13:01:22 +00:00
|
|
|
+ error (_("Not readable\n"));
|
|
|
|
+ goto done;
|
|
|
|
}
|
|
|
|
|
2018-02-21 09:31:35 +00:00
|
|
|
if (fread (armag, SARMAG, 1, filedata->handle) != 1)
|
2017-01-16 13:01:22 +00:00
|
|
|
{
|
|
|
|
- error (_("%s: Failed to read file's magic number\n"), file_name);
|
2018-02-21 09:31:35 +00:00
|
|
|
- fclose (filedata->handle);
|
|
|
|
- free (filedata);
|
2017-07-24 15:48:39 +00:00
|
|
|
- return FALSE;
|
2018-02-21 09:31:35 +00:00
|
|
|
- }
|
|
|
|
-
|
|
|
|
- filedata->file_size = (bfd_size_type) statbuf.st_size;
|
|
|
|
-
|
|
|
|
- if (memcmp (armag, ARMAG, SARMAG) == 0)
|
|
|
|
- {
|
|
|
|
- if (! process_archive (filedata, FALSE))
|
|
|
|
- ret = FALSE;
|
|
|
|
- }
|
|
|
|
- else if (memcmp (armag, ARMAGT, SARMAG) == 0)
|
|
|
|
- {
|
|
|
|
- if ( ! process_archive (filedata, TRUE))
|
|
|
|
- ret = FALSE;
|
|
|
|
+ error (_("Failed to read file's magic number\n"));
|
2017-01-16 13:01:22 +00:00
|
|
|
}
|
2018-02-21 09:31:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
- if (do_archive_index)
|
|
|
|
- error (_("File %s is not an archive so its index cannot be displayed.\n"),
|
|
|
|
- file_name);
|
|
|
|
+ filedata->file_size = (bfd_size_type) statbuf.st_size;
|
2017-01-16 13:01:22 +00:00
|
|
|
|
2018-02-21 09:31:35 +00:00
|
|
|
- rewind (filedata->handle);
|
|
|
|
- archive_file_size = archive_file_offset = 0;
|
|
|
|
-
|
|
|
|
- if (! process_object (filedata))
|
|
|
|
- ret = FALSE;
|
|
|
|
+ if (memcmp (armag, ARMAG, SARMAG) == 0)
|
|
|
|
+ {
|
|
|
|
+ if (process_archive (filedata, FALSE))
|
|
|
|
+ ret = TRUE;
|
|
|
|
+ }
|
|
|
|
+ else if (memcmp (armag, ARMAGT, SARMAG) == 0)
|
|
|
|
+ {
|
|
|
|
+ if (process_archive (filedata, TRUE))
|
|
|
|
+ ret = TRUE;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (do_archive_index)
|
|
|
|
+ error (_("Not an archive so its index cannot be displayed.\n"));
|
|
|
|
+
|
|
|
|
+ rewind (filedata->handle);
|
|
|
|
+ archive_file_size = archive_file_offset = 0;
|
|
|
|
+
|
|
|
|
+ if (process_object (filedata))
|
|
|
|
+ ret = TRUE;
|
|
|
|
+ }
|
2017-07-24 15:48:39 +00:00
|
|
|
}
|
2017-01-16 13:01:22 +00:00
|
|
|
|
2018-02-21 09:31:35 +00:00
|
|
|
fclose (filedata->handle);
|
2017-01-16 13:01:22 +00:00
|
|
|
+ done:
|
2018-02-21 09:31:35 +00:00
|
|
|
free (filedata);
|
2017-01-16 13:01:22 +00:00
|
|
|
+ free (program_name);
|
|
|
|
+ program_name = saved_program_name;
|
2017-07-24 15:48:39 +00:00
|
|
|
|
2017-01-16 13:01:22 +00:00
|
|
|
return ret;
|
|
|
|
}
|