[PATCH v2] readelf: Handle 0 sh_entsize of GOT sections for x86

H.J. Lu hjl.tools@gmail.com
Thu Sep 4 01:02:49 GMT 2025


Some linker sets sh_entsize to 0 on .got and .got.plt sections, for
example, x86-64 Google chrome browser:

$ readelf -SW /opt/google/chrome/chrome | grep got
  [27] .got      PROGBITS 000000000fb29fc0 fb27fc0 001be0 00 WA 0 0 8
  [28] .got.plt  PROGBITS 000000000fb2bba0 fb29ba0 0029a8 00 WA 0 0 8
$

If sh_entsize of GOT sections is 0, assume 4 for i386 and 8 for ELFCLASS64
or x86-64.  Skip with a warning for ELFCLASS32 which may use 8, like x32.

	PR binutils/33368
	* readelf.c (process_got_section_contents): Handle 0 sh_entsize
	of GOT sections for i386 and x86-64.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 binutils/readelf.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 4b1a26602c2..4be66c69dde 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -21150,6 +21150,30 @@ process_got_section_contents (Filedata * filedata)
 	  }
 
 	uint32_t entsz = section->sh_entsize;
+	/* NB: Some linker sets sh_entsize to 0 on .got and .got.plt
+	   sections, for example x86-64 Google chrome browser.  */
+	if (entsz == 0)
+	  switch (filedata->file_header.e_machine)
+	    {
+	    default:
+	      if (is_32bit_elf)
+		{
+		  /* NB: ELFCLASS32 may use 8 byte GOT sh_entsize,
+		     like x32.  */
+		  warn (_("Can't determine section '%s' sh_entsize\n"),
+			name);
+		  res = false;
+		  goto out;
+		}
+	      /* Fall through.  */
+	    case EM_X86_64:
+	      entsz = 8;
+	      break;
+	    case EM_386:
+	      entsz = 4;
+	      break;
+	    }
+
 	entries = section->sh_size / entsz;
 	if (entries == 1)
 	  printf (_("\nGlobal Offset Table '%s' contains 1 entry:\n"),
-- 
2.51.0



More information about the Binutils mailing list