[binutils-gdb] readelf: Avoid may be used uninitialized warning from GCC 14

"H.J. Lu via Binutils-cvs" <[email protected]> Wed, 1 Jul 2026 23:13:58 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c1c4795df872f48b7f3659cae5974a6ae4f917ea

commit c1c4795df872f48b7f3659cae5974a6ae4f917ea
Author: H.J. Lu <[email protected]>
Date:   Thu Jul 2 07:02:48 2026 +0800

    readelf: Avoid may be used uninitialized warning from GCC 14
    
    GCC 14 fails to recognize that rel_entsz and entsz_name are unused when
    process_relocs returns early for error:
    
    .../binutils/readelf.c:10127:18: error: ‘rel_entsz’ may be used uninitialized [-Werror=maybe-uninitialized]
    10127 |               if (rel_entsz == 0)
          |                  ^
    ...
    .../binutils/readelf.c:10129:19: error: ‘entsz_name’ may be used uninitialized [-Werror=maybe-uninitialized]
    10129 |                   printf (_("<missing or corrupt dynamic tag: %s>\n"),
          |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    10130 |                           entsz_name);
    
    Clear them before returning error.  Also replace reltype_unknown with
    default since GCC 14 fails to see that reltype_unknown is the only
    unhandled value for relocation_type enum.
    
            PR binutils/34324
            * readelf.c (process_relocs): Clear rel_entsz and entsz_name
            before returning error on missing DT_REL and DT_RELA dynamic
            tags.
    
    Signed-off-by: H.J. Lu <[email protected]>

Diff:
---
 binutils/readelf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 33b95da8b7e..59b9d906f08 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -10080,8 +10080,11 @@ process_relocs (Filedata * filedata)
 
 	  switch (rel_type)
 	    {
-	    case reltype_unknown:
+	    default:
 	      error (_("missing DT_REL and DT_RELA dynamic tags\n"));
+	      /* Avoid may be used uninitialized warning from GCC 14.  */
+	      rel_entsz = 0;
+	      entsz_name = NULL;
 	      return false;
 	    case reltype_rel:
 	      rel_entsz = filedata->dynamic_info[DT_RELENT];