aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2025-09-04 06:05:33 -0700
committerH.J. Lu <hjl.tools@gmail.com>2025-09-05 04:56:27 -0700
commit3e1716c9fc203f5654d49c17b160a466c78a2a2c (patch)
treeda8b87fa670a8124d8b065dd955af83fd56ce27b
parent507d144bbf083c88110700a123711b2f9bb616b7 (diff)
downloadbinutils-3e1716c9fc203f5654d49c17b160a466c78a2a2c.zip
binutils-3e1716c9fc203f5654d49c17b160a466c78a2a2c.tar.gz
binutils-3e1716c9fc203f5654d49c17b160a466c78a2a2c.tar.bz2
readelf: Handle 0 sh_entsize of GOT sections
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>
-rw-r--r--binutils/readelf.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 705b776..03c4520 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -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"),