[PATCH] readelf: Don't dump GOT section after seeing error
"H.J. Lu" <[email protected]>
| Newsgroups | gmane.comp.gnu.binutils |
|---|---|
| Message-ID | <CAMe9rOpDwQ-N9Up3yNqzyOnb1hi+pyiSnzA5VZEtSGR=R4B69A@mail.gmail.com> |
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. -- H.J.
0001-readelf-Don-t-dump-GOT-section-after-seeing-error.patch
(text/x-patch, 2.8 KB)
From ea834234328560fdf6d1b89d2bb255a6e58cba4b Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <[email protected]> Date: Thu, 6 Aug 2026 10:33:02 +0800 Subject: [PATCH] readelf: Don't dump GOT section after seeing error 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 <[email protected]> --- binutils/elfcomm.c | 16 ++++++++++++++++ binutils/elfcomm.h | 3 +++ binutils/readelf.c | 10 ++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/binutils/elfcomm.c b/binutils/elfcomm.c index 4a4f5368220..d54de39ecdd 100644 --- a/binutils/elfcomm.c +++ b/binutils/elfcomm.c @@ -35,11 +35,27 @@ 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); diff --git a/binutils/elfcomm.h b/binutils/elfcomm.h index 953bc3d1bc3..5bd61e9587d 100644 --- a/binutils/elfcomm.h +++ b/binutils/elfcomm.h @@ -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); diff --git a/binutils/readelf.c b/binutils/readelf.c index 90ce1f1f0fc..7d14201cfef 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -21664,6 +21664,9 @@ process_got_section_contents (Filedata * filedata) bool res = true; bool found = false; + if (seen_elf_error ()) + return false; + if (!do_got_section_contents || all_relocations_count == 0) return res; @@ -25613,8 +25616,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); -- 2.55.0