]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
readelf: Don't dump GOT section after seeing error
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Aug 2026 02:33:02 +0000 (10:33 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 6 Aug 2026 06:37:41 +0000 (14:37 +0800)
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>
binutils/elfcomm.c
binutils/elfcomm.h
binutils/readelf.c

index 4a4f536822088cf62e0aea24493c7b7bd14ed3ea..d54de39ecdd89af82e742cb7c119526be75f9940 100644 (file)
 
 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);
 
index 953bc3d1bc386dedb9bab658f36a6ceee0568808..5bd61e9587d1bc9430bbaf07dd370eeca113e159 100644 (file)
@@ -30,6 +30,9 @@ extern void error (const char *, ...) ATTRIBUTE_PRINTF_1;
 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);
index a52fe2b8d6375ee6a14476109dd2531ad955d38e..c7076d22e5c6e69fbb11aa0b33835566b37f8792 100644 (file)
@@ -21667,6 +21667,9 @@ process_got_section_contents (Filedata * filedata)
   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:
@@ -25607,8 +25610,11 @@ main (int argc, char ** argv)
 
   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);