Don't dump GOT section contents after seeing errors in input:
readelf: Error: Section 10 has invalid sh_entsize of 0
readelf: Error: (Using the expected size of 18 for the rest of this dump)
readelf: Error: Too many program headers - 0x3030 - the file is not that big
PR binutils/34473
* elfcomm.c (seen_error): New.
(seen_elf_error): Likewise.
(clear_elf_error): Likewise.
(error): Set seen_error to true.
* elfcomm.h (seen_elf_error): New.
(clear_elf_error): Likewise.
* readelf.c (process_got_section_contents): Return false if
seen_elf_error returns true.
(main): Call clear_elf_error before calling process_file.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
extern char *program_name;
+static bool seen_error = false;
+
+bool
+seen_elf_error (void)
+{
+ return seen_error;
+}
+
+void
+clear_elf_error (void)
+{
+ seen_error = false;
+}
+
void
error (const char *message, ...)
{
va_list args;
+ seen_error = true;
+
/* Try to keep error messages in sync with the program's normal output. */
fflush (stdout);
extern void warn (const char *, ...) ATTRIBUTE_PRINTF_1;
extern void inform (const char *, ...) ATTRIBUTE_PRINTF_1;
+extern bool seen_elf_error (void);
+extern void clear_elf_error (void);
+
extern void (*byte_put) (unsigned char *, uint64_t, unsigned int);
extern void byte_put_little_endian (unsigned char *, uint64_t, unsigned int);
extern void byte_put_big_endian (unsigned char *, uint64_t, unsigned int);
if (!do_got_section_contents || all_relocations_count == 0)
return res;
+ if (seen_elf_error ())
+ return false;
+
switch (filedata->file_header.e_type)
{
case ET_DYN:
err = false;
while (optind < argc)
- if (! process_file (argv[optind++]))
- err = true;
+ {
+ clear_elf_error ();
+ if (! process_file (argv[optind++]))
+ err = true;
+ }
free (cmdline.dump_sects);