]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
readelf: Handle 0 sh_entsize of GOT sections
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 4 Sep 2025 13:05:33 +0000 (06:05 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 5 Sep 2025 11:56:27 +0000 (04:56 -0700)
Gold, lld and mold set sh_entsize to 0 on .got and .got.plt sections.
If sh_entsize of GOT sections is 0, assume 8 for ELFCLASS64 and 4 for
ELFCLASS32, except for x32 which uses 8.

PR binutils/33368
* readelf.c (process_got_section_contents): Handle 0 sh_entsize
of GOT sections.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
binutils/readelf.c

index 705b7761bc8c0254928cf4be39e89adb6460d890..03c4520ff9242287c9f2a3bc19d5b1cd21f683f6 100644 (file)
@@ -21075,6 +21075,25 @@ process_got_section_contents (Filedata * filedata)
          }
 
        uint32_t entsz = section->sh_entsize;
+       /* NB: Gold, lld and mold set sh_entsize to 0 on .got and
+          .got.plt sections.  */
+       if (entsz == 0)
+         {
+           if (is_32bit_elf)
+             switch (filedata->file_header.e_machine)
+               {
+               default:
+                 entsz = 4;
+                 break;
+               case EM_X86_64:
+                 /* x32 uses 8 byte GOT sh_entsize.  */
+                 entsz = 8;
+                 break;
+               }
+           else
+             entsz = 8;
+         }
+
        entries = section->sh_size / entsz;
        if (entries == 1)
          printf (_("\nGlobal Offset Table '%s' contains 1 entry:\n"),